Commit 8bd7db33 by Francois Gygi

modified to accumulate kpoints contributions and

consider spin


git-svn-id: http://qboxcode.org/svn/qb/trunk@1393 cba15fb0-1239-40c8-b417-11db7ca47a34
parent 3f6f1b1e
......@@ -2,6 +2,7 @@
# qbox_dos.py: extract dos from Qbox output
# generate dos plot in gnuplot format
# use: qbox_dos.py emin emax width file.r
# the DOS is accumulated separately for each spin
import xml.sax
import sys
......@@ -27,17 +28,21 @@ def gauss(x, width):
# Qbox output handler to extract and process data
class QboxOutputHandler(xml.sax.handler.ContentHandler):
def __init__(self):
self.iter = 0
self.nspin = 1
self.readData = 0
self.dos_up = [0] * ndos
self.dos_dn = [0] * ndos
def startElement(self, name, attributes):
if name == "eigenvalues":
self.n = attributes["n"]
self.spin = attributes["spin"]
self.spin = int(attributes["spin"])
self.kpoint = attributes["kpoint"]
self.weight = float(attributes["weight"])
self.readData = 1
self.iter += 1
self.buffer = ""
if self.spin == 1:
self.nspin = 2
def characters(self, data):
if self.readData:
......@@ -46,25 +51,36 @@ class QboxOutputHandler(xml.sax.handler.ContentHandler):
def endElement(self, name):
if name == "eigenvalues":
self.readData = 0
self.compute_dos()
self.accumulate_dos()
def compute_dos(self):
dos = [0] * ndos
def accumulate_dos(self):
self.e = self.buffer.split()
for i in range(len(self.e)):
for j in range(ndos):
ej = emin + j * de
dos[j] += gauss(float(self.e[i])-ej, width )
if self.iter > 1:
print
print
print "# ",infile, " iter=", self.iter," spin=",self.spin, \
" kpoint=", self.kpoint," width=",width
if self.spin == 0:
for i in range(len(self.e)):
for j in range(ndos):
ej = emin + j * de
self.dos_up[j] += gauss(float(self.e[i])-ej, width ) * self.weight
if self.spin == 1:
for i in range(len(self.e)):
for j in range(ndos):
ej = emin + j * de
self.dos_dn[j] += gauss(float(self.e[i])-ej, width ) * self.weight
def print_dos(self):
print "# ",infile," spin=0 width=",width
for j in range(ndos):
ej = emin + j * de
print ej, dos[j]
print ej, self.dos_up[j]
if self.nspin == 2:
print
print
print "# ",infile," spin=1 width=",width
for j in range(ndos):
ej = emin + j * de
print ej, self.dos_dn[j]
parser = xml.sax.make_parser()
handler = QboxOutputHandler()
parser.setContentHandler(handler)
parser.parse(infile)
handler.print_dos()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment