Commit 960a15aa authored by Markus Scheidgen's avatar Markus Scheidgen

Added more parsers to NOMAD

parent 5dadf385
*parser.egg-info/
\ No newline at end of file
from .parser_openkim import OpenKIMParser
\ No newline at end of file
import sys
from nomad.metainfo import Environment
from nomad.metainfo.legacy import LegacyMetainfoEnvironment
import openkimparser.metainfo.openkim
import nomad.datamodel.metainfo.common
import nomad.datamodel.metainfo.public
import nomad.datamodel.metainfo.general
m_env = LegacyMetainfoEnvironment()
m_env.m_add_sub_section(Environment.packages, sys.modules['openkimparser.metainfo.openkim'].m_package) # type: ignore
m_env.m_add_sub_section(Environment.packages, sys.modules['nomad.datamodel.metainfo.common'].m_package) # type: ignore
m_env.m_add_sub_section(Environment.packages, sys.modules['nomad.datamodel.metainfo.public'].m_package) # type: ignore
m_env.m_add_sub_section(Environment.packages, sys.modules['nomad.datamodel.metainfo.general'].m_package) # type: ignore
import numpy as np # pylint: disable=unused-import
import typing # pylint: disable=unused-import
from nomad.metainfo import ( # pylint: disable=unused-import
MSection, MCategory, Category, Package, Quantity, Section, SubSection, SectionProxy,
Reference
)
from nomad.metainfo.legacy import LegacyDefinition
from nomad.datamodel.metainfo import public
m_package = Package(
name='openkim_nomadmetainfo_json',
description='None',
a_legacy=LegacyDefinition(name='openkim.nomadmetainfo.json'))
class section_run(public.section_run):
m_def = Section(validate=False, extends_base_section=True, a_legacy=LegacyDefinition(name='section_run'))
openkim_build_date = Quantity(
type=str,
shape=[],
description='''
build date as string
''',
categories=[public.accessory_info, public.program_info],
a_legacy=LegacyDefinition(name='openkim_build_date'))
openkim_src_date = Quantity(
type=str,
shape=[],
description='''
date of last modification of the source as string
''',
categories=[public.accessory_info, public.program_info],
a_legacy=LegacyDefinition(name='openkim_src_date'))
class section_method(public.section_method):
m_def = Section(validate=False, extends_base_section=True, a_legacy=LegacyDefinition(name='section_method'))
x_openkim_atom_kind_refs = Quantity(
type=public.section_method_atom_kind,
shape=['number_of_atoms'],
description='''
reference to the atom kinds of each atom
''',
a_legacy=LegacyDefinition(name='x_openkim_atom_kind_refs'))
m_package.__init_metainfo__()
...@@ -4,10 +4,8 @@ from builtins import map ...@@ -4,10 +4,8 @@ from builtins import map
from builtins import range from builtins import range
from builtins import object from builtins import object
import logging, sys, bisect import logging, sys, bisect
import setup_paths
from datetime import datetime from datetime import datetime
import os, logging, re, traceback import re, traceback
from nomadcore.parser_backend import JsonParseEventsWriterBackend
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
import numpy as np import numpy as np
from nomadcore.unit_conversion.unit_conversion import convert_unit_function from nomadcore.unit_conversion.unit_conversion import convert_unit_function
...@@ -138,7 +136,7 @@ class OpenkimContext(object): ...@@ -138,7 +136,7 @@ class OpenkimContext(object):
self.cell = None self.cell = None
self.labels = None self.labels = None
celltype = None celltype = None
if('basis-atom-coordinates.source-value' in querydict and if('basis-atom-coordinates.source-value' in querydict and
('a.si-value' in querydict) or ('a.si-value' in querydict) or
('b.si-value' in querydict) or ('b.si-value' in querydict) or
('c.si-value' in querydict) or ('c.si-value' in querydict) or
...@@ -164,9 +162,9 @@ class OpenkimContext(object): ...@@ -164,9 +162,9 @@ class OpenkimContext(object):
else: else:
lat_a = float(a_si_val) lat_a = float(a_si_val)
si_conv = convert_unit_function("m", "angstrom") si_conv = convert_unit_function("m", "angstrom")
cellAtoms = Atoms( cellAtoms = Atoms(
positions=basis, positions=basis,
cell=[si_conv(lat_a), cell=[si_conv(lat_a),
si_conv(lat_a), si_conv(lat_a),
si_conv(lat_a)], si_conv(lat_a)],
pbc=True) pbc=True)
...@@ -293,7 +291,8 @@ class KIMParser(object): ...@@ -293,7 +291,8 @@ class KIMParser(object):
backend.startedParsingSession( backend.startedParsingSession(
mainFileUri = mainFileUri, mainFileUri = mainFileUri,
parserInfo = self.parserInfo) parserInfo = self.parserInfo)
self.superContext.startedParsing(self) superContext = self.superContext
superContext.startedParsing(self)
QueryList = KIMQueryReader(self.fIn) QueryList = KIMQueryReader(self.fIn)
try: try:
for qi, qdict in enumerate(QueryList): for qi, qdict in enumerate(QueryList):
...@@ -338,13 +337,19 @@ parserInfo = { ...@@ -338,13 +337,19 @@ parserInfo = {
"version": "1.0" "version": "1.0"
} }
if __name__ == "__main__":
""" class OpenKIMParser():
This code is modified from parser-vasprun to work for OpenKIM """ A proper class envolop for running this parser from within python. """
""" def __init__(self, backend, **kwargs):
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),"../../../../nomad-meta-info/meta_info/nomad_meta_info/openkim.nomadmetainfo.json")) self.backend_factory = backend
metaInfoEnv, warnings = loadJsonFile(filePath = metaInfoPath, dependencyLoader = None, extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)
superContext = OpenkimContext() def parse(self, mainfile):
parser = KIMParser(parserInfo, superContext) logging.info('turbomole parser started')
backend = JsonParseEventsWriterBackend(metaInfoEnv, sys.stdout) logging.getLogger('nomadcore').setLevel(logging.WARNING)
parser.parse(sys.argv[1], sys.argv[2], backend) backend = self.backend_factory("openkim.nomadmetainfo.json")
parserInfo = {'name': 'parser_openkim', 'version': '1.0'}
context = OpenkimContext()
parser = KIMParser(parserInfo, context)
parser.parse('nmd://uri', mainfile, backend)
return backend
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, ".."))
if commondir not in sys.path:
sys.path.insert(1, commondir)
if parserdir not in sys.path:
sys.path.insert(1, parserdir)
# Copyright 2015-2018 Berk Onat
#
# 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='openkimparser',
version='0.1',
description='NOMAD parser implementation for OpenKIM.',
license='MIT',
package_dir={'': './'},
packages=find_packages(),
install_requires=[
'nomadcore',
'nomad'
],
)
if __name__ == '__main__':
main()
package eu.nomad_lab.parsers
import eu.nomad_lab
import eu.nomad_lab.DefaultPythonInterpreter
import org.{ json4s => jn }
import eu.{ nomad_lab => lab }
import scala.collection.breakOut
object OpenkimParser extends SimpleExternalParserGenerator(
name = "OpenkimParser",
parserInfo = jn.JObject(
("name" -> jn.JString("OpenkimParser")) ::
("parserId" -> jn.JString("OpenkimParser" + lab.OpenkimVersionInfo.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.OpenkimVersionInfo.toMap.map {
case (key, value) =>
(key -> jn.JString(value.toString))
}(breakOut): List[(String, jn.JString)])
)) :: Nil
),
mainFileTypes = Seq("text/.*"),
mainFileRe = """\s*OPENKIM_QUERY_OUTPUT\s*""".r,
cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/parsers/openkim/parser/parser-openkim/parser-openkim.py",
"${mainFilePath}", "${mainFilePath}/data.json"),
resList = Seq(
"parser-openkim/parser-openkim.py",
"parser-openkim/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/openkim.nomadmetainfo.json"
) ++ DefaultPythonInterpreter.commonFiles(),
dirMap = Map(
"parser-openkim" -> "parsers/openkim/parser/parser-openkim",
"nomad_meta_info" -> "nomad-meta-info/meta_info/nomad_meta_info",
"python" -> "python-common/common/python/nomadcore"
) ++ DefaultPythonInterpreter.commonDirMapping(),
metaInfoEnv = Some(lab.meta.KnownMetaInfoEnvs.openkim)
)
package eu.nomad_lab.parsers
import org.specs2.mutable.Specification
object OpenkimParserTests extends Specification {
"OpenkimParserTest" >> {
"[OpenKIM Query with 3767 entries] test with json-events" >> {
ParserRun.parse(OpenkimParser, "parsers/openkim/test/examples/data.json", "json-events") must_== ParseResult.ParseSuccess
}
"[OpenKIM Query with 3767 entries] test with json" >> {
ParserRun.parse(OpenkimParser, "parsers/openkim/test/examples/data.json", "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