Skip to content

Commit

Permalink
Energy units, also cm-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mikibonacci committed Dec 9, 2024
1 parent 83f3400 commit 3787eb0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
24 changes: 11 additions & 13 deletions src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
):
Expand Down Expand Up @@ -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":
Expand All @@ -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,
Expand Down
17 changes: 7 additions & 10 deletions src/aiidalab_qe_vibroscopy/app/widgets/structurefactorwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<sup>-1</sup>", "cm-1"),
("1/cm", "1/cm"),
],
value="meV",
description="Energy units:",
Expand All @@ -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(
Expand Down Expand Up @@ -191,7 +191,7 @@ def render(self):
margin="10px 0",
),
),
E_units_button,
E_units_ddown,
q_spacing,
energy_broadening,
energy_bins,
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 3787eb0

Please sign in to comment.