From 6ff4cbc1cd9c5a74c68eec601bb9ffddb4abc676 Mon Sep 17 00:00:00 2001 From: AndresOrtegaGuerrero Date: Wed, 8 Jan 2025 09:01:11 +0000 Subject: [PATCH 1/4] adding info for optimized structured --- .../components/viewer/structure/structure.py | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/aiidalab_qe/app/result/components/viewer/structure/structure.py b/src/aiidalab_qe/app/result/components/viewer/structure/structure.py index 0011ef49c..5bc90d8bc 100644 --- a/src/aiidalab_qe/app/result/components/viewer/structure/structure.py +++ b/src/aiidalab_qe/app/result/components/viewer/structure/structure.py @@ -1,6 +1,7 @@ import ipywidgets as ipw from aiidalab_qe.common.panel import ResultsPanel +from aiidalab_qe.common.time import format_time, relative_time from aiidalab_qe.common.widgets import TableWidget from aiidalab_widgets_base.viewers import StructureDataViewer @@ -26,11 +27,22 @@ def _render(self): """) self.atom_coordinates_table = TableWidget() self._generate_table(structure.get_ase()) - self.results_container.children = [ + + # Basic widgets + children = [ self.widget, self.table_description, self.atom_coordinates_table, ] + + # Add structure info if it is a relaxed structure + if "relax" in self._model.properties: + self._initialize_structure_info(structure) + children.insert(0, self.structure_info) + + # Add the children to the container + self.results_container.children = tuple(children) + self.atom_coordinates_table.observe(self._change_selection, "selected_rows") # Listen for changes in self.widget.displayed_selection and update the table self.widget.observe(self._update_table_selection, "displayed_selection") @@ -42,6 +54,20 @@ def _render(self): ngl._set_size("100%", "300px") ngl.control.zoom(0.0) + def _initialize_structure_info(self, structure): + self.structure_info = ipw.HTML( + f""" +

Structure properties

+
+ PK: {structure.pk}
+ Label: {structure.label}
+ Description: {structure.description}
+ Number of atoms: {len(structure.sites)}
+ Creation time: {format_time(structure.ctime)} ({relative_time(structure.ctime)})
+
+ """ + ) + def _generate_table(self, structure): data = [ [ From 48f128aff229583b8bf342d8d2975806a9005e78 Mon Sep 17 00:00:00 2001 From: AndresOrtegaGuerrero Date: Wed, 8 Jan 2025 09:03:31 +0000 Subject: [PATCH 2/4] removing header --- .../app/result/components/viewer/structure/structure.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/aiidalab_qe/app/result/components/viewer/structure/structure.py b/src/aiidalab_qe/app/result/components/viewer/structure/structure.py index 5bc90d8bc..925007a55 100644 --- a/src/aiidalab_qe/app/result/components/viewer/structure/structure.py +++ b/src/aiidalab_qe/app/result/components/viewer/structure/structure.py @@ -57,7 +57,6 @@ def _render(self): def _initialize_structure_info(self, structure): self.structure_info = ipw.HTML( f""" -

Structure properties

PK: {structure.pk}
Label: {structure.label}
From 13f964ff5e482dbc2512fc8a46a80e16a0484925 Mon Sep 17 00:00:00 2001 From: AndresOrtegaGuerrero Date: Wed, 8 Jan 2025 10:33:08 +0000 Subject: [PATCH 3/4] apply edan's suggestions --- .../components/viewer/structure/structure.py | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/aiidalab_qe/app/result/components/viewer/structure/structure.py b/src/aiidalab_qe/app/result/components/viewer/structure/structure.py index 925007a55..0904c380a 100644 --- a/src/aiidalab_qe/app/result/components/viewer/structure/structure.py +++ b/src/aiidalab_qe/app/result/components/viewer/structure/structure.py @@ -28,21 +28,17 @@ def _render(self): self.atom_coordinates_table = TableWidget() self._generate_table(structure.get_ase()) - # Basic widgets - children = [ + # Get information from the structure + structure_info = self._get_structure_info(structure) + + # Add the children to the container + self.results_container.children = [ + structure_info, self.widget, self.table_description, self.atom_coordinates_table, ] - # Add structure info if it is a relaxed structure - if "relax" in self._model.properties: - self._initialize_structure_info(structure) - children.insert(0, self.structure_info) - - # Add the children to the container - self.results_container.children = tuple(children) - self.atom_coordinates_table.observe(self._change_selection, "selected_rows") # Listen for changes in self.widget.displayed_selection and update the table self.widget.observe(self._update_table_selection, "displayed_selection") @@ -54,8 +50,8 @@ def _render(self): ngl._set_size("100%", "300px") ngl.control.zoom(0.0) - def _initialize_structure_info(self, structure): - self.structure_info = ipw.HTML( + def _get_structure_info(self, structure): + return ipw.HTML( f"""
PK: {structure.pk}
From a5d4021bf35723894a9799ec8ed51a62471f7283 Mon Sep 17 00:00:00 2001 From: AndresOrtegaGuerrero Date: Wed, 8 Jan 2025 12:27:53 +0000 Subject: [PATCH 4/4] removing comments --- .../app/result/components/viewer/structure/structure.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/aiidalab_qe/app/result/components/viewer/structure/structure.py b/src/aiidalab_qe/app/result/components/viewer/structure/structure.py index 0904c380a..3ddd7f55e 100644 --- a/src/aiidalab_qe/app/result/components/viewer/structure/structure.py +++ b/src/aiidalab_qe/app/result/components/viewer/structure/structure.py @@ -28,10 +28,8 @@ def _render(self): self.atom_coordinates_table = TableWidget() self._generate_table(structure.get_ase()) - # Get information from the structure structure_info = self._get_structure_info(structure) - # Add the children to the container self.results_container.children = [ structure_info, self.widget,