-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMO-plot-vertical.py
147 lines (126 loc) · 3.87 KB
/
MO-plot-vertical.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
#!/usr/bin/env python3
# MO-plot-vertical
# Option to print only occupied or occupied and verticals.
#OccOnly=True only occ. OccOnly=False both coc and vit
OccOnly=False
#Pointsize
pointsize=4000
#Linewidth of bars
linewidth=2
##################################################
# probably unnecessary to change anything below
##################################################
#Lists and defintions
occorbsgrab=False
virtorbsgrab=False
endocc="unset"
tddftgrab="unset"
tddft="unset"
bands_alpha=[]
bands_beta=[]
virtbands_a=[]
virtbands_b=[]
f=[]
virtf=[]
tddftstates=[]
spinflag="unset"
hftyp="unset"
#Only using alpha orbitals (regardless of RHF or UHF). Handled by break.
import sys
with open(sys.argv[1]) as file:
for line in file:
#print("spinflag:",spinflag)
#print("occorbsgrab:", occorbsgrab, "virtorbsgrab:", virtorbsgrab)
if '%tddft' in line:
tddft="yes"
if 'Hartree-Fock type HFTyp' in line:
hftyp=line.split()[4]
print("HF type is", hftyp)
#if hftyp=="UHF":
if hftyp == "RHF":
spinflag="alpha"
if 'SPIN UP ORBITALS' in line:
spinflag="alpha"
if 'SPIN DOWN ORBITALS' in line:
spinflag="beta"
if occorbsgrab==True:
endocc=line.split()[1]
if endocc == "0.0000" :
occorbsgrab=False
virtorbsgrab=True
else:
if spinflag=="alpha":
bands_alpha.append(float(line.split()[3]))
if spinflag=="beta":
bands_beta.append(float(line.split()[3]))
if virtorbsgrab==True:
print("line2:", line)
if '------------------' in line:
break
if line == '\n':
print("Setting virtorbs to false", line)
virtorbsgrab=False
spinflag="unset"
continue
if spinflag=="alpha":
virtbands_a.append(float(line.split()[3]))
if spinflag=="beta":
virtbands_b.append(float(line.split()[3]))
endvirt=line.split()[1]
if 'NO OCC E(Eh) E(eV)' in line:
occorbsgrab=True
print("Occupied MOs-alpha are (eV):")
print(bands_alpha)
print("")
print("Occupied MOs-beta are (eV):")
print(bands_beta)
print("")
print("virtual alpha")
print(virtbands_a)
print("")
print("virtual beta")
print(virtbands_b)
# Check for numpy and matplotlib, try to exit gracefully if not found
import imp
import matplotlib.pyplot
try:
imp.find_module('numpy')
foundnp = True
except ImportError:
foundnp = False
try:
imp.find_module('matplotlib')
foundplot = True
except ImportError:
foundplot = False
if not foundnp:
print("Numpy is required. Exiting")
sys.exit()
if not foundplot:
print("Matplotlib is required. Exiting")
sys.exit()
import numpy as np
import matplotlib.pyplot as plt
import math
if OccOnly==True:
print("OccOnly True! Plotting only occupied orbital levels")
else:
print("OccOnly False! Plotting occupied and virtual orbital levels")
fig, ax = plt.subplots()
#Alpha MOs
ax.scatter([1]*len(bands_alpha), bands_alpha, color='blue', marker = '_', s=pointsize, linewidth=linewidth )
if OccOnly!=True:
ax.scatter([1]*len(virtbands_a), virtbands_a, color='cyan', marker = '_', s=pointsize, linewidth=linewidth )
#Beta MOs
if hftyp == "UHF":
ax.scatter([1.05]*len(bands_beta), bands_beta, color='red', marker = '_', s=pointsize, linewidth=linewidth )
if OccOnly!=True:
ax.scatter([1.05]*len(virtbands_b), virtbands_b, color='pink', marker = '_', s=pointsize, linewidth=linewidth )
plt.xlim(0.98,1.07)
plt.ylim(-12,3)
plt.xticks([])
plt.ylabel('MO energy (eV)')
#Vertical line
plt.axhline(y=0.0, color='black', linestyle='--')
plt.savefig(str(sys.argv[1])+'.png', format='png', dpi=200)
plt.show()