Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SamiralVdB committed Dec 20, 2024
1 parent 195c907 commit 24f1a77
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/PAModelpy/Enzyme.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from optlang.symbolics import Zero

from .CatalyticEvent import CatalyticEvent
from typing import Dict, Union, Optional
from typing import Dict, Union, Optional, Literal
from warnings import warn

def _change_catalytic_event_list_to_dictlist_after_unpickling(self):
Expand Down Expand Up @@ -97,7 +97,7 @@ def kcat_values(self):

@property
def concentration(
self, units: str = "mmol/gDW", return_units: bool = False
self, units: Literal['mmol/gDW', 'g/gDW'] = "mmol/gDW", return_units: bool = False
) -> float:
"""Returns the enzyme's total concentration considering any associated reactions.
Expand All @@ -113,11 +113,11 @@ def concentration(
concentration = self.enzyme_variable.concentration
if units == 'g/gDW':
#converting mmol to grams of protein:
# [g] = [mmol]* 1e-3 [mol/mmol] * MW[g/mol] *1e-6 [solver tolerance conversion factor]
concentration = concentration * 1e-3 * self.molmass*1e-6
# [g] = [mmol]* 1e-3 [mol/mmol] * MW[g/mol]
concentration = concentration * 1e-3 * self.molmass
if return_units:
return concentration*1e-6, units
return concentration*1e-6
return concentration, units
return concentration

@concentration.setter
def concentration(self, conc):
Expand Down
8 changes: 5 additions & 3 deletions src/PAModelpy/EnzymeSectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ def add(self, model):
if rxn_id in rxn2protein.keys():
del rxn2protein[rxn_id]
except:
print(model.reactions.query(rxn_id))
warn(
f"Reaction {rxn_id} is not in the model, this reaction will be skipped"
)
Expand Down Expand Up @@ -194,6 +193,11 @@ def add(self, model):
if enzyme_id in model.enzyme_variables and not self._enzyme_is_enzyme_complex(protein_reaction, enzyme_id):
enzyme = model.enzymes.get_by_id(enzyme_id)
self._add_reaction_to_enzyme(model, enzyme, rxn_id, kcat)
self.rxn2protein[rxn_id] = {**self.rxn2protein[rxn_id],
**{enzyme_id: {
**kcat,
'genes': enzyme.genes,
'protein_reaction_association': protein_reaction}}}

else:
if self.protein2gene != {}:
Expand All @@ -208,7 +212,6 @@ def add(self, model):
molmass=molmass,
genes=gene_list
)

if self._enzyme_is_enzyme_complex(protein_reaction, enzyme_id):
for pr in protein_reaction:
if len(pr) > 1:
Expand Down Expand Up @@ -252,7 +255,6 @@ def add(self, model):

# adding to the enzyme sector object for easy removal
model.tpc += 1

return model

def check_kcat_values(self, model, reaction, enzyme_dict):
Expand Down
15 changes: 9 additions & 6 deletions src/PAModelpy/PAModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ def parameter_filter(enz: Enzyme) -> bool:

# check kcat values
for kcatdict in kcats.values():
for kcat in kcatdict.values():
if kcat < 0:
for kcat_dict in kcatdict.values():
if kcat_dict < 0:
# invalid kcat value
warnings.warn(
'Turnover number for reaction "'
Expand All @@ -276,7 +276,8 @@ def parameter_filter(enz: Enzyme) -> bool:

# extract reaction from model
reaction = self.reactions.get_by_id(rxn_id)
for kcats in kcats.values():

for kcat_dict in kcats.values():
# check consistency between provided kcat values and reaction direction
if self._sensitivity:
lower_bound = -self.constraints[f"{rxn_id}_lb"].ub
Expand All @@ -286,23 +287,23 @@ def parameter_filter(enz: Enzyme) -> bool:
upper_bound = reaction.upper_bound
if lower_bound >= 0 and upper_bound > 0:
# reaction is irreversible in the forward direction
if "f" not in kcats: # or 'b' in kcats:
if "f" not in kcat_dict: # or 'b' in kcats:
warnings.warn(
rxn_id
+ ": Inconsistencies between the reaction reversibility and the provided kcat values"
)
return False
elif lower_bound < 0 and upper_bound <= 0:
# reaction is irreversible in the backward direction
if "b" not in kcats or "f" in kcats:
if "b" not in kcats or "f" in kcat_dict:
warnings.warn(
rxn_id
+ ": Inconsistencies between the reaction reversibility and the provided kcat values"
)
return False
else:
# reaction is reversible
if "f" not in kcats: # or 'b' not in kcats:
if "f" not in kcat_dict: # or 'b' not in kcats:
warnings.warn(
rxn_id
+ ": Inconsistencies between the reaction reversibility and the provided kcat values"
Expand Down Expand Up @@ -1338,12 +1339,14 @@ def change_reaction_bounds(
def change_reaction_ub(self, rxn_id: str, upper_bound: float = None):
if self._sensitivity:
self.constraints[rxn_id + "_ub"].ub = upper_bound
self.reactions.get_by_id(rxn_id).upper_bound = upper_bound*0.01
else:
self.reactions.get_by_id(rxn_id).upper_bound = upper_bound

def change_reaction_lb(self, rxn_id: str, lower_bound: float = None):
if self._sensitivity:
self.constraints[rxn_id + "_lb"].ub = -lower_bound
self.reactions.get_by_id(rxn_id).lower_bound = lower_bound*0.01
else:
self.reactions.get_by_id(rxn_id).lower_bound = lower_bound

Expand Down

0 comments on commit 24f1a77

Please sign in to comment.