Skip to content

Commit

Permalink
Replace advanced settings override checkbox with a reset button (#1012)
Browse files Browse the repository at this point in the history
This PR discards the override mechanism in the advanced settings panel. All widgets are enabled and may be overridden by the user. A reset button is added in place of the override checkbox to reset the advanced settings to their defaults w.r.t the basic settings and selected structure.
  • Loading branch information
edan-bainglass authored Dec 26, 2024
1 parent 00d4a87 commit 5ce2532
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 250 deletions.
108 changes: 21 additions & 87 deletions src/aiidalab_qe/app/configuration/advanced/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ def __init__(self, model: AdvancedConfigurationSettingsModel, **kwargs):
self._on_protocol_change,
"protocol",
)
self._model.observe(
self._on_override_change,
"override",
)
self._model.observe(
self._on_kpoints_distance_change,
"kpoints_distance",
Expand Down Expand Up @@ -78,29 +74,21 @@ def render(self):

# clean-up workchain settings
self.clean_workdir = ipw.Checkbox(
description="",
description="Tick to delete the work directory after the calculation is finished",
indent=False,
layout=ipw.Layout(max_width="20px"),
layout=ipw.Layout(width="fit-content"),
)
ipw.link(
(self._model, "clean_workdir"),
(self.clean_workdir, "value"),
)
# Override setting widget
self.override = ipw.Checkbox(
description="",
indent=False,
layout=ipw.Layout(max_width="10%"),
)
ipw.link(
(self._model, "override"),
(self.override, "value"),
)
ipw.dlink(
(self._model, "input_structure"),
(self.override, "disabled"),
lambda structure: structure is None,
self.reset_to_defaults_button = ipw.Button(
description="Reset to defaults",
button_style="warning",
icon="undo",
layout=ipw.Layout(width="fit-content"),
)
self.reset_to_defaults_button.on_click(self._on_reset_to_defaults_button_click)

# Smearing setting widget
self.smearing.render()
Expand All @@ -116,15 +104,10 @@ def render(self):
(self._model, "kpoints_distance"),
(self.kpoints_distance, "value"),
)
ipw.dlink(
(self.override, "value"),
(self.kpoints_distance, "disabled"),
lambda override: not (override and self._model.has_pbc),
)
ipw.dlink(
(self._model, "input_structure"),
(self.kpoints_distance, "disabled"),
lambda _: not (self._model.override and self._model.has_pbc),
lambda _: not self._model.has_pbc,
)
self.mesh_grid = ipw.HTML()
ipw.dlink(
Expand All @@ -147,11 +130,6 @@ def render(self):
(self._model, "total_charge"),
(self.total_charge, "value"),
)
ipw.dlink(
(self._model, "override"),
(self.total_charge, "disabled"),
lambda override: not override,
)

# Van der Waals setting widget
self.van_der_waals = ipw.Dropdown(
Expand All @@ -166,11 +144,6 @@ def render(self):
(self._model, "van_der_waals"),
(self.van_der_waals, "value"),
)
ipw.dlink(
(self._model, "override"),
(self.van_der_waals, "disabled"),
lambda override: not override,
)

# Magnetization settings
self.magnetization.render()
Expand All @@ -190,11 +163,6 @@ def render(self):
(self._model, "scf_conv_thr_step"),
(self.scf_conv_thr, "step"),
)
ipw.dlink(
(self._model, "override"),
(self.scf_conv_thr, "disabled"),
lambda override: not override,
)
self.forc_conv_thr = ipw.BoundedFloatText(
min=1e-15,
max=1.0,
Expand All @@ -209,11 +177,6 @@ def render(self):
(self._model, "forc_conv_thr_step"),
(self.forc_conv_thr, "step"),
)
ipw.dlink(
(self._model, "override"),
(self.forc_conv_thr, "disabled"),
lambda override: not override,
)
self.etot_conv_thr = ipw.BoundedFloatText(
min=1e-15,
max=1.0,
Expand All @@ -228,11 +191,6 @@ def render(self):
(self._model, "etot_conv_thr_step"),
(self.etot_conv_thr, "step"),
)
ipw.dlink(
(self._model, "override"),
(self.etot_conv_thr, "disabled"),
lambda override: not override,
)
self.electron_maxstep = ipw.BoundedIntText(
min=20,
max=1000,
Expand All @@ -244,11 +202,6 @@ def render(self):
(self._model, "electron_maxstep"),
(self.electron_maxstep, "value"),
)
ipw.dlink(
(self._model, "override"),
(self.electron_maxstep, "disabled"),
lambda override: not override,
)

self.pseudos.render()

Expand All @@ -257,31 +210,9 @@ def render(self):
ipw.HBox(
children=[
self.clean_workdir,
ipw.HTML("""
<div style="line-height: 140%; padding-top: 0px; padding-bottom: 5px">
Tick to clean-up the work directory after the calculation is finished.
</div>
"""),
self.reset_to_defaults_button,
],
layout=ipw.Layout(height="50px", justify_content="flex-start"),
),
ipw.HBox(
children=[
ipw.HTML("""
Select the advanced settings for the <b>pw.x</b> code.
"""),
ipw.HBox(
children=[
ipw.HTML(
value="<b>Override</b>",
layout=ipw.Layout(margin="0 5px 0 0"),
),
self.override,
],
layout=ipw.Layout(max_width="20%"),
),
],
layout=ipw.Layout(height="50px", justify_content="space-between"),
layout=ipw.Layout(justify_content="space-between"),
),
self.total_charge,
self.van_der_waals,
Expand All @@ -293,17 +224,16 @@ def render(self):
self.etot_conv_thr,
self.scf_conv_thr,
],
layout=ipw.Layout(height="50px", justify_content="flex-start"),
layout=ipw.Layout(justify_content="space-between"),
),
self.electron_maxstep,
self.smearing,
ipw.HTML("""
<div>
The k-points mesh density of the SCF calculation is set by the
<b>protocol</b>. The value below represents the maximum distance
between the k-points in each direction of reciprocal space. Tick
the box to override the default, smaller is more accurate and
costly.
between the k-points in each direction of reciprocal space. Smaller
is more accurate and costly.
</div>
"""),
ipw.HBox(
Expand All @@ -329,6 +259,10 @@ def _on_protocol_change(self, _):
def _on_kpoints_distance_change(self, _):
self.refresh(specific="mesh")

def _on_override_change(self, change):
if not change["new"]:
self._model.reset()
def _on_reset_to_defaults_button_click(self, _):
self._reset()

def _reset(self):
self._model.reset()
for _, model in self._model.get_models():
model.reset()
10 changes: 0 additions & 10 deletions src/aiidalab_qe/app/configuration/advanced/hubbard/hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ def render(self):
(self._model, "is_active"),
(self.activate_hubbard_checkbox, "value"),
)
ipw.dlink(
(self._model, "override"),
(self.activate_hubbard_checkbox, "disabled"),
lambda override: not override,
)

self.eigenvalues_help = ipw.HTML(
value="For transition metals and lanthanoids, the starting eigenvalues can be defined (Magnetic calculation).",
Expand All @@ -55,11 +50,6 @@ def render(self):
(self._model, "has_eigenvalues"),
(self.define_eigenvalues_checkbox, "value"),
)
ipw.dlink(
(self._model, "override"),
(self.define_eigenvalues_checkbox, "disabled"),
lambda override: not override,
)

self.eigenvalues_container = ipw.VBox(
children=[
Expand Down
2 changes: 0 additions & 2 deletions src/aiidalab_qe/app/configuration/advanced/hubbard/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class HubbardConfigurationSettingsModel(
"input_structure",
]

override = tl.Bool()

is_active = tl.Bool(False)
has_eigenvalues = tl.Bool(False)
parameters = tl.Dict(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,18 @@ def render(self):
(self._model, "type"),
(self.magnetization_type, "value"),
)
ipw.dlink(
(self._model, "override"),
(self.magnetization_type, "disabled"),
lambda override: not override,
)

self.tot_magnetization = ipw.BoundedIntText(
min=0,
max=100,
step=1,
disabled=True,
description="Total magnetization:",
style={"description_width": "initial"},
)
ipw.link(
(self._model, "total"),
(self.tot_magnetization, "value"),
)
ipw.dlink(
(self._model, "override"),
(self.tot_magnetization, "disabled"),
lambda override: not override,
)

self.kind_moment_widgets = ipw.VBox()

Expand Down Expand Up @@ -140,7 +129,6 @@ def _build_kinds_widget(self):
min=-4,
max=4,
step=0.1,
disabled=True,
)
link = ipw.link(
(self._model, "moments"),
Expand All @@ -154,11 +142,6 @@ def _build_kinds_widget(self):
],
)
self.links.append(link)
ipw.dlink(
(self._model, "override"),
(kind_moment_widget, "disabled"),
lambda override: not override,
)
children.append(kind_moment_widget)

self.kind_moment_widgets.children = children
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class MagnetizationConfigurationSettingsModel(

electronic_type = tl.Unicode()
spin_type = tl.Unicode()
override = tl.Bool()

type_options = tl.List(
trait=tl.List(tl.Unicode()),
Expand Down
10 changes: 2 additions & 8 deletions src/aiidalab_qe/app/configuration/advanced/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class AdvancedConfigurationSettingsModel(
spin_orbit = tl.Unicode()

clean_workdir = tl.Bool(DEFAULT["advanced"]["clean_workdir"])
override = tl.Bool(False)
total_charge = tl.Float(DEFAULT["advanced"]["tot_charge"])
van_der_waals_options = tl.List(
trait=tl.List(tl.Unicode()),
Expand Down Expand Up @@ -155,8 +154,8 @@ def get_model_state(self):
# Set tot_magnetization for collinear simulations.
if self.spin_type == "collinear":
# Conditions for metallic systems.
# Select the magnetization type and set the value if override is True
if self.electronic_type == "metal" and self.override:
# Select the magnetization type and set the value
if self.electronic_type == "metal":
if magnetization.type == "tot_magnetization":
parameters["pw"]["parameters"]["SYSTEM"]["tot_magnetization"] = (
magnetization.total
Expand Down Expand Up @@ -238,7 +237,6 @@ def reset(self):
self.electron_maxstep = self._get_default("electron_maxstep")
self.spin_orbit = self._get_default("spin_orbit")
self.kpoints_distance = self._get_default("kpoints_distance")
self.override = self._get_default("override")

def _get_default(self, trait):
return self._defaults.get(trait, self.traits()[trait].default_value)
Expand All @@ -248,10 +246,6 @@ def _link_model(self, model: AdvancedCalculationSubSettingsModel):
(self, "loaded_from_process"),
(model, "loaded_from_process"),
)
ipw.dlink(
(self, "override"),
(model, "override"),
)
model.observe(
self._on_any_change,
tl.All,
Expand Down
6 changes: 5 additions & 1 deletion src/aiidalab_qe/app/configuration/advanced/pseudos/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class PseudosConfigurationSettingsModel(

protocol = tl.Unicode()
spin_orbit = tl.Unicode()
override = tl.Bool()

dictionary = tl.Dict(
key_trait=tl.Unicode(), # kind name
Expand Down Expand Up @@ -110,6 +109,8 @@ class PseudosConfigurationSettingsModel(

family_help_message = tl.Unicode(PSEUDO_HELP_WO_SOC)

pseudo_filename_reset_trigger = tl.Int(0)

def update(self, specific=""): # noqa: ARG002
with self.hold_trait_notifications():
if not self.has_structure:
Expand Down Expand Up @@ -264,13 +265,16 @@ def reset(self):
with self.hold_trait_notifications():
self.dictionary = self._get_default("dictionary")
self.cutoffs = self._get_default("cutoffs")
self.ecutwfc = max(self.cutoffs[0])
self.ecutrho = max(self.cutoffs[1])
self.library_options = self._get_default("library_options")
self.library = self._get_default("library")
self.functional = self._get_default("functional")
self.functional_options = self._get_default("functional_options")
self.family = self._get_default("family")
self.family_help_message = self._get_default("family_help_message")
self.status_message = self._get_default("status_message")
self.pseudo_filename_reset_trigger += 1

def _get_default(self, trait):
if trait == "dictionary":
Expand Down
Loading

0 comments on commit 5ce2532

Please sign in to comment.