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

fixed dos and gw

parent 4bda169e
......@@ -34,8 +34,9 @@ class DosHandler(xml.sax.handler.ContentHandler):
# self.dosProjSectionGIndex = -1
def startElement(self, name, attrs):
ha_per_joule = convert_unit(1, "hartree", "J")
bohr_cube_to_m_cube = convert_unit(1, "bohr^3", "m^3")
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
......@@ -49,11 +50,11 @@ class DosHandler(xml.sax.handler.ContentHandler):
self.inDosProj = True
elif name == "point":
if self.inDos:
self.totDos.append(float(attrs.getValue('dos')))
self.totDos.append(ha_per_joule*bohr_cube_to_m_cube*float(attrs.getValue('dos')))
# 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.dosProj.append(ha_per_joule*bohr_cube_to_m_cube*float(attrs.getValue('dos')))
# self.energy.append(float(attrs.getValue('e')))
self.energy.append(fromH(float(attrs.getValue('e'))))
elif name == "diagram":
......@@ -102,7 +103,6 @@ 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")
if name == 'totaldos':
self.inDos = False
if not self.spinTreat:
......
......@@ -5,36 +5,32 @@ from nomadcore.simple_parser import mainFunction, CachingLevel
from nomadcore.simple_parser import SimpleMatcher as SM
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.unit_conversion import unit_conversion
import os, sys, json
import os, sys, json, logging
################################################################
# This is the subparser for the exciting GW output
################################################################
class GWContext(object):
class GWParser(object):
"""context for wien2k In2 parser"""
def __init__(self):
self.parser = None
self.spinTreat = None
self.vertexDist = []
self.vertexLabels = []
self.vertexNum = 0
def initialize_values(self):
"""allows to reset values if the same superContext is used to parse different files"""
pass
def parseGW(self, gwFile, backend, dftMethodSectionGindex, dftSingleConfigurationGindex):
# logging.error("GW onClose_section_single_configuration_calculation")
backend.openNonOverlappingSection("section_single_configuration_calculation")
if dftSingleConfigurationGindex is not None:
backend.openNonOverlappingSection("section_calculation_to_calculation_refs")
backend.addValue("calculation_to_calculation_ref", dftSingleConfigurationGindex)
backend.addValue("calculation_to_calculation_kind", "starting_point")
backend.closeNonOverlappingSection("section_calculation_to_calculation_refs")
def startedParsing(self, path, parser):
"""called when parsing starts"""
self.parser = parser
self.initialize_values()
def onClose_x_exciting_section_GW(self, backend, gIndex, section):
dirPath = os.path.dirname(self.parser.fIn.name)
dirPath = os.path.dirname(gwFile)
if os.access(os.path.join(dirPath, "EVALQP.DAT"), os.F_OK):
eigvalGWFile = os.path.join(dirPath, "EVALQP.DAT")
elif os.access(os.path.join(dirPath, "EVALQP.TXT"), os.F_OK):
......@@ -50,7 +46,13 @@ class GWContext(object):
inputFile = os.path.join(dirPath, "input.xml")
if os.path.exists(inputFile):
selfGWSetGIndex = backend.openSection("x_exciting_section_GW_settings")
selfGWSetGIndex = backend.openSection("section_method")
backend.addValue('electronic_structure_method', "G0W0")
if dftMethodSectionGindex is not None:
m2mGindex = backend.openNonOverlappingSection("section_method_to_method_refs")
backend.addValue("method_to_method_ref", dftMethodSectionGindex)
backend.addValue("method_to_method_kind", "starting_point")
backend.closeNonOverlappingSection("section_method_to_method_refs")
singularity = 'mpd'
actype = 'pade'
npol = 0
......@@ -60,16 +62,16 @@ class GWContext(object):
fgrid = "gaule2"
k1 = 0
k2 = 0
# f1 = 0
# f2 = 0
# f1 = 0
# f2 = 0
s1 = 0
s2 = 0
# m1 = 0
# m2 = 0
# bc1 = 0
# bc2 = 0
# sc1 = 0
# sc2 = 0
# m1 = 0
# m2 = 0
# bc1 = 0
# bc2 = 0
# sc1 = 0
# sc2 = 0
with open(inputFile) as g:
i = 0
while 1:
......@@ -80,16 +82,16 @@ class GWContext(object):
s = s.split('=')
if s[0] == "<gw": k1 = i
if s[0] == "</gw>": k2 = i
# if s[0] == "<freqgrid": f1 = i
# if s[0] == "</freqgrid>": f2 = i
# if s[0] == "<freqgrid": f1 = i
# if s[0] == "</freqgrid>": f2 = i
if s[0] == "<selfenergy": s1 = i
if s[0] == "</selfenergy>": s2 = i
# if s[0] == "<mixbasis": m1 = i
# if s[0] == "</mixbasis>": m2 = i
# if s[0] == "<barecoul": bc1 = i
# if s[0] == "</barecoul>": bc2 = i
# if s[0] == "<scrcoul": sc1 = i
# if s[0] == "</scrcoul>": sc2 = i
# if s[0] == "<mixbasis": m1 = i
# if s[0] == "</mixbasis>": m2 = i
# if s[0] == "<barecoul": bc1 = i
# if s[0] == "</barecoul>": bc2 = i
# if s[0] == "<scrcoul": sc1 = i
# if s[0] == "</scrcoul>": sc2 = i
with open(inputFile) as g:
i = 0
while 1:
......@@ -119,7 +121,7 @@ class GWContext(object):
backend.addValue("x_exciting_GW_self_energy_c_analytical_continuation", actype)
backend.addValue("x_exciting_GW_self_energy_c_number_of_poles", int(npol))
backend.addValue("x_exciting_GW_screened_Coulomb", scrtype)
backend.closeSection("x_exciting_section_GW_settings",selfGWSetGIndex)
backend.closeSection("section_method",selfGWSetGIndex)
if os.path.exists(vertexGWFile):
with open(vertexGWFile) as g:
......@@ -134,7 +136,7 @@ class GWContext(object):
elif float(s[0]) != self.vertexDist[-1]:
self.vertexDist.append(float(s[0]))
self.vertexNum = len(self.vertexDist)-1
if os.path.exists(vertexLabGWFile):
with open(vertexLabGWFile) as g:
while 1:
......@@ -147,8 +149,7 @@ class GWContext(object):
self.vertexLabels.append(f[1])
if os.path.exists(eigvalGWFile):
eigvalGWOutGIndex = backend.openSection("x_exciting_section_GW_output")
eigvalGWGIndex = backend.openSection("x_exciting_section_GW_qp_eigenvalues")
eigvalGWGIndex = backend.openSection("section_eigenvalues")
with open(eigvalGWFile) as g:
qpGWKpoint=[]
Sx = [[],[]]
......@@ -187,23 +188,21 @@ class GWContext(object):
Sc[i][-1].append(fromH(float(s[5])))
qpE[i][-1].append(fromH(float(s[3])))
Znk[i][-1].append(float(s[9]))
backend.addValue("x_exciting_GW_qp_eigenvalues_kpoints", qpGWKpoint)
backend.addValue("x_exciting_GW_qp_number_of_eigenvalues", len(qpE[0]))
backend.addValue("x_exciting_GW_qp_number_of_eigenvalues_kpoints", len(qpGWKpoint))
backend.addValue("x_exciting_GW_qp_eigenvalues_values", qpE)
backend.addValue("eigenvalues_kpoints", qpGWKpoint)
backend.addValue("number_of_eigenvalues", len(qpE[0]))
backend.addValue("number_of_eigenvalues_kpoints", len(qpGWKpoint))
backend.addValue("eigenvalues_values", qpE)
backend.addValue("x_exciting_GW_qp_linearization_prefactor", Znk)
backend.closeSection("x_exciting_section_GW_qp_eigenvalues",eigvalGWGIndex)
selfGWGIndex = backend.openSection("x_exciting_section_GW_self_energy")
backend.closeSection("section_eigenvalues",eigvalGWGIndex)
backend.addValue("x_exciting_GW_self_energy_x", Sx)
backend.addValue("x_exciting_GW_self_energy_c", Sc)
backend.closeSection("x_exciting_section_GW_self_energy",selfGWGIndex)
backend.closeSection("x_exciting_section_GW_output",eigvalGWOutGIndex)
####################DOS######################
####################DOS######################
if os.path.exists(dosGWFile):
dosGWOutGIndex = backend.openSection("x_exciting_section_GW_output")
dosGWGIndex = backend.openSection("x_exciting_section_GW_dos")
dosGWGIndex = backend.openSection("section_dos")
ha_per_joule = unit_conversion.convert_unit(1, "hartree", "J")
bohr_cube_to_m_cube = unit_conversion.convert_unit(1, "bohr^3", "m^3")
fromH = unit_conversion.convert_unit_function("hartree", "J")
with open(dosGWFile) as g:
dosValues = [[],[]]
......@@ -213,23 +212,22 @@ class GWContext(object):
if not s: break
s = s.strip()
s = s.split()
ene, value = fromH(float(s[0])), float(s[1])
ene, value = fromH(float(s[0])), ha_per_joule*bohr_cube_to_m_cube*float(s[1])
dosEnergies.append(ene)
if not self.spinTreat:
for i in range(0,2):
dosValues[i].append(value)
else:
pass
backend.addValue("x_exciting_GW_dos_energies", dosEnergies)
backend.addValue("x_exciting_GW_dos_values", dosValues)
backend.addValue("x_exciting_GW_number_of_dos_values", len(dosEnergies))
backend.closeSection("x_exciting_section_GW_dos",dosGWGIndex)
backend.closeSection("x_exciting_section_GW_output",dosGWOutGIndex)
##################BANDSTRUCTURE#####################
backend.addValue("dos_energies", dosEnergies)
backend.addValue("dos_values", dosValues)
backend.addValue("number_of_dos_values", len(dosEnergies))
backend.closeSection("section_dos",dosGWGIndex)
##################BANDSTRUCTURE#####################
if os.path.exists(bandCarbGWFile):
bandGWOutGIndex = backend.openSection("x_exciting_section_GW_output")
bandGWGIndex = backend.openSection("x_exciting_section_GW_k_band")
bandGWGIndex = backend.openSection("section_k_band")
fromH = unit_conversion.convert_unit_function("hartree", "J")
with open(bandCarbGWFile) as g:
......@@ -293,16 +291,14 @@ class GWContext(object):
bandGWBE[i][j][-1].append(bandEnergiesSegm[j][l][i][k])
for i in range(0,len(Kindex)-1):
bandGWSegmGIndex = backend.openSection("x_exciting_section_GW_k_band_segment")
backend.addValue("x_exciting_GW_band_energies", bandGWBE[i])
backend.closeSection("x_exciting_section_GW_k_band_segment",bandGWSegmGIndex)
bandGWSegmGIndex = backend.openSection("section_k_band_segment")
backend.addValue("band_energies", bandGWBE[i])
backend.closeSection("section_k_band_segment",bandGWSegmGIndex)
backend.closeSection("x_exciting_section_GW_k_band",bandGWGIndex)
backend.closeSection("x_exciting_section_GW_output",bandGWOutGIndex)
backend.closeSection("section_k_band",bandGWGIndex)
if os.path.exists(bandBorGWFile) and not os.path.exists(bandCarbGWFile):
bandGWOutGIndex = backend.openSection("x_exciting_section_GW_output")
bandGWGIndex = backend.openSection("x_exciting_section_GW_k_band")
bandGWGIndex = backend.openSection("section_k_band")
fromH = unit_conversion.convert_unit_function("hartree", "J")
with open(bandBorGWFile) as g:
bandEnergies = [[[]],[[]]]
......@@ -363,38 +359,11 @@ class GWContext(object):
bandGWBE[i][j][-1].append(bandEnergiesSegm[j][l][i][k])
for i in range(0,len(Kindex)-1):
bandGWSegmGIndex = backend.openSection("x_exciting_section_GW_k_band_segment")
backend.addValue("x_exciting_GW_band_energies", bandGWBE[i])
backend.closeSection("x_exciting_section_GW_k_band_segment",bandGWSegmGIndex)
backend.closeSection("x_exciting_section_GW_k_band",bandGWGIndex)
backend.closeSection("x_exciting_section_GW_output",bandGWOutGIndex)
def buildGWMatchers():
return SM(
name = 'root',
weak = True,
startReStr = "\*\s*GW input parameters\s*\*",
sections = ["x_exciting_section_GW","x_exciting_section_GW_settings"],
subMatchers = [
SM(r"\s*Number of empty states \(GW\):\s*(?P<x_exciting_GW_polarizability_empty_states>[0-9]+)\s*")
])
def get_cachingLevelForMetaName(metaInfoEnv, CachingLvl):
"""Sets the caching level for the metadata.
Args:
metaInfoEnv: metadata which is an object of the class InfoKindEnv in nomadcore.local_meta_info.py.
CachingLvl: Sets the CachingLevel for the sections k_band, run, and single_configuration_calculation.
This allows to run the parser without opening new sections.
bandGWSegmGIndex = backend.openSection("section_k_band_segment")
backend.addValue("band_energies", bandGWBE[i])
backend.closeSection("section_k_band_segment",bandGWSegmGIndex)
Returns:
Dictionary with metaname as key and caching level as value.
"""
# manually adjust caching of metadata
cachingLevelForMetaName = {
'section_run': CachingLvl,
'section_method': CachingLvl
}
return cachingLevelForMetaName
backend.closeSection("section_k_band",bandGWGIndex)
backend.closeNonOverlappingSection("section_single_configuration_calculation")
# logging.error("done GW onClose_section_single_configuration_calculation")
......@@ -8,6 +8,7 @@ from nomadcore.caching_backend import CachingLevel
from nomadcore.unit_conversion import unit_conversion
import os, sys, json, exciting_parser_dos,exciting_parser_bandstructure, exciting_parser_gw #, exciting_parser_gw_bor
from ase import Atoms
import logging
class ExcitingParserContext(object):
......@@ -24,40 +25,43 @@ class ExcitingParserContext(object):
self.atom_labels = []
self.secMethodIndex = None
self.secSystemIndex = None
self.secGWIndex = None
self.secSingleConfIndex = None
self.spinTreat = None
self.sim_cell = []
self.cell_format = ''
self.secRunIndex = None
def onOpen_section_system(self, backend, gIndex, section):
self.secSystemIndex = gIndex
def onOpen_section_single_configuration_calculation(self, backend, gIndex, section):
if self.secSingleConfIndex is None:
self.secSingleConfIndex = gIndex
def onOpen_section_method(self, backend, gIndex, section):
self.secMethodIndex = gIndex
if self.secMethodIndex is None:
self.secMethodIndex = gIndex
def onClose_section_run(self, backend, gIndex, section):
# logging.error("BASE onClose_section_run")
self.secRunIndex = gIndex
mainFile = self.parser.fIn.fIn.name
dirPath = os.path.dirname(self.parser.fIn.name)
gw_File = os.path.join(dirPath, "GW_INFO.OUT")
gwFile = os.path.join(dirPath, "GWINFO.OUT")
if os.path.exists(gw_File):
subSuperContext = exciting_parser_gw.GWContext()
subParser = AncillaryParser(
fileDescription = exciting_parser_gw.buildGWMatchers(),
parser = self.parser,
cachingLevelForMetaName = exciting_parser_gw.get_cachingLevelForMetaName(self.metaInfoEnv, CachingLevel.PreOpenedIgnore),
superContext = subSuperContext)
with open(gw_File) as fIn:
subParser.parseFile(fIn)
elif os.path.exists(gwFile):
subSuperContext = exciting_parser_gw.GWContext()
subParser = AncillaryParser(
fileDescription = exciting_parser_gw.buildGWMatchers(),
parser = self.parser,
cachingLevelForMetaName = exciting_parser_gw.get_cachingLevelForMetaName(self.metaInfoEnv, CachingLevel.PreOpenedIgnore),
superContext = subSuperContext)
with open(gwFile) as fIn:
subParser.parseFile(fIn)
for gFile in [gw_File, gwFile]:
if os.path.exists(gFile):
# logging.error("Starting GW")
gwParser = exciting_parser_gw.GWParser()
gwParser.parseGW(gFile, backend,
dftMethodSectionGindex = self.secMethodIndex,
dftSingleConfigurationGindex = self.secSingleConfIndex)
# logging.error("Finished GW")
break
# logging.error("done BASE onClose_section_run")
def onClose_x_exciting_section_lattice_vectors(self, backend, gIndex, section):
latticeX = section["x_exciting_geometry_lattice_vector_x"]
......@@ -99,15 +103,15 @@ class ExcitingParserContext(object):
backend.closeSection("section_XC_functionals", gi)
def onClose_section_single_configuration_calculation(self, backend, gIndex, section):
# logging.error("BASE onClose_section_single_configuration_calculation")
backend.addValue('single_configuration_to_calculation_method_ref', self.secMethodIndex)
backend.addValue('single_configuration_calculation_to_system_ref', self.secSystemIndex)
dirPath = os.path.dirname(self.parser.fIn.name)
dosFile = os.path.join(dirPath, "dos.xml")
bandFile = os.path.join(dirPath, "bandstructure.xml")
fermiSurfFile = os.path.join(dirPath, "FERMISURF.bxsf")
gw_File = os.path.join(dirPath, "GW_INFO.OUT")
gwFile = os.path.join(dirPath, "GWINFO.OUT")
eigvalFile = os.path.join(dirPath, "EIGVAL.OUT")
# logging.error("done BASE onClose_section_single_configuration_calculation")
if os.path.exists(dosFile):
with open(dosFile) as f:
......@@ -115,10 +119,6 @@ class ExcitingParserContext(object):
if os.path.exists(bandFile):
with open(bandFile) as g:
exciting_parser_bandstructure.parseBand(g, backend, self.spinTreat)
if os.path.exists(gwFile) or os.path.exists(gw_File):
backend.addValue('electronic_structure_method', "G0W0")
else:
backend.addValue('electronic_structure_method', "DFT")
if os.path.exists(eigvalFile):
eigvalGIndex = backend.openSection("section_eigenvalues")
with open(eigvalFile) as g:
......@@ -279,21 +279,10 @@ class ExcitingParserContext(object):
self.atom_pos.append([pos[0][i], pos[1][i], pos[2][i]])
self.atom_labels = self.atom_labels + (section['x_exciting_geometry_atom_labels'] * natom)
def onClose_section_method(self, backend, gIndex, value):
if value["electronic_structure_method"][-1] == "G0W0":
gi = backend.openSection("section_method_to_method_refs")
backend.addValue("method_to_method_ref", (gIndex - 1))
backend.addValue("method_to_method_kind", 'starting_point')
backend.closeSection("section_method_to_method_refs", gi)
gi = backend.openSection("section_calculation_to_calculation_refs")
backend.addValue("calculation_to_calculation_ref", (self.CalculationGIndex - 1))
backend.addValue("calculation_to_calculation_kind", 'starting_point')
backend.closeSection("section_calculation_to_calculation_refs", gi)
def onOpen_section_single_configuration_calculation(self, backend, gIndex, value):
self.CalculationGIndex = gIndex
def onClose_section_method(self, backend, gIndex, value):
if gIndex == self.secMethodIndex:
backend.addValue('electronic_structure_method', "DFT")
mainFileDescription = \
SM(name = "root matcher",
......
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