-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_output.py
More file actions
executable file
·360 lines (335 loc) · 9.86 KB
/
get_output.py
File metadata and controls
executable file
·360 lines (335 loc) · 9.86 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
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
#!/usr/bin/python
# Arnfinn Hykkerud Steindal, Odense Dec. 2009
# Get the excitation energies from
# an output-file
import re
import sys
import shutil
import string
import math
try:
from scipy.constants import *
bohr=1e2*physical_constants['Bohr radius'][0]
eV2au=physical_constants['electron volt-hartree relationship'][0]
c=c*100
except:
bohr=5.291772108e-9 # cm
alpha=0.007297352568 # -
c=2.99792458e10 # cm/s
eV2au=0.03674932379 # au/eV
pi=math.pi # -
def get_property(lines):
lrsp = False
qrsp = False
crsp = False
rsp = False
prop = False
my_prop = ""
for i in lines[150:250]:
try:
dalinp = i[0:7]
except:
continue
if dalinp == ".RUN RE":
rsp = True
elif dalinp == ".RUN PR":
prop = True
if rsp:
if dalinp == "*LINEAR":
lrsp = True
elif dalinp == "*QUADRA":
qrsp = True
elif dalinp == "*CUBIC ":
crsp = True
if lrsp:
if dalinp == ".SINGLE":
my_prop = "1pa"
break
elif dalinp == ".DIPLEN":
my_prop = "alpha"
elif dalinp[0:4] == "NEF ":
my_prop = "nef"
break
elif qrsp:
if dalinp == ".TWO-PH":
my_prop = "2pa"
break
elif dalinp == ".DIPLEN":
my_prop = "beta"
elif dalinp[0:4] == "NEF ":
my_prop = "nef"
break
elif crsp:
if dalinp == ".DIPLEN":
my_prop = "gamma"
break
elif dalinp[0:4] == "NEF ":
my_prop = "nef"
break
elif dalinp[0:6] == ".THREE":
my_prop = "3pa"
break
if prop:
if dalinp == ".ECD ":
my_prop = "ecd"
break
if rsp:
for i in lines:
if "SOLUTION VECTORS NOT CONVERGED" in i:
my_prop = "no"
if prop and my_prop == "":
my_prop = "dipole"
return my_prop
def get_output(lines,prop):
if prop == "1pa":
output = get_opa(lines)
elif prop =="2pa":
output = get_tpa(lines)
elif prop == "3pa":
output = get_3pa(lines)
elif prop == "alpha":
output = get_alpha(lines)
elif prop == "beta":
output = get_beta(lines)
elif prop == "gamma":
output = get_gamma(lines)
elif prop == "dipole":
output = get_dipole(lines)
elif prop == "nef":
output = get_nef(lines)
elif prop == "ecd":
output = get_ecd(lines)
else:
output = ""
return output
def get_ecd(lines):
count = False
k = -999
out = ""
nm = False
nm = True
for i in lines:
if "Oscillator and Scalar Rotational Strengths" in i:
count = True
k = 0
if count:
k += 1
if "@ -------------" in i:
return out
if k > 9:
r = i.split()
if nm:
out += "{0} ({1} {2}) ".format(int(1240.0/float(r[3])+0.5),r[7],r[5])
else:
out += "{0} ({1} {2}) ".format(r[3],r[7],r[5])
def get_dipole(lines):
count = False
k = -999
for i in lines:
if "Dipole moment" in i:
count = True
k = 0
if count:
k+=1
if k == 5:
return i.split()[0]
def get_opa(lines):
read_exc = False
exc = []
osc = []
opa_string = ""
for i in lines:
if "@ Excitation energy :" in i:
read_exc = True
osc_tmp = 0.0
k = 0
elif read_exc:
exc.append(i.split()[1])
read_exc = False
if "@ Oscillator strength (LENGTH)" in i:
osc_tmp += float(i.split()[5])
k += 1
if k == 3:
osc.append(osc_tmp)
if len(osc) != len(exc):
exit("Something wrong in get_opa!")
for i in range(len(osc)):
opa_string += "{0:.2f} ({1:.3f}) ".format(float(exc[i]),osc[i])
return opa_string
def get_tpa(lines):
get_data = False
tpa_string = ""
exc = []
GM = []
for i in lines:
if "Two-photon absorption summary" in i:
get_data = True
if get_data:
words = i.split()
if len(words) == 9:
if words[3] == "Linear":
exc.append(words[2])
sigma_au=float(words[6])
GM.append(au2GM(float(words[2]),sigma_au))
for i in range(len(exc)):
tpa_string += "{0:.2f} ({1:.3f}) ".format(float(exc[i]),float(GM[i]))
return tpa_string
def get_3pa(lines):
get_data = False
tpa_string = ""
exc = []
sigma_au = []
for i in lines:
if "Three-photon transition probability" in i:
get_data = True
if get_data:
words = i.split()
if len(words) == 8:
if words[3] == "Linear":
exc.append(words[2])
sigma_au.append(float(words[6]))
for i in range(len(exc)):
tpa_string += "{0:.2f} ({1:.2f}) ".format(float(exc[i]),sigma_au[i])
return tpa_string
def get_alpha(lines):
k = 0
indep = False
freqd = False
alpha_freq = ""
for i in lines:
if "@ FREQUENCY INDEPENDENT SECOND ORDER PROPERTIES" in i:
indep = True
k = 0
elif "@ FREQUENCY DEPENDENT SECOND ORDER PROPERTIES WITH FREQUENCY :" in i:
freqd = True
k = 0
if indep or freqd:
k += 1
if "@ -<< XDIPLEN ; XDIPLEN >> =" in i:
xx = float(i.split()[7].replace('D','E'))
elif "@ -<< YDIPLEN ; YDIPLEN >> =" in i:
yy = float(i.split()[7].replace('D','E'))
elif "@ -<< ZDIPLEN ; ZDIPLEN >> =" in i:
zz = float(i.split()[7].replace('D','E'))
if k == 9:
if indep:
alpha_indep = (xx + yy + zz)/3.0
indep = False
if k == 15:
alpha_freq = (xx + yy + zz)/3.0
freqd = False
return "{0} {1}".format(alpha_indep, alpha_freq)
def get_beta(lines):
beta = 0.0
for i in lines:
for k in ["X","Y","Z"]:
for l in ["X","Y","Z"]:
if "beta("+k+";"+l+","+l+")" in i:
if k+l+l in ["YXX","ZXX","ZYY"]:
# XXY, XXZ and YZZ not printed to output
prefact = 2.0
else:
prefact = 1.0
words = i.split()
try:
beta += prefact*float(words[9])
except:
pass
if "beta("+l+";"+k+","+l+")" in i:
words = i.split()
try:
beta += float(words[9])
except:
pass
if "beta("+l+";"+l+","+k+")" in i:
if l+l+k in ["YYX","ZZX","ZZY"]:
# YXY, ZXZ and ZYZ not printed to output
prefact = 2.0
else:
prefact = 1.0
words = i.split()
try:
beta += prefact*float(words[9])
except:
pass
return beta/15.0
def get_gamma(lines):
for i in lines:
if "@ Averaged gamma parallel to the applied field is" in i:
words = i.split()
return words[-1]
def get_nef(lines):
for i in lines[-20:]:
if "@ << A; B, C, D >> =" in i:
order = "cubic"
value = i.split()[-1]
elif "@ omega B, omega C, QR value :" in i:
order = "quadratic"
value = i.split()[-1]
elif "@ -<< NEF " in i:
order = "linear"
value = i.split()[-1]
try:
return value.replace('D','E')
except:
exit("No data in the dalton output")
def get_opa_ex(file,line):
# Input:
# 1. Dalton input file
# 2. line "@ Excited state no: ..."
# Output: a (b)
# a = Excitation energy
# b = dipole moment (zero if no diplen keyword)
excit = ''
words = line.split()
for k in range(4):
line = file.readline()
words = line.split()
value = str(float(words[1])+0.00005)
# value = str(float(words[1])+0.005)
# value = str(float(words[1]))
excit = excit + ' ' + value[0:6]
for k in range(4):
line = file.readline()
intens = 0.0
for k in range(3):
for j in range(3):
line = file.readline()
words = line.split()
try:
intens = intens + float(words[5])
except:
break
# intens = intens/3.0
strint = str(intens)
if intens<0.001:
strint = '0.00000'
excit = excit + ' (' + strint[0:5] + ')'
return excit
def get_tpa_ex(file,line):
words = line.split()
exi_eV = float(words[2])
sigma_au=float(words[6])
sigma_GM="%.2f" % au2GM(exi_eV,sigma_au)
excit = ' ' + words[2] + ' (' + str(sigma_GM) + ')'
return excit
def au2GM(exi_ev,sigma_au):
lorentzian=0.0036749326 # au
const=1e50*8*(pi**2)*alpha*(bohr**5)/(c*lorentzian*4)
exi_au=exi_ev*eV2au
sigma_GM=const*exi_au**2*sigma_au
return sigma_GM
for i in sys.argv[1:]:
try:
myfile = open(i,'r')
except:
print 'Did not find file '+i
break
lines = myfile.readlines()
myfile.close()
prop = get_property(lines)
if prop == "no":
exit("Response calculation did not converge {0}".format(i))
prline = get_output(lines,prop)
if prline != '':
print "{0} {1} {2}".format(prline, prop, i)