Skip to content

Commit

Permalink
move the fetch data to dielectric model
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresOrtegaGuerrero committed Nov 30, 2024
1 parent 04d5d17 commit 3321f58
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/aiidalab_qe_vibroscopy/app/result/model.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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())
Expand Down
9 changes: 5 additions & 4 deletions src/aiidalab_qe_vibroscopy/app/result/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,21 @@ 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")))

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))

Expand Down
10 changes: 8 additions & 2 deletions src/aiidalab_qe_vibroscopy/app/widgets/dielectricmodel.py
Original file line number Diff line number Diff line change
@@ -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."""

Expand Down
5 changes: 3 additions & 2 deletions src/aiidalab_qe_vibroscopy/app/widgets/dielectricwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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,
)
self._model = model

self.rendered = False
self._model.dielectric_data = dielectric_data
self._model.vibro = node

def render(self):
if self.rendered:
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 3321f58

Please sign in to comment.