[lammps-users] trimming the full neighbor list

Hello,

I've noticed that pair styles that make use of a full neighbor list (e.g. Tersoff) use the following lines to skip half of it:

// two-body interactions from full neighbor list, skip half of them
if (itag > jtag) {
if ((itag+jtag) 2 == 0\) continue; \} else if \(itag < jtag\) \{ if \(\(itag\+jtag\) 2 == 1) continue;
} else { //itag==jtag -> they are the same particle (j is a ghost)
if (x[j][2] < ztmp ) continue;
if (x[j][2] == ztmp && x[j][1] < ytmp ) continue;
if (x[j][2] == ztmp && x[j][1] == ytmp && x[j][0] < xtmp) continue;
}

There are two things unclear to me:

1) the advantage of using the if..else-if with the "% 2" instead of a simple
if (itag > jtag) continue;

2) the reason of the "else" condition: why would we want the interaction of an atom with a ghost of itself?

Thank you for any reply,
Roberto

Hello,

I’ve noticed that pair styles that make use of a full neighbor list
(e.g. Tersoff) use the following lines to skip half of it:

// two-body interactions from full neighbor list, skip half of them
if (itag > jtag) {
if ((itag+jtag) 2 == 0) continue; } else if (itag < jtag) { if ((itag+jtag) 2 == 1) continue;
} else { //itag==jtag -> they are the same particle (j is a ghost)
if (x[j][2] < ztmp ) continue;
if (x[j][2] == ztmp && x[j][1] < ytmp ) continue;
if (x[j][2] == ztmp && x[j][1] == ytmp && x[j][0] < xtmp) continue;
}

There are two things unclear to me:

  1. the advantage of using the if…else-if with the “% 2” instead of a simple
    if (itag > jtag) continue;

load balancing.

consider a system with only two adjacent subdomains and without periodic boundaries:
for each you have the index in the range [0,nlocal), and j in the range [0,nlocal+nghost).
while the range [0,nlocal) are atoms with different tags between the two subdomains,
the range [nlocal, nlocal+nghost) are atoms that are local on one subdomain and ghosts on the other.
you also want to evenly split these pairs between the two subdomains, so that when running in parallel
both subdomains have to do about the same amount of work. specifically at the beginning of a run and for solids where there is no diffusion,

chances are high that the tags are sorted by location and thus all or most of the tags of the atoms in the first
subdomain would be smaller than the tags of the atoms in the second. please keep in mind that this construct is used for pair styles that require newton for pairs to be on.

if you have periodic boundaries and more subdomains, things are a bit more complex, but the principle remains the same.

  1. the reason of the “else” condition: why would we want the interaction
    of an atom with a ghost of itself?

periodic boundary conditions.

Due to using domain distribution for MPI parallelization, you need a copy of (some) atoms from the neighboring sub-domain, AKA ghost atoms.
if there is only one subdomain those ghost atoms are copies of the same subdomain (from the other “side” of the box).
if the (communication) cutoff is large compared to the size of the subdomain, there may even be multiple copies. because of how LAMMPS is doing this, it is not subject to minimum image conventions (and you don’t see those applied when using the neighbor list). the only exception I know is pair style list (which does not use a neighborlist at all and is built to handle interactions of pairs with very large distances). if you have the same tag for a pair of atoms, you need to find a different way to get the even split (and consistently so) thus you decide based on the z coordinates, if those are the same then on the y coordinates, and if those are the same, too, on the x coordinates. all 3 coordinates cannot be the same as that would mean the particles are on top of each other, but that could only happen if both were local; if one is a ghost it has to be different in at least one of x, y, or z.

HTH,
axel.

Thank you, very clear That was clear. My doubt was about the physical reason of considering forces between an atom and itself. I think the answer is that these are many-body potentials, and in general to evaluate also energy and pressure. However, now it’s clearer, sorry for the trifle… Thank you, Roberto

That was clear. My doubt was about the physical reason of considering forces between an atom and itself.

sorry, but it is not the interaction between an atom and itself, but the interaction with an atom and one of its periodic replica.

I think the answer is that these are many-body potentials, and in general to evaluate also energy and pressure.

this has nothing to do with many-body potentials. the selection is done in the neighbor list code for constructing half neighbor lists.

let us assume you have a very large box and you increase the cutoff for a model using a simple pairwise attractive potential (for large distances), say Lennard-Jones or Morse, the potential energy will decrease continually for as long as there are significant energy contribution within the precision of floating point numbers. This is what is computed and added to the potential energy with “pair_modify tail yes”.
you want the same behavior also for periodic boundaries and the case of smaller boxes. as I already mentioned, for LAMMPS you can go beyond minimum image conventions and still get correct results, i.e. you can have a cutoff larger than half the box.

Axel.

yes indeed, but in terms of forces, +F and -F will be applied on the same atom I agree, as I said it is needed to evaluate energy and pressure my only concern was the redundancy of applying +F and -F on the same atom… Best, Roberto

[…]

my only concern was the redundancy of applying +F and -F on the same atom…

your number of pairs grows with O(r_cut**3). thus for a large cutoff having one more pair doesn’t matter.

axel.