示例#1
0
文件: test_mpi.py 项目: hainm/pytraj
def test_mpi():
    comm = MPI.COMM_WORLD

    rank = comm.rank

    traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7'))
    data = pt.pmap_mpi(pt.radgyr, traj, '*')

    frame_indices = range(10, 50)
    data_frame_indices = pt.pmap_mpi(pt.radgyr,
                                     traj,
                                     '*',
                                     frame_indices=frame_indices)
    data_frame_indices_cpp_style = pt.pmap_mpi([
        'radgyr nomax',
    ],
                                               traj,
                                               frame_indices=frame_indices)

    if rank == 0:
        saved_data = pt.radgyr(traj, '*')
        saved_data_frame_indices = pt.radgyr(traj,
                                             '*',
                                             frame_indices=frame_indices)
        aa_eq(data['RoG_00000'], saved_data)
        aa_eq(data_frame_indices['RoG_00000'], saved_data_frame_indices)
        aa_eq(data_frame_indices_cpp_style['RoG_00000'],
              saved_data_frame_indices)
示例#2
0
    def test_radgyr_dispatch(self):
        traj = pt.iterload("./data/tz2.ortho.nc", "./data/tz2.ortho.parm7")

        # mask is an array-like
        aa_eq(sb._toy_radgyr(traj, [0, 3]), pt.radgyr(traj, '@1,4'))

        # frame_indices
        aa_eq(
            sb._toy_radgyr(traj,
                           '@CA',
                           frame_indices=[0, 3]),
            pt.radgyr(traj, '@CA')[[0, 3]])

        # frame_indices, mask in kwd
        aa_eq(
            sb._toy_radgyr(traj,
                           mask='@CA',
                           frame_indices=[0, 3]),
            pt.radgyr(traj, '@CA')[[0, 3]])

        # frame iterator
        aa_eq(
            sb._toy_radgyr(
                traj(0, 3),
                mask='@CA'),
            pt.radgyr(traj, '@CA')[[0, 1, 2]])
示例#3
0
    def test_iterframe(self):
        '''test iterframe for both Trajectory and TrajectoryIterator
        '''

        orig_traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7'))
        # iterframe (already in doctest), just throwing raise to increase coverage score

        for traj in [orig_traj, orig_traj[:]]:
            with pytest.raises(ValueError):
                traj.iterframe(rmsfit='crazy')

            # rmsfit is an int
            t0 = orig_traj[:].rmsfit(ref=3)
            aa_eq(pt.rmsd_nofit(traj(rmsfit=3), ref=orig_traj[-1]),
                  pt.rmsd_nofit(t0, ref=orig_traj[-1]))

        # test TypeError if not has n_frames info
        t0 = orig_traj[:]

        def int_gen(k):
            for i in range(k):
                yield i

        fi = pt.iterframe(t0, frame_indices=int_gen(3))
        aa_eq(pt.radgyr(fi, top=traj.top), pt.radgyr(orig_traj[:3]))
示例#4
0
    def test_loading(self):
        for frame_slice in [(0, -1, 1), (0, 8, 2), (3, 9, 3)]:
            traj = pt.iterload('data/tz2.nc',
                               './data/tz2.parm7',
                               frame_slice=frame_slice)

            # load from text
            text = '''
            rms @CA
            radgyr @CA nomax
            '''

            s = load_batch(traj, text)
            s.run()

            rmsd0 = pt.rmsd(traj, '@CA', ref=0)
            r0 = pt.radgyr(traj, '@CA')
            s.data._pop(0)
            aa_eq(rmsd0, s.data[0])
            aa_eq(r0, s.data[1])
            assert len(s.data[0]) == traj.n_frames

            # load from list
            lines = ['rms @CA', '  radgyr @CA nomax']

            s = load_batch(traj, lines)
            s.run()
            s.data._pop(0)

            rmsd0 = pt.rmsd(traj, '@CA', ref=0)
            r0 = pt.radgyr(traj, '@CA')
            aa_eq(rmsd0, s.data[0])
            aa_eq(r0, s.data[1])
            assert len(s.data[0]) == traj.n_frames
示例#5
0
    def test_iterframe(self):
        '''test iterframe for both Trajectory and TrajectoryIterator
        '''

        orig_traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7")
        # iterframe (already in doctest), just throwing raise to increase coverage score

        for traj in [orig_traj, orig_traj[:]]:
            self.assertRaises(ValueError,
                              lambda: traj.iterframe(rmsfit='crazy'))

            # rmsfit is an int
            t0 = orig_traj[:].rmsfit(ref=3)
            aa_eq(
                pt.rmsd_nofit(
                    traj(rmsfit=3),
                    ref=orig_traj[-1]),
                pt.rmsd_nofit(t0, ref=orig_traj[-1]))

        # test TypeError if not has n_frames info
        t0 = orig_traj[:]

        def int_gen(k):
            for i in range(k):
                yield i

        fi = pt.iterframe(t0, frame_indices=int_gen(3))
        aa_eq(pt.radgyr(fi, top=traj.top), pt.radgyr(orig_traj[:3]))
示例#6
0
    def test_loading(self):
        for frame_slice in [(0, -1, 1), (0, 8, 2), (3, 9, 3)]:
            traj = pt.iterload(fn('tz2.nc'),
                               fn('tz2.parm7'),
                               frame_slice=frame_slice)

            # load from text
            text = '''
            rms @CA
            radgyr @CA nomax
            '''

            s = load_batch(traj, text)
            s.run()

            rmsd0 = pt.rmsd(traj, '@CA', ref=0)
            r0 = pt.radgyr(traj, '@CA')
            s.data._pop(0)
            aa_eq(rmsd0, s.data[0])
            aa_eq(r0, s.data[1])
            assert len(s.data[0]) == traj.n_frames

            # load from list
            lines = ['rms @CA', '  radgyr @CA nomax']

            s = load_batch(traj, lines)
            s.run()
            s.data._pop(0)

            rmsd0 = pt.rmsd(traj, '@CA', ref=0)
            r0 = pt.radgyr(traj, '@CA')
            aa_eq(rmsd0, s.data[0])
            aa_eq(r0, s.data[1])
            assert len(s.data[0]) == traj.n_frames
示例#7
0
def test():
    fname = 'data/nogit/remd/remd.x.000'
    topname = 'data/nogit/remd/myparm.parm7'
    traj = pt.trajectory.Trajectory(fname, top=topname)
    print(traj.xyz.dtype)

    for f in traj:
        pass

    pt.radgyr(traj)
    pt.molsurf(traj, '@CA')
    pt.rmsd(traj, mask='@CA')
    pt.multidihedral(traj)
示例#8
0
    def test_general(self):
        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")

        # with mask
        saved_data = pt.radgyr(traj, '@CA')
        data = pt.pmap(pt.radgyr, traj, '@CA')
        data = pt.tools.dict_to_ndarray(data)
        aa_eq(saved_data, data)

        # with a series of functions
        func_list = [pt.radgyr, pt.molsurf, pt.rmsd]
        ref = traj[-3]

        for n_cores in [2, 3]:
            for func in func_list:
                if func in [pt.rmsd, ]:
                    pout = pt.tools.dict_to_ndarray(pt.pmap(func=func,
                                                            traj=traj,
                                                            ref=ref,
                                                            n_cores=n_cores))
                    serial_out = flatten(func(traj, ref=ref))
                else:
                    pout = pt.tools.dict_to_ndarray(pt.pmap(n_cores=n_cores,
                                                            func=func,
                                                            traj=traj))
                    serial_out = flatten(func(traj))
                aa_eq(pout[0], serial_out)

         # test worker
         # need to test this since coverages seems not recognize partial func
        from pytraj.parallel.multiprocessing_ import worker_byfunc
        data = worker_byfunc(rank=2, n_cores=8, func=pt.radgyr, traj=traj, args=(), kwd={'mask': '@CA'}, iter_options={})
        assert data[0] == 2, 'rank must be 2'
        assert data[2] == 1, 'n_frames for rank=2 should be 1 (only 10 frames in total)'
示例#9
0
def test_radgyr_default():
    traj = pt.iterload(fn("tz2.truncoct.nc"), fn("tz2.truncoct.parm7"))
    state = pt.load_cpptraj_state("""
    radgyr :1-13
    """, traj)
    state.run()
    np.testing.assert_almost_equal(
        pt.radgyr(traj, ':1-13'), state.data['RoG_00001'].values)
    def test_iterframe_indices(self):
        traj = pt.iterload(fn('Tc5b.x'), fn('Tc5b.top'))

        t0 = traj[:]
        indices = range(3)

        d1 = pt.radgyr(traj[indices])
        d2 = pt.radgyr(traj, frame_indices=indices)

        aa_eq(d2, d1)

        # raise if out of bound
        # only care about TrajectoryCpptraj since we would get segmentation fault
        # if index is larger than max n_frame
        with pytest.raises(AssertionError):
            for _ in traj._iterframe_indices([
                    traj.n_frames,
            ]):
                print(_.xyz)
示例#11
0
    def test_iterframe_indices(self):
        traj = pt.iterload(fn('Tc5b.x'), fn('Tc5b.top'))

        t0 = traj[:]
        indices = range(3)

        d1 = pt.radgyr(traj[indices])
        d2 = pt.radgyr(traj, frame_indices=indices)

        aa_eq(d2, d1)

        n_frames = traj.n_frames
        aa_eq(
             np.array([frame.xyz.copy() for frame in
                       traj._iterframe_indices([-2, -1])]),
             traj[[n_frames-2, n_frames-1]].xyz) # yapf: disable
        aa_eq(
             traj[[-2, -1]].xyz,
             traj[[n_frames-2, n_frames-1]].xyz) # yapf: disable
示例#12
0
    def test_insert_new_function(self):
        traj = pt.iterload("data/tz2.nc", "data/tz2.parm7")

        # create mutable Trajectory
        t0 = traj[:]
        for frame in t0:
            frame.xyz[:10] += 1.

        data_parallel = pt.pmap(pt.radgyr, traj, n_cores=2, apply=change_10_atoms)
        data_serial = pt.radgyr(t0)
        aa_eq(data_parallel['RoG_00000'], data_serial)
    def test_iterframe_indices(self):
        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")

        t0 = traj[:]
        indices = range(3)

        d0 = pt.radgyr(traj._iterframe_indices(indices), top=traj.top)
        d1 = pt.radgyr(traj[indices])
        d2 = pt.radgyr(traj, frame_indices=indices)

        aa_eq(d0, d1)
        aa_eq(d0, d2)

        # raise if out of bound
        # only care about TrajectoryCpptraj since we would get segmentation fault
        # if index is larger than max n_frame
        def iter_(traj=traj):
            for _ in traj._iterframe_indices([traj.n_frames, ]):
                print(_.xyz)

        self.assertRaises(AssertionError, lambda: iter_(traj))
示例#14
0
    def test_insert_new_function(self):
        traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7'))

        # create mutable Trajectory
        t0 = traj[:]
        for frame in t0:
            frame.xyz[:10] += 1.

        data_parallel = pt.pmap(
            pt.radgyr, traj, n_cores=2, apply=change_10_atoms)
        data_serial = pt.radgyr(t0)
        aa_eq(data_parallel['RoG_00000'], data_serial)
示例#15
0
    def test_unstrip(self):
        from pytraj.datasets import CpptrajDatasetList

        traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7'))

        dslist = CpptrajDatasetList()
        actlist = pt.ActionList(['strip !@CA', 'unstrip', 'radgyr nomax'],
                                top=traj.top,
                                dslist=dslist)

        actlist.compute(traj)

        # make sure that after stripping and unstrip the Frame coords are restored
        aa_eq(pt.radgyr(traj), dslist.values)

        dslist2 = CpptrajDatasetList()
        actlist2 = pt.ActionList(['strip !@CA', 'radgyr nomax'],
                                 top=traj.top,
                                 dslist=dslist2)
        actlist2.compute(traj)
        # make sure get correct radgyr after stripping all but CA atoms
        aa_eq(dslist2.values, pt.radgyr(traj, '@CA'))
示例#16
0
    def test_reference(self):
        traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7")

        for n_cores in [2, 3]:
            # use 4-th Frame for reference
            data = pt.pmap(['rms @CA refindex 0'],
                           traj,
                           ref=traj[3],
                           n_cores=n_cores)
            # another way to get reference
            data2 = pt.pmap(['rms @CA reference'],
                            traj,
                            ref=traj[3],
                            n_cores=n_cores)
            # use int for ref
            data3 = pt.pmap(pt.rmsd,
                            traj,
                            ref=3,
                            mask='@CA',
                            n_cores=n_cores)
            # use int for ref: use cpptraj's commmand style
            data4 = pt.pmap(['rms @CA reference'],
                            traj,
                            ref=3,
                            n_cores=n_cores)
            arr = pt.tools.dict_to_ndarray(data)[0]
            arr2 = pt.tools.dict_to_ndarray(data2)[0]
            arr3 = pt.tools.dict_to_ndarray(data3)[0]
            arr4 = pt.tools.dict_to_ndarray(data4)[0]
            aa_eq(arr, pt.rmsd(traj, ref=3, mask='@CA'))
            aa_eq(arr2, pt.rmsd(traj, ref=3, mask='@CA'))
            aa_eq(arr3, pt.rmsd(traj, ref=3, mask='@CA'))
            aa_eq(arr4, pt.rmsd(traj, ref=3, mask='@CA'))

            # use 4-th and 5-th Frame for reference
            data = pt.pmap(
                ['rms @CA refindex 0', 'rms @CB refindex 1'],
                traj,
                ref=[traj[3], traj[4]],
                n_cores=n_cores)
            arr = pt.tools.dict_to_ndarray(data)[0]
            aa_eq(arr, pt.rmsd(traj, '@CA', 3))

            arr1 = pt.tools.dict_to_ndarray(data)[1]
            aa_eq(arr1, pt.rmsd(traj, ref=4, mask='@CB'))

            # no ref
            data = pt.pmap(['radgyr', ], traj, n_cores=n_cores)
            arr = pt.tools.dict_to_ndarray(data)[0]
            aa_eq(arr, pt.radgyr(traj))
示例#17
0
    def test_iterframe_indices(self):
        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")

        t0 = traj[:]
        indices = range(3)

        d0 = pt.radgyr(traj._iterframe_indices(indices), top=traj.top)
        d1 = pt.radgyr(traj[indices])
        d2 = pt.radgyr(traj, frame_indices=indices)

        aa_eq(d0, d1)
        aa_eq(d0, d2)

        # raise if out of bound
        # only care about TrajectoryCpptraj since we would get segmentation fault
        # if index is larger than max n_frame
        def iter_(traj=traj):
            for _ in traj._iterframe_indices([
                    traj.n_frames,
            ]):
                print(_.xyz)

        self.assertRaises(AssertionError, lambda: iter_(traj))
    def test_issue807(self):
        # files are provided by Chris Lee
        traj = pt.iterload("./data/issue807/trunc.nc",
                           "./data/issue807/system.prmtop")

        traj[0]
        for frame in traj:
            pass
        traj[::2]
        pt.radgyr(traj[[0, 3]])
        pt.radgyr(traj, frame_indices=[0, 3])
        pt.radgyr(traj())
        traj[:3, '@O'].xyz
        pt.get_coordinates((traj.iterframe(mask='@O')))
        pt.radgyr(traj(mask='@O'))
        for c in pt.iterchunk(traj, 4):
            assert c[0].n_atoms == traj.top.n_atoms
    def test_radgyr(self):
        traj = pt.iterload(top="./data/Tc5b.top",
                           filename='data/Tc5b.x', )
        txt = '''
        parm ./data/Tc5b.top
        trajin ./data/Tc5b.x
        radgyr @CA nomax
        radgyr nomax
        radgyr !@H= nomax
        '''

        # exclude DatasetTopology
        data = pt.datafiles.load_cpptraj_output(txt)[1:]
        for mask, out in zip(['@CA', '', '!@H='], data):
            aa_eq(pt.radgyr(traj, mask), out)
示例#20
0
    def test_unstrip(self):
        from pytraj.datasets import CpptrajDatasetList

        traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7")

        dslist = CpptrajDatasetList()
        actlist = pt.ActionList(
            ['strip !@CA', 'unstrip', 'radgyr nomax'],
            top=traj.top,
            dslist=dslist)

        actlist.compute(traj)

        # make sure that after stripping and unstrip the Frame coords are restored
        aa_eq(pt.radgyr(traj), dslist.values)

        dslist2 = CpptrajDatasetList()
        actlist2 = pt.ActionList(
            ['strip !@CA', 'radgyr nomax'],
            top=traj.top,
            dslist=dslist2)
        actlist2.compute(traj)
        # make sure get correct radgyr after stripping all but CA atoms
        aa_eq(dslist2.values, pt.radgyr(traj, '@CA'))
    def test_issue807(self):
        # files are provided by Chris Lee
        traj = pt.iterload("./data/issue807/trunc.nc",
                           "./data/issue807/system.prmtop")

        traj[0]
        for frame in traj:
            pass
        traj[::2]
        pt.radgyr(traj[[0, 3]])
        pt.radgyr(traj, frame_indices=[0, 3])
        pt.radgyr(traj())
        traj[:3, '@O'].xyz
        pt.get_coordinates((traj.iterframe(mask='@O')))
        pt.radgyr(traj(mask='@O'))
        for c in pt.iterchunk(traj, 4):
            assert c[0].n_atoms == traj.top.n_atoms
示例#22
0
    def test_reference(self):
        traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7")

        for n_cores in [2, 3]:
            # use 4-th Frame for reference
            data = pt.pmap(['rms @CA refindex 0'],
                           traj,
                           ref=traj[3],
                           n_cores=n_cores)
            # another way to get reference
            data2 = pt.pmap(['rms @CA reference'],
                            traj,
                            ref=traj[3],
                            n_cores=n_cores)
            # use int for ref
            data3 = pt.pmap(pt.rmsd, traj, ref=3, mask='@CA', n_cores=n_cores)
            # use int for ref: use cpptraj's commmand style
            data4 = pt.pmap(['rms @CA reference'],
                            traj,
                            ref=3,
                            n_cores=n_cores)
            arr = pt.tools.dict_to_ndarray(data)[0]
            arr2 = pt.tools.dict_to_ndarray(data2)[0]
            arr3 = pt.tools.dict_to_ndarray(data3)[0]
            arr4 = pt.tools.dict_to_ndarray(data4)[0]
            aa_eq(arr, pt.rmsd(traj, ref=3, mask='@CA'))
            aa_eq(arr2, pt.rmsd(traj, ref=3, mask='@CA'))
            aa_eq(arr3, pt.rmsd(traj, ref=3, mask='@CA'))
            aa_eq(arr4, pt.rmsd(traj, ref=3, mask='@CA'))

            # use 4-th and 5-th Frame for reference
            data = pt.pmap(['rms @CA refindex 0', 'rms @CB refindex 1'],
                           traj,
                           ref=[traj[3], traj[4]],
                           n_cores=n_cores)
            arr = pt.tools.dict_to_ndarray(data)[0]
            aa_eq(arr, pt.rmsd(traj, '@CA', 3))

            arr1 = pt.tools.dict_to_ndarray(data)[1]
            aa_eq(arr1, pt.rmsd(traj, ref=4, mask='@CB'))

            # no ref
            data = pt.pmap([
                'radgyr',
            ], traj, n_cores=n_cores)
            arr = pt.tools.dict_to_ndarray(data)[0]
            aa_eq(arr, pt.radgyr(traj))
示例#23
0
def test_pytraj_do():
    traj = pt.iterload(fn("tz2.nc"), fn("tz2.parm7"))

    ref0 = pt.autoimage(traj[0], top=traj.top)
    ref1 = pt.autoimage(traj[1], top=traj.top)

    data = pt.tools.dict_to_ndarray(pt.compute(
        ['autoimage', 'radgyr nomax @CA', 'rms refindex 0',
         'rms refindex 1'],
        traj,
        ref=[ref0, ref1]))

    t0 = pt.autoimage(traj[:])
    aa_eq(pt.radgyr(t0, '@CA'), data[0])
    aa_eq(pt.rmsd(t0, ref=ref0), data[1])
    aa_eq(pt.rmsd(t0, ref=ref1), data[2])
    aa_eq(pt.compute(pt.radgyr, t0, '@CA'), data[0])
示例#24
0
    def test_iter_options(self):
        traj = pt.iterload("data/tz2.ortho.nc", "data/tz2.ortho.parm7")
        t0 = traj[:].autoimage().rmsfit(ref=0)
        saved_avg = pt.mean_structure(t0)
        saved_radgyr = pt.radgyr(traj, '@CA')

        # perform autoimage, then rms fit to 1st frame, then compute mean structure
        iter_options = {'autoimage': True, 'rmsfit': 0}
        for n_cores in [2, 3]:
            avg = pt.pmap(pt.mean_structure,
                          traj,
                          iter_options=iter_options,
                          n_cores=n_cores)
            aa_eq(saved_avg.xyz, avg.xyz)
            radgyr_ = pt.tools.dict_to_ndarray(
                pt.pmap(pt.radgyr, traj, iter_options={'mask': '@CA'}))
            aa_eq(radgyr_[0], saved_radgyr)
示例#25
0
    def test_frame_indices(self):
        traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7'))

        # frame_indices could be a list, range
        frame_indices_list = [[0, 8, 9, 3, 2, 5], range(6)]

        for frame_indices in frame_indices_list:
            for n_cores in [2, 3]:
                serial_out = pt.radgyr(
                    traj, '@CA', frame_indices=frame_indices)
                parallel_out = pt.pmap(
                    pt.radgyr, traj, '@CA', frame_indices=frame_indices)
                parallel_out_c_style = pt.pmap(
                    ['radgyr @CA nomax'], traj, frame_indices=frame_indices)
                aa_eq([serial_out], pt.tools.dict_to_ndarray(parallel_out))
                aa_eq([serial_out],
                      pt.tools.dict_to_ndarray(parallel_out_c_style))
    def test_radgyr(self):
        traj = pt.iterload(
            top="./data/Tc5b.top",
            filename='data/Tc5b.x',
        )
        txt = '''
        parm ./data/Tc5b.top
        trajin ./data/Tc5b.x
        radgyr @CA nomax
        radgyr nomax
        radgyr !@H= nomax
        '''

        # exclude DatasetTopology
        data = pt.datafiles.load_cpptraj_output(txt)[1:]
        for mask, out in zip(['@CA', '', '!@H='], data):
            aa_eq(pt.radgyr(traj, mask), out)
示例#27
0
    def test_pytraj_do(self):
        traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7")

        ref0 = pt.autoimage(traj[0], top=traj.top)
        ref1 = pt.autoimage(traj[1], top=traj.top)

        data = pt.tools.dict_to_ndarray(pt.compute(
            ['autoimage', 'radgyr nomax @CA', 'rms refindex 0',
             'rms refindex 1'],
            traj,
            ref=[ref0, ref1]))

        t0 = pt.autoimage(traj[:])
        aa_eq(pt.radgyr(t0, '@CA'), data[0])
        aa_eq(pt.rmsd(t0, ref=ref0), data[1])
        aa_eq(pt.rmsd(t0, ref=ref1), data[2])

        # pytraj's method
        aa_eq(pt.compute(pt.radgyr, t0, '@CA'), data[0])
示例#28
0
    def test_iter_options(self):
        traj = pt.iterload("data/tz2.ortho.nc", "data/tz2.ortho.parm7")
        t0 = traj[:].autoimage().rmsfit(ref=0)
        saved_avg = pt.mean_structure(t0)
        saved_radgyr = pt.radgyr(traj, '@CA')

        # perform autoimage, then rms fit to 1st frame, then compute mean structure
        iter_options = {'autoimage': True, 'rmsfit': 0}
        for n_cores in [2, 3]:
            avg = pt.pmap(pt.mean_structure,
                          traj,
                          iter_options=iter_options,
                          n_cores=n_cores)
            aa_eq(saved_avg.xyz, avg.xyz)
            radgyr_ = pt.tools.dict_to_ndarray(pt.pmap(pt.radgyr,
                                                       traj,
                                                       iter_options={'mask':
                                                                     '@CA'}))
            aa_eq(radgyr_[0], saved_radgyr)
示例#29
0
 def calc_all(self):
     # calculate fluctuations
     self.calc_fluct()
     # calculate covariances
     self.calc_cov()
     # calculate correlations
     self.calc_corr()
     # calculate principal axes (length)
     self.calc_ppal_axes()
     # calculate radius of gyrations
     self.rg = np.mean(pt.radgyr(self.traj))
     # computes average distance between residues (~3.8A = .38nm)
     tem_dist = [self.dist[i][i+1] for i in range(self.traj.n_atoms - 1)]
     self.avg_dist = np.mean(tem_dist)
     # calculate shape factor fluctuations and mean value
     self.shape_factor_fluct()
     self.shape_factor = np.mean(self.SF_fluct)
     # compute suceptibility
     self.calc_suceptibility()
示例#30
0
def test_radgyr_tensor():
    traj = pt.iterload(fn("tz2.truncoct.nc"), fn("tz2.truncoct.parm7"))

    d = pt.radgyr_tensor(traj, mask=':1-13', dtype='dict')
    expectect_tensor = [[
        18.26403420734941, 12.330493458000614, 15.326805252790127,
        -2.125659395015517, -8.632996672082086, 4.7252454067158975
    ], [
        19.246862113820757, 11.432920183634895, 15.489687898615074,
        -3.0267399828080603, -9.129524039907787, 4.5109070835284255
    ], [
        19.75385387541704, 10.836915486429934, 15.803415368373425,
        -3.441456117622487, -9.28446388556888, 4.1670219147678464
    ], [
        19.269059015181764, 13.042016327597267, 15.817716819622737,
        -3.710072422051309, -9.489039068401922, 5.2288271979672745
    ], [
        19.813786389085553, 11.80314746736244, 15.44020623457249,
        -3.502106891601859, -9.099872095876812, 4.6923151789825015
    ], [
        19.60077776416306, 12.609058958163347, 15.896052062712025,
        -3.6477265975369044, -9.698869709134073, 4.850778745624434
    ], [
        18.174738583179614, 12.74891714333484, 15.832179262508554,
        -3.5327010118759263, -8.664441526832949, 5.420192653400531
    ], [
        19.507715402036883, 11.7096354909941, 14.459002582255001,
        -3.3556288916094963, -8.441118169033068, 4.699660712555152
    ], [
        18.534885181089813, 11.609977647369599, 15.403693965901535,
        -3.0397336400024666, -8.90681248448317, 5.083930132028563
    ], [
        19.232621566893187, 12.027900886619847, 15.150377798541307,
        -3.525614491193894, -8.611207782564183, 5.491302107043754
    ]]

    key = 'RoG_00000[Tensor]'
    np.testing.assert_almost_equal(d.get(key), expectect_tensor)

    d2 = pt.radgyr_tensor(traj, mask=':1-13')
    np.testing.assert_almost_equal(d2[1], expectect_tensor)
    np.testing.assert_almost_equal(d2[0], pt.radgyr(traj, ':1-13'))
 def calc_all(self):
     # calculate fluctuations
     self.calc_fluct()
     # calculate covariances and correlations
     self.calc_cov()
     # calculate principal axes (length)
     self.calc_ppal_axes()
     # calculate radius of gyrations
     self.rg = np.mean(pt.radgyr(self.traj))
     # computes average distance between residues (~3.8A = .38nm)
     self.calc_avg_dist()
     # calculate shape factor fluctuations and mean value
     self.shape_factor_fluct()
     self.shape_factor = np.mean(self.SF_fluct)
     # compute suceptibility
     self.calc_suceptibility()
     # compute TA-MSD
     # self.calc_TA_MSD() # not yet
     # compute autocorrelation in terms of the lag
     self.autocorr = self.calc_autocorr() 
示例#32
0
    def test_general(self):
        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")

        # with mask
        saved_data = pt.radgyr(traj, '@CA')
        data = pt.pmap(pt.radgyr, traj, '@CA')
        data = pt.tools.dict_to_ndarray(data)
        aa_eq(saved_data, data)

        # with a series of functions
        func_list = [pt.radgyr, pt.molsurf, pt.rmsd]
        ref = traj[-3]

        for n_cores in [2, 3]:
            for func in func_list:
                if func in [
                        pt.rmsd,
                ]:
                    pout = pt.tools.dict_to_ndarray(
                        pt.pmap(func=func, traj=traj, ref=ref,
                                n_cores=n_cores))
                    serial_out = flatten(func(traj, ref=ref))
                else:
                    pout = pt.tools.dict_to_ndarray(
                        pt.pmap(n_cores=n_cores, func=func, traj=traj))
                    serial_out = flatten(func(traj))
                aa_eq(pout[0], serial_out)

        # test worker
        # need to test this since coverages seems not recognize partial func
        from pytraj.parallel.multiprocessing_ import worker_byfunc
        data = worker_byfunc(rank=2,
                             n_cores=8,
                             func=pt.radgyr,
                             traj=traj,
                             args=(),
                             kwd={'mask': '@CA'},
                             iter_options={})
        assert data[0] == 2, 'rank must be 2'
        assert data[
            2] == 1, 'n_frames for rank=2 should be 1 (only 10 frames in total)'
示例#33
0
    def test_frame_indices(self):
        traj = pt.iterload("data/tz2.nc", "data/tz2.parm7")

        # frame_indices could be a list, range
        frame_indices_list = [[0, 8, 9, 3, 2, 5], range(6)]

        for frame_indices in frame_indices_list:
            for n_cores in [2, 3]:
                serial_out = pt.radgyr(traj,
                                       '@CA',
                                       frame_indices=frame_indices)
                parallel_out = pt.pmap(pt.radgyr,
                                       traj,
                                       '@CA',
                                       frame_indices=frame_indices)
                parallel_out_c_style = pt.pmap(
                    ['radgyr @CA nomax'],
                    traj,
                    frame_indices=frame_indices)
                aa_eq(serial_out, pt.tools.dict_to_ndarray(parallel_out))
                aa_eq(serial_out,
                      pt.tools.dict_to_ndarray(parallel_out_c_style))
示例#34
0
import pytraj as pt

# use iterload for memory saving
traj = pt.iterload("../tests/data/Tc5b.x", "../tests/data/Tc5b.top")

#
print(pt.radgyr(traj, '@CA', nomax=True))
示例#35
0
import pytraj as pt

# use iterload for memory saving
# you can use `load` to load all data to mem too

traj0 = pt.iterload(['../tests/data/Test_RemdTraj/rem.nc.000',
                     '../tests/data/Test_RemdTraj/rem.nc.001'],
                    top='../tests/data/Test_RemdTraj/ala2.99sb.mbondi2.parm7')

print(traj0)

# you can use `*` to load all files too
traj1 = pt.iterload('../tests/data/Test_RemdTraj/rem.nc.*',
                    top='../tests/data/Test_RemdTraj/ala2.99sb.mbondi2.parm7')

print(traj1)

# just want to calculate radgyr for few frames?
# frames: 1, 3, 6, 8
print(pt.radgyr(traj1[[1, 3, 6, 8]]))

# frame 1 to 100, skip every 2 frames
print(pt.radgyr(traj1(1, 100, 2)))
示例#36
0
import pytraj as pt

# use iterload for memory saving
# you can use `load` to load all data to mem too

traj0 = pt.iterload([
    '../tests/data/Test_RemdTraj/rem.nc.000',
    '../tests/data/Test_RemdTraj/rem.nc.001'
],
                    top='../tests/data/Test_RemdTraj/ala2.99sb.mbondi2.parm7')

print(traj0)

# you can use `*` to load all files too
traj1 = pt.iterload('../tests/data/Test_RemdTraj/rem.nc.*',
                    top='../tests/data/Test_RemdTraj/ala2.99sb.mbondi2.parm7')

print(traj1)

# just want to calculate radgyr for few frames?
# frames: 1, 3, 6, 8
print(pt.radgyr(traj1[[1, 3, 6, 8]]))

# frame 1 to 100, skip every 2 frames
print(pt.radgyr(traj1(1, 100, 2)))
示例#37
0
import unittest  # for travis (you don't need to add this)

# since MD simulations produce huge amount of data (hundreds of GB, few TB
# or enven tens of TB)
# so we always try to use TrajectoryIterator to save memory
# coordinates of specific frames are only loaded if needed

import pytraj as pt
traj = pt.iterload('../tests/data/tz2.ortho.nc',
                   '../tests/data/tz2.ortho.parm7')

# calculate molsurf for frame 0, 2, 4, 6
# start=0, stop=8, stride=2 (just like python's range(0, 8, 2))
print(pt.molsurf(traj(0, 8, 2), '@CA'))

# if we want to load all frames at once, use [] indexing style
# (just like indexing a list/array in python)
print(pt.molsurf(traj[0:8:2], '@CA'))

# we even perform `autoimage`
print(pt.radgyr(traj(0, 8, 2, autoimage=True), '@CA', nomax=True))
import pytraj as pt

# use `iterload` to save memory
traj = pt.iterload("../tests/data/tz2.ortho.nc",
                   "../tests/data/tz2.ortho.parm7")

# use 4 available cores
# calculate radgyr for all atoms
result = pt.pmap(n_cores=4, func=pt.radgyr, traj=traj)
print(result)

# serial version
result = pt.radgyr(traj)
print(result)
示例#39
0
import pytraj as pt
from pytraj.testing import aa_eq
from mpi4py import MPI

comm = MPI.COMM_WORLD

rank = comm.rank

traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7")
data = pt.pmap_mpi(pt.radgyr, traj, '*')

frame_indices = range(10, 50)
data_frame_indices = pt.pmap_mpi(pt.radgyr,
                                 traj,
                                 '*',
                                 frame_indices=frame_indices)
data_frame_indices_cpp_style = pt.pmap_mpi(
    ['radgyr nomax', ],
    traj,
    frame_indices=frame_indices)

if rank == 0:
    saved_data = pt.radgyr(traj, '*')
    saved_data_frame_indices = pt.radgyr(traj,
                                         '*',
                                         frame_indices=frame_indices)
    aa_eq(data['RoG_00000'], saved_data)
    aa_eq(data_frame_indices['RoG_00000'], saved_data_frame_indices)
    aa_eq(data_frame_indices_cpp_style['RoG_00000'], saved_data_frame_indices)