Ejemplo n.º 1
0
    def __iter__(self):
        from pytraj.analysis.c_action import c_action
        # do not import c_action in the top to avoid circular importing
        if self.autoimage:
            image_act = c_action.Action_AutoImage()
            image_act.read_input("", top=self.original_top)
            image_act.setup(self.original_top)
        if self.rmsfit is not None:
            ref, mask_for_rmsfit = self.rmsfit
            need_align = True
            if self.autoimage:
                # need to do autoimage for ref too
                # make a copy to avoid changing ref
                ref = ref.copy()
                image_act.compute(ref)
            rmsd_act = c_action.Action_Rmsd()
            rmsd_act.read_input(mask_for_rmsfit, top=self.original_top)
            rmsd_act.setup(self.original_top)
            # creat first frame to trick cpptraj to align to this.
            rmsd_act.compute(ref)
        else:
            need_align = False
            ref, mask_for_rmsfit = None, None

        if self.mask is not None:
            mask = self.mask
            atm = self.original_top(mask)

        for frame0 in self.frame_iter:
            if self.copy:
                # use copy for TrajectoryIterator
                # so [f for f in traj()] will return a list of different
                # frames
                frame = frame0.copy()
            else:
                frame = frame0
            if self.autoimage:
                # from pytraj.c_action.c_action import Action_AutoImage
                # Action_AutoImage()("", frame, self.top)
                image_act.compute(frame)
            if need_align:
                # trick cpptraj to fit to 1st frame (=ref)
                rmsd_act.compute(frame)
            if self.mask is not None:
                frame2 = Frame(frame, atm)
                yield frame2
            else:
                yield frame
Ejemplo n.º 2
0
    def autoimage(self, command=''):
        '''perform autoimage

        Returns
        -------
        self

        Examples
        --------
        >>> import pytraj as pt; from pytraj.testing import get_fn
        >>> t0 = pt.load(*get_fn('tz2'))
        >>> t0.top.has_box()
        True
        >>> t0 = t0.autoimage()
        '''
        from pytraj.analysis.c_action import c_action

        act = c_action.Action_AutoImage()
        act(command, self, top=self.top)
        return self