Skip to content

Commit

Permalink
Add numerical values to test
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n committed Nov 7, 2024
1 parent b647c33 commit 5973240
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
24 changes: 20 additions & 4 deletions tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
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)

0 comments on commit 5973240

Please sign in to comment.