Commit 49851e8c authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added a repository normalizer.

parent 18c80134
......@@ -18,6 +18,7 @@ from .system import SystemNormalizer
from .symmetry import SymmetryNormalizer
from .systemtype import SystemTypeNormalizer
from .fhiaims import FhiAimsBaseNormalizer
from .repository import RepositoryNormalizer
"""
After parsing calculations have to be normalized with a set of *normalizers*.
......@@ -46,5 +47,6 @@ normalizers: List[Any] = [
SystemNormalizer,
FhiAimsBaseNormalizer,
SymmetryNormalizer,
SystemTypeNormalizer
SystemTypeNormalizer,
RepositoryNormalizer
]
# Copyright 2018 Fawzi Mohamed, Danio Brambila, Markus Scheidgen
#
# 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 nomad import utils
from .normalizer import Normalizer
class RepositoryNormalizer(Normalizer):
"""
The normalizer that turnes normalized parse results into a set of metadata
quantities for the repository.
"""
def normalize(self, logger=None) -> None:
super().normalize(logger)
b = self._backend
b.openNonOverlappingSection('section_repository_info')
b.openNonOverlappingSection('section_repository_parserdata')
b.addValue('repository_checksum', utils.archive.calc_hash(b.get_value('archive_id', 0)))
b.addValue('repository_chemical_formula', b.get_value('chemical_composition_bulk_reduced', 0))
b.addValue('repository_parser_id', b.get_value('parser_name', 0))
atoms = b.get_value('atom_labels', 0)
b.addValue('repository_atomic_elements', atoms)
b.addValue('repository_atomic_elements_count', len(atoms))
b.addValue('repository_basis_set_type', b.get_value('program_basis_set_type', 0))
b.addValue('repository_crystal_system', b.get_value('crystal_system', 0))
b.addValue('repository_program_name', b.get_value('program_name', 0))
# TODO shorten and normalize the code version
b.addValue('repository_code_version', b.get_value('program_version', 0))
b.addValue('repository_spacegroup_nr', b.get_value('space_group_number', 0))
b.addValue('repository_system_type', b.get_value('system_type', 0))
# TODO shorten and normalize to functional type
b.addValue('repository_xc_treatment', b.get_value('XC_functional_name', 0))
b.closeNonOverlappingSection('section_repository_parserdata')
b.closeNonOverlappingSection('section_repository_info')
b.finishedParsingSession("ParseSuccess", None)
......@@ -59,6 +59,9 @@ class UserData(InnerDoc):
dataset_doi_id=Long()))
))
def fill_from_coe_repo(self, calc: coe_repo.Calc):
pass
class CalcData(InnerDoc):
repository_checksum = Keyword()
......
......@@ -50,13 +50,12 @@ def normalized_template_example(parsed_template_example) -> LocalBackend:
def assert_normalized(backend):
assert backend.get_value('atom_species', 0) is not None
assert backend.get_value('system_type', 0) is not None
assert backend.get_value('crystal_system', 0) is not None
assert backend.get_value('space_group_number', 0) is not None
assert backend.get_value('XC_functional_name', 0) is not None
assert backend.get_value('chemical_composition', 0) is not None
assert backend.get_value('chemical_composition_bulk_reduced', 0) is not None
count = 0
for metainfo in backend.metaInfoEnv().infoKindEls():
if 'section_repository_parserdata' in metainfo.superNames:
count += 1
assert backend.get_value(metainfo.name, 0) is not None
assert count > 0
def test_normalizer(normalized_example: LocalBackend, no_warn):
......
......@@ -217,7 +217,8 @@ def assert_parser_result(backend):
def run_parser(parser_name, mainfile):
parser = parser_dict[parser_name]
return parser.run(mainfile, logger=utils.get_logger(__name__))
result = parser.run(mainfile, logger=utils.get_logger(__name__))
return add_calculation_info(result)
@pytest.fixture
......@@ -235,10 +236,19 @@ def parsed_template_example() -> LocalBackend:
@pytest.fixture(params=parser_examples, ids=lambda spec: '%s-%s' % spec)
def parsed_example(request) -> LocalBackend:
parser_name, mainfile = request.param
run_parser(parser_name, mainfile)
return run_parser(parser_name, mainfile)
def add_calculation_info(backend: LocalBackend) -> LocalBackend:
backend.openNonOverlappingSection('section_calculation_info')
backend.addValue('upload_id', 'test_upload_id')
backend.addValue('archive_id', 'test_upload_hash/test_calc_hash')
backend.addValue('main_file', 'test/mainfile.txt')
backend.addValue('parser_name', 'testParser')
backend.closeNonOverlappingSection('section_calculation_info')
return backend
def test_parser(parsed_example, no_warn):
assert_parser_result(parsed_example)
......
Supports Markdown
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