Skip to content

Commit

Permalink
Move diagonalisation and smearing settings to a separate widget (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha authored Nov 1, 2023
1 parent 9db2e6e commit 779511b
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 68 deletions.
40 changes: 10 additions & 30 deletions submit_pdos.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,7 @@
"ipw.dlink((empa_viewer, \"details\"), (uks_widget, \"details\"))\n",
"ipw.dlink((uks_widget, \"uks\"), (fragment_list, \"uks\"))\n",
"\n",
"sc_diag_check = ipw.Checkbox(\n",
" value=False, description=\"self-consistent diagonalization\", disabled=True\n",
")\n",
"force_multiplicity_check = ipw.Checkbox(\n",
" value=True, description=\"Fix multiplicity\", disabled=True\n",
")\n",
"\n",
"\n",
"def enable_smearing(b):\n",
" temperature_text.disabled = not smear_switch.value\n",
" force_multiplicity_check.disabled = not smear_switch.value\n",
"\n",
"\n",
"smear_switch = ipw.Checkbox(\n",
" value=False, description=\"Enable Fermi-Dirac smearing\", style=style\n",
")\n",
"smear_switch.observe(enable_smearing, names=\"value\")\n",
"\n",
"temperature_text = ipw.FloatText(\n",
" value=150.0, description=\"Temperature [K]\", disabled=True, style=style\n",
")"
"diagonalisation_smearing = inputs.DiagonalisationSmearingWidget()"
]
},
{
Expand Down Expand Up @@ -301,7 +281,7 @@
" dft_params_dict = {\n",
" \"elpa_switch\": elpa_check.value,\n",
" \"uks\": uks_widget.uks,\n",
" \"sc_diag\": sc_diag_check.value,\n",
" \"sc_diag\": diagonalisation_smearing.enable_diagonalisation.value,\n",
" \"periodic\": \"XYZ\",\n",
" \"charges\": {\n",
" fragment.name.value: fragment.charge.value\n",
Expand All @@ -319,12 +299,16 @@
" fragment.name.value: fragment.multiplicity.value\n",
" for fragment in fragment_list.fragments\n",
" },\n",
" \"force_multiplicity\": force_multiplicity_check.value,\n",
" }\n",
" )\n",
"\n",
" if smear_switch.value:\n",
" dft_params_dict[\"smear_t\"] = temperature_text.value\n",
" if diagonalisation_smearing.smearing_enabled:\n",
" dft_params_dict[\n",
" \"smear_t\"\n",
" ] = diagonalisation_smearing.smearing_temperature.value\n",
" dft_params_dict[\n",
" \"force_multiplicity\"\n",
" ] = diagonalisation_smearing.force_multiplicity.value\n",
"\n",
" dft_params = orm.Dict(dict=dft_params_dict)\n",
"\n",
Expand Down Expand Up @@ -453,11 +437,7 @@
"metadata": {},
"outputs": [],
"source": [
"display(\n",
" protocol,\n",
" uks_widget,\n",
" ipw.HBox([smear_switch, temperature_text, force_multiplicity_check]),\n",
")"
"display(protocol, uks_widget, diagonalisation_smearing)"
]
},
{
Expand Down
49 changes: 11 additions & 38 deletions submit_spm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"\n",
"uks_input = inputs.UksSectionWidget()\n",
"\n",
"sc_diag_check = ipw.Checkbox(value=False, description=\"self-consistent diagonalization\")\n",
"diagonalisation_smearing = inputs.DiagonalisationSmearingWidget()\n",
"\n",
"\n",
"protocol = ipw.Dropdown(\n",
" value=\"standard\",\n",
Expand All @@ -118,38 +119,7 @@
")\n",
"\n",
"elpa_check = ipw.Checkbox(value=True, description=\"use ELPA\")\n",
"display(uks_input, sc_diag_check)\n",
"\n",
"\n",
"# Smearing options.\n",
"force_multiplicity = ipw.Checkbox(\n",
" value=True, description=\"Force multiplicity\", disabled=True\n",
")\n",
"\n",
"\n",
"def enable_smearing(b):\n",
" temperature_text.disabled = not smear_switch.value\n",
" force_multiplicity.disabled = not smear_switch.value\n",
"\n",
"\n",
"smear_switch = ipw.ToggleButton(\n",
" value=False,\n",
" description=\"Enable Fermi-Dirac smearing\",\n",
" style=style,\n",
" layout={\"width\": \"450px\"},\n",
")\n",
"smear_switch.observe(enable_smearing, names=\"value\")\n",
"\n",
"temperature_text = ipw.FloatText(\n",
" value=150.0,\n",
" description=\"Temperature [K]\",\n",
" disabled=True,\n",
" style={\"description_width\": \"100px\"},\n",
" layout={\"width\": \"20%\"},\n",
")\n",
"\n",
"\n",
"display(smear_switch, ipw.HBox([temperature_text, force_multiplicity]), protocol)"
"display(uks_input, diagonalisation_smearing, protocol)"
]
},
{
Expand Down Expand Up @@ -538,16 +508,19 @@
"\n",
" dft_params_dict = {\n",
" \"elpa_switch\": elpa_check.value,\n",
" \"sc_diag\": sc_diag_check.value,\n",
" \"force_multiplicity\": force_multiplicity.value,\n",
" \"sc_diag\": smearing_diagonalisation.enable_diagonalisation.value,\n",
" \"periodic\": \"XYZ\",\n",
" }\n",
"\n",
" dft_params_dict.update(uks_input.return_dict()[\"dft_params\"])\n",
"\n",
" if smear_switch.value:\n",
" dft_params_dict[\"smear_t\"] = temperature_text.value\n",
" dft_params_dict[\"force_multiplicity\"] = force_multiplicity.value\n",
" if smearing_diagonalisation.smearing_enabled:\n",
" dft_params_dict[\n",
" \"smear_t\"\n",
" ] = smearing_diagonalisation.smearing_temperature.value\n",
" dft_params_dict[\n",
" \"force_multiplicity\"\n",
" ] = smearing_diagonalisation.force_multiplicity.value\n",
"\n",
" dft_params = orm.Dict(dict=dft_params_dict)\n",
"\n",
Expand Down
64 changes: 64 additions & 0 deletions surfaces_tools/widgets/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,70 @@ def traits_to_link(self):
return ["details", "do_cell_opt"]


class DiagonalisationSmearingWidget(ipw.HBox):
def __init__(self, **kwargs):
self.enable_diagonalisation = ipw.Checkbox(
value=False,
description="Self-consistent diagonalisation",
style={"description_width": "initial"},
layout={"width": "240px"},
)
self.enable_diagonalisation.observe(
self._observe_enable_diagonalisation, "value"
)
self.enable_diagonalisation.observe(self.enable_or_disable_widgets, "value")

self.enable_smearing = ipw.ToggleButton(
value=False,
description="Enable Fermi-Dirac smearing",
style={"description_width": "initial"},
layout={"width": "450px"},
)
self.enable_smearing.observe(self.enable_or_disable_widgets, "value")

self.smearing_temperature = ipw.FloatText(
value=150.0,
description="Temperature [K]",
disabled=True,
style={"description_width": "initial"},
layout={"width": "200px"},
)
self.force_multiplicity = ipw.Checkbox(
value=True, description="Force multiplicity", disabled=True
)
self.smearing_box = ipw.VBox(
children=[
self.enable_smearing,
ipw.HBox(children=[self.smearing_temperature, self.force_multiplicity]),
]
)

super().__init__(
children=[
self.enable_diagonalisation,
],
**kwargs,
)

def _observe_enable_diagonalisation(self, _=None):
if self.enable_diagonalisation.value:
self.children = [
self.enable_diagonalisation,
self.smearing_box,
]
else:
self.children = [self.enable_diagonalisation]

def enable_or_disable_widgets(self, _=None):
self.enable_smearing.disabled = not self.enable_diagonalisation.value
self.smearing_temperature.disabled = not self.enable_smearing.value
self.force_multiplicity.disabled = not self.enable_smearing.value

@property
def smearing_enabled(self):
return self.enable_diagonalisation and self.enable_smearing.value


SECTIONS_TO_DISPLAY = {
"None": [],
"Wire": [
Expand Down

0 comments on commit 779511b

Please sign in to comment.