espressomd / espresso

The ESPResSo package
https://espressomd.org
GNU General Public License v3.0
224 stars 183 forks source link

Constraint violation by particles #3981

Closed dpo854 closed 3 years ago

dpo854 commented 3 years ago

Hi everyone, I am trying to simulate mobile dissociable species confined to a surface, which is in contact with a salt solution maintained at a specific pH. The surface is represented in the simulation by a wall, which interacts with the solution species through a standard Lennard Jones potential. The dissociable species on the wall are constrained to move only on the surface through the fix option in system.part.add(). Other features of the simulation involve performing Monte-Carlo for reaction moves and placing a second wall at the other end of the simulation box to prevent particles from coming close to the wall from the side away from the solution. Now coming straight to the business, when I do energy minimization before starting the simulation, I get a long stream of error messages mentioning the violation of wall constraints by particles. I have checked my code multiple times and all my mobile species during the particle generation process are placed sufficiently far away from the walls. And the surface dissociable particles do not interact with the wall. What is causing the error then?

Thanks, Debadutta Prusty

jonaslandsgesell commented 3 years ago

Hey,

did you constrain the volume in which MC moves happen? You need to do that because the MC moves do not know about constraints (and even if they knew, there are no guaranteed rules what should happen then).

The corresponding commands are:

RE.set_wall_constraints_in_z_direction(slab_start_z, slab_end_z) And RE.set_volume(volume) Be sure to set the correct available volume for the MC moves, it affects the acceptance probability Again, the rules for computing the volume are not in every situation clear (multiple constraints etc.) which is why you have to set it by hand.

dpo854 commented 3 years ago

Hi Jonas, I did have the above lines in my program to enforce the volume constraint on MC moves. The error comes up before the reaction ensemble is invoked. I guess that might have something to do with the dissociable particles since they are placed on the wall.

jonaslandsgesell commented 3 years ago

The error comes up before the reaction ensemble is invoked.

This is a good point. Did you try to place the particles +/-1e-6 [sigma] in front of the wall and not directly on the wall? I recall that there were numerical instabilities related to this.

Otherwise, could you share a minimal working example which provokes the failure?

dpo854 commented 3 years ago

Flat.zip

dpo854 commented 3 years ago

The above zipped file has the code along with the shell script for job submission. Unfortunately, putting some distance between dissociable particles and the wall didn't do much to resolve the error.

jonaslandsgesell commented 3 years ago

If the integration fails before any mc moves, then I think the problem here is the placement of the the walls? I suspect you want to place them at z=zwall and z=box_l_z, where zwall=0.3*box_l_z and then only place particles in between z=zwall+1 till z=box_l_z-1 (note the +/- 1 here is due to the diverging interaction energy of the WCA/LJ wall), MC moves will fail if you allow for placing particles closer to the walls. Can you try to place the second wall at box_l_z-1e-5 ? I recall constraints being set outside the central box are ignored by Espresso.

If this does not help, maybe @jngrad can execute the script and check for the correct placement of the walls.

dpo854 commented 3 years ago

Bringing the wall on the edge of the box a little bit in did the trick. Thanks a lot.

dpo854 commented 3 years ago

Sorry for restarting the issue. It turns out that it wasn't that simple. Even after I put the above-mentioned changes in place, the constraint violation error comes up at different points in the program. Anticipating that the proximity between newly introduced species in the system during the reaction moves and the already existing particles and the resulting kick experienced by a particle, which has the potential to take it close to or across one of the walls, might be contributing to this problem, I decreased the time step from 0.01 to 0.001 with no success. Now, it comes up just after reaction moves. How does one ensure that there is no blow-up during these reaction moves? Do you suggest doing an energy minimization after reaction moves and then turning it off before starting a few md runs? Please ignore the code that I had put up previously. I have changed it considerably. The updated code is attached below if that matters. shortfiber.zip

jonaslandsgesell commented 3 years ago

Hey no probelm! If your particles have all the same effective "size" I implemented the solution already (without expensive energy minimization which would also probably destroy thermalization), please make sure that:

0) make sure you don't setup unfixed particles next to the wall initially. 1) you do only insert particles up to a distsance shortly before the LJ interaction of the wall diverges (for me it was ~0.9sigma, but this might differ if you use some combination rule or some mixed particle sizes/LJ potentials ) -> this is the purpose of RE.set_wall_constraints_in_z_direction() ). If you have different "particle sizes" you would need to make this command aware of the particle types in the C++ core and then also the insertion of the different types would need to be performed in different "available" volumes in the core. 2) set the exclusion radius in the Reaction ensemble to the closest distance where the energy of the LJ interaction is not yet so high that the force resulting in a placement of a new particle at this distance will cause the MD integration to crash. For a typical WCA interaction with epsilon and simga 1.0 this 0.9 is a good value. Again if you have different particle sizes/LJ combination rules you would need to adapt the C++ code to make use of different exclusion radii for different particle sizes.

dpo854 commented 3 years ago

Unfortunately, the error remains even after I put sufficient space between the walls and the locations of reaction moves using RE.set_wall_constraints_in_z_direction(zwall+3.0, boxlz-3.0) with a sigma of 1.0. The exclusion radius is sigma. By the way, I had set the wall sigmas to zero just so the effective sigma between the walls and the particles is simply half the diameter of particles. The error messages are: ERROR: Constraint violated by particle 4509 dist -267.234 ERROR: Constraint violated by particle 4509 dist -0.000494613

My walls are located at zwall=267.234 and 0.001 while the boxlz is 890.78. The error comes up right in the first loop of grand-canonical moves. By the way, for your information, I had enabled the slab correction in electrostatics with the following commands and set the gap size to the gap between two walls. Do you think that is a potential contributor to the error?

elc=electrostatic_extensions.ELC(gap_size=zwall,neutralize=False,maxPWerror=1e-3,check_neutrality=True) system.actors.add(elc)

jonaslandsgesell commented 3 years ago

My walls are located at zwall=267.234 and 0.001 while the boxlz is 890.78.

Could you place them at zwall and boxlz-0.000001?

From what you reported earlier you want the space between z=0 to z=zwall to be free of particles.

Another possibility could be that the interaction of the wall is too soft to contrain the particles. Try to use the standard LJ for both the particles and the wall to check if the error still occurs.

KaiSzuttor commented 3 years ago

this is probably a topic for the mailing list

dpo854 commented 3 years ago

My walls are located at zwall=267.234 and 0.001 while the boxlz is 890.78.

Could you place them at zwall and boxlz-0.000001?

From what you reported earlier you want the space between z=0 to z=zwall to be free of particles.

Another possibility could be that the interaction of the wall is too soft to contrain the particles. Try to use the standard LJ for both the particles and the wall to check if the error still occurs.

I did that but it doesn't change anything. Now it throws the same error from a different location in the program.

system.actors.add(p3m)

Traceback (most recent call last): File "MD-fiber-new.py", line 299, in system.actors.add(p3m) File "espressomd/actors.pyx", line 215, in espressomd.actors.Actors.add (/home/dpo854/mycode/espresso/build/src/python/espressomd/actors.cpp:5586) File "espressomd/actors.pyx", line 70, in espressomd.actors.Actor._activate (/home/dpo854/mycode/espresso/build/src/python/espressomd/actors.cpp:2365) File "espressomd/electrostatics.pyx", line 343, in espressomd.electrostatics.P3M._activate_method (/home/dpo854/mycode/espresso/build/src/python/espressomd/electrostatics.cpp:6925) File "espressomd/electrostatics.pyx", line 334, in espressomd.electrostatics.P3M._tune (/home/dpo854/mycode/espresso/build/src/python/espressomd/electrostatics.cpp:6664) File "espressomd/electrostatics.pxd", line 136, in espressomd.electrostatics.python_p3m_adaptive_tune (/home/dpo854/mycode/espresso/build/src/python/espressomd/electrostatics.cpp:13360) File "espressomd/utils.pyx", line 264, in espressomd.utils.handle_errors (/home/dpo854/mycode/espresso/build/src/python/espressomd/utils.cpp:7717) Exception: Error in p3m_adaptive_tune: ERROR: Constraint violated by particle 0 dist -623.547

dpo854 commented 3 years ago

Finally some good news. The program runs smoothly now thanks to Jonas bringing to my notice another post with the same problem. The crux of the whole thing is while putting walls in the simulation box, one must set the directions properly, which should always point into the region of simulation. I was under the impression that as long as the product of the distance and the direction gives the proper location of the wall, change of signs (a negative distance with a negative direction gives the same product as the corresponding positive distance with the corresponding positive direction) does not impact how constraints interact with particles. But, that turned out to be wrong.