Skip to content

Commit

Permalink
Merge pull request #51 from andreastallvik/fix-sum-objective
Browse files Browse the repository at this point in the history
allow objective function to be a sum of multiple reactions
  • Loading branch information
dukovski authored Mar 6, 2024
2 parents 16c5b28 + 9b109a3 commit 04253a9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cometspy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,13 @@ def load_cobra_model(self, curr_m : cobra.Model, randomtag : bool = False):
if hasattr(curr_m, 'default_bounds'):
self.default_bounds = curr_m.default_bounds

obj = [str(x).split(':')[0]
for x in reaction_list
if x.objective_coefficient != 0][0]
self.objective = int(self.reactions[self.reactions.
REACTION_NAMES == obj]['ID'])
obj = {str(x).split(':')[0]:x.objective_coefficient
for x in reaction_list
if x.objective_coefficient != 0}
obj = {rx: -1 if coef < 0 else 1 for rx, coef in obj.items()}

self.objective = [int(self.reactions[self.reactions.
REACTION_NAMES == rx]['ID']) * coef for rx, coef in obj.items()]

if hasattr(curr_m, 'comets_optimizer'):
self.optimizer = curr_m.comets_optimizer
Expand Down Expand Up @@ -980,7 +982,7 @@ def write_comets_model(self, working_dir : str = None):
f.write(r'//' + '\n')

f.write('OBJECTIVE\n' +
' ' + str(self.objective) + '\n')
' ' + ' '.join([str(rx) for rx in self.objective]) + '\n')
f.write(r'//' + '\n')

f.write('METABOLITE_NAMES\n')
Expand Down

0 comments on commit 04253a9

Please sign in to comment.