Beispiel #1
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)'
Beispiel #2
0
def dssp_allresidues(traj, *args, **kwd):
    '''calculate dssp for all residues. Mostly used for visulization.

    Returns
    -------
    ndarray, shape=(n_frames, n_residues)

    Examples
    --------
    >>> import pytraj as pt
    >>> traj = pt.datafiles.load_dpdp()
    >>> x = pt.dssp_allresidues(traj, simplified=True)
    >>> x[0].tolist()
    ['C', 'E', 'E', 'E', 'E', 'C', 'C', 'C', 'C', 'E', 'E', 'E', 'E', 'E', 'C', 'C', 'E', 'E', 'E', 'E', 'C', 'C']
    >>> len(x[0]) == traj.top.n_residues
    True

    >>> # load trajectory having waters
    >>> traj = pt.datafiles.load_tz2_ortho()
    >>> x = pt.dssp_allresidues(traj, simplified=True)
    >>> len(x[0]) == traj.top.n_residues
    True
    >>> len(x[0])
    1704
    >>> # only calculate protein residues, use `pytraj.dssp`
    >>> y = pt.dssp(traj, simplified=True)
    >>> len(y[0])
    13

    Notes
    -----
    this method is not well optimized for speed.

    See also
    --------
    calc_dssp
    '''
    res_labels, data = calc_dssp(traj, *args, **kwd)[:2]
    top = get_topology(traj, kwd.get('top', None))

    # do not need to compute again if there is no solvent or weird residues
    if len(res_labels) == top.n_residues:
        return data

    res_indices = [int(x.split(':')[-1]) - 1 for x in res_labels]

    if not PY3:
        new_data = np.empty((traj.n_frames, traj.top.n_residues), dtype='S2')
    else:  # pragma no cover
        new_data = np.empty((traj.n_frames, traj.top.n_residues), dtype='U2')

    simplified = kwd.get('simplified', False)
    for fid, arr in enumerate(data):
        new_data[fid][:] = tools.flatten(
            get_ss_per_frame(arr,
                             top,
                             res_indices,
                             simplified,
                             all_atoms=False))
    return new_data
Beispiel #3
0
def dssp_allatoms(traj, *args, **kwd):
    '''calculate dssp for all atoms

    Returns
    -------
    ndarray, shape=(n_frames, n_atoms)

    Notes
    -----
    this method is not well optimized for speed.

    Examples
    --------
    >>> import pytraj as pt
    >>> traj = pt.fetch_pdb('1l2y')
    >>> x = pt.dssp_allatoms(traj, simplified=True)
    >>> x[0, :3].tolist()
    ['C', 'C', 'C']

    See also
    --------
    dssp
    '''
    res_labels, data = dssp(traj, *args, **kwd)[:2]
    top = get_topology(traj, kwd.get('top'))
    res_indices = [int(x.split(':')[-1]) - 1 for x in res_labels]

    new_data = np.empty((traj.n_frames, traj.n_atoms), dtype='U2')
    simplified = kwd.get('simplified', False)
    for fid, arr in enumerate(data):
        new_data[fid][:] = tools.flatten(
            get_ss_per_frame(arr, top, res_indices, simplified,
                             all_atoms=True))
    return new_data
Beispiel #4
0
def dssp_allresidues(traj, *args, **kwd):
    '''calculate dssp for all residues. Mostly used for visulization.

    Returns
    -------
    ndarray, shape=(n_frames, n_residues)

    Examples
    --------
    >>> import pytraj as pt
    >>> traj = pt.datafiles.load_dpdp()
    >>> x = pt.dssp_allresidues(traj, simplified=True)
    >>> x[0].tolist()
    ['C', 'E', 'E', 'E', 'E', 'C', 'C', 'C', 'C', 'E', 'E', 'E', 'E', 'E', 'C', 'C', 'E', 'E', 'E', 'E', 'C', 'C']
    >>> len(x[0]) == traj.top.n_residues
    True

    >>> # load trajectory having waters
    >>> traj = pt.datafiles.load_tz2_ortho()
    >>> x = pt.dssp_allresidues(traj, simplified=True)
    >>> len(x[0]) == traj.top.n_residues
    True
    >>> len(x[0])
    1704
    >>> # only calculate protein residues, use `pytraj.dssp`
    >>> y = pt.dssp(traj, simplified=True)
    >>> len(y[0])
    13

    Notes
    -----
    this method is not well optimized for speed.

    See also
    --------
    calc_dssp
    '''
    res_labels, data = calc_dssp(traj, *args, **kwd)[:2]
    top = get_topology(traj, kwd.get('top', None))

    # do not need to compute again if there is no solvent or weird residues
    if len(res_labels) == top.n_residues:
        return data

    res_indices = [int(x.split(':')[-1]) - 1 for x in res_labels]

    if not PY3:
        new_data = np.empty((traj.n_frames, traj.top.n_residues), dtype='S2')
    else:  # pragma no cover
        new_data = np.empty((traj.n_frames, traj.top.n_residues), dtype='U2')

    simplified = kwd.get('simplified', False)
    for fid, arr in enumerate(data):
        new_data[fid][:] = tools.flatten(get_ss_per_frame(arr,
                                                          top,
                                                          res_indices,
                                                          simplified,
                                                          all_atoms=False))
    return new_data
Beispiel #5
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)'
Beispiel #6
0
 def test_different_references(self):
     traj = self.traj
     func = pt.rmsd
     for i in range(0, 8, 2):
         ref = self.traj[i]
         for n_cores in [2, 3, ]:
             pout = pt.tools.dict_to_ndarray(pt.pmap(n_cores=n_cores,
                                                     func=func,
                                                     traj=traj,
                                                     ref=ref))
             serial_out = flatten(func(traj, ref=ref))
             aa_eq(pout[0], serial_out)
Beispiel #7
0
 def test_different_references(self):
     traj = self.traj
     func = pt.rmsd
     for i in range(0, 8, 2):
         ref = self.traj[i]
         for n_cores in [
                 2,
                 3,
         ]:
             pout = pt.tools.dict_to_ndarray(
                 pt.pmap(n_cores=n_cores, func=func, traj=traj, ref=ref))
             serial_out = flatten(func(traj, ref=ref))
             aa_eq(pout[0], serial_out)
Beispiel #8
0
def dssp_allatoms(traj, *args, **kwd):
    '''calculate dssp for all atoms

    Returns
    -------
    ndarray, shape=(n_frames, n_atoms)

    Notes
    -----
    this method is not well optimized for speed.

    Examples
    --------
    >>> import pytraj as pt
    >>> traj = pt.fetch_pdb('1l2y')
    >>> x = pt.dssp_allatoms(traj, simplified=True)
    >>> x[0, :3].tolist()
    ['C', 'C', 'C']

    See also
    --------
    calc_dssp
    '''
    res_labels, data = calc_dssp(traj, *args, **kwd)[:2]
    top = get_topology(traj, kwd.get('top'))
    res_indices = [int(x.split(':')[-1]) - 1 for x in res_labels]

    if not PY3:
        new_data = np.empty((traj.n_frames, traj.n_atoms), dtype='S2')
    else:  # pragma: no cover
        new_data = np.empty((traj.n_frames, traj.n_atoms), dtype='U2')

    simplified = kwd.get('simplified', False)
    for fid, arr in enumerate(data):
        new_data[fid][:] = tools.flatten(get_ss_per_frame(arr,
                                                          top,
                                                          res_indices,
                                                          simplified,
                                                          all_atoms=True))
    return new_data
Beispiel #9
0
'''print unique residue names from all mol2 files in current folder
python ./residues_from_mol2.py
'''
import parmed as pmd
from glob import glob
from pytraj.tools import flatten

plist = [pmd.load_file(fname, structure=True) for fname in glob('*.mol2')]

reslist = flatten([[res.name for res in p.residues] for p in plist])

print(set(reslist))