-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgaussian_analysis_module.py
More file actions
133 lines (124 loc) · 4.68 KB
/
gaussian_analysis_module.py
File metadata and controls
133 lines (124 loc) · 4.68 KB
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
import numpy as np
import re
class Gaussian_module:
def __init__(self, file):
# self.Temperature = Temperature
# self.Pressure = Pressure
self.file = file
def getElectronic_E(self):
# get electronic energy
lookup = "SCF Done"
EE = []
f = open(self.file,"r")
for line in f:
if lookup in line:
EE.append(line.split())
EE = float(EE[len(EE)-1][4])
f.close()
return EE
def getNum_atoms(self):
# function to get number of atoms
lookup = "Charge ="
count = 0
f = open(self.file,"r")
for line in f:
if lookup in line:
for i in range(0,1000000):
line = next(f)
if len(line.strip()) == 0:
break
count = count + 1
if count > 0:
break
Num_atoms = count
f.close()
return Num_atoms
def getMasses(self):
# function to get masses
lookup = "- Thermochemistry -"
Masses = []
f = open(self.file,"r")
for line in f:
if lookup in line:
line = next(f)
line = next(f)
line = next(f)
for i in range (0,Gaussian_module.getNum_atoms(self)):
if "mass**********" in line.split()[-1]:
Masses.append("100000000")
else:
Masses.append(line.split()[-1])
line = next(f)
break
f.close()
return np.asarray(Masses,dtype=np.float32)
def getAtomlist(self):
lookup = "Symbolic Z-matrix:"
Atoms = []
with open(self.file,"r") as f:
for line in f:
if lookup in line:
line = next(f)
line = next(f)
for i in range (0,Gaussian_module.getNum_atoms(self)):
Atoms.append(re.split('\(',line)[0].split())
line = next(f)
break
for i in range(0,len(Atoms)):
Atoms[i] = Atoms[i][0]
return Atoms
def optComplete(self):
# function to check if optimization was completed
# label=0 -> optimization didnt finish
# label=1 -> optimization completed
label = 0
with open(self.file,"r") as f:
for line in f:
if " Optimization completed." in line:
label = 1
return label
def getLastcoords(self):
# function to get coordinates of input structure
Coords = []
with open(self.file,"r") as f:
for line in f:
if "Input orientation:" in line:
line = f.readline()
line = f.readline()
line = f.readline()
line = f.readline()
line = f.readline()
for j in range(100000):
Coords.append(line.split())
line = f.readline()
if "---------------------------------------------------------------------" in line:
break
for i in range(0,len(Coords)):
Coords[i] = Coords[i][3:]
return np.asarray(Coords[Gaussian_module.getNum_atoms(self)*(len(Coords)/Gaussian_module.getNum_atoms(self)-1):len(Coords)],dtype=np.float32)
def getOptcoords(self):
# function to get optimized coordinates
# add warning if opt complete is not present
Coords = []
count = 0
with open(self.file,"r") as f:
for line in f:
if " Optimization completed" in line and count ==0 :
count = 1
for i in range(0,10000):
line = f.readline()
if "Input orientation:" in line:
line = f.readline()
line = f.readline()
line = f.readline()
line = f.readline()
line = f.readline()
for j in range(0,100000):
Coords.append(line.split())
line = f.readline()
if "---------------------------------------------------------------------" in line:
break
break
for i in range(0,len(Coords)):
Coords[i] = Coords[i][3:]
return np.asarray(Coords,dtype=np.float32)