How can finds the index number of particular atoms after equilibration

Dear All

I want to calculate MSD of some atoms in a group with same atom type. For example, I have tree types of atoms like, nitrogen, carbon, oxygen. Now after equilibration, I calculate the RDF and found that the first neighbor distance from nitrogen to carbon 0.31nm and from oxygen 0.37nm. Since, all ate in a mixture, I want to calculate the carbons those have 0.31nm distance from nitrogen. Therefore, I thinking If I can, find the index of those carbons then I can make a group and calculate the MSD.

It will be very helpful if someone help how can I do it in LAMMPS

Thank you very much

Houston University