Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflows: change logic for relabeling +V case #42

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/aiida_quantumespresso_hp/workflows/hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@ def inspect_hp(self):

def check_convergence(self):
"""Check the convergence of the Hubbard parameters."""
from aiida_quantumespresso.utils.hubbard import is_intersite_hubbard

workchain = self.ctx.workchains_hp[-1]

# We store in memory the parameters before relabelling to make the comparison easier.
Expand All @@ -624,16 +626,17 @@ def check_convergence(self):
# We check if new types were created, in which case we relabel the `HubbardStructureData`
self.ctx.current_hubbard_structure = workchain.outputs.hubbard_structure

for site in workchain.outputs.hubbard.dict.sites:
if not site['type'] == site['new_type']:
self.report('new types have been detected: relabeling the structure and starting new iteration.')
result = structure_relabel_kinds(
self.ctx.current_hubbard_structure, workchain.outputs.hubbard, self.ctx.current_magnetic_moments
)
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']
break
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']:
self.report('new types have been detected: relabeling the structure and starting new iteration.')
result = structure_relabel_kinds(
self.ctx.current_hubbard_structure, workchain.outputs.hubbard, self.ctx.current_magnetic_moments
)
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']
break

if not len(ref_params) == len(new_params):
self.report('The new and old Hubbard parameters have different lenghts. Assuming to be at the first cycle.')
Expand Down
23 changes: 14 additions & 9 deletions tests/workflows/test_hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,6 @@ def test_not_converged_check_convergence(

process.setup()

# Mocking current (i.e. "old") and "new" HubbardStructureData,
# containing different Hubbard parameters
process.ctx.current_hubbard_structure = generate_hubbard_structure()
process.ctx.workchains_hp = [generate_hp_workchain_node(u_value=5.0)]

Expand All @@ -354,19 +352,26 @@ def test_relabel_check_convergence(

process.setup()

# Mocking current (i.e. "old") and "new" HubbardStructureData,
# containing different Hubbard parameters
process.ctx.current_hubbard_structure = generate_hubbard_structure()
process.ctx.workchains_hp = [generate_hp_workchain_node(relabel=True, u_value=100)]

current_hubbard_structure = generate_hubbard_structure(u_value=1, only_u=True)
process.ctx.current_hubbard_structure = current_hubbard_structure
process.ctx.workchains_hp = [generate_hp_workchain_node(relabel=True, u_value=100, only_u=True)]
process.check_convergence()
assert not process.ctx.is_converged
assert process.ctx.current_hubbard_structure.get_kind_names() != current_hubbard_structure.get_kind_names()

process.ctx.current_hubbard_structure = generate_hubbard_structure(u_value=99.99)
process.ctx.workchains_hp = [generate_hp_workchain_node(relabel=True, u_value=100)]
current_hubbard_structure = generate_hubbard_structure(u_value=99.99, only_u=True)
process.ctx.current_hubbard_structure = current_hubbard_structure
process.ctx.workchains_hp = [generate_hp_workchain_node(relabel=True, u_value=100, only_u=True)]
process.check_convergence()
assert process.ctx.is_converged
assert process.ctx.current_hubbard_structure.get_kind_names() != current_hubbard_structure.get_kind_names()

current_hubbard_structure = generate_hubbard_structure(u_value=99.99)
process.ctx.current_hubbard_structure = current_hubbard_structure
process.ctx.workchains_hp = [generate_hp_workchain_node(relabel=True, u_value=100)]
process.check_convergence()
assert process.ctx.is_converged
assert process.ctx.current_hubbard_structure.get_kind_names() == current_hubbard_structure.get_kind_names()


@pytest.mark.usefixtures('aiida_profile')
Expand Down
Loading