Skip to content

Commit

Permalink
fix: address regression in loopless FVA (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdiener authored and Midnighter committed Apr 29, 2018
1 parent 7a3ec0e commit e897956
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cobra/flux_analysis/loopless.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def _add_cycle_free(model, fluxes):
rxn.bounds = (flux, flux)
continue
if flux >= 0:
rxn.lower_bound = max(0, rxn.lower_bound)
rxn.bounds = max(0, rxn.lower_bound), max(flux, rxn.upper_bound)
objective_vars.append(rxn.forward_variable)
else:
rxn.upper_bound = min(0, rxn.upper_bound)
rxn.bounds = min(flux, rxn.lower_bound), min(0, rxn.upper_bound)
objective_vars.append(rxn.reverse_variable)

model.objective.set_linear_coefficients(dict.fromkeys(objective_vars, 1.0))
Expand Down Expand Up @@ -208,11 +208,11 @@ def loopless_fva_iter(model, reaction, solution=False, zero_cutoff=1e-6):

with model:
_add_cycle_free(model, sol.fluxes)
flux = model.slim_optimize()
model.slim_optimize()

# If the previous optimum is maintained in the loopless solution it was
# loopless and we are done
if abs(flux - current) < zero_cutoff:
if abs(reaction.flux - current) < zero_cutoff:
if solution:
return sol
return current
Expand All @@ -221,11 +221,11 @@ def loopless_fva_iter(model, reaction, solution=False, zero_cutoff=1e-6):
# almost loopless solution containing only loops including the current
# reaction. Than remove all of those loops.
ll_sol = get_solution(model).fluxes
bounds = reaction.bounds
reaction.bounds = (current, current)
model.slim_optimize()
almost_ll_sol = get_solution(model).fluxes
reaction.bounds = bounds

with model:
# find the reactions with loops using the current reaction and remove
# the loops
for rxn in model.reactions:
Expand Down

0 comments on commit e897956

Please sign in to comment.