pytraj.FrameIterator

class pytraj.frameiter.FrameIterator(fi_generator, original_top=None, new_top=None, start=0, stop=-1, step=1, mask='', autoimage=False, rmsfit=None, n_frames=None, copy=True, frame_indices=None)

Bases: object

create this class to hold all iterating information. This class is for internal use.

Parameters:

top : new Topology

original_top : original Topology

start, stop, step : int

mask : str or None, default None (all atoms)

only take atom with given mask

frame_indices : iterable, default: None

if frame_indices is not None: ignore (start, stop, step)

autoimage : bool, default: False

if autoimage, perform autoimage

rmsfit : int or a tuple, default False

if rmsfit, perform rms fit to reference. If rmsfit is an integer, perform rms fit to indicated frame for all atoms. If rmsfit is a tuple, perform rmsfit to given frame with given mask. if both autoimage and rmsfit are specified, do autoimage first.

n_frames : total number of frame. read-only

copy : bool, defaul: True

if True, always make a copy of Frame when iterating.

Notes

if ‘autoimage’ and ‘rmsfit’, reference frame is also autoimaged

Examples

>>> # short cut:
>>> # create FrameIterator with start=0, stop=8, step=2
>>> import pytraj as pt
>>> traj = pt.load_sample_data('tz2')
>>> fi = traj(0, 8, 2)
>>> # perform radgyr calculation with FrameIterator
>>> pt.radgyr(traj(0, 8, 2))
array([ 18.91114428,  18.84969884,  18.8568644 ,  18.9430491 ])
>>> # create FrameIterator with start, stop, step = 0, 8, 2
>>> # autoimage=False, rmsfit=False
>>> fi = traj.iterframe(0, 8, 2)
>>> # create FrameIterator with start, stop, step = 2, 8, 1
>>> # autoimage=False, rmsfit=False
>>> fi = traj.iterframe(2, 8)
>>> # create FrameIterator with start, stop, step = 2, 8, 1
>>> # autoimage=False, rmsfit=False, mask='@CA'
>>> fi = traj.iterframe(2, 8, mask='@CA')
>>> # create FrameIterator with start, stop, step = 2, 8, 1
>>> # autoimage=True, rmsfit=False, mask='@CA'
>>> for frame in traj.iterframe(2, 8, autoimage=True, mask='@CA'): print(frame)
<Frame with 12 atoms>
<Frame with 12 atoms>
<Frame with 12 atoms>
<Frame with 12 atoms>
<Frame with 12 atoms>
<Frame with 12 atoms>
>>> # with rmsfit
>>> for frame in traj.iterframe(2, 8, autoimage=True, rmsfit=0): pass
>>> for frame in traj.iterframe(2, 8, autoimage=True, rmsfit=(1, '!@H=')): pass
>>> # rmsfit
>>> fi = traj.iterframe(2, 8, rmsfit=(0, '@CA'))
>>> fi.n_frames
6
>>> fi = traj.iterframe(2, 8, mask='@1,2,3,4,5')
>>> fi.n_atoms
5
>>> # make copy of each Frame
>>> fi = traj.iterframe(2, 8, mask='@1,2,3,4,5', copy=True)
>>> fi = traj.iterframe(2, 8, rmsfit=3)
>>> fi = traj.iterframe(2, 8, mask='@1,2,3,4,5')
>>> # explit use copy=True to give different Frame with list
>>> fi = traj.iterframe(2, 8)
>>> fi.copy = True
>>> pt.radgyr(list(fi), top=traj.top)
array([ 18.84969884,  18.90449256,  18.8568644 ,  18.88917208,
        18.9430491 ,  18.88878079])

Attributes

n_atoms
n_frames

Methods

save([filename, overwrite, options]) save to different file format.
n_atoms
n_frames
save(filename='', overwrite=False, options='', *args, **kwd)

save to different file format.

Notes

FrameIterator will be exhausted since this is an iterator.

Examples

>>> import pytraj as pt
>>> traj = pt.load_sample_data('tz2')
>>> fi = traj(2, 8, 2, mask='@CA')
>>> fi.save('output/test.nc', overwrite=True)
>>> # short version
>>> traj(2, 8, 2, mask='@CA').save('output/test.nc', overwrite=True)