diff --git a/cpmdparser/parser.py b/cpmdparser/parser.py index 27e04d58e49b41deda753fef8a011d98e804e137..715291414305293b6263002359cceb0ad1c8cdef 100644 --- a/cpmdparser/parser.py +++ b/cpmdparser/parser.py @@ -19,6 +19,7 @@ import re import logging import importlib from nomadcore.baseclasses import ParserInterface +logger = logging.getLogger("nomad") class CPMDRunType(object): @@ -35,21 +36,8 @@ class CPMDParser(ParserInterface): After the implementation has been setup, you can parse the files with parse(). """ - def __init__( - self, metainfo_to_keep=None, backend=None, default_units=None, - metainfo_units=None, debug=True, logger=None, - log_level=logging.ERROR, store=True - ): - super(CPMDParser, self).__init__( - metainfo_to_keep, backend, default_units, metainfo_units, - debug, log_level, store - ) - - if logger is not None: - self.logger = logger - self.logger.debug('received logger') - else: - self.logger = logging.getLogger(__name__) + def __init__(self, metainfo_to_keep=None, backend=None, default_units=None, metainfo_units=None, debug=True, log_level=logging.ERROR, store=True): + super(CPMDParser, self).__init__(metainfo_to_keep, backend, default_units, metainfo_units, debug, log_level, store) def setup_version(self): """Setups the version by looking at the output file and the version @@ -58,7 +46,7 @@ class CPMDParser(ParserInterface): # Search for the CPMD version specification and the run type for the # calculation. The correct and optimized parser is initialized based on # this information. - regex_version = re.compile(r"\s+VERSION ([\d\.]+)") + regex_version = re.compile("\s+VERSION ([\d\.]+)") regex_single_point = re.compile(r" SINGLE POINT DENSITY OPTIMIZATION") regex_geo_opt = re.compile(r" OPTIMIZATION OF IONIC POSITIONS") regex_md = re.compile(r"( CAR-PARRINELLO MOLECULAR DYNAMICS)|( BORN-OPPENHEIMER MOLECULAR DYNAMICS)") @@ -106,12 +94,12 @@ class CPMDParser(ParserInterface): if version_id is None: msg = "Could not find a version specification from the given main file." - self.logger.exception(msg) + logger.exception(msg) raise RuntimeError(msg) if run_type is None: msg = "Could not find a run type specification from the given main file at: {}".format(self.parser_context.main_file) - self.logger.exception(msg) + logger.exception(msg) raise RuntimeError(msg) # Setup the root folder to the fileservice that is used to access files @@ -139,16 +127,17 @@ class CPMDParser(ParserInterface): try: parser_module = importlib.import_module(base) except ImportError: - self.logger.warning("Could not find a parser for version '{}'. Trying to default to the base implementation for CPMD 4.1".format(version_id)) + logger.warning("Could not find a parser for version '{}'. Trying to default to the base implementation for CPMD 4.1".format(version_id)) base = "cpmdparser.versions.cpmd41.{}".format(run_type.module_name) try: parser_module = importlib.import_module(base) except ImportError: - self.logger.exception("Tried to default to the CPMD 4.1 implementation but could not find the correct module.") + logger.exception("Tried to default to the CPMD 4.1 implementation but could not find the correct module.") raise try: parser_class = getattr(parser_module, "{}".format(run_type.class_name)) except AttributeError: - self.logger.exception("A parser class '{}' could not be found in the module '[]'.".format(run_type.class_name, parser_module)) + logger.exception("A parser class '{}' could not be found in the module '[]'.".format(run_type.class_name, parser_module)) raise self.main_parser = parser_class(self.parser_context) + diff --git a/cpmdparser/scalainterface.py b/cpmdparser/scalainterface.py deleted file mode 100644 index d15ab1bebd424583c1a1aca7996c774cd9c432eb..0000000000000000000000000000000000000000 --- a/cpmdparser/scalainterface.py +++ /dev/null @@ -1,31 +0,0 @@ -# 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. - -""" -This is the access point to the parser for the scala layer in the -nomad project. -""" -from __future__ import absolute_import -import sys -import setup_paths -from nomadcore.parser_backend import JsonParseEventsWriterBackend -from cpmdparser import CPMDParser - - -if __name__ == "__main__": - - # Initialise the parser with the main filename and a JSON backend - main_file = sys.argv[1] - parser = CPMDParser(backend=JsonParseEventsWriterBackend) - parser.parse(main_file) diff --git a/cpmdparser/setup_paths.py b/cpmdparser/setup_paths.py deleted file mode 100644 index 4b51dde6b7033423925fdd677509342eea4da6d0..0000000000000000000000000000000000000000 --- a/cpmdparser/setup_paths.py +++ /dev/null @@ -1,31 +0,0 @@ -# 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. - -""" -Setups the python-common library in the PYTHONPATH system variable. -""" -import sys -import os -import os.path - -baseDir = os.path.dirname(os.path.abspath(__file__)) -commonDir = os.path.normpath(os.path.join(baseDir, "../../../../../python-common/common/python")) -parserDir = os.path.normpath(os.path.join(baseDir, "../../parser-cpmd")) - -# Using sys.path.insert(1, ...) instead of sys.path.insert(0, ...) based on -# this discusssion: -# http://stackoverflow.com/questions/10095037/why-use-sys-path-appendpath-instead-of-sys-path-insert1-path -if commonDir not in sys.path: - sys.path.insert(1, commonDir) - sys.path.insert(1, parserDir) diff --git a/src/main/scala/eu/nomad_lab/parsers/CpmdParser.scala b/src/main/scala/eu/nomad_lab/parsers/CpmdParser.scala deleted file mode 100644 index 2779dbe69175c4ddaa4bf3e0dc85132bb275cb38..0000000000000000000000000000000000000000 --- a/src/main/scala/eu/nomad_lab/parsers/CpmdParser.scala +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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. - */ - -package eu.nomad_lab.parsers - -import eu.{ nomad_lab => lab } -import eu.nomad_lab.DefaultPythonInterpreter -import org.{ json4s => jn } -import scala.collection.breakOut - -object CpmdParser extends SimpleExternalParserGenerator( - name = "CpmdParser", - parserInfo = jn.JObject( - ("name" -> jn.JString("CpmdParser")) :: - ("parserId" -> jn.JString("CpmdParser" + lab.CpmdVersionInfo.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.CpmdVersionInfo.toMap.map { - case (key, value) => - (key -> jn.JString(value.toString)) - }(breakOut): List[(String, jn.JString)]) - )) :: Nil - ), - mainFileTypes = Seq("text/.*"), - mainFileRe = """\s* \*\*\*\*\*\* \*\*\*\*\*\* \*\*\*\* \*\*\*\* \*\*\*\*\*\*\s* -\s* \*\*\*\*\*\*\* \*\*\*\*\*\*\* \*\*\*\*\*\*\*\*\*\* \*\*\*\*\*\*\*\s* -\s* \*\*\* \*\* \*\*\* \*\* \*\*\*\* \*\* \*\* \*\*\*\s* -\s* \*\* \*\* \*\*\* \*\* \*\* \*\* \*\* \*\*\s* -\s* \*\* \*\*\*\*\*\*\* \*\* \*\* \*\* \*\*\s* -\s* \*\*\* \*\*\*\*\*\* \*\* \*\* \*\* \*\*\*\s* -\s* \*\*\*\*\*\*\* \*\* \*\* \*\* \*\*\*\*\*\*\*\s* -\s* \*\*\*\*\*\* \*\* \*\* \*\* \*\*\*\*\*\*\s* -""".r, - cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/parsers/cpmd/parser/parser-cpmd/cpmdparser/scalainterface.py", - "${mainFilePath}"), - cmdCwd = "${mainFilePath}/..", - resList = Seq( - "parser-cpmd/cpmdparser/__init__.py", - "parser-cpmd/cpmdparser/setup_paths.py", - "parser-cpmd/cpmdparser/parser.py", - "parser-cpmd/cpmdparser/scalainterface.py", - "parser-cpmd/cpmdparser/versions/__init__.py", - "parser-cpmd/cpmdparser/versions/cpmd41/__init__.py", - "parser-cpmd/cpmdparser/versions/cpmd41/geooptparser.py", - "parser-cpmd/cpmdparser/versions/cpmd41/mdparser.py", - "parser-cpmd/cpmdparser/versions/cpmd41/singlepointparser.py", - "parser-cpmd/cpmdparser/versions/cpmd41/inputparser.py", - "parser-cpmd/cpmdparser/versions/cpmd41/commonparser.py", - "parser-cpmd/cpmdparser/versions/cpmd41/input_data/cpmd_input_tree.pickle", - "parser-cpmd/cpmdparser/generic/__init__.py", - "parser-cpmd/cpmdparser/generic/inputparsing.py", - "nomad_meta_info/public.nomadmetainfo.json", - "nomad_meta_info/common.nomadmetainfo.json", - "nomad_meta_info/meta_types.nomadmetainfo.json", - "nomad_meta_info/cpmd.general.nomadmetainfo.json", - "nomad_meta_info/cpmd.nomadmetainfo.json" - ) ++ DefaultPythonInterpreter.commonFiles(), - dirMap = Map( - "parser-cpmd" -> "parsers/cpmd/parser/parser-cpmd", - "nomad_meta_info" -> "nomad-meta-info/meta_info/nomad_meta_info" - ) ++ DefaultPythonInterpreter.commonDirMapping() -) diff --git a/src/test/scala/eu/nomad_lab/parsers/CpmdParserSpec.scala b/src/test/scala/eu/nomad_lab/parsers/CpmdParserSpec.scala deleted file mode 100644 index 42d6f500884c6d43fab0681efa75f74236a516f1..0000000000000000000000000000000000000000 --- a/src/test/scala/eu/nomad_lab/parsers/CpmdParserSpec.scala +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ - -package eu.nomad_lab.parsers - -import org.specs2.mutable.Specification - -object CpmdParserSpec extends Specification { - "CpmdParserTest" >> { - "test with json-events" >> { - ParserRun.parse(CpmdParser, "parsers/cpmd/test/examples/single_point/output.out", "json-events") must_== ParseResult.ParseSuccess - } - } - - "test energy_force with json" >> { - ParserRun.parse(CpmdParser, "parsers/cpmd/test/examples/single_point/output.out", "json") must_== ParseResult.ParseSuccess - } - "test geo_opt with json" >> { - ParserRun.parse(CpmdParser, "parsers/cpmd/test/examples/geo_opt/output.out", "json") must_== ParseResult.ParseSuccess - } - "test md with json" >> { - ParserRun.parse(CpmdParser, "parsers/cpmd/test/examples/md/output.out", "json") must_== ParseResult.ParseSuccess - } -}