Note
when calling iterload
, no data is loaded to memory if not needed.
Register to load up to 50-th frame and skip every 2 frames
In [1]: import pytraj as pt
In [2]: traj = pt.iterload('tz2.nc', 'tz2.parm7', frame_slice=(0, 50, 2))
In [3]: traj
Out[3]:
pytraj.TrajectoryIterator, 25 frames:
Size: 0.000125 (GB)
<Topology: 223 atoms, 13 residues, 1 mols, non-PBC>
Register to load all frames
In [4]: traj = pt.iterload('tz2.nc', 'tz2.parm7')
In [5]: traj
Out[5]:
pytraj.TrajectoryIterator, 101 frames:
Size: 0.000503 (GB)
<Topology: 223 atoms, 13 residues, 1 mols, non-PBC>
# since we registered to load all frames, if we only need up to 50-th frame for our
# calculation, we can use ( ) notation
In [6]: for frame in traj(0, 50): pass
# print the last frame
In [7]: print(frame)
<Frame with 223 atoms>