Sorting atoms based on their Atom ids

I am writing a custom potential for a molecule so I want to sort all the atoms in amolecule according to their Atom ids .Any idea how that can be done ?

Do you mean you already have the LAMMPS data file and you want to sort the atoms of each molecule with respect to atom ID (for example, let’s say in ascending order)?

I would do a python code :smiley:
If the data file is in style full, and A is a Nx10 array containing the information of all atoms in the simulation box, you could for example do the following:

# This will first order the information with respect to molecule ID
temporary_array = np.zeros((1,10))
for it_1 in range (0, len(A)):
    for it_2 in range (it_1 + 1, len(A)):
        if A[it_1,1] > A[it_2,1]:
            temporary_array[0,:] = A[it_1,:]
            A[it_1,:] = A[it_2,:]
            A[it_2,:] = temporary_array[0,:]

#This will now order the atoms of each molecule in ascending order with respect to atom ID.
for it_1 in range (0, len(A)):
    for it_2 in range (it_1 + 1, len(A)):
        if (A[it_1,0] > A[it_2,0]) & (A[it_1,1] == A[it_2,1]):
            temporary_array[0,:] = A[it_1,:]
            A[it_1,:] = A[it_2,:]
            A[it_2,:] = temporary_array[0,:]

Probably there are more optimal ways of doing this sorting, but I am not the person who writes most optimal python codes :monkey:

ASE can do that I suspect,

ase.io.lammps and then sorting should just be a numpy operation away