diff --git a/src/aiidalab_qe_vibroscopy/app/result/model.py b/src/aiidalab_qe_vibroscopy/app/result/model.py index 3196fc0..35f0b92 100644 --- a/src/aiidalab_qe_vibroscopy/app/result/model.py +++ b/src/aiidalab_qe_vibroscopy/app/result/model.py @@ -1,7 +1,7 @@ from aiidalab_qe.common.panel import ResultsModel import traitlets as tl -from aiidalab_qe_vibroscopy.utils.dielectric.result import export_dielectric_data + from aiidalab_qe_vibroscopy.utils.raman.result import export_iramanworkchain_data from aiidalab_qe_vibroscopy.utils.phonons.result import export_phononworkchain_data from aiidalab_qe_vibroscopy.utils.euphonic import export_euphonic_data @@ -18,7 +18,10 @@ def get_vibro_node(self): return self._get_child_outputs() def needs_dielectric_tab(self): - return export_dielectric_data(self.get_vibro_node()) + node = self.get_vibro_node() + if not any(key in node for key in ["iraman", "dielectric", "harmonic"]): + return False + return True def needs_raman_tab(self): return export_iramanworkchain_data(self.get_vibro_node()) diff --git a/src/aiidalab_qe_vibroscopy/app/result/result.py b/src/aiidalab_qe_vibroscopy/app/result/result.py index d445519..21ced89 100644 --- a/src/aiidalab_qe_vibroscopy/app/result/result.py +++ b/src/aiidalab_qe_vibroscopy/app/result/result.py @@ -27,7 +27,7 @@ def render(self): ) tab_data = [] - # vibro_node = self._model.get_vibro_node() + vibro_node = self._model.get_vibro_node() if self._model.needs_phonons_tab(): tab_data.append(("Phonons", ipw.HTML("phonon_data"))) @@ -35,12 +35,13 @@ def render(self): if self._model.needs_raman_tab(): tab_data.append(("Raman", ipw.HTML("raman_data"))) - dielectric_data = self._model.needs_dielectric_tab() + needs_dielectri_tab = self._model.needs_dielectric_tab() - if dielectric_data: + if needs_dielectri_tab: dielectric_model = DielectricModel() dielectric_widget = DielectricWidget( - model=dielectric_model, dielectric_data=dielectric_data + model=dielectric_model, + node=vibro_node, ) tab_data.append(("Dielectric Properties", dielectric_widget)) diff --git a/src/aiidalab_qe_vibroscopy/app/widgets/dielectricmodel.py b/src/aiidalab_qe_vibroscopy/app/widgets/dielectricmodel.py index 3fbd2d1..95f376f 100644 --- a/src/aiidalab_qe_vibroscopy/app/widgets/dielectricmodel.py +++ b/src/aiidalab_qe_vibroscopy/app/widgets/dielectricmodel.py @@ -1,25 +1,31 @@ from aiidalab_qe.common.mvc import Model import traitlets as tl - +from aiida.common.extendeddicts import AttributeDict from aiidalab_qe_vibroscopy.utils.dielectric.result import NumpyEncoder import numpy as np import base64 import json from IPython.display import display +from aiidalab_qe_vibroscopy.utils.dielectric.result import export_dielectric_data class DielectricModel(Model): - dielectric_data = {} + vibro = tl.Instance(AttributeDict, allow_none=True) site_selector_options = tl.List( trait=tl.Tuple((tl.Unicode(), tl.Int())), ) + dielectric_data = {} dielectric_tensor_table = tl.Unicode("") born_charges_table = tl.Unicode("") raman_tensors_table = tl.Unicode("") site = tl.Int() + def fetch_data(self): + """Fetch the dielectric data from the VibroWorkChain""" + self.dielectric_data = export_dielectric_data(self.vibro) + def set_initial_values(self): """Set the initial values for the model.""" diff --git a/src/aiidalab_qe_vibroscopy/app/widgets/dielectricwidget.py b/src/aiidalab_qe_vibroscopy/app/widgets/dielectricwidget.py index d729e25..ac6c889 100644 --- a/src/aiidalab_qe_vibroscopy/app/widgets/dielectricwidget.py +++ b/src/aiidalab_qe_vibroscopy/app/widgets/dielectricwidget.py @@ -8,7 +8,7 @@ class DielectricWidget(ipw.VBox): Widget for displaying dielectric properties results """ - def __init__(self, model: DielectricModel, dielectric_data: None, **kwargs): + def __init__(self, model: DielectricModel, node: None, **kwargs): super().__init__( children=[LoadingWidget("Loading widgets")], **kwargs, @@ -16,7 +16,7 @@ def __init__(self, model: DielectricModel, dielectric_data: None, **kwargs): self._model = model self.rendered = False - self._model.dielectric_data = dielectric_data + self._model.vibro = node def render(self): if self.rendered: @@ -100,6 +100,7 @@ def render(self): self._initial_view() def _initial_view(self): + self._model.fetch_data() self._model.set_initial_values() self.dielectric_tensor_table.layout = ipw.Layout(width="300px", height="auto") self.born_charges_table.layout = ipw.Layout(width="300px", height="auto")