If...then quit statement

Dear LAMMPS users,

My plan is to set up a run that terminates when one atom reaches a point in the z-coordinate (as it is only moving along this axis).
Now i have a variable, say z that has the data for coordinates.
Having read the LAMMPS documentation, I do this as follows:

run 2000 every 1 "if '$z > 10' then quit"

This seems to work, but I would like to know if there is a better way of optimising this- maybe say writing the output in a file first before terminating the script, or perhaps saving the configuration in a restart file before quitting LAMMPS, such that I could run another simulation straight after the first script is aborted?

Thank you very much in advanced,

Anna Lappala

You can define a loop.
If you want to run a simulation for 2000 steps, and check for (z>10)
every 20 steps, then you could try something like this:
---------- loop example --------------
variable nrebond loop 100
   label loop
   run 20

   write_restart latest_snapshot.rst
   # you can add more commands here if you like.
   # you can even invoke external shell commands
   # and load the files created by them

   if '$z > 10' then quit

   next nrebond
   jump SELF loop

You can also put multiple commands in the "then"
part of an if statement. E.g. a write_restart, followed
by a quit.

Steve