diff --git a/src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py b/src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py index 13fccc5..761f355 100644 --- a/src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py +++ b/src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py @@ -66,7 +66,7 @@ def __init__(self, node=None, spectrum_type: str = "single_crystal", **kwargs): self.q_path = None self.spectrum_type = spectrum_type self.xlabel = None - self.ylabel = "Energy (meV)" + self.ylabel = self.energy_units self.detached_app = False if node: self.vibro = node @@ -201,13 +201,11 @@ def get_spectra( ) = generated_curated_data(spectra) self.z = final_zspectra.T - self.y = self.y[:, 0] * self.energy_conversion_factor( - self.energy_units, "meV" - ) + self.y = self.y[:, 0] # self.x = None # we have, instead, the ticks positions and labels self.xlabel = "" - self.ylabel = f"Energy ({self.energy_units})" + self.ylabel = self.energy_units elif self.spectrum_type == "powder": # powder case # Spectrum2D as output of the powder data @@ -218,13 +216,13 @@ 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.x = spectra.x_data.magnitude - self.y = self.y[:, 0] * self.energy_conversion_factor( - self.energy_units, "meV" - ) + self.y = self.y[:, 0] self.z = spectra.z_data.magnitude.T else: raise ValueError("Spectrum type not recognized:", self.spectrum_type) + self.y = self.y * self.energy_conversion_factor(self.energy_units, "meV") + def _get_qsection_spectra( self, ): @@ -280,14 +278,14 @@ def energy_conversion_factor(self, new, old): if new == "meV": if old == "THz": return self.THz_to_meV - elif old == "cm-1": - return self.THz_to_meV * self.THz_to_cm1 + elif old == "1/cm": + return 1 / self.THz_to_cm1 * self.THz_to_meV elif new == "THz": if old == "meV": return 1 / self.THz_to_meV - elif old == "cm-1": + elif old == "1/cm": return 1 / self.THz_to_cm1 - elif new == "cm-1": + elif new == "1/cm": if old == "meV": return 1 / self.THz_to_meV * self.THz_to_cm1 elif old == "THz": @@ -296,7 +294,7 @@ def energy_conversion_factor(self, new, old): def _update_energy_units(self, new, old): # This is used to update the energy units in the plot. self.y = self.y * self.energy_conversion_factor(new, old) - self.ylabel = f"Energy ({new})" + self.ylabel = self.energy_units def _curate_path_and_labels( self, diff --git a/src/aiidalab_qe_vibroscopy/app/widgets/structurefactorwidget.py b/src/aiidalab_qe_vibroscopy/app/widgets/structurefactorwidget.py index dc60ebf..c04ec61 100644 --- a/src/aiidalab_qe_vibroscopy/app/widgets/structurefactorwidget.py +++ b/src/aiidalab_qe_vibroscopy/app/widgets/structurefactorwidget.py @@ -65,11 +65,11 @@ def render(self): "(Intensity is relative to the maximum intensity at T=0K)" ) - E_units_button = ipw.ToggleButtons( + E_units_ddown = ipw.Dropdown( options=[ ("meV", "meV"), ("THz", "THz"), - ("cm-1", "cm-1"), + ("1/cm", "1/cm"), ], value="meV", description="Energy units:", @@ -79,10 +79,10 @@ def render(self): ), ) ipw.link( - (E_units_button, "value"), + (E_units_ddown, "value"), (self._model, "energy_units"), ) - E_units_button.observe(self._update_energy_units, "value") + 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( @@ -191,7 +191,7 @@ def render(self): margin="10px 0", ), ), - E_units_button, + E_units_ddown, q_spacing, energy_broadening, energy_bins, @@ -408,6 +408,8 @@ def _update_plot(self, _=None): colorscale=COLORSCALE, # imported from euphonic_base_widgets ) + self.fig.update_layout(yaxis_title=self._model.ylabel) + # change the path wants also a change in the labels if hasattr(self._model, "ticks_positions") and hasattr( self._model, "ticks_labels" @@ -454,11 +456,6 @@ def _update_energy_units(self, change): self.fig.data[0].y = self._model.y self.fig.update_layout(yaxis_title=self._model.ylabel) - self.fig.update_xaxes(autorange=True) - self.fig.update_yaxes(autorange=True) - - # Update the layout to enable autoscaling - self.fig.update_layout(autosize=True) def _reset_settings(self, _): self._model.reset()