How site nearest neighbors can be found in `pymatgen`

I have a perplexity about how to use the different algorithms implemented within pymatgen to retrieve neighbors (connectivity) of sites within a Structure.

So first of all, if I have a Structure object and I use get_all_neighbors() method, then I return all periodic neighbors (for each site) within a certain distance and I understand that. What if instead, I want to use IsayevNN or CrystalNN modules. These two don’t have a get_all_neighbors() method, but you have to specify the index for each site… I just don’t understand how these things are related to each other, or if I’m missing anything.

hey @Federico_Ottomano,

The various NearNeighbors implementations differ in their definitions of what a neighbor is. I believe most, if not all, include a DOI for a reference paper about the method (I see 10.1038/ncomms15679 for IsayevNN, for instance), from which you can decide if it fits your use case. If you simply need all sites within a certain cutoff, get_all_neighbors() does the job.

Thanks for your answer, but at a practical level, what method should I run if I want to return all the sites using IsayevNN , if that makes sense?

It seems like IsayevNN.get_all_nn_info(structure) gives you what you want. It returns a list with structure.num_sites elements, where the nth element is a list of neighbors of site n, and each neighbor is defined as a dictionary with keys 'site', 'image', 'weight', 'site_index', 'poly_info'.

Many thanks, I don’t know why but I was only looking at the get_nn_info method for which you need to specify the index n of the site.