Sorting reactions in the increasing order

(per produced entity's concentration level)
This commit is contained in:
Artur Meski
2016-03-10 12:30:14 +01:00
parent 2387e8ad26
commit a6aa5e4590

View File

@@ -577,13 +577,32 @@ class ReactionSystemWithConcentrations(ReactionSystem):
for p_e in producible_entities: for p_e in producible_entities:
reactions_by_prod[p_e] = [] reactions_by_prod[p_e] = []
rcts_for_p_e = reactions_by_prod[p_e]
for r in self.reactions: for r in self.reactions:
product_entities = [e for e,c in r[2]] product_entities = [e for e,c in r[2]]
if p_e in product_entities: if p_e in product_entities:
reactants = r[0] reactants = r[0]
inhibitors = r[1] inhibitors = r[1]
products = [(e,c) for e,c in r[2] if e == p_e] products = [(e,c) for e,c in r[2] if e == p_e]
reactions_by_prod[p_e].append((reactants, inhibitors, products))
prod_conc = products[0][1]
insert_place = None
# we need to order the reactions w.r.t. the concentration levels produced (increasing order)
for i in range(0,len(rcts_for_p_e)):
checked_conc = rcts_for_p_e[i][2][0][1]
if prod_conc <= checked_conc:
insert_place = i
break
if insert_place == None: # empty or the is only one element which is smaller than the element being added
rcts_for_p_e.append((reactants, inhibitors, products)) # we append (to the end)
else:
rcts_for_p_e.insert(insert_place,(reactants, inhibitors, products))
# save in cache # save in cache
self.reactions_by_prod = reactions_by_prod self.reactions_by_prod = reactions_by_prod