2727from .estimators import MaximumLikelihoodMSM as _ML_MSM
2828from .estimators import ImpliedTimescales as _ImpliedTimescales
2929
30- from msmtools .flux import tpt as tpt_factory
3130from .models import MSM
3231from pyemma .util .annotators import shortcut
3332from pyemma .util import types as _types
@@ -1199,9 +1198,7 @@ def bayesian_hidden_markov_model(dtrajs, nstates, lag, nsamples=100, reversible=
11991198 dt_traj = dt_traj , conf = conf , store_hidden = store_hidden , show_progress = show_progress )
12001199 return bhmsm_estimator .estimate (dtrajs )
12011200
1202- # TODO: need code examples
1203- # Examples
1204- # --------
1201+
12051202def tpt (msmobj , A , B ):
12061203 r""" A->B reactive flux from transition path theory (TPT)
12071204
@@ -1221,29 +1218,29 @@ def tpt(msmobj, A, B):
12211218
12221219 Returns
12231220 -------
1224- tptobj : :class:`ReactiveFlux <msmtools.flux .ReactiveFlux>` object
1221+ tptobj : :class:`ReactiveFlux <pyemma.msm.reactive_flux .ReactiveFlux>` object
12251222 An object containing the reactive A->B flux network
12261223 and several additional quantities, such as the stationary probability,
12271224 committors and set definitions.
12281225
12291226 See also
12301227 --------
1231- :class:`ReactiveFlux <msmtools.flux .ReactiveFlux>`
1232- Reactive Flux object
1228+ :class:`ReactiveFlux <pyemma.msm.reactive_flux .ReactiveFlux>`
1229+ Reactive Flux model
12331230
12341231
1235- .. autoclass:: msmtools.flux .reactive_flux.ReactiveFlux
1232+ .. autoclass:: pyemma.msm .reactive_flux.ReactiveFlux
12361233 :members:
12371234 :undoc-members:
12381235
12391236 .. rubric:: Methods
12401237
1241- .. autoautosummary:: msmtools.flux .reactive_flux.ReactiveFlux
1238+ .. autoautosummary:: pyemma.msm .reactive_flux.ReactiveFlux
12421239 :methods:
12431240
12441241 .. rubric:: Attributes
12451242
1246- .. autoautosummary:: msmtools.flux .reactive_flux.ReactiveFlux
1243+ .. autoautosummary:: pyemma.msm .reactive_flux.ReactiveFlux
12471244 :attributes:
12481245
12491246 References
@@ -1268,10 +1265,88 @@ def tpt(msmobj, A, B):
12681265 from Short Off-Equilibrium Simulations.
12691266 Proc. Natl. Acad. Sci. USA, 106, 19011-19016 (2009)
12701267
1268+
1269+ Computes the A->B reactive flux using transition path theory (TPT)
1270+
1271+ Parameters
1272+ ----------
1273+ T : (M, M) ndarray or scipy.sparse matrix
1274+ Transition matrix (default) or Rate matrix (if rate_matrix=True)
1275+ A : array_like
1276+ List of integer state labels for set A
1277+ B : array_like
1278+ List of integer state labels for set B
1279+ mu : (M,) ndarray (optional)
1280+ Stationary vector
1281+ qminus : (M,) ndarray (optional)
1282+ Backward committor for A->B reaction
1283+ qplus : (M,) ndarray (optional)
1284+ Forward committor for A-> B reaction
1285+ rate_matrix = False : boolean
1286+ By default (False), T is a transition matrix.
1287+ If set to True, T is a rate matrix.
1288+
1289+ Returns
1290+ -------
1291+ tpt: msmtools.flux.ReactiveFlux object
1292+ A python object containing the reactive A->B flux network
1293+ and several additional quantities, such as stationary probability,
1294+ committors and set definitions.
1295+
1296+ Notes
1297+ -----
1298+ The central object used in transition path theory is
1299+ the forward and backward comittor function.
1300+
1301+ TPT (originally introduced in [1]) for continous systems has a
1302+ discrete version outlined in [2]. Here, we use the transition
1303+ matrix formulation described in [3].
1304+
1305+ See also
1306+ --------
1307+ msmtools.analysis.committor, ReactiveFlux
1308+
1309+ References
1310+ ----------
1311+ .. [1] W. E and E. Vanden-Eijnden.
1312+ Towards a theory of transition paths.
1313+ J. Stat. Phys. 123: 503-523 (2006)
1314+ .. [2] P. Metzner, C. Schuette and E. Vanden-Eijnden.
1315+ Transition Path Theory for Markov Jump Processes.
1316+ Multiscale Model Simul 7: 1192-1219 (2009)
1317+ .. [3] F. Noe, Ch. Schuette, E. Vanden-Eijnden, L. Reich and T. Weikl:
1318+ Constructing the Full Ensemble of Folding Pathways from Short Off-Equilibrium Simulations.
1319+ Proc. Natl. Acad. Sci. USA, 106, 19011-19016 (2009)
1320+
12711321 """
1322+ from msmtools .flux import flux_matrix , to_netflux
1323+ import msmtools .analysis as msmana
1324+
12721325 T = msmobj .transition_matrix
12731326 mu = msmobj .stationary_distribution
12741327 A = _types .ensure_ndarray (A , kind = 'i' )
12751328 B = _types .ensure_ndarray (B , kind = 'i' )
1276- tptobj = tpt_factory (T , A , B , mu = mu )
1277- return tptobj
1329+
1330+ if len (A ) == 0 or len (B ) == 0 :
1331+ raise ValueError ('set A or B is empty' )
1332+ n = T .shape [0 ]
1333+ if len (A ) > n or len (B ) > n or max (A ) > n or max (B ) > n :
1334+ raise ValueError ('set A or B defines more states, than given transition matrix.' )
1335+
1336+ # forward committor
1337+ qplus = msmana .committor (T , A , B , forward = True )
1338+ # backward committor
1339+ if msmana .is_reversible (T , mu = mu ):
1340+ qminus = 1.0 - qplus
1341+ else :
1342+ qminus = msmana .committor (T , A , B , forward = False , mu = mu )
1343+ # gross flux
1344+ grossflux = flux_matrix (T , mu , qminus , qplus , netflux = False )
1345+ # net flux
1346+ netflux = to_netflux (grossflux )
1347+
1348+ # construct flux object
1349+ from .models .reactive_flux import ReactiveFlux
1350+
1351+ F = ReactiveFlux (A , B , netflux , mu = mu , qminus = qminus , qplus = qplus , gross_flux = grossflux )
1352+ return F
0 commit comments