-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimilarity.py
62 lines (56 loc) · 2.09 KB
/
similarity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
# coding: utf-8
def polar(x,y,z):
import numpy as np
r = np.sqrt((x*x)+(y*y)+(z*z))
if x<0 and y>=0:
teta = np.degrees(np.arctan(y/x)+np.pi)
elif x>0:
teta = np.degrees(np.arctan(y/x))
elif x<0 and y<0:
teta = np.degrees(np.arctan(y/x)-np.pi)
elif x==0 and y>0:
teta = np.degrees(np.pi/2)
elif x==0 and y<0:
teta = np.degrees(-np.pi/2)
elif x==0 and y==0:
teta = 0
if z>0:
zeta = np.degrees(np.arctan((np.sqrt((x*x)+(y*y))/2)))
elif z>0:
zeta = np.degrees(np.arctan((np.sqrt((x*x)+(y*y))/2))+np.pi)
elif z==0:
zeta = np.degrees(np.pi/2)
return(r,teta,zeta)
def similarity(filename):
import numpy as np
with open(filename) as f:
lines = f.readlines()
natoms=int(lines[0])
frame=np.zeros((natoms,3,1))
coordinates=np.zeros((natoms,3,1))
count=2 #if number of atom and title are present
f=0
while count < len(lines):
frame[f,0] = float(lines[count].split()[1])
frame[f,1] = float(lines[count].split()[2])
frame[f,2] = float(lines[count].split()[3])
count+=1
f+=1
if count%(natoms+2)==0:
coordinates=np.append(coordinates,frame,axis=2)
count+=2
f=0
coordinates=np.delete(coordinates,0,axis=2)
sim=[]
polaris= np.zeros((natoms,3,len(coordinates[0,0,:])))
for i in range(0,natoms):
for j in range(len(coordinates[0,0,:])):
polaris[i,:,j]=polar(coordinates[i,0,j],coordinates[i,1,j],coordinates[i,2,j])
for j in range(len(coordinates[0,0,:])):
for k in range(len(coordinates[0,0,:])):
if (polaris[i,:,j]-polaris[i,:,k])[1]==180.0:
if (j,k) not in sim and (k,j) not in sim:
sim.append((j,k))
print("Similarity is detected in between {}".format((j+1,k+1)))
print("Total similar structure : {}".format(len(sim)))