From 2c512766dee2858091683288167a21fa75e7738b Mon Sep 17 00:00:00 2001 From: bastonero Date: Fri, 19 Apr 2024 11:20:05 +0000 Subject: [PATCH] Add exit code for relabelling failure Fixes #66 The relabel function might not work if the spin configuration changes and the kinds cannot be determined uniquely by the parsed configuration from the hp.x post-processing. For this reason, we catch the error and exit smoothly with a new exit code if this would happen. --- .../functions/structure_relabel_kinds.py | 5 ++++- src/aiida_quantumespresso_hp/workflows/hubbard.py | 13 ++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/aiida_quantumespresso_hp/calculations/functions/structure_relabel_kinds.py b/src/aiida_quantumespresso_hp/calculations/functions/structure_relabel_kinds.py index 0c547e6..d175d5e 100644 --- a/src/aiida_quantumespresso_hp/calculations/functions/structure_relabel_kinds.py +++ b/src/aiida_quantumespresso_hp/calculations/functions/structure_relabel_kinds.py @@ -64,7 +64,10 @@ def structure_relabel_kinds( new_magnetization[kind_name] = old_magnetization[site['kind']] site = sites[index] - relabeled.append_atom(position=site.position, symbols=symbol, name=kind_name) + try: + relabeled.append_atom(position=site.position, symbols=symbol, name=kind_name) + except ValueError as exc: + raise ValueError('cannot distinguish kinds with the given Hubbard input configuration') from exc # Now add the non-Hubbard sites for site in sites[len(relabeled.sites):]: diff --git a/src/aiida_quantumespresso_hp/workflows/hubbard.py b/src/aiida_quantumespresso_hp/workflows/hubbard.py index d517163..d7c13f4 100644 --- a/src/aiida_quantumespresso_hp/workflows/hubbard.py +++ b/src/aiida_quantumespresso_hp/workflows/hubbard.py @@ -171,6 +171,9 @@ def define(cls, spec): spec.exit_code(330, 'ERROR_FAILED_TO_DETERMINE_PSEUDO_POTENTIAL', message='Failed to determine the correct pseudo potential after the structure changed its kind names.') + spec.exit_code(340, 'ERROR_RELABELLING_KINDS', + message='Failed to determine the kind names during the relabelling.') + spec.exit_code(401, 'ERROR_SUB_PROCESS_FAILED_RECON', message='The reconnaissance PwBaseWorkChain sub process failed') spec.exit_code(402, 'ERROR_SUB_PROCESS_FAILED_RELAX', @@ -428,9 +431,13 @@ def relabel_hubbard_structure(self, workchain) -> None: if not is_intersite_hubbard(workchain.outputs.hubbard_structure.hubbard): for site in workchain.outputs.hubbard.dict.sites: if not site['type'] == site['new_type']: - result = structure_relabel_kinds( - self.ctx.current_hubbard_structure, workchain.outputs.hubbard, self.ctx.current_magnetic_moments - ) + try: + result = structure_relabel_kinds( + self.ctx.current_hubbard_structure, workchain.outputs.hubbard, + self.ctx.current_magnetic_moments + ) + except ValueError: + return self.exit_codes.ERROR_RELABELLING_KINDS self.ctx.current_hubbard_structure = result['hubbard_structure'] if self.ctx.current_magnetic_moments is not None: self.ctx.current_magnetic_moments = result['starting_magnetization']