@@ -135,7 +135,7 @@ def run_Gillespie(
135135 full_update_scheme (bool): controls if update every propensity entry in each iteration. Defualt `full_update_scheme=False`.
136136 rate_update_rules (callable): How to update kinetic rates.
137137 It takes inputs (rate_constants, y_curr, reactant_matrix, volume)
138- avogadro=6.02214e23,
138+ avogadro=6.02214e23, set `avogadro=1` if Molar is not used in units.
139139 seed (int): Set random seed if given.
140140 excluded_volume (float): Consider excluded volume in 1D or other reasonable systems.
141141 excluded_species_id (int): Index of the species that creates excluded volume.
@@ -176,6 +176,8 @@ def run_Gillespie(
176176 raise ValueError ('To update rates, macroscopic rates must be provided.' )
177177 elif (rate_update_rules is not None ) and (bool (macroscopic )):
178178 need_update_rates = True
179+ # print('[DEBUG] rate_update_rules:', rate_update_rules)
180+ # print('[DEBUG] need_update_rates:', need_update_rates)
179181
180182 # process excluded volume
181183 if excluded_volume is not None :
@@ -198,15 +200,14 @@ def reduced_volume(y_curr, excluded_volume, volume):
198200 volume_corrected_rates = rate_constants
199201 elif bool (macroscopic ) ^ bool (volume_corrected ):
200202 if macroscopic :
203+ new_volume = reduced_volume (y_init , excluded_volume , volume )
201204 if need_update_rates :
202205 volume_corrected_rates = update_rates (
203- rate_constants , y_init , reduced_volume (y_init , excluded_volume , volume ),
204- rate_update_rules , reactant_matrix , avogadro
206+ rate_constants , y_init , new_volume , rate_update_rules , reactant_matrix , avogadro
205207 )
206208 else :
207209 volume_corrected_rates = rate_constants_volume_correction (
208- rate_constants , reactant_matrix ,
209- reduced_volume (y_init , excluded_volume , volume )
210+ rate_constants , reactant_matrix , new_volume , avogadro
210211 )
211212 else :
212213 volume_corrected_rates = rate_constants
@@ -232,22 +233,26 @@ def reduced_volume(y_curr, excluded_volume, volume):
232233 if seed is not None : np .random .seed (seed ) # set random seed if given
233234
234235 while time < max_time : # Control simulation time scale
236+
237+ # update volume if needed
238+ if excluded_volume is not None :
239+ new_volume = reduced_volume (y , excluded_volume , volume )
240+ volume_corrected_rates = rate_constants_volume_correction (
241+ rate_constants , reactant_matrix , new_volume , avogadro
242+ )
243+ else :
244+ new_volume = volume
235245
246+ # update rates if needed (adaptive rates)
247+ if need_update_rates : volume_corrected_rates = update_rates (
248+ rate_constants , y , new_volume , rate_update_rules , reactant_matrix , avogadro
249+ )
250+ # print('[DEBUG] volume corrected rates:', volume_corrected_rates)
236251 if full_update_scheme :
237- # update rates
238- if need_update_rates : volume_corrected_rates = update_rates (
239- rate_constants , y , reduced_volume (y , excluded_volume , volume ),
240- rate_update_rules , reactant_matrix , avogadro
241- )
242252 # Calculate propensity
243253 propensities = calculate_propensity (y , reactant_matrix , volume_corrected_rates )
244254
245255 else :
246- # update rates
247- if need_update_rates : volume_corrected_rates = update_rates (
248- rate_constants , y , reduced_volume (y , excluded_volume , volume ),
249- rate_update_rules , reactant_matrix , avogadro
250- )
251256 # Calculate propensity
252257 propensities = calculate_propensity (y , reactant_matrix , volume_corrected_rates ,
253258 propensities , is_propensity_update_needed )
0 commit comments