diff --git a/src/aiidalab_qe/app/result/components/viewer/structure/model.py b/src/aiidalab_qe/app/result/components/viewer/structure/model.py index 7e12d89a6..e58d5b9d9 100644 --- a/src/aiidalab_qe/app/result/components/viewer/structure/model.py +++ b/src/aiidalab_qe/app/result/components/viewer/structure/model.py @@ -1,6 +1,7 @@ from __future__ import annotations import traitlets as tl +from ase.formula import Formula from aiida import orm from aiidalab_qe.common.panel import ResultsModel @@ -14,13 +15,15 @@ class StructureResultsModel(ResultsModel): structure = tl.Instance(orm.StructureData, allow_none=True) selected_view = tl.Unicode("initial") header = tl.Unicode() + sub_header = tl.Unicode() source = tl.Instance(orm.utils.managers.NodeLinksManager, allow_none=True) info = tl.Unicode() table_data = tl.List(tl.List()) _this_process_label = "PwRelaxWorkChain" - header_template = "

{title}

" + HEADER_TEMPLATE = "

{content}

" + _SUB_HEADER_TEMPLATE = "

{content}

" @property def include(self): @@ -34,15 +37,18 @@ def update(self): super().update() with self.hold_trait_notifications(): if not self.is_relaxed or self.selected_view == "initial": - self.header = self.header_template.format(title="Initial") + self.sub_header = self._SUB_HEADER_TEMPLATE.format(content="Initial") self.source = self.inputs else: - self.header = self.header_template.format(title="Relaxed") + self.sub_header = self._SUB_HEADER_TEMPLATE.format(content="Relaxed") self.source = self.outputs self.structure = self._get_structure() if self.structure: self.info = self._get_structure_info() self.table_data = self._get_atom_table_data() + if not self.header: + formatted = Formula(self.structure.get_formula()).format("html") + self.header = self.HEADER_TEMPLATE.format(content=formatted) def toggle_selected_view(self): self.selected_view = "relaxed" if self.selected_view == "initial" else "initial" 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 ae3e704bf..21cd1f4e9 100644 --- a/src/aiidalab_qe/app/result/components/viewer/structure/structure.py +++ b/src/aiidalab_qe/app/result/components/viewer/structure/structure.py @@ -31,6 +31,12 @@ def _render(self): (self.header, "value"), ) + self.sub_header = ipw.HTML() + ipw.dlink( + (self._model, "sub_header"), + (self.sub_header, "value"), + ) + self.view_toggle_button = ipw.Button( icon="eye", layout=ipw.Layout( @@ -68,7 +74,12 @@ def _render(self): children=[ ipw.VBox( children=[ - self.header, + ipw.VBox( + children=[ + self.header, + self.sub_header, + ], + ), self.view_toggle_button, ], layout=ipw.Layout(justify_content="space-between"), diff --git a/tests/test_result.py b/tests/test_result.py index 7a1d1d69a..0a5e16128 100644 --- a/tests/test_result.py +++ b/tests/test_result.py @@ -151,7 +151,8 @@ def test_table_data(model): wc = generate_qeapp_workchain(relax_type="none") model.process_uuid = wc.node.uuid node = model.fetch_process_node() - assert "Initial" in model.header + assert "Si2" in model.header + assert "Initial" in model.sub_header assert "properties" in model.source # inputs assert model.structure.pk == node.inputs.structure.pk assert str(node.inputs.structure.pk) in model.info @@ -163,12 +164,12 @@ def test_table_data(model): wc = generate_qeapp_workchain(relax_type="positions_cell") model.process_uuid = wc.node.uuid node = model.fetch_process_node() - assert "Initial" in model.header + assert "Initial" in model.sub_header assert panel.view_toggle_button.layout.display == "block" assert panel.view_toggle_button.description == "View relaxed" panel.view_toggle_button.click() assert panel.view_toggle_button.description == "View initial" - assert "Relaxed" in model.header + assert "Relaxed" in model.sub_header assert "properties" not in model.source # outputs assert model.structure.pk == node.outputs.structure.pk assert str(node.outputs.structure.pk) in model.info