Repository navigation
Expand file tree
/
Copy pathbandgapoccu.py
More file actions
executable file
·96 lines (90 loc) · 2.35 KB
/
Copy pathbandgapoccu.py
File metadata and controls
executable file
·96 lines (90 loc) · 2.35 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
#!/usr/bin/env python
import numpy as np
import sys
vbm = None
cbm = None
bg = None
class bg:
def __init__( self, direct):
self.vbm = None
self.cbm = None
self.bg = None
self.Fermi = None
self.occu = None
self.energy = None
self.metallic = False
self.get_bandgap(direct)
def __call__ ( self,direct):
self.get_bandgap(direct)
def __iter__(self):
yield 'gap', self.bg
yield 'cbm', self.cbm
yield 'vbm', self.vbm
def get_bandgap(self,direct):
self.occu = []
self.energy = []
f = open(direct)
for i in f:
if "End of self-consistent" in i:
self.occu = []
self.energy = []
if ' k =' in i:
data = []
i = next(f)
i = next(f)
while len(i.split()) > 0:
for jj in i.split():
try:
data.append(float(jj))
except ValueError:
jjt = [xx for xx in jj.split('-') if xx]
for xx in jjt:
data.append(-float(xx))
i = next(f)
self.energy.append(data)
if 'occupation numbers' in i:
data = []
while len(i.split()) > 0:
i = next(f)
for jj in i.split():
data.append(float(jj.strip()))
self.occu.append(data)
if 'Fermi' in i:
self.Fermi = float(i.split()[4])
f.close()
minmax = []
metallic = False
if len(self.occu) > 0:
for c,i in enumerate(self.occu):
t = np.array(i)
if 0.0 in t:
idx = np.where(t==0.0)[0][0]
te = np.array(self.energy[c])
minmax.append([te[idx-1],te[idx]])
else:
metallic = True
if not metallic:
minmax = np.array(minmax)
self.vbm = np.max(minmax[:,0])
self.cbm = np.min(minmax[:,1])
self.bg = self.cbm - self.vbm
else:
self.vbm = None
self.cbm = None
self.metallic = True
self.bg = 0.0
else:
minmax = []
for c,i in enumerate(self.energy):
t = np.array(i)
t = np.subtract(i,self.Fermi)
m_ = np.argwhere(t>0)
minmax.append([t[m_[0][0]-1],t[m_[0][0]]])
minmax = np.array(minmax)
self.vbm = np.max(minmax[:,0])
self.cbm = np.min(minmax[:,1])
self.bg = self.cbm - self.vbm
if __name__ == "__main__":
import sys
x = bg(sys.argv[1])
print(x.bg)