Exemple #1
0
    def test_with_almost_converged_stat_dist(self):
        """ test for #106 """
        from msmtools.analysis import committor, is_reversible
        from msmtools.flux import tpt, flux_matrix, to_netflux, ReactiveFlux

        T = np.array([[
            0.2576419223095193, 0.2254214623509954, 0.248270708174756,
            0.2686659071647294
        ],
                      [
                          0.2233847186210225, 0.2130434781715344,
                          0.2793477268264001, 0.284224076381043
                      ],
                      [
                          0.2118717275169231, 0.2405661227681972,
                          0.2943396213976011, 0.2532225283172787
                      ],
                      [
                          0.2328617711043517, 0.2485926610067547,
                          0.2571819311236834, 0.2613636367652102
                      ]])
        mu = np.array([
            0.2306979668517676, 0.2328013892993006, 0.2703312416016573,
            0.2661694022472743
        ])
        assert is_reversible(T)
        np.testing.assert_allclose(mu.dot(T), mu)
        np.testing.assert_equal(mu.dot(T), T.T.dot(mu))
        A = [0]
        B = [1]

        # forward committor
        qplus = committor(T, A, B, forward=True, mu=mu)
        # backward committor
        if is_reversible(T, mu=mu):
            qminus = 1.0 - qplus
        else:
            qminus = committor(T, A, B, forward=False, mu=mu)

        tpt_obj = tpt(T, A, B)
        tpt_obj.major_flux(1.0)
        # gross flux
        grossflux = flux_matrix(T, mu, qminus, qplus, netflux=False)
        # net flux
        netflux = to_netflux(grossflux)
        F = ReactiveFlux(A,
                         B,
                         netflux,
                         mu=mu,
                         qminus=qminus,
                         qplus=qplus,
                         gross_flux=grossflux)
        F.pathways(1.0)
Exemple #2
0
    def calc_committor(T, source, target, forward=None):
        """Calculate forward or backward committor for each node between source and target.

        Parameters
        ----------
        T : 2D numpy.ndarray.
            Row stochastic transition matrix.

        source : list.
            Source of probability flux. Committor value i will be the probability of leaving source and reaching node i
            before reaching target or source again.

        target : list.
            Sink of probability flux. Committor value i will be the probability of reaching target from node i before
            reaching source.

        forward : bool.
            If True, forward committor is calculated. If False, backward committor is calculated.

        Returns
        -------
        committor : 1D numpy.ndarray.
            Committor values in order of transition matrix.
        """
        committor = mana.committor(T, source, target, forward=forward)
        return committor
Exemple #3
0
    def committor(self, source, target, forward=True):
        """Compute the committor between sets of states.

        Parameters
        ----------
        source : Set
            The set of source states.
        target : Set
            The set of target states.
        forward : bool, optional
            If true, compute the forward committor (default). If false,
            compute the backward committor.

        Returns
        -------
        (M,) ndarray
            Vector of committor probabilities.

        """
        source = [self.index(state) for state in set(source)]
        target = [self.index(state) for state in set(target)]
        return msmana.committor(self.jump_matrix,
                                source,
                                target,
                                forward=forward)
Exemple #4
0
    def setUp(self):
        P = np.array([[0.8, 0.15, 0.05, 0.0,
                       0.0], [0.1, 0.75, 0.05, 0.05, 0.05],
                      [0.05, 0.1, 0.8, 0.0, 0.05], [0.0, 0.2, 0.0, 0.8, 0.0],
                      [0.0, 0.02, 0.02, 0.0, 0.96]])
        P = csr_matrix(P)
        A = [0]
        B = [4]
        mu = statdist(P)
        qminus = committor(P, A, B, forward=False, mu=mu)
        qplus = committor(P, A, B, forward=True, mu=mu)
        self.A = A
        self.B = B
        self.F = flux_matrix(P, mu, qminus, qplus, netflux=True)

        self.paths = [
            np.array([0, 1, 4]),
            np.array([0, 2, 4]),
            np.array([0, 1, 2, 4])
        ]
        self.capacities = [
            0.0072033898305084252, 0.0030871670702178975,
            0.00051452784503631509
        ]
Exemple #5
0
 def test_backward_comittor(self):
     P = self.bdc.transition_matrix_sparse()
     un = committor(P, list(range(10)), list(range(90, 100)), forward=False)
     u = self.bdc.committor_backward(9, 90)
     assert_allclose(un, u)
Exemple #6
0
 def test_backward_comittor(self):
     P = self.bdc.transition_matrix()
     un = committor(P, [0, 1], [8, 9], forward=False)
     u = self.bdc.committor_backward(1, 8)
     assert_allclose(un, u)
Exemple #7
0
def tpt(T, A, B, mu=None, qminus=None, qplus=None, rate_matrix=False):
    r""" Computes the A->B reactive flux using transition path theory (TPT)

    Parameters
    ----------
    T : (M, M) ndarray or scipy.sparse matrix
        Transition matrix (default) or Rate matrix (if rate_matrix=True)
    A : array_like
        List of integer state labels for set A
    B : array_like
        List of integer state labels for set B
    mu : (M,) ndarray (optional)
        Stationary vector
    qminus : (M,) ndarray (optional)
        Backward committor for A->B reaction
    qplus : (M,) ndarray (optional)
        Forward committor for A-> B reaction
    rate_matrix = False : boolean
        By default (False), T is a transition matrix.
        If set to True, T is a rate matrix.

    Returns
    -------
    tpt: msmtools.flux.ReactiveFlux object
        A python object containing the reactive A->B flux network
        and several additional quantities, such as stationary probability,
        committors and set definitions.

    Notes
    -----
    The central object used in transition path theory is
    the forward and backward comittor function.

    TPT (originally introduced in [1]) for continous systems has a
    discrete version outlined in [2]. Here, we use the transition
    matrix formulation described in [3].

    See also
    --------
    msmtools.analysis.committor, ReactiveFlux

    References
    ----------
    .. [1] W. E and E. Vanden-Eijnden.
        Towards a theory of transition paths.
        J. Stat. Phys. 123: 503-523 (2006)
    .. [2] P. Metzner, C. Schuette and E. Vanden-Eijnden.
        Transition Path Theory for Markov Jump Processes.
        Multiscale Model Simul 7: 1192-1219 (2009)
    .. [3] F. Noe, Ch. Schuette, E. Vanden-Eijnden, L. Reich and T. Weikl:
        Constructing the Full Ensemble of Folding Pathways from Short Off-Equilibrium Simulations.
        Proc. Natl. Acad. Sci. USA, 106, 19011-19016 (2009)

    """
    import msmtools.analysis as msmana

    if len(A) == 0 or len(B) == 0:
        raise ValueError('set A or B is empty')
    n = T.shape[0]
    if len(A) > n or len(B) > n or max(A) > n or max(B) > n:
        raise ValueError(
            'set A or B defines more states, than given transition matrix.')
    if (rate_matrix is False) and (not msmana.is_transition_matrix(T)):
        raise ValueError('given matrix T is not a transition matrix')
    if (rate_matrix is True):
        raise NotImplementedError(
            'TPT with rate matrix is not yet implemented - But it is very simple, so feel free to do it.'
        )

    # we can compute the following properties from either dense or sparse T
    # stationary dist
    if mu is None:
        mu = msmana.stationary_distribution(T)
    # forward committor
    if qplus is None:
        qplus = msmana.committor(T, A, B, forward=True)
    # backward committor
    if qminus is None:
        if msmana.is_reversible(T, mu=mu):
            qminus = 1.0 - qplus
        else:
            qminus = msmana.committor(T, A, B, forward=False, mu=mu)
    # gross flux
    grossflux = flux_matrix(T, mu, qminus, qplus, netflux=False)
    # net flux
    netflux = to_netflux(grossflux)

    # construct flux object
    from .reactive_flux import ReactiveFlux

    F = ReactiveFlux(A,
                     B,
                     netflux,
                     mu=mu,
                     qminus=qminus,
                     qplus=qplus,
                     gross_flux=grossflux)
    # done
    return F