diff --git a/parser/parser-quantum-espresso/FortranNamelistParser.py b/quantumespressoparser/FortranNamelistParser.py similarity index 100% rename from parser/parser-quantum-espresso/FortranNamelistParser.py rename to quantumespressoparser/FortranNamelistParser.py diff --git a/parser/parser-quantum-espresso/QuantumEspressoCommon.py b/quantumespressoparser/QuantumEspressoCommon.py similarity index 81% rename from parser/parser-quantum-espresso/QuantumEspressoCommon.py rename to quantumespressoparser/QuantumEspressoCommon.py index 43a0d819ef1f3c0d698292991e86ba64f52f0ddb..054812845eb0af9c739940c1cc11ddf183cf30b3 100644 --- a/parser/parser-quantum-espresso/QuantumEspressoCommon.py +++ b/quantumespressoparser/QuantumEspressoCommon.py @@ -1,13 +1,15 @@ -import setup_paths +import quantumespressoparser.setup_paths as setup_paths import calendar import json import os +import sys import re import numpy as np import logging from nomadcore.local_meta_info import loadJsonFile, InfoKindEl from nomadcore.unit_conversion.unit_conversion import convert_unit from nomadcore.simple_parser import mainFunction, SimpleMatcher as SM, CachingLevel +from nomadcore.baseclasses import ParserInterface ############################################################ # This file contains functions and constants that are needed @@ -39,13 +41,18 @@ def re_vec(name, units='', split="\s+"): # loading metadata from # nomad-meta-info/meta_info/nomad_meta_info/quantum_espresso.nomadmetainfo.json -META_INFO = loadJsonFile( - filePath=os.path.normpath(os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "../../../../nomad-meta-info/meta_info/nomad_meta_info/quantum_espresso.nomadmetainfo.json")), - dependencyLoader=None, - extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS, - uri=None)[0] +# META_INFO = loadJsonFile( +# filePath=os.path.normpath(os.path.join( +# os.path.dirname(os.path.abspath(__file__)), +# "../../../../nomad-meta-info/meta_info/nomad_meta_info/quantum_espresso.nomadmetainfo.json")), +# dependencyLoader=None, +# extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS, +# uri=None)[0] + +import nomad_meta_info +metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(nomad_meta_info.__file__)), "quantum_espresso.nomadmetainfo.json")) +metaInfoEnv, warnings = loadJsonFile(filePath = metaInfoPath, dependencyLoader = None, extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None) +META_INFO = metaInfoEnv PARSER_INFO_DEFAULT = { "name": "parser_quantum_espresso", @@ -71,13 +78,17 @@ QE_SMEARING_KIND = { } -class ParserQuantumEspresso(object): +class ParserQuantumEspresso(): """Base class for all Quantum Espresso parsers""" - def __init__(self,cachingLevelForMetaName=None, coverageIgnoreList=None, - re_program_name=None): + def __init__( + self, cachingLevelForMetaName=None, coverageIgnoreList=None, + re_program_name=None, metainfo_to_keep=None, backend=None, default_units=None, + metainfo_units=None, debug=True, log_level=logging.ERROR, store=True): + self.re_program_name = re_program_name self.parserInfo = PARSER_INFO_DEFAULT.copy() self.cachingLevelForMetaName = {} + self.backend = backend for name in META_INFO.infoKinds: # set all temporaries to caching-only if name.startswith('x_qe_t_'): @@ -92,11 +103,30 @@ class ParserQuantumEspresso(object): ] self.coverageIgnore = None - def parse(self): + # Old parser definition pre-Nomad-Fair (dts edit 11/02/2019) + # def parse(self): + # self.coverageIgnore = re.compile(r"^(?:" + r"|".join(self.coverageIgnoreList) + r")$") + # mainFunction(self.mainFileDescription(), META_INFO, self.parserInfo, + # cachingLevelForMetaName=self.cachingLevelForMetaName, + # superContext=self) + + def parse(self, mainfile): self.coverageIgnore = re.compile(r"^(?:" + r"|".join(self.coverageIgnoreList) + r")$") - mainFunction(self.mainFileDescription(), META_INFO, self.parserInfo, - cachingLevelForMetaName=self.cachingLevelForMetaName, - superContext=self) + logging.info('quantum espresso parser started') + logging.getLogger('nomadcore').setLevel(logging.WARNING) + backend = self.backend(META_INFO) + # print("Main File Description in parse()") + # print(self.mainFileDescription()) + # with patch.object(sys, 'argv', ['<exe>', '--uri', 'nmd://uri', mainfile]): + mainFunction( + self.mainFileDescription(), + META_INFO, + self.parserInfo, + cachingLevelForMetaName=self.cachingLevelForMetaName, + superContext=self, + superBackend=backend, + mainFile=mainfile) + return backend def adHoc_suicide_qe_program_name(self, parser): if self.re_program_name is not None: @@ -155,6 +185,7 @@ class ParserQuantumEspresso(object): SM(name='copyright_msg040', coverageIgnore=True, startReStr=r"\s*in publications or presentations arising from this work. More details at", ), + # Changed CI to False SM(name='copyright_msg050', coverageIgnore=True, startReStr=r"\s*http://www.quantum-espresso.org/quote(?:\.php)?", ), @@ -250,4 +281,4 @@ class ParserQuantumEspresso(object): def addSectionDict(self, backend, section_name, section_dict): gIndex = backend.openSection(section_name) self.addDict(backend, section_dict) - backend.closeSection(section_name, gIndex) + backend.closeSection(section_name, gIndex) \ No newline at end of file diff --git a/parser/parser-quantum-espresso/QuantumEspressoXC.md b/quantumespressoparser/QuantumEspressoXC.md similarity index 100% rename from parser/parser-quantum-espresso/QuantumEspressoXC.md rename to quantumespressoparser/QuantumEspressoXC.md diff --git a/parser/parser-quantum-espresso/QuantumEspressoXC.py b/quantumespressoparser/QuantumEspressoXC.py similarity index 100% rename from parser/parser-quantum-espresso/QuantumEspressoXC.py rename to quantumespressoparser/QuantumEspressoXC.py diff --git a/quantumespressoparser/__init__.py b/quantumespressoparser/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..92126e2d35cc78a221d78764c8f45eb6257f6e49 --- /dev/null +++ b/quantumespressoparser/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2016-2018 Lauri Himanen, Fawzi Mohamed, Ankit Kariryaa +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from quantumespressoparser.parser_quantum_espresso import QuantumEspressoParserPWSCF diff --git a/parser/parser-quantum-espresso/devutil/garbage_check/00_list b/quantumespressoparser/devutil/garbage_check/00_list similarity index 100% rename from parser/parser-quantum-espresso/devutil/garbage_check/00_list rename to quantumespressoparser/devutil/garbage_check/00_list diff --git a/parser/parser-quantum-espresso/devutil/garbage_check/10_check b/quantumespressoparser/devutil/garbage_check/10_check similarity index 100% rename from parser/parser-quantum-espresso/devutil/garbage_check/10_check rename to quantumespressoparser/devutil/garbage_check/10_check diff --git a/parser/parser-quantum-espresso/devutil/garbage_check/20_doublecheck b/quantumespressoparser/devutil/garbage_check/20_doublecheck similarity index 100% rename from parser/parser-quantum-espresso/devutil/garbage_check/20_doublecheck rename to quantumespressoparser/devutil/garbage_check/20_doublecheck diff --git a/parser/parser-quantum-espresso/devutil/garbage_check/90_move b/quantumespressoparser/devutil/garbage_check/90_move similarity index 100% rename from parser/parser-quantum-espresso/devutil/garbage_check/90_move rename to quantumespressoparser/devutil/garbage_check/90_move diff --git a/parser/parser-quantum-espresso/devutil/lRno b/quantumespressoparser/devutil/lRno similarity index 100% rename from parser/parser-quantum-espresso/devutil/lRno rename to quantumespressoparser/devutil/lRno diff --git a/parser/parser-quantum-espresso/devutil/reparse b/quantumespressoparser/devutil/reparse similarity index 100% rename from parser/parser-quantum-espresso/devutil/reparse rename to quantumespressoparser/devutil/reparse diff --git a/parser/parser-quantum-espresso/devutil/testsuite_move_done b/quantumespressoparser/devutil/testsuite_move_done similarity index 100% rename from parser/parser-quantum-espresso/devutil/testsuite_move_done rename to quantumespressoparser/devutil/testsuite_move_done diff --git a/parser/parser-quantum-espresso/devutil/testsuite_run b/quantumespressoparser/devutil/testsuite_run similarity index 100% rename from parser/parser-quantum-espresso/devutil/testsuite_run rename to quantumespressoparser/devutil/testsuite_run diff --git a/parser/parser-quantum-espresso/parser_quantum_espresso.py b/quantumespressoparser/parser_quantum_espresso.py similarity index 99% rename from parser/parser-quantum-espresso/parser_quantum_espresso.py rename to quantumespressoparser/parser_quantum_espresso.py index aaed32125deb390acb7b6db785546ce32bb44a61..49d2e1cb071a3648b73552cc8dda857f351589d8 100644 --- a/parser/parser-quantum-espresso/parser_quantum_espresso.py +++ b/quantumespressoparser/parser_quantum_espresso.py @@ -1,4 +1,3 @@ -import setup_paths from nomadcore.simple_parser import mainFunction, SimpleMatcher as SM from nomadcore.local_meta_info import loadJsonFile, InfoKindEl import os @@ -9,10 +8,11 @@ import logging import nomadcore.unit_conversion.unit_conversion as unit_conversion import math import numpy as np -import QuantumEspressoCommon as QeC +import quantumespressoparser.setup_paths as quantumespressoparser +import quantumespressoparser.QuantumEspressoCommon as QeC from nomadcore.parser_backend import valueForStrValue -from QuantumEspressoCommon import RE_f, RE_i, cRE_f, cRE_i -from QuantumEspressoXC import translate_qe_xc_num +from quantumespressoparser.QuantumEspressoCommon import RE_f, RE_i, cRE_f, cRE_i +from quantumespressoparser.QuantumEspressoXC import translate_qe_xc_num from nomadcore.parser_backend import valueForStrValue @@ -48,9 +48,12 @@ QE_MD_RELAX_SAMPLING_METHOD = { class QuantumEspressoParserPWSCF(QeC.ParserQuantumEspresso): """main place to keep the parser status, open ancillary files,...""" - def __init__(self): + def __init__(self, metainfo_to_keep=None, backend=None, default_units=None, + metainfo_units=None, debug=True, log_level=logging.ERROR, store=True): QeC.ParserQuantumEspresso.__init__( - self, re_program_name=re.compile(r"^PWSCF$")) + self, re_program_name=re.compile(r"^PWSCF$"), metainfo_to_keep=metainfo_to_keep, + backend=backend, default_units=default_units, metainfo_units=metainfo_units, + debug=debug, log_level=log_level, store=store) def initialize_values(self): """allows to reset values if the same superContext is used to parse diff --git a/parser/parser-quantum-espresso/setup_paths.py b/quantumespressoparser/setup_paths.py similarity index 100% rename from parser/parser-quantum-espresso/setup_paths.py rename to quantumespressoparser/setup_paths.py diff --git a/quntumespressoparser.egg-info/PKG-INFO b/quntumespressoparser.egg-info/PKG-INFO new file mode 100644 index 0000000000000000000000000000000000000000..ade453476a39b0fe8570fd90f5f315a733356f98 --- /dev/null +++ b/quntumespressoparser.egg-info/PKG-INFO @@ -0,0 +1,10 @@ +Metadata-Version: 1.0 +Name: quntumespressoparser +Version: 0.1 +Summary: NOMAD parser implementation for QuantumEspresso. +Home-page: UNKNOWN +Author: Glaweh@debian.org +Author-email: dts@physik.hu-berlin.de +License: GPL3 +Description: UNKNOWN +Platform: UNKNOWN diff --git a/quntumespressoparser.egg-info/SOURCES.txt b/quntumespressoparser.egg-info/SOURCES.txt new file mode 100644 index 0000000000000000000000000000000000000000..720fd18583b5fdb759a061397dfabc8cf98e19b5 --- /dev/null +++ b/quntumespressoparser.egg-info/SOURCES.txt @@ -0,0 +1,13 @@ +README.md +setup.py +./quantumespressoparser/FortranNamelistParser.py +./quantumespressoparser/QuantumEspressoCommon.py +./quantumespressoparser/QuantumEspressoXC.py +./quantumespressoparser/__init__.py +./quantumespressoparser/parser_quantum_espresso.py +./quantumespressoparser/setup_paths.py +./quntumespressoparser.egg-info/PKG-INFO +./quntumespressoparser.egg-info/SOURCES.txt +./quntumespressoparser.egg-info/dependency_links.txt +./quntumespressoparser.egg-info/requires.txt +./quntumespressoparser.egg-info/top_level.txt \ No newline at end of file diff --git a/quntumespressoparser.egg-info/dependency_links.txt b/quntumespressoparser.egg-info/dependency_links.txt new file mode 100644 index 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/quntumespressoparser.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/quntumespressoparser.egg-info/requires.txt b/quntumespressoparser.egg-info/requires.txt new file mode 100644 index 0000000000000000000000000000000000000000..f23d3478b1b70b8eab22077805184aa208d1876e --- /dev/null +++ b/quntumespressoparser.egg-info/requires.txt @@ -0,0 +1 @@ +nomadcore diff --git a/quntumespressoparser.egg-info/top_level.txt b/quntumespressoparser.egg-info/top_level.txt new file mode 100644 index 0000000000000000000000000000000000000000..fe966b5f64756a3239286ae85b8ed0d15e4b615e --- /dev/null +++ b/quntumespressoparser.egg-info/top_level.txt @@ -0,0 +1 @@ +quantumespressoparser diff --git a/setup.py b/setup.py new file mode 100644 index 0000000000000000000000000000000000000000..012925fd2321b267de3a73ba3001a9fe9976678a --- /dev/null +++ b/setup.py @@ -0,0 +1,36 @@ +# Copyright 2016-2018 Lauri Himanen, Fawzi Mohamed, Ankit Kariryaa +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from setuptools import setup, find_packages + + +def main(): + setup( + name='quntumespressoparser', + version='0.1', + description='NOMAD parser implementation for QuantumEspresso.', + author='Glaweh@debian.org', + author_email='dts@physik.hu-berlin.de', + license='GPL3', + package_dir={'': './'}, + packages=find_packages(), + include_package_data=True, + install_requires=[ + 'nomadcore', + ], + ) + + +if __name__ == '__main__': + main() diff --git a/src/main/scala/eu/nomad_lab/parsers/QuantumEspressoParser.scala b/src/main/scala/eu/nomad_lab/parsers/QuantumEspressoParser.scala deleted file mode 100644 index 39abecc5779208ff501dd77cde8b167cde14948b..0000000000000000000000000000000000000000 --- a/src/main/scala/eu/nomad_lab/parsers/QuantumEspressoParser.scala +++ /dev/null @@ -1,88 +0,0 @@ -/* - Copyright 2016-2017 The NOMAD Developers Group - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ -package eu.nomad_lab.parsers - -import eu.{ nomad_lab => lab } -import eu.nomad_lab.{ JsonUtils, DefaultPythonInterpreter } -import org.{ json4s => jn } -import scala.collection.breakOut - -object QuantumEspressoParser extends SimpleExternalParserGenerator( - name = "QuantumEspressoParser", - parserInfo = jn.JObject( - ("name" -> jn.JString("QuantumEspressoParser")) :: - ("parserId" -> jn.JString("QuantumEspressoParser" + lab.QuantumEspressoVersionInfo.version)) :: - ("versionInfo" -> jn.JObject( - ("nomadCoreVersion" -> jn.JObject(lab.NomadCoreVersionInfo.toMap.map { - case (k, v) => k -> jn.JString(v.toString) - }(breakOut): List[(String, jn.JString)])) :: - (lab.QuantumEspressoVersionInfo.toMap.map { - case (key, value) => - (key -> jn.JString(value.toString)) - }(breakOut): List[(String, jn.JString)]) - )) :: Nil - ), - mainFileTypes = Seq("text/.*"), - mainFileRe = """^\s*Program (?<programName>\S+)\s+v\.(?<version>\S+)(?:\s+\(svn\s+rev\.\s+(?<revision>\d+)\s*\))?\s+starts[^\n]+ -(?:\s*\n?)*This program is part of the open-source Quantum""".r, - cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/parsers/quantum-espresso/parser/parser-quantum-espresso/parser_quantum_espresso.py", - "--uri", "${mainFileUri}", "${mainFilePath}"), - resList = Seq( - "parser-quantum-espresso/QuantumEspressoCommon.py", - "parser-quantum-espresso/QuantumEspressoXC.py", - "parser-quantum-espresso/parser_quantum_espresso.py", - "parser-quantum-espresso/setup_paths.py", - "nomad_meta_info/public.nomadmetainfo.json", - "nomad_meta_info/common.nomadmetainfo.json", - "nomad_meta_info/meta_types.nomadmetainfo.json", - "nomad_meta_info/quantum_espresso.nomadmetainfo.json" - ) ++ DefaultPythonInterpreter.commonFiles(), - dirMap = Map( - "parser-quantum-espresso" -> "parsers/quantum-espresso/parser/parser-quantum-espresso", - "nomad_meta_info" -> "nomad-meta-info/meta_info/nomad_meta_info" - ) ++ DefaultPythonInterpreter.commonDirMapping(), - metaInfoEnv = Some(lab.meta.KnownMetaInfoEnvs.quantumEspresso) -) { - - val fallbackRe = """\s*Program (?<programName>\S+)\s+v\.(?<version>\S+)(?:\s+\(svn\s+rev\.\s+(?<revision>\d+)\s*\))?\s+starts""".r - - override def isMainFile(filePath: String, bytePrefix: Array[Byte], stringPrefix: Option[String]): Option[ParserMatch] = { - stringPrefix match { - case Some(str) => - mainFileRe.findFirstMatchIn(str) match { - case Some(m) => - val extraInfo: List[(String, jn.JString)] = m.groupNames.map { (name: String) => - name -> jn.JString(m.group(name)) - }(breakOut) - Some(ParserMatch(mainFileMatchPriority, mainFileMatchWeak, jn.JObject(extraInfo))) - case None => - fallbackRe.findFirstMatchIn(str) match { - case Some(m) => - val extraInfo: List[(String, jn.JString)] = m.groupNames.map { (name: String) => - name -> jn.JString(m.group(name)) - }(breakOut) - Some(ParserMatch(mainFileMatchPriority - 1, true, jn.JObject(extraInfo))) - case None => - None - } - } - case None => - logger.warn(s"parser $name asked about $filePath which has no stringPrefix") - None - } - - } -} diff --git a/src/test/scala/eu/nomad_lab/parsers/QuantumEspressoParserSpec.scala b/src/test/scala/eu/nomad_lab/parsers/QuantumEspressoParserSpec.scala deleted file mode 100644 index 21c3a1eefdcabf9ba764255fef784c98f49f4ef9..0000000000000000000000000000000000000000 --- a/src/test/scala/eu/nomad_lab/parsers/QuantumEspressoParserSpec.scala +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright 2016-2017 The NOMAD Developers Group - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ -package eu.nomad_lab.parsers - -import org.specs2.mutable.Specification - -/** - * pw.x output Test files: - * parsers/quantum-espresso/test/examples/PWSCF/benchmark.out.r11920.inp=dft1.in - * parsers/quantum-espresso/test/examples/PWSCF/scf-ncpp.ref.1193929391 - * - */ - -object QuantumEspressoParserSpec extends Specification { - "QuantumEspressoParserTest" >> { - "test1 (pw.x 5.2.1) with json-events" >> { - ParserRun.parse(QuantumEspressoParser, "parsers/quantum-espresso/test/examples/PWSCF/benchmark.out.r11920.inp=dft1.in", "json-events") must_== ParseResult.ParseSuccess - } - "test1 (pw.x 5.2.1) with json" >> { - ParserRun.parse(QuantumEspressoParser, "parsers/quantum-espresso/test/examples/PWSCF/benchmark.out.r11920.inp=dft1.in", "json") must_== ParseResult.ParseSuccess - } - "test2 (pw.x 4.0) with json-events" >> { - ParserRun.parse(QuantumEspressoParser, "parsers/quantum-espresso/test/examples/PWSCF/scf-ncpp.ref.1193929391", "json-events") must_== ParseResult.ParseSuccess - } - "test2 (pw.x 4.0) with json" >> { - ParserRun.parse(QuantumEspressoParser, "parsers/quantum-espresso/test/examples/PWSCF/scf-ncpp.ref.1193929391", "json") must_== ParseResult.ParseSuccess - } - "test3 (pw.x 5.2.1, binary, USPP) with json-events" >> { - ParserRun.parse(QuantumEspressoParser, "parsers/quantum-espresso/test/examples/PWSCF/benchmark.out.r11920.inp=uspp1.in.1451158822", "json-events") must_== ParseResult.ParseSuccess - } - "test3 (pw.x 5.2.1, binary, USPP) with json" >> { - ParserRun.parse(QuantumEspressoParser, "parsers/quantum-espresso/test/examples/PWSCF/benchmark.out.r11920.inp=uspp1.in.1451158822", "json") must_== ParseResult.ParseSuccess - } - } -} diff --git a/test/examples/PWSCF/benchmark.out.r11920.inp=dft1.in b/test/examples/PWSCF/benchmark.out similarity index 100% rename from test/examples/PWSCF/benchmark.out.r11920.inp=dft1.in rename to test/examples/PWSCF/benchmark.out diff --git a/test/examples/PWSCF/benchmark.out.r11920.inp=uspp1.in.1451158822 b/test/examples/PWSCF/benchmark2.out similarity index 100% rename from test/examples/PWSCF/benchmark.out.r11920.inp=uspp1.in.1451158822 rename to test/examples/PWSCF/benchmark2.out diff --git a/test/examples/PWSCF/scf-ncpp.ref.1193929391 b/test/examples/PWSCF/scf-ncpp.ref similarity index 100% rename from test/examples/PWSCF/scf-ncpp.ref.1193929391 rename to test/examples/PWSCF/scf-ncpp.ref