Skip to content

Commit

Permalink
Add a basic trajectory test
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewRadev committed Dec 7, 2024
1 parent 3734d77 commit 767711e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,17 @@ def from_ca_frames(data, topology_attr={}):
def __init__(self, mda_universe):
self.mda_universe = mda_universe

@property
def coordinates(self):
return self.mda_universe.atoms.positions

@property
def frames(self):
return self.mda_universe.trajectory

def __next__(self):
return next(self.mda_universe.trajectory)

def select_atoms(self, *args):
return self.mda_universe.select_atoms(*args)

Expand Down
22 changes: 22 additions & 0 deletions tests/trajectory_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import unittest

from lib.trajectory import Trajectory

class TrajectoryTest(unittest.TestCase):
def test_basic(self):
coordinates1 = [[1, 2, 3], [4, 5, 6]]
coordinates2 = [[2, 3, 4], [3, 4, 5]]

trajectory = Trajectory.from_ca_frames(
[coordinates1, coordinates2]
)

self.assertEqual(len(trajectory.frames), 2)

self.assertEqual(trajectory.coordinates.tolist(), coordinates1)
next(trajectory)
self.assertEqual(trajectory.coordinates.tolist(), coordinates2)


if __name__ == '__main__':
unittest.main()

0 comments on commit 767711e

Please sign in to comment.