Commit 4d2bc025 authored by Daniel Speckhard's avatar Daniel Speckhard
Browse files

Nomad-faird

parent 49782a92
......@@ -9,6 +9,7 @@ syntax: glob
*.pyc
*.bk
*.swp
*.egg-info
.DS_Store
# logging files
......
from octopusparser.parser_octopus import OctopusParserWrapper
\ No newline at end of file
# Copyright 2015-2018 Ask Hjorth Larsen, 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.
......@@ -24,16 +24,17 @@ from glob import glob
from contextlib import contextmanager
import numpy as np
import logging
from ase.units import Bohr
from ase.io import read
import setup_paths
# import setup_paths
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.parser_backend import JsonParseEventsWriterBackend
from nomadcore.unit_conversion.unit_conversion import convert_unit
from aseoct import Octopus, parse_input_file
from octopusparser.aseoct import Octopus, parse_input_file
"""This is the Octopus parser.
......@@ -232,7 +233,7 @@ def normalize_names(names):
return [name.lower() for name in names]
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
"../../../../nomad-meta-info/meta_info/nomad_meta_info/octopus.nomadmetainfo.json"))
"../../../../dependencies/nomad-meta-info/meta_info/nomad_meta_info/octopus.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(filePath=metaInfoPath,
dependencyLoader=None,
extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS,
......@@ -286,12 +287,13 @@ def is_octopus_logfile(fname):
def find_octopus_logfile(dirname):
for fname in os.listdir(dirname):
fname = os.path.join(dirname, fname)
if os.path.isfile(fname) and is_octopus_logfile(fname):
return fname
return None
def override_keywords(kwargs, parser_log_kwargs, fd):
def override_keywords(kwargs, parser_log_kwargs):
# Some variables we can get from the input file, but they may
# contain arithmetic and variable assignments which cannot
# just be parsed into a final value. The output of the
......@@ -321,10 +323,13 @@ def override_keywords(kwargs, parser_log_kwargs, fd):
outkwargs[name] = [lsize]
continue
print('Keyword %s with value %s overridden by value '
'%s obtained from parser log'
% (name, kwargs[name], parser_log_kwargs[name]),
file=fd)
# print('Keyword %s with value %s overridden by value '
# '%s obtained from parser log'
# % (name, kwargs[name], parser_log_kwargs[name]),
# file=fd)
logging.debug('Keyword %s with value %s overridden by value '
'%s obtained from parser log'
% (name, kwargs[name], parser_log_kwargs[name]))
outkwargs[name] = parser_log_kwargs[name]
return outkwargs
......@@ -367,18 +372,23 @@ def register_octopus_keywords(pew, category, kwargs):
pew.addValue(name, value)
def parse(fname, fd):
def parse_without_class(fname, backend, parser_info):
# fname refers to the static/info file.
# Look for files before we create some of our own files for logging etc.:
# fd = stdout # Print output to stdout
absfname = os.path.abspath(fname)
staticdirname, _basefname = os.path.split(absfname)
dirname, _static = os.path.split(staticdirname)
assert _static == 'static'
# staticdirname, _basefname = os.path.split(absfname)
# dirname, _static = os.path.split(staticdirname)
dirname = os.path.dirname(os.path.abspath(fname))
# assert _static == 'static'
inp_path = os.path.join(dirname, 'inp')
parser_log_path = os.path.join(dirname, 'exec', 'parser.log')
logfile = find_octopus_logfile(dirname)
pew = JsonParseEventsWriterBackend(metaInfoEnv)
# pew = JsonParseEventsWriterBackend(metaInfoEnv)
# pew.startedParsingSession(fname, parser_info)
pew = backend
pew.startedParsingSession(fname, parser_info)
# this context manager shamelessly copied from GPAW parser
......@@ -393,22 +403,27 @@ def parse(fname, fd):
pew.addValue('program_name', 'Octopus')
pew.addValue('program_basis_set_type', 'Real-space grid')
print(file=fd)
print('Read Octopus keywords from input file %s' % inp_path,
file=fd)
# print(file=fd)
# print('Read Octopus keywords from input file %s' % inp_path,
# file=fd)
logging.debug('Read Octopus keywords from input file %s' % inp_path)
with open(inp_path) as inp_fd:
kwargs = parse_input_file(inp_fd)
register_octopus_keywords(pew, 'input', kwargs)
print('Read processed Octopus keywords from octparse logfile %s'
% parser_log_path, file=fd)
# print('Read processed Octopus keywords from octparse logfile %s'
# % parser_log_path, file=fd)
logging.debug(
'Read processed Octopus keywords from octparse logfile %s' % parser_log_path)
parser_log_kwargs = read_parser_log(parser_log_path)
register_octopus_keywords(pew, 'parserlog', parser_log_kwargs)
print('Override certain keywords with processed keywords', file=fd)
kwargs = override_keywords(kwargs, parser_log_kwargs, fd)
# print('Override certain keywords with processed keywords', file=fd)
kwargs = override_keywords(kwargs, parser_log_kwargs)
print('Read as ASE calculator', file=fd)
# print('Read as ASE calculator', file=fd)
calc = Octopus(dirname)
with open_section('section_basis_set_cell_dependent') as basis_set_cell_dependent_gid:
......@@ -420,13 +435,16 @@ def parse(fname, fd):
nkpts = len(calc.get_k_point_weights())
if logfile is None:
print('No stdout logfile found', file=fd)
# print('No stdout logfile found', file=fd)
logging.debug('No stdout logfile found')
else:
print('Found stdout logfile %s' % logfile, file=fd)
print('Parse logfile %s' % logfile, file=fd)
# print('Found stdout logfile %s' % logfile, file=fd)
logging.debug('Found stdout logfile %s' % logfile)
# print('Parse logfile %s' % logfile, file=fd)
logging.debug('Parse logfile %s' % logfile)
parse_logfile(metaInfoEnv, pew, logfile)
print('Add parsed values', file=fd)
# print('Add parsed values', file=fd)
with open_section('section_system') as system_gid:
gridinfo = parse_gridinfo(metaInfoEnv, pew, fname)
cell_unit = gridinfo['unit']
......@@ -499,7 +517,8 @@ def parse(fname, fd):
with open_section('section_single_configuration_calculation'):
pew.addValue('single_configuration_calculation_to_system_ref',
system_gid)
print('Parse info file %s' % fname, file=fd)
# print('Parse info file %s' % fname, file=fd)
logging.debug('Parse info file %s' % fname)
parse_infofile(metaInfoEnv, pew, fname)
with open_section('section_method') as method_gid:
......@@ -587,9 +606,33 @@ def parse(fname, fd):
pew.addArrayValues('eigenvalues_occupation', occ)
pew.finishedParsingSession('ParseSuccess', None)
return backend
class OctopusParserWrapper():
""" 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__)), "octopus.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(
filePath = metaInfoPath, dependencyLoader = None,
extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)
from unittest.mock import patch
logging.info('octopus parser started')
logging.getLogger('nomadcore').setLevel(logging.WARNING)
backend = self.backend_factory(metaInfoEnv)
# Call the old parser without a class.
parserInfo = parser_info
backend = parse_without_class(mainfile, backend, parserInfo)
return backend
if __name__ == '__main__':
fname = sys.argv[1]
logfname = 'parse.log'
with open(logfname, 'w') as fd:
parse(fname, fd)
parse(fname, fd)
\ No newline at end of file
../../test/examples
\ No newline at end of file
# 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='octopusparser',
version='0.1',
description='NOMAD parser implementation for Octopus.',
license='APACHE 2.0',
package_dir={'': './'},
packages=find_packages(),
install_requires=[
'nomadcore'
],
)
if __name__ == '__main__':
main()
/*
* Copyright 2015-2018 Ask Hjorth Larsen, 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
import eu.nomad_lab.parsers.AncillaryFilesPrefilter.{ ParentSubtree => ParentSubtree }
import eu.nomad_lab.parsers.AncillaryFilesPrefilter.{ WholeUpload => WholeUpload }
object OctopusParser extends SimpleExternalParserGenerator(
name = "OctopusParser",
parserInfo = jn.JObject(
("name" -> jn.JString("OctopusParser")) ::
("parserId" -> jn.JString("OctopusParser" + lab.OctopusVersionInfo.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.OctopusVersionInfo.toMap.map {
case (key, value) =>
(key -> jn.JString(value.toString))
}(breakOut): List[(String, jn.JString)])
)) :: Nil
),
mainFileTypes = Seq("text/.*"),
//TODO: Update the replacement string (mainFileRe)
mainFileRe = """\*{32} Grid \*{32}
Simulation Box:
""".r,
cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/parsers/octopus/parser/parser-octopus/parser_octopus.py",
"${mainFilePath}"),
ancillaryFilesPrefilter = ParentSubtree,
resList = Seq(
"parser-octopus/parser_octopus.py",
"parser-octopus/aseoct.py",
"parser-octopus/generate-octopus-json.py",
"parser-octopus/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/octopus.autogenerated.nomadmetainfo.json",
"nomad_meta_info/octopus.nomadmetainfo.json"
) ++ DefaultPythonInterpreter.commonFiles(),
dirMap = Map(
"parser-octopus" -> "parsers/octopus/parser/parser-octopus",
"nomad_meta_info" -> "nomad-meta-info/meta_info/nomad_meta_info"
) ++ DefaultPythonInterpreter.commonDirMapping()
)
/*
* Copyright 2015-2018 Ask Hjorth Larsen, 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 OctopusParserSpec extends Specification {
"OctopusParserTest" >> {
"test with json-events" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/ink-gs/static/info", "json-events") must_== ParseResult.ParseSuccess
}
"test with json" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/ink-gs/static/info", "json") must_== ParseResult.ParseSuccess
}
"test H2O with json-events" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/H2O/static/info", "json-events") must_== ParseResult.ParseSuccess
}
"test H2O with json" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/H2O/static/info", "json") must_== ParseResult.ParseSuccess
}
"test O2 with json-events" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/O2/static/info", "json-events") must_== ParseResult.ParseSuccess
}
"test O2 with json" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/O2/static/info", "json") must_== ParseResult.ParseSuccess
}
"test Si with json-events" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/Si/static/info", "json-events") must_== ParseResult.ParseSuccess
}
"test Si with json" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/Si/static/info", "json") must_== ParseResult.ParseSuccess
}
"test Fe with json-events" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/Fe/static/info", "json-events") must_== ParseResult.ParseSuccess
}
"test Fe with json" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/Fe/static/info", "json") must_== ParseResult.ParseSuccess
}
"test newFe with json-events" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/newFe/static/info", "json-events") must_== ParseResult.ParseSuccess
}
"test newFe with json" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/newFe/static/info", "json") must_== ParseResult.ParseSuccess
}
"test newH2O with json-events" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/newH2O/static/info", "json-events") must_== ParseResult.ParseSuccess
}
"test newH2O with json" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/newH2O/static/info", "json") must_== ParseResult.ParseSuccess
}
"test newO2 with json-events" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/newO2/static/info", "json-events") must_== ParseResult.ParseSuccess
}
"test newO2 with json" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/newO2/static/info", "json") must_== ParseResult.ParseSuccess
}
"test newSi with json-events" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/newSi/static/info", "json-events") must_== ParseResult.ParseSuccess
}
"test newSi with json" >> {
ParserRun.parse(OctopusParser, "parsers/octopus/test/examples/newSi/static/info", "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