Ejemplo n.º 1
0
    def test_actionlist(self):
        '''test_actionlist
        '''
        dslist = DatasetList()
        actlist = ActionList()
        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")
        mask_list = ['@CB @CA', '@CA @H']

        for mask in mask_list:
            actlist.add(CA.Action_Vector(),
                        mask,
                        traj.top,
                        dslist=dslist)
        actlist.compute(traj)

        dslist2 = pt.calc_vector(traj, mask_list)
        dslist4 = va.vector_mask(traj, mask_list)

        dslist3_0 = pt.calc_vector(traj, mask_list[0])
        dslist3_1 = pt.calc_vector(traj, mask_list[1])

        aa_eq(dslist3_0, dslist2[0])
        aa_eq(dslist3_1, dslist2[1])

        aa_eq(dslist3_0, dslist4[0])
        aa_eq(dslist3_1, dslist4[1])

        aa_eq(dslist3_0, dslist[0].values)
        aa_eq(dslist3_1, dslist[1].values)
Ejemplo n.º 2
0
    def test_constructor_from_command_list_Trajectory(self):
        '''mutable Trajectory'''
        # use `load` method rather `iterload`
        traj = pt.load(fn("tz2.ortho.nc"), fn("tz2.ortho.parm7"))

        # make sure no space-sensitivity
        # make the code (commands) ugly is my intention.
        commands = [
            'autoimage ',
            'autoimage',
            'rmsd @CA',
            'distance :3 :7',
            'distance     :3 :7',
            'vector :2 :3',
            '  distance :3 :7',
            'rms @C,N,O',
        ]

        dslist = CpptrajDatasetList()
        actlist = ActionList(commands, traj.top, dslist=dslist)

        for frame in traj:
            actlist.compute(frame)

        aa_eq(pt.rmsd(traj, mask='@CA'), dslist[0])
        aa_eq(pt.distance(traj, ':3 :7'), dslist[1])
        aa_eq(pt.distance(traj, ':3 :7'), dslist[2])
        # do not need to perform rmsfit again.
        aa_eq(pt.vector.vector_mask(traj, ':2 :3'), dslist[3].values)
        aa_eq(pt.distance(traj, ':3 :7'), dslist[4])
        aa_eq(pt.rmsd(traj, mask='@C,N,O'), dslist[5])
Ejemplo n.º 3
0
    def test_constructor_from_command_list_Trajectory(self):
        '''mutable Trajectory'''
        # use `load` method rather `iterload`
        traj = pt.load("data/tz2.ortho.nc", "data/tz2.ortho.parm7")

        # make sure no space-sensitivity
        # make the code (commands) ugly is my intention.
        commands = [
            'autoimage ',
            'autoimage',
            'rmsd @CA',
            'distance :3 :7',
            'distance     :3 :7',
            'vector :2 :3',
            '  distance :3 :7',
            'rms @C,N,O',
        ]

        dslist = CpptrajDatasetList()
        actlist = ActionList(commands, traj.top, dslist=dslist)

        for frame in traj:
            actlist.compute(frame)

        aa_eq(pt.rmsd(traj, mask='@CA'), dslist[0])
        aa_eq(pt.distance(traj, ':3 :7'), dslist[1])
        aa_eq(pt.distance(traj, ':3 :7'), dslist[2])
        # do not need to perform rmsfit again.
        aa_eq(pt.vector.vector_mask(traj, ':2 :3'), dslist[3].values)
        aa_eq(pt.distance(traj, ':3 :7'), dslist[4])
        aa_eq(pt.rmsd(traj, mask='@C,N,O'), dslist[5])
Ejemplo n.º 4
0
    def test_actionlist(self):
        '''test_actionlist
        '''
        dslist = DatasetList()
        actlist = ActionList()
        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")
        mask_list = ['@CB @CA', '@CA @H']

        for mask in mask_list:
            actlist.add(CA.Action_Vector(), mask, traj.top, dslist=dslist)
        actlist.compute(traj)

        dslist2 = pt.calc_vector(traj, mask_list)
        dslist4 = va.vector_mask(traj, mask_list)

        dslist3_0 = pt.calc_vector(traj, mask_list[0])
        dslist3_1 = pt.calc_vector(traj, mask_list[1])

        aa_eq(dslist3_0, dslist2[0])
        aa_eq(dslist3_1, dslist2[1])

        aa_eq(dslist3_0, dslist4[0])
        aa_eq(dslist3_1, dslist4[1])

        aa_eq(dslist3_0, dslist[0].values)
        aa_eq(dslist3_1, dslist[1].values)
Ejemplo n.º 5
0
    def test_run_0(self):
        # load traj
        farray = pt.load(filename="./data/tz2.truncoct.nc",
                         top="./data/tz2.truncoct.parm7")[:2]
        fold = farray.copy()

        act = allactions.Action_Image()
        ptrajin = """
        center :2-11
        image center familiar com :6
        """

        # create 'strip' action
        stripact = allactions.Action_Strip()

        # creat datasetlist to hold distance data
        dsetlist = CpptrajDatasetList()
        dflist = DataFileList()

        # creat ActionList to hold actions
        alist = ActionList()

        top = farray.top

        # add two actions: Action_Strip and Action_Distance
        alist.add(allactions.Action_Center(), ArgList(":2-11"), top=top)
        alist.add(allactions.Action_Image(),
                  ArgList("center familiar com :6"),
                  top=top)

        # do checking
        alist.check_topology(top)

        farray2 = Trajectory()
        frame0 = Frame()
        # testing how fast to do the actions

        # loop all frames
        # use iterator to make faster loop
        # don't use "for i in range(farray.n_frames)"
        for frame in farray:
            # perform actions for each frame
            # we make a copy since we want to keep orginal Frame
            frame0 = frame.copy()
            alist.compute(frame0)

            # we need to keep the modified frame in farray2
            farray2.append(frame0)

        # make sure that Action_Strip does its job in stripping
        assert farray2.n_frames == farray.n_frames

        fsaved = pt.iterload(cpptraj_test_dir + "/Test_Image/image4.crd.save",
                             "data/tz2.truncoct.parm7")
        assert fsaved.n_frames == 2
Ejemplo n.º 6
0
    def test_run_0(self):
        # load traj
        farray = pt.load(filename="./data/tz2.truncoct.nc",
                         top="./data/tz2.truncoct.parm7")[:2]
        fold = farray.copy()

        act = allactions.Action_Image()
        ptrajin = """
        center :2-11
        image center familiar com :6
        """

        # create 'strip' action
        stripact = allactions.Action_Strip()

        # creat datasetlist to hold distance data
        dsetlist = CpptrajDatasetList()
        dflist = DataFileList()

        # creat ActionList to hold actions
        alist = ActionList()

        top = farray.top

        # add two actions: Action_Strip and Action_Distance
        alist.add(allactions.Action_Center(), ArgList(":2-11"), top=top)
        alist.add(allactions.Action_Image(),
                  ArgList("center familiar com :6"),
                  top=top)

        # do checking
        alist.check_topology(top)

        farray2 = Trajectory()
        frame0 = Frame()
        # testing how fast to do the actions

        # loop all frames
        # use iterator to make faster loop
        # don't use "for i in range(farray.n_frames)"
        for frame in farray:
            # perform actions for each frame
            # we make a copy since we want to keep orginal Frame
            frame0 = frame.copy()
            alist.compute(frame0)

            # we need to keep the modified frame in farray2
            farray2.append(frame0)

        # make sure that Action_Strip does its job in stripping
        assert farray2.n_frames == farray.n_frames

        fsaved = pt.iterload(cpptraj_test_dir + "/Test_Image/image4.crd.save",
                             "data/tz2.truncoct.parm7")
        assert fsaved.n_frames == 2
Ejemplo n.º 7
0
    def test_run_5(self):
        traj = pt.iterload(tc5b_trajin, tc5b_top)
        mask_list = ('@CB @CA', '@CA @H')
        dslist = CpptrajDatasetList()
        actlist = ActionList()

        for mask in mask_list:
            actlist.add(CA.Action_Distance(), mask, traj.top, dslist=dslist)
        actlist.compute(traj)

        dslist2 = pt.calc_distance(traj, mask_list)
        aa_eq(dslist.values, dslist2)
Ejemplo n.º 8
0
        def test_rmsd_actlist(input_traj):
            from pytraj.analysis.c_action.c_action import Action_Rmsd
            from pytraj import ActionList
            from pytraj.datasets import DatasetList

            alist = ActionList()
            dslist = DatasetList()
            act = Action_Rmsd()
            alist.add(act, 'first @CA', top=input_traj.top, dslist=dslist)

            for frame in input_traj:
                alist.compute(frame)
            return (dslist.values)
Ejemplo n.º 9
0
    def test_run_2(self):
        # load traj
        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")
        dslist = CpptrajDatasetList()
        dflist = DataFileList()

        # creat ActionList to hold actions
        alist = ActionList()
        alist.add(adict['distance'], ":2@CA :10@CA out ./output/_dist.out",
                  traj.top, dslist, dflist)
        alist.compute([traj.iterchunk()])
        print('dslist', dslist[0].size)
        assert len(dslist) == 1
        assert dslist[0].size == traj.n_frames
Ejemplo n.º 10
0
    def test_run_2(self):
        # load traj
        traj = pt.iterload(tc5b_trajin, tc5b_top)
        dslist = CpptrajDatasetList()
        dflist = DataFileList()

        # creat ActionList to hold actions
        alist = ActionList()
        alist.add(adict['distance'], ":2@CA :10@CA out _dist.out", traj.top,
                  dslist, dflist)
        with tempfolder():
            alist.compute([traj.iterchunk()])
        assert len(dslist) == 1
        assert dslist[0].size == traj.n_frames
Ejemplo n.º 11
0
    def test_run_2(self):
        # load traj
        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")
        dslist = CpptrajDatasetList()
        dflist = DataFileList()

        # creat ActionList to hold actions
        alist = ActionList()
        alist.add(adict['distance'],
                  ":2@CA :10@CA out ./output/_dist.out", traj.top,
                  dslist, dflist)
        alist.compute([traj.iterchunk()])
        print('dslist', dslist[0].size)
        assert len(dslist) == 1
        assert dslist[0].size == traj.n_frames
Ejemplo n.º 12
0
    def test_run_5(self):
        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")
        mask_list = ('@CB @CA', '@CA @H')
        dslist = CpptrajDatasetList()
        actlist = ActionList()

        for mask in mask_list:
            actlist.add(CA.Action_Distance(),
                        mask,
                        traj.top,
                        dslist=dslist)
        actlist.compute(traj)

        dslist2 = pt.calc_distance(traj, mask_list)
        aa_eq(dslist.values, dslist2)
Ejemplo n.º 13
0
        def test_rmsd_actlist(input_traj):
            from pytraj.c_action.c_action import Action_Rmsd
            from pytraj import ActionList
            from pytraj.datasets import DatasetList

            alist = ActionList()
            dslist = DatasetList()
            act = Action_Rmsd()
            alist.add(act,
                      'first @CA',
                      top=input_traj.top,
                      dslist=dslist)

            for frame in input_traj:
                alist.compute(frame)
            return (dslist.values)
Ejemplo n.º 14
0
    def test_constructor_from_command_list_TrajectoryIterator_no_DatasetList(
            self):
        traj = pt.iterload(tc5b_trajin, tc5b_top)

        commands = [
            'rmsd @CA', 'distance :3 :7', 'distance     :3 :7', 'vector :2 :3'
        ]

        actlist = ActionList(commands, top=traj.top)

        for frame in traj:
            actlist.compute(frame)

        aa_eq(pt.rmsd(traj, mask='@CA'), actlist.data[0])
        aa_eq(pt.distance(traj, ':3 :7'), actlist.data[1])
        aa_eq(pt.distance(traj, ':3 :7'), actlist.data[2])
        aa_eq(pt.vector.vector_mask(traj(rmsfit=(0, '@CA')), ':2 :3'),
              actlist.data[3].values)
Ejemplo n.º 15
0
    def test_run_3(self):
        dslist = CpptrajDatasetList()
        actlist = ActionList()
        traj = pt.iterload(tc5b_trajin, tc5b_top)
        mask_list = ['@CB @CA @N', '@CA @H @N']

        for mask in mask_list:
            actlist.add(CA.Action_Angle(), mask, traj.top, dslist=dslist)
        actlist.compute(traj)
        pt.calc_angle(traj, mask_list)

        dslist3_0 = pt.calc_angle(traj, mask_list[0])
        dslist3_1 = pt.calc_angle(traj, mask_list[1])
        aa_eq(dslist3_0, dslist[0].to_ndarray())
        aa_eq(dslist3_1, dslist[1].to_ndarray())

        aa_eq(dslist3_0, dslist[0].to_ndarray())
        aa_eq(dslist3_1, dslist[1].to_ndarray())
Ejemplo n.º 16
0
    def test_modify_frame(self):
        traj = pt.iterload("data/tz2.ortho.nc", "data/tz2.ortho.parm7")
        dslist = CpptrajDatasetList()
        dslist.add_new('topology', name='mytop')

        # add a new topology
        dslist[0].data = pt.strip(traj.top, ':WAT')
        commands = ['autoimage', 'strip :WAT', 'createcrd mycrd', ]

        actlist = ActionList(commands, top=traj.top, dslist=dslist)

        for frame in traj:
            actlist.compute(frame)

        aa_eq(dslist['mycrd'].xyz,
              pt.get_coordinates(traj,
                                 mask='!:WAT',
                                 autoimage=True))
Ejemplo n.º 17
0
    def test_run_4(self):
        dslist = CpptrajDatasetList()
        actlist = ActionList()
        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")
        mask_list = ['@CB @CA @N @H', '@CA @H @N @H=']

        for mask in mask_list:
            actlist.add(CA.Action_Dihedral(), mask, traj.top, dslist=dslist)
        actlist.compute(traj)

        dslist2 = pt.calc_dihedral(traj, mask_list)

        dslist3_0 = pt.calc_dihedral(traj, mask_list[0])
        dslist3_1 = pt.calc_dihedral(traj, mask_list[1])
        aa_eq(dslist3_0, dslist2[0])
        aa_eq(dslist3_1, dslist2[1])

        aa_eq(dslist3_0, dslist[0].to_ndarray())
        aa_eq(dslist3_1, dslist[1].to_ndarray())
Ejemplo n.º 18
0
    def test_modify_frame(self):
        traj = pt.iterload(fn("tz2.ortho.nc"), fn("tz2.ortho.parm7"))
        dslist = CpptrajDatasetList()
        dslist.add('topology', name='mytop')

        # add a new topology
        dslist[0].data = pt.strip(traj.top, ':WAT')
        commands = [
            'autoimage',
            'strip :WAT',
            'createcrd mycrd',
        ]

        actlist = ActionList(commands, top=traj.top, dslist=dslist)

        for frame in traj:
            actlist.compute(frame)

        aa_eq(dslist['mycrd'].xyz,
              pt.get_coordinates(traj, mask='!:WAT', autoimage=True))
Ejemplo n.º 19
0
    def test_constructor_from_command_list_TrajectoryIterator_no_DatasetList(
            self):
        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")

        commands = ['rmsd @CA', 'distance :3 :7', 'distance     :3 :7',
                    'vector :2 :3']

        actlist = ActionList(commands, top=traj.top)

        for frame in traj:
            actlist.compute(frame)

        aa_eq(pt.rmsd(traj, mask='@CA'), actlist.data[0])
        aa_eq(pt.distance(traj, ':3 :7'), actlist.data[1])
        aa_eq(pt.distance(traj, ':3 :7'), actlist.data[2])
        aa_eq(
            pt.vector.vector_mask(
                traj(rmsfit=(0, '@CA')),
                ':2 :3'),
            actlist.data[3].values)
Ejemplo n.º 20
0
    def test_constructor_from_command_list_TrajectoryIterator(self):
        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")

        commands = [
            'rmsd @CA', 'distance :3 :7', 'distance     :3 :7', 'vector :2 :3'
        ]

        dslist = CpptrajDatasetList()
        actlist = ActionList(commands, traj.top, dslist=dslist)

        d0 = dslist.add('ref_frame', 'my_ref')
        d0.add_frame(traj[3])

        for frame in traj:
            actlist.compute(frame)

        aa_eq(pt.rmsd(traj, mask='@CA'), dslist[0])
        aa_eq(pt.distance(traj, ':3 :7'), dslist[1])
        aa_eq(pt.distance(traj, ':3 :7'), dslist[2])
        aa_eq(pt.vector.vector_mask(traj(rmsfit=(0, '@CA')), ':2 :3'),
              dslist[3].values)
Ejemplo n.º 21
0
    def test_run_4(self):
        dslist = CpptrajDatasetList()
        actlist = ActionList()
        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")
        mask_list = ['@CB @CA @N @H', '@CA @H @N @H=']

        for mask in mask_list:
            actlist.add(CA.Action_Dihedral(),
                        mask,
                        traj.top,
                        dslist=dslist)
        actlist.compute(traj)

        dslist2 = pt.calc_dihedral(traj, mask_list)

        dslist3_0 = pt.calc_dihedral(traj, mask_list[0])
        dslist3_1 = pt.calc_dihedral(traj, mask_list[1])
        aa_eq(dslist3_0, dslist2[0])
        aa_eq(dslist3_1, dslist2[1])

        aa_eq(dslist3_0, dslist[0].to_ndarray())
        aa_eq(dslist3_1, dslist[1].to_ndarray())
Ejemplo n.º 22
0
    def test_constructor_from_command_list_TrajectoryIterator(self):
        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")

        commands = ['rmsd @CA', 'distance :3 :7', 'distance     :3 :7',
                    'vector :2 :3']

        dslist = CpptrajDatasetList()
        actlist = ActionList(commands, traj.top, dslist=dslist)

        d0 = dslist.add('ref_frame', 'my_ref')
        d0.add_frame(traj[3])

        for frame in traj:
            actlist.compute(frame)

        aa_eq(pt.rmsd(traj, mask='@CA'), dslist[0])
        aa_eq(pt.distance(traj, ':3 :7'), dslist[1])
        aa_eq(pt.distance(traj, ':3 :7'), dslist[2])
        aa_eq(
            pt.vector.vector_mask(
                traj(rmsfit=(0, '@CA')),
                ':2 :3'),
            dslist[3].values)