Skip to content

Commit

Permalink
Explicitly switch on/off cell optimisation, fix bugs (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha authored Jun 2, 2023
1 parent c42acd8 commit 69c8fb7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 51 deletions.
5 changes: 1 addition & 4 deletions submit_calculations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@
" parameters = input_details.final_dictionary.copy()\n",
"\n",
" builder = Cp2kGeoOptWorkChain.get_builder()\n",
" if 'cell_opt' in parameters['dft_params']:\n",
" builder.metadata.label += \"CP2K_CellOpt\"\n",
" else:\n",
" builder.metadata.label = \"CP2K_GeoOpt\"\n",
" builder.metadata.label = \"CP2K_CellOpt\" if input_details.do_cell_opt else \"CP2K_GeoOpt\"\n",
" builder.metadata.description = parameters['description']\n",
" code = orm.load_code(computational_resources.value)\n",
" builder.code = code\n",
Expand Down
79 changes: 32 additions & 47 deletions surfaces_tools/widgets/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,16 +569,8 @@ class CellSectionWidget(ipw.Accordion):
do_cell_opt = tr.Bool()

def __init__(self):
self.cell_constraint = ipw.Dropdown(
description="Cell constr.",
options=["XYZ", "NONE", "X", "XY", "XZ", "Y", "YZ", "Z"],
value="NONE",
style=STYLE,
layout=LAYOUT2,
)

self.cell_sym = ipw.Dropdown(
description="symmetry",
self.cell_symmetry = ipw.Dropdown(
description="Cell symmetry:",
options=[
"CUBIC",
"HEXAGONL",
Expand All @@ -593,62 +585,55 @@ def __init__(self):
],
value="ORTHORHOMBIC",
style=STYLE,
layout=LAYOUT,
)

self.opt_cell = ipw.ToggleButton(
value=False,
description="Optimize cell",
style={"description_width": "120px"},
self.cell_constraint = ipw.Dropdown(
description="Cell constraints:",
options=["XYZ", "NONE", "X", "XY", "XZ", "Y", "YZ", "Z"],
value="NONE",
style=STYLE,
)

def on_cell_opt(c=None):
self.do_cell_opt = self.opt_cell.value

self.opt_cell.observe(on_cell_opt, "value")

self.cell_free = ipw.ToggleButtons(
self.cell_freedom = ipw.Dropdown(
options=["FREE", "KEEP_SYMMETRY", "KEEP_ANGLES", "KEEP_SPACE_GROUP"],
description="Cell freedom",
value="KEEP_SYMMETRY",
style=STYLE,
layout=LAYOUT,
)

super().__init__(selected_index=None)
self.opt_cell = ipw.Checkbox(
value=False,
description="Optimize cell",
)
tr.link((self, "do_cell_opt"), (self.opt_cell, "value"))

self.set_title(0, "Cell optimization")

super().__init__(
selected_index=None,
children=[
ipw.VBox(
[
self.cell_symmetry,
self.cell_freedom,
self.cell_constraint,
self.opt_cell,
]
)
],
)

def return_dict(self):
sys_params = {"symmetry": self.cell_sym.value}
sys_params = {"symmetry": self.cell_symmetry.value}
if self.opt_cell.value:
sys_params["cell_opt"] = ""
if self.cell_constraint.value != "NONE":
sys_params["cell_opt_constraint"] = self.cell_constraint.value
if self.cell_free.value != "FREE":
sys_params[self.cell_free.value.lower()] = ""
if self.cell_freedom.value != "FREE":
sys_params[self.cell_freedom.value.lower()] = ""

return {"sys_params": sys_params}

@tr.observe("details")
def _observe_details(self, _=None):
self._widgets_to_show()

@tr.observe("do_cell_opt")
def _observe_do_cell_opt(self, _=None):
self._widgets_to_show()

def _widgets_to_show(self):
if self.opt_cell.value:
self.set_title(0, "CELL details")
self.children = [
ipw.VBox([self.cell_sym, self.cell_free, self.cell_constraint])
]
else:
self.set_title(0, "CELL details")
self.children = [self.cell_sym]

if self.details["system_type"] == "Molecule":
self.periodic.value = "NONE"

def traits_to_link(self):
return ["details", "do_cell_opt"]

Expand Down

0 comments on commit 69c8fb7

Please sign in to comment.