[lammps-users] unwrapped position

dear users

i can find wrapped coordinate of atom 1 using x[1] but how can i access to unwrapped coordinates of a given particle? because xu[1] doesn’t work!


There is not enough context information here to give an informed answer without making guesses. Can you elaborate some more? Especially, what is the distinction you are making between an “atom” and a “particle”? And provide a simple example for demonstration?


sorry i mean atom and particle are same.

for an example in the following loop i want to write unwrapped position coordinates of atom 1 to a data file each 10 steps. if i’d use wrapped coordinates (x[1], y[1], z[1]) works but for unwrapped coordinates it reports error.

label loop
variable i loop 1 1000000
run 10
variable posx equal xu[1]
variable posy equal yu[1]
variable posz equal zu[1]
print “{i} {posx} {posy} {posz}” append data.dat
next i
jump SELF loop

where does it say in the documentation for the variable command, that it supports a xu, yu, or zu keyword to access?
all functionality in LAMMPS that is available for use is documented. so you cannot just make something up because a similar keyword exists elsewhere and hope that it works. it will not.

…and anyway, why such a complex construct? why not simply use a custom dump on a group containing the atoms you want to track? that one does support writing out unwrapped coordinates, is simple to use and has minimal overhead.

when doing a loop, you have the overhead of re-initializing the forces with every “run” command (unless you use the “pre no” option) and overhead of printing a timing summary output (unless you use the “post no”) and the overhead of a collective operation copying the atom coordinates when accessing them from an equal style variable. furthermore, there is no need to redefine equal style variables, anyway, so that is additional unnecessary work. the dump command is optimized for outputting per-atom data and if the format doesn’t suit you, it is much easier (and much faster, too) to write a little script reformatting the output than doing overly complex LAMMPS input scripting.

that all said, there is a way to access unwrapped positions when you use “compute property/atom”, but since you cannot easily access data from computes in between runs, you also need to cache those with a fix ave/atom command. so an optimized and corrected version of your script code would be something like this:

compute 1 all property/atom xu yu zu
fix 0 all ave/atom 1 1 10 c_1[1] c_1[2] c_1[3]
variable posx equal f_0[1][1]
variable posy equal f_0[2][1]
variable posz equal f_0[3][1]

label loop
variable i loop 1 100
run 10 pre no post no
print “{i} {posx} {posy} {posz}” append data.dat
next i
jump SELF loop

nevertheless, this is just to demonstrate that when following the manual, that operation is possible. it is still strongly recommended to use the dump command to output (unwrapped) coordinates.


thank you so much for the your useful comments and guides.