Give parameters to model.optimize() #1329
Replies: 3 comments
-
Sorry for the late reply. The API of cobrapy and the cobratoolbox are pretty different, so generally you can't really translate code from one to the other. The first two arguments are easy to translate and are the defualt for from cobra.io import load_model
from cobra.util import fix_objective_as_constraint
model = load_model("textbook")
fix_objective_as_constraint(model)
obj = sum(1e-6 * rxn.flux_expression**2 for rxn in model.reactions)
model.objective = obj
model.objective_direction = "minimize"
sol = model.optimize()
|
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer. But when I run your solution I get the following error message: Traceback (most recent call last): In Matlab with the cobratoolbox there is no problem with GLPK as solver. The remaining options work only with a valid QP solver:
So it's not the normal L2 minimization and that's why there isn't a way to do it in COBRApy? |
Beta Was this translation helpful? Give feedback.
-
You do need a QP solver exactly the same as in Matlab (hence the note in their docs). GLPK does not support quadratic problems. You probably have another QP solver installed in your Matlab setup.
It is the normal L2 minimization in cobrapy as well, that is what the code above does. But minimizing the L2 norm is a quadratic programming problem. For cobrapy you can use cplex, gurobi or the free osqp solver ( |
Beta Was this translation helpful? Give feedback.
-
Hi, I am new to Cobrapy.
I used this command in the COBRA toolbox in MATLAB:
solution= optimizeCbModel(model,'max',1e-6);
Is there a simple way to do it in Cobrapy also?
When I use model.optimize(), I don't get the same results as in MATLAB.
Beta Was this translation helpful? Give feedback.
All reactions