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

modifications to the EditStructureData Widgets #956

Merged
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
40 changes: 35 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,22 @@ 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:</p>
<ul style="padding-left: 2em; list-style-type: disc;">
<li>Atom indices start from 1, not 0. This means that the first atom in the list is numbered 1, the second atom is numbered 2, and so on.</li>
</ul>

Note:
</p>
"""
),
ipw.HBox(
[
Expand All @@ -501,10 +524,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 +554,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 +586,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
Loading