Which one is the correct "site_index"?

Hi,

I am using the following code to extract the number of nearest neighbors using minimum distance method.

crystal = Structure.from_file(“name.cif”)

MD = MinimumDistanceNN(tol=0.1, cutoff=6.0, get_all_sites=True).get_nn_info(crystal, 1)

which gives me the following list:

[{‘site’: PeriodicSite: C (5.6851, 4.9066, 23.9859) [-0.8629, 0.9999, 0.7204], ‘image’: (-1, 0, 0), ‘weight’: 5.68586621, ‘site_index’: 0}, {‘site’: PeriodicSite: C (-0.0008, -0.7793, 23.9859) [0.1371, -0.0001, 0.7204], ‘image’: (0, -1, 0), ‘weight’: 5.68586621, ‘site_index’: 0}, {‘site’: PeriodicSite: C (11.3710, -0.7793, 23.9859) [0.1371, 1.9999, 0.7204], ‘image’: (0, 1, 0), ‘weight’: 5.6858662099999995, ‘site_index’: 0}, {‘site’: PeriodicSite: C (5.6851, -6.4651, 23.9859) [1.1371, 0.9999, 0.7204], ‘image’: (1, 0, 0), ‘weight’: 5.68586621, ‘site_index’: 0}, {‘site’: PeriodicSite: O (5.6851, 4.9066, 25.1859) [-0.8629, 0.9999, 0.7564], ‘image’: (-1, 0, 0), ‘weight’: 5.8111164445624395, ‘site_index’: 1}, {‘site’: PeriodicSite: O (-0.0008, -0.7793, 25.1859) [0.1371, -0.0001, 0.7564], ‘image’: (0, -1, 0), ‘weight’: 5.8111164445624395, ‘site_index’: 1}, {‘site’: PeriodicSite: O (5.6851, -0.7793, 25.1859) [0.1371, 0.9999, 0.7564], ‘image’: (0, 0, 0), ‘weight’: 1.1999999059350976, ‘site_index’: 1}, {‘site’: PeriodicSite: O (11.3710, -0.7793, 25.1859) [0.1371, 1.9999, 0.7564], ‘image’: (0, 1, 0), ‘weight’: 5.811116444562439, ‘site_index’: 1}, {‘site’: PeriodicSite: O (5.6851, -6.4651, 25.1859) [1.1371, 0.9999, 0.7564], ‘image’: (1, 0, 0), ‘weight’: 5.8111164445624395, ‘site_index’: 1}, {‘site’: PeriodicSite: Al (2.8422, -0.7793, 22.2539) [0.1371, 0.4999, 0.6684], ‘image’: (0, 0, 0), ‘weight’: 3.3290042116900906, ‘site_index’: 2}, {‘site’: PeriodicSite: Al (8.5280, -0.7793, 22.2539) [0.1371, 1.4999, 0.6684], ‘image’: (0, 1, 0), ‘weight’: 3.3290042116900898, ‘site_index’: 2}, {‘site’: PeriodicSite: Al (5.6847, -0.7784, 19.4432) [0.1369, 0.9998, 0.5840], ‘image’: (0, 0, 0), ‘weight’: 4.542710059301281, ‘site_index’: 5}, {‘site’: PeriodicSite: Se (4.3750, 0.6649, 20.9536) [-0.1169, 0.7694, 0.6293], ‘image’: (-1, 0, 0), ‘weight’: 3.605193398332698, ‘site_index’: 9}, {‘site’: PeriodicSite: Se (10.0608, 0.6649, 20.9536) [-0.1169, 1.7694, 0.6293], ‘image’: (-1, 1, 0), ‘weight’: 5.516174271152079, ‘site_index’: 9}, {‘site’: PeriodicSite: Se (4.3750, -5.0210, 20.9536) [0.8831, 0.7694, 0.6293], ‘image’: (0, 0, 0), ‘weight’: 5.37622682531896, ‘site_index’: 9}, {‘site’: PeriodicSite: Se (7.0002, 3.4666, 20.9499) [-0.6097, 1.2312, 0.6292], ‘image’: (-1, 1, 0), ‘weight’: 5.382813848581894, ‘site_index’: 10}, {‘site’: PeriodicSite: Se (1.3143, -2.2193, 20.9499) [0.3903, 0.2312, 0.6292], ‘image’: (0, 0, 0), ‘weight’: 5.513196678545521, ‘site_index’: 10}, {‘site’: PeriodicSite: Se (7.0002, -2.2193, 20.9499) [0.3903, 1.2312, 0.6292], ‘image’: (0, 1, 0), ‘weight’: 3.60843555189817, ‘site_index’: 10}]

I would like to find out which site in my structure each atom in the above list corresponds to. To this end, I thought of using “site_index”. However, since some of the atoms are in the adjacent periodic cell /image, their corresponding indices don’t exist in my structure. Even for the atoms that are inside the unit cell and not in the adjacent cells, I could not identify them because the “site_index” here is confusing.

what is the relation between “site_index” in the above list and the following list named “INDS” extract using the below code:

INDS = []

for i in range(len(crystal.species)):
INDS.append(i)

INDS: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

In particular, I am wondering to which atom/site in the INDS list the site_index = 2, for example, in the neighbors list corresponds to.

Your help is greatly appreciated!

Hi @moka,
So, the site_index is in fact the index of the atom from the original structure you defined in your crystal variable. Even if that atom belongs to a neighboring cell, the site_index refers to the index of the equivalent atom in the original unit cell of crystal.
For example, site_index: 2 refers to crystal[2].
Is that answering your question?
-Peter

Hi Peter,

Thanks much for your quick response. It was a great help.

I have another question: are the neighbors are sorted based on their proximity/distance to the center atom? Lets say if I want to take the first 6 closest neighbor atoms to the center atom, will taking the first six from the list be enough?

Thank you!

No, the list is not sorted based on distance. However, the distances are stored under the weight entries. One option would be to sort the list: sorted(MD, key = lambda i: i['weight']) or you just decrease the cutoff until your MD list is less than 7 entries long.
Also, keep in mind the case where the 6th closest atom and the 7th closest atom have the exact same distance from the center atom. Hence, instead of restricting the number of nearest neighbors, I’d rather restrict the cutoff value.
-Peter

PS: You can remove the tol=0.1 tag because it is ignored when you set get_all_sites=True.

Hi Peter,
Thanks much again for your time!

1 Like