2 S <-> U and S <-> X¶Both mostly forward. 1st-order kinetics throughout.
Same as substeps_1, but with fixed steps: a lot of tiny steps - as a proxy for the "exact value"
LAST REVISED: May 25, 2023
import set_path # Importing this module will add the project's home directory to sys.path
Added 'D:\Docs\- MY CODE\BioSimulations\life123-Win7' to sys.path
from experiments.get_notebook_info import get_notebook_basename
from src.modules.reactions.reaction_data import ReactionData as chem
from src.modules.reactions.reaction_dynamics import ReactionDynamics
import numpy as np
import plotly.express as px
from src.modules.visualization.graphic_log import GraphicLog
# Initialize the HTML logging
log_file = get_notebook_basename() + ".log.htm" # Use the notebook base filename for the log file
# Set up the use of some specified graphic (Vue) components
GraphicLog.config(filename=log_file,
components=["vue_cytoscape_1"],
extra_js="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.21.2/cytoscape.umd.js")
-> Output will be LOGGED into the file 'substeps_2.log.htm'
# Initialize the system
chem_data = chem(names=["U", "X", "S"])
# Reaction 2 S <-> U , with 1st-order kinetics for all species (mostly forward)
chem_data.add_reaction(reactants=[(2, "S")], products="U",
forward_rate=8., reverse_rate=2.)
# Reaction S <-> X , with 1st-order kinetics for all species (mostly forward)
chem_data.add_reaction(reactants="S", products="X",
forward_rate=6., reverse_rate=3.)
chem_data.describe_reactions()
# Send the plot of the reaction network to the HTML log file
graph_data = chem_data.prepare_graph_network()
GraphicLog.export_plot(graph_data, "vue_cytoscape_1")
Number of reactions: 2 (at temp. 25 C) 0: 2 S <-> U (kF = 8 / kR = 2 / Delta_G = -3,436.56 / K = 4) | 1st order in all reactants & products 1: S <-> X (kF = 6 / kR = 3 / Delta_G = -1,718.28 / K = 2) | 1st order in all reactants & products [GRAPHIC ELEMENT SENT TO LOG FILE `substeps_2.log.htm`]
dynamics = ReactionDynamics(reaction_data=chem_data)
dynamics.set_conc(conc={"U": 50., "X": 100., "S": 0.})
dynamics.describe_state()
SYSTEM STATE at Time t = 0: 3 species: Species 0 (U). Conc: 50.0 Species 1 (X). Conc: 100.0 Species 2 (S). Conc: 0.0
dynamics.set_diagnostics() # To save diagnostic information about the call to single_compartment_react()
dynamics.single_compartment_react(initial_step=0.0001, target_end_time=0.3,
variable_steps=False)
df = dynamics.get_history()
df
3000 total step(s) taken
| SYSTEM TIME | U | X | S | caption | |
|---|---|---|---|---|---|
| 0 | 0.0000 | 50.000000 | 100.000000 | 0.000000 | Initial state |
| 1 | 0.0001 | 49.990000 | 99.970000 | 0.050000 | |
| 2 | 0.0002 | 49.980042 | 99.940039 | 0.099877 | |
| 3 | 0.0003 | 49.970126 | 99.910117 | 0.149631 | |
| 4 | 0.0004 | 49.960252 | 99.880234 | 0.199263 | |
| ... | ... | ... | ... | ... | ... |
| 2996 | 0.2996 | 59.344280 | 61.942266 | 19.369175 | |
| 2997 | 0.2997 | 59.347906 | 61.935304 | 19.368883 | |
| 2998 | 0.2998 | 59.351532 | 61.928345 | 19.368592 | |
| 2999 | 0.2999 | 59.355156 | 61.921388 | 19.368300 | |
| 3000 | 0.3000 | 59.358780 | 61.914432 | 19.368008 |
3001 rows × 5 columns
df.iloc[400]
SYSTEM TIME 0.04 U 48.449494 X 90.386964 S 12.714047 caption Name: 400, dtype: object
df.iloc[1850] # This data point is used in experiment `substeps_1`
SYSTEM TIME 0.185 U 54.529071 X 71.351769 S 19.590088 caption Name: 1850, dtype: object
(transition_times, step_sizes) = dynamics.explain_time_advance(return_times=True)
From time 0 to 0.3, in 3000 steps of 0.0001 (3000 steps total)
np.array(step_sizes)
array([1.e-04])
np.array(transition_times) # Note: there will be one more transition time (the end time) than step sizes
array([0. , 0.3])
dynamics.plot_curves(colors=['green', 'orange', 'blue'])