Skip to content

Commit

Permalink
Only run FVA if the solution is feasible; Add print statement
Browse files Browse the repository at this point in the history
  • Loading branch information
YinHoon committed Mar 13, 2020
1 parent 2862db5 commit 618f698
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions wc_model_gen/eukaryote/metabolism.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,19 +564,25 @@ def calibrate_submodel(self):
})
result = conv_model.solve()
growth = result.value/scale_factor*coef_scale_factor

# Relax bounds if necessary
if growth < measured_growth:
target = {'biomass_reaction': measured_growth}
lower, upper = self.relax_bounds(target, lower_bound_adjustable, upper_bound_adjustable)
for reaction_id, adjustment in lower.items():
conv_variables[reaction_id].lower_bound -= adjustment*scale_factor
for reaction_id, adjustment in upper.items():
conv_variables[reaction_id].upper_bound += adjustment*scale_factor

# Impute kinetic constants with no measured values based on range values from Flux Variability Analysis
flux_range = self.flux_variability_analysis(conv_model)
self.impute_kinetic_constant(flux_range)

print('Optimized flux through biomass reaction before calibration is {}'.format(growth))

if not numpy.isnan(growth):
# Relax bounds if necessary
lower = upper = {}
if growth < measured_growth:
target = {'biomass_reaction': measured_growth}
lower, upper = self.relax_bounds(target, lower_bound_adjustable, upper_bound_adjustable)
for reaction_id, adjustment in lower.items():
conv_variables[reaction_id].lower_bound -= adjustment*scale_factor
for reaction_id, adjustment in upper.items():
conv_variables[reaction_id].upper_bound += adjustment*scale_factor
# Impute kinetic constants with no measured values based on range values from Flux Variability Analysis
if any(numpy.isnan(i) for i in lower.values()) or any(numpy.isnan(i) for i in upper.values()):
pass
else:
flux_range = self.flux_variability_analysis(conv_model)
self.impute_kinetic_constant(flux_range)

def relax_bounds(self, target, lower_bound_adjustable, upper_bound_adjustable):
""" Relax bounds to achieve set target flux(es) while minimizing the total necessary adjustment
Expand Down

0 comments on commit 618f698

Please sign in to comment.