-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractresults
executable file
·130 lines (112 loc) · 3.94 KB
/
extractresults
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
#!/usr/bin/env python
import os
import numpy as np
import subprocess
import molrecog
import itertools
b2A = 0.529177249
A2b = 1./b2A
Hartree2ev = 27.211386245988
ev2Hartree = 1./Hartree2ev
def getChunks(cwd: str) -> list[str]:
fileName = cwd + "/final_output"
fileLines = (line for line in open(fileName,'r'))
nrICs = 0
inputLines = []
for iFileLine, fileLine in enumerate(fileLines):
if nrICs == 0 and iFileLine < 20:
inputLines.append(fileLine)
elif nrICs == 0:
nrICs += 1
yield inputLines
inputLines = []
elif nrICs > 0:
if ('Initial condition =' in fileLine and
int(fileLine.split()[-1]) > nrICs):
yield inputLines
nrICs += 1
inputLines = [fileLine]
else:
inputLines.append(fileLine)
yield inputLines
def getElData(cwd: str, jInitCond: int) -> dict[str, float]:
fileName = cwd + "/ICs/IC" + str(jInitCond) + '/input.out'
fileLines = (line for line in open(fileName,'r'))
elData = {}
readOsc = False
coupledState = 0
for fileLine in fileLines:
splitLine = fileLine.strip().split()
if '* MS-CASPT2 energy :' in fileLine:
state = splitLine[-2]
energy = float(splitLine[-1])
elData['E' + state] = energy
if 'Oscillator strength' in fileLine:
coupledState += 1
oscStrength = float(splitLine[-2])
elData['f0' + str(coupledState)] = oscStrength
continue
return elData
def substitute(inputChunk: list[str],
elData: dict[str, float],
iState: int) -> list[str]:
outputChunk = []
for line in inputChunk:
if 'Epot of initial state (eV):' in line:
tmpLine = line.split()
tmpLine[5] = str(elData['E0'])[:6] + ' '
tmpLine[4] += ' '*3
tmpLine[-1] = str(elData['E' + str(iState)])[:6]
tmpLine[-2] += ' '*5
tmpLine = ' '.join(tmpLine)
tmpLine = ' ' + tmpLine + '\n'
elif 'Vertical excitation (eV):' in line:
tmpLine = line.split()
tmpLine[3] = str(elData['E' + str(iState)]-
elData['E0'])[:6] + ' '
tmpLine[2] += ' '*5
tmpLine = ' '.join(tmpLine)
tmpLine = ' ' + tmpLine + '\n'
elif 'Oscillator strength:' in line:
tmpLine = line.split()
tmpLine[-1] = str(elData['f0' + str(iState)])[:6]
tmpLine[1] += ' '*10
tmpLine = ' '.join(tmpLine)
tmpLine = ' ' + tmpLine + '\n'
elif 'State:' in line:
tmpLine = line.split()
tmpLine[-1] = str(iState + 1)
tmpLine[0] += ' '*24
tmpLine = ' '.join(tmpLine)
tmpLine = ' ' + tmpLine + '\n'
else:
tmpLine = line
outputChunk.append(tmpLine)
return outputChunk
def main():
cwd = os.getcwd()
inputChunks = getChunks(cwd)
output = []
for i in range(4):
output.append([])
for jInputChunk, inputChunk in enumerate(inputChunks):
#if jInputChunk == 1:
# break
elData = getElData(cwd, jInputChunk + 1)
if jInputChunk == 0:
refGSEn = elData['E0']
s0Diff = elData['E0'] - refGSEn
oldE0 = elData['E0']
elData['E0'] = s0Diff*Hartree2ev
for i in range(1,5):
sIs0Diff = elData['E' + str(i)] - oldE0 + s0Diff
elData['E' + str(i)] = sIs0Diff*Hartree2ev
outputChunkI = substitute(inputChunk, elData, i)
output[i-1].extend(outputChunkI)
for i in range(2,6):
outFile = cwd + '/final_output.' + str(i)
with open(outFile, 'w') as outFile:
for line in output[i-2]:
outFile.write(line)
if __name__ == "__main__":
main()