Add deserializer for TrajectoryData and Trajectory data class#63
Add deserializer for TrajectoryData and Trajectory data class#63ElliottKasoar wants to merge 4 commits intoaiidateam:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #63 +/- ##
==========================================
+ Coverage 90.14% 90.26% +0.11%
==========================================
Files 22 22
Lines 1228 1263 +35
==========================================
+ Hits 1107 1140 +33
- Misses 121 123 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
superstar54
left a comment
There was a problem hiding this comment.
Hi @ElliottKasoar , thanks for the work. This is indeed important for the community.
I have one suggestion. In pythonjob, we keep one raw Python class <–-> one Data node. In this PR, I only see a Trajectory class that inherits the AiiDA Data class. So I think you still need to add a raw Python class to represent a list of Atoms, e.g.,
from typing import Iterable
from ase import Atoms
class AtomsTrajectory(list):
"""List of ASE Atoms representing a trajectory."""
def __init__(self, frames: Iterable[Atoms] = ()):
super().__init__(frames)
def append(self, item: Atoms) -> None:
if not isinstance(item, Atoms):
raise TypeError(f'AtomsTrajectory only accepts ase.Atoms, got {type(item)}')
super().append(item)
def extend(self, items: Iterable[Atoms]) -> None:
for item in items:
self.append(item)The name Trajectory is too broad, and may be confused with the TrjaeoctryData from aiida-core. So I suggest using AtomsTrajectoryData. So in the entry point, we write this:
[project.entry-points."aiida.data"]
"pythonjob.ase.trajectory.AtomsTrajectory": "aiida_pythonjob.data.trajectory:AtomsTrajectoryData"
Here is an example of using it.
@task
def make_supercell(trajectory: AtomsTrajectory):
return AtomsTrajectory([atoms*[2, 2, 2] for atoms in trajectory])
| data = Trajectory([Atoms("C"), Atoms("C")]) | ||
| serialized_data = general_serializer(data, serializers=all_serializers) | ||
| assert isinstance(serialized_data, Trajectory) |
There was a problem hiding this comment.
I am confused on this part. The input data is Trajectory, and then it is serialized to a Trajectory again?
As discussed in aiidateam/aiida-workgraph#735, adds deserializer for
TrajectoryData, allowing this to be passed to atask.Also adds a
Trajectorydata class, which allows a list of Atoms to be returned. For example:Of these
wg.inputs.x, everything apart from the raw list of ASE Atoms (traj) can be successfully input and output from the task.I've tried to add tests for these, but couldn't find a way to test the serialisation of the StructureData and TrajectoryData, as these seem to shortcut to just returning the same data: https://github.com/aiidateam/aiida-pythonjob/blob/main/src/aiida_pythonjob/data/serializer.py#L115