-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdos_reader.py
executable file
·167 lines (125 loc) · 4.86 KB
/
dos_reader.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env python
import sys
import commands
import numpy
print 'This code is built around the assumption that all atoms are of the same type \
try pdos.py for those systems'
subtractFermi = False
ncore_electrons = 0
nvalence_electrons = 10
def main():
try:
input_filename = sys.argv[1]
except IndexError:
print '\nusage: ' + sys.argv[0] + ' input_filename'
print '\nexiting...\n'
sys.exit(0)
nelectrons = ncore_electrons + nvalence_electrons
command_line_counter = commands.getoutput('wc -l ' + input_filename).split()
if len(command_line_counter) != 2:
print 'Error determining file size'
else:
number_of_lines = int(command_line_counter[0])
outputFile_dos = open('dos.dat', 'w')
outputFile_pdos = open('pdos.dat', 'w')
inputFile = open(input_filename, 'r')
natom = int(inputFile.readline().split()[0])
for i in range(4):
inputFile.readline()
inline_total = inputFile.readline()
emin_total = float(inline_total.split()[1])
emax_total = float(inline_total.split()[0])
enum_total = int(inline_total.split()[2])
efermi_total = float(inline_total.split()[3])
dos = numpy.zeros((enum_total, 3), dtype = numpy.float) # E, dos, idos
for i in range(enum_total):
inline_total = inputFile.readline().split()
if (subtractFermi == True):
dos[i][0] = float(inline_total[0]) - efermi_total
else:
dos[i][0] = float(inline_total[0])
dos[i][1], dos[i][2] = float(inline_total[1]), float(inline_total[2])
# loop through dos, find point where idos > atoms in 3s2 state of S
core_valence_divide = 0 # initialize to safe value
for i in range(enum_total):
if ( dos[i][2] > natom*ncore_electrons):
core_valence_divide = i
break
efermi_bin = 1e6 # initialize to crazy value
for i in range(enum_total):
if ( dos[i][2] > natom*nelectrons):
efermi_bin = i
break
if (efermi_bin == 1e6):
print 'Fermi bin not found. There is something wrong.'
sys.exit(0)
for row in dos:
for element in row:
outputFile_dos.write(str(element) + ' ')
outputFile_dos.write('\n')
############
enum_project = enum_total
spacing = (emax_total - emin_total)/enum_total
pdos = numpy.zeros((enum_project, 1 + 3*2), dtype = numpy.float) # E, s, p, d
for i in range(len(pdos)):
pdos[i][0] = dos[i][0] # fills in the E column of pdos
for atoms in range(natom):
inline_project = inputFile.readline()
if len(inline_project) != 70:
print 'There are no more atoms in this DOSCAR. Something is wrong.'
sys.exit(0)
for i in range(enum_project):
inline_project = inputFile.readline().split()
pdos[i][1] += float(inline_project[1]) # s
pdos[i][2] += float(inline_project[2]) # p
pdos[i][3] += float(inline_project[3]) # d
for i in numpy.arange(1,enum_project):
pdos[i][4] = pdos[i - 1][4] + pdos[i][1]
pdos[i][5] = pdos[i - 1][5] + pdos[i][2]
pdos[i][6] = pdos[i - 1][6] + pdos[i][3]
energies = numpy.transpose(pdos)[0]
s_project = numpy.transpose(pdos)[1]
p_project = numpy.transpose(pdos)[2]
d_project = numpy.transpose(pdos)[3]
energies_core = energies[0:core_valence_divide]
s_project_core = s_project[0:core_valence_divide]
p_project_core = p_project[0:core_valence_divide]
d_project_core = d_project[0:core_valence_divide]
energies_valence = energies[core_valence_divide:efermi_bin]
s_project_valence = s_project[core_valence_divide:efermi_bin]
p_project_valence = p_project[core_valence_divide:efermi_bin]
d_project_valence = d_project[core_valence_divide:efermi_bin]
spd_sum_core = sum(s_project_core) + sum(p_project_core) + sum(d_project_core)
spd_sum_valence = sum(s_project_valence) + sum(p_project_valence) + sum(d_project_valence)
if (spd_sum_core > 0.):
s_fraction_core = sum(s_project_core)/spd_sum_core
p_fraction_core = sum(p_project_core)/spd_sum_core
else:
s_fraction_core, p_fraction_core = 0.,0.
if (spd_sum_valence > 0.):
s_fraction_valence = sum(s_project_valence)/spd_sum_valence
p_fraction_valence = sum(p_project_valence)/spd_sum_valence
d_fraction_valence = sum(d_project_valence)/spd_sum_valence
else:
s_fraction_valence, p_fraction_valence, d_fraction_valence = 0., 0., 0.
print
print "%s core", s_fraction_core*100
print "%p core", p_fraction_core*100
print
print "%s valence", s_fraction_valence*100
print "%p valence", p_fraction_valence*100
print "%d valence", d_fraction_valence*100
print
print "norm = ", str(s_fraction_valence + p_fraction_valence + d_fraction_valence)
print
print "efermi_total = ", efermi_total
print "spacing = ", spacing
print
if (subtractFermi == True):
print "Note, levels have been shifted so E_Fermi = 0"
for row in pdos:
for element in row:
outputFile_pdos.write(str(element) + ' ')
outputFile_pdos.write('\n')
if __name__ == '__main__':
main()