diff --git a/src/aiidalab_qe_vibroscopy/app/result.py b/src/aiidalab_qe_vibroscopy/app/result.py index 04ac1fa..af8acf2 100644 --- a/src/aiidalab_qe_vibroscopy/app/result.py +++ b/src/aiidalab_qe_vibroscopy/app/result.py @@ -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") diff --git a/src/aiidalab_qe_vibroscopy/utils/euphonic/__init__.py b/src/aiidalab_qe_vibroscopy/utils/euphonic/__init__.py index d169a46..59abff6 100644 --- a/src/aiidalab_qe_vibroscopy/utils/euphonic/__init__.py +++ b/src/aiidalab_qe_vibroscopy/utils/euphonic/__init__.py @@ -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() @@ -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", @@ -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, diff --git a/src/aiidalab_qe_vibroscopy/utils/euphonic/euphonic_single_crystal_widgets.py b/src/aiidalab_qe_vibroscopy/utils/euphonic/euphonic_single_crystal_widgets.py index 1437772..7e9ec26 100644 --- a/src/aiidalab_qe_vibroscopy/utils/euphonic/euphonic_single_crystal_widgets.py +++ b/src/aiidalab_qe_vibroscopy/utils/euphonic/euphonic_single_crystal_widgets.py @@ -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 @@ -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 ) @@ -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_, diff --git a/src/aiidalab_qe_vibroscopy/utils/euphonic/intensity_maps.py b/src/aiidalab_qe_vibroscopy/utils/euphonic/intensity_maps.py index 0bc1a0e..e2628db 100644 --- a/src/aiidalab_qe_vibroscopy/utils/euphonic/intensity_maps.py +++ b/src/aiidalab_qe_vibroscopy/utils/euphonic/intensity_maps.py @@ -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() @@ -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}