From 2fe8e72c1423d33a2e8f4d87d3f30d2ccb3fe7d8 Mon Sep 17 00:00:00 2001 From: bastonero Date: Tue, 23 Apr 2024 16:30:05 +0000 Subject: [PATCH] Fix the convergence check in self-consistent workflow The convergence check on parameters had a bug in the logic. That logic would work for 1 Hubbard atom only, and that's the reason why this passed unseen in the tests. The fix is rather simple, and the new tests are tested again a case which made the old tests to make. --- src/aiida_quantumespresso_hp/workflows/hubbard.py | 4 ++-- tests/conftest.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/aiida_quantumespresso_hp/workflows/hubbard.py b/src/aiida_quantumespresso_hp/workflows/hubbard.py index d517163..8e346e6 100644 --- a/src/aiida_quantumespresso_hp/workflows/hubbard.py +++ b/src/aiida_quantumespresso_hp/workflows/hubbard.py @@ -634,7 +634,7 @@ def check_convergence(self): new = np.array(new_onsites, dtype='object') diff = np.abs(old[:, 4] - new[:, 4]) - if (diff > self.inputs.tolerance_onsite).all(): + if (diff > self.inputs.tolerance_onsite).any(): check_onsites = False self.report(f'Hubbard onsites parameters are not converged. Max difference is {diff.max()}.') @@ -644,7 +644,7 @@ def check_convergence(self): new = np.array(new_intersites, dtype='object') diff = np.abs(old[:, 4] - new[:, 4]) - if (diff > self.inputs.tolerance_intersite).all(): + if (diff > self.inputs.tolerance_intersite).any(): check_onsites = False self.report(f'Hubbard intersites parameters are not converged. Max difference is {diff.max()}.') diff --git a/tests/conftest.py b/tests/conftest.py index 84a2943..187de05 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -377,7 +377,7 @@ def _generate_structure(structure_id=None): def generate_hubbard_structure(generate_structure): """Return a `HubbardStructureData` representing bulk silicon.""" - def _generate_hubbard_structure(only_u=False, u_value=1e-5, v_value=1e-5): + def _generate_hubbard_structure(only_u=False, u_value=1e-5, v_value=1e-5, u_o_value=1e-5): """Return a `StructureData` representing bulk silicon.""" from aiida_quantumespresso.data.hubbard_structure import HubbardStructureData @@ -386,9 +386,12 @@ def _generate_hubbard_structure(only_u=False, u_value=1e-5, v_value=1e-5): if only_u: hubbard_structure.initialize_onsites_hubbard('Co', '3d', u_value) + hubbard_structure.initialize_onsites_hubbard('O', '2p', u_o_value) else: hubbard_structure.initialize_onsites_hubbard('Co', '3d', u_value) + hubbard_structure.initialize_onsites_hubbard('O', '2p', u_o_value) hubbard_structure.initialize_intersites_hubbard('Co', '3d', 'O', '2p', v_value) + hubbard_structure.initialize_intersites_hubbard('O', '2p', 'Co', '3d', u_o_value) return hubbard_structure