From 3ae3f98654bd6c973be82d7a32d1da2ebc2c715c Mon Sep 17 00:00:00 2001 From: AndresOrtegaGuerrero Date: Tue, 7 Jan 2025 12:33:45 +0000 Subject: [PATCH] splitting editors --- src/aiidalab_qe/app/structure/__init__.py | 4 +- src/aiidalab_qe/common/__init__.py | 8 ++- src/aiidalab_qe/common/widgets.py | 78 ++++++++++++++--------- 3 files changed, 57 insertions(+), 33 deletions(-) diff --git a/src/aiidalab_qe/app/structure/__init__.py b/src/aiidalab_qe/app/structure/__init__.py index f58d1f2bc..286bdd379 100644 --- a/src/aiidalab_qe/app/structure/__init__.py +++ b/src/aiidalab_qe/app/structure/__init__.py @@ -13,6 +13,7 @@ AddingTagsEditor, LazyLoadedOptimade, LazyLoadedStructureBrowser, + PeriodicityEditor, ) from aiidalab_qe.common.infobox import InAppGuide from aiidalab_qe.common.widgets import CategorizedStructureExamplesWidget, QeWizardStep @@ -80,7 +81,8 @@ def _render(self): editors = [ BasicCellEditor(title="Edit cell"), BasicStructureEditor(title="Edit structure"), - AddingTagsEditor(title="Edit StructureData"), + AddingTagsEditor(title="Set atom tags"), + PeriodicityEditor(title="Set periodicity"), ] plugin_editors = get_entry_items("aiidalab_qe.properties", "editor") diff --git a/src/aiidalab_qe/common/__init__.py b/src/aiidalab_qe/common/__init__.py index 70dc6de9f..a82e29dd2 100644 --- a/src/aiidalab_qe/common/__init__.py +++ b/src/aiidalab_qe/common/__init__.py @@ -1,7 +1,12 @@ # trigger registration of the viewer widget: from .node_view import CalcJobNodeViewerWidget # noqa: F401 from .process import QeAppWorkChainSelector, WorkChainSelector -from .widgets import AddingTagsEditor, LazyLoadedOptimade, LazyLoadedStructureBrowser +from .widgets import ( + AddingTagsEditor, + LazyLoadedOptimade, + LazyLoadedStructureBrowser, + PeriodicityEditor, +) __all__ = [ "AddingTagsEditor", @@ -9,4 +14,5 @@ "LazyLoadedStructureBrowser", "QeAppWorkChainSelector", "WorkChainSelector", + "PeriodicityEditor", ] diff --git a/src/aiidalab_qe/common/widgets.py b/src/aiidalab_qe/common/widgets.py index 5b101eb7d..e2c2a3ce8 100644 --- a/src/aiidalab_qe/common/widgets.py +++ b/src/aiidalab_qe/common/widgets.py @@ -474,21 +474,6 @@ def __init__(self, title="", **kwargs): button_style="warning", layout={"width": "initial"}, ) - self.periodicity = ipw.RadioButtons( - options=[ - ("3D (bulk systems)", "xyz"), - ("2D (surfaces, slabs, ...)", "xy"), - ("1D (wires)", "x"), - ("0D (molecules)", "molecule"), - ], - value="xyz", - layout={"width": "initial"}, - ) - self.apply_periodicity = ipw.Button( - description="Apply", - button_style="primary", - layout={"width": "100px"}, - ) self.scroll_note = ipw.HTML( value="

Note: The table is scrollable.

", layout={"visibility": "hidden"}, @@ -501,7 +486,6 @@ def __init__(self, title="", **kwargs): self.add_tags.on_click(self._display_table) self.reset_tags.on_click(self._display_table) self.reset_all_tags.on_click(self._display_table) - self.apply_periodicity.on_click(self._select_periodicity) super().__init__( children=[ @@ -532,21 +516,6 @@ def __init__(self, title="", **kwargs): self.scroll_note, ipw.HBox([self.add_tags, self.reset_tags, self.reset_all_tags]), self._status_message, - ipw.HTML( - '
Set structure periodicity
' - ), - ipw.HTML(""" -

Select the periodicity of your system.

-

NOTE:

- - - """), - self.periodicity, - self.apply_periodicity, ], **kwargs, ) @@ -653,6 +622,53 @@ def _reset_all_tags(self, _=None): self.input_selection = None self.input_selection = deepcopy(self.selection) + +class PeriodicityEditor(ipw.VBox): + """Editor for changing periodicity of structures.""" + + structure = traitlets.Instance(ase.Atoms, allow_none=True) + + def __init__(self, title="", **kwargs): + self.title = title + + self.periodicity = ipw.RadioButtons( + options=[ + ("3D (bulk systems)", "xyz"), + ("2D (surfaces, slabs, ...)", "xy"), + ("1D (wires)", "x"), + ("0D (molecules)", "molecule"), + ], + value="xyz", + layout={"width": "initial"}, + ) + self.apply_periodicity = ipw.Button( + description="Apply", + button_style="primary", + layout={"width": "100px"}, + ) + self.apply_periodicity.on_click(self._select_periodicity) + + super().__init__( + children=[ + ipw.HTML( + '
Set structure periodicity
' + ), + ipw.HTML(""" +

Select the periodicity of your system.

+

NOTE:

+ + + """), + self.periodicity, + self.apply_periodicity, + ], + **kwargs, + ) + def _select_periodicity(self, _=None): """Select periodicity.""" periodicity_options = {