Commit dd555aad authored by Markus Scheidgen's avatar Markus Scheidgen

Added more parsers to NOMAD

parent f240bd2d
......@@ -52,3 +52,5 @@ TAGS
lib/
env/
*.egg-info/
\ No newline at end of file
from .parser_asap import AsapParser
\ No newline at end of file
import sys
from nomad.metainfo import Environment
from nomad.metainfo.legacy import LegacyMetainfoEnvironment
import asapparser.metainfo.asap
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['asapparser.metainfo.asap'].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='asap_nomadmetainfo_json',
description='None',
a_legacy=LegacyDefinition(name='asap.nomadmetainfo.json'))
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_asap_langevin_friction = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Friction coeffient used in Langevin dynamics
''',
a_legacy=LegacyDefinition(name='x_asap_langevin_friction'))
x_asap_maxstep = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Maxstep in Angstrom for geometry optimization
''',
a_legacy=LegacyDefinition(name='x_asap_maxstep'))
x_asap_temperature = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Temperature used in molecular-dynamics
''',
a_legacy=LegacyDefinition(name='x_asap_temperature'))
x_asap_timestep = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Timestep in molecular dynamics
''',
a_legacy=LegacyDefinition(name='x_asap_timestep'))
m_package.__init_metainfo__()
# Copyright 2016-2018 Mikkel Strange, 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.
......@@ -18,11 +18,9 @@ from contextlib import contextmanager
import numpy as np
from ase.io.trajectory import Trajectory
from ase import units
import setup_paths
from constraint_conversion import get_nomad_name
from .constraint_conversion import get_nomad_name
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
import logging
@contextmanager
......@@ -39,18 +37,9 @@ def c(value, unit=None):
parser_info = {"name": "parser_asap", "version": "1.0"}
path = '../../../../nomad-meta-info/meta_info/nomad_meta_info/' +\
'asap.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):
def parse(filename, backend):
t = Trajectory(filename, 'r')
# some sanity checks
if hasattr(t.backend, 'calculator'):
......@@ -62,7 +51,7 @@ def parse(filename):
else:
ds = {}
p = JsonParseEventsWriterBackend(metaInfoEnv)
p = backend
o = open_section
p.startedParsingSession(filename, parser_info)
with o(p, 'section_run'):
......@@ -159,7 +148,16 @@ def parse(filename):
p.finishedParsingSession("ParseSuccess", None)
if __name__ == '__main__':
import sys
filename = sys.argv[1]
parse(filename)
class AsapParser():
""" 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('asap parser started')
logging.getLogger('nomadcore').setLevel(logging.WARNING)
backend = self.backend_factory("asap.nomadmetainfo.json")
parserInfo = parser_info
parse(mainfile, backend)
return backend
\ No newline at end of file
# Copyright 2016-2018 Mikkel Strange, Fawzi Mohamed
#
# Copyright 2015-2018
#
# 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='asapparser',
version='0.1',
description='NOMAD parser implementation for asap.',
license='APACHE 2.0',
package_dir={'': './'},
packages=find_packages(),
install_requires=[
'nomadcore',
'nomad'
],
)
if __name__ == '__main__':
main()
/*
* Copyright 2016-2018 Mikkel Strange, 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 => lab }
import eu.nomad_lab.DefaultPythonInterpreter
import org.{ json4s => jn }
import scala.collection.breakOut
import java.nio.charset.StandardCharsets
object AsapParser extends SimpleExternalParserGenerator(
name = "AsapParser",
parserInfo = jn.JObject(
("name" -> jn.JString("AsapParser")) ::
("parserId" -> jn.JString("AsapParser" + lab.AsapVersionInfo.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.AsapVersionInfo.toMap.map {
case (key, value) =>
(key -> jn.JString(value.toString))
}(breakOut): List[(String, jn.JString)])
)) :: Nil
),
mainFileTypes = Seq("application/octet-stream"),
cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/parsers/asap/parser/parser-asap/parser_asap.py",
"${mainFilePath}"),
mainFileRe = "".r,
resList = Seq(
"parser-asap/setup_paths.py",
"parser-asap/parser_asap.py",
"parser-asap/constraint_conversion.py",
"nomad_meta_info/public.nomadmetainfo.json",
"nomad_meta_info/common.nomadmetainfo.json",
"nomad_meta_info/meta_types.nomadmetainfo.json",
"nomad_meta_info/asap.nomadmetainfo.json"
) ++ DefaultPythonInterpreter.commonFiles(),
dirMap = Map(
"parser-asap" -> "parsers/asap/parser/parser-asap",
"nomad_meta_info" -> "nomad-meta-info/meta_info/nomad_meta_info"
) ++ DefaultPythonInterpreter.commonDirMapping(),
metaInfoEnv = Some(lab.meta.KnownMetaInfoEnvs.asap)
) {
override def isMainFile(filePath: String, bytePrefix: Array[Byte], stringPrefix: Option[String]): Option[ParserMatch] = {
if (bytePrefix.startsWith("AFFormatASE-Trajectory".getBytes(StandardCharsets.US_ASCII)))
Some(ParserMatch(mainFileMatchPriority, mainFileMatchWeak))
else
None
}
}
/*
* Copyright 2016-2018 Mikkel Strange, 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 AsapParserSpec extends Specification {
"AsapParserTest" >> {
"test moldyn1 with json-events" >> {
ParserRun.parse(AsapParser, "parsers/asap/test/examples/moldyn1.traj", "json-events") must_== ParseResult.ParseSuccess
}
"test moldyn1 with json" >> {
ParserRun.parse(AsapParser, "parsers/asap/test/examples/moldyn1.traj", "json") must_== ParseResult.ParseSuccess
}
"test moldyn2 with json-events" >> {
ParserRun.parse(AsapParser, "parsers/asap/test/examples/moldyn2.traj", "json-events") must_== ParseResult.ParseSuccess
}
"test moldyn2 with json" >> {
ParserRun.parse(AsapParser, "parsers/asap/test/examples/moldyn2.traj", "json") must_== ParseResult.ParseSuccess
}
"test geo_opt1 with json-events" >> {
ParserRun.parse(AsapParser, "parsers/asap/test/examples/geo_opt1.traj", "json-events") must_== ParseResult.ParseSuccess
}
"test geo_opt1 with json" >> {
ParserRun.parse(AsapParser, "parsers/asap/test/examples/geo_opt1.traj", "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