Commit bab03a28 authored by Daniel Speckhard's avatar Daniel Speckhard

FAIRD integration.

parent 7974957f
......@@ -9,6 +9,7 @@ syntax: glob
*.pyc
*.bk
*.swp
*.egg-info
.DS_Store
# logging files
......
# 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 atkparser.parser_atk import ATKParserWrapper
# 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.
......@@ -15,9 +15,9 @@
from scipy.io.netcdf import netcdf_file
import numpy as np
from ase.units import Hartree
from configurations import conf_types
from parser_configurations import parse_configuration
from parser_calculator import parse_calculator
from atkparser.configurations import conf_types
from atkparser.parser_configurations import parse_configuration
from atkparser.parser_calculator import parse_calculator
import re
......@@ -111,7 +111,7 @@ class Reader:
eigenvalues = eigenvalues.reshape(2, 1, -1)
wf.eigenvalues = eigenvalues
continue
def read_names(self):
"""Read the names of the variables in the netcdf file for
configurations and calculators and setup
......
# 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.
......@@ -14,8 +14,8 @@
from copy import copy
from scipy.io.netcdf import netcdf_file
from parser_configurations import parse_configuration as p_conf
from parser_calculator import parse_calculator as p_calc
from atkparser.parser_configurations import parse_configuration as p_conf
from atkparser.parser_calculator import parse_calculator as p_calc
import re
class X:
......@@ -51,7 +51,7 @@ class Reader:
print(self.finger_prints)
self.extract_common_concepts() # atoms
self.extract_calculator() # extract the calculator
self.extract_total_energy() # look for total energy
self.extract_total_energy() # look for total energy
self.extract_results() # look for results, forces, stress etc
self.extract_wave_functions() # look for eigenvalues, wave functions
self.extract_bandstructure() # look for band structures
......
# 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.
......@@ -16,15 +16,15 @@ from __future__ import division
import os
from contextlib import contextmanager
import numpy as np
import logging
from ase import units
from ase.data import chemical_symbols
from atkio import Reader
from atkparser.atkio import Reader
from ase.data import atomic_masses
import setup_paths
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
from libxc_names import get_libxc_xc_names
from atkparser.libxc_names import get_libxc_xc_names
@contextmanager
......@@ -42,16 +42,28 @@ def c(value, unit=None):
parser_info = {"name": "parser_atk", "version": "1.0"}
path = '../../../../nomad-meta-info/meta_info/nomad_meta_info/' +\
'atk.nomadmetainfo.json'
import nomad_meta_info
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):
os.path.join(os.path.dirname(os.path.abspath(nomad_meta_info.__file__)),
"atk.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(
filePath = metaInfoPath, dependencyLoader = None,
extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)
class ATKParserWrapper():
""" 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):
from unittest.mock import patch
logging.info('ATK parser started')
logging.getLogger('nomadcore').setLevel(logging.WARNING)
backend = self.backend_factory(metaInfoEnv)
backend = parse_without_class(mainfile, backend)
return backend
def parse_without_class(filename, backend):
r = Reader(filename)
indices = range(r.get_number_of_calculators())
for index in indices:
......@@ -60,7 +72,7 @@ def parse(filename):
return
r.atoms = r.get_atoms(index)
p = JsonParseEventsWriterBackend(metaInfoEnv)
p = backend # JsonParseEventsWriterBackend(metaInfoEnv)
o = open_section
p.startedParsingSession(filename, parser_info)
with o(p, 'section_run'):
......@@ -172,6 +184,7 @@ def parse(filename):
band_path.kpoints[-1]]))
p.finishedParsingSession("ParseSuccess", None)
return p
if __name__ == '__main__':
import sys
......
# 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.
......@@ -14,7 +14,7 @@
from ase import data
import re
from physical_quantities import eV, Angstrom, Bohr, Kelvin, Hour, Hartree
from atkparser.physical_quantities import eV, Angstrom, Bohr, Kelvin, Hour, Hartree
All = 'All'
Automatic = 'Automatic'
......
# 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.
from periodic_table import things as ptab_ns
from physical_quantities import things as physquan_ns
from configurations import conf_types, things as confs_ns
from atkparser.periodic_table import things as ptab_ns
from atkparser.physical_quantities import things as physquan_ns
from atkparser.configurations import conf_types, things as confs_ns
def parse_configuration(fd, name, verbose=False):
......
# 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='abinitparser',
version='0.1',
description='NOMAD parser implementation for ATK.',
license='APACHE 2.0',
package_dir={'': './'},
packages=find_packages(),
install_requires=[
'nomadcore'
],
)
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 AtkParser extends SimpleExternalParserGenerator(
name = "AtkParser",
parserInfo = jn.JObject(
("name" -> jn.JString("AtkParser")) ::
("parserId" -> jn.JString("AtkParser" + lab.AtkVersionInfo.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.AtkVersionInfo.toMap.map {
case (key, value) =>
(key -> jn.JString(value.toString))
}(breakOut): List[(String, jn.JString)])
)) :: Nil
),
mainFileTypes = Seq("application/x-netcdf"),
cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/parsers/atk/parser/parser-atk/parser_atk.py",
"${mainFilePath}"),
mainFileRe = "".r,
resList = Seq(
"parser-atk/atkio.py",
"parser-atk/configurations.py",
"parser-atk/libxc_names.py",
"parser-atk/parser_atk.py",
"parser-atk/parser_calculator.py",
"parser-atk/parser_configurations.py",
"parser-atk/periodic_table.py",
"parser-atk/physical_quantities.py",
"parser-atk/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/atk.nomadmetainfo.json"
) ++ DefaultPythonInterpreter.commonFiles(),
dirMap = Map(
"parser-atk" -> "parsers/atk/parser/parser-atk",
"nomad_meta_info" -> "nomad-meta-info/meta_info/nomad_meta_info"
) ++ DefaultPythonInterpreter.commonDirMapping(),
metaInfoEnv = Some(lab.meta.KnownMetaInfoEnvs.atk)
) {
override def isMainFile(filePath: String, bytePrefix: Array[Byte], stringPrefix: Option[String]): Option[ParserMatch] = {
// TO DO: be more specific: open and look for something special, not all netcdf files are Atk files...
if (bytePrefix.startsWith("CDF".getBytes(StandardCharsets.US_ASCII)) &&
bytePrefix.size > 3 && (bytePrefix(3) == 1 || bytePrefix(3) == 2))
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 AtkParserSpec extends Specification {
"AtkParserTest" >> {
"test Si2 with json-events" >> {
ParserRun.parse(AtkParser, "parsers/atk/test/examples/Si2.nc", "json-events") must_== ParseResult.ParseSuccess
}
"test Si2 with json" >> {
ParserRun.parse(AtkParser, "parsers/atk/test/examples/Si2.nc", "json") must_== ParseResult.ParseSuccess
}
"test Water with json-events" >> {
ParserRun.parse(AtkParser, "parsers/atk/test/examples/Water.nc", "json-events") must_== ParseResult.ParseSuccess
}
"test Water with json" >> {
ParserRun.parse(AtkParser, "parsers/atk/test/examples/Water.nc", "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