# [lammps-users] Atom variable containing positions of neighbor atoms

Dear all,

In short, I want to get positions of other atoms when defining an atom variable.

My system consists of a bunch of rigid bodies composed each of them of three aligned particles. I want to apply a force (fix add force) on each of the center (2) atoms in the direction of the axis defined by each of the back (1) and front (3) atoms.

O—O—O
1 2 3

I wonder what is the best way of doing so. I think I could do it by giving different types for the atoms (center = type 1, back = type 2, front = type 3), but I want to avoid this for other reasons.

My approach was defining atom variables that contain the position of the central particle neighbor atoms (back and front). Since particles are ordered, the central particles are 2, 5, 8, … the back particles 1, 4, 7, … and the front particles 3, 6, 9, …

Since I apply the “add force” only to the center particles, when the atom variable is evaluated, it will only contain non-zero elements for the particles in the group “centralParts”.

fix 2 centralParts addforce v_orientationsX v_orientationsY v_orientationsZ

I thought (incorrectly) that when an atom variable is evaluated I could pass an atom variable index like this,

variable backIDs atom id-1
variable frontIDs atom id+1

variable backPosX atom x[v_backIDs]
variable frontPosX atom x[v_frontIDs]

Since only the central particles will be given non-zero elements I thought there would be no problem for indexes 0 and N+1 (this may be wrong also).

But of course my approach is wrong since, as the documentation states, an atom variable cannot be passed as an index to another atom variable. But I think you can get the idea.

Is there a clean way of doing this?

Thank you very much,

Dear all,

In short, I want to get positions of other atoms when defining an atom variable.

[…]

Since only the central particles will be given non-zero elements I thought there would be no problem for indexes 0 and N+1 (this may be wrong also).

But of course my approach is wrong since, as the documentation states, an atom variable cannot be passed as an index to another atom variable. But I think you can get the idea.

Is there a clean way of doing this?

the script language in LAMMPS is deliberately not a fully developed script language as a lot of more complex operations can only be done by first synchronizing all data on a single node, which will seriously interfere with the distributed data parallelization, or may not even be possible for large systems.

the only only clean way I see would be through a custom fix.

for each local atom i you can determine its atom ID through atom->tag[i] and then get the local ids adjacent atom IDs via atom->map(atom->tag[i]+/-1). but you need to be careful that your communication cutoff is sufficiently large, or else atom->map() will return -1 if that atom would be beond, and that you are not looking at a different periodic image so you would also need to call domain->closest_image() to make certain that you get the image closest to your index i atom.

axel.