diff --git a/pyproject.toml b/pyproject.toml index b576f90..9e1b5d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,6 +25,7 @@ dependencies = [ "pre-commit", "euphonic", "kaleido", + "weas-widget==0.1.12", ] [tool.ruff.lint] diff --git a/src/aiidalab_qe_vibroscopy/app/result.py b/src/aiidalab_qe_vibroscopy/app/result.py index 30dae04..4b1d19e 100644 --- a/src/aiidalab_qe_vibroscopy/app/result.py +++ b/src/aiidalab_qe_vibroscopy/app/result.py @@ -72,9 +72,13 @@ class Result(ResultPanel): """ title = "Vibrational Structure" - workchain_label = "iraman" + workchain_label = "vibro" children_result_widget = () + def __init__(self, node=None, **kwargs): + super().__init__(node=node, identifier="vibro", **kwargs) + self._update_view() + def _update_view(self): children_result_widget = () tab_titles = [] # this is needed to name the sub panels diff --git a/src/aiidalab_qe_vibroscopy/utils/raman/result.py b/src/aiidalab_qe_vibroscopy/utils/raman/result.py index 029eaf2..832de02 100644 --- a/src/aiidalab_qe_vibroscopy/utils/raman/result.py +++ b/src/aiidalab_qe_vibroscopy/utils/raman/result.py @@ -8,9 +8,8 @@ from IPython.display import HTML, clear_output, display import base64 import json -import nglview as nv -from ase import Atoms +from weas_widget import WeasWidget from aiida_vibroscopy.utils.broadenings import multilorentz @@ -373,6 +372,20 @@ def __init__(self, node, output_node, spectrum_type, **kwargs): self.output_node = output_node self.spectrum_type = spectrum_type + # WeasWidget configuration + self.guiConfig = { + "enabled": True, + "components": { + "atomsControl": True, + "buttons": True, + "cameraControls": True, + }, + "buttons": { + "fullscreen": True, + "download": True, + "measurement": True, + }, + } # VibrationalData vibrational_data = self.output_node.vibrational_data self.vibro = ( @@ -391,8 +404,6 @@ def __init__(self, node, output_node, spectrum_type, **kwargs): # StructureData self.structure_ase = self.node.inputs.structure.get_ase() - self.ngl = nv.NGLWidget() - modes_values = [ f"{index + 1}: {value}" for index, value in enumerate(self.rounded_frequencies) @@ -494,7 +505,7 @@ def _select_active_mode(self, change): self._animation_widget() with self.animation: clear_output() - display(self.ngl) + display(self.weas) def _animation_widget(self): """Create animation widget.""" @@ -507,31 +518,27 @@ def _animation_widget(self): amplitude = self.amplitude.value # Get the structure of the selected mode structure = self.structure_ase - # Create a trajectory - traj = [] - time_array = np.linspace(0.0, 2 * np.pi, 20) - for time in time_array: - vibro_atoms = Atoms( - symbols=structure.symbols, - positions=structure.positions + amplitude * eigenvector * np.sin(time), - cell=structure.cell, - pbc=True, - ) - supercell = vibro_atoms.repeat( - ( - self._supercell[0].value, - self._supercell[1].value, - self._supercell[2].value, - ) - ) - traj.append(supercell) - # Create the animation widget - self.ngl.clear() - self.ngl = nv.show_asetraj(traj) - self.ngl.add_unitcell() - # Make the animation to be set in a loop - self.ngl._iplayer.children[0]._playing = False - self.ngl._iplayer.children[0]._playing = True - self.ngl._iplayer.children[0]._repeat = True - self.ngl._set_size("400px", "400px") - self.ngl.center() + + self.weas = WeasWidget(guiConfig=self.guiConfig) + self.weas.from_ase(structure) + + phonon_setting = { + "eigenvectors": np.array( + [[[real_part, 0] for real_part in row] for row in eigenvector] + ), + "kpoint": [0, 0, 0], # optional + "amplitude": amplitude, + "nframes": 20, + "repeat": [ + self._supercell[0].value, + self._supercell[1].value, + self._supercell[2].value, + ], + "color": "black", + "radius": 0.1, + } + self.weas.avr.phonon_setting = phonon_setting + + self.weas.avr.model_style = 1 + self.weas.avr.color_type = "JMOL" + self.weas.avr.vf.show = True