robustnet.kinetics ================== .. py:module:: robustnet.kinetics .. autoapi-nested-parse:: Define classes for metabolic kinetics. Classes ------- .. autoapisummary:: robustnet.kinetics.Simulator robustnet.kinetics.Fitter Module Contents --------------- .. py:class:: Simulator(model, exclude_metabs=None, exclude_end_metabs=True, exclude_stoy_only_metabs=False) .. py:attribute:: model .. py:attribute:: exclude_metabs :value: [] .. py:attribute:: stoy_mat .. py:attribute:: ini_subs :value: [] .. py:attribute:: fin_pros :value: [] .. py:attribute:: enz_vars .. py:attribute:: metabs_only_in_rate .. py:attribute:: metab_vars .. py:attribute:: kparams .. py:attribute:: rate_exprs :value: [] .. py:attribute:: rxn_vars .. py:attribute:: var_names .. py:attribute:: v_fun .. py:attribute:: v_fun_simple .. py:attribute:: e_fun .. py:attribute:: aug_stoy_mat :value: None .. py:method:: _get_involved_enzymes(exclude_enzs) .. py:method:: _augment_stoichiometric_matrix() 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. .. py:method:: _rank_decomposition() 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. .. py:method:: _lambdify_v(exchange=True, derivative=False) 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. :param exchange: If ``True``, influxes and effluxes are included in the system, both in the function inputs and outputs. :type exchange: bool :param derivative: If ``True``, callable derivatives with respect to metabolites (``x``) and enzymes (``e``) are also returned. :type derivative: bool .. py:method:: _lambdify_e() 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``. .. py:method:: _check_nan(x, label) :staticmethod: .. py:method:: _simulate_flux(es, xs, kparams, v_fun, check_nan=False) :staticmethod: :param es: Enzyme concentrations in order of ``self.enz_vars``. :type es: numpy.array :param xs: Metabolite concentrations in order of ``self.metab_vars``. :type xs: numpy.array :param kparams: Kinetic parameters in order of ``self.kparams``. :type kparams: list :param v_fun: Function that that computes reaction fluxes from metabolite concentrations and other parameters. :type v_fun: callable :param check_nan: If ``True``, check whether the simulation results contain NaN values. :type check_nan: bool, optional :returns: **v** -- Simulated fluxes with shape ``(n_rxns,)``. :rtype: numpy.array .. py:method:: _check_bounds(lb, ub) .. py:method:: _get_bounds(bounds, varnames) 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. :param bounds: Bounds for variables. :type bounds: 2-tuple or dict of 2-tuple :param varnames: Variable names for which bounds are retrieved. :type varnames: list .. py:method:: _get_initial_values(varnames, lbs, ubs, rng_seed=None, ref=None) 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. :param varnames: Variable names. :type varnames: list :param lbs: Lower bounds in the same order as ``varnames``. :type lbs: numpy.array :param ubs: Upper bounds in the same order as ``varnames``. :type ubs: numpy.array :param rng_seed: Seed of random number generator. :type rng_seed: float or None. :param ref: Reference values used as initial guesses. :type ref: dict, pandas.Series or None .. py:class:: Fitter(model, exclude_metabs=None, exclude_end_metabs=True) Bases: :py:obj:`Simulator` .. py:method:: _check_fluxomics() 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']``. .. py:method:: _check_optimizer(optimizer) .. py:method:: _check_method(method) .. py:method:: fit_reference_fluxes(bounds, optimizer='scipy', method='COBYQA', tol=0.0001, maxtime=600) Estimate reference fluxes by fitting to fluxomics data. :param bounds: 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. :type bounds: 2-tuple or dict of 2-tuple :param optimizer: Optimizer used to solve the fitting problem. The NLopt package must be installed if ``optimizer="nlopt"`` is selected. :type optimizer: {"scipy", "nlopt"}, optional :param method: 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"``. :type method: {"COBYQA", "SLSQP"}, optional :param tol: Tolerance criterion for optimization convergence. :type tol: float, optional :param maxtime: Maximum optimization time (s) allowed. Only applicable when ``optimizer="nlopt"``. :type maxtime: float, optional .. py:method:: _fit_flux_with_scipy(method, tol, u_ini, N, T, W, v_exp, v_lbs, v_ubs, pbar) .. py:method:: _fit_flux_with_nlopt(method, tol, maxtime, u_ini, N, T, W, v_exp, v_lbs, v_ubs, n_vars, n_constrs, pbar)