Skip to content
Snippets Groups Projects
Commit aac03d99 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added more parsers to NOMAD

parent 9392341f
Branches
No related tags found
No related merge requests found
......@@ -53,3 +53,5 @@ TAGS
lib/
env/
*.egg-info/
\ No newline at end of file
from .parser_mopac import MopacParser
\ No newline at end of file
import sys
from nomad.metainfo import Environment
from nomad.metainfo.legacy import LegacyMetainfoEnvironment
import mopacparser.metainfo.mopac
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['mopacparser.metainfo.mopac'].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='mopac_nomadmetainfo_json',
description='None',
a_legacy=LegacyDefinition(name='mopac.nomadmetainfo.json'))
class section_single_configuration_calculation(public.section_single_configuration_calculation):
m_def = Section(validate=False, extends_base_section=True, a_legacy=LegacyDefinition(name='section_single_configuration_calculation'))
x_mopac_fhof = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Final heat of formation
''',
a_legacy=LegacyDefinition(name='x_mopac_fhof'))
class section_method(public.section_method):
m_def = Section(validate=False, extends_base_section=True, a_legacy=LegacyDefinition(name='section_method'))
x_mopac_keyword_line = Quantity(
type=str,
shape=[],
description='''
Mopac keyword line (it controls the calculation)
''',
a_legacy=LegacyDefinition(name='x_mopac_keyword_line'))
x_mopac_method = Quantity(
type=str,
shape=[],
description='''
Mopac method, i.e. PM7, AM1, etc..
''',
a_legacy=LegacyDefinition(name='x_mopac_method'))
m_package.__init_metainfo__()
# Copyright 2016-2018 Mikkel Strange, Fawzi Mohamed, Ankit Kariryaa
#
#
# 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.
......@@ -92,9 +92,32 @@ parserInfo = {
"version": "1.0"
}
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../../nomad-meta-info/meta_info/nomad_meta_info/mopac.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(filePath=metaInfoPath, dependencyLoader=None, extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS, uri=None)
class MopacParser():
""" 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('mopac parser started')
logging.getLogger('nomadcore').setLevel(logging.WARNING)
backend = self.backend_factory("mopac.nomadmetainfo.json")
context = MopacContext()
with patch.object(sys, 'argv', ['<exe>', '--uri', 'nmd://uri', mainfile]):
mainFunction(
mainFileDescription,
None,
parserInfo,
cachingLevelForMetaName=dict(),
superContext=context,
superBackend=backend)
return backend
if __name__ == "__main__":
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../../nomad-meta-info/meta_info/nomad_meta_info/mopac.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(filePath=metaInfoPath, dependencyLoader=None, extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS, uri=None)
superContext = MopacContext()
mainFunction(mainFileDescription, metaInfoEnv, parserInfo, superContext=superContext)
# Copyright 2016-2018 Mikkel Strange, Fawzi Mohamed, Ankit Kariryaa
#
#
# 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.
......@@ -16,11 +16,10 @@ from __future__ import division
import os
from contextlib import contextmanager
import numpy as np
import setup_paths
from nomadcore.unit_conversion.unit_conversion import convert_unit as cu
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.parser_backend import JsonParseEventsWriterBackend
from reader import Reader
from .reader import Reader
import logging
@contextmanager
......@@ -36,19 +35,9 @@ def c(value, unit=None):
parser_info = {"name": "parser_mopac", "version": "1.0"}
path = '../../../../nomad-meta-info/meta_info/nomad_meta_info/' +\
'mopac.nomadmetainfo.json'
metaInfoPath = os.path.normpath(
os.path.join(os.path.dirname(os.path.abspath(__file__)), path))
metaInfoEnv, warns = loadJsonFile(filePath=metaInfoPath,
dependencyLoader=None,
extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS,
uri=None)
def parse(filename):
p = JsonParseEventsWriterBackend(metaInfoEnv)
def parse(filename, backend):
p = backend
o = open_section
r = Reader(filename)
p.startedParsingSession(filename, parser_info)
......@@ -113,6 +102,20 @@ def parse(filename):
p.finishedParsingSession("ParseSuccess", None)
class MopacParser():
""" A proper class envolop for running this parser from within python. """
def __init__(self, backend, **kwargs):
self.backend_factory = backend
def parse(self, mainfile):
logging.info('mopac parser started')
logging.getLogger('nomadcore').setLevel(logging.WARNING)
backend = self.backend_factory("mopac.nomadmetainfo.json")
parse(mainfile, backend)
return backend
if __name__ == '__main__':
import sys
filename = sys.argv[1]
......
File moved
# Copyright 2016-2018 Mikkel Strange, Fawzi Mohamed, Ankit Kariryaa
#
# 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.
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"))
from setuptools import setup, find_packages
if not commonDir in sys.path:
sys.path.insert(0, commonDir)
def main():
setup(
name='mopacparser',
version='0.1',
description='NOMAD parser implementation for Mopac.',
license='APACHE 2.0',
package_dir={'': './'},
packages=find_packages(),
install_requires=[
'nomadcore',
'nomad'
],
)
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment