Using the write_restart command in a loop deletes stored compute values

To LAMMPS users,

I need to calculate the bonds between two atoms in a simulation. However, I want the simulation to automatically write a restart file once the bond length reaches a certain value and then continue until certain other criteria are met (see below).

I currently use the following lines to calculate the bond between the two atoms specified by the group "dw":

compute bond_length dw pair/local dist #computes the bond distance between these two atoms
compute order all reduce ave c_bond_length #this produces a scalar output which can be used in the variable command
variable OP equal c_order

Further down in my LAMMPS input script I use loop/jump and run individual MD time steps in each turn of the loop as shown below:

To LAMMPS users,

[...]

Is there any way for me to write this restart file with this input script setup but not have it affect the simulation as it seems it is doing?

I undertand that I may be stretching LAMMPS capabilities with using such a loop and running individual time steps. However, for the problem I am trying to solve, LAMMPS needs to be able to write restart files as well as stop on-the-fly according to certain specified thresholds.

perhaps it may be helpful to look at this problem from a different
perspective: what is it in the restart files that has to be different?
is it only the atom positions and/or velocities?

if yes, you can achieve the same effect by writing a restart at the
beginning of your run and then only write out suitable dump files. to
restart you would then use read_restart followed by read_dump. to make
things easier, i have code for a "write_dump" command that allows to
write out a "one-shot" dump file similar to how write restart works.
however, this will avoid all the overhead and setup associated with
writing restarts.

axel.

I don’t see precisely what you are trying to do, but
I wouldn’t try it all in one loop.

If you simply replace a “run” command with this construct:

first run

label startrun
run 1 pre no post no
if “condition involving a variable” then “jump SELF endrun”
jump SELF startrun

label endrun
write_restart tmp.restart

continue the run

then there should be no restriction on what further commands
you add at the end to continue the run. If they involve
another test on the variable, then so long as the variable
is “current” it should work. And there are many ways to
make the variable “current”, as outlined on the variable doc
page, e.g. do a run 0, or insure it was used with thermo output
at the end of the first run.

Steve