Commit b3f6f3a8 authored by Daniel Speckhard's avatar Daniel Speckhard
Browse files

Nomad Fair

parent 0c709a6a
......@@ -9,6 +9,7 @@ syntax: glob
*.pyc
*.bk
*.swp
*.egg-info
.DS_Store
# logging files
......
from libatomsparser.libAtomsParser import LibAtomsParserWrapper
......@@ -17,15 +17,15 @@ import os
import sys
import re
import json
#import logging
import setup_paths
import logging
# import setup_paths
import numpy as np
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.parser_backend import JsonParseEventsWriterBackend
from contextlib import contextmanager
from libLibAtomsParser import *
from libatomsparser.libLibAtomsParser import *
try:
from libMomo import osio, endl, flush
......@@ -41,11 +41,31 @@ parser_info = {
"json": "../../../../nomad-meta-info/meta_info/nomad_meta_info/lib_atoms.nomadmetainfo.json"
}
class LibAtomsParserWrapper():
""" 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__)), "lib_atoms.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(filePath = metaInfoPath, dependencyLoader = None, extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)
from unittest.mock import patch
logging.info('lib-atoms parser started')
logging.getLogger('nomadcore').setLevel(logging.WARNING)
backend = self.backend_factory(metaInfoEnv)
# Call the old parser without a class.
parserInfo = {'name': 'lib_atoms-parser', 'version': '0.0'}
backend = parse_without_class(mainfile, backend, parserInfo)
return backend
# LOGGING
def log(msg, highlight=None, enter=endl):
if osio:
if highlight==None: hightlight = osio.ww
osio << highlight << msg << enter
# if osio:
# if highlight==None: hightlight = osio.ww
# osio << highlight << msg << enter
return
# CONTEXT GUARD
......@@ -75,18 +95,23 @@ def push_array_values(jbe, value, key):
jbe.addArrayValues(key, value)
return value
def parse(output_file_name):
jbe = JsonParseEventsWriterBackend(meta_info_env)
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))
# jbe = JsonParseEventsWriterBackend(meta_info_env)
# jbe.startedParsingSession(output_file_name, parser_info)
# base_dir = os.path.dirname(os.path.abspath(output_file_name))
terminal_gap = LibAtomsGapParser(osio)
terminal_gap.ParseOutput(output_file_name, base_dir)
terminal_trj = terminal_gap.trj
osio << "Start parsing ..." << osio.endl
osio << "Base directory = '%s'" % base_dir << osio.endl
# osio << "Start parsing ..." << osio.endl
# osio << "Base directory = '%s'" % base_dir << osio.endl
gap = terminal_gap
trj = terminal_trj
......@@ -167,7 +192,7 @@ def parse(output_file_name):
push_array_values(jbe, gap['gpCoordinates.%s' % key].As(), 'x_lib_atoms_gpCoordinates_%s' % key.replace('.', '_'))
jbe.finishedParsingSession("ParseSuccess", None)
return
return jbe
if __name__ == '__main__':
......
......@@ -178,8 +178,8 @@ class LibAtomsParser(object):
# PARSE CONFIGURATIONS
self.ase_configs = read_fct(output_file, **read_fct_args)
for config in ase_configs:
print(config)
# for config in ase_configs:
# print(config)
self.Set('program_name', 'libAtoms')
self.Set('program_version', 'n/a')
......@@ -340,7 +340,7 @@ class LibAtomsFrame(LibAtomsParser):
self.config_type = None
def LoadAseConfig(self, ase_config):
self.ase_config = ase_config
print("INFO", self.ase_config.info)
# print("INFO", self.ase_config.info)
key = 'energy'
if key in self.ase_config.info:
self.has_energy = True
......
......@@ -220,7 +220,7 @@ class OptionsInterface(object):
except KeyError:
raise ValueError('CLIO does not know how to convert %s into a boolean.' % expr)
def InterpretAsNumpyArray(self, expr):
print("Interpret", expr)
# print("Interpret", expr)
array = [ float(e) for e in expr ]
array = np.array(array)
return array
......@@ -374,7 +374,7 @@ class ShellInterface(object):
mssg = self.color_dict[c] + mssg + self.color_dict['endcolor']
if h:
mssg = self.os_generate_header(mssg, t)
print(mssg)
# print(mssg)
# LOGFILE ADAPTOR =========================================================
def ConnectToFile(self, logfile):
self.logfile = logfile
......@@ -419,7 +419,7 @@ class ShellInterface(object):
mssg = OS_COLOR_DICT[c] + mssg + OS_COLOR_DICT['endcolor']
if h:
mssg = os_generate_header(mssg, t)
print(mssg)
# print(mssg)
return
def os_print_config(self, c=None, j=None, h=False, t="=", tl=' '):
self.sel_color = c
......
# Copyright 2015-2019 NOMAD
#
# 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='libatomsparser',
version='0.1',
description='NOMAD parser implementation for Lib-Atoms.',
license='APACHE 2.0',
package_dir={'': './'},
packages=find_packages(),
install_requires=[
'nomadcore'
],
)
if __name__ == '__main__':
main()
/*
* Copyright 2016-2018 Fawzi Mohamed, Carl Poelking, Daria Tomecka
*
* 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 LibAtomsParser extends SimpleExternalParserGenerator(
name = "LibAtomsParser",
parserInfo = jn.JObject(
("name" -> jn.JString("LibAtomsParser")) ::
("parserId" -> jn.JString("LibAtomsParser" + lab.LibAtomsVersionInfo.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.LibAtomsVersionInfo.toMap.map {
case (key, value) =>
(key -> jn.JString(value.toString))
}(breakOut): List[(String, jn.JString)])
)) :: Nil
),
mainFileTypes = Seq("application/xml"),
mainFileRe = """\s*<GAP_params\s""".r,
cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/parsers/lib-atoms/parser/parser-lib-atoms/libAtomsParser.py",
"${mainFilePath}"),
resList = Seq(
"parser-lib-atoms/libAtomsParser.py",
"parser-lib-atoms/libLibAtomsParser.py",
"parser-lib-atoms/libMomo.py",
"parser-lib-atoms/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/lib_atoms.nomadmetainfo.json"
) ++ DefaultPythonInterpreter.commonFiles(),
dirMap = Map(
"parser-lib-atoms" -> "parsers/lib-atoms/parser/parser-lib-atoms",
"nomad_meta_info" -> "nomad-meta-info/meta_info/nomad_meta_info"
) ++ DefaultPythonInterpreter.commonDirMapping()
)
/*
* Copyright 2016-2018 Fawzi Mohamed, Carl Poelking, Daria Tomecka
*
* 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 LibAtomsParserSpec extends Specification {
"LibAtomsParserTest" >> {
"test with json-events" >> {
ParserRun.parse(LibAtomsParser, "parsers/lib-atoms/test/lib-atoms-gap-test/gp.xml", "json-events") must_== ParseResult.ParseSuccess
}
"test with json" >> {
ParserRun.parse(LibAtomsParser, "parsers/lib-atoms/test/lib-atoms-gap-test/gp.xml", "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