diff --git a/pyproject.toml b/pyproject.toml index 0f6a9ed..5561513 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,6 +25,7 @@ dependencies = [ "pre-commit", "euphonic", "kaleido", + "weas-widget==0.1.4", ] [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..fd036e7 100644 --- a/src/aiidalab_qe_vibroscopy/utils/raman/result.py +++ b/src/aiidalab_qe_vibroscopy/utils/raman/result.py @@ -8,9 +8,9 @@ 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 weas_widget.utils import generate_phonon_trajectory from aiida_vibroscopy.utils.broadenings import multilorentz @@ -373,6 +373,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 +405,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 +506,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 +519,20 @@ 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() + + trajectory = generate_phonon_trajectory( + atoms=structure, + eigenvectors=eigenvector, + amplitude=amplitude, + repeat=[ + self._supercell[0].value, + self._supercell[1].value, + self._supercell[2].value, + ], + ) + self.weas = WeasWidget(guiConfig=self.guiConfig) + self.weas.from_ase(trajectory) + self.weas.avr.vf.settings = [ + {"origins": "positions", "vectors": "movement", "radius": 0.1} + ] + self.weas.avr.vf.show = True