Skip to content

Commit

Permalink
Fix symbol matching pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
bastonero committed May 7, 2024
1 parent c65bc6d commit 996ce64
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
23 changes: 18 additions & 5 deletions src/aiida_quantumespresso_hp/workflows/hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 8 additions & 6 deletions tests/workflows/test_hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 996ce64

Please sign in to comment.