From 779511b741ad2adb8077466aabf09e2fd907338f Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Wed, 1 Nov 2023 15:18:12 +0100 Subject: [PATCH] Move diagonalisation and smearing settings to a separate widget (#200) --- submit_pdos.ipynb | 40 +++++--------------- submit_spm.ipynb | 49 ++++++------------------ surfaces_tools/widgets/inputs.py | 64 ++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 68 deletions(-) diff --git a/submit_pdos.ipynb b/submit_pdos.ipynb index 74f7cc9..a716ec3 100644 --- a/submit_pdos.ipynb +++ b/submit_pdos.ipynb @@ -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()" ] }, { @@ -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", @@ -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", @@ -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)" ] }, { diff --git a/submit_spm.ipynb b/submit_spm.ipynb index 87dcbce..3ac2742 100644 --- a/submit_spm.ipynb +++ b/submit_spm.ipynb @@ -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", @@ -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)" ] }, { @@ -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", diff --git a/surfaces_tools/widgets/inputs.py b/surfaces_tools/widgets/inputs.py index 76be8ec..f4d9cb5 100644 --- a/surfaces_tools/widgets/inputs.py +++ b/surfaces_tools/widgets/inputs.py @@ -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": [