Commit ae97cd46 authored by Daniel Speckhard's avatar Daniel Speckhard

Ready for Nomad-Faird

parent 0ad9cb3f
......@@ -9,6 +9,7 @@ syntax: glob
*.pyc
*.bk
*.swp
*.egg-info
.DS_Store
# eclipse conf file
......
......@@ -15,7 +15,6 @@
from __future__ import print_function
from builtins import range
from builtins import object
import setup_paths
import numpy as np
import math
from nomadcore.simple_parser import mainFunction
......@@ -38,7 +37,7 @@ class DL_POLYParserContext(object):
def onClose_section_system(self, backend, gIndex, section):
print("<onClose_section_system>")
return
def onClose_dl_poly_section_md_molecule_type(self, backend, gIndex, section):
def onClose_x_dl_poly_section_md_molecule_type(self, backend, gIndex, section):
print("<onClose_molecule_type>")
return
......@@ -67,18 +66,18 @@ mainFileDescription = SM(name = 'root',
SM(name = 'progHeader',
startReStr = r" \*\* DL_POLY \*\* authors: i.t.todorov & w.smith \** P \**",
subMatchers = [
SM(r"\s*\*\*\s*\*\* version: (?P<program_version>[0-9a-zA-Z_.]*) / \s* (?P<dl_poly_program_version_date>[\w]*\s*[\w]*)\s*\** O \**"),
SM(r"\s*\*\*\s*\*\* version: (?P<program_version>[0-9a-zA-Z_.]*) / \s* (?P<x_dl_poly_program_version_date>[\w]*\s*[\w]*)\s*\** O \**"),
SM(r"\s*\** when publishing research data obtained using (?P<program_name>[0-9a-zA-Z_.]*) \**"),
SM(r"\s*\**\s*(?P<dl_poly_system_description>[0-9a-zA-Z_()]*)\s*\**")
SM(r"\s*\**\s*(?P<x_dl_poly_system_description>[0-9a-zA-Z_()]*)\s*\**")
]),
SM(name = 'mdParams',
startReStr = r"\s*SIMULATION CONTROL PARAMETERS\s*",
required = True,
sections = ['section_method'],
subMatchers = [
SM(r"\s*simulation temperature \(K\)\s*(?P<dl_poly_thermostat_temperature>[-+0-9.eEdD]*)\s*"),
SM(r"\s*equilibration period \(steps\)\s*(?P<dl_poly_step_number_equilibration>[0-9]*)\s*"),
SM(r"\s*selected number of timesteps\s*(?P<dl_poly_step_number>[0-9]*)\s*")
SM(r"\s*simulation temperature \(K\)\s*(?P<x_dl_poly_thermostat_temperature>[-+0-9.eEdD]*)\s*"),
SM(r"\s*equilibration period \(steps\)\s*(?P<x_dl_poly_step_number_equilibration>[0-9]*)\s*"),
SM(r"\s*selected number of timesteps\s*(?P<x_dl_poly_step_number>[0-9]*)\s*")
]),
# Open system
......@@ -96,18 +95,18 @@ mainFileDescription = SM(name = 'root',
startReStr = r"\s*number of molecular types\s*[0-9]*\s*",
required = True,
forwardMatch = True,
sections = ['dl_poly_section_md_topology'],
sections = ['x_dl_poly_section_md_topology'],
subMatchers = [
SM(r"\s*number of molecular types\s*(?P<dl_poly_md_molecular_types>[0-9]*)"),
SM(r"\s*number of molecular types\s*(?P<x_dl_poly_md_molecular_types>[0-9]*)"),
SM(name = 'mdTopologyMolecule',
startReStr = r"\s*molecular species type\s*[0-9]*\s*",
repeats = True,
required = True,
forwardMatch = True,
sections = ['dl_poly_section_md_molecule_type'],
sections = ['x_dl_poly_section_md_molecule_type'],
subMatchers = [
SM(r"\s*molecular species type\s*(?P<dl_poly_md_molecule_type_id>[0-9]*)\s*"),
SM(r"\s*name of species:\s*(?P<dl_poly_md_molecule_type_name>[\w]* [\w]*)\s*")
SM(r"\s*molecular species type\s*(?P<x_dl_poly_md_molecule_type_id>[0-9]*)\s*"),
SM(r"\s*name of species:\s*(?P<x_dl_poly_md_molecule_type_name>[\w]* [\w]*)\s*")
])
])
#SM(r"\s*number of molecular types\s*(?P<dl_poly_molecular_types_number>[0-9]*)\s*"),
......@@ -196,13 +195,41 @@ mainFileDescription = SM(name = 'root',
# THIS PARSER
parserInfo = {'name':'dl_poly-parser', 'version': '0.0'}
# LOAD METADATA
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),"../../../../nomad-meta-info/meta_info/nomad_meta_info/dl_poly.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(filePath = metaInfoPath, dependencyLoader = None, extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)
# # LOAD METADATA
# metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),"../../../../nomad-meta-info/meta_info/nomad_meta_info/dl_poly.nomadmetainfo.json"))
# metaInfoEnv, warnings = loadJsonFile(filePath = metaInfoPath, dependencyLoader = None, extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)
# CUSTOMIZE CACHING
cachingLevelForMetaName = {}
import nomad_meta_info
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(nomad_meta_info.__file__)), "dl_poly.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(filePath = metaInfoPath, dependencyLoader = None, extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)
class DlPolyParser():
""" 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('dl-poly parser started')
logging.getLogger('nomadcore').setLevel(logging.WARNING)
backend = self.backend_factory(metaInfoEnv)
with patch.object(sys, 'argv', ['<exe>', '--uri', 'nmd://uri', mainfile]):
mainFunction(
mainFileDescription=mainFileDescription,
metaInfoEnv=metaInfoEnv,
parserInfo = parserInfo,
cachingLevelForMetaName = cachingLevelForMetaName,
superContext=DL_POLYParserContext(),
superBackend=backend,
onClose = {},
defaultSectionCachingLevel = True)
return backend
if __name__ == "__main__":
mainFunction(mainFileDescription,
......
# Copyright 2015-2018 Lauri Himanen, 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.
# See the License for the specific language governing permissions and
# limitations under the License.
from dlpolyparser.dlPolyParser import DlPolyParserWrapper
......@@ -17,18 +17,17 @@ import os
import sys
import re
import json
#import logging
import setup_paths
import logging
import numpy as np
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.parser_backend import JsonParseEventsWriterBackend
from contextlib import contextmanager
from libDlPolyParser import *
from dlpolyparser.libDlPolyParser import *
try:
from libMomo import osio, endl, flush
from dlpolyparser.libMomo import osio, endl, flush
osio.ConnectToFile('parser.osio.log')
green = osio.mg
except:
......@@ -36,11 +35,11 @@ except:
green = None
parser_info = {
"name": "parser-dl-poly",
"version": "0.0",
"json": "../../../../nomad-meta-info/meta_info/nomad_meta_info/dl_poly.nomadmetainfo.json"
}
# parser_info = {
# "name": "parser-dl-poly",
# "version": "0.0",
# "json": "../../../../nomad-meta-info/meta_info/nomad_meta_info/dl_poly.nomadmetainfo.json"
# }
# LOGGING
def log(msg, highlight=None, enter=endl):
......@@ -88,8 +87,45 @@ def push_array_values(jbe, value, key, conv=None):
jbe.addArrayValues(key, value)
return value
def parse(output_file_name):
jbe = JsonParseEventsWriterBackend(meta_info_env)
# class DlPolyParser():
# """ A proper class envolop for running this parser from within python. """
# def __init__(self, backend, **kwargs):
# self.backend_factory = backend
# from unittest.mock import patch
# logging.info('dl-poly parser started')
# logging.getLogger('nomadcore').setLevel(logging.WARNING)
# backend = self.backend_factory(metaInfoEnv)
# # Rename parser
# def parse(self, mainfile):
logger = logging.getLogger("nomad.DLPolyParser")
class DlPolyParserWrapper():
""" A proper class envolop for running this parser using Noamd-FAIRD infra. """
def __init__(self, backend, **kwargs):
self.backend_factory = backend
def parse(self, mainfile):
import nomad_meta_info
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(nomad_meta_info.__file__)), "dl_poly.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(filePath = metaInfoPath, dependencyLoader = None, extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)
from unittest.mock import patch
logging.info('dl-poly parser started')
logging.getLogger('nomadcore').setLevel(logging.WARNING)
backend = self.backend_factory(metaInfoEnv)
# Call the old parser without a class.
parserInfo = {'name': 'dl_poly-parser', 'version': '0.0'}
backend = parse_without_class(mainfile, backend, parserInfo)
return backend
def parse_without_class(output_file_name, backend, parser_info):
""" Parse method to parse mainfile and write output to backend."""
jbe = backend
jbe.startedParsingSession(output_file_name, parser_info)
base_dir = os.path.dirname(os.path.abspath(output_file_name))
......@@ -252,8 +288,10 @@ def parse(output_file_name):
with open_section(jbe, 'section_system') as gid:
refs_system_description.append(gid)
# Configuration core
atom_labels = np.array([ atom['atom_name'].As() for atom in frame.atoms ])
atom_labels = np.array(
[ atom['atom_name'].As().replace('+','').replace('-','') for atom in frame.atoms ])
push_array_values(jbe, atom_labels, 'atom_labels')
# push_array_values(jbe, atom_species, 'atom_atom_numbers')
push_array_values(jbe, frame.position_matrix, 'atom_positions', conv=UNITCONV_DLPOLY_TO_SI['length'])
push_array_values(jbe, frame.box_matrix, 'simulation_cell', conv=UNITCONV_DLPOLY_TO_SI['length'])
push_array_values(jbe, frame.pbc_booleans, 'configuration_periodic_dimensions')
......@@ -296,7 +334,7 @@ def parse(output_file_name):
pass
jbe.finishedParsingSession("ParseSuccess", None)
return
return jbe
if __name__ == '__main__':
......
# Copyright 2015-2018 Lorenzo Pardini
#
# 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='dlpolyparser',
version='0.1',
description='NOMAD parser implementation for DL-Poly.',
license='APACHE 2.0',
package_dir={'': './'},
packages=find_packages(),
install_requires=[
'nomadcore'
],
)
if __name__ == '__main__':
main()
/*
* Copyright 2016-2018 Carl Poelking, 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.
* 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
object DlPolyParser extends SimpleExternalParserGenerator(
name = "DlPolyParser",
parserInfo = jn.JObject(
("name" -> jn.JString("DlPolyParser")) ::
("parserId" -> jn.JString("DlPolyParser" + lab.DlPolyVersionInfo.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.DlPolyVersionInfo.toMap.map {
case (key, value) =>
(key -> jn.JString(value.toString))
}(breakOut): List[(String, jn.JString)])
)) :: Nil
),
mainFileTypes = Seq("text/.*"),
mainFileRe = """ DL_POLY """.r,
cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/parsers/dl_poly/parser/parser-dl_poly/dlPolyParser.py",
"${mainFilePath}"),
resList = Seq(
"parser-dl_poly/dlPolyParser.py",
"parser-dl_poly/libDlPolyParser.py",
"parser-dl_poly/libMomo.py",
"parser-dl_poly/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/dl_poly.nomadmetainfo.json"
) ++ DefaultPythonInterpreter.commonFiles(),
dirMap = Map(
"parser-dl_poly" -> "parsers/dl_poly/parser/parser-dl_poly",
"nomad_meta_info" -> "nomad-meta-info/meta_info/nomad_meta_info"
) ++ DefaultPythonInterpreter.commonDirMapping()
)
/*
* Copyright 2016-2018 Carl Poelking, 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.
* 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 DlPolyParserSpec extends Specification {
"DlPolyParserTest" >> {
"test with json-events" >> {
ParserRun.parse(DlPolyParser, "parsers/dl-poly/test/examples/dl-poly-test1/OUTPUT", "json-events") must_== ParseResult.ParseSuccess
}
"test with json" >> {
ParserRun.parse(DlPolyParser, "parsers/dl-poly/test/examples/dl-poly-test1/OUTPUT", "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