Skip to content

Commit

Permalink
fixing detached app and upload of files for INS.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikibonacci committed Jan 13, 2025
1 parent c9f7ef4 commit 4642444
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
18 changes: 13 additions & 5 deletions src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ class EuphonicResultsModel(Model):
THz_to_meV = 4.13566553853599 # conversion factor.
THz_to_cm1 = 33.3564095198155 # conversion factor.

def __init__(self, node=None, spectrum_type: str = "single_crystal", **kwargs):
def __init__(
self,
node=None,
spectrum_type: str = "single_crystal",
detached_app: bool = False,
**kwargs,
):
super().__init__(**kwargs)

self.spectra = {}
Expand All @@ -67,8 +73,8 @@ def __init__(self, node=None, spectrum_type: str = "single_crystal", **kwargs):
self.spectrum_type = spectrum_type
self.xlabel = None
self.ylabel = self.energy_units
self.detached_app = False
if node:
self.detached_app = detached_app
if node: # qe app mode.
self.vibro = node

if self.spectrum_type == "single_crystal":
Expand Down Expand Up @@ -114,10 +120,12 @@ def fetch_data(self):
self.q_path = ins_data["q_path"]
# 2. from uploaded files...
else:
# here we just use upload_widget as MVC all together, for simplicity.
# moreover, this part is not used in the current QE app.
self.fc = self.upload_widget._read_phonopy_files(
fname=self.fname,
phonopy_yaml_content=self._model.phonopy_yaml_content,
fc_hdf5_content=self._model.fc_hdf5_content,
phonopy_yaml_content=self.phonopy_yaml_content,
fc_hdf5_content=self.fc_hdf5_content,
)

def _inject_single_crystal_settings(
Expand Down
3 changes: 2 additions & 1 deletion src/aiidalab_qe_vibroscopy/app/widgets/euphonicwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def render(self):
)
self.upload_widget.children[0].observe(self._on_upload_yaml, "_counter")
self.upload_widget.children[1].observe(self._on_upload_hdf5, "_counter")
self._model.upload_widget = self.upload_widget
self.children += (self.upload_widget,)

self.download_widget = DownloadYamlHdf5Widget(model=self._model)
Expand Down Expand Up @@ -166,7 +167,7 @@ def _on_upload_yaml(self, change):
for fname in self.upload_widget.children[
0
].value.keys(): # always one key because I allow only one file at the time.
self.fname = fname
self._model.fname = fname
self._model.phonopy_yaml_content = self.upload_widget.children[0].value[
fname
]["content"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a2abe40204ac4a478c99cb6f8ba683b4",
"model_id": "152be27af20540b8aeeadd7fc2d2a462",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -100,8 +100,8 @@
"from IPython.display import display\n",
"from jinja2 import Environment\n",
"\n",
"from aiidalab_qe_vibroscopy.utils.euphonic import static\n",
"from aiidalab_qe_vibroscopy.utils.euphonic import EuphonicSuperWidget"
"from aiidalab_qe_vibroscopy.utils.euphonic.detached_app import static\n",
"from aiidalab_qe_vibroscopy.app.widgets.euphonicwidget import EuphonicWidget"
]
},
{
Expand All @@ -113,7 +113,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "aec117638bca4fb998fcec2ce07f9d0d",
"model_id": "a4b4d2771766495f95056deffcc53a2b",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -135,25 +135,21 @@
" '<p style=\"text-align:right;\">Copyright (c) 2024 Miki Bonacci (PSI), [email protected]; &#8195Version: 0.1.1</p>'\n",
")\n",
"\n",
"from aiidalab_qe_vibroscopy.app.widgets.euphonicmodel import EuphonicBaseResultsModel\n",
"from aiidalab_qe_vibroscopy.app.widgets.euphonicmodel import EuphonicResultsModel\n",
"\n",
"widget = EuphonicSuperWidget(mode=\"detached\", model=EuphonicBaseResultsModel())\n",
"widget = EuphonicWidget(\n",
" model=EuphonicResultsModel(detached_app=True), detached_app=True\n",
")\n",
"widget.render()\n",
"\n",
"output = ipw.Output()\n",
"\n",
"with output:\n",
" display(welcome_message, widget, footer)\n",
"\n",
"\n",
"display(output)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "22387f54",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def _on_upload_yaml(self, change):
for fname in self.upload_widget.children[
0
].value.keys(): # always one key because I allow only one file at the time.
self.fname = fname
self._model.fname = fname
self._model.phonopy_yaml_content = self.upload_widget.children[0].value[
fname
]["content"]
Expand Down

0 comments on commit 4642444

Please sign in to comment.