memote.support.consistency_helpers

Helper functions for stoichiometric consistency checks.

Module Contents

Functions

stoichiometry_matrix(metabolites, reactions) Return the stoichiometry matrix representation of a set of reactions.
nullspace(matrix, atol=1e-13, rtol=0.0) Compute an approximate basis for the null space (kernel) of a matrix.
memote.support.consistency_helpers.stoichiometry_matrix(metabolites, reactions)[source]

Return the stoichiometry matrix representation of a set of reactions.

The reactions and metabolites order is respected. All metabolites are expected to be contained and complete in terms of the reactions.

Parameters:
reactions : iterable

A somehow ordered list of unique reactions.

metabolites : iterable

A somehow ordered list of unique metabolites.

Returns:
numpy.array

The 2D array that represents the stoichiometry matrix.

dict

A dictionary mapping metabolites to row indexes.

dict

A dictionary mapping reactions to column indexes.

memote.support.consistency_helpers.nullspace(matrix, atol=1e-13, rtol=0.0)[source]

Compute an approximate basis for the null space (kernel) of a matrix.

The algorithm used by this function is based on the singular value decomposition of the given matrix.

Parameters:
matrix : ndarray

The matrix should be at most 2-D. A 1-D array with length k will be treated as a 2-D with shape (1, k)

atol : float

The absolute tolerance for a zero singular value. Singular values smaller than atol are considered to be zero.

rtol : float

The relative tolerance for a zero singular value. Singular values less than the relative tolerance times the largest singular value are considered to be zero.

Returns:
ndarray

If matrix is an array with shape (m, k), then the returned nullspace will be an array with shape (k, n), where n is the estimated dimension of the nullspace.

Notes

If both atol and rtol are positive, the combined tolerance is the maximum of the two; that is:

tol = max(atol, rtol * smax)

Singular values smaller than tol are considered to be zero.

References

Adapted from: https://scipy.github.io/old-wiki/pages/Cookbook/RankNullspace.html