From ab69f318ea806230e2d7de29e162dd55bbe51a89 Mon Sep 17 00:00:00 2001 From: Miki Bonacci Date: Mon, 2 Dec 2024 20:14:54 +0000 Subject: [PATCH] Adding model modifications. --- src/aiidalab_qe_vibroscopy/app/__init__.py | 6 -- .../app/widgets/euphonicmodel.py | 9 ++- .../utils/euphonic/Detached_app.ipynb | 57 ++++++++++++++++++- .../utils/euphonic/__init__.py | 52 ++++++++--------- .../euphonic_single_crystal_widgets.py | 2 +- 5 files changed, 88 insertions(+), 38 deletions(-) diff --git a/src/aiidalab_qe_vibroscopy/app/__init__.py b/src/aiidalab_qe_vibroscopy/app/__init__.py index 361de09..e77ed16 100644 --- a/src/aiidalab_qe_vibroscopy/app/__init__.py +++ b/src/aiidalab_qe_vibroscopy/app/__init__.py @@ -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 @@ -26,9 +24,5 @@ class VibroPluginOutline(PluginOutline): "panel": VibroResourcesSettingsPanel, "model": VibroResourceSettingsModel, }, - "result": { - "panel": VibroResultsPanel, - "model": VibroResultsModel, - }, "workchain": workchain_and_builder, } diff --git a/src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py b/src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py index 2fd57b2..014fad4 100644 --- a/src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py +++ b/src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py @@ -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 @@ -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) @@ -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) diff --git a/src/aiidalab_qe_vibroscopy/utils/euphonic/Detached_app.ipynb b/src/aiidalab_qe_vibroscopy/utils/euphonic/Detached_app.ipynb index c3485a7..e66b899 100644 --- a/src/aiidalab_qe_vibroscopy/utils/euphonic/Detached_app.ipynb +++ b/src/aiidalab_qe_vibroscopy/utils/euphonic/Detached_app.ipynb @@ -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", + "
\n", + "

Warning:

\n", + "

The default profile 'default' was loaded automatically. This behavior will be removed in the v3.0.0. Please load the profile manually before loading modules from aiidalab-widgets-base by adding the following code at the beginning cell of the notebook:

\n", + "
\n",
+       "from aiida import load_profile\n",
+       "load_profile();
\n", + "
\n" + ], + "text/plain": [ + "" + ] + }, + "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": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "# Fix pybel import path\n", "try:\n", @@ -64,7 +113,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "5230d58511154ade9207b38bd0fa35a6", + "model_id": "aec117638bca4fb998fcec2ce07f9d0d", "version_major": 2, "version_minor": 0 }, @@ -86,7 +135,9 @@ " '

Copyright (c) 2024 Miki Bonacci (PSI), miki.bonacci@psi.ch;  Version: 0.1.1

'\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", diff --git a/src/aiidalab_qe_vibroscopy/utils/euphonic/__init__.py b/src/aiidalab_qe_vibroscopy/utils/euphonic/__init__.py index 5d81d72..9b41707 100644 --- a/src/aiidalab_qe_vibroscopy/utils/euphonic/__init__.py +++ b/src/aiidalab_qe_vibroscopy/utils/euphonic/__init__.py @@ -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: @@ -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: @@ -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", @@ -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" @@ -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" ] @@ -247,21 +247,21 @@ 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 @@ -269,27 +269,25 @@ def _generate_force_constants( 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" diff --git a/src/aiidalab_qe_vibroscopy/utils/euphonic/euphonic_single_crystal_widgets.py b/src/aiidalab_qe_vibroscopy/utils/euphonic/euphonic_single_crystal_widgets.py index f5e17a0..206e8af 100644 --- a/src/aiidalab_qe_vibroscopy/utils/euphonic/euphonic_single_crystal_widgets.py +++ b/src/aiidalab_qe_vibroscopy/utils/euphonic/euphonic_single_crystal_widgets.py @@ -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( "

Neutron dynamic structure factor - Single Crystal

"