Detect molecule fragmentation

Dear LAMMPS users and developers,

I have 2 molecules that will eventually dissociate during the simulation. I would like the simulation to print “Fragmentation” and quit when the distance between the center of mass of the 2 molecules is greater than a certain value. Here is my code:

 compute cc1 all chunk/atom molecule
 compute com all com/chunk cc1
variable distance equal  sqrt((c_com[1][1]-c_com[2][1])^2+(c_com[1][2]-c_com[2][2])^2+(c_com[1][3]-c_com[2][3])^2)

if "${distance} > 10" then "print 'Fragmentation'" & quit

However, I am getting this error:
ERROR: Variable distance: Compute used in variable between runs is not current (…/variable.cpp:1400)
Last command: ${distance

What is the issue with my code and what is the potential solutions ?
Thank you,
Rafid.

You are misunderstanding how LAMMPS processes its input commands and thus have the wrong idea what you can use the “if” command for. Also “compute” commands must be “consumed” (e.g. by a fix) or the variable that your access it from. Hence the error.

You want to look at “fix halt” instead which can provide the functionality you are looking for.

Thank you so much for your immediate reply. I tried fix halt and it worked perfectly.

I just want to expand a little bit on this question: imagine I am running 100 simulations in a loop and I want to count the number of times that fragmentation happens. By using fix halt, I get the halt message and I can manually count the number of these messages, which is tedious. However, I would like to know if there is a way to return the value of 1 if the halt command is executed. So, I can sum up these values and obtain the number of times that fragmentation happened.
Is there a command in LAMMPS that allows this ?
Thank you.

Please read the documentation of fix halt more carefully.

Also what do you mean by counting messages being tedious?
What about this?

grep "Some Message" log.lammps | wc -l

Thank you. Your response was very useful. It is much more clearer now.