Exemple #1
0
    def test_mfpt_between_sets(self):
        x = mfpt(self.P, [1, 2], origin=0)
        assert_allclose(x, self.o0t12)

        x = mfpt(self.P, [0, 1], origin=2)
        assert_allclose(x, self.o2t01)

        x = mfpt(self.P, 2, origin=[0, 1])
        assert_allclose(x, self.o01t2)

        x = mfpt(self.P, 0, origin=[1, 2])
        assert_allclose(x, self.o12t0)
Exemple #2
0
    def test_mfpt(self):
        x = mfpt(self.P, 0)
        assert_allclose(x, self.m0)

        x = mfpt(self.P, 1)
        assert_allclose(x, self.m1)

        x = mfpt(self.P, 2)
        assert_allclose(x, self.m2)

        x = mfpt(self.P, [0, 1])
        assert_allclose(x, self.m01)

        x = mfpt(self.P, [1, 2])
        assert_allclose(x, self.m12)
Exemple #3
0
def test_time_units():
    dtraj = np.random.randint(0, 4, 1000)
    tau = 12
    dt = 0.456
    msmobj = estimate_markov_model(dtraj, lag=tau, dt_traj='%f ns' % dt)

    # check MFPT consistency
    mfpt_ref = msmobj.mfpt([0], [1])
    tptobj = tpt(msmobj, [0], [1])
    assert_allclose(tptobj.mfpt, mfpt_ref)
    assert_allclose(mfpt(msmobj.P, [1], [0], tau=tau) * dt, mfpt_ref)
    assert_allclose(
        np.dot(msmobj.stationary_distribution, tptobj.backward_committor) /
        tptobj.total_flux, mfpt_ref)

    # check flux consistency
    total_flux_ref = tptobj.total_flux
    A = tptobj.A
    B = tptobj.B
    I = tptobj.I
    assert_allclose(
        tptobj.gross_flux[A, :][:, B].sum() +
        tptobj.gross_flux[A, :][:, I].sum(), total_flux_ref)
    assert_allclose(
        tptobj.net_flux[A, :][:, B].sum() + tptobj.net_flux[A, :][:, I].sum(),
        total_flux_ref)
    assert_allclose(
        tptobj.flux[A, :][:, B].sum() + tptobj.flux[A, :][:, I].sum(),
        total_flux_ref)
    mf = tptobj.major_flux(1.0)
    assert_allclose(mf[A, :][:, B].sum() + mf[A, :][:, I].sum(),
                    total_flux_ref)

    # check that the coarse-grained version is consistent too
    _, tptobj2 = tptobj.coarse_grain([A, I, B])
    assert_allclose(tptobj2.total_flux, total_flux_ref)
    assert_allclose(tptobj2.mfpt, mfpt_ref)