Positions of atoms in the neighbor list

Dear LAMMPS developers,

I have been dealing with a problem of finding the most nearest neighbor(with a specific atom type) of an atom in a 2D system. I found this very helpful example 2.3.10. Neighbor list access — LAMMPS documentation from the documentation and I think it prints the neighbor list for each atom where the neighbors can be anywhere(irrespective of atom type) within a cutoff distance.

As per my understanding, for an atom with a local-id, the printed information shows the number of neighbors it has within the cutoff distance and each of those neighbor’s ‘atom-count number’ with it’s local-id. Since some of the neighbor atoms can be the periodic replicas of local atoms, their neighbor ‘atom-count number’ can go beyond the (total number of local atoms-1), otherwise, (local id-1) in python. Please correct me if I misunderstood.

What would be the best way if I want to classify this neighbor list based on the atom type and sort it by the distance between them to the center atom, so as to get the most nearest neighbor of a specific atom type. I think, it will be enough if I could print the positions of the neighbors in the neighbor list. Please help me to understand how to get these positions.

Thank you so much for reading about my problem. I hope I made my explanation clear.

The output of the example:
NeighLists.html (612.5 KB)

There is no such thing as a “local id”. Within LAMMPS each MPI process has a list of atoms and thus lists of per-atom properties. This list contains the “local” atoms first, i.e. atoms that are “owned” by the MPI process, followed by “ghost” atoms, i.e. atoms that are copies from neighboring subdomains. Generally, only some basic properties (type, position, ID, molecule ID) are available and updated for “ghost” atoms (e.g. velocities are not unless comm_modify vel yes is used, forces will only be correct for “local” atoms and so on).

A neighbor list has one entry for each “local” atom which is a list of the indices of the atoms that are its neighbors based on the neighbor list cutoff settings (usually largest cutoff plus neighbor skin). Care needs to be taken when you have a molecular system, then the topmost two bits will be set for all “special_bonds” neighbors, i.e. the index will be much larger than the number of local plus ghost atoms. The value of those two bit integer (after applying a bitmask and bitshift) determines whether an atom is: 0 = not a “special” neighbor, 1 = a 1-2 neighbor, 2 = a 1-3 neighbor, 4 = a 1-4 neighbor. So to get the real index a bitmask needs to be applied or else you may get a segmentation fault when accessing per-atom data.

Please note the line:

tags = lmp.extract_atom('id')

Which gives you access to the per-atom property of the (global) atom ID. You can access other per-atom properties like type or position the same way.
Please note

Dear Axel,

Thank you so much for the explanation for my better understanding. From your suggestion, I got the positions of the neighbor atoms now using the extract_atom(‘x’) command.