Skip to content

Commit

Permalink
For INS in low dimensional systems, parsing the band path from the Wo…
Browse files Browse the repository at this point in the history
…rkChain inputs

This fix #69
  • Loading branch information
mikibonacci committed Sep 20, 2024
1 parent 24bafec commit dfb735f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/aiidalab_qe_vibroscopy/app/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _update_view(self):
) # the comma is required! otherwise the tuple is not detected.
# euphonic
if ins_data:
intensity_maps = EuphonicSuperWidget(fc=ins_data["fc"])
intensity_maps = EuphonicSuperWidget(fc=ins_data["fc"], q_path=ins_data["q_path"])
children_result_widget += (intensity_maps,)
tab_titles.append("Inelastic Neutrons")

Expand Down
33 changes: 31 additions & 2 deletions src/aiidalab_qe_vibroscopy/utils/euphonic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,34 @@ class EuphonicSuperWidget(ipw.VBox):
In between, we trigger the initialization of plots via a button.
"""

def __init__(self, mode="aiidalab-qe app plugin", fc=None):
def __init__(self, mode="aiidalab-qe app plugin", fc=None, q_path=None):
"""
Initialize the Euphonic utility class.
Parameters:
-----------
mode : str, optional
The mode of operation, default is "aiidalab-qe app plugin".
fc : optional
Force constants, default is None.
q_path : optional
Q-path for phonon calculations, default is None. If Low-D system, this can be provided.
It is the same path obtained for the PhonopyCalculation of the phonopy_bands.
Attributes:
-----------
mode : str
The mode of operation.
upload_widget : UploadPhonopyWidget
Widget for uploading phonopy files.
fc_hdf5_content : None
Content of the force constants HDF5 file.
tab_widget : ipw.Tab
Tab widget for different views.
plot_button : ipw.Button
Button to initialize INS data.
fc : optional
Force constants if provided.
"""

self.mode = mode

self.upload_widget = UploadPhonopyWidget()
Expand All @@ -127,6 +154,8 @@ def __init__(self, mode="aiidalab-qe app plugin", fc=None):

if fc:
self.fc = fc

self.q_path = q_path

self.plot_button = ipw.Button(
description="Initialise INS data",
Expand Down Expand Up @@ -206,7 +235,7 @@ def _on_first_plot_button_clicked(self, change=None):
self.fc = self._generate_force_constants()

# I first initialise this widget, to then have the 0K ref for the other two.
singlecrystalwidget = SingleCrystalFullWidget(self.fc)
singlecrystalwidget = SingleCrystalFullWidget(self.fc, self.q_path)

self.tab_widget.children = (
singlecrystalwidget,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from IPython.display import display

import numpy as np
import copy
import ipywidgets as ipw
import plotly.graph_objects as go
import plotly.io as pio
Expand Down Expand Up @@ -196,11 +197,13 @@ class SingleCrystalFullWidget(ipw.VBox):
and are from Sears (1992) Neutron News 3(3) pp26--37.
"""

def __init__(self, fc, **kwargs):
def __init__(self, fc, q_path, **kwargs):
self.fc = fc
self.q_path = q_path

self.spectra, self.parameters = produce_bands_weigthed_data(
fc=self.fc,
linear_path = self.q_path,
plot=False, # CHANGED
)

Expand Down Expand Up @@ -248,7 +251,8 @@ def _on_plot_button_clicked(self, change=None):
"delta_q": parameters_["q_spacing"],
}
else:
linear_path = None
linear_path = copy.deepcopy(self.q_path)
linear_path["delta_q"] = parameters_["q_spacing"]

self.spectra, self.parameters = produce_bands_weigthed_data(
params=parameters_,
Expand Down
21 changes: 19 additions & 2 deletions src/aiidalab_qe_vibroscopy/utils/euphonic/intensity_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def join_q_paths(coordinates: list, labels: list, delta_q=0.1, G=[0, 0, 0]):
def produce_bands_weigthed_data(
params: Optional[List[str]] = parameters,
fc: ForceConstants = None,
linear_path=None,
linear_path = None,
plot=False,
) -> None:
blockPrint()
Expand Down Expand Up @@ -752,13 +752,30 @@ def export_euphonic_data(node, fermi_energy=None):
return None

output_set = node.outputs.vibronic.phonon_bands


if any(not element for element in node.inputs.structure.pbc):
vibro_bands = node.inputs.vibronic.phonopy_bands_dict.get_dict()
# Group the band and band_labels
band = vibro_bands['band']
band_labels = vibro_bands['band_labels']

grouped_bands = [item for sublist in [band_labels[i:i+2] for i in range(len(band_labels)-1)] for item in sublist]
grouped_q = [[tuple(band[i:i+3]), tuple(band[i+3:i+6])] for i in range(0, len(band)-3,3)]
q_path = {
"coordinates":grouped_q,
"labels":grouped_bands,
"delta_q":0.01, #1/A
}
else:
q_path = None

phonopy_calc = output_set.creator
fc = generate_force_constant_instance(phonopy_calc)
# bands = compute_bands(fc)
# pdos = compute_pdos(fc)
return {
"fc": fc,
"q_path": q_path,
} # "bands": bands, "pdos": pdos, "thermal": None}


Expand Down

0 comments on commit dfb735f

Please sign in to comment.