About printing the number of executed timesteps before quitting lammps conditionally

Hello,

I’m trying to implement a conditional termination of lammps with if statement (see below) and print the number of executed timesteps before lammps quits.

if “a certain condition is satisfied” then &
“print ‘${#_of_executed_timesteps}’ append timesteps.txt” &
“quit 1”

However, I don’t know how to return the number of timesteps from lammps…

I wish to know if there is any built-in method or variable that allows me to print the number of executed timesteps before quitting lammps ?

I appreciate all information and suggestions that you provide.

Thank you so much in advance.

The number of timesteps and many other properties are available as custom thermodynamic properties and can be output in thermo output or explicitly defined or immediate variable expressions.

Please note that the if statement is executed immediately and not evaluated during a run (this is a common misconception). So it only makes sense to use it the way you indicate inside a loop. Otherwise you may want to look at the fix halt command.