Commit 179c4ce3 authored by Daniel Speckhard's avatar Daniel Speckhard

Removed scala infrastructure.

parent 261cabfe
......@@ -14,6 +14,8 @@
# from builtins import next
# from builtins import range
from builtins import next
from builtins import range
import os
import re
import logging
......@@ -30,20 +32,8 @@ class NWChemParser(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(NWChemParser, 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(NWChemParser, 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
......@@ -62,7 +52,7 @@ class NWChemParser(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)
# Setup the root folder to the fileservice that is used to access files
......@@ -90,16 +80,16 @@ class NWChemParser(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 NWChem 6.6".format(version_id))
logger.warning("Could not find a parser for version '{}'. Trying to default to the base implementation for NWChem 6.6".format(version_id))
base = "nwchemparser.versions.nwchem66.mainparser"
try:
parser_module = importlib.import_module(base)
except ImportError:
self.logger.exception("Tried to default to the NWChem 6.6 implementation but could not find the correct module.")
logger.exception("Tried to default to the NWChem 6.6 implementation but could not find the correct module.")
raise
try:
parser_class = getattr(parser_module, "NWChemMainParser")
except AttributeError:
self.logger.exception("A parser class 'NWChemMainParser' could not be found in the module '[]'.".format(parser_module))
logger.exception("A parser class 'NWChemMainParser' could not be found in the module '[]'.".format(parser_module))
raise
self.main_parser = parser_class(self.parser_context)
self.main_parser = parser_class(self.parser_context)
\ No newline at end of file
# Copyright 2016-2018 Lauri Himanen, Fawzi Mohamed
#
# 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 nwchemparser import NWChemParser
if __name__ == "__main__":
# Initialise the parser with the main filename and a JSON backend
main_file = sys.argv[1]
parser = NWChemParser(backend=JsonParseEventsWriterBackend)
parser.parse(main_file)
# Copyright 2016-2018 Lauri Himanen, Fawzi Mohamed
#
# 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-nwchem"))
# 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)
# Copyright 2016-2018 Lauri Himanen, Fawzi Mohamed
#
#
# 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.
......
/*
* Copyright 2016-2018 Lauri Himanen, Fawzi Mohamed
*
* 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 NWChemParser extends SimpleExternalParserGenerator(
name = "NWChemParser",
parserInfo = jn.JObject(
("name" -> jn.JString("NWChemParser")) ::
("parserId" -> jn.JString("NWChemParser" + lab.NwchemVersionInfo.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.NwchemVersionInfo.toMap.map {
case (key, value) =>
(key -> jn.JString(value.toString))
}(breakOut): List[(String, jn.JString)])
)) :: Nil
),
mainFileTypes = Seq("text/.*"),
mainFileRe = """ Northwest Computational Chemistry Package \(NWChem\) \d+\.\d+
------------------------------------------------------
Environmental Molecular Sciences Laboratory
Pacific Northwest National Laboratory
Richland, WA 99352""".r,
cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/parsers/nwchem/parser/parser-nwchem/nwchemparser/scalainterface.py",
"${mainFilePath}"),
cmdCwd = "${mainFilePath}/..",
resList = Seq(
"parser-nwchem/nwchemparser/__init__.py",
"parser-nwchem/nwchemparser/setup_paths.py",
"parser-nwchem/nwchemparser/parser.py",
"parser-nwchem/nwchemparser/scalainterface.py",
"parser-nwchem/nwchemparser/versions/__init__.py",
"parser-nwchem/nwchemparser/versions/nwchem66/__init__.py",
"parser-nwchem/nwchemparser/versions/nwchem66/mainparser.py",
"nomad_meta_info/public.nomadmetainfo.json",
"nomad_meta_info/common.nomadmetainfo.json",
"nomad_meta_info/meta_types.nomadmetainfo.json",
"nomad_meta_info/nwchem.nomadmetainfo.json"
) ++ DefaultPythonInterpreter.commonFiles(),
dirMap = Map(
"parser-nwchem" -> "parsers/nwchem/parser/parser-nwchem",
"nomad_meta_info" -> "nomad-meta-info/meta_info/nomad_meta_info"
) ++ DefaultPythonInterpreter.commonDirMapping()
)
/*
* Copyright 2016-2018 Lauri Himanen, Fawzi Mohamed
*
* 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 NWChemParserSpec extends Specification {
"NWChemParserTest" >> {
"test with json-events" >> {
ParserRun.parse(NWChemParser, "parsers/nwchem/test/examples/single_point/output.out", "json-events") must_== ParseResult.ParseSuccess
}
}
"test single_point with json" >> {
ParserRun.parse(NWChemParser, "parsers/nwchem/test/examples/single_point/output.out", "json") must_== ParseResult.ParseSuccess
}
"test geo_opt with json" >> {
ParserRun.parse(NWChemParser, "parsers/nwchem/test/examples/geo_opt/output.out", "json") must_== ParseResult.ParseSuccess
}
"test md with json" >> {
ParserRun.parse(NWChemParser, "parsers/nwchem/test/examples/md/output.out", "json") must_== ParseResult.ParseSuccess
}
}
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