Skip to content

Commit

Permalink
splitting editors
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresOrtegaGuerrero committed Jan 7, 2025
1 parent 94f23c7 commit 3ae3f98
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 33 deletions.
4 changes: 3 additions & 1 deletion src/aiidalab_qe/app/structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
AddingTagsEditor,
LazyLoadedOptimade,
LazyLoadedStructureBrowser,
PeriodicityEditor,
)
from aiidalab_qe.common.infobox import InAppGuide
from aiidalab_qe.common.widgets import CategorizedStructureExamplesWidget, QeWizardStep
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 7 additions & 1 deletion src/aiidalab_qe/common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# 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",
"LazyLoadedOptimade",
"LazyLoadedStructureBrowser",
"QeAppWorkChainSelector",
"WorkChainSelector",
"PeriodicityEditor",
]
78 changes: 47 additions & 31 deletions src/aiidalab_qe/common/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="<p style='font-style: italic;'>Note: The table is scrollable.</p>",
layout={"visibility": "hidden"},
Expand All @@ -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=[
Expand Down Expand Up @@ -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(
'<div style="margin-top: 20px;"><b>Set structure periodicity</b></div>'
),
ipw.HTML("""
<p>Select the periodicity of your system.</p>
<p style="font-weight: bold; color: #1f77b4;">NOTE:</p>
<ul style="padding-left: 2em; list-style-type: disc;">
<li>For <b>2D</b> systems (e.g., surfaces, slabs), the non-periodic direction must be the third lattice vector (z-axis).</li>
<li>For <b>1D</b> systems (e.g., wires), the periodic direction must be the first lattice vector (x-axis).</li>
</ul>
"""),
self.periodicity,
self.apply_periodicity,
],
**kwargs,
)
Expand Down Expand Up @@ -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(
'<div style="margin-top: 20px;"><b>Set structure periodicity</b></div>'
),
ipw.HTML("""
<p>Select the periodicity of your system.</p>
<p style="font-weight: bold; color: #1f77b4;">NOTE:</p>
<ul style="padding-left: 2em; list-style-type: disc;">
<li>For <b>2D</b> systems (e.g., surfaces, slabs), the non-periodic direction must be the third lattice vector (z-axis).</li>
<li>For <b>1D</b> systems (e.g., wires), the periodic direction must be the first lattice vector (x-axis).</li>
</ul>
"""),
self.periodicity,
self.apply_periodicity,
],
**kwargs,
)

def _select_periodicity(self, _=None):
"""Select periodicity."""
periodicity_options = {
Expand Down

0 comments on commit 3ae3f98

Please sign in to comment.