Skip to content

Commit

Permalink
modifications to the EditStructureData Widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresOrtegaGuerrero committed Nov 28, 2024
1 parent a5d670e commit b959f9f
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/aiidalab_qe/common/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,11 @@ def __init__(self, title="", **kwargs):

self._status_message = StatusHTML()
self.atom_selection = ipw.Text(
description="Index of atoms", value="", layout={"width": "initial"}
placeholder="e.g. 1..5 8 10",
description="Index of atoms",
value="",
style={"description_width": "100px"},
layout={"width": "initial"},
)
self.from_selection = ipw.Button(description="From selection")
self.from_selection.on_click(self._from_selection)
Expand Down Expand Up @@ -478,6 +482,10 @@ def __init__(self, title="", **kwargs):
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"},
)
self.tag_display = ipw.Output()
self.add_tags.on_click(self._add_tags)
self.reset_tags.on_click(self._reset_tags)
Expand All @@ -491,7 +499,18 @@ def __init__(self, title="", **kwargs):
super().__init__(
children=[
ipw.HTML(
"<b>Adding a tag to atoms</b>",
"<b>Set custom tags for atoms</b>",
),
ipw.HTML(
"""
<p>
These are used to distinguish atoms of the same chemical element. <br>
For example, they can be used to assign different initial magnetization values for antiferromagnetic systems.
</p>
<p style="font-weight: bold; color: #1f77b4;">
Note: Atom indices are 1-based (first atom has index 1, second atom has index 2, ...).
</p>
"""
),
ipw.HBox(
[
Expand All @@ -501,10 +520,11 @@ def __init__(self, title="", **kwargs):
]
),
self.tag_display,
self.scroll_note,
ipw.HBox([self.add_tags, self.reset_tags, self.reset_all_tags]),
self._status_message,
ipw.HTML(
"<b>Define periodicity</b>",
'<div style="margin-top: 20px;"><b>Set structure periodicity</b></div>'
),
ipw.HTML("""
<p>Select the periodicity of your system.</p>
Expand All @@ -530,14 +550,18 @@ def _display_table(self, _=None):
current_tags = self.structure.get_tags()
chemichal_symbols = self.structure.get_chemical_symbols()

if selection and (max(selection) <= (len(self.structure) - 1)):
if (
selection
and (min(selection) >= 0)
and (max(selection) <= (len(self.structure) - 1))
):
table_data = []
for index in selection:
tag = current_tags[index]
symbol = chemichal_symbols[index]
if tag == 0:
tag = ""
table_data.append([f"{index}", f"{symbol}", f"{tag}"])
table_data.append([f"{index+ 1}", f"{symbol}", f"{tag}"])

# Create an HTML table
table_html = "<table>"
Expand All @@ -558,10 +582,12 @@ def _display_table(self, _=None):
with self.tag_display:
clear_output()
display(HTML(table_html))
self.scroll_note.layout = {"visibility": "visible"}
else:
self.tag_display.layout = {}
with self.tag_display:
clear_output()
self.scroll_note.layout = {"visibility": "hidden"}

def _from_selection(self, _=None):
"""Set the atom selection from the current selection."""
Expand Down

0 comments on commit b959f9f

Please sign in to comment.