Skip to content

Commit

Permalink
Fixing single crystal and qplanes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikibonacci committed Dec 9, 2024
1 parent 3787eb0 commit 0b339d0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 58 deletions.
63 changes: 34 additions & 29 deletions src/aiidalab_qe_vibroscopy/app/widgets/euphonicmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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.
Expand Down
48 changes: 19 additions & 29 deletions src/aiidalab_qe_vibroscopy/app/widgets/structurefactorwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)",
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit 0b339d0

Please sign in to comment.