Commit 1c4afcf4 authored by Pardini, Lorenzo (lopa)'s avatar Pardini, Lorenzo (lopa)
Browse files

fixed bug in DOS energies units

parent 53f9b02d
......@@ -3,6 +3,7 @@ import logging
import numpy as np
from nomadcore.unit_conversion.unit_conversion import convert_unit_function
from nomadcore.unit_conversion.unit_conversion import convert_unit
from nomadcore.unit_conversion import unit_conversion
class DosHandler(xml.sax.handler.ContentHandler):
def __init__(self, backend, spinTreat):
......@@ -33,7 +34,8 @@ class DosHandler(xml.sax.handler.ContentHandler):
# self.dosProjSectionGIndex = -1
def startElement(self, name, attrs):
ev_per_joule = convert_unit(1, "eV", "J")
fromH = unit_conversion.convert_unit_function("hartree", "J")
# ev_per_joule = convert_unit(1, "eV", "J")
if name == "totaldos":
self.dosSectionGIndex = self.backend.openSection("section_dos")
self.inDos = True
......@@ -48,10 +50,12 @@ class DosHandler(xml.sax.handler.ContentHandler):
elif name == "point":
if self.inDos:
self.totDos.append(float(attrs.getValue('dos')))
self.energy.append(ev_per_joule*float(attrs.getValue('e')))
# self.energy.append(float(attrs.getValue('e')))
self.energy.append(fromH(float(attrs.getValue('e'))))
elif self.inDosProj:
self.dosProj.append(float(attrs.getValue('dos')))
self.energy.append(ev_per_joule*float(attrs.getValue('e')))
# self.energy.append(float(attrs.getValue('e')))
self.energy.append(fromH(float(attrs.getValue('e'))))
elif name == "diagram":
if not self.speciesrn: pass
elif self.speciesrn [-1] == 1 and self.atom[-1] == 1:
......@@ -98,7 +102,7 @@ class DosHandler(xml.sax.handler.ContentHandler):
# print("self.dosProjSpin=",len(self.dosProjSpin))
# print("self.dosProjDummy2=",len(self.dosProjDummy2))
def endElement(self, name):
ev_per_joule = convert_unit(1, "eV", "J")
# ev_per_joule = convert_unit(1, "eV", "J")
if name == 'totaldos':
self.inDos = False
if not self.spinTreat:
......
......@@ -147,6 +147,7 @@ class GWContext(object):
if os.path.exists(dosGWFile):
dosGWGIndex = backend.openSection("x_exciting_section_GW_dos")
fromH = unit_conversion.convert_unit_function("hartree", "J")
with open(dosGWFile) as g:
dosValues = [[],[]]
dosEnergies = []
......@@ -155,7 +156,8 @@ class GWContext(object):
if not s: break
s = s.strip()
s = s.split()
ene, value = float(s[0]), float(s[1])
ene, value = fromH(float(s[0])), float(s[1])
# ene, value = float(s[0]), float(s[1])
dosEnergies.append(ene)
if not self.spinTreat:
for i in range(0,2):
......
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