Commit aec0fda5 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added more NOMAD parsers.

parent d41015e7
......@@ -52,3 +52,5 @@ TAGS
lib/
env/
*.egg-info
\ No newline at end of file
......@@ -12,9 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import setup_paths
import numpy as np
from NAMDCommon import PARSERNAME, PROGRAMNAME, PARSERTAG
from .NAMDCommon import PARSERNAME, PROGRAMNAME, PARSERTAG
from nomadcore.smart_parser.SmartParserDictionary import metaNameConverter, metaNameConverter_UnderscoreSpaceDash
from nomadcore.smart_parser.SmartParserDictionary import MetaInfoMap, FileInfoMap, MapDictionary
from nomadcore.smart_parser.SmartParserDictionary import getDict_MetaStrInDict, getList_MetaStrInDict, get_unitDict
......
......@@ -15,7 +15,6 @@
from builtins import map
from builtins import range
from builtins import object
import setup_paths
import numpy as np
import nomadcore.ActivateLogging
from nomadcore.caching_backend import CachingLevel
......@@ -24,9 +23,9 @@ from nomadcore.smart_parser import SmartParserCommon as SmartParser
from nomadcore.smart_parser.SmartParserCommon import get_metaInfo, conv_str, conv_int, conv_float, open_section
from nomadcore.smart_parser.SmartParserDictionary import getList_MetaStrInDict, getDict_MetaStrInDict
from nomadcore.smart_parser.SmartParserDictionary import isMetaStrInDict
from NAMDDictionary import get_updateDictionary, set_Dictionaries
from NAMDCommon import PARSERNAME, PROGRAMNAME, PARSERVERSION, PARSERTAG, LOGGER
from NAMDCommon import PARSER_INFO_DEFAULT, META_INFO_PATH, set_excludeList, set_includeList
from .NAMDDictionary import get_updateDictionary, set_Dictionaries
from .NAMDCommon import PARSERNAME, PROGRAMNAME, PARSERVERSION, PARSERTAG, LOGGER
from .NAMDCommon import PARSER_INFO_DEFAULT, META_INFO_PATH, set_excludeList, set_includeList
from nomadcore.md_data_access import MDDataAccess as MDDA
import argparse
import logging
......@@ -1258,6 +1257,29 @@ class NAMDParser(SmartParser.ParserBase):
]
class NamdParserInterface():
""" A proper class envolop for running this parser from within python. """
def __init__(self, backend, **kwargs):
self.backend_factory = backend
def parse(self, mainfile):
from unittest.mock import patch
logging.info('namd parser started')
logging.getLogger('nomadcore').setLevel(logging.WARNING)
backend = self.backend_factory("namd.nomadmetainfo.json")
parserInfo = {'name': 'namd-parser', 'version': '1.0'}
context = NAMDParser()
with patch.object(sys, 'argv', ['<exe>', '--uri', 'nmd://uri', mainfile]):
mainFunction(
mainFileDescription=context.mainFileDescription(),
metaInfoEnv=None,
parserInfo=parserInfo,
cachingLevelForMetaName=context.cachingLevelForMetaName,
superContext=context,
superBackend=backend)
return backend
if __name__ == "__main__":
parser = NAMDParser()
parser.parse()
from .NAMDParser import NamdParserInterface as NamdParser
\ No newline at end of file
import sys
from nomad.metainfo import Environment
from nomad.metainfo.legacy import LegacyMetainfoEnvironment
import namdparser.metainfo.namd
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['namdparser.metainfo.namd'].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
This diff is collapsed.
# Copyright 2018-2018 Berk Onat, Fawzi Mohamed
# 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.
......@@ -12,11 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.
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"))
from setuptools import setup, find_packages
if not commondir in sys.path:
sys.path.insert(0, commondir)
def main():
setup(
name='namdparser',
version='0.1',
description='NOMAD parser implementation for Namd.',
license='APACHE 2.0',
package_dir={'': './'},
packages=find_packages(),
install_requires=[
'nomadcore',
'nomad'
],
)
if __name__ == '__main__':
main()
/*
* Copyright 2018-2018 Berk Onat, 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
import eu.nomad_lab.DefaultPythonInterpreter
import org.{ json4s => jn }
import eu.{ nomad_lab => lab }
import scala.collection.breakOut
object NamdParser extends SimpleExternalParserGenerator(
name = "NamdParser",
parserInfo = jn.JObject(
("name" -> jn.JString("NamdParser")) ::
("parserId" -> jn.JString("NamdParser" + lab.NamdVersionInfo.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.NamdVersionInfo.toMap.map {
case (key, value) =>
(key -> jn.JString(value.toString))
}(breakOut): List[(String, jn.JString)])
)) :: Nil
),
mainFileTypes = Seq("text/.*"),
mainFileRe = """\s*Info:\s*NAMD\s*[0-9.]+\s*for\s*""".r,
cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/parsers/namd/parser/parser-namd/NAMDParser.py",
"${mainFilePath}"),
resList = Seq(
"parser-namd/NAMDParser.py",
"parser-namd/NAMDDictionary.py",
"parser-namd/NAMDCommon.py",
"parser-namd/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/namd.nomadmetainfo.json"
) ++ DefaultPythonInterpreter.commonFiles(),
dirMap = Map(
"parser-namd" -> "parsers/namd/parser/parser-namd",
"nomad_meta_info" -> "nomad-meta-info/meta_info/nomad_meta_info",
"python" -> "python-common/common/python/nomadcore"
) ++ DefaultPythonInterpreter.commonDirMapping(),
metaInfoEnv = Some(lab.meta.KnownMetaInfoEnvs.namd)
)
/*
* Copyright 2018-2018 Berk Onat, 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 NamdParserTests extends Specification {
"NAMDParserTest" >> {
"[tiny with 507 atoms] test with json-events" >> {
ParserRun.parse(NamdParser, "parsers/namd/test/examples/tiny/tiny.log", "json-events") must_== ParseResult.ParseSuccess
}
"[tiny with 507 atoms] test with json" >> {
ParserRun.parse(NamdParser, "parsers/namd/test/examples/tiny/tiny.log", "json") must_== ParseResult.ParseSuccess
}
"[apoa1-trajectory with 92224 atoms] test with json-events" >> {
ParserRun.parse(NamdParser, "parsers/namd/test/examples/apoa1-trajectory/apoa1.log", "json-events") must_== ParseResult.ParseSuccess
}
"[apoa1-trajectory with 92224 atoms] test with json" >> {
ParserRun.parse(NamdParser, "parsers/namd/test/examples/apoa1-trajectory/apoa1.log", "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