From 996ce6407e02e2c007ec287eebf33efd2a519e22 Mon Sep 17 00:00:00 2001 From: bastonero Date: Tue, 7 May 2024 13:52:06 +0000 Subject: [PATCH] Fix symbol matching pattern --- .../workflows/hubbard.py | 23 +++++++++++++++---- tests/workflows/test_hubbard.py | 14 ++++++----- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/aiida_quantumespresso_hp/workflows/hubbard.py b/src/aiida_quantumespresso_hp/workflows/hubbard.py index a42e449..10b3d2f 100644 --- a/src/aiida_quantumespresso_hp/workflows/hubbard.py +++ b/src/aiida_quantumespresso_hp/workflows/hubbard.py @@ -419,7 +419,7 @@ def get_pseudos(self) -> dict: for kind in self.ctx.current_hubbard_structure.kinds: for key, pseudo in pseudos.items(): symbol = re.sub(r'\d', '', key) - if re.match(fr'{kind.symbol}*.', symbol): + if re.match(fr'{kind.symbol}[0-9]*', symbol): results[kind.name] = pseudo break else: @@ -562,12 +562,25 @@ def recon_scf(self): bands = workchain.outputs.output_band parameters = workchain.outputs.output_parameters.get_dict() - # number_electrons = parameters['number_of_electrons'] - # is_insulator, _ = find_bandgap(bands, number_electrons=number_electrons) + fermi_energy = parameters['fermi_energy'] - is_insulator, _ = find_bandgap(bands, fermi_energy=fermi_energy) + number_electrons = parameters['number_of_electrons'] + + # Due to uncertainty in the prediction of the fermi energy, we try + # both options of this function. If one of the two give an insulating + # state as a result, we then set fixed occupation as it is likely that + # hp.x would crash otherwise. + is_insulator_1, _ = find_bandgap(bands, fermi_energy=fermi_energy) + + # I am not sure, but I think for some materials, e.g. having anti-ferromagnetic + # ordering, the following function would crash for some reason, possibly due + # to the format of the BandsData. To double check if actually needed. + try: + is_insulator_2, _ = find_bandgap(bands, number_electrons=number_electrons) + except: # pylint: disable=bare-except + is_insulator_2 = False - if is_insulator: + if is_insulator_1 or is_insulator_2: self.report('after relaxation, system is determined to be an insulator') self.ctx.is_insulator = True else: diff --git a/tests/workflows/test_hubbard.py b/tests/workflows/test_hubbard.py index fb66a5b..84c780e 100644 --- a/tests/workflows/test_hubbard.py +++ b/tests/workflows/test_hubbard.py @@ -36,10 +36,14 @@ def _generate_scf_workchain_node(exit_status=0, relax=False, remote_folder=False node.set_process_state(ProcessState.FINISHED) node.set_exit_status(exit_status) - parameters = Dict(dict={ - 'number_of_bands': 1, - 'total_magnetization': 1, - }).store() + parameters = Dict( + dict={ + 'number_of_bands': 1, + 'number_of_electrons': 1, + 'fermi_energy': 0, + 'total_magnetization': 1, + } + ).store() parameters.base.links.add_incoming(node, link_type=LinkType.RETURN, link_label='output_parameters') if relax: @@ -228,8 +232,6 @@ def test_skip_relax_iterations_relabeling( generate_workchain_hubbard, generate_inputs_hubbard, generate_hp_workchain_node, generate_hubbard_structure ): """Test `SelfConsistentHubbardWorkChain` when skipping the first relax iterations and relabeling is needed.""" - from aiida.orm import Bool, Int - inputs = generate_inputs_hubbard() inputs['skip_relax_iterations'] = Int(1) inputs['meta_convergence'] = Bool(True)