Skip to content

Commit

Permalink
Fix OptMDFpathway
Browse files Browse the repository at this point in the history
  • Loading branch information
Paulocracy committed Apr 10, 2024
1 parent 34745a7 commit d3d423f
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions cnapy/gui_elements/thermodynamics_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ def make_model_irreversible(

if create_forward:
forward_reaction_id = cobra_reaction.id + forward_id
forward_reaction = copy.deepcopy(cobra_reaction)
forward_reaction.id = forward_reaction_id
forward_reaction = cobra.Reaction(id=forward_reaction_id, name=cobra_reaction.name)
forward_reaction.add_metabolites(cobra_reaction.metabolites)
if cobra_reaction.lower_bound >= 0:
forward_reaction.lower_bound = cobra_reaction.lower_bound
else:
forward_reaction.lower_bound = 0
forward_reaction.lower_bound = 0.0
forward_reaction.upper_bound = cobra_reaction.upper_bound
cobra_model.add_reactions([forward_reaction])

if create_reverse:
reverse_reaction_id = cobra_reaction.id + reverse_id
reverse_reaction = copy.deepcopy(cobra_reaction)
reverse_reaction.id = reverse_reaction_id

reverse_reaction = cobra.Reaction(id=reverse_reaction_id, name=cobra_reaction.name)
reverse_reaction.add_metabolites(cobra_reaction.metabolites)
metabolites_to_add = {}
for metabolite in reverse_reaction.metabolites:
metabolites_to_add[metabolite] = (
Expand All @@ -103,7 +103,6 @@ def make_model_irreversible(

if create_forward or create_reverse:
cobra_model.remove_reactions([cobra_reaction])

return cobra_model


Expand Down Expand Up @@ -506,7 +505,7 @@ def compute_optmdf(self):
R = STANDARD_R
T = STANDARD_T
optmdfpathway_lp = create_optmdfpathway_milp(
cobra_model=model,
cobra_model=make_model_irreversible(model, forward_id=self.FWDID, reverse_id=self.REVID),
dG0_values=dG0_values,
concentration_values=concentration_values,
extra_constraints=extra_constraints,
Expand Down Expand Up @@ -601,15 +600,15 @@ def set_boxes(self, solution: Dict[str, float], objective_value: float):
console_text += f"Reached objective value: {objective_value}"
console_text += f"\\nReached MDF @ optimum of objective: {optmdf} kJ/mol"
elif self.analysis_type == ThermodynamicAnalysisTypes.BOTTLENECK_ANALYSIS:
bottleneck_z_sum = combined_solution["bottleneck_z_sum"]
console_text += f"Number of deactivated bottlenecks to reach minimal MDF: {bottleneck_z_sum}"

combined_bottleneck_sum = 0
for key in combined_solution.keys():
if key.startswith("bottleneck_z_"):
if key == "bottleneck_z_sum":
continue
if combined_solution[key] > 0.1:
console_text += f"\\n* {key.replace('bottleneck_z_', '')}"
combined_bottleneck_sum += 1
console_text += f"\\n↳Total number of thermodynamically deactivated bottlenecks to reach minimal MDF: {combined_bottleneck_sum}"
console_text += "')"
self.central_widget.kernel_client.execute(console_text)
self.central_widget.show_bottom_of_console()

0 comments on commit d3d423f

Please sign in to comment.