Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splitting AddingTag and Periodicity editors #1060

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="Edit atom tags"),
PeriodicityEditor(title="Edit 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: 44 additions & 34 deletions src/aiidalab_qe/common/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,21 +475,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 @@ -502,13 +487,9 @@ 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=[
ipw.HTML(
"<b>Set custom tags for atoms</b>",
),
ipw.HTML(
"""
<p>
Expand All @@ -533,21 +514,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 @@ -654,6 +620,50 @@ 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("""
<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
Loading