-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsorted_angles.py
108 lines (78 loc) · 2.29 KB
/
sorted_angles.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/python
import numpy as np
import os
import math
import csv
import system
coords = []
vals = []
energy =[]
atom1 = sys.argv[1]
atom2 = sys.argv[2]
atom3 = sys.argv[3]
def main():
global coords
global vals
root = os.getcwd()
subdirs = os.listdir(root)
for subdir in subdirs:
if os.path.isdir(subdir):
file_dir = os.path.join(root,subdir)
# print(file_dir)
os.chdir(file_dir)
xyz_name = (str(subdir) + 'out.xyz')
os.system( "t2x -c > {}".format(xyz_name))
else:
continue
f=open(xyz_name,"r")
f.readline()
for line in f:
line =line.split()
coords.append(line[1:4])
#print(coords)
f.close()
input_atoms = [atom1,atom2,atom3]
input_one = input_atoms[0]
input_two = input_atoms[1]
input_three = input_atoms[2]
coords1 = coords[input_one]
coords2 = coords[input_two]
coords3 = coords[input_three]
coords1 = coords[input_one]
coords2 = coords[input_two]
coords3 = coords[input_three]
# print(coords1)
coords1 = np.array(coords1)
coords2 = np.array(coords2)
coords3 = np.array(coords3)
#print(coords1)
coords1 = coords1.astype(np.float)
coords2 = coords2.astype(np.float)
coords3 = coords3.astype(np.float)
# print(coords1)
# print(coords2)
# print(coords3)
a_vector= np.transpose(np.subtract(coords2,coords1))
b_vector = np.subtract(coords3,coords2)
# print(b_vector)
# print(a_vector)
ab_dot = np.float(np.sum(a_vector * b_vector))
a_mag = np.float(np.linalg.norm(a_vector))
b_mag = np.float(np.linalg.norm(b_vector))
#print(a_mag)
#print(b_mag)
#print(ab_dot)
theta = -( (ab_dot) / (a_mag * b_mag) )
#print(theta)
theta = math.acos(theta)
theta = (theta) * float(180 / math.pi)
row_output = [int(subdir), str(theta)]
vals.append(row_output)
coords = []
os.chdir(root)
myfile = open('angles.csv', 'w')
with myfile:
writer = csv.writer(myfile)
writer.writerows(sorted(vals, key= lambda x:int(x[0]))) #sorted by ints
if __name__ == '__main__':
main()