33from pathlib import Path
44from tempfile import NamedTemporaryFile
55
6- from aiida .orm import Node , SinglefileData , StructureData
6+ from aiida .orm import Node , SinglefileData , StructureData , TrajectoryData
77from ase import Atoms
88from ase import io as ase_io
99from ipywidgets import HTML , VBox
@@ -25,6 +25,8 @@ def __init__(self, node: Node | None = None, **kwargs):
2525 self .assign_structure_from_structuredata (node )
2626 elif isinstance (node , SinglefileData ):
2727 self .assign_structure_from_file (node .filename , node .content )
28+ elif isinstance (node , TrajectoryData ):
29+ self .assign_structure_from_trajectorydata (node )
2830 elif node :
2931 self .message .value = (
3032 "<p>AiiDA Node type not supported by the structure viewer."
@@ -61,13 +63,13 @@ def assign_structure_from_file(self, fname: str, content: bytes) -> None:
6163 ]
6264 return
6365
64- def assign_structure_from_ase (self , structure : Atoms ) -> None :
66+ def assign_structure_from_ase (self , structure : Atoms | list [ Atoms ] ) -> None :
6567 """Visualise the given ASE structure.
6668
6769 Parameters
6870 ----------
69- structure: Atoms
70- The ASE atoms structure object.
71+ structure: Atoms | list[Atoms]
72+ The ASE atoms structure(s) object.
7173 """
7274 self .viewer = WeasWidget ()
7375 self .viewer .from_ase (structure )
@@ -86,3 +88,22 @@ def assign_structure_from_structuredata(self, structure: StructureData) -> None:
8688 """
8789 self .assign_structure_from_ase (structure ._get_object_ase ())
8890 return
91+
92+ def assign_structure_from_trajectorydata (self , trajectory : TrajectoryData ) -> None :
93+ """
94+ Visualise a series of structures contained in an AiiDA TrajectoryData node.
95+
96+ Parameters
97+ ----------
98+ trajectory: TrajectoryData
99+ The AiiDA TrajectoryData node containing the structure series to visualise.
100+ """
101+ symbols = trajectory .symbols
102+ positions = trajectory .get_positions ()
103+ nsteps = trajectory .numsteps
104+ atoms = []
105+ for i in range (nsteps ):
106+ step = Atoms (symbols = symbols , positions = positions [i ])
107+ atoms .append (step )
108+ self .assign_structure_from_ase (atoms )
109+ return
0 commit comments