Skip to content

Commit

Permalink
Assign frame properties to molecule/structure when indexing trajectory (
Browse files Browse the repository at this point in the history
#3979)

* fea: assign frame properties to molecule/structure when indexing trajectory.

* test: test that the frame properties are carried over when indexing a single frame
  • Loading branch information
CompRhys authored Aug 8, 2024
1 parent 61b02a5 commit a3b0ddb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/pymatgen/core/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def __getitem__(self, frames: ValidIndex) -> Molecule | Structure | Self:
charge=charge,
spin_multiplicity=spin,
site_properties=self._get_site_props(frames), # type: ignore[arg-type]
properties=None if self.frame_properties is None else self.frame_properties[frames],
)

lattice = self.lattice if self.constant_lattice else self.lattice[frames]
Expand All @@ -228,6 +229,7 @@ def __getitem__(self, frames: ValidIndex) -> Molecule | Structure | Self:
self.species,
self.coords[frames],
site_properties=self._get_site_props(frames), # type: ignore[arg-type]
properties=None if self.frame_properties is None else self.frame_properties[frames],
to_unit_cell=True,
)

Expand Down
4 changes: 4 additions & 0 deletions tests/core/test_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ def test_frame_properties(self):
expected = props[1:]
assert traj[1:].frame_properties == expected

# test that the frame properties are set correctly when indexing an individual structure/molecule
expected = props[0]
assert traj[0].properties == expected

def test_extend(self):
traj = copy.deepcopy(self.traj)

Expand Down

0 comments on commit a3b0ddb

Please sign in to comment.