Hello readers
I have extracted a material from material project using pymatgen and created a supercell.
struct = MPRester(API_KEY).get_structure_by_material_id(‘mp-1183751’, conventional_unit_cell=True)
struct.make_supercell((3,3,3))
struct
OUTPUT
Lattice
- abc : 10.543851 10.543851 10.543851*
- angles : 90.0 90.0 90.0*
- volume : 1172.1893742428667*
-
A : 10.543851 0.0 6.45624668891831e-16*
-
B : 1.695580560791565e-15 10.543851 6.45624668891831e-16*
-
C : 0.0 0.0 10.543851*
PeriodicSite: Co (0.0000, 0.0000, 0.0000) [0.0000, 0.0000, 0.0000]
PeriodicSite: Co (0.0000, 0.0000, 3.5146) [0.0000, 0.0000, 0.3333]
PeriodicSite: Co (0.0000, 0.0000, 7.0292) [0.0000, 0.0000, 0.6667]
PeriodicSite: Co (0.0000, 3.5146, 0.0000) [0.0000, 0.3333, 0.0000]
PeriodicSite: Co (0.0000, 3.5146, 3.5146) [0.0000, 0.3333, 0.3333]
PeriodicSite: Co (0.0000, 3.5146, 7.0292) [0.0000, 0.3333, 0.6667]
I need to use the coordinates to Kdtree algorith from scipy to identify the closest points.
kdtree script
import numpy as np
from scipy.spatial import KDTree
import matplotlib.pyplot as plt
*a = np.random.rand(15,2)8+1
*b = np.random.rand(15,2)8+1
t1 = KDTree(a)
t2 = KDTree(b)
c1=t1.query_ball_tree(t1,1)
c2=t2.query_ball_tree(t2,1)
c3=t1.query_ball_tree(t2,1)
print(c3)
fig,ax = plt.subplots(1,2)
*ax[0].scatter(a.T, s=5, color=‘k’)
*ax[0].scatter(b.T, s=5, color=‘r’)
*ax[1].scatter(a.T, s=5, color=‘k’)
*ax[1].scatter(b.T, s=5, color=‘r’)
for n1,p in enumerate(c1):
- for n2 in p:*
-
ax[1].plot(*np.vstack((a[n1],a[n2])).T, color='k')*
for n1,p in enumerate(c2):
- for n2 in p:*
-
ax[1].plot(*np.vstack((b[n1],b[n2])).T, color='r')*
for n1,p in enumerate(c3):
- for n2 in p:*
-
ax[1].plot(*np.vstack((a[n1],b[n2])).T, color='g')*
plt.show()
but unfortunately, I am stuck how to use the output from pymatgen to kdtree as it is not in array format.
Any help related to this would be of great help.