From 59732401c8a7effc47089f144b453ebfe63c61a2 Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Thu, 7 Nov 2024 11:23:02 +0100 Subject: [PATCH] Add numerical values to test --- tests/conftest.py | 6 ++++++ tests/test_workflows.py | 24 ++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 1a06590..ae526cf 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -48,6 +48,12 @@ def _generate_structure(structure_id='silicon'): structure = StructureData(cell=cell) structure.append_atom(position=(0., 0., 0.), symbols='Si', name='Si') structure.append_atom(position=(param / 4., param / 4., param / 4.), symbols='Si', name='Si') + elif structure_id == 'silicon_perturbed': + param = 5.43 + cell = [[param / 2., param / 2., 0], [param / 2., 0, param / 2.], [0, param / 2., param / 2.]] + structure = StructureData(cell=cell) + structure.append_atom(position=(0.05, 0., 0.), symbols='Si', name='Si') + structure.append_atom(position=(param / 4., param / 4., param / 4.), symbols='Si', name='Si') elif structure_id == 'water': structure = StructureData(cell=[[5.29177209, 0., 0.], [0., 5.29177209, 0.], [0., 0., 5.29177209]]) structure.append_atom(position=[12.73464656, 16.7741411, 24.35076238], symbols='H', name='H') diff --git a/tests/test_workflows.py b/tests/test_workflows.py index 17e40bd..9ee6c0c 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -4,10 +4,11 @@ def test_silicon_workflow(get_dftk_code, generate_structure, generate_kpoints_me """ from aiida import orm from aiida_dftk.workflows.base import DftkBaseWorkChain + from numpy.testing import assert_allclose builder = DftkBaseWorkChain.get_builder() builder.dftk.code = get_dftk_code() - builder.dftk.structure = generate_structure("silicon") + builder.dftk.structure = generate_structure("silicon_perturbed") builder.kpoints = generate_kpoints_mesh(3) builder.dftk.pseudos.Si = load_psp("Si") @@ -47,6 +48,21 @@ def test_silicon_workflow(get_dftk_code, generate_structure, generate_kpoints_me result = submit_and_await_success(builder, timeout=300) - assert result.outputs.output_parameters.get_dict()["converged"] - assert result.outputs.output_forces.get_array().shape == (2, 3) - assert result.outputs.output_stresses.get_array().shape == (3, 3) \ No newline at end of file + output_parameters = result.outputs.output_parameters.get_dict() + assert output_parameters["converged"] + + # Compare against values from running the test in the past, just to make sure they don't change unexpectedly. + _REFERENCE_ENERGY = -8.4379856175524 + _REFERENCE_FORCES = [ + [-1.44715423e-02, -4.32340280e-13, -4.32937222e-13], + [ 1.44678314e-02, 2.36668451e-13, 2.35940027e-13], + ] + _REFERENCE_STRESSES = [ + [-1.23236770e-04, 0.00000000e+00, 0.00000000e+00], + [ 0.00000000e+00, -1.28905279e-04, -6.65119701e-05], + [ 0.00000000e+00, -6.65119701e-05, -1.28905279e-04], + ] + + assert_allclose(output_parameters["energies"]["total"], _REFERENCE_ENERGY, rtol=1e-2) + assert_allclose(result.outputs.output_forces.get_array(), _REFERENCE_FORCES, rtol=1e-2) + assert_allclose(result.outputs.output_stresses.get_array(), _REFERENCE_STRESSES, rtol=1e-2)