-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_transitions.py
More file actions
executable file
·143 lines (124 loc) · 4.08 KB
/
get_transitions.py
File metadata and controls
executable file
·143 lines (124 loc) · 4.08 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
#!/usr/bin/python
#Arnfinn Hykkerud Steindal, Tromso July 2011
#Get the excitation energies and transitions from an Dalton
#output-file
import re
import sys
import shutil
import string
from optparse import OptionParser
from mymodules import *
def get_homo(file):
for i in file.readlines():
words=i.split()
leng=len(words)
if "Orbital occupations :" in i:
homo = int(words[3])
break
# if leng==4:
# if words[0]=='Orbital' and words[1]=='occupations' and words[2]==':':
# homo = int(words[3])
file.seek(0)
return homo
def convergence(file):
conv = False
for i in file.readlines():
if "SOLUTION VECTORS CONVERGED" in i and "THE REQUESTED" in i:
conv = True
break
file.seek(0)
return conv
def get_maxnumtrans(file):
maxnumtrans = 0
for i in file.readlines():
if "SOLUTION VECTORS CONVERGED" in i:
if "THE REQUESTED" in i:
words = i.split()
maxnumtrans = int(words[3])
break
file.seek(0)
return maxnumtrans
parser = OptionParser()
parser.add_option("-i", "--input",dest="filename", help="The input file")
parser.add_option("-l", "--latex",action="store_true",default=False, dest="latex", help="Make LaTeX output")
parser.add_option("-t", "--trans",type="int",default=10, dest="numtrans", help="Maximum number transitions printed")
(options, args) = parser.parse_args()
try:
file = open(options.filename,'r')
except:
exit('Did not find file '+i)
numtrans=options.numtrans
latex=options.latex
maxnum=get_maxnumtrans(file)
if numtrans > maxnum:
numtrans = get_maxnumtrans(file)
homo=get_homo(file)
prline = ''
convergence = convergence(file)
if not convergence:
print "The response calculation did not converge"
exit()
opa = False
tpa = False
threepa = False
numline = len(file.readlines())
file.seek(0)
reader=True
if latex:
homostr = "H"
lumostr = "L"
else:
homostr = "HOMO"
lumostr = "LUMO"
for i in range(numtrans):
while reader:
line = file.readline()
if "RSPCTL MICROITERATIONS CONVERGED" in line:
reader = False
for j in range(50):
line = file.readline()
words=line.split()
leng = len(words)
if leng==8:
if words[1]=='Excited' and words[2]=='state' and words[3]=='no:' and words[4]==str(i+1):
done=False
opa = True
# print words[4] + ' ' + get_opa_ex(file,line)
opa=get_opa_ex(file,line).split('(')
if latex:
printline=words[4] + ' & ' + opa[0] + ' & ' + opa[1][0:5]+'& & '
else:
printline=words[4] + ' ' + opa[0] + 'eV (' + opa[1][0:5]+') -'
for k in range(8):
file.readline()
for k in range(100):
line=file.readline()
words=line.split()
try:
int(words[0])
except:
a=len(printline)
print printline[0:a-1]
done=True
break
low=int(words[1].split('(')[0])
high=int(words[2].split('(')[0])
down=str(low-homo)
up=str(high-homo-1)
if down=='0':
mo1=homostr
else:
mo1=homostr+down
if up=='0':
mo2=lumostr
else:
mo2=lumostr+"+"+up
percent=2*100.0*float(words[3])**2+0.5
if percent>=5.0:
if latex:
printline=printline+str(percent).split('.')[0]+'\%('+mo1+'$\\to$'+mo2+')+'
else:
printline=printline+" "+str(percent).split('.')[0]+'% ('+mo1+' -> '+mo2+') +'
if done:
break
file.close()