4
4
Bear in mind that they are not actually Python meta-classes. The first design utilized this feature but know there
5
5
are just regular classes
6
6
"""
7
- from mobspy .simulation_logging .log_scripts import error as simlog_error , debug as simlog_debug
7
+ from copy import deepcopy
8
+
9
+ from mobspy .simulation_logging .log_scripts import error as simlog_error , debug as simlog_debug , error
8
10
from mobspy .modules .species_string_generator import construct_all_combinations as ssg_construct_all_combinations
9
11
from mobspy .modules .assignments_implementation import Assign as asgi_Assign , Asg as asgi_Asg
10
12
from pint import Quantity
@@ -43,6 +45,30 @@ def override_get_item(cls, object_to_return, item):
43
45
cls .last_rate = item
44
46
return object_to_return
45
47
48
+ @classmethod
49
+ def process_rate (cls , rate ):
50
+
51
+ if isinstance (rate , (np_int_ , np_float_ )):
52
+ rate = float (rate )
53
+
54
+ if isinstance (rate , Species ) \
55
+ or isinstance (rate , Reacting_Species ) \
56
+ or isinstance (rate , Reactions ):
57
+ simlog_error ('Reaction rate of type ' + str (type (_Last_rate_storage .last_rate )) + ' not valid' ,
58
+ stack_index = 3 )
59
+
60
+ if not (type (rate ) == int or type (rate ) == float
61
+ or callable (rate ) or type (rate ) == str
62
+ or isinstance (rate , me_OverrideQuantity )
63
+ or isinstance (rate , Quantity )
64
+ or isinstance (rate , mp_Mobspy_Parameter )
65
+ or rate is None
66
+ or isinstance (rate , me_ExpressionDefiner )):
67
+ simlog_error ('Reaction rate of type ' + str (type (rate )) + ' not valid' ,
68
+ stack_index = 3 )
69
+
70
+ return rate
71
+
46
72
47
73
class Reactions :
48
74
"""
@@ -95,7 +121,7 @@ def __getitem__(self, item):
95
121
"""
96
122
return _Last_rate_storage .override_get_item (self , item )
97
123
98
- def __init__ (self , reactants , products ):
124
+ def __init__ (self , reactants , products , rate = None ):
99
125
"""
100
126
Constructor of the reaction object. For the object construction only the reactants and products are
101
127
necessary - the order and the rate are assigned later by the compiler
@@ -117,7 +143,37 @@ def __init__(self, reactants, products):
117
143
'A reaction was defined with the assignment context activated.'
118
144
'The assignment context was deactivated. Please try to redefine the model' )
119
145
120
- # Add characteristics in Cts_context to each reactant and product
146
+ # Setup rate - consider reversible reactions
147
+ try :
148
+ flag_len = len (_Last_rate_storage .last_rate ) == 2
149
+ except :
150
+ flag_len = False
151
+
152
+ if flag_len and rate is None :
153
+
154
+ store_last_rate = _Last_rate_storage .last_rate [0 ]
155
+ Reactions (reactants = products , products = reactants , rate = _Last_rate_storage .last_rate [1 ])
156
+ rate = _Last_rate_storage .process_rate (store_last_rate )
157
+
158
+ elif rate is not None and not flag_len :
159
+
160
+ rate = _Last_rate_storage .process_rate (rate )
161
+
162
+ elif rate is None and not flag_len :
163
+
164
+ rate = _Last_rate_storage .process_rate (_Last_rate_storage .last_rate )
165
+
166
+ elif rate is not None and flag_len :
167
+
168
+ rate = _Last_rate_storage .process_rate (rate )
169
+
170
+ else :
171
+ simlog_error ('To many rate provided' , stack_index = 3 )
172
+ self .rate = rate
173
+ if _Last_rate_storage .last_rate is not None :
174
+ _Last_rate_storage .last_rate = None
175
+
176
+ # Add characteristics in Cts_context to each reactant and product
121
177
if len (Species .meta_specie_named_any_context ) != 0 :
122
178
for j in Species .meta_specie_named_any_context :
123
179
for r in reactants :
@@ -143,29 +199,12 @@ def __init__(self, reactants, products):
143
199
144
200
# Assign default order
145
201
self .order = None
146
- # Cast np to float
147
- if isinstance (_Last_rate_storage .last_rate , (np_int_ , np_float_ )):
148
- _Last_rate_storage .last_rate = float (_Last_rate_storage .last_rate )
149
202
150
- if isinstance (_Last_rate_storage .last_rate , Species ) \
151
- or isinstance (_Last_rate_storage .last_rate , Reacting_Species ) \
152
- or isinstance (_Last_rate_storage .last_rate , Reactions ):
153
- simlog_error ('Reaction rate of type ' + str (type (_Last_rate_storage .last_rate )) + ' not valid' ,
154
- stack_index = 3 )
155
-
156
- if not (type (_Last_rate_storage .last_rate ) == int or type (_Last_rate_storage .last_rate ) == float
157
- or callable (_Last_rate_storage .last_rate ) or type (_Last_rate_storage .last_rate ) == str
158
- or isinstance (_Last_rate_storage .last_rate , me_OverrideQuantity )
159
- or isinstance (_Last_rate_storage .last_rate , Quantity )
160
- or isinstance (_Last_rate_storage .last_rate , mp_Mobspy_Parameter )
161
- or _Last_rate_storage .last_rate is None
162
- or isinstance (_Last_rate_storage .last_rate , me_ExpressionDefiner )):
163
- simlog_error ('Reaction rate of type ' + str (type (_Last_rate_storage .last_rate )) + ' not valid' ,
164
- stack_index = 3 )
203
+ # Define reversible reaction with two rates
165
204
166
- self . rate = _Last_rate_storage . last_rate
167
- if _Last_rate_storage .last_rate is not None :
168
- _Last_rate_storage .last_rate = None
205
+ # Cast np to float
206
+ # if _Last_rate_storage.last_rate is not None:
207
+ # _Last_rate_storage.last_rate = None
169
208
170
209
# Here we extract all involved objects to pact them in a set
171
210
# This is done to find the reactions associated with the species when the Compiler is started
0 commit comments