Skip to content

Commit

Permalink
Fix the convergence check in self-consistent workflow
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bastonero committed Apr 22, 2024
1 parent 4c8036e commit 3671a3c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/aiida_quantumespresso_hp/workflows/hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}.')

Expand All @@ -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()}.')

Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -386,8 +386,10 @@ 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)

return hubbard_structure
Expand Down

0 comments on commit 3671a3c

Please sign in to comment.