Пример #1
0
def _va_sim(model):
    model.objective.direction = 'max'
    sol_max = safe_optim(model)

    model.objective.direction = 'min'
    sol_min = safe_optim(model)

    return sol_min, sol_max
Пример #2
0
def _va_sim(model, rxn, epsilon=EPSILON):
    lb, ub = rxn.bounds

    rxn.lower_bound = epsilon
    # model.objective.direction = 'max'
    sol_max = safe_optim(model)
    rxn.lower_bound = lb

    rxn.upper_bound = -epsilon
    # model.objective.direction = 'min'
    sol_min = safe_optim(model)
    rxn.upper_bound = ub

    return ~isnan(sol_min.objective_value), \
           ~isnan(sol_max.objective_value)
Пример #3
0
def simulate(available_uptake, model, variables, warm_start=None):

    model.logger.info('available_uptake = {}'.format(available_uptake))
    model.reactions.EX_glc__D_e.lower_bound = available_uptake
    model.growth_reaction.lower_bound = 0
    model.growth_reaction.upper_bound = 10

    model.objective = model.growth_reaction.id
    model.objective.direction = 'max'

    out = safe_optim(model)

    if model.solver.status == 'infeasible' or model.solver.status == 'time_limit':
        ret = {
            'obj': np.nan,
            'mu': np.nan,
            'mu_lb': np.nan,
            'mu_ub': np.nan,
            'available_substrate': available_uptake,
            'uptake': np.nan,
            'prot_ratio': np.nan,
            'mrna_ratio': np.nan
        }
        for var in variables:
            ret[var + '_lb'] = np.nan
            ret[var + '_ub'] = np.nan
        print('INFEASIBLE SOLUTION AT q={}'.format(available_uptake))
        return pd.Series(ret)

    growth_solution = copy(model.solution)
    mu_i, mu_lb, mu_ub = get_active_growth_bounds(model)
    mu = model.growth_reaction.flux
    # release_warm_start(model)

    try:
        prot_ratio = model.interpolation_variable.prot_ggdw.variable.primal
        mrna_ratio = model.interpolation_variable.mrna_ggdw.variable.primal
    except AttributeError:
        # Model without Neidhardt data
        prot_ratio = np.nan
        mrna_ratio = np.nan

    ret = {
        'obj': model.solution.objective_value,
        'mu': mu,
        'mu_lb': mu_lb,
        'mu_ub': mu_ub,
        'available_substrate': -1 * available_uptake,
        'uptake': -1 * growth_solution.fluxes['EX_glc__D_e'],
        'prot_ratio': prot_ratio,
        'mrna_ratio': mrna_ratio
    }

    fix_growth(model, model.solution)

    for var in variables:
        model.objective = model.variables.get(var)

        lb, ub = _va_sim(model)

        ret[var + '_lb'] = lb.objective_value
        ret[var + '_ub'] = ub.objective_value

    print(pd.Series(ret))

    release_growth(model)
    # apply_warm_start(model, growth_solution)

    return pd.Series(ret)