I am new to python and numpy. I can generate cartesian coordinate of atoms. e.g. (CuO)n
I would like to calculate interatomic distance (Euclidean distance) between different species of atoms, e.g. Cu to O vice versa. NOT O to O or Cu to Cu.
This is example of (CuO)n n=2 cartesian coordinate. (For the convenience, (Cu) and (O) notations are added in this question)
0.000410140 0.000000000 -1.1437349409 (Cu1)
0.021984617 0.000000005 0.432069216 (Cu2)
0.021984488 0.000000005 0.432067361 (O1)
-0.043697492 0.000000005 0.432252977(O2)
and as n
size increases the two more of cartesian coordinated are generated.
So, my question is how to calculate iterative Euclidean distance, like Cu1 to O1 then Cu2 to O2, then Cu2 to O1, and Cu2 to O2?
a = np.loadtxt({file})
for {} in a:
d = np.sqrt(np.sum((a[int(x)]-a[int(y)]**2))
n=2
x < n
y >= n+1
a[0] to a[3], and a[1] to a[4]
I can see that my weakness in assigning multiple variables in a for loop.
Trial 1
a = np.loadtxt({data})
cation = a[:{n}]
anion = a[{n}:]
d = np.sqrt(np.sum((cation-anion)**2))
print(d)
this value is 1.5809706852417704. Pressumable it is wrong (WHY?)
However, the for loop in below gives all the value, 1.5759499815439955, 1.5766050227405235, 1.859480034843622e-06, 0.0656823660565985
for x in cation:
for y in anion:
d = np.sqrt(np.sum((x-y)**2))
print (d)