Commit fc46fa6e authored by Daniel Speckhard's avatar Daniel Speckhard
Browse files

Added system normalizer tests.

parent 1475f770
Pipeline #47599 failed with stages
in 19 minutes and 17 seconds
{
"section_run": [
{
"_name": "section_run",
"_gIndex": 0,
"program_name": "VASP",
"program_version": "4.6.35 3Apr08 complex parallel LinuxIFC",
"program_basis_set_type": "plane waves",
"section_method": [
{
"_name": "section_method",
"_gIndex": 0,
"electronic_structure_method": "DFT",
"section_XC_functionals": [
{
"_name": "section_XC_functionals",
"_gIndex": 0,
"XC_functional_name": "GGA_X_PBE"
}
]
}
],
"section_system": [
{
"_name": "section_system",
"_gIndex": 0,
"configuration_periodic_dimensions": [
true,
true,
true
],
"atom_positions": [
[
0,
0,
0
]],
"atom_labels": [
"Na"
],
"lattice_vectors": [
[0, 0.5, 0.5],[0.5, 0 , 0.5],[0.5, 0.5, 0]]
}
],
"section_single_configuration_calculation": [
{
"_name": "section_single_configuration_calculation",
"_gIndex": 0,
"single_configuration_calculation_to_system_ref": 0,
"single_configuration_to_calculation_method_ref": 0,
"energy_free": -1.5936767191492225e-18,
"energy_total": -1.5935696296699573e-18,
"energy_total_T0": -3.2126683561907e-22
}
],
"section_sampling_method": [
{
"_name": "section_sampling_method",
"_gIndex": 0,
"sampling_method": "geometry_optimization"
}
],
"section_frame_sequence": [
{
"_name": "section_frame_sequence",
"_gIndex": 0,
"frame_sequence_to_sampling_ref": 0,
"frame_sequence_local_frames_ref": [
0
]
}
]
}
]
}
\ No newline at end of file
{
"section_run": [
{
"_name": "section_run",
"_gIndex": 0,
"program_name": "VASP",
"program_version": "4.6.35 3Apr08 complex parallel LinuxIFC",
"program_basis_set_type": "plane waves",
"section_method": [
{
"_name": "section_method",
"_gIndex": 0,
"electronic_structure_method": "DFT",
"section_XC_functionals": [
{
"_name": "section_XC_functionals",
"_gIndex": 0,
"XC_functional_name": "GGA_X_PBE"
}
]
}
],
"section_system": [
{
"_name": "section_system",
"_gIndex": 0,
"configuration_periodic_dimensions": [
true,
true,
true
],
"atom_positions": [
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
]
],
"atom_labels": [
"C", "O", "H", "H", "C", "O", "H", "H",
"C", "O", "H", "H", "C", "O", "H", "H",
"C", "O", "H", "H", "C", "O", "H", "H"
]
}
],
"section_single_configuration_calculation": [
{
"_name": "section_single_configuration_calculation",
"_gIndex": 0,
"single_configuration_calculation_to_system_ref": 0,
"single_configuration_to_calculation_method_ref": 0,
"energy_free": -1.5936767191492225e-18,
"energy_total": -1.5935696296699573e-18,
"energy_total_T0": -3.2126683561907e-22
}
],
"section_sampling_method": [
{
"_name": "section_sampling_method",
"_gIndex": 0,
"sampling_method": "geometry_optimization"
}
],
"section_frame_sequence": [
{
"_name": "section_frame_sequence",
"_gIndex": 0,
"frame_sequence_to_sampling_ref": 0,
"frame_sequence_local_frames_ref": [
0
]
}
]
}
]
}
\ No newline at end of file
......@@ -21,12 +21,25 @@ 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
from tests.test_parsing import parsed_example # pylint: disable=unused-import
from tests.test_parsing import parsed_faulty_unknown_matid_example # pylint: disable=unused-import
from tests.test_parsing import parsed_single_string_atom_labels_test # pylint: disable=unused-import
from tests.test_parsing import parsed_unknown_atom_label_test # pylint: disable=unused-import
from tests.test_parsing import parse_file
from tests.utils import assert_log
boolean_positions = (
'parsers/template', 'tests/data/normalizers/no_sim_cell_boolean_positions.json')
single_string_atom_labels = (
'parsers/template', 'tests/data/normalizers/single_string_atom_labels.json')
unknown_atom_label = (
'parsers/template', 'tests/data/normalizers/unknown_atom_label_test.json')
fcc_symmetry = (
'parsers/template', 'tests/data/normalizers/fcc_crystal_structure.json')
glucose_atom_labels = (
'parsers/template', 'tests/data/normalizers/glucose_atom_labels.json')
symmetry_keys = ['spacegroup', 'spacegroup_symbol', 'crystal_system']
calc_metadata_keys = [
'code_name', 'code_version', 'basis_set', 'xc_functional', 'system', 'formula'] + symmetry_keys
......@@ -108,24 +121,63 @@ def test_normalizer(normalized_example: LocalBackend):
assert_normalized(normalized_example)
def test_normalizer_faulty_matid(
parsed_faulty_unknown_matid_example: LocalBackend, caplog):
def test_normalizer_faulty_matid(caplog):
""" Runs normalizer on an example w/ bools for atom pos. Should force matid error."""
run_normalize(parsed_faulty_unknown_matid_example)
# assert isinstance(backend, LocalBackend)
backend = parse_file(boolean_positions)
run_normalize(backend)
assert_log(caplog, 'ERROR', 'matid project system classification failed')
assert_log(caplog, 'ERROR', 'no lattice vectors but periodicity')
def test_normalizer_single_string_atom_labels(
parsed_single_string_atom_labels_test: LocalBackend, caplog):
def test_normalizer_single_string_atom_labels(caplog):
""" Runs normalizer on ['Br1SiSiK'] expects error that it is formatted wrong."""
run_normalize(parsed_single_string_atom_labels_test)
backend = parse_file(single_string_atom_labels)
run_normalize(backend)
assert_log(caplog, 'ERROR', 'Atom labels cannot be recognized.')
def test_normalizer_unknown_atom_label(
parsed_unknown_atom_label_test: LocalBackend, caplog):
def test_normalizer_unknown_atom_label(caplog):
""" Runs normalizer on ['Br','Si','Si','Za'], expects Za throws an error"""
run_normalize(parsed_unknown_atom_label_test)
backend = parse_file(unknown_atom_label)
run_normalize(backend)
assert_log(caplog, 'ERROR', 'Atom labels cannot be recognized.')
def test_symmetry_classification_fcc():
"""Runs normalizer where lattice vectors should give fcc symmetry."""
backend = parse_file(fcc_symmetry)
backend = run_normalize(backend)
expected_crystal_system = 'cubic'
expected_bravais_lattice = 'cF'
expected_point_group = 'm-3m'
expected_origin_shift = [0, 0, 0]
cyrstal_system = backend.get_value('crystal_system')
assert cyrstal_system == expected_crystal_system
bravais_lattice = backend.get_value('bravais_lattice')
assert bravais_lattice == expected_bravais_lattice
point_group = backend.get_value('point_group')
assert point_group == expected_point_group
origin_shift = backend.get_value('origin_shift')
assert all(origin_shift == expected_origin_shift)
def test_system_classification():
"Ensure the classification of fcc Na is atom"
# TODO: @dts - This is a bit strange that a system with only
# one atom is automatically classified as atom. It could be
# an elemental solid.
backend = parse_file(fcc_symmetry)
backend = run_normalize(backend)
expected_system_type = 'atom'
system_type = backend.get_value('system_type')
assert expected_system_type == system_type
def test_reduced_chemical_formula():
"Ensure we get the right reduced chemical formula for glucose atom labels"
backend = parse_file(glucose_atom_labels)
backend = run_normalize(backend)
expected_red_chem_formula = 'C6H12O6'
reduced_chemical_formula = backend.get_value('chemical_composition_bulk_reduced')
assert expected_red_chem_formula == reduced_chemical_formula
......@@ -69,16 +69,6 @@ for parser, mainfile in parser_examples:
fixed_parser_examples.append((parser, mainfile))
parser_examples = fixed_parser_examples
faulty_unknown_one_d_matid_example = [
('parsers/template', 'tests/data/normalizers/no_sim_cell_boolean_positions.json')
]
single_string_atom_labels_test = [
('parsers/template', 'tests/data/normalizers/single_string_atom_labels.json')
]
unknown_atom_label_test = [
('parsers/template', 'tests/data/normalizers/unknown_atom_label_test.json')
]
correct_num_output_files = 34
......@@ -303,22 +293,9 @@ def parsed_template_example() -> LocalBackend:
'parsers/template', 'tests/data/parsers/template.json')
@pytest.fixture(
params=faulty_unknown_one_d_matid_example, ids=lambda spec: '%s-%s' % spec)
def parsed_faulty_unknown_matid_example(caplog, request) -> LocalBackend:
parser_name, mainfile = request.param
return run_parser(parser_name, mainfile)
@pytest.fixture(
params=single_string_atom_labels_test, ids=lambda spec: '%s-%s' % spec)
def parsed_single_string_atom_labels_test(caplog, request) -> LocalBackend:
parser_name, mainfile = request.param
return run_parser(parser_name, mainfile)
@pytest.fixture(
params=unknown_atom_label_test, ids=lambda spec: '%s-%s' % spec)
def parsed_unknown_atom_label_test(caplog, request) -> LocalBackend:
parser_name, mainfile = request.param
# Function used by normalizer tests.
def parse_file(parser_name_and_mainfile) -> LocalBackend:
parser_name, mainfile = parser_name_and_mainfile
return run_parser(parser_name, mainfile)
......
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