Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion for_local_use.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
from mobspy import *

if __name__ == "__main__":
pass

A, B = BaseSpecies()
A.a1, A.a2, A.a3, B.b1, B.b2
C = A*B

~C.a1 >> Zero [10]

S = Simulation(A | C)
print(S.compile())
6 changes: 6 additions & 0 deletions mobspy/modules/compiler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from mobspy.modules.compiler_operator_functions import (
create_all_not_reactions as cof_create_all_not_reactions
)
from mobspy.simulation_logging.log_scripts import (
error as simlog_error,
warning as simlog_warning,
Expand Down Expand Up @@ -326,6 +329,9 @@ def compile(
parameters_used, parameters_for_sbml, parameters_in_counts
)

# Invert the not$ operators in all reactions
reactions_set = cof_create_all_not_reactions(reactions_set)

# BaseSpecies reactions for SBML with theirs respective parameters and rates
# What do I have so far
# Species_String_Dict and a set of reaction objects in Reactions_Set
Expand Down
129 changes: 129 additions & 0 deletions mobspy/modules/compiler_operator_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
from itertools import product as ite_product

from mobspy.modules.meta_class import Reactions
from mobspy.modules.meta_class import Reacting_Species
from mobspy.modules.meta_class import Zero

"""
Species and meta-species supporting scripts
"""
def create_all_not_reactions(reactions):

new_reactions_set = reactions

def include_new_combinations(r, attribute_to_get):
ignore_flag = True
for x in getattr(r, attribute_to_get):

if 'not$' in x['characteristics']:
new_reactions_set.remove(r)
ignore_flag = False
combinations = get_all_non_listed_characteristics(
x['object'],
x['characteristics'] - {'not$'},
)

for comb in combinations:
x['characteristics'] = comb
new_r = new_reaction_with_new_characteristics(r, x['object'], comb)
new_reactions_set.add(new_r)

return ignore_flag

has_not = True
while has_not:
has_not = False
loop_reactions = set(new_reactions_set) # Snapshot
for r in loop_reactions:
if not include_new_combinations(r, "reactants"):
has_not = True
if not include_new_combinations(r, "products"):
has_not = True

return new_reactions_set



def get_all_non_listed_characteristics(
species,
characteristics
):
"""
This function gets all characteristics related to a species except the ones listed bellow.
It uses inheritance to find all charactersitcs linked to a species
"""
operator_characteristics = {c for c in characteristics if '$' in c}

multi_list_char_struct = []
for spe in species.get_references():
if characteristics:
dimension_cha = {e for e in spe.get_characteristics() if e not in characteristics}
else:
dimension_cha = {}

if dimension_cha:
multi_list_char_struct.append(dimension_cha)

combinations = [set(combo) | operator_characteristics for combo in ite_product(*multi_list_char_struct)]

return combinations


def new_reaction_with_new_characteristics(
r,
spe_to_modify,
new_characteristics
):
"""
Create a copy of this reaction, replacing characteristics of a specific dict

:param dict_to_modify: The specific reactant/product dict to modify
:param new_characteristics: New characteristics set for that dict
:return: New Reactions object
"""
# Build new reactants list
React = Zero
for reactant in r.reactants:
if reactant['object'] == spe_to_modify:
# Use the new characteristics
rs = Reacting_Species(
reactant['object'],
new_characteristics,
reactant['stoichiometry'],
reactant['label']
)
else:
# Copy existing reactant
rs = Reacting_Species(
reactant['object'],
reactant['characteristics'],
reactant['stoichiometry'],
reactant['label']
)

React = React + rs

# Build new products list
Product = Zero
for product in r.products:
if product['object'] == spe_to_modify:
# Use the new characteristics
ps = Reacting_Species(
product['object'],
new_characteristics,
product['stoichiometry'],
product['label']
)
else:
# Copy existing product
ps = Reacting_Species(
product['object'],
product['characteristics'],
product['stoichiometry'],
product['label']
)

Product = Product +ps

# Create new reaction
return React >> Product [r.rate]
Loading