Skip to content

Electron MaxStep Widget #800

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

Merged
merged 5 commits into from
Sep 24, 2024
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
35 changes: 35 additions & 0 deletions src/aiidalab_qe/app/configuration/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ def __init__(self, default_protocol=None, **kwargs):
(self.etot_conv_thr, "disabled"),
lambda override: not override,
)

# Max electron SCF steps widget
self._create_electron_maxstep_widgets()

# Spin-Orbit calculation
self.spin_orbit = ipw.ToggleButtons(
options=[
Expand Down Expand Up @@ -260,6 +264,8 @@ def __init__(self, default_protocol=None, **kwargs):
[self.forc_conv_thr, self.etot_conv_thr, self.scf_conv_thr],
layout=ipw.Layout(height="50px", justify_content="flex-start"),
),
# Max electron SCF steps widget
self.electron_maxstep,
# smearing setting widget
self.smearing,
# Kpoints setting widget
Expand All @@ -279,6 +285,22 @@ def __init__(self, default_protocol=None, **kwargs):
# Default settings to trigger the callback
self.reset()

def _create_electron_maxstep_widgets(self):
self.electron_maxstep = ipw.BoundedIntText(
min=20,
max=1000,
step=1,
value=80,
description="Max. electron steps:",
style={"description_width": "initial"},
)
ipw.dlink(
(self.override, "value"),
(self.electron_maxstep, "disabled"),
lambda override: not override,
)
self.electron_maxstep.observe(self._callback_value_set, "value")

def set_value_and_step(self, attribute, value):
"""
Sets the value and adjusts the step based on the order of magnitude of the value.
Expand Down Expand Up @@ -459,6 +481,11 @@ def get_panel_value(self):
self.etot_conv_thr.value
)

# Max electron SCF steps
parameters["pw"]["parameters"]["ELECTRONS"]["electron_maxstep"] = (
self.electron_maxstep.value
)

# Spin-Orbit calculation
if self.spin_orbit.value == "soc":
parameters["pw"]["parameters"]["SYSTEM"]["lspinorb"] = True
Expand Down Expand Up @@ -542,6 +569,14 @@ def set_panel_value(self, parameters):
.get("conv_thr", 0.0)
)

# Max electron SCF steps
self.electron_maxstep.value = (
parameters.get("pw", {})
.get("parameters", {})
.get("ELECTRONS", {})
.get("electron_maxstep", 80)
)

# Logic to set the magnetization
if parameters.get("initial_magnetic_moments"):
self.magnetization._set_magnetization_values(
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def _submit_app_generator(
tot_charge=0.0,
vdw_corr="none",
initial_magnetic_moments=0.0,
electron_maxstep=80,
):
configure_step = app.configure_step
# Settings
Expand All @@ -379,6 +380,7 @@ def _submit_app_generator(
configure_step.advanced_settings.magnetization._set_magnetization_values(
initial_magnetic_moments
)
configure_step.advanced_settings.electron_maxstep.value = electron_maxstep
# mimic the behavior of the smearing widget set up
configure_step.advanced_settings.smearing.smearing.value = smearing
configure_step.advanced_settings.smearing.degauss.value = degauss
Expand Down
5 changes: 5 additions & 0 deletions tests/test_submit_qe_workchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def test_create_builder_advanced_settings(
-collinear
-tot_charge
-initial_magnetic_moments
-vdw_corr
-electron_maxstep
-properties: bands, pdos
"""

app = submit_app_generator(
Expand All @@ -66,6 +69,7 @@ def test_create_builder_advanced_settings(
tot_charge=1.0,
vdw_corr="dft-d3bj",
initial_magnetic_moments=0.1,
electron_maxstep=100,
properties=["bands", "pdos"],
)
submit_step = app.submit_step
Expand All @@ -85,6 +89,7 @@ def test_create_builder_advanced_settings(
assert parameters["pw"]["parameters"]["SYSTEM"]["tot_charge"] == 1.0
assert parameters["pw"]["parameters"]["SYSTEM"]["vdw_corr"] == "dft-d3"
assert parameters["pw"]["parameters"]["SYSTEM"]["dftd3_version"] == 4
assert parameters["pw"]["parameters"]["ELECTRONS"]["electron_maxstep"] == 100

# test initial_magnetic_moments set 'starting_magnetization' in pw.in
assert (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ advanced:
forc_conv_thr: 0.0001
ELECTRONS:
conv_thr: 4.0e-10
electron_maxstep: 80
SYSTEM:
degauss: 0.015
ecutrho: 240.0
Expand Down
Loading