Skip to content

Commit afaf368

Browse files
2 parents cfac44f + e6bf75f commit afaf368

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

ionerdss/gillespie_simulation/adaptive_rates.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def adaptive_bimolecular_rate_1D(
143143
D_tot = np.sum([diffusion_constants[i] for i in reactant_ids])
144144
sigma = sigmalist[reactionid]
145145
ka = ratelist[reactionid]
146+
if b < sigma: raise ValueError(f'Too many molecules! b - sigma = {b-sigma:.2f} < 0')
146147
new_ratelist[reactionid] = ( 1/ka + (b-sigma)/3/D_tot )**(-1)
147148
reverse_reaction_id = reverse_reaction_pairs[reactionid]
148149
kb = ratelist[reverse_reaction_id]
@@ -157,6 +158,7 @@ def adaptive_bimolecular_rate_1D(
157158
D_tot = 2 * diffusion_constants[dimerization_id[0]]
158159
sigma = sigmalist[reactionid]
159160
ka = ratelist[reactionid]
161+
if b < sigma: raise ValueError(f'Too many molecules! b - sigma = {b-sigma:.2f} < 0')
160162
new_ratelist[reactionid] = ( 1/ka + (b-sigma)/3/D_tot )**(-1)
161163
reverse_reaction_id = reverse_reaction_pairs[reactionid]
162164
kb = ratelist[reverse_reaction_id]

ionerdss/gillespie_simulation/simple_gillespie.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

proaffinity-gnn/ProAffinity_GNN_inference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,6 @@ def run_proaffinity_inference(
795795

796796
# Example usage
797797
if __name__ == "__main__":
798-
run_proaffinity_inference("./pdbfiles/1i4d.pdbqt", "HL,F", verbose=True)
798+
run_proaffinity_inference("./pdbfiles/1i4d.pdbqt", "D,AB", verbose=True)
799799

800800

0 commit comments

Comments
 (0)