Condition during a run

Dear all,

I am interested to dump a system configuration with the least, let’s say, potential energy during an MD run. The best scheme that I could come up with to dump that configuration is below:

variable PE equal “pe”
variable Step equal “step”
variable PE_Min equal 0.0

fix 1 all nvt temp 300 300 (100.0 * dt) fix 2 all print 10 "{Step} $(v_PE:%20.16g)" screen no title “Step PE” append Thermo.histo
fix 3 all dt/reset 1 NULL NULL 0.01 units box

label LoopRun
variable N_Run loop 1000

run 1 start 0 stop 1000 post no every 1 “if ‘{PE_Min} > {PE}’ then ‘variable PE_Min equal ${PE}’ ‘write_dump all custom Output.Min id type x y z’”

next N_Run
jump ${FileName} LoopRun

Now, my question are listed below.

  1. Is there any fix or commend to implement the if condition above without using the run commend?
  2. Is it possible to mess up with the dynamics by calling run commend every step? Especially, I am concerned about using fixes like “fix dt/reset” above.
  3. The outputs in “fix print” are going to be like this:
Step PE
0 -48069.7
10 -48032.1
10 -48032.1
20 -47944.8
20 -47944.8
30 -47951
30 -47951

.
.
.

Is there anyway to prevent repletion of steps in printing?

  1. The commends above generate huge amount of outputs. Is there any way to limit the amount of outputs on screen and a log file?

Thanks and stay safe,

Reza.

please look at dump_modify thresh

Dear Axel,

I tried to play with “dump_modify thresh”. The issue is I don’t know how to check the condition at every step of MD run and update the PE_Min variable:

if ‘{PE_Min} > {PE}’ then 'variable PE_Min equal ${PE} ’

There is a refresh keyword for compute displace/atom only, but I think it is not working for other computes that I am interested in.

Is there anyway to implement the conditional statement above during an MD run?

Bests,

Reza.

the use of an “if” statement is the wrong approach. you need to use variables with logical expressions and then a fix ave/time 1 1 1 to avoid a recursive evaluation

then you can use this information to modify the dump output so that you only get a full dump with the next lowest energy.

the first part can be done like this:

variable pelow equal (pe<f_cache[1])*pe+(pe>=f_cache[1])*f_cache[1]
variable steplow equal (pe<f_cache[1])*step+(pe>=f_cache[1])*f_cache[2]
fix cache all ave/time 1 1 1 v_pelow v_steplow

after this the “pelow” variable will contain the lowest potential energy thus far and “steplow” the timestep number when this happened.
you can output this information periodically (but down have to) with fix print (not the frequency of this output doesn’t matter, fix ave/time will make sure the lowest pe info is evaluated in every step.

fix peout all print 50 “Current step: (step) Lowest energy step: {steplow} energy: ${pelow}”

with this information you can also output coordinates. since this could happen at any step, you have to set a dump frequency of 1, which would lead to huge files. but you can limit that with dump_modify thresh.

variable islow atom (v_steplow==step)
dump out all custom 1 pelow.lammpstrj id type xu yu zu

dump_modify out thresh v_islow > 0.0

now you get for every timestep only the dump header, but 0 atoms.
and if you look at the fix print output you will see the last dump frame containing atom coordinates is the step where the energy was the lowest.

for a more elegant solution, that does not produce output at all for unwanted frames, one would need to modify the source code. there is an ongoing effort to implement something like this, but that is not yet complete.

Dear Axel,

I tried to play with “dump_modify thresh”. The issue is I don’t know how to check the condition at every step of MD run and update the PE_Min variable:

if ‘{PE_Min} > {PE}’ then 'variable PE_Min equal ${PE} ’

There is a refresh keyword for compute displace/atom only, but I think it is not working for other computes that I am interested in.

that has nothing to do with this. you have to pay better attention when studying the documentation.

LAMMPS is not like a regular programming language. all of those kind of programming features are implemented as part equal and atom style variables.
but there is no real “persistent storage” for variables, it is assumed that values are computed from immediate data, and that is where fixes like fix store/state or fix ave/time come into play.

axel.

after thinking a bit more minutes about this, here is a way to reduce the output even more and output only the lowest energy configuration (for the duration of the run). no more dump and dump_modify is needed. instead the second part of the processing is done with fix store/state:

variable lowx atom (v_steplow==step)*x+(v_steplow!=step)*f_store[1]
variable lowy atom (v_steplow==step)*y+(v_steplow!=step)*f_store[2]
variable lowz atom (v_steplow==step)*z+(v_steplow!=step)*f_store[3]
fix store all store/state 1 v_lowx v_lowy v_lowz

and then, after the run you can output the stored/updated coordinates with:

write_dump all custom store.lammptrj id type f_store[1] f_store_[2] f_store[3]

for this file there is just one frame. if you compare it with the output from the previous option, you will see the coordinates are the same.
only the timestep number will not be correct (as it is the timestep where the file was created not the coordinates recorded) but you can have that information with a simple:

print “timestep: ${steplow}”

to make the file understood by visualization tools, you need to edit the ITEM: ATOMS line and replace f_store[1] with x, f_store[2] with y and f_store[3] with z.

axel.