westpa.core.kinetics package

westpa.core.kinetics module

Kinetics analysis library

class westpa.core.kinetics.RateAverager(bin_mapper, system=None, data_manager=None, work_manager=None)

Bases: object

Calculate bin-to-bin kinetic properties (fluxes, rates, populations) at 1-tau resolution

extract_data(iter_indices)

Extract data from the data_manger and place in dict mirroring the same underlying layout.

task_generator(iter_start, iter_stop, block_size)
calculate(iter_start=None, iter_stop=None, n_blocks=1, queue_size=1)

Read the HDF5 file and collect flux matrices and population vectors for each bin for each iteration in the range [iter_start, iter_stop). Break the calculation into n_blocks blocks. If the calculation is broken up into more than one block, queue_size specifies the maxmimum number of tasks in the work queue.

westpa.core.kinetics.calculate_labeled_fluxes(nstates, weights, parent_ids, micro_assignments, traj_assignments, fluxes)
westpa.core.kinetics.labeled_flux_to_rate(labeled_fluxes, labeled_pops, output=None)

Convert a labeled flux matrix and corresponding labeled bin populations to a labeled rate matrix.

westpa.core.kinetics.calculate_labeled_fluxes_alllags(nstates, weights, parent_ids, micro_assignments, traj_assignments, fluxes)
westpa.core.kinetics.nested_to_flat_matrix(input)

Convert nested flux/rate matrix into a flat supermatrix.

westpa.core.kinetics.nested_to_flat_vector(input)

Convert nested labeled population vector into a flat vector.

westpa.core.kinetics.flat_to_nested_matrix(nstates, nbins, input)

Convert flat supermatrix into nested matrix.

westpa.core.kinetics.flat_to_nested_vector(nstates, nbins, input)

Convert flat “supervector” into nested vector.

westpa.core.kinetics.find_macrostate_transitions(nstates, weights, label_assignments, state_assignments, dt, state, macro_fluxes, macro_counts, target_fluxes, target_counts, durations)
westpa.core.kinetics.sequence_macro_flux_to_rate(dataset, pops, istate, jstate, pairwise=True, stride=None)

Convert a sequence of macrostate fluxes and corresponding list of trajectory ensemble populations to a sequence of rate matrices.

If the optional pairwise is true (the default), then rates are normalized according to the relative probability of the initial state among the pair of states (initial, final); this is probably what you want, as these rates will then depend only on the definitions of the states involved (and never the remaining states). Otherwise (``pairwise’’ is false), the rates are normalized according the probability of the initial state among all other states.

class westpa.core.kinetics.WKinetics

Bases: object

w_kinetics()

westpa.core.kinetics.events module

westpa.core.kinetics.events.weight_dtype

alias of float64

westpa.core.kinetics.events.index_dtype

alias of uint16

westpa.core.kinetics.events.find_macrostate_transitions(nstates, weights, label_assignments, state_assignments, dt, state, macro_fluxes, macro_counts, target_fluxes, target_counts, durations)
class westpa.core.kinetics.events.WKinetics

Bases: object

w_kinetics()

westpa.core.kinetics.matrates module

Routines for implementing Letteri et al.’s macrostate-to-macrostate rate calculations using extrapolation to steady-state populations from average rate matrices

Internally, “labeled” objects (bin populations labeled by history, rate matrix elements labeled by history) are stored as nested arrays – e.g. rates[initial_label, final_label, initial_bin, final_bin]. These are converted to the flat forms required for, say, eigenvalue calculations internally, and the results converted back. This is because these conversions are not expensive, and saves users of this code from having to know how the flattened indexing works (something I screwed up all too easily during development) – mcz

westpa.core.kinetics.matrates.weight_dtype

alias of float64

westpa.core.kinetics.matrates.calculate_labeled_fluxes(nstates, weights, parent_ids, micro_assignments, traj_assignments, fluxes)
westpa.core.kinetics.matrates.calculate_labeled_fluxes_alllags(nstates, weights, parent_ids, micro_assignments, traj_assignments, fluxes)
westpa.core.kinetics.matrates.labeled_flux_to_rate(labeled_fluxes, labeled_pops, output=None)

Convert a labeled flux matrix and corresponding labeled bin populations to a labeled rate matrix.

westpa.core.kinetics.matrates.nested_to_flat_matrix(input)

Convert nested flux/rate matrix into a flat supermatrix.

westpa.core.kinetics.matrates.nested_to_flat_vector(input)

Convert nested labeled population vector into a flat vector.

westpa.core.kinetics.matrates.flat_to_nested_vector(nstates, nbins, input)

Convert flat “supervector” into nested vector.

exception westpa.core.kinetics.matrates.ConsistencyWarning

Bases: UserWarning

westpa.core.kinetics.matrates.get_steady_state(rates)

Get steady state solution for a rate matrix. As an optimization, returns the flattened labeled population vector (of length nstates*nbins); to convert to the nested vector used for storage, use nested_to_flat_vector().

westpa.core.kinetics.matrates.get_macrostate_rates(labeled_rates, labeled_pops, extrapolate=True)

Using a labeled rate matrix and labeled bin populations, calculate the steady state probability distribution and consequent state-to-state rates.

Returns (ss, macro_rates), where ss is the steady-state probability distribution and macro_rates is the state-to-state rate matrix.

westpa.core.kinetics.matrates.estimate_rates(nbins, state_labels, weights, parent_ids, bin_assignments, label_assignments, state_map, labeled_pops, all_lags=False, labeled_fluxes=None, labeled_rates=None, unlabeled_rates=None)

Estimate fluxes and rates over multiple iterations. The number of iterations is determined by how many vectors of weights, parent IDs, bin assignments, and label assignments are passed.

If all_lags is true, then the average is over all possible lags within the length-N window given, otherwise simply the length N lag.

Returns labeled flux matrix, labeled rate matrix, and unlabeled rate matrix.

westpa.core.kinetics.rate_averaging module

westpa.core.kinetics.rate_averaging.namedtuple(typename, field_names, *, rename=False, defaults=None, module=None)

Returns a new subclass of tuple with named fields.

>>> Point = namedtuple('Point', ['x', 'y'])
>>> Point.__doc__                   # docstring for the new class
'Point(x, y)'
>>> p = Point(11, y=22)             # instantiate with positional args or keywords
>>> p[0] + p[1]                     # indexable like a plain tuple
33
>>> x, y = p                        # unpack like a regular tuple
>>> x, y
(11, 22)
>>> p.x + p.y                       # fields also accessible by name
33
>>> d = p._asdict()                 # convert to a dictionary
>>> d['x']
11
>>> Point(**d)                      # convert from a dictionary
Point(x=11, y=22)
>>> p._replace(x=100)               # _replace() is like str.replace() but targets named fields
Point(x=100, y=22)
class westpa.core.kinetics.rate_averaging.zip_longest

Bases: object

zip_longest(iter1 [,iter2 […]], [fillvalue=None]) –> zip_longest object

Return a zip_longest object whose .__next__() method returns a tuple where the i-th element comes from the i-th iterable argument. The .__next__() method continues until the longest iterable in the argument sequence is exhausted and then it raises StopIteration. When the shorter iterables are exhausted, the fillvalue is substituted in their place. The fillvalue defaults to None or can be specified by a keyword argument.

westpa.core.kinetics.rate_averaging.flux_assign(weights, init_assignments, final_assignments, flux_matrix)
westpa.core.kinetics.rate_averaging.pop_assign(weights, assignments, populations)
westpa.core.kinetics.rate_averaging.calc_rates(fluxes, populations, rates, mask)

Calculate a rate matrices from flux and population matrices. A matrix of the same shape as fluxes, is also produced, to be used for generating a mask for the rate matrices where initial state populations are zero.

class westpa.core.kinetics.rate_averaging.StreamingStats1D

Bases: object

Calculate mean and variance of a series of one-dimensional arrays of shape (nbins,) using an online algorithm. The statistics are accumulated along what would be axis=0 if the input arrays were stacked vertically.

This code has been adapted from: http://www.johndcook.com/skewness_kurtosis.html

M1
M2
mean
n
update(x, mask)

Update the running set of statistics given

Parameters:
  • x (1d ndarray) – values from a single observation

  • mask (1d ndarray) – A uint8 array to exclude entries from the accumulated statistics.

var
class westpa.core.kinetics.rate_averaging.StreamingStats2D

Bases: object

Calculate mean and variance of a series of two-dimensional arrays of shape (nbins, nbins) using an online algorithm. The statistics are accumulated along what would be axis=0 if the input arrays were stacked vertically.

This code has been adapted from: http://www.johndcook.com/skewness_kurtosis.html

M1
M2
mean
n
update(x, mask)

Update the running set of statistics given

Parameters:
  • x (2d ndarray) – values from a single observation

  • mask (2d ndarray) – A uint8 array to exclude entries from the accumulated statistics.

var
class westpa.core.kinetics.rate_averaging.StreamingStatsTuple(M1, M2, n)

Bases: tuple

Create new instance of StreamingStatsTuple(M1, M2, n)

M1

Alias for field number 0

M2

Alias for field number 1

n

Alias for field number 2

westpa.core.kinetics.rate_averaging.grouper(n, iterable, fillvalue=None)

Collect data into fixed-length chunks or blocks

westpa.core.kinetics.rate_averaging.tuple2stats(stat_tuple)
westpa.core.kinetics.rate_averaging.process_iter_chunk(bin_mapper, iter_indices, iter_data=None)

Calculate the flux matrices and populations of a set of iterations specified by iter_indices. Optionally provide the necessary arrays to perform the calculation in iter_data. Otherwise get data from the data_manager directly.

class westpa.core.kinetics.rate_averaging.RateAverager(bin_mapper, system=None, data_manager=None, work_manager=None)

Bases: object

Calculate bin-to-bin kinetic properties (fluxes, rates, populations) at 1-tau resolution

extract_data(iter_indices)

Extract data from the data_manger and place in dict mirroring the same underlying layout.

task_generator(iter_start, iter_stop, block_size)
calculate(iter_start=None, iter_stop=None, n_blocks=1, queue_size=1)

Read the HDF5 file and collect flux matrices and population vectors for each bin for each iteration in the range [iter_start, iter_stop). Break the calculation into n_blocks blocks. If the calculation is broken up into more than one block, queue_size specifies the maxmimum number of tasks in the work queue.