Commit 68e471c5 authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Simplified tests, modified scope of normalizer fixtures.

parent d856da22
Pipeline #67295 failed with stages
in 14 minutes and 9 seconds
......@@ -16,7 +16,6 @@ import pytest
from nomad.parsing import LocalBackend
from nomad.normalizing import normalizers
from nomad.metainfo.encyclopedia import Encyclopedia
from tests.test_parsing import parsed_vasp_example # pylint: disable=unused-import
from tests.test_parsing import parsed_template_example # pylint: disable=unused-import
......@@ -50,41 +49,46 @@ def normalized_template_example(parsed_template_example) -> LocalBackend:
return run_normalize(parsed_template_example)
@pytest.fixture
def geometry_optimization() -> Encyclopedia:
@pytest.fixture(scope='session')
def geometry_optimization() -> LocalBackend:
parser_name = "parsers/template"
filepath = "tests/data/normalizers/fcc_crystal_structure.json"
backend = parse_file((parser_name, filepath))
backend = run_normalize(backend)
enc = backend.get_mi2_section(Encyclopedia.m_def)
return enc
return backend
@pytest.fixture
def molecular_dynamics() -> Encyclopedia:
@pytest.fixture(scope='session')
def molecular_dynamics() -> LocalBackend:
parser_name = "parsers/cp2k"
filepath = "tests/data/normalizers/encyclopedia/cp2k_bulk_md/si_md.out"
backend = parse_file((parser_name, filepath))
backend = run_normalize(backend)
enc = backend.get_mi2_section(Encyclopedia.m_def)
return enc
return backend
@pytest.fixture
def phonon() -> Encyclopedia:
@pytest.fixture(scope='session')
def phonon() -> LocalBackend:
parser_name = "parsers/phonopy"
filepath = "tests/data/parsers/phonopy/phonopy-FHI-aims-displacement-01/control.in"
backend = parse_file((parser_name, filepath))
backend = run_normalize(backend)
enc = backend.get_mi2_section(Encyclopedia.m_def)
return enc
return backend
@pytest.fixture
def twod() -> Encyclopedia:
@pytest.fixture(scope='session')
def bulk() -> LocalBackend:
parser_name = "parsers/template"
filepath = "tests/data/normalizers/fcc_crystal_structure.json"
backend = parse_file((parser_name, filepath))
backend = run_normalize(backend)
return backend
@pytest.fixture(scope='session')
def two_d() -> LocalBackend:
parser_name = "parsers/fhi-aims"
filepath = "tests/data/normalizers/encyclopedia/fhiaims_2d_singlepoint/aims.out"
backend = parse_file((parser_name, filepath))
backend = run_normalize(backend)
enc = backend.get_mi2_section(Encyclopedia.m_def)
return enc
return backend
......@@ -15,69 +15,73 @@
import pytest
import numpy as np
from nomad.parsing import LocalBackend
from nomad.metainfo.encyclopedia import Encyclopedia
from tests.normalizing.conftest import geometry_optimization, molecular_dynamics, phonon, twod # pylint: disable=unused-import
from tests.normalizing.conftest import geometry_optimization, molecular_dynamics, phonon, two_d, bulk # pylint: disable=unused-import
# def test_geometry_optimization(geometry_optimization: Encyclopedia):
# """Tests that geometry optimizations are correctly processed."
# """
# run_type = geometry_optimization.calculation.run_type
# assert run_type == "geometry optimization"
def test_geometry_optimization(geometry_optimization: LocalBackend):
"""Tests that geometry optimizations are correctly processed."
"""
enc = geometry_optimization.get_mi2_section(Encyclopedia.m_def)
run_type = enc.calculation.run_type
assert run_type == "geometry optimization"
# def test_molecular_dynamics(molecular_dynamics: Encyclopedia):
# """Tests that geometry optimizations are correctly processed."
# """
# run_type = molecular_dynamics.calculation.run_type
# assert run_type == "molecular dynamics"
def test_molecular_dynamics(molecular_dynamics: LocalBackend):
"""Tests that geometry optimizations are correctly processed."
"""
enc = molecular_dynamics.get_mi2_section(Encyclopedia.m_def)
run_type = enc.calculation.run_type
assert run_type == "molecular dynamics"
# def test_phonon(phonon: Encyclopedia):
# """Tests that geometry optimizations are correctly processed."
# """
# run_type = phonon.calculation.run_type
# assert run_type == "phonon calculation"
def test_phonon(phonon: LocalBackend):
"""Tests that geometry optimizations are correctly processed."
"""
enc = phonon.get_mi2_section(Encyclopedia.m_def)
run_type = enc.calculation.run_type
assert run_type == "phonon calculation"
# def test_system_type(geometry_optimization: Encyclopedia):
# """Tests that geometry optimizations are correctly processed."
# """
# system_type = geometry_optimization.material.system_type
# assert system_type == "bulk"
def test_system_type(geometry_optimization: LocalBackend):
"""Tests that geometry optimizations are correctly processed.
"""
enc = geometry_optimization.get_mi2_section(Encyclopedia.m_def)
system_type = enc.material.system_type
assert system_type == "bulk"
# def test_bulk_information(geometry_optimization: Encyclopedia):
# """Tests that information for bulk systems is correctly processed."
# """
# enc = geometry_optimization
# assert enc.material.system_type == "bulk"
# assert enc.material.number_of_atoms == 4
# assert enc.material.atom_labels == ["Na", "Na", "Na", "Na"]
# assert enc.material.atom_positions is not None
# assert enc.material.crystal_system == "cubic"
# assert enc.material.bravais_lattice == "cF"
# assert enc.material.formula == "Na"
# assert enc.material.formula_reduced == "Na"
# assert enc.material.has_free_wyckoff_parameters is False
# assert enc.material.material_name == "Sodium"
# assert enc.material.point_group == "m-3m"
# assert enc.material.cell_normalized is not None
# assert enc.material.cell_primitive is not None
# assert np.array_equal(enc.material.periodicity, [0, 1, 2])
# assert enc.material.wyckoff_groups is not None
def test_bulk_metainfo(bulk: LocalBackend):
"""Tests that information for bulk systems is correctly processed.
"""
enc = bulk.get_mi2_section(Encyclopedia.m_def)
assert enc.material.system_type == "bulk"
assert enc.material.number_of_atoms == 4
assert enc.material.atom_labels == ["Na", "Na", "Na", "Na"]
assert enc.material.atom_positions is not None
assert enc.material.crystal_system == "cubic"
assert enc.material.bravais_lattice == "cF"
assert enc.material.formula == "Na"
assert enc.material.formula_reduced == "Na"
assert enc.material.has_free_wyckoff_parameters is False
assert enc.material.material_name == "Sodium"
assert enc.material.point_group == "m-3m"
assert enc.material.cell_normalized is not None
assert enc.material.cell_primitive is not None
assert np.array_equal(enc.material.periodicity, [0, 1, 2])
assert enc.material.wyckoff_groups is not None
# assert enc.calculation.atomic_density == pytest.approx(4.0e+30, rel=0.000001, abs=None)
# assert enc.calculation.lattice_parameters is not None
# assert enc.calculation.cell_angles_string is not None
# assert enc.calculation.mass_density == 4 * 22.98976928 * 1.6605389e-27 / 1e-30 # Atomic mass in kg / cell volume
# assert enc.calculation.cell_volume == 1e-30
assert enc.calculation.atomic_density == pytest.approx(4.0e+30, rel=0.000001, abs=None)
assert enc.calculation.lattice_parameters is not None
assert enc.calculation.mass_density == 4 * 22.98976928 * 1.6605389e-27 / 1e-30 # Atomic mass in kg / cell volume
assert enc.calculation.cell_volume == 1e-30
def test_2d_information(twod: Encyclopedia):
"""Tests that information for 2D systems is correctly processed."
def test_2d_metainfo(two_d: LocalBackend):
"""Tests that information for 2D systems is correctly processed.
"""
enc = twod
enc = two_d.get_mi2_section(Encyclopedia.m_def)
assert enc.material.system_type == "2D"
assert enc.material.number_of_atoms == 2
assert enc.material.atom_labels == ["C", "C"]
......@@ -88,4 +92,3 @@ def test_2d_information(twod: Encyclopedia):
assert enc.material.formula_reduced == "C"
assert np.allclose(enc.calculation.lattice_parameters, [2.46559821e-10, 2.46559821e-10, 0, 120 / 180 * np.pi, 0, 0])
assert np.array_equal(enc.material.periodicity, [0, 1])
# assert go.calculation.cell_angles_string is not None
......@@ -16,7 +16,7 @@ from nomad import datamodel, config
from nomad.parsing import LocalBackend
from tests.test_parsing import parse_file
from tests.normalizing.conftest import run_normalize
from tests.normalizing.conftest import run_normalize, two_d # pylint: disable=unused-import
from tests.utils import assert_log
......@@ -32,6 +32,9 @@ unknown_atom_label = (
fcc_symmetry = (
'parsers/template', 'tests/data/normalizers/fcc_crystal_structure.json')
two_d = (
'parsers/template', 'tests/data/normalizers/fcc_crystal_structure.json')
vasp_parser = (
'parsers/vasp', 'tests/data/parsers/vasp/vasp.xml')
......@@ -91,7 +94,7 @@ def test_normalizer(normalized_example: LocalBackend):
def test_normalizer_faulty_matid(caplog):
""" Runs normalizer on an example w/ bools for atom pos. Should force matid error."""
"""Runs normalizer on an example w/ bools for atom pos. Should force matid error."""
# assert isinstance(backend, LocalBackend)
backend = parse_file(boolean_positions)
run_normalize(backend)
......@@ -110,8 +113,8 @@ def test_normalizer_single_string_atom_labels(caplog):
def test_normalizer_unknown_atom_label(caplog, no_warn):
""" Runs normalizer on ['Br','Si','Si','Za'], for normalizeation Za will be replaced,
but stays int the labels.
"""Runs normalizer on ['Br','Si','Si','Za'], for normalization Za will be
replaced, but stays int the labels.
"""
backend = parse_file(unknown_atom_label)
run_normalize(backend)
......@@ -136,15 +139,14 @@ def test_symmetry_classification_fcc():
assert all(origin_shift == expected_origin_shift)
def test_system_classification():
def test_system_classification(bulk, two_d):
"""Tests that the system classification is correct for different kind of systems
"""
# Bulk system
backend = parse_file(fcc_symmetry)
backend = run_normalize(backend)
expected_system_type = 'bulk'
system_type = backend.get_value('system_type')
assert expected_system_type == system_type
assert bulk.get_value('system_type') == "bulk"
# 2D system
assert two_d.get_value('system_type') == "2D"
def test_reduced_chemical_formula():
......
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