Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NpT sanity checks should run at integration start #4139

Closed
jngrad opened this issue Mar 5, 2021 · 0 comments · Fixed by #4165
Closed

NpT sanity checks should run at integration start #4139

jngrad opened this issue Mar 5, 2021 · 0 comments · Fixed by #4165

Comments

@jngrad
Copy link
Member

jngrad commented Mar 5, 2021

The Coulomb/dipoles NpT sanity checks are executed only once, when setting up the NpT integrator. Adding a P3M actor before setting a rectangular NpT integrator fails loudly. But if we add a P3M actor after setting up a rectangular NpT, no error is raised.

MWE:

import espressomd.integrate
import espressomd.electrostatics
import numpy as np
np.random.seed(42)

system = espressomd.System(box_l=3 * [6], time_step = 0.01)
system.cell_system.skin = 0.25
system.part.add(pos=np.random.uniform(0, system.box_l[0], (10, 3)), q=5 * [-1, 1])
system.non_bonded_inter[0, 0].wca.set_params(epsilon=1, sigma=1)
npt_params = dict(ext_pressure=1e-4, piston=1e-4, cubic_box=False, direction=(0, 1, 1))
system.thermostat.set_npt(kT=1.0, gamma0=2, gammav=0.04, seed=42)
system.integrator.set_isotropic_npt(**npt_params)
system.actors.add(espressomd.electrostatics.P3M(prefactor=1.0, accuracy=1e-2,
                  mesh=3 * [8], cao=3, r_cut=0.36, alpha=5.35, tune=False))
system.integrator.run(100)     # no failure
print('box_l:', system.box_l)  # box is now rectangular
system.integrator.set_isotropic_npt(**npt_params)  # fails

Output:

box_l: [ 6. 18.34 18.34]
Traceback (most recent call last):
  File "npt.py", line 18, in <module>
    system.integrator.set_isotropic_npt(**npt_params)  # fails
  File "integrate.pyx", line 92, in espressomd.integrate.IntegratorHandle.set_isotropic_npt
  File "integrate.pyx", line 147, in espressomd.integrate.Integrator.__init__
  File "integrate.pyx", line 364, in espressomd.integrate.VelocityVerletIsotropicNPT._set_params_in_es_core
RuntimeError: If electrostatics is being used you must use the cubic box npt.

This can be fixed by moving the sanity checks from the setter to the callback.

@jngrad jngrad self-assigned this Mar 5, 2021
@kodiakhq kodiakhq bot closed this as completed in #4165 Mar 29, 2021
kodiakhq bot added a commit that referenced this issue Mar 29, 2021
Fixes #4139

Description of changes:
- gather NpT sanity checks in a function that is called at integration start
- the combination P3M + rectangular NpT now generates an exception regardless of the order in which the system is set up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants