Skip to content

Commit

Permalink
including weas_widget for modes animation
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresOrtegaGuerrero committed Oct 10, 2024
1 parent ff40d39 commit 57e57a8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies = [
"pre-commit",
"euphonic",
"kaleido",
"weas-widget==0.1.4",
]

[tool.ruff.lint]
Expand Down
6 changes: 5 additions & 1 deletion src/aiidalab_qe_vibroscopy/app/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 34 additions & 33 deletions src/aiidalab_qe_vibroscopy/utils/raman/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = (
Expand All @@ -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)
Expand Down Expand Up @@ -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."""
Expand All @@ -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

0 comments on commit 57e57a8

Please sign in to comment.