From 0b339d09a1b1f2ff907404e1338078f43705aa79 Mon Sep 17 00:00:00 2001 From: mikibonacci Date: Mon, 9 Dec 2024 19:15:43 +0000 Subject: [PATCH] Fixing single crystal and qplanes --- .../app/widgets/euphonicmodel.py | 63 ++++++++++--------- .../app/widgets/structurefactorwidget.py | 48 ++++++-------- 2 files changed, 53 insertions(+), 58 deletions(-) diff --git a/src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py b/src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py index 761f355..710c697 100644 --- a/src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py +++ b/src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py @@ -163,30 +163,28 @@ def get_spectra( if self.spectrum_type == "q_planes": self._get_qsection_spectra() - return - - self.parameters.update(self.get_model_state()) - - # custom linear path - custom_kpath = self.custom_kpath if hasattr(self, "custom_kpath") else "" - if len(custom_kpath) > 1: - coordinates, labels = self._curate_path_and_labels() - qpath = { - "coordinates": coordinates, - "labels": labels, # ["$\Gamma$","X","X","(1,1,1)"], - "delta_q": self.parameters["q_spacing"], - } else: - qpath = copy.deepcopy(self.q_path) - if qpath: - qpath["delta_q"] = self.parameters["q_spacing"] - - spectra, parameters = self._callback_spectra_generation( - params=AttrDict(self.parameters), - fc=self.fc, - linear_path=qpath, - plot=False, - ) + self.parameters.update(self.get_model_state()) + # custom linear path + custom_kpath = self.custom_kpath if hasattr(self, "custom_kpath") else "" + if len(custom_kpath) > 1: + coordinates, labels = self._curate_path_and_labels() + qpath = { + "coordinates": coordinates, + "labels": labels, # ["$\Gamma$","X","X","(1,1,1)"], + "delta_q": self.parameters["q_spacing"], + } + else: + qpath = copy.deepcopy(self.q_path) + if qpath: + qpath["delta_q"] = self.parameters["q_spacing"] + + spectra, parameters = self._callback_spectra_generation( + params=AttrDict(self.parameters), + fc=self.fc, + linear_path=qpath, + plot=False, + ) # curated spectra (labels and so on...) if self.spectrum_type == "single_crystal": # single crystal case @@ -196,15 +194,19 @@ def get_spectra( ( final_xspectra, final_zspectra, - self.ticks_positions, - self.ticks_labels, + ticks_positions, + ticks_labels, ) = generated_curated_data(spectra) + self.ticks_positions = ticks_positions + self.ticks_labels = ticks_labels + self.z = final_zspectra.T self.y = self.y[:, 0] - # self.x = None # we have, instead, the ticks positions and labels + self.x = list( + range(self.ticks_positions[-1]) + ) # we have, instead, the ticks positions and labels - self.xlabel = "" self.ylabel = self.energy_units elif self.spectrum_type == "powder": # powder case @@ -215,9 +217,12 @@ def get_spectra( # we don't need to curate the powder data, at variance with the single crystal case. # We can directly use them: + self.xlabel = "|q| (1/A)" self.x = spectra.x_data.magnitude self.y = self.y[:, 0] self.z = spectra.z_data.magnitude.T + elif self.spectrum_type == "q_planes": + pass else: raise ValueError("Spectrum type not recognized:", self.spectrum_type) @@ -268,8 +273,8 @@ def _get_qsection_spectra( dw=dw, labels=labels, ) - self.xlabel = "AAA" - self.ylabel = "AAA" + self.xlabel = self.labels["h"] + self.ylabel = self.labels["k"] def energy_conversion_factor(self, new, old): # TODO: check this is correct. diff --git a/src/aiidalab_qe_vibroscopy/app/widgets/structurefactorwidget.py b/src/aiidalab_qe_vibroscopy/app/widgets/structurefactorwidget.py index c04ec61..acdfce5 100644 --- a/src/aiidalab_qe_vibroscopy/app/widgets/structurefactorwidget.py +++ b/src/aiidalab_qe_vibroscopy/app/widgets/structurefactorwidget.py @@ -83,7 +83,6 @@ def render(self): (self._model, "energy_units"), ) E_units_ddown.observe(self._update_energy_units, "value") - # MAYBE WE LINK ALSO THIS TO THE MODEL? so we can download the data with the preferred units. q_spacing = ipw.FloatText( value=self._model.q_spacing, @@ -276,6 +275,9 @@ def render(self): # fi self._model.spectrum_type == "powder" elif self._model.spectrum_type == "q_planes": + E_units_ddown.layout.display = "none" + q_spacing.layout.display = "none" + self.ecenter = ipw.FloatText( value=0, description="E (meV)", @@ -343,24 +345,12 @@ def render(self): [ipw.HTML("k: ", layout={"width": "20px"}), self.k_vec] ) - self.energy_broadening = ipw.FloatText( - value=0.5, - description="ΔE (meV)", - tooltip="Energy window in eV", - ) - ipw.link( - (self._model, "energy_broadening"), - (self.energy_broadening, "value"), - ) - self.energy_broadening.observe(self._on_setting_change, names="value") - self.children += ( self.ecenter, self.plane_description_widget, self.Q0_widget, self.h_widget, self.k_widget, - self.energy_broadening, ) # fi self._model.spectrum_type == "q_planes" @@ -388,25 +378,15 @@ def _on_setting_change( def _update_plot(self, _=None): # update the spectra, i.e. the data contained in the _model. - # TODO: we need to treat differently the update of intensity and units. - # they anyway need to modify the data, but no additional spectra re-generation is really needed. - # so the update_spectra need some more logic, or we call another method. + self._model.get_spectra() - if self._model.spectrum_type == "q_planes" and not self.rendered: + if self._model.spectrum_type == "q_planes": # hide figure until we have the data - self.figure_container.layout.display = "none" - - if self._model.spectrum_type == "q_planes" and self.rendered: - self.figure_container.layout.display = "block" - - heatmap_trace = go.Heatmap( - z=self._model.z, - y=(self._model.y), - x=self._model.x, - colorbar=COLORBAR_DICT, - colorscale=COLORSCALE, # imported from euphonic_base_widgets - ) + self.figure_container.layout.display = ( + "none" if not self.rendered else "block" + ) + self.plot_button.disabled = self.rendered self.fig.update_layout(yaxis_title=self._model.ylabel) @@ -421,6 +401,16 @@ def _update_plot(self, _=None): ticktext=self._model.ticks_labels, ) ) + elif hasattr(self._model, "xlabel"): + self.fig.update_layout(xaxis_title=self._model.xlabel) + + heatmap_trace = go.Heatmap( + z=self._model.z, + y=self._model.y, + x=self._model.x, + colorbar=COLORBAR_DICT, + colorscale=COLORSCALE, + ) # Add colorbar colorbar = heatmap_trace.colorbar