-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalyzer_New.py
311 lines (239 loc) · 8.72 KB
/
Analyzer_New.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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
import numpy
import os
from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
#### deal with filename and path ####
#### struct to record data ####
class iCI_RawData:
def __init__(self,
spintwo,
symmetry,
cmin,
ncfg,
ncsf,
istate,
evar,
ept,
etot) -> None:
self.spintwo = spintwo
self.symmetry = symmetry
self.cmin = cmin
self.ncfg = ncfg
self.ncsf = ncsf
self.istate = istate
self.evar = evar
self.ept = ept
self.etot = etot
def __str__(self) -> str:
return "spintwo: %d, symmetry: %s, ncfg: %d, ncsf: %d, istate: %d, evar: %f, ept: %f, etot: %f" % (self.spintwo, self.symmetry, self.ncfg, self.ncsf, self.istate, self.evar, self.ept, self.etot)
def __repr__(self) -> str:
return self.__str__()
def __eq__(self, o: object) -> bool:
return self.spintwo == o.spintwo and self.symmetry == o.symmetry and self.cmin == o.cmin and self.istate == o.istate
def __lt__(self, o: object) -> bool:
# first spintwo then symmetry then istate then cmin
if self.spintwo == o.spintwo:
if self.symmetry == o.symmetry:
if self.istate == o.istate:
return self.cmin > o.cmin
else:
return self.istate < o.istate
else:
return self.symmetry < o.symmetry
else:
return self.spintwo < o.spintwo
#### deal with info ####
CMIN_TAG = "(CMIN_SCHEDULE)"
def _fetch_cmin(filename):
'''
fetch info in lines like: Cmin Schedule (CMIN_SCHEDULE) = 1.0000e-04 7.0000e-05 5.0000e-05 3.0000e-05 1.5000e-05
'''
file = open(filename)
lines = file.readlines()
cmin = []
for line in lines:
if CMIN_TAG in line:
cmin = line.split("=")[1].split()
cmin = [float(x) for x in cmin]
break
file.close()
return cmin
### extract pt info ###
def Extract_NonRela_Pt_Info_New(filename: str):
SPINTWO_LOC = 0
SYMMETRY_LOC = 1
NCFG_LOC = 2
NCSF_LOC = 3
E_VAR_LOC = 4
E_PT_LOC = 5
E_TOT_LOC = 6
lines = None
try:
file = open(filename)
lines = file.readlines()
file.close()
except:
return None, False, False, 0
Res = []
CMIN = _fetch_cmin(filename)
ITASK = 0
# print("CMIN: ", CMIN)
for i in range(len(lines)):
if "iCI_ENPT(2)_NonRela::Info" in lines[i]:
begin = i
end = i+1
for j in range(begin+1, len(lines)):
if "********************************" in lines[j]:
end = j
break
DataTmp = []
spintwo = None
symmetry = None
ncfg = None
ncsf = None
istate = None
evar = None
ept = None
etot = None
# print("ITASK: ", ITASK)
# print("CMIN: ", CMIN[ITASK])
cmin = CMIN[ITASK]
ITASK += 1
for j in range(begin, end):
if '_______________________________________________________________________________________________' in lines[j]:
for k in range(j+3, end):
if '_______________________________________________________________________________________________' in lines[k]:
break
str_tmp = lines[k].split("|")
# print(str_tmp)
try:
spintwo = int(str_tmp[SPINTWO_LOC])
istate = 0
except:
istate += 1
assert spintwo is not None
try:
# symmetry = int(str_tmp[SYMMETRY_LOC])
symmetry = int(str_tmp[SYMMETRY_LOC])
except:
if len(str_tmp[SYMMETRY_LOC]) > 0 and "Rela 4C" in str_tmp[SYMMETRY_LOC]:
symmetry = str_tmp[SYMMETRY_LOC]
assert symmetry is not None
try:
ncfg = int(str_tmp[NCFG_LOC])
except:
assert ncfg is not None
try:
ncsf = int(str_tmp[NCSF_LOC])
except:
assert ncsf is not None
evar = float(str_tmp[E_VAR_LOC])
ept = float(str_tmp[E_PT_LOC])
etot = float(str_tmp[E_TOT_LOC])
DataTmp.append(iCI_RawData(
spintwo, symmetry, cmin, ncfg, ncsf, istate, evar, ept, etot))
break
# print("DataTmp: ", len(DataTmp))
# print("DataTmp: ", DataTmp[0])
Res.append(DataTmp)
return Res
def Extract_NonRela_Pt_Info_Origin(filename: str):
# SPINTWO_LOC = 0
# SYMMETRY_LOC = 1
NCFG_LOC = 2-2
NCSF_LOC = 3-2
E_VAR_LOC = 4-2
E_PT_LOC = 5-2
E_TOT_LOC = 6-2
lines = None
try:
file = open(filename)
lines = file.readlines()
file.close()
except:
return None, False, False, 0
Res = []
CMIN = _fetch_cmin(filename)
ITASK = 0
for i in range(len(lines)):
if "iCI_ENPT(2)_NonRela::Info" in lines[i]:
begin = i
end = i+1
for j in range(begin+1, len(lines)):
if "********************************" in lines[j]:
end = j
break
DataTmp = []
spintwo = None
symmetry = None
ncfg = None
ncsf = None
istate = None
evar = None
ept = None
etot = None
cmin = CMIN[ITASK]
ITASK += 1
for j in range(begin, end):
if '_______________________________________________________________________________________________' in lines[j]:
for k in range(j+3, end):
if '_______________________________________________________________________________________________' in lines[k]:
break
str_tmp = lines[k].split("|")
# try:
# spintwo = int(str_tmp[SPINTWO_LOC])
# istate = 0
# except:
# istate += 1
# assert spintwo is not None
# try:
# symmetry = int(str_tmp[SYMMETRY_LOC])
# except:
# assert symmetry is not None
try:
ncfg = int(str_tmp[NCFG_LOC])
istate = 0
except:
istate += 1
assert ncfg is not None
try:
ncsf = int(str_tmp[NCSF_LOC])
except:
assert ncsf is not None
evar = float(str_tmp[E_VAR_LOC])
ept = float(str_tmp[E_PT_LOC])
etot = float(str_tmp[E_TOT_LOC])
DataTmp.append(iCI_RawData(
0, 0, cmin, ncfg, ncsf, istate, evar, ept, etot))
break
# print("DataTmp: ", len(DataTmp))
Res.append(DataTmp)
return Res
if __name__ == "__main__":
lines_test = "(CMIN_SCHEDULE) = 1.0000e-04 7.0000e-05 5.0000e-05 3.0000e-05 1.5000e-05"
cmin = lines_test.split("=")[1].split()
cmin = [float(x) for x in cmin]
print(cmin)
filename = "/home/ningzhang/HPC_Task/CoreExtTest/pt_coreext/input_SO2_S2p_aug-cc-pVTZ_Vert.out"
cmin = _fetch_cmin(filename)
print(cmin)
pt_info = Extract_NonRela_Pt_Info_New(filename)
for array in pt_info:
for item in array:
print(item)
print("**********")
# flat array
pt_info_flat = []
for array in pt_info:
pt_info_flat.extend(array)
# sort array
pt_info_flat.sort()
# print array
for item in pt_info_flat:
print(item)
# 文件名匹配,提取信息,根据文件名提取信息
FILENAME = "input_SO2_S2p_aug-cc-pVTZ_Vert.out"
FILENAME = FILENAME.split(".")[0]
print(FILENAME)
print(FILENAME.split("_"))