-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathG09_Summary.py
More file actions
139 lines (113 loc) · 4.18 KB
/
G09_Summary.py
File metadata and controls
139 lines (113 loc) · 4.18 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
134
135
136
137
138
139
import os
class G09_Summary:
def __init__(self, file_path):
self.file_path = file_path
self.file_lines = open(self.file_path, "r").readlines()
# Some variables to save from output
self.job_name = None
self.atoms = None
self.xyz = None
self.theory = None
self.output_summary = None
self.vibrations_string = None
self.HF = None
self.MP2 = None
self.Version = None
self.ZPE = None
self.Dipole = None
self.DipoleDerivative = None
self.NImag = None
self.charge = None
self.multiplicity = None
self.num_atoms = None
def record(self, line):
self.output_summary.append(line)
def saveVibrations(self, path=None):
if self.vibrations_string is None:
self.setVirbrations()
if path:
f_out = open(os.path.join(path, "{}_cart_disp.dat".format(self.job_name), "w"))
else:
f_out = open("{}_cart_disp.dat".format(self.job_name), "w")
f_out.write(self.vibrations_string)
f_out.close()
def saveXYZ(self, path=None):
if self.xyz is None:
self.setInfo()
if path:
f_out = open(os.path.join(path, "{}.xyz".format(self.job_name), "w"))
else:
f_out = open("{}.xyz".format(self.job_name), "w")
header = "{}\n\n".format(self.num_atoms)
for coord in self.xyz:
header += "{} {} {} {}\n".format(*coord.split(","))
f_out.write(header)
f_out.close()
def setVirbrations(self):
start = False
stop = False
for i, line in enumerate(self.file_lines):
if line.startswith(" 1 2 3"):
start = i
if start and line.__contains__("-------------------"):
stop = i - 1
if start and stop:
break
output_string = ""
for x in self.file_lines[start:stop]:
output_string += x
self.vibrations_string = output_string
def setInfo(self):
self.output_summary = []
reversed = list(self.file_lines)
reversed.reverse()
find_end = r"\\\@"
find_start = " 1\\1\\"
record = False
for line in reversed:
if line.startswith(find_start):
record = False
if line.__contains__(find_end):
self.record(line)
record = True
if record:
self.record(line)
self.output_summary.reverse()
output_string = ""
for x in self.output_summary:
output_string += x.rstrip()
self.output_summary = output_string.rstrip() # strips new line character
output_string = ""
for x in self.output_summary:
output_string += x
self.output_summary = output_string
self.output_summary = self.output_summary.split("\\")
self.output_summary = [i.replace(" ", "") for i in self.output_summary if i]
self.job_name = self.output_summary[2]
c_m = self.output_summary[3]
self.charge = int(c_m.split(",")[0])
self.multiplicity = int(c_m.split(",")[1])
"""
Setting the XYZ coordinates
"""
self.xyz = []
for line in self.output_summary[4:]:
if line.__contains__("Version"):
break
self.xyz.append(line)
self.atoms = [x.split(",")[0].upper() for x in self.xyz]
print(str(self.atoms)[1:-1])
self.num_atoms = len(self.atoms)
# for i, x in enumerate(self.output_summary):
# print(i, x)
def generateNMS_F90(self):
s = open("nms.f90.template", "r").read()
atoms_formatted = str(self.atoms)[1:-1]
f_out = open("{}_nms.f90".format(self.job_name), "w")
f_out.write(s.format(self.num_atoms, atoms_formatted, "{}.xyz".format(self.job_name),
"{}_cart_disp.dat".format(self.job_name), self.job_name))
f_out.close()
test = G09_Summary("butane_opt_freq.out")
test.saveXYZ()
test.saveVibrations()
test.generateNMS_F90()