Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

including weas_widget for modes animation #99

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.12",
]

[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
73 changes: 40 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,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

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