Conditional end

Hello,

I have a simple question about Lammps: how to insert a conditional end of the run, depending on the value of a structural variable (in this case a number of molecules in a slit). I need to stop the run and print out essential results when certain slit occupancy is reached. Does anyone know of a simple way to do this? Could it be done in the input script of lammps? My understanding is that there is a limit to the ‘if’ statements possible in the run command.

I already have the number of molecules in a particular region printed out into the thermo results. When the value changes by 20% I need the run to stop, save the dump, start a new identical run, then save a different dump file. Please let me know if you have any insight.

Thank you,
Josh

Hello,

I have a simple question about Lammps: how to insert a conditional end of
the run, depending on the value of a structural variable (in this case a
number of molecules in a slit). I need to stop the run and print out
essential results when certain slit occupancy is reached. Does anyone know
of a simple way to do this? Could it be done in the input script of lammps?
My understanding is that there is a limit to the 'if' statements possible in
the run command.

I already have the number of molecules in a particular region printed out
into the thermo results. When the value changes by 20% I need the run to
stop, save the dump, start a new identical run, then save a different dump
file. Please let me know if you have any insight.

it is usually *much* simpler and easier to simply continue the
simulation beyond that point and then just determine from the log
file, which frame was the frame you should have stopped and then
restart from there.

axel.

Or you could use a loop to split your long simulation into many short
simulations. In every iteration, test for the condition and quit.

http://lammps.sandia.gov/threads/msg35144.html

http://lammps.sandia.gov/doc/jump.html
http://lammps.sandia.gov/doc/label.html
http://lammps.sandia.gov/doc/next.html

http://lammps.sandia.gov/threads/msg28591.html

As far as starting new simulations with new dump files, perhaps this
can be done within a LAMMPS for-loop. (I've had some success
restarting LAMMPS simulations in a loop, but I remember it was a
little bit tricky. Each time you restart the simulation, you would
probably want to invoke "clear" command. Then you have to
re-initialize the system from scratch again, using read_data if
applicable, resetting the force-field styles and coeffs, reset the
thermo and dump settings, and changing the name of the dump file to
avoid overwriting it.
http://lammps.sandia.gov/doc/clear.html)

...However, if that turns out to be messy or difficult, perhaps you
could do this outside of LAMMPS with a bash for-loop? (In other
words, a bash-script containing a for-loop which invokes LAMMPS.
After LAMMPS is finished (for whatever reason), the bash-script
invokes LAMMPS again in another directory, which it generates, for
example.)

I hope this helps.
Andrew

I’ll add just a bit to Andrew’s answer.
The run every command can’t be used to
invoke an “if” test every N steps and exit the
loop. See the IMPORTANT NOTE on the run
doc page about it.

But Andrew’s idea will work. Simply use the
if and jump commands, with a run N inside the loop,
and the if test after it. So long as you can write
a variable to test the value of, you can break out
of the loop easily.

Note that the variable has to be able to be
evaluated with its current value outside
of a run. If LAMMPS gives an error, then
a simple way to do this is include the variable
in thermo output, which will get evaluated on
the last timestep of each small N-length run.

Steve

here is an example of logic that will exit a long
run (executed in chunks of 1000 steps), when a condition
is met, in this case the temperature falls below some value

variable myTemp equal temp
label loop
variable a loop 1000
run 1000
if “${myTemp} < 300.0” then “jump SELF break”
next a
jump SELF loop
label break
print “ALL DONE”

Steve