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 @@ ...@@ -2,6 +2,7 @@
# qbox_dos.py: extract dos from Qbox output # qbox_dos.py: extract dos from Qbox output
# generate dos plot in gnuplot format # generate dos plot in gnuplot format
# use: qbox_dos.py emin emax width file.r # use: qbox_dos.py emin emax width file.r
# the DOS is accumulated separately for each spin
import xml.sax import xml.sax
import sys import sys
...@@ -27,17 +28,21 @@ def gauss(x, width): ...@@ -27,17 +28,21 @@ def gauss(x, width):
# Qbox output handler to extract and process data # Qbox output handler to extract and process data
class QboxOutputHandler(xml.sax.handler.ContentHandler): class QboxOutputHandler(xml.sax.handler.ContentHandler):
def __init__(self): def __init__(self):
self.iter = 0 self.nspin = 1
self.readData = 0 self.readData = 0
self.dos_up = [0] * ndos
self.dos_dn = [0] * ndos
def startElement(self, name, attributes): def startElement(self, name, attributes):
if name == "eigenvalues": if name == "eigenvalues":
self.n = attributes["n"] self.n = attributes["n"]
self.spin = attributes["spin"] self.spin = int(attributes["spin"])
self.kpoint = attributes["kpoint"] self.kpoint = attributes["kpoint"]
self.weight = float(attributes["weight"])
self.readData = 1 self.readData = 1
self.iter += 1
self.buffer = "" self.buffer = ""
if self.spin == 1:
self.nspin = 2
def characters(self, data): def characters(self, data):
if self.readData: if self.readData:
...@@ -46,25 +51,36 @@ class QboxOutputHandler(xml.sax.handler.ContentHandler): ...@@ -46,25 +51,36 @@ class QboxOutputHandler(xml.sax.handler.ContentHandler):
def endElement(self, name): def endElement(self, name):
if name == "eigenvalues": if name == "eigenvalues":
self.readData = 0 self.readData = 0
self.compute_dos() self.accumulate_dos()
def compute_dos(self): def accumulate_dos(self):
dos = [0] * ndos
self.e = self.buffer.split() self.e = self.buffer.split()
for i in range(len(self.e)): if self.spin == 0:
for j in range(ndos): for i in range(len(self.e)):
ej = emin + j * de for j in range(ndos):
dos[j] += gauss(float(self.e[i])-ej, width ) ej = emin + j * de
if self.iter > 1: self.dos_up[j] += gauss(float(self.e[i])-ej, width ) * self.weight
print if self.spin == 1:
print for i in range(len(self.e)):
print "# ",infile, " iter=", self.iter," spin=",self.spin, \ for j in range(ndos):
" kpoint=", self.kpoint," width=",width 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): for j in range(ndos):
ej = emin + j * de 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() parser = xml.sax.make_parser()
handler = QboxOutputHandler() handler = QboxOutputHandler()
parser.setContentHandler(handler) parser.setContentHandler(handler)
parser.parse(infile) 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