`index` meaning within `PeriodicNeighbor` class

Hi, I’m trying to better frame the meaning of index in PeriodicNeighbor class of pymatgen.core.Structure.

On the documentation, I’ve read that it is referred as index (int, optional) – Index within structure… Defaults to 0. But it’s not clear yet what does that mean at a conceptual level.

If the periodic neighbor is defined within a structure, which is the expected use case, then all the sites in that structure have an index. I.e. a structure is a list of sites, and an index in that list will identify a site uniquely so long as the list is not shuffled/sorted. It’s usually easiest to identify sites this way because it is fast and convenient, but one can always backtrace to find out which site corresponds to your PeriodicNeighbor by searching for matching coordinates.

1 Like

Thanks, and could you explain to me what’s the difference between PeriodicSite and PeriodicNeighbor as well?

A PeriodicNeighbor is a sub-class of the PeriodicSite. It is the exact same but contains the index, image, and nn_distance fields as attributes for record keeping.