Hi Nishant,
I think you can use the function in pymatgen.core.structure
: get_neighbors(site, r)
to get all the closest atom. Then you can get all the connected sites.
If you want to do it by yourself, here’s a function which can also do the trick:
def connectedMatrix(struct_pmg, bond_length):
import numpy as np
cM = {} # connected Matrix
for ind1, site1 in enumerate(struct_pmg):
nameStr = site1.specie + str(ind1)
cM[nameStr] = []
for ind2, site2 in enumerate(struct_pmg):
if ind != ind2 and np.linalg.norm(site1.coords - site2.coords) <= bond_length:
cM[nameStr].append(ind2)
return cM
You need to choose the bond_length that you want, also you can modify it to choose the desirable bond angle.
The output is like this:
cM = {
'Pt0': [1, 3, 5] # just an example
}
Once you have the connected matrix, you can still doing the loop, but now you can check whether the two atoms are connected or not, this will help you only find all the connected sites.
if you have any issues, please do tell.
Best,
Zhengda