Пример #1
0
    def test_run(self):
        print "test_process_input"
        state2 = CpptrajState()

        toplist = state2.toplist
        toplist.add_parm("./data/Tc5b.top")

        state2.add_trajin("./data/md1_prod.Tc5b.x")

        state2.add_reference("./data/Tc5b.nat.crd")
        state2.add_trajout("./output/test.out")

        state2.add_action(
            allactions.Action_Distance(),
            ArgList("distance :2@CA :10@CA out ./output/dist_test.txt"))

        state2.add_action(allactions.Action_Distance(),
                          ArgList("distance :4@CA :10@CA"))

        state2.framelist.set_active_ref(0)
        print "test framelist.list()"
        state2.run()
        dslist = state2.datasetlist
        d0 = dslist[0]
        print "d0 is empty? ", d0.is_empty()
        d1 = cast_dataset(d0, dtype="general")
        print "d1 is empty? ", d1.is_empty()
        print d1.data[0:10]
Пример #2
0
    def test_0(self):
        dslist = DataSetList()
        dslist2 = DataSetList()
        act = allactions.Action_Distance()
        act_radgyr = allactions.Action_Radgyr()

        act.master(command="distance :1@CA :2@CA", 
                   current_frame=farray,
                   current_top=farray.top, dslist=dslist)

        act_radgyr.master(command="radgyr @CA",
                   current_frame=farray,
                   current_top=farray.top, dslist=dslist2)
       
        d1 = cast_dataset(dslist[0], dtype="general")
        d2 = cast_dataset(dslist2[0], dtype="general")
        print d1.data[:10]
        print d2.data[:10]
Пример #3
0
    def test_distance_frames(self):
        traj = FrameArray(filename="./data/md1_prod.Tc5b.x",
                          top="./data/Tc5b.top")
        dslist = DataSetList()
        act = allactions.Action_Distance()
        act.master(command="distance :1@CA :2@CA",
                   current_frame=traj,
                   current_top=traj.top,
                   dslist=dslist)
        d1 = cast_dataset(dslist[0], dtype="general")
        print d1.data[:10]

        frame0 = traj[0]
        frame0.strip_atoms("!@CA", traj.top)
        frame1 = traj[1]
        frame1.strip_atoms("!@CA", traj.top)
        print "dist_rmsd = ", frame0.dist_rmsd(frame1)
        distframes = distance_frames(frame0, frame1)
        print distframes.__len__()
        xyz0_0 = frame0.atoms(0)
        xyz0_1 = frame0.atoms(1)

        assert distance(xyz0_1, xyz0_0) == d1.data[0]
Пример #4
0
    def test_action(self):
        distaction = allactions.Action_Distance()
        boxaction = allactions.Action_Box()
        boxaction.help()
        toplist = TopologyList()
        framelist = FrameList()
        dsetlist = DataSetList()
        dflist = DataFileList()

        # add stuff
        toplist.add_parm("./data/Tc5b.top")
        framelist.add_reference(ArgList("./data/Tc5b.nat.crd"), toplist)
        distaction.read_input(ArgList(":2@CA :10@CA"), toplist, framelist,
                              dsetlist, dflist, 0)
        boxaction.read_input(ArgList("x 1000. y 1000. alpha 500."), toplist,
                             framelist, dsetlist, dflist, 0)
        distaction.process(toplist[0])

        idx = 0
        farray = FrameArray("./data/Tc5b.nat.crd", "./data/Tc5b.top")
        distaction.do_action(0, farray[idx])
        frame0 = farray[idx]
        # update Frame instance with new Box info
        boxaction.do_action(idx, frame0)
        print frame0.get_box()
        mdio.writetraj(filename="test_withbox.r",
                       traj=frame0,
                       top=farray.top,
                       fmt='AMBERRESTART',
                       overwrite=True)
        frame0.set_nobox()
        print frame0.get_box()
        mdio.writetraj(filename="test.r",
                       traj=frame0,
                       top=farray.top,
                       fmt='AMBERRESTART',
                       overwrite=True)
Пример #5
0
def run_0():
    # load traj
    farray = mdio.load("./data/md1_prod.Tc5b.x", "./data/Tc5b.top")

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

    # creat datasetlist to hold distance data
    dsetlist = DataSetList()

    # creat datafilelist to hold filenames and do writing later
    dflist = DataFileList()

    # creat ActionList to hold all actions
    alist = ActionList()

    # creat TopologyList to hold Topology instances
    toplist = TopologyList()
    # add parm
    toplist.add_parm(farray.top)

    # add actions: Action_Strip, Action_Distance and Action_Rmsd
    alist.add_action(stripact, ArgList("@H*"), toplist, None, dsetlist, dflist)
    alist.add_action(allactions.Action_Distance(),
                     ArgList(":2@CA :3@CA out _distance.dat"), toplist, None,
                     dsetlist, dflist)
    alist.add_action(allactions.Action_Rmsd(),
                     ArgList("rms first @CA out _rmsd.dat"), toplist, None,
                     dsetlist, dflist)

    #
    print "test setup_actions"
    print "number of actions = ", alist.n_actions

    # do checking
    alist.process(toplist[0])

    farray2 = FrameArray()

    # creat frame0 as data holder to avoid free memory twices
    # TODO : fix this
    frame0 = Frame()
    # testing how fast to do the actions

    t0 = time()
    # loop all frames
    # use iterator to make faster loop
    # don't use "for i in range(farray.size)"
    for frame in farray:
        # perform actions for each frame
        frame0 = frame.copy()
        alist.do_actions(frame=frame0)
        #alist.do_actions(frame)

        # we need to keep the modified frame in farray2
        #farray2.append(frame)
        farray2.append(frame0)
    print time() - t0

    # make sure that Action_Strip does its job in stripping
    print farray2.size
    assert farray2.n_frames == farray.n_frames
    assert farray2[0].n_atoms != farray[0].n_atoms

    # it's time to retrieve the data
    # get distance data
    # we need to explicitly cast_dataset
    # future : automatically cast data

    # get distance
    ds0 = cast_dataset(dsetlist[0], dtype='general')
    # get rmsd data
    ds1 = cast_dataset(dsetlist[1], dtype='general')
    print ds0[:10]
    print ds1[:10]

    # reproduce cpptraj's output?
    import numpy as np
    rmsdcpp = np.loadtxt("./data/rmsd_to_firstFrame_CA_allres.Tc5b.dat",
                         skiprows=1).transpose()[1][:10]
    # YES
    assert_almost_equal(rmsdcpp, ds1[:10])

    # write output for rmsd and distance (stored in dflist)
    # datatfile: ./_rmsd.dat, _distance.dat
    dflist.write_all_datafiles()
    print dir(dflist)
Пример #6
0
    def test_run_0(self):
        # load traj
        farray = mdio.load("./data/md1_prod.Tc5b.x", "./data/Tc5b.top")

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

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

        # creat ActionList to hold actions
        alist = ActionList()

        # creat TopologyList
        toplist = TopologyList()

        # add parm
        toplist.add_parm(farray.top)

        # add two actions: Action_Strip and Action_Distance
        alist.add_action(stripact, ArgList("@H*"), toplist, None, dsetlist,
                         dflist)
        alist.add_action(allactions.Action_Distance(),
                         ArgList(":2@CA :3@CA out test_df.dat"), toplist, None,
                         dsetlist, dflist)

        #
        print "test setup_actions"
        print alist.n_actions

        # do checking
        alist.process(toplist[0])

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

        t0 = time()
        # loop all frames
        # use iterator to make faster loop
        # don't use "for i in range(farray.size)"
        for frame in farray:
            # perform actions for each frame
            frame0 = frame.copy()
            alist.do_actions(frame=frame0)
            #alist.do_actions(frame)

            # we need to keep the modified frame in farray2
            #farray2.append(frame)
            farray2.append(frame0)
        print time() - t0

        # make sure that Action_Strip does its job in stripping
        print farray2.size
        assert farray2.n_frames == farray.n_frames
        assert farray2[0].n_atoms != farray[0].n_atoms

        # it's time to retrieve the data
        ds = cast_dataset(dsetlist[0], dtype='general')
        print ds[:10]
        print dir(dflist)
        dflist.write_all_datafiles()