-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParsers.py
More file actions
262 lines (203 loc) · 7.51 KB
/
Copy pathParsers.py
File metadata and controls
262 lines (203 loc) · 7.51 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
import numpy as np
import re
def fatal(jobText, args):
linePattern = re.compile(b"fatal")
matches = re.findall(linePattern, jobText)
return matches != []
def dist(jobText, args):
atom1 = args[0]
atom2 = args[1]
jobText = trimGeom(jobText)
floatPattern = b"-*[0-9]+\.*[0-9]*"
distPattern1 = re.compile(atom1.encode() + b"\s+" + floatPattern + b"\s+" + floatPattern + b"\s+" + floatPattern)
distPattern2 = re.compile(atom2.encode() + b"\s+" + floatPattern + b"\s+" + floatPattern + b"\s+" + floatPattern)
distMatch1 = re.findall(distPattern1, jobText)
distMatch2 = re.findall(distPattern2, jobText)
if(len(distMatch1) == 0 and len(distMatch2) == 0):
return None
elif(len(distMatch1) == 0 or (atom1 == atom2 and len(distMatch1) == 1)):
return float(distMatch2[0].split()[2])
elif(len(distMatch2) == 0):
return float(distMatch1[0].split()[2])
else:
ind2 = 0
if(atom1 == atom2):
ind2 = 1
return abs(float(distMatch2[ind2].split()[-1]) - float(distMatch1[0].split()[-1]))
def GSEnergy(jobText, args):
linePattern = re.compile(b"Total energy in.*")
matches = re.findall(linePattern, jobText)
if(matches == []):
return None
else:
return float(matches[0].split()[-1])
def GSSpin(jobText, args):
linePattern = re.compile(b"S\^2.*")
matches = re.findall(linePattern, jobText)
if(matches == []):
return None
else:
return float(matches[0].split()[-1])
def CISEnergies(jobText, args):
nroots = NRoots(jobText)
jobText = trimCIS(jobText)
linePattern = re.compile(b"Total energy for state.*")
matches = re.findall(linePattern, jobText)
if(matches == []):
return None
else:
return [float(x.split()[-2]) for x in matches][:nroots]
def CISSpins(jobText, args):
nroots = NRoots(jobText)
jobText = trimCIS(jobText)
linePattern = re.compile(b"S\*\*2.*")
matches = re.findall(linePattern, jobText)
if(matches == []):
return None
else:
return [float(x.split()[-1]) for x in matches][:nroots]
def CISDGSEnergy(jobText, args):
linePattern = re.compile(b"RIMP2 total energy.*")
matches = re.findall(linePattern, jobText)
if(matches == []):
return None
else:
return float(matches[0].split()[-2])
def CISDEnergies(jobText, args):
nroots = NRoots(jobText)
jobText = trimCISD(jobText)
linePattern = re.compile(b"Total energy for state.*")
matches = re.findall(linePattern, jobText)
if(matches == []):
return None
else:
return [float(x.split()[-2]) for x in matches][:nroots]
def CISDTerm1(jobText, args):
nroots = NRoots(jobText)
linePattern = re.compile(b"term1.*")
matches = re.findall(linePattern, jobText)
if(matches == []):
return None
else:
return [float(x.split()[-2]) for x in matches][:nroots]
def CISDTerm2(jobText, args):
nroots = NRoots(jobText)
linePattern = re.compile(b"term2.*")
matches = re.findall(linePattern, jobText)
if(matches == []):
return None
else:
return [float(x.split()[-2]) for x in matches][:nroots]
def CCSDpTEnergy(jobText, args):
linePattern = re.compile(b"CCSD\(T\) total.*")
matches = re.findall(linePattern, jobText)
if(matches != []):
return float(matches[0].split()[-1])
def CCSDEnergy(jobText, args):
linePattern = re.compile(b"CCSD total.*")
matches = re.findall(linePattern, jobText)
if(matches != []):
return float(matches[0].split()[-1])
def CC2Energy(jobText, args):
matches = re.findall(b"CC2 total energy.*", jobText)
if(matches != []):
return float(matches[0].split()[-1])
def SCFEnergy(jobText, args):
matches = re.findall(b"SCF energy.*", jobText)
if(matches != []):
return float(matches[0].split()[-1])
def MP2Energy(jobText, args):
matches = re.findall(b"MP2 total energy.*", jobText)
if(matches != []):
return float(matches[0].split()[-2])
matches = re.findall(b"MP2 energy.*", jobText)
if(matches != []):
return float(matches[0].split()[-1])
def koomp2CorrEnergy(jobText, args):
matches = re.findall(b"RIMP2 correlation energy.*", jobText)
if(matches != []):
return float(matches[-1].split()[-2])
def MP3Energy(jobText, args):
matches = re.findall(b"MP3 energy .*", jobText)
if(matches != []):
return float(matches[-1].split()[-1])
def EEEnergy(jobText, args):
matches = re.findall(b"Excitation energy.*", jobText)
if(matches != []):
return [float(m.split()[-2]) for m in matches]
def Transitions(jobText, args):
pattern = re.compile("Amplitude Transitions between orbitals.*\n(?:.*->.*\n)*.*\n.*Summary", re.MULTILINE)
matches = re.findall(pattern, jobText)
matches = [m.split("\n")[1:-2] for m in matches]
vecs = []
for m in matches:
vecs.append(getTransVec(m))
return np.array(vecs).T
def BCC2Energy(jobText, args):
pattern = re.compile(b"CC2 ENERGY.*")
matches = re.findall(pattern, jobText)
if(matches != []):
finalEnergy = float(matches[-1].split()[-1])
return finalEnergy
def kMP2Energy(jobText, args):
pattern = re.compile(b"RIMP2 total energy.*")
match = re.search(pattern, jobText)
if(match != None):
return float(match.group(0).split()[-2])
def TAmps(jobText, args):
pattern = re.compile(b"t amps.*\n((?:\s|[0-9]|\.|-|\+|\n|e)*)", re.MULTILINE)
matches = re.findall(pattern, jobText)
ts = []
for match in matches:
lineSplitMatches = match.split(b"\n")
for line in lineSplitMatches:
vals = [float(t) for t in line.split()]
ts += vals
return np.array(ts)
def MP2NBS(jobText, args):
matches = re.findall(b"non-Brillouin singles =.*", jobText)
if(matches != []):
return float(matches[0].split()[-2])
def integMag(jobText, args):
matches = re.findall(b"Integral magnitude.*", jobText)
if(matches != []):
return float(matches[-1].split()[-1])
#
# helpers
#
def trimGeom(jobText):
startInd = jobText.find(b"$molecule")
endInd = jobText.find(b"$end")
return jobText[startInd:endInd]
def trimCIS(jobText, args):
startInd = jobText.find(b"CIS Excitation Energies")
endInd = jobText[startInd+90:].find("---------------") + startInd + 90
return jobText[startInd:endInd]
def trimCISD(jobText, args):
startInd = jobText.find(b"RI-CIS(D) Excitation Energies")
endInd = jobText[startInd+93:].find("---------------") + startInd + 93
return jobText[startInd:endInd]
def NRoots(jobText, args):
rootsLine = re.findall(b"cis_n_roots.*",jobText)
rootsLine += re.findall(b"EE_STATES .*", jobText)
if(len(rootsLine) == 0):
singletsLine = re.findall(b"EE_SINGLETS .*", jobText)
tripletsLine = re.findall(b"EE_TRIPLETS .*", jobText)
if(len(singletsLine) + len(tripletsLine) == 0):
return None
else:
nroots = int(singletsLine[0].split()[-1]) + int(tripletsLine[0].split()[-1])
else:
nroots = int(rootsLine[0].split()[-1])
return nroots
def getTransVec(transitions):
l = 300
vec = np.zeros(l)
for t in transitions:
vals = t.split()
amp = float(vals[0])
from_ind = int(vals[1]) + (l/4 if vals[3] == "A" else 0)
to_ind = l/2 + int(vals[5]) + (l/4 if vals[3] == "A" else 0)
vec[from_ind] -= amp
vec[to_ind] += amp
return vec