diff --git a/parser/parser-exciting/exciting_parser_gw.py b/parser/parser-exciting/exciting_parser_gw.py index 2ee4b9df8d387413faeca7a95cf045a37a84350c..35795db552c13a6ffdda84a9d524dc9c012d91a7 100644 --- a/parser/parser-exciting/exciting_parser_gw.py +++ b/parser/parser-exciting/exciting_parser_gw.py @@ -5,7 +5,7 @@ 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, logging +import os, sys, json, logging, exciting_parser_input ################################################################ # This is the subparser for the exciting GW output @@ -48,8 +48,22 @@ class GWParser(object): vertexLabGWFile = os.path.join(dirPath, "bandstructure.xml") selfCorGWFile = os.path.join(dirPath, "SELFC.DAT") inputFile = os.path.join(dirPath, "input.xml") + inputgw1File = os.path.join(dirPath, "input-gw.xml") + inputgw2File = os.path.join(dirPath, "input_gw.xml") if os.path.exists(inputFile): + if os.path.exists(inputgw1File): + inputgwFile = inputgw1File + elif os.path.exists(inputgw2File): + inputgwFile = inputgw2File + else: + inputgwFile = inputFile + elif os.path.exists(inputgw1File): + inputgwFile = inputgw1File + elif os.path.exists(inputgw2File): + inputgwFile = inputgw2File + + if os.path.exists(inputgwFile): selfGWSetGIndex = backend.openSection("section_method") backend.addValue('electronic_structure_method', "G0W0") backend.addValue('gw_starting_point', xcName) @@ -58,164 +72,8 @@ class GWParser(object): 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 - scrtype = "rpa" - snempty = 0 - pnempty = 0 - coreflag = "all" - fgrid = "gaule2" - lmaxmb = 3 - epsmb = 0.0001 - gmb = 1.0 - sciavtype = "isotropic" - cutofftype = "none" - pwm = 2.0 - ngridq = [2,2,2] - freqmax = 1.0 - nomeg = 16 - k1 = 0 - k2 = 0 - # f1 = 0 - # f2 = 0 - s1 = 0 - s2 = 0 - m1 = 0 - m2 = 0 - bc1 = 0 - bc2 = 0 - sc1 = 0 - sc2 = 0 - with open(inputFile) as g: - i = 0 - while 1: - s = g.readline() - i += 1 - if not s: break - s = s.strip() - 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] == "<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 -# print("m1= ",m1) -# print("m2= ",m2) - with open(inputFile) as g: - i = 0 - while 1: - s = g.readline() - i += 1 - if not s: break - s = s.strip() - s = s.split('=') - if (s[0] == "coreflag") and (i >= k1) and (i < (k2-1)): - coreflag = s[1][1:-1] - elif (s[0] == "coreflag") and (i == (k2-1)): - coreflag = s[1][1:-2] - if (s[0] == "singularity") and (i >= k1) and (i < (k2-1)): - freq_conv = s[1][1:-1] - elif (s[0] == "singularity") and (i == (k2-1)): - freq_conv = s[1][1:-2] - if (s[0] == "actype") and (i >= k1) and (i < (k2-1)): - actype = s[1][1:-1] - elif (s[0] == "actype") and (i == (k2-1)): - actype = s[1][1:-2] - if (s[0] == "ngridq") and (i >= k1) and (i < (k2-1)): - dummy = s[1].split('"') - dummy1 = dummy[1].split() - for j in range(0,3): - ngridq[j] = int(dummy1[j]) - elif (s[0] == "ngrid") and (i == (k2-1)): - dummy = s[1].split('"') - dummy1 = dummy[1].split() - for j in range(0,3): - ngridq[j] = int(dummy1[j]) - if (s[0] == "npol") and (i >= k1) and (i < (k2-1)): - npol = int(s[1][1:-1]) - elif (s[0] == "npol") and (i == (k2-1)): - npol = int(s[1][1:-2]) - if (s[0] == "nempty") and (i >= k1) and (i < (k2-1)): - pnempty = int(s[1][1:-1]) - elif (s[0] == "nempty") and (i == (k2-1)): - pnempty = int(s[1][1:-2]) - if (s[0] == "scrtype") and (i >= k1) and (i < (k2-1)): - scrtype = s[1][1:-1] - elif (s[0] == "scrtype") and (i == (k2-1)): - scrtype = s[1][1:-2] - if (s[0] == "nempty") and (i >= s1) and (i < (s2-1)): - snempty = int(s[1][1:-1]) - elif (s[0] == "nempty") and (i == (s2-1)): - snempty = int(s[1][1:-2]) - if (s[0] == "freqmax") and (i >= f1) and (i < (f2-1)): - freqmax = float(s[1][1:-1]) - elif (s[0] == "freqmax") and (i == (f2-1)): - freqmax = float(s[1][1:-2]) - if (s[0] == "nomeg") and (i >= f1) and (i < (f2-1)): - nomeg = int(s[1][1:-1]) - elif (s[0] == "nomeg") and (i == (f2-1)): - nomeg = int(s[1][1:-2]) - if (s[0] == "lmaxmb") and (i >= m1) and (i < (m2-1)): - lmaxmb = int(s[1][1:-1]) - elif (s[0] == "lmaxmb") and (i == (m2-1)): - lmaxmb = int(s[1][1:-2]) - if (s[0] == "epsmb") and (i >= m1) and (i < (m2-1)): - epsmb = float(s[1][1:-1]) - elif (s[0] == "epsmb") and (i == (m2-1)): - epsmb = float(s[1][1:-2]) - if (s[0] == "gmb") and (i >= m1) and (i < (m2-1)): - gmb = float(s[1][1:-1]) - elif (s[0] == "gmb") and (i == (m2-1)): - gmb = float(s[1][1:-2]) - if (s[0] == "sciavtype") and (i >= sc1) and (i < (sc2-1)): - sciavtype = s[1][1:-1] - elif (s[0] == "sciavtype") and (i == (sc2-1)): - sciavtype = s[1][1:-2] - if (s[0] == "fgrid") and (i >= k1) and (i < (k2-1)): - fgrid = s[1][1:-1] - elif (s[0] == "fgrid") and (i == (k2-1)): - fgrid = s[1][1:-2] - if (s[0] == "pwm") and (i >= bc1) and (i < (bc2-1)): - pwm = float(s[1][1:-1]) - elif (s[0] == "pwm") and (i == (bc2-1)): - pwm = float(s[1][1:-2]) - if (s[0] == "cutofftype") and (i >= bc1) and (i < (bc2-1)): - cutofftype = s[1][1:-1] - elif (s[0] == "cutofftype") and (i == (bc2-1)): - cutofftype = s[1][1:-2] -# gmb = gmb*self.gmaxvr -# pwm = pwm*gmb*self.gmaxvr -# print("gmb= ",type(gmb)) -# print("pwm= ", type(pwm)) -# print("self.gmaxvr= ",type(self.gmaxvr)) - backend.addValue("gw_frequency_grid_type", fgrid) - backend.addValue("gw_self_energy_c_number_of_empty_states", int(snempty)) - backend.addValue("gw_core_treatment", coreflag) - backend.addValue("gw_self_energy_singularity_treatment", singularity) - backend.addValue("gw_self_energy_c_analytical_continuation", actype) - backend.addValue("gw_self_energy_c_number_of_poles", int(npol)) - backend.addValue("gw_screened_Coulomb", scrtype) - backend.addValue("gw_polarizability_number_of_empty_states", int(pnempty)) - backend.addValue("gw_basis_set", "mixed") - backend.addValue("gw_mixed_basis_lmax", lmaxmb) - backend.addValue("gw_mixed_basis_tolerance", epsmb) - backend.addValue("gw_mixed_basis_gmax", gmb*self.gmaxvr) - backend.addValue("gw_screened_coulomb_volume_average",sciavtype) - backend.addValue("gw_bare_coulomb_gmax", pwm*gmb*self.gmaxvr) - backend.addValue("gw_ngridq", ngridq) - backend.addValue("gw_bare_coulomb_cutofftype", cutofftype) - backend.addValue("gw_max_frequency", freqmax) - backend.addValue("gw_number_of_frequencies", nomeg) - backend.addValue("gw_qp_equation_treatment", "linearization") -# backend.addArrayValues + with open(inputgwFile) as f: + exciting_parser_input.parseInput(f, backend, self.gmaxvr) backend.closeSection("section_method",selfGWSetGIndex) if os.path.exists(vertexGWFile): diff --git a/parser/parser-exciting/exciting_parser_input.py b/parser/parser-exciting/exciting_parser_input.py index 8ea72781a17e826b169499f50d39175c88196edc..1253c37d219e54d7b9f027b02c35eb9868a8b8df 100644 --- a/parser/parser-exciting/exciting_parser_input.py +++ b/parser/parser-exciting/exciting_parser_input.py @@ -1,50 +1,194 @@ import xml.sax 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 InputHandler(xml.sax.handler.ContentHandler): - def __init__(self, backend): + def __init__(self, backend, gmaxvr): + self.gmaxvr = gmaxvr self.backend = backend self.inputSectionGIndex = -1 - self.inInput = False + self.inGWInput = False + self.freqmax = 1.0 + self.singularity = 'mpd' + self.actype = 'pade' + self.npol = 0 + self.scrtype = "rpa" + self.snempty = 0 + self.pnempty = 0 + self.coreflag = "all" + self.fgrid = "gaule2" + self.lmaxmb = 3 + self.epsmb = 0.0001 + self.gmb = 1.0 + self.sciavtype = "isotropic" + self.cutofftype = "none" + self.pwm = 2.0 + self.ngridqDum = "2 2 2" + self.ngridq = [2,2,2] + self.nomeg = 16 + + self.freqgrid = "none" + self.selfenergy = "none" + self.mixbasis = "none" + self.barecoul = "none" + self.scrcoul = "none" def endDocument(self): - pass + if self.freqgrid == "none": + self.backend.addValue("gw_max_frequency", self.freqmax) + self.backend.addValue("gw_frequency_grid_type", self.fgrid) + self.backend.addValue("gw_number_of_frequencies", self.nomeg) + if self.selfenergy == "none": + self.backend.addValue("gw_self_energy_c_number_of_poles", int(self.npol)) + self.backend.addValue("gw_self_energy_c_number_of_empty_states", int(self.snempty)) + self.backend.addValue("gw_self_energy_singularity_treatment", self.singularity) + self.backend.addValue("gw_self_energy_c_analytical_continuation", self.actype) + if self.mixbasis == "none": + self.backend.addValue("gw_mixed_basis_lmax", self.lmaxmb) + self.backend.addValue("gw_mixed_basis_tolerance", self.epsmb) + self.backend.addValue("gw_mixed_basis_gmax", self.gmb*self.gmaxvr) + if self.barecoul == "none": + self.backend.addValue("gw_bare_coulomb_gmax", self.pwm*self.gmb*self.gmaxvr) + self.backend.addValue("gw_bare_coulomb_cutofftype", self.cutofftype) + if self.scrcoul == "none": + self.backend.addValue("gw_screened_coulomb_volume_average",self.sciavtype) + self.backend.addValue("gw_screened_Coulomb", self.scrtype) + self.backend.addValue("gw_basis_set", "mixed") + self.backend.addValue("gw_qp_equation_treatment", "linearization") + for j in range(0,3): + self.ngridq[j] = int(self.ngridqDum[j]) + self.backend.addValue("gw_ngridq", self.ngridq) def startElement(self, name, attrs): - if name == "structure": + fromH = unit_conversion.convert_unit_function("hartree", "J") + if name == "gw": self.inputSectionGIndex = self.backend.openSection("section_system") - self.inInput = True - elif name == "atom" and self.inInput: - g = attrs.getValue('coord') -# print ("coord=", g) -# self.backend.addValue("atom_positions",float(attrs.getValue('coord'))) -# self.backend.addValue("x_exciting_dos_energy",float(attrs.getValue('e'))) - # attrDict={} - # for name in attrs.getNames(): - # attrDict[name] = attrs.getValue(name) - # logging.error("start element %s attr %s", name, attrDict) + self.inGWInput = True + try: + self.coreflag = attrs.getValue('coreflag') + self.backend.addValue("gw_core_treatment", self.coreflag) + except: + self.coreflag = "all" + self.backend.addValue("gw_core_treatment", self.coreflag) + try: + self.pnempty = attrs.getValue('nempty') + self.backend.addValue("gw_polarizability_number_of_empty_states", int(self.pnempty)) + except: + self.pnempty = 0 + self.backend.addValue("gw_polarizability_number_of_empty_states", int(self.pnempty)) + try: + dummy = attrs.getValue('ngridq') + self.ngridqDum = dummy.split() + except: + self.ngridqDum = "2 2 2" + + elif name == "freqgrid": + self.freqgrid = "freqgrid" + try: + self.freqmax = attrs.getValue('freqmax') + self.backend.addValue("gw_max_frequency", float(self.freqmax)) + except: + self.freqmax = 1.0 + self.backend.addValue("gw_max_frequency", self.freqmax) + try: + self.fgrid = attrs.getValue('fgrid') + self.backend.addValue("gw_frequency_grid_type", self.fgrid) + except: + self.fgrid = "gaule2" + self.backend.addValue("gw_frequency_grid_type", self.fgrid) + try: + self.nomeg = attrs.getValue('nomeg') + self.backend.addValue("gw_number_of_frequencies", int(self.nomeg)) + except: + self.nomeg = 16 + self.backend.addValue("gw_number_of_frequencies", self.nomeg) + + elif name == "selfenergy": + self.selfenergy = "selfenergy" + try: + self.npol = attrs.getValue('npol') + self.backend.addValue("gw_self_energy_c_number_of_poles", int(self.npol)) + except: + self.npol = 0 + self.backend.addValue("gw_self_energy_c_number_of_poles", self.npol) + try: + self.snempty = attrs.getValue('nempty') + self.backend.addValue("gw_self_energy_c_number_of_empty_states", int(self.snempty)) + except: + self.snempty = 0 + self.backend.addValue("gw_self_energy_c_number_of_empty_states", self.snempty) + try: + self.singularity = attrs.getValue('singularity') + self.backend.addValue("gw_self_energy_singularity_treatment", self.singularity) + except: + self.singularity = 'mpd' + self.backend.addValue("gw_self_energy_singularity_treatment", self.singularity) + try: + self.actype = attrs.getValue('actype') + self.backend.addValue("gw_self_energy_c_analytical_continuation", self.actype) + except: + self.actype = 'pade' + self.backend.addValue("gw_self_energy_c_analytical_continuation", self.actype) + + elif name == "mixbasis": + self.mixbasis = "mixbasis" + try: + self.lmaxmb = attrs.getValue('lmaxmb') + self.backend.addValue("gw_mixed_basis_lmax", int(self.lmaxmb)) + except: + self.lmaxmb = 3 + self.backend.addValue("gw_mixed_basis_lmax", self.lmaxmb) + try: + self.epsmb = attrs.getValue('epsmb') + self.backend.addValue("gw_mixed_basis_tolerance", float(self.epsmb)) + except: + self.epsmb = 0.0001 + self.backend.addValue("gw_mixed_basis_tolerance", self.epsmb) + try: + self.gmb = attrs.getValue('gmb') + self.backend.addValue("gw_mixed_basis_gmax", float(self.gmb)*self.gmaxvr) + except: + self.gmb = 1.0 + self.backend.addValue("gw_mixed_basis_gmax", self.gmb*self.gmaxvr) + + elif name == "barecoul": + self.barecoul = "barecoul" + try: + self.pwm = attrs.getValue('pwm') + self.backend.addValue("gw_bare_coulomb_gmax", float(self.pwm)*float(self.gmb)*self.gmaxvr) + except: + self.pwm = 2.0 + self.backend.addValue("gw_bare_coulomb_gmax", self.pwm*float(self.gmb)*self.gmaxvr) + try: + self.cutofftype = attrs.getValue('cutofftype') + self.backend.addValue("gw_bare_coulomb_cutofftype", self.cutofftype) + except: + self.cutofftype = "none" + self.backend.addValue("gw_bare_coulomb_cutofftype", self.cutofftype) + + elif name == "scrcoul": + self.scrcoul = "scrcoul" + try: + self.sciavtype = attrs.getValue('sciavtype') + self.backend.addValue("gw_screened_coulomb_volume_average",self.sciavtype) + except: + self.sciavtype = "isotropic" + self.backend.addValue("gw_screened_coulomb_volume_average",self.sciavtype) + try: + self.scrtype = attrs.getValue('scrtype') + self.backend.addValue("gw_screened_Coulomb", self.scrtype) + except: + self.scrtype = "rpa" + self.backend.addValue("gw_screened_Coulomb", self.scrtype) def endElement(self, name): - if name == 'structure': - self.inInput = False - self.backend.closeSection("section_system",self.inputSectionGIndex) - self.inputSectionGIndex = -1 - # logging.error("end element %s", name) - -# def startElementNS(self, name, qname, attrs): -# attrDict={} -# for name in attrs.getNames(): -# attrDict[name] = attrs.getValue(name) -# logging.error("start element %s ns %s attr %s", name, qname, attrDict) - -# def endElementNS(self, name, qname): -# logging.error("end element %s ns %s", name, qname) - -# def characters(self, content): -# pass - -def parseInput(inF, backend): - handler = InputHandler(backend) + pass + +def parseInput(inF, backend, gmaxvr): + handler = InputHandler(backend, gmaxvr) logging.error("will parse") xml.sax.parse(inF, handler) logging.error("did parse") diff --git a/parser/parser-exciting/parser_exciting.py b/parser/parser-exciting/parser_exciting.py index 91c787e4fd1709df0d39271fa390d77f4ee1e7f0..00246d71d4ca8df036a105d725dcbbb789611551 100644 --- a/parser/parser-exciting/parser_exciting.py +++ b/parser/parser-exciting/parser_exciting.py @@ -6,7 +6,7 @@ from nomadcore.simple_parser import SimpleMatcher as SM, mainFunction from nomadcore.local_meta_info import loadJsonFile, InfoKindEl 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 +import os, sys, json, exciting_parser_dos,exciting_parser_bandstructure, exciting_parser_gw #, exciting_parser_input from ase import Atoms import logging @@ -122,6 +122,7 @@ class ExcitingParserContext(object): bandFile = os.path.join(dirPath, "bandstructure.xml") fermiSurfFile = os.path.join(dirPath, "FERMISURF.bxsf") eigvalFile = os.path.join(dirPath, "EIGVAL.OUT") +# inputFile = os.path.join(dirPath, "input.xml") # logging.error("done BASE onClose_section_single_configuration_calculation") if os.path.exists(dosFile): @@ -270,8 +271,9 @@ class ExcitingParserContext(object): smearing_internal_map = { "Gaussian": ['gaussian'], - "Methfessel-Paxton": ['methfessel-paxton'], - "Fermi-Dirac": ['fermi'], + "Methfessel-Paxton 1": ['methfessel-paxton'], + "Methfessel-Paxton 2": ['methfessel-paxton'], + "Fermi Dirac": ['fermi'], "Extended": ['tetrahedra'] }