-
Notifications
You must be signed in to change notification settings - Fork 0
/
vib.py
135 lines (90 loc) · 2.38 KB
/
vib.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python
import numpy as np, os
import numpy.linalg as npl
import sys
import time
start_time = time.time()
np.set_printoptions(linewidth = 200)
molGeom = open('.\\Input_Files\\water.txt', 'r')
geomCont = molGeom.readlines()
hessRaw = open('.\\Input_Files\\waterHessian.txt', 'r')
hessCont = hessRaw.readlines()
molGeom.close()
hessRaw.close()
try:
if(hessCont[0] != geomCont[0]):
raise Exception("Number of Atoms in input and inputHessian do not match!")
except Exception as err:
print("ERROR: " + str(err))
sys.exit()
atomCount = int(geomCont[0].replace('\n', ''))
geomCont = geomCont[1:]
hessCont = hessCont[1:]
def pos(content):
posMatrix = np.array([])
for i in content:
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(content),3))
return posMatrix
def atomicMass(content):
an = np.array([])
for i in content:
i = i.split('\t')
i = i[:1]
i = [float(x) for x in i]
an = np.append(an,i)
for x in range(len(an)):
if(an[x] == 6.):
an[x] = 12.
elif(an[x] == 8):
an[x] = 16
return an
def hessianDat(hess):
hessMatrix = np.array([])
for i in hess:
i = i.split('\t')
i[-1] = i[-1].replace('\n','')
i = [float(x) for x in i]
hessMatrix = np.append(hessMatrix, i)
hessMatrix = np.reshape(hessMatrix, (atomCount*3,atomCount*3))
return hessMatrix
def massWeight(H, masses):
I = np.zeros(atomCount*3)
for i in range(0, atomCount*3,3):
I[i] = masses[int(i/3)]
I[i+1] = masses[int(i/3)]
I[i+2] = masses[int(i/3)]
M = np.outer(I,I)
M = np.sqrt(M)
H = np.divide(H,M)
return H
def hessFrequencies(H):
evec, ev = npl.eigh(H)
evec = np.sort(evec)
evec = evec[::-1]
evec = [np.sqrt(evec[i]*(1.0432*10**9))/(2*np.pi) for i in range(len(evec))]
return evec
def v_(atom1, atom2, positions = pos(geomCont)):
v_ij = (positions[atom2]-positions[atom1])
return v_ij
def main(geometry, hessian):
positions = pos(geometry)
atomicMasses = atomicMass(geometry)
hess = hessianDat(hessian)
MH = massWeight(hess,atomicMasses)
ev = hessFrequencies(MH)
print("\nPositions:")
print(positions)
print("\nHessian:")
print(hess)
print("\nMass Weighted Hessian:")
print(MH)
print("\nHessian Eigenvalues:")
print(np.around(ev, 6))
return None
main(geomCont,hessCont)
print("--- %s seconds ---" % (time.time() - start_time))