[lammps-users] about if and variable command


I want to carry out the following function with LAMMPS’s commands:

if x> -2(an atom’s x coordinate) then y ++;

How can I do? I have code with lammps’s commands like this:

variable totaltime equal 1
variable xcoord atom x[1]
if {xcoord} > -2 then {totaltime} ={totaltime}+1 #or adding" {totaltime} =${totaltime}+1"

But It’s can’t do. if I code

variable a equal 1
if … then “print X is smaller = $a”
when it runs to if sentence, It gives
if … then “print X is smaller =$a”
print X is smaller = $a
print X is smaller = 1

then It give a error information meaning print synatax error. What’s the matter?


You can't do something like this:

\{totaltime\} ={totaltime}+1

LAMMPS input scripts are not computer code. There would
have to be a LAMMPS command that does what you want.
The closest is probably the "set" command, which allows
you to set the y coord of some atom. But I don't know if
you can do all the necessary operations inside an if statement.
Again the LAMMPS if command is not like the if statement
in C - you can't stick a bunch of other statements inside it.