Ejemplo n.º 1
0
    def test_ComparetoMDtraj(self):
        import mdtraj as md
        traj = pt.load(filename="./data/Tc5b.x",
                       top="./data/Tc5b.top")
        m_top = md.load_prmtop("./data/Tc5b.top")
        m_traj = md.load_mdcrd("./data/Tc5b.x", m_top)
        m_traj.xyz = m_traj.xyz * 10  # convert `nm` to `Angstrom` unit

        arr0 = pt.rmsd(traj, ref=0)
        arr1 = pt.rmsd(traj, ref=0)
        arr2 = pt.rmsd(traj, )
        a_md0 = md.rmsd(m_traj, m_traj, 0)
        aa_eq(arr0, arr1)
        aa_eq(arr0, arr2)
        aa_eq(arr0, a_md0)

        arr0 = pt.rmsd(traj, ref=-1)
        arr1 = pt.rmsd(traj, ref=-1)
        a_md = md.rmsd(m_traj, m_traj, -1)
        aa_eq(arr0, arr1)
        aa_eq(arr0, a_md)

        mask = ":3-18@CA,C"
        atm = traj.top(mask)
        arr0 = pt.rmsd(traj, ref=-1, mask=mask)
        arr1 = pt.rmsd(traj, mask=atm.indices, ref=-1)
        arr2 = pt.rmsd(traj, mask=list(atm.indices), ref=-1)
        arr3 = pt.rmsd(traj, mask=tuple(atm.indices), ref=-1)
        a_md = md.rmsd(m_traj, m_traj, -1, atm.indices)
        aa_eq(arr0, a_md)
        aa_eq(arr1, a_md)
        aa_eq(arr2, a_md)
        aa_eq(arr3, a_md)

        fa = Trajectory(traj)
        arr0 = pt.rmsd(fa, ref=-1, mask=mask)
        arr1 = pt.rmsd(fa, mask=atm.indices, ref=-1)
        arr2 = pt.rmsd(fa, mask=list(atm.indices), ref=-1)
        arr3 = pt.rmsd(fa, mask=tuple(atm.indices), ref=-1)
        a_md = md.rmsd(m_traj, m_traj, -1, atm.indices)
        aa_eq(arr0, a_md)
        aa_eq(arr1, a_md)
        aa_eq(arr2, a_md)
        aa_eq(arr3, a_md)

        fa = Trajectory(traj)
        mask = "!@H="
        atm = fa.top(mask)
        arr0 = pt.rmsd(fa, ref=4, mask=mask)
        a_md = md.rmsd(m_traj, m_traj, 4, atm.indices)

        # exclude 0-th frame for ref
        aa_eq(arr0, a_md)
Ejemplo n.º 2
0
    def test_ComparetoMDtraj(self):
        import mdtraj as md
        traj = pt.load(filename=tc5b_trajin, top=tc5b_top)
        m_top = md.load_prmtop(tc5b_top)
        m_traj = md.load_mdcrd(tc5b_trajin, m_top)
        m_traj.xyz = m_traj.xyz * 10  # convert `nm` to `Angstrom` unit

        arr0 = pt.rmsd(traj, ref=0)
        arr1 = pt.rmsd(traj, ref=0)
        arr2 = pt.rmsd(traj, )
        a_md0 = md.rmsd(m_traj, m_traj, 0)
        aa_eq(arr0, arr1)
        aa_eq(arr0, arr2)
        aa_eq(arr0, a_md0)

        arr0 = pt.rmsd(traj, ref=-1)
        arr1 = pt.rmsd(traj, ref=-1)
        a_md = md.rmsd(m_traj, m_traj, -1)
        aa_eq(arr0, arr1)
        aa_eq(arr0, a_md)

        mask = ":3-18@CA,C"
        atm = traj.top(mask)
        arr0 = pt.rmsd(traj, ref=-1, mask=mask)
        arr1 = pt.rmsd(traj, mask=atm.indices, ref=-1)
        arr2 = pt.rmsd(traj, mask=list(atm.indices), ref=-1)
        arr3 = pt.rmsd(traj, mask=tuple(atm.indices), ref=-1)
        a_md = md.rmsd(m_traj, m_traj, -1, atm.indices)
        aa_eq(arr0, a_md)
        aa_eq(arr1, a_md)
        aa_eq(arr2, a_md)
        aa_eq(arr3, a_md)

        fa = Trajectory(traj)
        arr0 = pt.rmsd(fa, ref=-1, mask=mask)
        arr1 = pt.rmsd(fa, mask=atm.indices, ref=-1)
        arr2 = pt.rmsd(fa, mask=list(atm.indices), ref=-1)
        arr3 = pt.rmsd(fa, mask=tuple(atm.indices), ref=-1)
        a_md = md.rmsd(m_traj, m_traj, -1, atm.indices)
        aa_eq(arr0, a_md)
        aa_eq(arr1, a_md)
        aa_eq(arr2, a_md)
        aa_eq(arr3, a_md)

        fa = Trajectory(traj)
        mask = "!@H="
        atm = fa.top(mask)
        arr0 = pt.rmsd(fa, ref=4, mask=mask)
        a_md = md.rmsd(m_traj, m_traj, 4, atm.indices)

        # exclude 0-th frame for ref
        aa_eq(arr0, a_md)
Ejemplo n.º 3
0
def load_MDAnalysis(universe, top=None):
    """load MDAnalysis' Universe object to pytra's traj object

    Notes
    -----
    All coords will be loaded

    See Also
    --------
    load_MDAnalysisIterator
    """

    from MDAnalysis import Universe
    from pytraj.Trajectory import Trajectory
    from ..Frame import Frame

    # don't import here since we import load_pseudo_parm in
    # TrajectoryMDAnalysisIterator

    # MDAnalysis needs numpy. So we always have numpy when using this
    if not isinstance(universe, Universe):
        raise ValueError("must be a Universe")

    # creat pseudotop
    if top is None:
        raise ValueError("need a Topology or pdb/mol2/...")
    else:
        pseudotop = top

    # creat atom group
    ag = universe.atoms

    farray = Trajectory()
    farray.top = pseudotop
    for _ in universe.trajectory:
        frame = Frame(farray.top.n_atoms)
        # set box for each Frame
        frame.boxview[:] = farray.top.box[:]
        # load xyz coords, let numpy do automatically casting
        frame.xyz[:] = ag.positions
        # we don't need to make copy=True since we already created
        # frame and `farray` can 'keep' it
        farray.append(frame, copy=False)
    return farray
Ejemplo n.º 4
0
def load_MDAnalysis(its_obj, top=None):
    """load MDAnalysis' Universe object to pytra's traj object

    Notes
    -----
    All coords will be loaded

    See Also
    --------
    load_MDAnalysisIterator
    """

    from MDAnalysis import Universe
    from pytraj.Trajectory import Trajectory
    from ..Frame import Frame

    # don't import here since we import load_pseudo_parm in
    # TrajectoryMDAnalysisIterator

    # MDAnalysis needs numpy. So we always have numpy when using this
    if not isinstance(its_obj, Universe):
        raise ValueError("must be a Universe")

    # creat pseudotop
    if top is None:
        raise ValueError("need a Topology or pdb/mol2/...")
    else:
        pseudotop = top

    # creat atom group
    ag = its_obj.atoms

    farray = Trajectory()
    farray.top = pseudotop
    for _ in its_obj.trajectory:
        frame = Frame(farray.top.n_atoms)
        # set box for each Frame
        frame.boxview[:] = farray.top.box[:]
        # load xyz coords, let numpy do automatically casting
        frame.xyz[:] = ag.positions
        # we don't need to make copy=True since we already created
        # frame and `farray` can 'keep' it
        farray.append(frame, copy=False)
    return farray