robustnet.kinetics¶
Define classes for metabolic kinetics.
Classes¶
Module Contents¶
- class robustnet.kinetics.Simulator(model, exclude_metabs=None, exclude_end_metabs=True, exclude_stoy_only_metabs=False)[source]¶
-
- _augment_stoichiometric_matrix()[source]¶
Augment the stoichiometric matrix by adding influxes (
vins) for initial substrates and effluxes (vouts) for final products.Note that adding influxes and effluxes may change the rank of the original stoichiometric matrix.
- _rank_decomposition()[source]¶
Decompose the stoichiometric matrix into a link matrix and a reduced stoichiometric matrix, both with full rank. Metabolites included in the reduced stoichiometric matrix are treated as independent.
Note that the assignments of independent and dependent metabolites within a conservation relationship are arbitrary. For example, if
A + B = constant, eitherAorBmay be selected as the independent metabolite, while the other is treated as dependent.
- _lambdify_v(exchange=True, derivative=False)[source]¶
Get callable reaction rate functions, including optional influxes (
vins) and effluxes (vouts).The callable takes inputs in the order:
[enz_vars] + [metab_vars] + [kparams] + [vins] + [vouts]and returns fluxes with shape:(len(vins) + len(vouts) + n_reactions, 1).If
derivative=True, callable derivatives with respect to metabolites (dv_dx) and enzymes (dv_de) are also returned. Their inputs are identical to the reaction-rate callable.The output shapes are:
dvdx_fun:(len(vins) + len(vouts) + n_reactions, n_metab_vars)dvde_fun:(len(vins) + len(vouts) + n_reactions, n_enz_vars)Note that
vinsandvoutsmay be empty.
- _lambdify_e()[source]¶
Get a callable Hill equation function.
The callable takes inputs in the order:
[t] + [eparams]whereeparamsincludeskf,km, andklfor each enzyme.The output is enzyme concentrations with shape:
(n_enz_vars, 1). The order of enzymes followsself.enz_vars.
- static _simulate_flux(es, xs, kparams, v_fun, check_nan=False)[source]¶
- Parameters:
es (numpy.array) – Enzyme concentrations in order of
self.enz_vars.xs (numpy.array) – Metabolite concentrations in order of
self.metab_vars.kparams (list) – Kinetic parameters in order of
self.kparams.v_fun (callable) – Function that that computes reaction fluxes from metabolite concentrations and other parameters.
check_nan (bool, optional) – If
True, check whether the simulation results contain NaN values.
- Returns:
v – Simulated fluxes with shape
(n_rxns,).- Return type:
numpy.array
- _get_bounds(bounds, varnames)[source]¶
Get lower and upper bounds for variables listed in
varnames.For variables not explicitly specified in
bounds, the minimum lower bound and maximum upper bound from the provided bounds are used.
- _get_initial_values(varnames, lbs, ubs, rng_seed=None, ref=None)[source]¶
Get initial values for variables listed in
varnames.If initial values are not provided in
ref, random values bounded bylbsandubsare generated.- Parameters:
varnames (list) – Variable names.
lbs (numpy.array) – Lower bounds in the same order as
varnames.ubs (numpy.array) – Upper bounds in the same order as
varnames.rng_seed (float or None.) – Seed of random number generator.
ref (dict, pandas.Series or None) – Reference values used as initial guesses.
- class robustnet.kinetics.Fitter(model, exclude_metabs=None, exclude_end_metabs=True)[source]¶
Bases:
Simulator- _check_fluxomics()[source]¶
Get the fluxomics data used for flux fitting.
- Returns:
flux_exp_fit (1-D numpy.array) – Experimental fluxomics measurements actually used for fitting.
flux_exp_std_fit (1-D numpy.array) – Standard deviations of the experimental fluxomics measurements actually used for fitting.
fluxes_fit (list) – Reaction IDs included in the fitting process.
indices (list) – Indices of the fitted reaction IDs in
self.var_names['vs'].
- fit_reference_fluxes(bounds, optimizer='scipy', method='COBYQA', tol=0.0001, maxtime=600)[source]¶
Estimate reference fluxes by fitting to fluxomics data.
- Parameters:
bounds (2-tuple or dict of 2-tuple) –
Lower and upper bounds used during fitting. If a tuple is provided, the same bounds are applied to all fluxes. If a dict is provided, bounds can be specified for individual fluxes, which is useful for defining flux reversibility. For example, Setting
lower_bound >= 0orupper_bound <= 0enforces irreversibility in the forward or reverse direction, respectively.Fluxes without explicit bounds use the minimum lower bound and maximum upper bound from the provided bounds.
optimizer ({"scipy", "nlopt"}, optional) – Optimizer used to solve the fitting problem. The NLopt package must be installed if
optimizer="nlopt"is selected.method ({"COBYQA", "SLSQP"}, optional) –
optimization method.
COBYQAis gradient-free and generally more robust for non-smooth problems, but may be slower.SLSQPis gradient-based and typically faster, but may struggle with highly nonlinear problems.Currently,
COBYQAis only available whenoptimizer="scipy".tol (float, optional) – Tolerance criterion for optimization convergence.
maxtime (float, optional) – Maximum optimization time (s) allowed. Only applicable when
optimizer="nlopt".