Displace_atoms with atom-style variable

Dear LAMMPS community, I am facing a small problem regarding the “displace_atoms” command.
Currently, I am working with the 15th May 2015 LAMMPS version.

I am simulating a LJ liquid in the NVE ensemble and I have the necessity to slightly change the box size along the z direction, and to change the z positions of the atoms in the boundary regions according to a formula involving their z coordinates. I would like to use an atom-style variable for saving each atom’s displacement (according to this formula), and use it inside the “displace atom” command.
The relevant part of my input script is:

variable deltaz equal (v_DeltaZ/v_check_freq) variable displ atom (z-({z0}))/(({z1})-({z0}))*({deltaz}) run {nsteps}
change_box all z delta (-v_deltaz) {deltaz} units lattice
displace_atoms ext_region move 0 0 ${displ} units lattice

Where all the variables involved in these formulas have already been defined before in the script, and this part of the code is inside a loop (this displacement happens every ${nsteps} steps).

The part related to the “change_box” command is correctly working, while the last line is causing me some trouble.
Trying to run this simulation, I get this error:
Substitution for illegal variable
referring to the line with the “displace_atoms” instruction.

Therefore, my question is: am I allowed to use an atom-style variable in this situation? According to the online manual it seems so (“Any of the 3 quantities defining the vector components can be specified as an equal-style or atom-style variable”), but I am not able to make it work, at the moment.
Any help appreciated, thanks in advance!

Francesco Mambretti

Laboratorio di Calcolo Parallelo e di Simulazioni di Materia Condensata, Dipartimento di Fisica, Università degli Studi di Milano

Dear LAMMPS community, I am facing a small problem regarding the
"displace_atoms" command.
Currently, I am working with the 15th May 2015 LAMMPS version.

I am simulating a LJ liquid in the NVE ensemble and I have the necessity to
slightly change the box size along the z direction, and to change the z
positions of the atoms in the boundary regions according to a formula
involving their z coordinates. I would like to use an atom-style variable
for saving each atom's displacement (according to this formula), and use it
inside the "displace atom" command.
The relevant part of my input script is:

variable deltaz equal \(v\_DeltaZ/v\_check\_freq\) variable displ atom \(z\-\({z0}))/((\{z1\}\)\-\({z0}))*(\{deltaz\}\) run {nsteps}
change_box all z delta \(\-v\_deltaz\) {deltaz} units lattice
displace_atoms ext_region move 0 0 ${displ} units lattice

Where all the variables involved in these formulas have already been defined
before in the script, and this part of the code is inside a loop (this
displacement happens every ${nsteps} steps).

The part related to the "change_box" command is correctly working, while the
last line is causing me some trouble.
Trying to run this simulation, I get this error:
Substitution for illegal variable
referring to the line with the "displace_atoms" instruction.

Therefore, my question is: am I allowed to use an atom-style variable in
this situation? According to the online manual it seems so ("Any of the 3
quantities defining the vector components can be specified as an equal-style
or atom-style variable"), but I am not able to make it work, at the moment.
Any help appreciated, thanks in advance!

the problem seems to be, that you are not considering, that there are
two *different* ways of accessing a variable.
you are only using *immediate* expansions (using ${name}) which will
translate variables to text and then feed LAMMPS that expanded line.
you can see those expansions when you run LAMMPS with -echo screen.
this is totally transparent to the individual LAMMPS commands.

for atom style variables, this doesn't make sense, and in any case
when the LAMMPS documentation mentions that a command accepts a
variable, it means that you can provide a variable *reference* in the
form v_name. this reference will not be immediately expanded, but
evaluated whenever the corresponding command references it internally,
i.e. in case of a fix repeatedly during a simulation.

so i suggest you re-read the documentation of the variable command
with this information in mind, and you should be able to figure out
how to do what you want to do.

axel.

I’ve re-read the documentation and changed my script according to what I’ve understood, but now I get a different error.
My new input script is like:

variable deltaz equal $(v_DeltaZ/v_check_freq)
variable displ atom (z-(${z0}))/((${z1})-(${z0}))*(${deltaz})
run ${nsteps}
change_box all z delta $(-v_deltaz) ${deltaz} units lattice
displace_atoms ext_region move 0 0 v_displ units lattice

And now the output (with -echo screen option) is:
displace_atoms ext_region move 0.0 0.0 v_displ units lattice
Displacing atoms …
ERROR: Expected floating point parameter in input script or data file (…/displace_atoms.cpp:94)… when it arrives to the last line.
Why? What am I missing again?
Thanks in advance,

Francesco

I've re-read the documentation and changed my script according to what I've
understood, but now I get a different error.
My new input script is like:

variable deltaz equal \(v\_DeltaZ/v\_check\_freq\) variable displ atom \(z\-\({z0}))/((\{z1\}\)\-\({z0}))*(\{deltaz\}\) run {nsteps}
change_box all z delta \(\-v\_deltaz\) {deltaz} units lattice
displace_atoms ext_region move 0 0 v_displ units lattice

And now the output (with -echo screen option) is:
displace_atoms ext_region move 0.0 0.0 v_displ units lattice
Displacing atoms ...
ERROR: Expected floating point parameter in input script or data file
(../displace_atoms.cpp:94)... when it arrives to the last line.
Why? What am I missing again?

that you probably checked the online documentation, which always
describes the latest patchlevel of LAMMPS, while you seem to be using
a version of LAMMPS that predates the implementation of variable
support in displace atoms.

you can see the history of (significant) changes here:
http://lammps.sandia.gov/bug.html and the links to the history of
previous years.
in your case, check out http://lammps.sandia.gov/bug2015.html around october.

axel.