-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeomAnalysis.py
112 lines (73 loc) · 2.56 KB
/
GeomAnalysis.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
109
110
111
112
#!/usr/bin/env python
import numpy as np, os
import numpy.linalg as npl
molGeom = open('.\\Input_Files\\geom.txt', 'r')
geomCont = molGeom.readlines()
atomCount = int(geomCont[0].replace('\n', ''))
geomCont = geomCont[1:]
def pos(positions):
posMatrix = np.array([])
for i in positions:
i = i.split('\t')
i[-1] = i[-1].replace('\n','')
i = i[1:]
i = [float(x) for x in i]
posMatrix = np.append(posMatrix, i)
posMatrix = np.reshape(posMatrix, (len(positions),3))
return posMatrix
def bondLenghts(positions):
distances = np.array([])
posDummy = positions.copy()
bondPartnerCount = 0 #correctly counts the index of the bonding partner as posDummy gets shorter while looping
for i in range(len(positions)):
posDummy = posDummy[1:]
bondPartnerCount = i+1
for k in range(len(posDummy)):
distances = np.append(distances, i)
distances = np.append(distances, bondPartnerCount)
distances = np.append(distances, np.abs(npl.norm(positions[i]-posDummy[k])))
bondPartnerCount += 1
distances = np.reshape(distances, (-1,3))
return distances
def bondAngles(positions, distances):
"""
Now gives the correct angles. However it needs some optimization as there are 5 for loops which can probably cut down to 3
"""
bondDis = [distances[x] for x in range(len(distances)) if distances[x][2] < 4]
bondDis = np.reshape(bondDis, (-1,3))
angles = np.array([])
for count in range(len(bondDis)):
for j in range(1,atomCount-1):
for i in range(0,j):
if(j == i):
continue
elif((i == bondDis[count][0] or i == bondDis[count][1]) and (j == bondDis[count][0] or j == bondDis[count][1])):
D_ij = bondDis[count][2]
e_ij = (positions[j]-positions[i])/D_ij
for k in range(j,atomCount):
if(k == j or k == i):
continue
for count2 in range(len(bondDis)):
if((j == bondDis[count2][0] or j == bondDis[count2][1]) and (k == bondDis[count2][0] or k == bondDis[count2][1])):
D_jk = bondDis[count2][2]
e_jk = (positions[k]-positions[j])/D_jk
angle = 180 - np.arccos(np.dot(e_ij,e_jk))*180/np.pi
angles = np.append(angles, [i,j,k,angle])
angles = np.reshape(angles, (-1,4))
return angles
def main(positions):
posMain = pos(positions)
lenghts = bondLenghts(posMain)
angles = bondAngles(posMain,lenghts)
print("Number of atoms: ")
print(atomCount)
print("\nPositions:")
print(posMain)
print("\nBond lenghts:")
print(lenghts)
print("\nBond Angles:")
print(angles)
return None
#bondAngles(pos(geomCont),bondLenghts(pos(geomCont)))
main(geomCont)
molGeom.close()