Skip to content

Commit

Permalink
Adding model modifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikibonacci committed Dec 2, 2024
1 parent 144dac7 commit ab69f31
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 38 deletions.
6 changes: 0 additions & 6 deletions src/aiidalab_qe_vibroscopy/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
VibroResourceSettingsModel,
VibroResourcesSettingsPanel,
)
from aiidalab_qe_vibroscopy.app.result.result import VibroResultsPanel
from aiidalab_qe_vibroscopy.app.result.model import VibroResultsModel

from aiidalab_qe_vibroscopy.app.workchain import workchain_and_builder

Expand All @@ -26,9 +24,5 @@ class VibroPluginOutline(PluginOutline):
"panel": VibroResourcesSettingsPanel,
"model": VibroResourceSettingsModel,
},
"result": {
"panel": VibroResultsPanel,
"model": VibroResultsModel,
},
"workchain": workchain_and_builder,
}
9 changes: 8 additions & 1 deletion src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from aiidalab_qe.common.panel import ResultsModel

class EuphonicSingleCrystalResultsModel(ResultsModel):
class EuphonicBaseResultsModel(ResultsModel):
"""Model for the neutron scattering results panel."""

# Here we mode all the model and data-controller, i.e. all the data and their
Expand All @@ -26,6 +26,7 @@ class EuphonicSingleCrystalResultsModel(ResultsModel):
# AAA TOBE defined with respect to the type
spectra = {}
path = []
q_path = None

# check the SingleCrystalSettingsWidget and base
q_spacing = tl.Float(0.01)
Expand All @@ -34,6 +35,12 @@ class EuphonicSingleCrystalResultsModel(ResultsModel):
temperature = tl.Float(0)
weighting = tl.Unicode("coherent")
custom_kpath = tl.Unicode("")

def fetch_data(self):
"""Fetch the data from the database."""
# 1. from aiida, so we have the node
# 2. from uploaded files...
pass

def set_model_state(self, parameters: dict):
self.q_spacing = parameters.get("q_spacing", 0.01)
Expand Down
57 changes: 54 additions & 3 deletions src/aiidalab_qe_vibroscopy/utils/euphonic/Detached_app.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,56 @@
"execution_count": 2,
"id": "a8549863",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a2abe40204ac4a478c99cb6f8ba683b4",
"version_major": 2,
"version_minor": 0
},
"text/plain": []
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"<div style=\"background-color: #f7f7f7; border: 2px solid #e0e0e0; padding: 20px; border-radius: 5px;\">\n",
" <p style=\"font-size: 16px; font-weight: bold; color: #ff5733;\">Warning:</p>\n",
" <p style=\"font-size: 14px;\">The default profile '<span style=\"font-style: italic;\">default</span>' was loaded automatically. This behavior will be removed in the <span style=\"font-style: italic;\">v3.0.0</span>. Please load the profile manually before loading modules from aiidalab-widgets-base by adding the following code at the beginning cell of the notebook:</p>\n",
" <pre style=\"background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; font-family: 'Courier New', monospace;\">\n",
"from aiida import load_profile\n",
"load_profile();</pre>\n",
"</div>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" var style = document.createElement('style');\n",
" style.type = 'text/css';\n",
" style.innerHTML = ``;\n",
" document.head.appendChild(style);\n",
" "
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Fix pybel import path\n",
"try:\n",
Expand Down Expand Up @@ -64,7 +113,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5230d58511154ade9207b38bd0fa35a6",
"model_id": "aec117638bca4fb998fcec2ce07f9d0d",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -86,7 +135,9 @@
" '<p style=\"text-align:right;\">Copyright (c) 2024 Miki Bonacci (PSI), [email protected]; &#8195Version: 0.1.1</p>'\n",
")\n",
"\n",
"widget = EuphonicSuperWidget(mode=\"detached\")\n",
"from aiidalab_qe_vibroscopy.app.widgets.euphonicmodel import EuphonicBaseResultsModel\n",
"\n",
"widget = EuphonicSuperWidget(mode=\"detached\", model=EuphonicBaseResultsModel())\n",
"\n",
"output = ipw.Output()\n",
"\n",
Expand Down
52 changes: 25 additions & 27 deletions src/aiidalab_qe_vibroscopy/utils/euphonic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .euphonic_powder_widgets import PowderFullWidget
from .euphonic_q_planes_widgets import QSectionFullWidget

from aiidalab_qe_vibroscopy.app.widgets.euphonicmodel import EuphonicSingleCrystalResultsModel
from aiidalab_qe_vibroscopy.app.widgets.euphonicmodel import EuphonicBaseResultsModel

###### START for detached app:

Expand Down Expand Up @@ -140,7 +140,7 @@ class EuphonicSuperWidget(ipw.VBox):
In between, we trigger the initialization of plots via a button.
"""

def __init__(self, mode="aiidalab-qe app plugin", model=None, fc=None, q_path=None):
def __init__(self, mode='aiidalab-qe app plugin', model=None, fc=None, q_path=None):
"""
Initialize the Euphonic utility class.
Parameters:
Expand All @@ -167,26 +167,26 @@ def __init__(self, mode="aiidalab-qe app plugin", model=None, fc=None, q_path=No
fc : optional
Force constants if provided.
"""

self._model = EuphonicSingleCrystalResultsModel()

self.mode = mode

self._model = model # this is the single crystal model.

self.upload_widget = UploadPhonopyWidget()
self.upload_widget.reset_uploads.on_click(self._on_reset_uploads_button_clicked)
self.fc_hdf5_content = None
self._model.fc_hdf5_content = None

self.tab_widget = ipw.Tab()
self.tab_widget.layout.display = "none"
self.tab_widget.set_title(0, "Single crystal")
self.tab_widget.set_title(1, "Powder sample")
self.tab_widget.set_title(2, "Q-plane view")
#self.tab_widget.set_title(1, "Powder sample")
#self.tab_widget.set_title(2, "Q-plane view")
self.tab_widget.children = ()

if fc:
self.fc = fc
self._model.fc = fc

self.q_path = q_path
self._model.q_path = q_path

self.plot_button = ipw.Button(
description="Initialise INS data",
Expand All @@ -197,7 +197,7 @@ def __init__(self, mode="aiidalab-qe app plugin", model=None, fc=None, q_path=No
)
self.plot_button.on_click(self._on_first_plot_button_clicked)

self.loading_widget = ipw.HTML(
self.loading_widget = ipw.HTML( # use the loading widget!
value=spinner_html,
)
self.loading_widget.layout.display = "none"
Expand Down Expand Up @@ -237,7 +237,7 @@ def _on_upload_yaml(self, change):
0
].value.keys(): # always one key because I allow only one file at the time.
self.fname = fname
self.phonopy_yaml_content = self.upload_widget.children[0].value[fname][
self._model.phonopy_yaml_content = self.upload_widget.children[0].value[fname][
"content"
]

Expand All @@ -247,49 +247,47 @@ def _on_upload_yaml(self, change):
def _on_upload_hdf5(self, change):
if change["new"] != change["old"]:
for fname in self.upload_widget.children[1].value.keys():
self.fc_hdf5_content = self.upload_widget.children[1].value[fname][
self._model.fc_hdf5_content = self.upload_widget.children[1].value[fname][
"content"
]

def _generate_force_constants(
def _generate_force_constants( #needs to go in the model
self,
):
if self.mode == "aiidalab-qe app plugin":
return self.fc
return self.fc # we should not check mode, but node, when we put this in the model.

else:
fc = self.upload_widget._read_phonopy_files(
fname=self.fname,
phonopy_yaml_content=self.phonopy_yaml_content,
fc_hdf5_content=self.fc_hdf5_content,
phonopy_yaml_content=self._model.phonopy_yaml_content,
fc_hdf5_content=self._model.fc_hdf5_content,
)

return fc

def _on_first_plot_button_clicked(self, change=None): # basically the render.
# It creates the widgets
self.plot_button.layout.display = "none"

self.loading_widget.layout.display = "block"

self.fc = self._generate_force_constants() # should be in the model.
self._model.fc = self._generate_force_constants() # should be in the model.

# I first initialise this widget, to then have the 0K ref for the other two.
singlecrystalmodel.fc = self.fc
singlecrystalwidget = SingleCrystalFullWidget(model=singlecrystalmodel)
# the model is passed to the widget. For the other two, I need to generate the model.
singlecrystalwidget = SingleCrystalFullWidget(model=self._model)

self.tab_widget.children = (
singlecrystalwidget,
PowderFullWidget(
self.fc, intensity_ref_0K=singlecrystalwidget.intensity_ref_0K
),
QSectionFullWidget(
self.fc, intensity_ref_0K=singlecrystalwidget.intensity_ref_0K
),
#PowderFullWidget(
# self.fc, intensity_ref_0K=singlecrystalwidget.intensity_ref_0K
#),
#QSectionFullWidget(
# self.fc, intensity_ref_0K=singlecrystalwidget.intensity_ref_0K
#),
)

self.loading_widget.layout.display = "none"

self.tab_widget.layout.display = "block"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def __init__(self, model, **kwargs):

# should be rendered, not done here!
# and moreover, should be done in the model.
self._model.produce_bands_weigthed_data()
self._model._update_spectra()

self.title_intensity = ipw.HTML(
"<h3>Neutron dynamic structure factor - Single Crystal</h3>"
Expand Down

0 comments on commit ab69f31

Please sign in to comment.