Commit 6656ac16 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added more parsers to NOMAD

parent 65077108
......@@ -52,3 +52,5 @@ TAGS
lib/
env/
*parser.egg-info
\ No newline at end of file
# Copyright 2017-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.
import setup_paths
import numpy as np
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.unit_conversion.unit_conversion import convert_unit
from nomadcore.caching_backend import CachingLevel
from nomadcore.simple_parser import mainFunction
from nomadcore.simple_parser import SimpleMatcher as SM
from AMBERDictionary import get_unitDict, get_nameListDict, get_fileListDict, set_excludeList, set_includeList
from MetaInfoStorage import COMMON_META_INFO_PATH, PUBLIC_META_INFO_PATH
import MetaInfoStorage as mStore
from .AMBERDictionary import get_unitDict, get_nameListDict, get_fileListDict, set_excludeList, set_includeList
from .MetaInfoStorage import COMMON_META_INFO_PATH, PUBLIC_META_INFO_PATH
from . import MetaInfoStorage as mStore
import logging
import json
import os
......@@ -34,20 +33,20 @@ PARSERMETANAME = PARSERNAME.lower()
PARSERTAG = 'x_' + PARSERMETANAME
PARSER_INFO_DEFAULT = {
'name':'amber-parser',
'name':'amber-parser',
'version': '0.0.1'
}
META_INFO_PATH = os.path.normpath(os.path.join(
os.path.dirname(os.path.abspath(__file__)),
os.path.dirname(os.path.abspath(__file__)),
"../../../../nomad-meta-info/meta_info/nomad_meta_info/amber.nomadmetainfo.json"))
LOGGER = logging.getLogger("nomad.AMBERParser")
def get_metaInfo(self):
metaInfoEnv, warnings = loadJsonFile(filePath=META_INFO_PATH,
dependencyLoader=None,
extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS,
metaInfoEnv, warnings = loadJsonFile(filePath=META_INFO_PATH,
dependencyLoader=None,
extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS,
uri=None)
metaInfoEnv = set_section_metaInfoEnv(metaInfoEnv, 'section', ['input_output_files'], 'type_section', False, ["section_run"])
metaInfoEnv = setDict_metaInfoEnv(metaInfoEnv, self.fileDict)
......@@ -56,7 +55,7 @@ def get_metaInfo(self):
metaInfoEnv = setDict_metaInfoEnv(metaInfoEnv, self.qmmmDict)
metaInfoEnv = setDict_metaInfoEnv(metaInfoEnv, self.parmDict)
metaInfoEnv = setDict_metaInfoEnv(metaInfoEnv, self.mddataDict)
metaInfoEnv = setDict_metaInfoEnv(metaInfoEnv, self.extraDict)
metaInfoEnv = setDict_metaInfoEnv(metaInfoEnv, self.extraDict)
return metaInfoEnv
def set_section_metaInfoEnv(infoEnv, metaNameTag, newList, listTypStr, repeatingSection, supraNames):
......@@ -76,7 +75,7 @@ def set_section_metaInfoEnv(infoEnv, metaNameTag, newList, listTypStr, repeating
name='x_amber_%s_%s' % (metaNameTag, newName),
kindStr=listTypStr,
repeats=repeatingSection,
superNames=supraNames))
superNames=supraNames))
return infoEnv
......@@ -97,7 +96,7 @@ def setDict_metaInfoEnv(infoEnv, nameDict):
description='auto generated meta info data',
dtypeStr=nameDict[keyName].metaInfoType,
shape=[],
superNames=nameDict[keyName].activeSections))
superNames=nameDict[keyName].activeSections))
return infoEnv
......@@ -118,7 +117,7 @@ def set_metaInfoEnv(infoEnv, metaNameTag, newList, listTypStr, supraNames):
description='auto generated meta info data',
dtypeStr=listTypStr,
shape=[],
superNames=supraNames))
superNames=supraNames))
return infoEnv
......@@ -128,15 +127,15 @@ class AMBERParserBase(object):
re_program_name=None):
self.metaStorage = mStore.Container('section_run')
self.metaStorageRestrict = mStore.Container('section_restricted_uri')
exclude_dict = {
exclude_dict = {
'section_run' : [
'section_processor_info',
'section_processor_log',
'section_processor_info',
'section_processor_log',
'section_springer_material',
'section_repository_info'
]}
jsonmetadata = mStore.JsonMetaInfo(
COMMON_META_INFO_PATH,
COMMON_META_INFO_PATH,
PUBLIC_META_INFO_PATH,
META_INFO_PATH
)
......@@ -165,8 +164,8 @@ class AMBERParserBase(object):
def parse(self):
self.coverageIgnore = re.compile(r"^(?:" + r"|".join(self.coverageIgnoreList) + r")$")
mainFunction(mainFileDescription=self.mainFileDescription(),
metaInfoEnv=self.metaInfoEnv,
mainFunction(mainFileDescription=self.mainFileDescription(),
metaInfoEnv=self.metaInfoEnv,
parserInfo=self.parserInfo,
cachingLevelForMetaName=self.cachingLevelForMetaName,
superContext=self)
......
# Copyright 2017-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.
import setup_paths
import numpy as np
from nomadcore.unit_conversion.unit_conversion import convert_unit
from contextlib import contextmanager
......@@ -23,11 +22,11 @@ import re
from collections import namedtuple
COMMON_META_INFO_PATH = os.path.normpath(os.path.join(
os.path.dirname(os.path.abspath(__file__)),
os.path.dirname(os.path.abspath(__file__)),
"../../../../nomad-meta-info/meta_info/nomad_meta_info/common.nomadmetainfo.json"))
PUBLIC_META_INFO_PATH = os.path.normpath(os.path.join(
os.path.dirname(os.path.abspath(__file__)),
os.path.dirname(os.path.abspath(__file__)),
"../../../../nomad-meta-info/meta_info/nomad_meta_info/public.nomadmetainfo.json"))
NOTEXCEPT = re.compile(r'[^a-cf-zA-CF-Z!\.?,]')
......@@ -57,7 +56,7 @@ class Container(object):
def add(self, *args):
for arg in args:
if isinstance(arg, Container):
self.Containers.append(arg)
self.Containers.append(arg)
if isinstance(arg, Storage):
if self.Storage:
self.Storage(arg.__dict__)
......@@ -73,7 +72,7 @@ class Container(object):
self.Storage = Storage(arg)
if isinstance(arg, JsonMetaInfo):
for item in arg.jsonList:
self.add(item)
self.add(item)
def build(self, metadata, startsection, umaskdict):
if isinstance(metadata, JsonMetaInfo):
......@@ -104,7 +103,7 @@ class Container(object):
def updaterefs(self, *args):
for arg in args:
if isinstance(arg, Container):
self.References.extend(arg.Name)
self.References.extend(arg.Name)
def update(self, *args):
for arg in args:
......@@ -193,23 +192,23 @@ class Container(object):
""" Updating value with the rules given in depends
Updating values follows the following order:
1) If 'depends' is supplied (not empty or not None),
1) If 'depends' is supplied (not empty or not None),
the tests in the depends list will be checked in order.
If one of the tests is successful than the one of the
If one of the tests is successful than the one of the
values in 'assign' or 'value' will be updated for the item.
Here 'assign' will assign a new value in the given string and
'value' will assign the value of the given key item.
(Ex. : 'assign' : 'CG' will update the item with 'CG' while
'value' : 'NATOM' will update the item with number of atoms
(Ex. : 'assign' : 'CG' will update the item with 'CG' while
'value' : 'NATOM' will update the item with number of atoms
returned by the value of NATOM key ,which is stored in lookup dict.)
2) If 'depends' is supplied but a lookup dictionary is not than
2) If 'depends' is supplied but a lookup dictionary is not than
only the values of attributes in the sections can be used for test.
The rest of the tests and assignments are updated as in case (1).
3) If 'depends' is not supplied, subfunction is used to update value.
4) If 'depends' and subfunction are not supplied but value of
MetaInfoMap is supplied, the value will be assign directly from the value
4) If 'depends' and subfunction are not supplied but value of
MetaInfoMap is supplied, the value will be assign directly from the value
item.
5) If none of the above items are supplied, this function will return None
5) If none of the above items are supplied, this function will return None
to not update any values for the selected item.
"""
# Check whether depends is supplied in the item.
......@@ -293,7 +292,7 @@ class Container(object):
# I hope you know what you are doing
newUpdateValue = updateValue
return newUpdateValue
def convertUnits(self, updateValue, unit, unitdict):
if(isinstance(updateValue, list) or isinstance(updateValue, tuple)):
updateValue = [float(ival) * self.unitConverter(
......@@ -320,7 +319,7 @@ class Container(object):
The unit names are converted to numbers and the resulting
expression will be evaluated by python.
Ex.: unit = 'electron-volt/Angstrom^3'
Ex.: unit = 'electron-volt/Angstrom^3'
will be converted to
unit = '1.602176565e-19*1.0/1.0e-10**3'
factor = eval(unit) = 160.2176565e+9 Joule/meter^3 (Pascal)
......@@ -359,7 +358,7 @@ class Container(object):
if depdict['value'] in localdict:
checkval = localdict[depdict['value']]
else:
accessName, checkval = self.findNameInLookupDict(depdict['value'],
accessName, checkval = self.findNameInLookupDict(depdict['value'],
item.lookupdict)
localdict.update({depdict['value'] : checkval})
return checkval, localdict
......@@ -446,12 +445,12 @@ class Container(object):
#No need to store, assign the updated value
self.Storage.__dict__[itemk]["val"] = updateValue
self.Storage.__dict__[itemk]["act"] = True
elif (itemk.startswith('x_') and
elif (itemk.startswith('x_') and
itemv.activeSection == self.Name):
attrvalues = {
'act' : True,
'val' : updateValue,
'kind': None,
'act' : True,
'val' : updateValue,
'kind': None,
'dtyp': "C",
'unit': None,
'size': [],
......@@ -503,16 +502,16 @@ class Container(object):
else:
if printok:
if color:
string = '%s\033[9%sm-->[' % (decorate + self.Indent, str(color%6 + 1))
string = '%s\033[9%sm-->[' % (decorate + self.Indent, str(color%6 + 1))
string = string + ','.join(['%s' % (name) for name in self.Name]) + ']\n\033[0m'
else:
string = '%s-->[' % (decorate + self.Indent)
string = '%s-->[' % (decorate + self.Indent)
string = string + ','.join(['%s' % (name) for name in self.Name]) + ']\n'
if printok:
if color:
string = string + '%s\033[9%sm|\033[0m `.\n' % (decorate + self.Indent, str(color%6 + 1))
string = string + '%s\033[9%sm|\033[0m `.\n' % (decorate + self.Indent, str(color%6 + 1))
else:
string = string + '%s| `.\n' % (decorate + self.Indent)
string = string + '%s| `.\n' % (decorate + self.Indent)
if self.Storage:
for key in self.Storage.__dict__:
printattrok = False
......@@ -524,19 +523,19 @@ class Container(object):
if printattrok and printok:
if color:
if onlynames:
string = string + '%s\033[9%sm|\033[0m |__.%s\n' % (decorate
string = string + '%s\033[9%sm|\033[0m |__.%s\n' % (decorate
+ self.Indent, str(color%6 + 1), key)
else:
string = string + '%s\033[9%sm|\033[0m |__.%s : Active=%s Value=%s\n' % (decorate
+ self.Indent, str(color%6 + 1), key, self.Storage.__dict__[key]["act"],
string = string + '%s\033[9%sm|\033[0m |__.%s : Active=%s Value=%s\n' % (decorate
+ self.Indent, str(color%6 + 1), key, self.Storage.__dict__[key]["act"],
self.Storage.__dict__[key]["val"])
else:
if onlynames:
string = string + '%s| |__.%s\n' % (decorate +
string = string + '%s| |__.%s\n' % (decorate +
self.Indent, key)
else:
string = string + '%s| |__.%s : Active=%s Value=%s\n' % (decorate +
self.Indent, key, self.Storage.__dict__[key]["act"],
string = string + '%s| |__.%s : Active=%s Value=%s\n' % (decorate +
self.Indent, key, self.Storage.__dict__[key]["act"],
self.Storage.__dict__[key]["val"])
if color:
string = string + '%s\033[9%sm|\033[0m\n' % (decorate + self.Indent, str(color%6 + 1))
......@@ -545,13 +544,13 @@ class Container(object):
if self.Containers:
for module in self.Containers:
if color:
string = string + '%s\033[9%sm|\033[0m\n' % (decorate + self.Indent,
str(color%6 + 1)) + module.__str__(self.Name,
'%s\033[9%sm|\033[0m' % (decorate + self.Indent, str(color%6 + 1)),
string = string + '%s\033[9%sm|\033[0m\n' % (decorate + self.Indent,
str(color%6 + 1)) + module.__str__(self.Name,
'%s\033[9%sm|\033[0m' % (decorate + self.Indent, str(color%6 + 1)),
color, printactive, onlynames)
else:
string = string + '%s|\n' % (decorate + self.Indent) + module.__str__(self.Name,
'%s|' % (decorate + self.Indent),
string = string + '%s|\n' % (decorate + self.Indent) + module.__str__(self.Name,
'%s|' % (decorate + self.Indent),
color, printactive, onlynames)
return string
......@@ -590,7 +589,7 @@ class Storage(dict):
class JsonMetaInfo(object):
""" Json file loader for meta info data of NOMAD.
Loads data and extracts values of items
Loads data and extracts values of items
with specified superNames
"""
def __init__(self, *args):
......@@ -600,7 +599,7 @@ class JsonMetaInfo(object):
with open(filepath, encoding="utf-8") as f:
jsonDict = json.load(f)
except:
logging.exception("Error while loading file %s" % filePath)
logging.exception("Error while loading file %s" % filepath)
raise
typeStr = jsonDict.get("type","nomad_meta_info_1_0")
typeRe = re.compile(r"nomad_meta_info_(?P<major>[0-9]+)_(?P<minor>[0-9]+)$")
......@@ -638,13 +637,13 @@ class JsonMetaInfo(object):
refs = item['referencedSections']
except:
refs = []
if ('type_section' in kindname or
if ('type_section' in kindname or
sectionname not in superlist):
continue
attrvalues = {
'act' : False,
'val' : None,
'kind': kindname,
'act' : False,
'val' : None,
'kind': kindname,
'dtyp': dtyp,
'unit': unit,
'size': size,
......@@ -665,14 +664,14 @@ class JsonMetaInfo(object):
kindname = item['kindStr']
except:
kindname = []
if ('type_section' in kindname or
'type_abstract_document_content' in kindname):
if ('type_section' in kindname or
'type_abstract_document_content' in kindname):
if sectionname in superlist:
searchList.append(itemname)
if itemname not in nameList:
nameList.append(itemname)
for name in searchList:
if (set([name]) not in set(nameList) and
if (set([name]) not in set(nameList) and
self.isparent(name)):
siblings.append(name)
return siblings
......@@ -717,10 +716,10 @@ class JsonMetaInfo(object):
if __name__ == "__main__":
run = Container('section_run')
exclude_dict = {
exclude_dict = {
'section_run' : [
'section_processor_info',
'section_processor_log',
'section_processor_info',
'section_processor_log',
'section_springer_material',
'section_repository_info'
]}
......@@ -736,7 +735,7 @@ if __name__ == "__main__":
'topology_force_field_name' : {'depends' : [[]], 'assign' : "ReaxFF"}
}
}
run.populate(jsonmetadata, 'section_run', exclude_dict, updateDict)
run.Color = 4
for container in run.Containers:
......
from .AMBERParser import AMBERParserInterface as AMBERParser
\ No newline at end of file
import sys
from nomad.metainfo import Environment
from nomad.metainfo.legacy import LegacyMetainfoEnvironment
import amberparser.metainfo.amber
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['amberparser.metainfo.amber'].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 common
from nomad.datamodel.metainfo import public
m_package = Package(
name='amber_nomadmetainfo_json',
description='None',
a_legacy=LegacyDefinition(name='amber.nomadmetainfo.json'))
class x_amber_mdin_method(MCategory):
'''
Parameters of mdin belonging to section method.
'''
m_def = Category(
a_legacy=LegacyDefinition(name='x_amber_mdin_method'))
class x_amber_mdout_single_configuration_calculation(MCategory):
'''
Parameters of mdout belonging to section_single_configuration_calculation.
'''
m_def = Category(
a_legacy=LegacyDefinition(name='x_amber_mdout_single_configuration_calculation'))
class x_amber_mdout_method(MCategory):
'''
Parameters of mdin belonging to section method.
'''
m_def = Category(
a_legacy=LegacyDefinition(name='x_amber_mdout_method'))
class x_amber_mdout_run(MCategory):
'''
Parameters of mdin belonging to settings run.
'''
m_def = Category(
categories=[public.settings_run],
a_legacy=LegacyDefinition(name='x_amber_mdout_run'))
class x_amber_mdin_run(MCategory):
'''
Parameters of mdin belonging to settings run.
'''
m_def = Category(
categories=[public.settings_run],
a_legacy=LegacyDefinition(name='x_amber_mdin_run'))
class x_amber_section_input_output_files(MSection):
'''
Temperory variable to store input and output file keywords
'''
m_def = Section(validate=False, a_legacy=LegacyDefinition(name='x_amber_section_input_output_files'))
class x_amber_section_single_configuration_calculation(MSection):
'''
section for gathering values for MD steps
'''
m_def = Section(validate=False, a_legacy=LegacyDefinition(name='x_amber_section_single_configuration_calculation'))
class section_system(public.section_system):
m_def = Section(validate=False, extends_base_section=True, a_legacy=LegacyDefinition(name='section_system'))
x_amber_atom_positions_image_index = Quantity(
type=np.dtype(np.int32),
shape=['number_of_atoms', 3],
unit='dimensionless',
description='''
PBC image flag index.
''',
a_legacy=LegacyDefinition(name='x_amber_atom_positions_image_index'))
x_amber_atom_positions_scaled = Quantity(
type=np.dtype(np.float64),
shape=['number_of_atoms', 3],
unit='dimensionless',
description='''
Position of the atoms in a scaled format [0, 1].
''',
a_legacy=LegacyDefinition(name='x_amber_atom_positions_scaled'))
x_amber_atom_positions_wrapped = Quantity(
type=np.dtype(np.float64),
shape=['number_of_atoms', 3],
unit='meter',
description='''
Position of the atoms wrapped back to the periodic box.
''',
a_legacy=LegacyDefinition(name='x_amber_atom_positions_wrapped'))
x_amber_dummy = Quantity(
type=str,
shape=[],
description='''
dummy
''',
a_legacy=LegacyDefinition(name='x_amber_dummy'))
x_amber_mdin_finline = Quantity(
type=str,
shape=[],
description='''
finline in mdin
''',
a_legacy=LegacyDefinition(name='x_amber_mdin_finline'))
x_amber_traj_timestep_store = Quantity(
type=str,
shape=[],
description='''
tmp
''',
a_legacy=LegacyDefinition(name='x_amber_traj_timestep_store'))
x_amber_traj_number_of_atoms_store = Quantity(
type=str,
shape=[],
description='''
tmp
''',
a_legacy=LegacyDefinition(name='x_amber_traj_number_of_atoms_store'))
x_amber_traj_box_bound_store = Quantity(
type=str,
shape=[],
description='''
tmp
''',
a_legacy=LegacyDefinition(name='x_amber_traj_box_bound_store'))
x_amber_traj_box_bounds_store = Quantity(
type=str,
shape=[],
description='''
tmp
''',
a_legacy=LegacyDefinition(name='x_amber_traj_box_bounds_store'))
x_amber_traj_variables_store = Quantity(
type=str,
shape=[],
description='''
tmp
''',
a_legacy=LegacyDefinition(name='x_amber_traj_variables_store'))
x_amber_traj_atoms_store = Quantity(
type=str,
shape=[],
description='''
tmp
''',
a_legacy=LegacyDefinition(name='x_amber_traj_atoms_store'))
class section_sampling_method(public.section_sampling_method):
m_def = Section(validate=False, extends_base_section=True, a_legacy=LegacyDefinition(name='section_sampling_method'))
x_amber_barostat_target_pressure = Quantity(
type=np.dtype(np.float64),
shape=[],
unit='pascal',