Commit 6b536f8f authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Adopted implementation for nomad-fairdi.

parent 9ae0c172
# use glob syntax.
syntax: glob
*.ser
*.class
*~
*.bak
#*.off
*.old
# python
__pycache__
.mypy_cache
*.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/
# Egg
parser/parser-big-dft/bigdftparser.egg-info/
*.egg-info/
\ No newline at end of file
from .main import MolcasParser
# Copyright 2016-2018 The NOMAD Developers Group
# Copyright 2016-2018 Ask Hjorth Larsen, Fawzi Mohamed
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright 2016-2018 The NOMAD Developers Group
# Copyright 2016-2018 Ask Hjorth Larsen, Fawzi Mohamed
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -17,8 +17,8 @@
from __future__ import print_function
import os
import sys
import setup_paths
import re
import logging
import numpy as np
from ase import Atoms
......@@ -29,10 +29,11 @@ from nomadcore.simple_parser import mainFunction, SimpleMatcher as SM
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.unit_conversion.unit_conversion \
import register_userdefined_quantity, convert_unit
import nomad_meta_info
from functionals import functionals
from .functionals import functionals
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),"../../../../nomad-meta-info/meta_info/nomad_meta_info/molcas.nomadmetainfo.json"))
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(nomad_meta_info.__file__)), "molcas.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(filePath=metaInfoPath,
dependencyLoader=None,
extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS,
......@@ -640,7 +641,8 @@ def molcas_main_loop_sm():
] + get_anymodule_sms())
return m
mainFileDescription = SM(
def main_file_description():
return SM(
name='root',
weak=True,
startReStr='',
......@@ -656,13 +658,36 @@ mainFileDescription = SM(
])
def main(**kwargs):
mainFunction(mainFileDescription=mainFileDescription,
class MolcasParser():
""" A proper class envolop for running this parser from within python. """
def __init__(self, backend, **kwargs):
self.backend_factory = backend
def parse(self, mainfile):
global context
context = MolcasContext()
from unittest.mock import patch
logging.debug('molcas parser started')
logging.getLogger('nomadcore').setLevel(logging.WARNING)
backend = self.backend_factory(metaInfoEnv)
with patch.object(sys, 'argv', ['<exe>', '--uri', 'nmd://uri', mainfile]):
mainFunction(
mainFileDescription=main_file_description(),
metaInfoEnv=metaInfoEnv,
parserInfo=parser_info,
cachingLevelForMetaName={},
superContext=context,
**kwargs)
superBackend=backend)
return backend
if __name__ == '__main__':
main()
mainFunction(
mainFileDescription=main_file_description(),
metaInfoEnv=metaInfoEnv,
parserInfo=parser_info,
cachingLevelForMetaName={},
superContext=context,
**kwargs)
# Copyright 2016-2018 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.
#
# Main author and maintainer: Ask Hjorth Larsen <asklarsen@gmail.com>
from __future__ import print_function
import os
from glob import glob
scala_imports = """package eu.nomad_lab.parsers
import eu.nomad_lab.{ parsers, DefaultPythonInterpreter }
import org.scalacheck.Properties
import org.specs2.mutable.Specification
import org.{ json4s => jn }
"""
test_template = """\
"test %(name)s " >> {
"test with json-events" >> {
ParserRun.parse(MolcasParser, "parsers/molcas/test/examples/%(name)s", "json-events") must_== ParseResult.ParseSuccess
}
"test with json" >> {
ParserRun.parse(MolcasParser, "parsers/molcas/test/examples/%(name)s", "json") must_== ParseResult.ParseSuccess
}
}"""
fd = open('out.scala', 'w')
fd.write(scala_imports)
print('object MolcasParserSpec extends Specification {', file=fd)
print(' "MolcasParserTest" >> {', file=fd)
fnames = glob('test/test???.input.out')
fnames.sort()
for fname in fnames:
fname = os.path.basename(fname)
print(test_template % dict(name=fname), file=fd)
print(' }', file=fd)
print('}', file=fd)
../../../../nomad-meta-info/meta_info/nomad_meta_info
\ No newline at end of file
# Copyright 2016-2018 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.
#
# Main author and maintainer: Ask Hjorth Larsen <asklarsen@gmail.com>
from __future__ import print_function
from glob import glob
import re
from optparse import OptionParser
from subprocess import Popen, PIPE
import os
from ase.parallel import world
import platform
p = OptionParser()
opts, args = p.parse_args()
if len(args) == 0:
testfiles = glob('test/test???.input.out')
testfiles.sort()
else:
testfiles = argv
for i, testfile in enumerate(testfiles):
if i % world.size != world.rank:
continue
dirname, basename = os.path.split(testfile)
py = 'python'
if platform.node() == 'labdev-nomad':
py = '/labEnv3/bin/python'
args = [py, 'main.py', '--annotate']
args.append(testfile)
print(' '.join(args))
proc = Popen(args, stdout=PIPE)
txt = proc.stdout.read()
with open('%s.json' % testfile, 'w') as fd:
fd.write(txt.decode('ascii'))
# Copyright 2016-2018 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.
#
# Main author and maintainer: Ask Hjorth Larsen <asklarsen@gmail.com>
import sys, os, os.path
baseDir = os.path.dirname(os.path.abspath(__file__))
commonDir = os.path.normpath(os.path.join(baseDir,"../../../../python-common/common/python"))
if not commonDir in sys.path:
sys.path.insert(0, commonDir)
../../test/examples
\ No newline at end of file
parser/parser-molcas
\ No newline at end of file
# Copyright 2016-2018 Ask Hjorth Larsen, 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.
from setuptools import setup, find_packages
def main():
setup(
name='molcasparser',
version='0.1',
description='NOMAD parser implementation for Molcas.',
author='Ask Hjorth Larsen, Fawzi Mohamed',
license='APACHE 2.0',
packages=find_packages(),
install_requires=[
'nomadcore'
],
)
if __name__ == '__main__':
main()
/*
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.DefaultPythonInterpreter
import org.{ json4s => jn }
import scala.collection.breakOut
object MolcasParser extends SimpleExternalParserGenerator(
name = "MolcasParser",
parserInfo = jn.JObject(
("name" -> jn.JString("MolcasParser")) ::
("parserId" -> jn.JString("MolcasParser" + lab.MolcasVersionInfo.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.MolcasVersionInfo.toMap.map {
case (key, value) =>
(key -> jn.JString(value.toString))
}(breakOut): List[(String, jn.JString)])
)) :: Nil
),
mainFileTypes = Seq("text/.*"),
mainFileRe = """
\s*\^[\s\^]*M O L C A S\s*
\s*\^[\s\^]*version \S+ patchlevel \S+\s*
""".r,
cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/parsers/molcas/parser/parser-molcas/main.py",
"--uri", "${mainFileUri}", "${mainFilePath}"),
resList = Seq(
"parser-molcas/main.py",
"parser-molcas/functionals.py",
"parser-molcas/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/molcas.nomadmetainfo.json"
) ++ DefaultPythonInterpreter.commonFiles(),
dirMap = Map(
"parser-molcas" -> "parsers/molcas/parser/parser-molcas",
"nomad_meta_info" -> "nomad-meta-info/meta_info/nomad_meta_info",
"python" -> "python-common/common/python/nomadcore"
) ++ DefaultPythonInterpreter.commonDirMapping(),
metaInfoEnv = Some(lab.meta.KnownMetaInfoEnvs.molcas)
)
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