def test_0(self):
        if os.path.exists(amberhome):
            from pytraj.amber_wrapper import minimize

            traj = pt.iterload("./data/Ala3/Ala3.crd", "./data/Ala3/Ala3.top")
            t0 = traj[:1]

            if has_("sander"):
                print('egb: ', pt.energy_decomposition(t0, igb=8)['gb'])

            minimize(t0)

            self.assertRaises(ValueError, lambda: minimize(traj))

            if has_("sander"):
                print('egb: ', pt.energy_decomposition(t0, igb=8)['gb'])

            # load saved file
            saved_coords = pt.load("./data/Ala3/min/min.r", traj.top).xyz
            aa_eq(t0.xyz, saved_coords, decimal=5)
    def test_0(self):
        if os.path.exists(amberhome):
            from pytraj.amber_wrapper import minimize

            traj = pt.iterload("./data/Ala3/Ala3.crd", "./data/Ala3/Ala3.top")
            t0 = traj[:1]

            if has_("sander"):
                print('egb: ', pt.energy_decomposition(t0, igb=8)['gb'])

            minimize(t0)

            self.assertRaises(ValueError, lambda: minimize(traj))

            if has_("sander"):
                print('egb: ', pt.energy_decomposition(t0, igb=8)['gb'])

            # load saved file
            saved_coords = pt.load("./data/Ala3/min/min.r", traj.top).xyz
            aa_eq(t0.xyz, saved_coords, decimal=5)
Beispiel #3
0
    def test_0(self):
        traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top")
        if has_("numpy"):
            import numpy as np
            from numpy.testing import assert_almost_equal
            arr0 = traj.xyz
            aa_eq(arr0, traj[:, :, :].xyz)

            # create Trajectory
            farray = traj[:]
            aa_eq(arr0, farray[:, :, :].xyz)
        else:
            pass
Beispiel #4
0
    def test_0(self):
        traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top")
        if has_("numpy"):
            import numpy as np
            from numpy.testing import assert_almost_equal
            arr0 = traj.xyz
            aa_eq(arr0, traj[:, :, :].xyz)

            # create Trajectory
            farray = traj[:]
            aa_eq(arr0, farray[:, :, :].xyz)
        else:
            pass
Beispiel #5
0
class TestSimpleRMSD(unittest.TestCase):
    def setUp(self):
        self.traj = pt.iterload(tc5b_trajin, tc5b_top)

    def test_fit_and_then_nofit(self):
        traj = pt.iterload(tc5b_trajin, tc5b_top)
        t0 = traj[:]
        pt.superpose(t0, ref=traj[3], mask='@CA')
        rmsd_0 = pt.rmsd_nofit(traj, ref=traj[3], mask='@CB')
        rmsd_1 = pt.rmsd(traj, ref=traj[3], mask='@CB', nofit=True)
        aa_eq(rmsd_1, rmsd_0)

    def test_rmsd_with_mask(self):
        TRAJ = pt.iterload(filename=tc5b_trajin, top=tc5b_top)
        cpptraj_rmsd = np.loadtxt(fn("rmsd_to_firstFrame_CA_allres.Tc5b.dat"),
                                  skiprows=1).transpose()[1]
        f0 = TRAJ[0]
        arr0 = np.zeros(TRAJ.n_frames)
        arr1 = np.zeros(TRAJ.n_frames)
        mask = "@CA"
        atm = AtomMask(mask)
        TRAJ.top._set_integer_mask(atm)

        for i, frame in enumerate(TRAJ):
            arr0[i] = frame.rmsd(f0, mask=mask, top=TRAJ.top)
            arr1[i] = frame.rmsd(f0, atommask=atm)

        arr2 = pt.rmsd(TRAJ, mask=mask, ref=f0)
        arr3 = pt.rmsd(TRAJ, mask=mask, ref=0)
        aa_eq(arr0, cpptraj_rmsd, decimal=3)
        aa_eq(arr1, cpptraj_rmsd, decimal=3)
        aa_eq(arr2, cpptraj_rmsd, decimal=3)
        aa_eq(arr3, cpptraj_rmsd, decimal=3)

    def testsuperpose_alias(self):
        '''testsuperpose_alias'''
        t0 = self.traj[:]
        t1 = self.traj[:]
        pt.transform(t0, ['superpose'])
        pt.transform(t1, ['rms'])
        aa_eq(t0.xyz, t1.xyz)

    def test_reference_with_different_topology_basic(self):
        traj1 = pt.iterload(filename=tc5b_trajin, top=tc5b_top)
        traj2 = pt.iterload(fn('tz2.nc'), fn('tz2.parm7'))

        # re-establish ActionList
        dslist = CpptrajDatasetList()
        dslist.add('reference', name='myref')

        dslist[0].top = traj2.top
        dslist[0].add_frame(traj2[0])

        actlist = pt.ActionList(['rmsd @1-11 @CB ref myref'],
                                top=traj1.top,
                                dslist=dslist)
        for frame in traj1:
            actlist.compute(frame)

        # raise if ref_mask is given but not mask
        self.assertRaises(ValueError,
                          lambda: pt.rmsd(traj1, ref=3, ref_mask='@CB'))
        self.assertRaises(
            ValueError, lambda: pt.rmsd(traj1, ref=traj2[:1], ref_mask='@CB'))

        # assert to cpptraj
        tc5b_traj = traj1[:]
        tz2_traj = traj2[:1]

        cm = '''
        parm  {} [tc5b]
        trajin {}
        parm {} [tz2]
        reference {} parm [tz2] 1 [myref]
        rms myrmsd ref [myref] @1-10 @11-20
        '''.format(tc5b_top, tc5b_trajin, tz2_top, tz2_trajin)
        print(cm)
        state = pt.load_cpptraj_state(cm)
        with tempfolder():
            state.run()

        expected_rmsd = state.data[-1].values
        rmsd_data = pt.rmsd(tc5b_traj,
                            mask='@1-10',
                            ref=tz2_traj,
                            ref_mask='@11-20')
        aa_eq(expected_rmsd, rmsd_data)

    @unittest.skipIf(not has_('mdtraj'), 'does not have mdtraj')
    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)

    def test_list_of_masks(self):
        traj = self.traj.copy()
        mask = ['@CA', '@CB', ':3-18@CA,C']
        arr = pt.rmsd(traj, mask=mask)
        for idx, m in enumerate(mask):
            aa_eq(arr[idx], pt.rmsd(traj, mask=m))
            aa_eq(arr[idx], pt.rmsd(traj, mask=traj.top.select(m)))

        mask = ['@CA', '@CB', ':3-18@CA,C', [0, 3, 5]]
        self.assertRaises(ValueError, lambda: pt.rmsd(traj, mask=mask))

        mask_2 = [[0, 3, 6], range(50)]
        aa_eq(pt.rmsd(traj, mask=mask_2)[0], pt.rmsd(traj, mask=mask_2[0]))
        aa_eq(pt.rmsd(traj, mask=mask_2)[1], pt.rmsd(traj, mask=mask_2[1]))

        ca = pt.select('@CA', traj.top)
        cb = pt.select('@CB', traj.top)
        aa_eq(pt.rmsd(traj, mask=ca), pt.rmsd(traj, mask=[ca, cb])[0])
        aa_eq(pt.rmsd(traj, mask=cb), pt.rmsd(traj, mask=[ca, cb])[1])

    def test_raise_savematrices_if_not_dataset(self):
        traj = self.traj.copy()
        self.assertRaises(
            ValueError,
            lambda: pt.rmsd(traj, mask='@CA savematrices', dtype='ndarray'))

    def test_not_update_coordinates(self):
        traj = self.traj[:]
        data = pt.rmsd(traj, ref=3, update_coordinate=False)

        # make sure coordinates are not updated
        aa_eq(traj.xyz, self.traj.xyz)

        # make sure give the same rmsd values
        aa_eq(pt.rmsd(traj, ref=3), data)

    def test_combine_nofit_mass_nomod(self):
        cm = '''
        parm {}
        trajin {}
        rms @CA nofit mass nomod
        '''.format(fn('tz2.parm7'), fn('tz2.nc'))
        state = pt.load_cpptraj_state(cm)
        state.run()

        unmut_traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7'))
        mut_traj = unmut_traj[:]

        data = pt.rmsd(mut_traj,
                       mask='@CA',
                       mass=True,
                       nofit=True,
                       update_coordinate=False)
        aa_eq(data, state.data[-1])