Commit 2e36dc1c authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Fixed linting, fixed issues in system tests.

parent 8509728a
Pipeline #72444 failed with stages
in 17 minutes and 45 seconds
......@@ -97,7 +97,7 @@ def _parse(
mainfile, show_backend, show_metadata, skip_normalizers, not_strict, parser,
annotate):
# nomadcore.simple_parser.annotate = annotate
nomadcore.simple_parser.annotate = annotate
utils.configure_logging()
kwargs = dict(strict=not not_strict, parser_name=parser)
......
......@@ -29,6 +29,7 @@ import elasticsearch.exceptions
from typing import List
import json
import logging
import numpy as np
from nomad import config, infrastructure, parsing, processing, app, utils
from nomad.datamodel import User
......@@ -634,69 +635,6 @@ def reset_config():
infrastructure.setup_logging()
def create_test_structure(
meta_info, id: int, h: int, o: int, extra: List[str], periodicity: int,
optimade: bool = True, metadata: dict = None):
""" Creates a calculation in Elastic and Mongodb with the given properties.
Does require initialized :func:`elastic_infra` and :func:`mongo_infra`.
Args:
meta_info: A legace metainfo env.
id: A number to create ``test_calc_id_<number>`` ids.
h: The amount of H atoms
o: The amount of O atoms
extra: A list of further atoms
periodicity: The number of dimensions to repeat the structure in
optimade: A boolean. Iff true the entry will have optimade metadata. Default is True.
metadata: Additional (user) metadata.
"""
atom_labels = ['H' for i in range(0, h)] + ['O' for i in range(0, o)] + extra
test_vector = np.array([0, 0, 0])
backend = Backend(meta_info, False, True) # type: ignore
backend.openSection('section_run')
backend.addValue('program_name', 'test_code')
backend.openSection('section_system')
backend.addArrayValues('atom_labels', np.array(atom_labels))
backend.addArrayValues(
'atom_positions', np.array([test_vector for i in range(0, len(atom_labels))]))
backend.addArrayValues(
'lattice_vectors', np.array([test_vector, test_vector, test_vector]))
backend.addArrayValues(
'configuration_periodic_dimensions',
np.array([True for _ in range(0, periodicity)] + [False for _ in range(periodicity, 3)]))
backend.closeSection('section_system', 0)
backend.closeSection('section_run', 0)
# Add entry info
backend.openSection('section_entry_info')
backend.addValue('upload_id', 'test_upload_id')
backend.addValue('mainfile', 'test/mainfile.txt')
backend.closeSection('section_entry_info', 0)
backend = run_normalize(backend)
calc = CalcWithMetadata(
upload_id='test_uload_id', calc_id='test_calc_id_%d' % id, mainfile='test_mainfile',
published=True, with_embargo=False)
calc.apply_domain_metadata(backend)
if metadata is not None:
calc.update(**metadata)
if not optimade:
calc.optimade = None # type: ignore
proc_calc = processing.Calc.from_calc_with_metadata(calc)
proc_calc.save()
search_entry = search.Entry.from_calc_with_metadata(calc)
search_entry.save()
assert processing.Calc.objects(calc_id__in=[calc.calc_id]).count() == 1
@pytest.fixture
def reset_infra(mongo, elastic):
''' Fixture that resets infrastructure after deleting db or search index. '''
......
......@@ -13,10 +13,10 @@
# limitations under the License.
import ase.build
import pytest
from nomad import datamodel, config, utils
from nomad.parsing import Backend
from nomad.normalizing import normalizers
from tests.test_parsing import parsed_vasp_example # pylint: disable=unused-import
from tests.test_parsing import parsed_template_example # pylint: disable=unused-import
......@@ -247,62 +247,65 @@ def test_vasp_incar_system():
def test_aflow_prototypes():
'''Tests that some basis structures are matched with the correct AFLOW prototypes
'''
def get_proto(atoms):
entry_archive = run_normalize_for_structure(atoms)
try:
sec_proto = entry_archive.section_run[0].section_system[0].section_prototype[0]
prototype_aflow_id = sec_proto.prototype_aflow_id
prototype_label = sec_proto.prototype_label
except Exception:
prototype_aflow_id = None
prototype_label = None
return prototype_aflow_id, prototype_label
# No prototype info for non-bulk structures
backend = run_normalize_for_structure(ase.build.molecule("H2O"))
assert len(backend["section_prototype"]) == 0
water = ase.build.molecule("H2O")
prototype_aflow_id, prototype_label = get_proto(water)
assert prototype_aflow_id is None
assert prototype_label is None
# No prototype info for bulk structure without match
rattled = ase.build.bulk("C", crystalstructure="diamond", a=3.57, cubic=True)
rattled.rattle(stdev=2, seed=42)
rattled.wrap()
backend = run_normalize_for_structure(rattled)
assert len(backend["section_prototype"]) == 0
aflow_id, prototype_label = get_proto(rattled)
assert aflow_id is None
assert prototype_label is None
# Diamond
diamond = ase.build.bulk("C", crystalstructure="diamond", a=3.57)
backend = run_normalize_for_structure(diamond)
prototype_aflow_id = backend.get_value("prototype_aflow_id")
prototype_label = backend.get_value("prototype_label")
prototype_aflow_id, prototype_label = get_proto(diamond)
assert prototype_aflow_id == "A_cF8_227_a"
assert prototype_label == "227-C-cF8"
# BCC
bcc = ase.build.bulk("Fe", crystalstructure="bcc", a=2.856)
backend = run_normalize_for_structure(bcc)
prototype_aflow_id = backend.get_value("prototype_aflow_id")
prototype_label = backend.get_value("prototype_label")
prototype_aflow_id, prototype_label = get_proto(bcc)
assert prototype_aflow_id == "A_cI2_229_a"
assert prototype_label == "229-W-cI2"
# FCC
fcc = ase.build.bulk("Ge", crystalstructure="fcc", a=5.658)
backend = run_normalize_for_structure(fcc)
prototype_aflow_id = backend.get_value("prototype_aflow_id")
prototype_label = backend.get_value("prototype_label")
prototype_aflow_id, prototype_label = get_proto(fcc)
assert prototype_aflow_id == "A_cF4_225_a"
assert prototype_label == "225-Cu-cF4"
# Rocksalt
rocksalt = ase.build.bulk("NaCl", crystalstructure="rocksalt", a=5.64)
backend = run_normalize_for_structure(rocksalt)
prototype_aflow_id = backend.get_value("prototype_aflow_id")
prototype_label = backend.get_value("prototype_label")
prototype_aflow_id, prototype_label = get_proto(rocksalt)
assert prototype_aflow_id == "AB_cF8_225_a_b"
assert prototype_label == "225-ClNa-cF8"
# Zincblende
zincblende = ase.build.bulk("ZnS", crystalstructure="zincblende", a=5.42, cubic=True)
backend = run_normalize_for_structure(zincblende)
prototype_aflow_id = backend.get_value("prototype_aflow_id")
prototype_label = backend.get_value("prototype_label")
prototype_aflow_id, prototype_label = get_proto(zincblende)
assert prototype_aflow_id == "AB_cF8_216_c_a"
assert prototype_label == "216-SZn-cF8"
# Wurtzite
wurtzite = ase.build.bulk("SiC", crystalstructure="wurtzite", a=3.086, c=10.053)
backend = run_normalize_for_structure(wurtzite)
prototype_aflow_id = backend.get_value("prototype_aflow_id")
prototype_label = backend.get_value("prototype_label")
prototype_aflow_id, prototype_label = get_proto(wurtzite)
assert prototype_aflow_id == "AB_hP4_186_b_b"
assert prototype_label == "186-SZn-hP4"
......
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