Commit ffdbdea1 authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Initial commit.

parent e5d11746
# use glob syntax.
syntax: glob
*.ser
*.class
*~
*.bak
#*.off
*.old
*.pyc
*.bk
*.swp
.DS_Store
**/__pycache__
# logging files
detailed.log
# eclipse conf file
.settings
.classpath
.project
.manager
.scala_dependencies
# idea
.idea
*.iml
# building
target
build
null
tmp*
temp*
dist
test-output
build.log
# other scm
.svn
.CVS
.hg*
# switch to regexp syntax.
# syntax: regexp
# ^\.pc/
#SHITTY output not in target directory
build.log
#emacs TAGS
TAGS
lib/
env/
stages:
- test
testing:
stage: test
script:
- cd .. && rm -rf nomad-lab-base
- git clone --recursive git@gitlab.mpcdf.mpg.de:nomad-lab/nomad-lab-base.git
- cd nomad-lab-base
- git submodule foreach git checkout master
- git submodule foreach git pull
- sbt nwchem/test
- export PYTHONEXE=/labEnv/bin/python
- sbt nwchem/test
only:
- master
tags:
- test
- spec2
from nwchemparser.parser import NWChemParser
from builtins import next
from builtins import range
import os
import re
import logging
import importlib
from nomadcore.baseclasses import ParserInterface
logger = logging.getLogger("nomad")
#===============================================================================
class NWChemParser(ParserInterface):
"""This class handles the initial setup before any parsing can happen. It
determines which version of NWChem was used to generate the output and then
sets up a correct main parser.
After the implementation has been setup, you can parse the files with
parse().
"""
def __init__(self, main_file, metainfo_to_keep=None, backend=None, default_units=None, metainfo_units=None, debug=True, log_level=logging.ERROR, store=True):
super(NWChemParser, self).__init__(main_file, 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
specified in it.
"""
# Search for the NWChem version specification. The correct parser is
# initialized based on this information.
regex_version = re.compile(" Northwest Computational Chemistry Package \(NWChem\) (\d+\.\d+)")
n_lines = 1000
version_id = None
with open(self.parser_context.main_file, 'r') as outputfile:
for i_line in range(n_lines):
try:
line = next(outputfile)
except StopIteration:
break
# Look for version
result_version = regex_version.match(line)
if result_version:
version_id = result_version.group(1).replace('.', '')
if version_id is None:
msg = "Could not find a version specification from the given main file."
logger.exception(msg)
raise RuntimeError(msg)
# Setup the root folder to the fileservice that is used to access files
dirpath, filename = os.path.split(self.parser_context.main_file)
dirpath = os.path.abspath(dirpath)
self.parser_context.file_service.setup_root_folder(dirpath)
self.parser_context.file_service.set_file_id(filename, "output")
# Setup the correct main parser based on the version id. If no match
# for the version is found, use the main parser for NWChem 6.6
self.setup_main_parser(version_id)
def get_metainfo_filename(self):
return "nwchem.nomadmetainfo.json"
def get_parser_info(self):
return {'name': 'nwchem-parser', 'version': '1.0'}
def setup_main_parser(self, version_id):
# Currently the version id is a pure integer, so it can directly be mapped
# into a package name.
base = "nwchemparser.versions.nwchem{}.mainparser".format(version_id)
parser_module = None
parser_class = None
try:
parser_module = importlib.import_module(base)
except ImportError:
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:
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:
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.main_file, self.parser_context)
"""
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(main_file, backend=JsonParseEventsWriterBackend)
parser.parse()
"""
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)
"""
This is a setup script for installing the parser locally on python path with
all the required dependencies. Used mainly for local testing.
"""
from setuptools import setup, find_packages
#===============================================================================
def main():
# Start package setup
setup(
name="nwchemparser",
version="0.1",
description="NoMaD parser implementation for NWChem.",
author="Lauri Himanen",
author_email="lauri.himanen@aalto.fi",
license="GPL3",
package_dir={'': 'parser/parser-nwchem'},
packages=find_packages(),
install_requires=[
'pint',
'numpy',
'nomadcore',
],
)
# Run main function by default
if __name__ == "__main__":
main()
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()
)
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
}
}
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