API Reference

msm_we.fpt

Adapted from the original NMpathAnalysis package, https://github.com/ZuckermanLab/NMpathAnalysis

msm_we.ensembles

Adapted from the original NMpathAnalysis package, https://github.com/ZuckermanLab/NMpathAnalysis

msm_we.nmm

Adapted from the original NMpathAnalysis package, https://github.com/ZuckermanLab/NMpathAnalysis

msm_we.utils

Adapted from the original NMpathAnalysis package, https://github.com/ZuckermanLab/NMpathAnalysis

Adapted from the original NMpathAnalysis package, https://github.com/ZuckermanLab/NMpathAnalysis

class msm_we.fpt.MatrixFPT[source]

Define a base class for calculating FPTs using transition matrix

classmethod mean_fpts(tmatrix, stateA, stateB, lag_time=1)[source]

Calculting mean-first passave time for at transition matrix

Derived class will implement this function differently.

classmethod directional_mfpt(transition_matrix, stateA, stateB, ini_probs=None, lag_time=1)[source]

Computes the mean-first passage time in a single direction using a recursive procedure

This method is useful when there is no B->A ensemble but only A->B transitions, for instance when B is absorbing.

transition_matrix: Numpy 2D array

stateA, stateB: List of integers

Both states are a list of indexes.

ini_probs: List of float, default is None

initial probabilities in stateA

lag_time: integer

Lag time used, the trajectory is “observed” every lag_time time steps

Returns

Return type

mean-first passage time from A->B

classmethod mfpts_to_target_microstate(transition_matrix, target, lag_time=1)[source]

Computes all the mean-first passage to a target microstate (k)

Returns a list where the i-element is mfpt(i->k). This function is useful to compute the mfpt matrix.

transition_matrix: Numpy 2D array

target: Integer number that specifies the index of the state. The indexes

should be consistent with the transition matrix and python (i.e. starting from 0)

lag_time: Integer

Lag time used, the trajectory is “observed” every lag_time time steps

Returns

  • a list where the i-element is mfpt(i->k). This function is

  • useful to compute the mfpt matrix.

classmethod mfpts_matrix(transition_matrix, lag_time=1)[source]

Calculate MFPT matrix, i.e., the matrix where the ij-element is MFPT(i->j)

transition_matrix: Numpy 2D array

lag_time: Integer

Lag time used, the trajectory is “observed” every lag_time time steps

Returns

Return type

mean-first passage time matrix with ij-element of MFPT(i->j)

classmethod min_commute_time(matrix_of_mfpts)[source]

Calculate minimum commuting time (round trip time) between all pairs

of microstates from the matrix of mfpts. It also returns the indexes of the pair of microstates involved.

matrix_of_mfpts: Numpy 2D array

matrix of MFPTs with ij-element of MFPT(i->j)

Returns

  • Minimum commuting time (round trip time) between all pairs

  • of microstates and the indexes of the pair of microstates involved.

classmethod max_commute_time(matrix_of_mfpts)[source]

Calculate maximum commuting time (round trip time) between all pairs

of microstates from the matrix of mfpts. It also returns the indexes of the pair of microstates involved.

matrix_of_mfpts: Numpy 2D array

matrix of MFPTs with ij-element of MFPT(i->j)

Returns

  • Maximum commuting time (round trip time) between all pairs

  • of microstates and the indexes of the pair of microstates involved.

classmethod fpt_distribution(t_matrix, initial_state, final_state, initial_distrib, min_power=1, max_power=12, max_n_lags=100, lag_time=1, dt=1.0, clean_recycling=False, logscale=False)[source]

Calculated distribution of first passage times from transition matrix

t_matrix: Numpy 2D array

initial_state, final_states: List of integer numbers

Specifies the indexes of initial and final states.

ini_probs: List of float, default is None

initial probabilities for initial states

min_power, max_power: Integer

The minimum and maximum power when the FPT distribution is shown in logscale such as (10^min_power, 10^max_power)*lag_time*dt.

max_n_lags: Integer

maximum number of lags when the FPT distribution is shown in linear scale such as (0, max_n_logs)*lag_time*dt. When in logscale, this is number of points to shown in the range of (10^min_power, 10^max_power)*lag_time*dt.

lag_time: Integer

Lag time used, the trajectory is “observed” every lag_time time steps

dt: Float

Time step

clean_recycling: Bool

Cleaning the recycling of steady state simulation if True

logscale: Bool

Option to use logscale for FPT time in the distribution

Returns

Return type

Distributions of first passage times

class msm_we.fpt.MarkovFPT[source]

Derived a class for calculating FPTs using Markovian transition matrix

classmethod mean_fpts(markov_tmatrix, stateA, stateB, lag_time=1)[source]

Computes mean first passage times using Markovian transition matrix

in both directions A->B and B->A from a markov model. The MFPTs computed in this way are directly comparable with the values obtained by a long back and forth simulation between the target states.

markov_matrix: Numpy 2D array

Markovian transition matrix

stateA, stateB: List of integers

Both states are a list of indexes.

lag_time: integer

Lag time used, the trajectory is “observed” every lag_time time steps

Returns

Return type

mean-first passage times from A->B and B->A

classmethod markov_commute_time(transition_matrix, stateA, stateB, lag_time=1)[source]

Computing commute time for Markovian Model

transition_matrix: Numpy 2D array

Markovian transition matrix

stateA, stateB: List of integers

Both states are a list of indexes.

lag_time: integer

Lag time used, the trajectory is “observed” every lag_time time steps

Returns

Return type

Commute time from mean-first passage times

class msm_we.fpt.NonMarkovFPT[source]

Derived a class for calculating FPTs using Non Markov transition matrix

classmethod mean_fpts(nm_transition_matrix, stateA, stateB, lag_time=1)[source]

Computes the mean first passage times from a non-markovian model

in both directions of A->B and B->A. The shape of the transition matrix should be (2*n_states, 2*n_states). Parameters: ———– nm_transition_matrix: Numpy 2D array

Non-Markovian transition matrix

stateA, stateB: List of integers

Both states are a list of indexes.

lag_time: integer

Lag time used, the trajectory is “observed” every lag_time time steps

Returns

Return type

mean-first passage times from A->B and B->A

Adapted from the original NMpathAnalysis package, https://github.com/ZuckermanLab/NMpathAnalysis

class msm_we.ensembles.Ensemble(trajectories=None, verbose=False, dtype='float32', discrete=False, lag_time=1, **kwargs)[source]

Define a base class to store a list of space-continuous trajectories

e.g.: [ trajectory1, trajectory2,…], each trajectory is just a matrix

where each row is a snapshot, and each column represents the evolution of the corresponding variable.

add_trajectory(trajectory)[source]

Add a single trajectory to the ensemble

empirical_mfpts(stateA, stateB)[source]

Calculate mean first passage time using direct counting method

empirical_corr_function(stateA, stateB, times, symmetric=True)[source]

Calculate correlation function for trajectories

class msm_we.ensembles.PathEnsemble(trajectories=None, verbose=False, dtype='float32', discrete=False, lag_time=1, stateA=None, stateB=None, **kwargs)[source]

Derive a class to store trajectories for path analysis

classmethod from_ensemble(ensemble, stateA=None, stateB=None, map_function=None, discrete=False, dtype='float32')[source]

Build a PathEnsemble from an ensemble object or a set of trajectories

class msm_we.ensembles.DiscreteEnsemble(trajectories=None, verbose=False, dtype='int32', discrete=True, lag_time=1, **kwargs)[source]

Define a base class to store a list of space-discrete trajectories

classmethod from_ensemble(ens, map_function=None, dtype='int32')[source]

Build a DiscreteEnsemble from an ensemble object or a set of trajectories

classmethod from_transition_matrix(transition_matrix, sim_length=None, initial_state=0)[source]

Generates a DiscreteEnsemble from the transition matrix

class msm_we.ensembles.DiscretePathEnsemble(trajectories=None, verbose=False, dtype='int32', discrete=True, lag_time=1, stateA=None, stateB=None, **kwargs)[source]

Derive a class to store a list of discrete trajectories for path analysis

classmethod from_transition_matrix(transition_matrix, stateA=None, stateB=None, n_paths=1000, ini_pops=None, max_iters=1000000000)[source]

Construct a path ensemble from a transition matrix

stateA: list, intitial state

stateB: list, final state

n_paths: integer, with default value of 1000

number of paths to generate

ini_pops: list or label, probability distribution over the

initial state used to generate the path

a) None Use a uniform distribution over the states in stateA c) list A list with the explicit values of the populations in stateA that should be used to generate the ensemble

max_iters: integer, with default value of 1000000000

maximum of iterations for generating path trajectories

classmethod from_ensemble(ensemble, stateA, stateB, map_function=None)[source]

Build a DiscreteEnsemble from an ensemble object or a set of trajectories

nm_mfpt(ini_probs=None, n_states=None)[source]

Compute the mean-first passage time from the transition matrix

weighted_fundamental_sequences(transition_matrix=None, symmetric=True)[source]

Generate sorted fundamental sequences with weights

Adapted from the original NMpathAnalysis package, https://github.com/ZuckermanLab/NMpathAnalysis

class msm_we.nmm.NonMarkovModel(trajectories, stateA, stateB, lag_time=1, clean_traj=False, sliding_window=True, reversible=True, markovian=False, coarse_macrostates=False, **kwargs)[source]

Define a class for analyzing MD trajectories using Markovian or non-Markovian Model

from a list of 1D trajectories of integers representing macrostates

For example:

trajectories = [ [1 , 2, 0, …], [2, 2, 1, …], [3, 1, 2, …], …]

If only one sequence is given in trajectories, the format is the same:

trajectories = [ [1 , 2, 0, …] ]

Parameters
  • (integer (lag_time) – Lag time of the model.

  • default – Lag time of the model.

  • (boolean) (sliding_window) – Use a sliding window of length lag_time to compute the count matrix

  • stateA – Define the initial and final macrostates in form of python lists for example: stateA=[0,2,5], stateB = [1]

  • lists) (stateB (python) – Define the initial and final macrostates in form of python lists for example: stateA=[0,2,5], stateB = [1]

n_states
Type

int

nm_cmatrix

Stores the number of transitions between states, the i,j element cij stores the number of transitions observed from i to j.

Type

array, with shape (2 n_states, 2 n_states)

populations[source]

Equilibrium population, the steady state solution of of the transition matrix

Type

array, shape (n_states,)

fit()[source]

Fits the non-Markovian model from a list of sequences

classmethod from_nm_tmatrix(transition_matrix, stateA, stateB, sim_length=None, initial_state=0)[source]

Generates a discrete ensemble from the transition matrix

empirical_mfpts()[source]

Calculate mean first passage time using direct counting method

corr_function(times)[source]

Compute the correlation function for a set of times.

Parameters

integers) (times (list of) – List of dt values used to compute the correlation function.

Returns

Return type

List of floats with the correlation values for the dt given in times

class msm_we.nmm.MarkovPlusColorModel(trajectories, stateA, stateB, lag_time=1, clean_traj=False, sliding_window=True, hist_length=0, **kwargs)[source]

Define a class for analyzing MD trajectories using Markovian Plus Color Model

fit()[source]

Fits the markov plus color model from a list of sequences

Adapted from the original NMpathAnalysis package, https://github.com/ZuckermanLab/NMpathAnalysis

class msm_we.utils.Interval(interval_set, n_variables)[source]

Intervals are in general defined as half-open interval [start,end).

in any case, in each dimension the interval is specified using a list [a,b] where a < b

  • For 1D (single) interval a single list in the form [a,b] has to be given

  • The union of multiple (1D) intervals can be specified as:

    [[a,b],[c,d],…]

  • A list of lists [[a,b],[c,d],…] are used for a n-dimensional

    intervals, one for each dimension, i.e, len(interval) = n_variables

  • A list-of-lists-of-lists for the mathematical union of n-dimensional

    intervals’

    [ [[a,b],[c,d],…], [[e,f],[g,h],…], … ]

msm_we.utils.reverse_sort_lists(list_1, list_2)[source]

Reverse sorting two list based on the first one

msm_we.utils.weighted_choice(list_, weights=None)[source]

Select an element from a list with probability from weights

msm_we.utils.get_shape(trajectory)[source]

Get the shape of a trajectory array in tuple (n_snapshots, n_variables)

msm_we.utils.num_of_nonzero_elements(my_vector)[source]

Returns the number of non-zero elements in a vector

msm_we.utils.normalize_markov_matrix(transition_matrix, reversible=False)[source]

Transform a matrix of positive elements to a markov-like matrix

by dividing each row by the sum of the elements of the row.

msm_we.utils.normalize(my_vector)[source]

Normalize a vector

by dividing each element by the total sum of all its elements

msm_we.utils.random_markov_matrix(n_states=5, seed=None)[source]

Returns a random transition markov matrix

msm_we.utils.check_tmatrix(t_matrix, accept_null_rows=True)[source]

Check if the given matrix is actually a row-stochastic transition matrix

i.e, all the elements are non-negative and the rows add to one.

If the keyword argument accept_null_rows is True, is going to accept rows where all the elements are zero. Those “problematic” states are going to be removed later if necessary by clean_tmatrix.

msm_we.utils.clean_tmatrix(transition_matrix, rm_absorbing=True)[source]

Removes the states/indexes with no transitions and that are absorbing

if the the keyword argument rm_absorbing is true Returns the “clean” transition matrix and a list with the removed states/indexes (clean_tmatrix, removed_states)

msm_we.utils.pops_from_tmatrix(transition_matrix)[source]

Calculate the eigen values and eigen vectors of the transposed transition matrix

Parameters

transition_matrix (ndarray with shape = (n_states, n_states)) –

Returns

Return type

the solution, p, of K.T p = p where K.T is the transposed transition matrix

msm_we.utils.pops_from_nm_tmatrix(transition_matrix)[source]

Computes the populations of the real/physical states

from a non-Markovian transtion matrix with shape (2*n_states, 2*n_states)

msm_we.utils.map_to_integers(sequence, mapping_dict=None)[source]

Map a sequence of elements to a sequence of integers for intance, maps [1, ‘a’, 1, ‘b’, 2.2] to [0, 1, 0, 2, 3]

msm_we.utils.pseudo_nm_tmatrix(markovian_tmatrix, stateA, stateB)[source]

Obtain a pseudo non-Markovian transition matrix from a Markovian transiton matrix

The pseudo Markovian matrix has a shape of (2 n_states, 2 n_states)