Issue with keeping track of a pair distance, mismatched compute

Hi all,

My purpose is to first, calculate (or to keep track) the distance between atom ID #9 and #19 and then, assign the distance as a variable to use as a condition in a following if command.

What I did was:

variable 9_19 equal sqrt((x[9]-x[19])^2+(y[9]-y[19])^2+(z[9]-z[19])^2)

run 1000000 every 100 “if ‘{9_19} < 1.0' then 'print {Nstep}=0=1 append record.dat’”

This works until I notice that LAMMPS reports the 9_19 pair distance regardless of the Nearest Image Covention. So the distance sometimes get bigger than [(box_side)*sqrt(3)]/2, which is not expected.

My other thought is that,

group test_pair id 9 19

compute distance test_pair pair/local dist

variable 9_19 equal c_distance

run 1000000 every 100 “if ‘{9_19} < 1.0' then 'print {Nstep}=0=1 append record.dat’”

The latter solution results in an error of “ERROR: Mismatched compute in variable formula (…/variable.cpp:1548)”.

I have found that local properties cannot be assigned to equal-style variables.

So is there any way to go about this issue or, how to extract a pair distance and use it internally as a variable in an ‘if command’ condition?

I am looking forward to hearing from you. Thanks in advance.

Hi all,

My purpose is to first, *calculate* (or to keep track) the distance
between atom ID #9 and #19 and then, *assign the distance as a variable*
to use as a condition in a following if command.

What I did was:

variable 9_19 equal sqrt((x[9]-x[19])^2+(y[9]-y[
19])^2+(z[9]-z[19])^2)

run 1000000 every 100 "if '\{9\_19\} &lt; 1\.0&#39; then &#39;print {Nstep}=0=1 append record.dat'"

This works until I notice that LAMMPS reports the 9_19 pair distance
regardless of the Nearest Image Covention. So the distance sometimes get
bigger than [(box_side)*sqrt(3)]/2, which is not expected.

My other thought is that,

group test_pair id 9 19

compute distance test_pair pair/local dist

variable 9_19 equal c_distance
run 1000000 every 100 "if '\{9\_19\} &lt; 1\.0&#39; then &#39;print {Nstep}=0=1 append record.dat'"

The latter solution results in an error of "ERROR: Mismatched compute in
variable formula (../variable.cpp:1548)".

I have found that local properties cannot be assigned to equal-style
variables.

So is there any way to go about this issue or, how to extract a pair
distance and use it internally as a variable in an 'if command' condition?

​i think what you need is are unwrapped coordinates. x[] and y[] and z[]
are wrapped coordinates, so if one of them has a "jump" because the atom is
passing through a periodic boundary, you have the jumps in your distance.
now unwrapped coordinates are not available (yet) in variable expressions,
but if this concerns only two specific atoms there might be a workaround:
you can define a group for each of them, and then use the xcm() function to
get the center of mass (which is computed using unwrapped coordinates and
with only one atom in the group is equivalent to the position) and then use
that for computing your distance.

axel.

Hi all,

Thanks to Alex’s suggestion, the job is on the run for now, I’ll keep you posted with the result. I have side question on equal-style varibale, why cannot a local property, for example, a pair/local distance be assigned as a variable in case it’s a single value?

Best,

Hi all,

Thanks to Alex's suggestion, the job is on the run for now, I'll keep you
posted with the result. I have side question on equal-style varibale, why
cannot a local property, for example, a pair/local distance be assigned as
a variable in case it's a single value?

​LAMMPS doesn't know that and must not assume it.

equal style variables​ require data that is globally uniquely identifiable.
this is obvious for global system properties and for per-atom data, that is
easily possible with the atom id. for local data such a global identifier
does not exist.

axel.

​Hi all,

Regarding to my question on keeping track of one atom pair’s distance. I tried using the xcm() func​tion as below:

group 9 id 9

group 19 id 19

variable 9_19 equal sqrt((xcm(9,x)-xcm(19,x))^2+(xcm(9,y)-xcm(19,y))^2+(xcm(9,z)-xcm(19,z))^2)

print {Nstep} {9_19}

The result is that the 9_19 distance increases and surpasses the value corrsponding to a boz size of ~120 angstrom as following. Such reported distance is unexpected thus cannot be used in an if command.

100 14.8919674850164

100000 103.713384457798

120000 144.331595676238

200000 178.699195701745

400000 194.973058071275

4000000 303.640648137181

40000000 2338.88145203497

Can you help me explain how the xcm() works relating to unwrapped coordinates and will using the xcm() function result in the correct pair distance, in which the Nearest Image Conention is taken into account?

Thank you so much,

​Hi all,

Regarding to my question on keeping track of one atom pair's distance. I
tried using the xcm() func​tion as below:

group 9 id 9

group 19 id 19

variable 9_19 equal sqrt((xcm(9,x)-xcm(19,x))^2+(
xcm(9,y)-xcm(19,y))^2+(xcm(9,z)-xcm(19,z))^2)

print \{Nstep\} {9_19}

The result is that the 9_19 distance increases and surpasses the value
corrsponding to a boz size of ~120 angstrom as following. Such reported
distance is unexpected thus cannot be used in an if command.

100 14.8919674850164

100000 103.713384457798

120000 144.331595676238

200000 178.699195701745

400000 194.973058071275

4000000 303.640648137181

40000000 2338.88145203497

Can you help me explain how the xcm() works relating to unwrapped
coordinates and will using the xcm() function result in the correct pair
distance, in which the Nearest Image Conention is taken into account?

​it does not take the minimum image convention into account and it *should*
not. if you apply minimum image convention you will suddenly switch to
monitoring a *different* pair of atoms, where one of them is replaced by
its periodic image. this will also result in a discontinuity in your
monitored distance, which would be unphysical.

in conclusion, i suspect you need to think more carefully what you are
exactly looking at, and when and why you want to apply your "if statement".

axel.