Fix rigid: Atoms have moved too far apart

Dear all,

I am using LAMMPS version 2 Aug 2023 - Update 2. I use the “fix rigid” command to simulate CO2 with the TraPPE model. However, when I write two “run” commands at the beginning of the second run or use the data file output as another simulation input, I sometimes encounter the following error:

ERROR on proc 0: Atoms have moved too far apart (734.0632310066682) for minimum image (src/domain.cpp:994).

What should be done to solve this error? Is this a software bug? I also tested with the version (7 Feb 2024 version) and got the same results.

Best regards,
Saeed

That depends on what you do in your input.

Unlikely.

I am running into the same problem.
I use the lammps binary from 21 Nov 2023.

I have rigid methane like molecules.
The inputfile: in.gcmc.sio4 (2.2 KB)
The molecule file: SiO4.txt (697 Bytes)
The input file where I try to restart:in.gcmc.sio4 (1.8 KB)
The restart files
restartfile.80000000 (937.3 KB)
restartfile.80000000.rigid (375.3 KB)

I have the same problem when restart the simulation. could you fix this?

Hi all - thanks JPBergsma for posting a set of files that reproduces the problem.

The issue is that fix rigid/small is using the mimimum_image() method in the Domain
class to do an operation that used to be OK for fix rigid/small, but now isn’t b/c the minimum_image()
method was changed to avoid problems with other use cases when with bad dynamics blew atoms out of the box to be “infinitely” far away. It had the unintended side effect that it breaks fix rigid/small when you run for a long time and a rigid body crosses the periodic boundary more
than 16 times, which is the case with JPBergsma’s files.

If any of you can re-compile LAMMPS yourself, you can change this line in src/domain.cpp
static constexpr double MAXIMGCOUNT = 16;
to a larger value, e.g. 1024, then recompile and your restart script should run.

A more robust solution will require the developers to post a new PR and then merge it into the
develop branch and do a new code release (likely sometime in the next week or two).

1 Like

I should clarify the issue is when a rigid body in the restart file is 16+ box lengths away from its starting position, not just crossed a periodic boundary 16 times, e.g. back and forth.

Personally I like this approach a lot better: Alternative `minimum_image` code by stanmoore1 · Pull Request #3721 · lammps/lammps · GitHub.

The more general fix is now available as PR #4123 using the code suggested by @stamoor

I compiled it on my computer, and it works now; the problem has been fixed.

Thanks for reporting. Please make sure you update to the next LAMMPS feature release when it becomes available to have the proper fix.

Was this merged into 29Aug2024?
I am using 29Aug2024 lammps (+colvars) and I got a similar error ERROR on proc 0: Atoms have moved too far apart (446.4371006084488) for minimum image (src/domain.cpp:1233)
Then I changed MAXIMGCOUNT = 16 to 1024 and I am not getting this anymore. I looked at the physical (within PBC) distances in the system and they seem to be fine.
I am not using fix rigid, but I have some bonds in my system.

Yes, as you can see from following the link about PR #4123 which was merged on April 5th 2024.

Bonds don’t matter for this, because the difference between image flags for bonded atoms will be rarely 1 or -1 and mostly 0. This issue, however, happens when atoms have moved very far away from their origin and need to be wrapped back without messing up their relative image flag settings.

To address that issue we need to know which style calls the regular minimum image function and instead needs to call the “big” minimum image function instead. Can you provide us with a full copy of your input? or better, can you run (without your code change) under the control of a debugger and intercep the error message on domain.cpp line 1233 and provide us with a stack trace, so we can see which class is causing the issue.

Here is it. Looks like Colvars is doing it.

...
   8000000   0.86323038     0.91676873     0.99886031
  10000000   0.91006353     0.8157675      0.91980162
terminate called after throwing an instance of 'LAMMPS_NS::LAMMPSAbortException'
  what():  ERROR on proc 0: Atoms have moved too far apart (-460.8030648351642) for minimum image
 (src/domain.cpp:1241)
Last command: run                       2000000000


Program received signal SIGABRT, Aborted.
0x00001555532a652f in raise () from /lib64/libc.so.6
#0  0x00001555532a652f in raise () from /lib64/libc.so.6
#1  0x0000155553279e65 in abort () from /lib64/libc.so.6
#2  0x00001555536e5fbe in __gnu_cxx::__verbose_terminate_handler () at /home/conda/feedstock_root/build_artifacts/gcc_compilers_1724798733686/work/build/x86_64-conda-linux-gnu/libstdc++-v3/libsupc++/vterminate.cc:95
#3  0x00001555536e4502 in __cxxabiv1::__terminate (handler=<optimized out>) at /home/conda/feedstock_root/build_artifacts/gcc_compilers_1724798733686/work/build/x86_64-conda-linux-gnu/libstdc++-v3/libsupc++/eh_terminate.cc:48
#4  0x00001555536de2ec in __cxa_call_terminate (ue_header_in=0x17d1fc0) at /home/conda/feedstock_root/build_artifacts/gcc_compilers_1724798733686/work/build/x86_64-conda-linux-gnu/libstdc++-v3/libsupc++/eh_call.cc:56
#5  0x00001555536e3e31 in __cxxabiv1::__gxx_personality_v0 (version=<optimized out>, actions=6, exception_class=5138137972254386944, ue_header=0x17d1fc0, context=0x7fffffff8eb0) at ../../../../libstdc++-v3/libsupc++/unwind-pe.h:692
#6  0x00001555554ade01 in _Unwind_RaiseException_Phase2 (exc=exc@entry=0x17d1fc0, context=context@entry=0x7fffffff8eb0, frames_p=frames_p@entry=0x7fffffff8db8) at ../../../libgcc/gthr-default.h:64
#7  0x00001555554ae3b7 in _Unwind_Resume (exc=0x17d1fc0) at ../../../libgcc/gthr-default.h:242
#8  0x0000000000853ddc in LAMMPS_NS::Domain::minimum_image(double&, double&, double&) const ()
#9  0x0000000000b27c21 in colvarproxy_lammps::position_distance(colvarmodule::rvector const&, colvarmodule::rvector const&) const ()
#10 0x00000000011c2d0a in colvarmodule::position_distance(colvarmodule::rvector const&, colvarmodule::rvector const&) ()
#11 0x000000000134f71e in colvar::distance::calc_value() ()
#12 0x000000000125d90b in colvar::calc_cvcs(int, unsigned long) ()
#13 0x00000000011f6577 in colvarproxy_smp::smp_colvars_loop() [clone .extracted] ()
#14 0x0000155553fa4d93 in __kmp_invoke_microtask () from /opt/intel/oneapi/compiler/2024.0/lib/libiomp5.so
#15 0x0000155553f11eb9 in __kmp_fork_call () from /opt/intel/oneapi/compiler/2024.0/lib/libiomp5.so
#16 0x0000155553ec9b63 in __kmpc_fork_call () from /opt/intel/oneapi/compiler/2024.0/lib/libiomp5.so
#17 0x00000000011f2646 in colvarproxy_smp::smp_colvars_loop() ()
#18 0x00000000011b3ad0 in colvarmodule::calc_colvars() ()
#19 0x00000000011b2d82 in colvarmodule::calc() ()
#20 0x0000000000b294dd in colvarproxy_lammps::compute() ()
#21 0x000000000064052d in LAMMPS_NS::FixColvars::post_force(int) ()
#22 0x00000000004957b1 in LAMMPS_NS::Modify::post_force(int) ()
#23 0x00000000006308dd in LAMMPS_NS::Verlet::run(int) ()
#24 0x0000000000574c49 in LAMMPS_NS::Run::command(int, char**) ()
#25 0x000000000041beb6 in LAMMPS_NS::Input::execute_command() ()
#26 0x000000000041a76e in LAMMPS_NS::Input::file() ()
#27 0x0000000000416c54 in main ()

I thought that was distance in parentheses, but it’s either the displacement or I am not sure what

Thanks.

Please try the following change:

  diff --git a/src/COLVARS/colvarproxy_lammps.cpp b/src/COLVARS/colvarproxy_lammps.cpp
  index dc989ad6de..265dc34f43 100644
  --- a/src/COLVARS/colvarproxy_lammps.cpp
  +++ b/src/COLVARS/colvarproxy_lammps.cpp
  @@ -204,7 +204,7 @@ cvm::rvector colvarproxy_lammps::position_distance(cvm::atom_pos const &pos1,
     double xtmp = pos2.x - pos1.x;
     double ytmp = pos2.y - pos1.y;
     double ztmp = pos2.z - pos1.z;
  -  _lmp->domain->minimum_image(xtmp,ytmp,ztmp);
  +  _lmp->domain->minimum_image_big(xtmp,ytmp,ztmp);
     return {xtmp, ytmp, ztmp};
   }
   

Yes, this did a 1h test run while as before it was failing after ~20mins.
I’ll report if it crushes at some point.
I’ve also created a pull request to fix this in the Colvars repo.