2A <-> 3B reaction, with 1st-order kinetics in both directions, taken to equilibrium¶Diffusion not applicable (just 1 bin)
LAST_REVISED = "May 4, 2025"
LIFE123_VERSION = "1.0.0rc3" # Library version this experiment is based on
#import set_path # Using MyBinder? Uncomment this before running the next cell!
#import sys, os
#os.getcwd()
#sys.path.append("C:/some_path/my_env_or_install") # CHANGE to the folder containing your venv or libraries installation!
# NOTE: If any of the imports below can't find a module, uncomment the lines above, or try: import set_path
from experiments.get_notebook_info import get_notebook_basename
from life123 import ChemData, BioSim1D, check_version
from life123 import GraphicLog
check_version(LIFE123_VERSION)
OK
# 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_2"],
extra_js="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.21.2/cytoscape.umd.js")
-> Output will be LOGGED into the file 'reaction_3.log.htm'
# Initialize the system
chem_data = ChemData(names=["A", "B"]) # NOTE: Diffusion not applicable (just 1 bin)
bio = BioSim1D(n_bins=1, chem_data=chem_data)
bio.set_uniform_concentration(chem_index=0, conc=10.)
bio.set_uniform_concentration(chem_index=1, conc=50.)
bio.describe_state()
SYSTEM STATE at Time t = 0: 1 bins and 2 chemical species:
| Species | Diff rate | Bin 0 | |
|---|---|---|---|
| 0 | A | None | 10.0 |
| 1 | B | None | 50.0 |
# Specify the reaction
reactions = bio.get_reactions()
# Reaction 2A <-> 3B , with 1st-order kinetics in both directions
reactions.add_reaction(reactants=[(2,"A",1)], products=[(3,"B",1)], forward_rate=5., reverse_rate=2.)
reactions.describe_reactions()
Number of reactions: 1 (at temp. 25 C)
0: 2 A <-> 3 B (kF = 5 / kR = 2 / delta_G = -2,271.4 / K = 2.5) | 1st order in all reactants & products
Set of chemicals involved in the above reactions: {'B', 'A'}
# Send the plot of the reaction network to the HTML log file
reactions.plot_reaction_network("vue_cytoscape_2")
[GRAPHIC ELEMENT SENT TO LOG FILE `reaction_3.log.htm`]
# Let's enable history - by default for all chemicals and all bins
bio.enable_history(take_snapshot=True, caption="Initial state")
History enabled for bins None and chemicals None (None means 'all')
bio.get_bin_history(bin_address=0)
| SYSTEM TIME | A | B | caption | |
|---|---|---|---|---|
| 0 | 0.0 | 10.0 | 50.0 | Initial state |
# First step
bio.react(time_step=0.05, n_steps=1)
bio.describe_state()
System Time is now: 0.05 SYSTEM STATE at Time t = 0.05: 1 bins and 2 chemical species:
| Species | Diff rate | Bin 0 | |
|---|---|---|---|
| 0 | A | None | 15.0 |
| 1 | B | None | 42.5 |
We're taking a smaller first step than in experiment "reaction_2", to avoid over-shooting the equilibrium value with too large a step!
# Numerous more steps
bio.react(time_step=0.1, n_steps=100)
bio.describe_state()
System Time is now: 10.05 SYSTEM STATE at Time t = 10.05: 1 bins and 2 chemical species:
| Species | Diff rate | Bin 0 | |
|---|---|---|---|
| 0 | A | None | 16.250 |
| 1 | B | None | 40.625 |
Consistent with the 5/2 ratio of forward/reverse rates (and the 1st order reactions), the systems settles in the following equilibrium: [A] = 16.25 , [B] = 40.625
# Verify that the reaction has reached equilibrium
bio.reaction_dynamics.is_in_equilibrium(rxn_index=0, conc=bio.bin_snapshot(bin_address = 0))
2 A <-> 3 B
Current concentrations: [A] = 16.25 ; [B] = 40.63
1. Ratio of reactant/product concentrations, adjusted for reaction orders: 2.5
Formula used: [B] / [A]
2. Ratio of forward/reverse reaction rates: 2.5
Discrepancy between the two values: 1.776e-14 %
Reaction IS in equilibrium (within 1% tolerance)
True
bio.get_bin_history(bin_address=0)
| SYSTEM TIME | A | B | caption | |
|---|---|---|---|---|
| 0 | 0.00 | 10.00 | 50.000 | Initial state |
| 1 | 0.05 | 15.00 | 42.500 | |
| 2 | 0.15 | 17.00 | 39.500 | |
| 3 | 0.25 | 15.80 | 41.300 | |
| 4 | 0.35 | 16.52 | 40.220 | |
| ... | ... | ... | ... | ... |
| 97 | 9.65 | 16.25 | 40.625 | |
| 98 | 9.75 | 16.25 | 40.625 | |
| 99 | 9.85 | 16.25 | 40.625 | |
| 100 | 9.95 | 16.25 | 40.625 | |
| 101 | 10.05 | 16.25 | 40.625 |
102 rows × 4 columns
bio.plot_history_single_bin(bin_address=0,
title="Reaction 2A <-> 3B . Concentrations at bin 0")
Variable, adaptive time steps are explored at length in the "reactions_single_compartment" experiments