Skip to content

Commit 3d14517

Browse files
committed
Fixed parameter bug in initial values and with reaction expressions. Version 2.6.0
1 parent 7ec1b67 commit 3d14517

File tree

9 files changed

+86
-5
lines changed

9 files changed

+86
-5
lines changed

debugging_script.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
test_update_parameter_for_multi_model, test_update_parameter_through_str,
3535
test_update_multiple_parameters_in_expression, test_update_parameter_with_unit,
3636
test_species_value_modification, test_all_value_modification, test_new_reversible_reaction_notation,
37-
test_2D_reaction_with_units]
37+
test_2D_reaction_with_units, test_parameters_as_initial_values, test_parameters_in_lambda_expression]
3838

3939
# test_no_species_in_asg
4040
# test_illegal_unit_op_in_assignment

docs/example_models/journal_models/PySB_Comparison.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
L, R = BaseSpecies()
44

55
L_0, R_0, kf, kr = ModelParameters(100, 200, 1e-3, 1e-3)
6-
Rev[ L.sl_0(L_0) + R.sr_0(R_0) >> L.sl_1 + R.sr_1 ] [kf, lambda r: kr*r]
6+
L.sl_0 + R.sr_0 >> L.sl_1 + R.sr_1 [kf, lambda r: kr*r]
77

8+
L(L_0), R(R_0)
89
S = Simulation(L | R)
910
print(S.compile())
1011

for_local_use.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,13 @@
33

44
if __name__ == '__main__':
55

6-
pass
6+
L, R = BaseSpecies()
7+
8+
kf, kr = ModelParameters(1e-3, 1e-3)
9+
L.sl_0 + R.sr_0 >> L.sl_1 + R.sr_1[kf, lambda r: kr * r]
10+
11+
S = Simulation(L | R)
12+
print(S.compile())
13+
14+
15+

mobspy/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.5.1"
1+
__version__ = "2.6.0"

mobspy/modules/compiler.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def add_to_parameters_to_sbml(cls, parameters_used, parameters_for_sbml, paramet
3838
except:
3939
parameters_for_sbml[parameter.name] = (parameter.value, f'dimensionless')
4040

41+
4142
@classmethod
4243
def override_get_item(cls, object_to_return, item):
4344
"""
@@ -169,6 +170,7 @@ def compile(cls, meta_species_to_simulate, reactions_set, species_counts, orthog
169170

170171
# Check volume:
171172
volume = uh_convert_volume(volume, dimension)
173+
parameters_for_sbml = {'volume': (volume, f'dimensionless')}
172174

173175
# Add the flag species used for verifying if the simulation is over
174176
if continuous_sim:
@@ -183,6 +185,7 @@ def compile(cls, meta_species_to_simulate, reactions_set, species_counts, orthog
183185

184186
# Assignments with all do not take priority
185187
# This allows specific assignments to override All assignments
188+
# I should encapsulate this, to make my life easier lol
186189
assigned_species = []
187190
parameters_in_counts = set()
188191
for count in species_counts:
@@ -245,6 +248,8 @@ def compile(cls, meta_species_to_simulate, reactions_set, species_counts, orthog
245248
species_for_sbml[species_string] = temp_count
246249
assigned_species.append(species_string)
247250

251+
cls.add_to_parameters_to_sbml(parameters_used, parameters_for_sbml, parameters_in_counts)
252+
248253
# BaseSpecies reactions for SBML with theirs respective parameters and rates
249254
# What do I have so far
250255
# Species_String_Dict and a set of reaction objects in Reactions_Set
@@ -256,7 +261,6 @@ def compile(cls, meta_species_to_simulate, reactions_set, species_counts, orthog
256261
parameter_exist, parameters_in_reaction,
257262
skip_expression_check)
258263

259-
parameters_for_sbml = {'volume': (volume, f'dimensionless')}
260264
cls.add_to_parameters_to_sbml(parameters_used, parameters_for_sbml, parameters_in_reaction)
261265

262266
# O(n^2) reaction check for doubles

mobspy/modules/function_rate_code.py

+2
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,13 @@ def extract_reaction_rate(combination_of_reactant_species, reactant_string_list
8282
if parameter_exist:
8383
parameters_in_reaction = search_for_parameters_in_str(reaction_rate_string,
8484
parameter_exist, parameters_in_reaction)
85+
8586
elif isinstance(rate, mbe_MobsPyExpression):
8687

8788
# Having an expression variable implies it is a constructed expression - not mass action
8889
if len(rate._expression_variables) > 0:
8990
reaction_rate_string, _ = rate.generate_string_operation(skip_check=skip_check, dimension=dimension)
91+
parameters_in_reaction = parameters_in_reaction.union(rate._parameter_set)
9092

9193
# Having no expression variables implies it is a constant for mass - action kinetics.
9294
elif len(rate._expression_variables) == 0:

test_script.py

+24
Original file line numberDiff line numberDiff line change
@@ -2092,3 +2092,27 @@ def test_2D_reaction_with_units():
20922092
S.level = -1
20932093
S.volume = 1 * u.m ** 2
20942094
assert compare_model(S.compile(), 'test_tools/model_64.txt')
2095+
2096+
2097+
def test_parameters_as_initial_values():
2098+
2099+
L, R = BaseSpecies()
2100+
2101+
L_0, R_0 = ModelParameters(100, 200)
2102+
2103+
L(L_0), R(R_0)
2104+
S = Simulation(L | R)
2105+
S.level = -1
2106+
assert compare_model(S.compile(), 'test_tools/model_65.txt')
2107+
2108+
2109+
def test_parameters_in_lambda_expression():
2110+
L, R = BaseSpecies()
2111+
2112+
kf, kr = ModelParameters(1e-3, 1e-3)
2113+
L.sl_0 + R.sr_0 >> L.sl_1 + R.sr_1[kf, lambda r: kr * r]
2114+
2115+
S = Simulation(L | R)
2116+
S.level = -1
2117+
assert compare_model(S.compile(), 'test_tools/model_66.txt')
2118+

test_tools/model_65.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
Species
3+
L,L_0
4+
R,R_0
5+
6+
Mappings
7+
L :
8+
L
9+
R :
10+
R
11+
12+
Parameters
13+
L_0,100
14+
R_0,200
15+
volume,1
16+
17+
Reactions

test_tools/model_66.txt

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
Species
3+
L.sl_0,0
4+
L.sl_1,0
5+
R.sr_0,0
6+
R.sr_1,0
7+
8+
Mappings
9+
L :
10+
L.sl_0
11+
L.sl_1
12+
R :
13+
R.sr_0
14+
R.sr_1
15+
16+
Parameters
17+
kf,0.001
18+
kr,0.001
19+
volume,1
20+
21+
Reactions
22+
reaction_0,{'re': [(1, 'L.sl_0'), (1, 'R.sr_0')], 'pr': [(1, 'L.sl_1'), (1, 'R.sr_1')], 'kin': 'L.sl_0 * R.sr_0 * kf * volume^-1'}
23+
reaction_1,{'re': [(1, 'L.sl_1'), (1, 'R.sr_1')], 'pr': [(1, 'L.sl_0'), (1, 'R.sr_0')], 'kin': '(kr*L.sl_1)'}
24+

0 commit comments

Comments
 (0)