From c33c2e761bc1b8a3d8227c0c0aee3c5d4922a35c Mon Sep 17 00:00:00 2001
From: lopa <pardini@physik.hu-berlin.de>
Date: Fri, 2 Feb 2018 10:08:11 +0100
Subject: [PATCH] added gw bandgap, frequencies and more

---
 parser/parser-exciting/exciting_parser_gw.py | 69 ++++++++++++++++++++
 parser/parser-exciting/parser_exciting.py    |  8 +++
 2 files changed, 77 insertions(+)

diff --git a/parser/parser-exciting/exciting_parser_gw.py b/parser/parser-exciting/exciting_parser_gw.py
index b388104..9a8c3e7 100644
--- a/parser/parser-exciting/exciting_parser_gw.py
+++ b/parser/parser-exciting/exciting_parser_gw.py
@@ -20,6 +20,14 @@ class GWParser(object):
         self.vertexDist = []
         self.vertexLabels = []
         self.vertexNum = 0
+        self.parser = None
+        self.secSingleConfIndex = None
+
+    def startedParsing(self, path, parser):
+        """called when parsing starts"""
+        self.parser = parser
+        # allows to reset values if the same superContext is used to parse different files
+#        self.initialize_values()
 
     def parseGW(self, gwFile, backend,  dftMethodSectionGindex, dftSingleConfigurationGindex, xcName, unitCellVol,gmaxvr):
 #        logging.error("GW onClose_section_single_configuration_calculation")
@@ -324,3 +332,64 @@ class GWParser(object):
         backend.closeNonOverlappingSection("section_single_configuration_calculation")
 #        logging.error("done GW onClose_section_single_configuration_calculation")
 
+#    def onOpen_section_method(self, backend, gIndex, section):
+#        fava = section["gw_frequency_number"]
+#        print("fava=",fava)
+
+#    def onClose_section_single_configuration_calculation(self, backend, gIndex, section):
+#        if dftSingleConfigurationGindex is not None:
+##        if self.secSingleConfIndex is None:
+##            self.secSingleConfIndex = gIndex
+##            singleGIndex = backend.openSection("section_single_configuration_calculation")
+#            fermi = section["gw_fermi_energy"]
+#            fundamental = section["gw_fundamental_gap"]
+#            optical = section["gw_optical_gap"]
+#            backend.addValue("gw_fermi_energy", fermi)
+#            backend.addValue("gw_fundamental_gap", fundamental)
+#            backend.addValue("gw_optical_gap", optical)
+##            backend.closeSection("section_single_configuration_calculation",singleGIndex)
+#        else:
+#            singleGIndex = backend.openSection("section_single_configuration_calculation")
+#            fermi = section["gw_fermi_energy"]
+#            fundamental = section["gw_fundamental_gap"]
+#            optical = section["gw_optical_gap"]
+#            backend.addValue("gw_fermi_energy", fermi)
+#            backend.addValue("gw_fundamental_gap", fundamental)
+ #           backend.addValue("gw_optical_gap", optical)
+ #           backend.closeSection("section_single_configuration_calculation",singleGIndex)
+
+def buildGWMatchers():     
+    return SM(     
+    name = 'root',     
+    weak = True,    
+    startReStr = "\=\s*Main GW output file\s*\=",
+#    sections = ["section_run"], 
+    subMatchers = [
+    SM(
+      startReStr = "\-\s*frequency grid\s*\-",
+      endReStr = "\-\s*Peak memory estimate \(Mb, per process\)\:\s*\-",
+      sections = ["section_method"],
+      subMatchers = [
+#        SM(r"\s*Type\:\s*\<\s*(?P<gw_dummy>[-a-zA-Z]+)\s*\>"),
+        SM(r"\s*(?P<gw_frequency_number>[0-9]+)\s*(?P<gw_frequency_values__hartree>[0-9]\.[0-9]*([E]?[-]?[-0-9]+))\s*(?P<gw_frequency_weights>[0-9]\.[0-9]*([E]?[-]?[-0-9]+))", repeats = True)
+    ]),
+    SM(
+      startReStr = "\-\s*G0W0\s*\-",
+      endReStr = "\=\s*GW timing info \(seconds\)\s*\=",        
+      sections = ["section_single_configuration_calculation"],     
+      subMatchers = [
+        SM(r"\s*Fermi energy\:\s*(?P<gw_fermi_energy__hartree>[-0-9.]+)"),
+        SM(r"\s* Fundamental BandGap \(eV\)\:\s*(?P<gw_fundamental_gap__eV>[0-9.]+)"),         
+        SM(r"\s*Direct BandGap \(eV\)\:\s*(?P<gw_fundamental_gap__eV>[0-9.]+)"),
+        SM(r"\s* Optical BandGap \(eV\)\:\s*(?P<gw_optical_gap__eV>[0-9.]+)")
+    ])
+    ])
+def get_cachingLevelForMetaName(metaInfoEnv, CachingLvl):
+    cachingLevelForMetaName = {}
+#                                'section_single_configuration_calculation': CachingLvl
+#                               }
+#    cachingLevelForMetaName["gw_fundamental_gap"] = CachingLevel.Cache
+#    cachingLevelForMetaName["gw_optical_gap"] = CachingLevel.Cache
+#    cachingLevelForMetaName["gw_fermi_energy"] = CachingLevel.Cache
+    return cachingLevelForMetaName
+
diff --git a/parser/parser-exciting/parser_exciting.py b/parser/parser-exciting/parser_exciting.py
index afa0cc1..a530b3d 100644
--- a/parser/parser-exciting/parser_exciting.py
+++ b/parser/parser-exciting/parser_exciting.py
@@ -58,6 +58,7 @@ class ExcitingParserContext(object):
 #    print("xcName= ",self.xcName)
     for gFile in [gw_File, gwFile]:
       if os.path.exists(gFile):
+#        print("gFile=",gFile)
 #        logging.error("Starting GW")
         gwParser = exciting_parser_gw.GWParser()
         gwParser.parseGW(gFile, backend,
@@ -67,6 +68,13 @@ class ExcitingParserContext(object):
                          unitCellVol = self.unit_cell_vol,
                          gmaxvr = self.gmaxvr)
 
+        subParser = AncillaryParser(
+            fileDescription = exciting_parser_gw.buildGWMatchers(),
+            parser = self.parser,
+            cachingLevelForMetaName = exciting_parser_gw.get_cachingLevelForMetaName(self.metaInfoEnv, CachingLevel.PreOpenedIgnore),
+            superContext = gwParser)
+        with open(gFile) as fIn:
+            subParser.parseFile(fIn)
 #        logging.error("Finished GW")
         break
 #    logging.error("done BASE onClose_section_run")
-- 
GitLab