[lammps-users] i and tag[i]

When reading the codes of pair_tersoff.cpp or pair_sw.cpp, I could hardly
understand what is the relation between i and tag[i]; and j = neighs[m],
which is in the second loop embedded in i-loop, its value can be above the
number of atoms. This is quite confusing for me, can anybody who knows very well the codes explain to me how should I understand this?

Thanks and best regards!

Xiang Gu

"i" is the local atom index for the current processor that goes from 0 to nlocal (number atoms owned, in the processor domain) and tag[i] is the global unique index of the atom. Atoms with "nlocal<=i<nall" are usually ghosts (only positions communicated for force calculation, slightly outside the processor's domain). In any case nlocal or nall are not the global total number of atoms (well "nlocal=total # of atoms" if you are running on 1 proc) . You have to think "in parallel": all procs read the same code and only "see" their domain. I'm not familiar with pair_tersoff.cpp or pair_sw.cpp but I think this is how it usually work in lammps.

hope this helps,

Mihail is correct. "I" is the local index of the atom on one
processor, tag[i] is the global ID of the atom. Neighs is the
neighbor list, so neighs[m] is the local index of the Mth neighbor
of a particular atom.


Dear Mihail and Steve,

thank you for your answers. Hence, if I understand correctly, j's value, if bigger than the # of atoms, should be viewed as the image of a certain atom (say, it's index number is j0) in the original simulation cell. After some consideration and debugs I want to ask, is it correct if I use j0 = tag[j]-1 to reproduce its original index number (so that I can use x[j0][0-2] to retrieve its position ...)? Up to now all the trials I made told me this seems correct, but I want to make sure ...; and even if it is correct, is it recommended to do so if I try to modify the code according to my own requirements (I mean: such a behavior may cause other problems perhaps)?

Thanks and regards!


Unless you are running on one processor and atoms are never
deleted or created, their local indices will change over time (e.g. as
they migrate to new processors). Their global ID will never change.

Thus you cannot use the global ID to find the local index as you


Thank you so much, Steve. However may be you understood what I said. What I want to do, roughly speaking, is to locate global ID from local index. Say, now I know an atom with local index j, may be it is just a ghost atom, I want to know which atom j0 in the original cell is related to ghost atom j and find its position. Do you think x[tag[j]-1][0-2] is the position of atom j0? And this applies for all processors when doing parallel computing? If I write code in such a way in the programm, would it incur bad problems?



I don't exactly get what you are trying to do. x[tag[i]-1][] is likely to give an error on more than one processor. The local index i has global id tag[i]. you can find the ghost j's coordinates as x[j][0-2]. If you want to find which processor owns a given atom "a" (find its local index) you can use the map function of the atom class (see atom.h or the documentation for "atom_modify" command if you don't see what the map is; your atom style must be other than atomic I think).