How to map Atom Number or Atom ID

Hi every,
Now I want to get neighbor list. By PyLammps, I can do this and extract Atom ID of Atom Number in neighbor list. However, I need to use the loop to extract each atom, it takes a long time. I want to know there is any way to map Atom Number to Atom ID?
Thank you very much.
The code to extract atom id in neighbor list is below.

from lammps import lammps
import numpy as np

lmp = lammps()
lmp.commands_string(“”"
region box block -2 2 -2 2 -2 2
lattice fcc 1.0
create_box 1 box
create_atoms 1 box
mass 1 1.0
pair_style lj/cut 2.5
pair_coeff 1 1 1.0 1.0
run 0 post no"“”)

look up the neighbor list

nlidx = lmp.find_pair_neighlist(‘lj/cut’)
nl = lmp.numpy.get_neighlist(nlidx)
tags = lmp.extract_atom(‘id’)
print(“half neighbor list with {} entries”.format(nl.size))

print neighbor list contents

for i in range(0,nl.size):
idx, nlist = nl.get(i)
print(“\natom {} with ID {} has {} neighbors:”.format(idx,tags[idx],nlist.size))
if nlist.size > 0:
for n in np.nditer(nlist):
print(" atom {} with ID {}".format(n,tags[n]))

What exactly do you mean by that and what is the relation to the code below.

P.S.: the code is not quoted correctly and thus not easily readable. You need to use triple backquotes (```) instead of the greater sign (>).

Hi Akohlmey,
In PyLammps, I can get neighbor list but the result is series of numbers which are Atom Number. By, command extract_atom(‘id’), I can get Atom ID according to Atom Number. But by that way, I need to use loops to extract each atom number in neighbor list. So it takes a long time. I want to know how to convert Atom Number to Atom ID directly? For instance, Lammps’s algorithm is used to assign Atom Number and Atom ID.
Simple example: Atom Number= [0,1,2,3] and corresponding Atom ID =[4,5,1,4].
The code I used to extract Atom ID like example code from LAMMPS 2.3.10. Neighbor list access — LAMMPS documentation

You are still not making any sense here. The array you get from extract_atom(‘id’) is that map you are talking about. The code you quoted (and still haven’t fixed its formatting!) is using that information directly.

But all per-atom data is indexed by the index used in the neighbor list, and this is necessary to use because some of the ghost atoms may have the same atoms may have the same atom ID as one of the local atoms. I cannot think of any way how you would need this information presented differently.

So what is it exactly that you want to achieve?
Can you give an example and show a piece of code that uses the data in the “slow” way that you are concerned about?
I suspect that there are some problems on your side not understanding the fundamentals of the data model and parallelization of LAMMPS with the domain decomposition. Have you studied the recent paper describing LAMMPS? or at least read through this section of the LAMMPS manual: 4.4. Parallel algorithms — LAMMPS documentation?

For example: I have an array consisting 10 elements whose values are Atom Number (D=[0,1,2,3…,9]. Now I want to know corresponding Atom ID of each Atom Number? I used command ‘extract_atom(‘id’)’ to extract Atom ID of each Atom Number in the array. So if the number of element in the array increase, the time also increases.
Below is a piece of my code to get neighbor list:

from lammps import lammps
import numpy as np 
lmp = lammps()

##############################
# Get neighbor list at timestep 0
lmp.command('units real')
lmp.command('dimension 3')
lmp.command('boundary p p p')
lmp.command('atom_style atomic')
lmp.command('read_data input_data_9.txt')                                                   ###########################
lmp.command('velocity all create 100 12345 ')         
lmp.command('pair_style lj/cut 10.')
lmp.command('pair_coeff * * 0.239 3.4 10.')          
lmp.command('neighbor 0.0 bin')
lmp.command('neigh_modify every 1 check yes ')
lmp.command('timestep 1.0 ')
lmp.command('fix 1 all nvt temp 100.0 100.0 100.0 ')
lmp.command('run 0')

######################################
# NEIGHBOR LIST
nlidx = lmp.find_pair_neighlist('lj/cut')      
nl = lmp.numpy.get_neighlist(nlidx)             
id = lmp.extract_atom('id')     

pos = lmp.extract_atom('x') 
force = lmp.extract_atom('f') 

pos_lst = np.zeros((nl.size,3))           
force_lst = np.zeros((nl.size,3))         Z 

src_node_lst = []
dst_node_lst = []

for i in range(nl.size):
    idx, nlist = nl[i]

    atom_id = id[idx]
    [pos[idx][0], pos[idx][1], pos[idx][2]]
    # insert position
    pos_lst[atom_id-1] = [pos[idx][0], pos[idx][1], pos[idx][2]]

    # insert force
    force_lst[atom_id-1] = [force[idx][0], force[idx][1], force[idx][2]]

    # calculate neighbor list
    if nlist.size >0:
        src_atom = np.full((nlist.size,), atom_id).tolist()
        dst_atom = []
        for atom in np.nditer(nlist):
            dst_atom.append(id[atom])    
        src_node_lst += src_atom
        dst_node_lst += dst_atom

np.savez('./data/data_9_0.npz', pos = pos_lst, force = force_lst)                                           ###########################
np.savez('./neighbor/neigh_9_0.npz', src_node = src_node_lst, dst_node = dst_node_lst)                      ###########################

Now why is this a surprise? This is how things work in computing: when you have a bigger problem, you have more work and thus it takes longer.
The way how you extract properties is the way you do it. The only thing that might help would be to extract “id”, “pos”, and “force” as numpy arrays instead of regular python lists via ctypes.

Please also keep in mind that the major time consumer is the part where you copy the neighbor list contents. For larger systems, this becomes large and since Python is about 100 times slower than C++ code of the same kind, things are bound to be slow. Writing out and compressing the data also is going to slow down things a lot.

Yes. I know. Thank you for your comments.
I just want to ask that there is any other ways to get Atom ID from Atom Number instead of using command “extract_atom(‘id’)”?
Thank you very much.

No.

Let me emphasize, it is not the access to the Atom->tag array that slows you down.
It is the process of collecting, reordering, and converting a massive amount of data with python that is slow.

Yes, Thank you for your answers.