robustnet.kinetics

Define classes for metabolic kinetics.

Classes

Simulator

Fitter

Module Contents

class robustnet.kinetics.Simulator(model, exclude_metabs=None, exclude_end_metabs=True, exclude_stoy_only_metabs=False)[source]
model[source]
exclude_metabs = [][source]
stoy_mat[source]
ini_subs = [][source]
fin_pros = [][source]
enz_vars[source]
metabs_only_in_rate[source]
metab_vars[source]
kparams[source]
rate_exprs = [][source]
rxn_vars[source]
var_names[source]
v_fun[source]
v_fun_simple[source]
e_fun[source]
aug_stoy_mat = None[source]
_get_involved_enzymes(exclude_enzs)[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, either A or B may 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 vins and vouts may be empty.

Parameters:
  • exchange (bool) – If True, influxes and effluxes are included in the system, both in the function inputs and outputs.

  • derivative (bool) – If True, callable derivatives with respect to metabolites (x) and enzymes (e) are also returned.

_lambdify_e()[source]

Get a callable Hill equation function.

The callable takes inputs in the order: [t] + [eparams] where eparams includes kf, km, and kl for each enzyme.

The output is enzyme concentrations with shape: (n_enz_vars, 1). The order of enzymes follows self.enz_vars.

static _check_nan(x, label)[source]
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

_check_bounds(lb, ub)[source]
_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.

Parameters:
  • bounds (2-tuple or dict of 2-tuple) – Bounds for variables.

  • varnames (list) – Variable names for which bounds are retrieved.

_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 by lbs and ubs are 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'].

_check_optimizer(optimizer)[source]
_check_method(method)[source]
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 >= 0 or upper_bound <= 0 enforces 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. COBYQA is gradient-free and generally more robust for non-smooth problems, but may be slower. SLSQP is gradient-based and typically faster, but may struggle with highly nonlinear problems.

    Currently, COBYQA is only available when optimizer="scipy".

  • tol (float, optional) – Tolerance criterion for optimization convergence.

  • maxtime (float, optional) – Maximum optimization time (s) allowed. Only applicable when optimizer="nlopt".

_fit_flux_with_scipy(method, tol, u_ini, N, T, W, v_exp, v_lbs, v_ubs, pbar)[source]
_fit_flux_with_nlopt(method, tol, maxtime, u_ini, N, T, W, v_exp, v_lbs, v_ubs, n_vars, n_constrs, pbar)[source]