A <-> B,¶with 1st-order kinetics in both directions, taken to equilibrium.
"No frills!" Please see other experiments for advanced graphics, analysis, diagnostics, fine-tuning, etc.
LAST_REVISED = "Aug. 29, 2025"
LIFE123_VERSION = "1.0.0rc6" # Library version this experiment is based on
#import set_path # Using MyBinder? Uncomment this before running the next cell!
# Importing this module will add the project's home directory to sys.path
#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
import life123
life123.check_version(LIFE123_VERSION) # To check compatibility
OK
# Instantiate the simulator and specify the chemicals
uc = life123.UniformCompartment()
# Elementary Reaction A <-> B
uc.add_reaction(reactants="A", products="B",
kF=3., kR=2.)
uc.describe_reactions()
Number of reactions: 1 0: A <-> B (Elementary Unimolecular reaction) (kF = 3 / kR = 2 / delta_G = -1,005.1 / K = 1.5 / Temp = 25 C) Chemicals involved in the above reactions: ['A', 'B']
# Set the initial concentrations of all the chemicals
uc.set_conc({"A": 80., "B": 10.})
uc.single_compartment_react(initial_step=0.1, target_end_time=1.) # Using defaults for all other parameters
47 total variable step(s) taken in 0.100 sec
Number of step re-do's because of elective soft aborts: 3
Norm usage: {'norm_A': 26, 'norm_B': 22, 'norm_C': 22, 'norm_D': 22}
System Time is now: 1.1343
uc.get_history() # The system's history, saved during the run of single_compartment_react()
| SYSTEM TIME | A | B | step | caption | |
|---|---|---|---|---|---|
| 0 | 0.000000 | 80.000000 | 10.000000 | Set concentration | |
| 1 | 0.006400 | 78.592000 | 11.408000 | 1 | 1st reaction step |
| 2 | 0.009600 | 77.910528 | 12.089472 | 2 | |
| 3 | 0.013440 | 77.105846 | 12.894154 | 3 | |
| 4 | 0.018048 | 76.158767 | 13.841233 | 4 | |
| 5 | 0.023578 | 75.048458 | 14.951542 | 5 | |
| 6 | 0.029107 | 73.968846 | 16.031154 | 6 | |
| 7 | 0.034637 | 72.919083 | 17.080917 | 7 | |
| 8 | 0.040166 | 71.898344 | 18.101656 | 8 | |
| 9 | 0.045696 | 70.905827 | 19.094173 | 9 | |
| 10 | 0.052332 | 69.747735 | 20.252265 | 10 | |
| 11 | 0.058967 | 68.628067 | 21.371933 | 11 | |
| 12 | 0.065603 | 67.545546 | 22.454454 | 12 | |
| 13 | 0.072238 | 66.498940 | 23.501060 | 13 | |
| 14 | 0.078874 | 65.487058 | 24.512942 | 14 | |
| 15 | 0.085509 | 64.508749 | 25.491251 | 15 | |
| 16 | 0.093472 | 63.373726 | 26.626274 | 16 | |
| 17 | 0.101434 | 62.283893 | 27.716107 | 17 | |
| 18 | 0.109397 | 61.237449 | 28.762551 | 18 | |
| 19 | 0.117360 | 60.232668 | 29.767332 | 19 | |
| 20 | 0.125322 | 59.267889 | 30.732111 | 20 | |
| 21 | 0.134877 | 58.156249 | 31.843751 | 21 | |
| 22 | 0.144433 | 57.097717 | 32.902283 | 22 | |
| 23 | 0.153988 | 56.089758 | 33.910242 | 23 | |
| 24 | 0.163543 | 55.129955 | 34.870045 | 24 | |
| 25 | 0.175009 | 54.033218 | 35.966782 | 25 | |
| 26 | 0.186475 | 52.999357 | 37.000643 | 26 | |
| 27 | 0.197941 | 52.024769 | 37.975231 | 27 | |
| 28 | 0.211701 | 50.922312 | 39.077688 | 28 | |
| 29 | 0.225460 | 49.895700 | 40.104300 | 29 | |
| 30 | 0.239220 | 48.939717 | 41.060283 | 30 | |
| 31 | 0.255731 | 47.871459 | 42.128541 | 31 | |
| 32 | 0.272242 | 46.891393 | 43.108607 | 32 | |
| 33 | 0.292056 | 45.812407 | 44.187593 | 33 | |
| 34 | 0.311869 | 44.840314 | 45.159686 | 34 | |
| 35 | 0.335646 | 43.789365 | 46.210635 | 35 | |
| 36 | 0.359422 | 42.863355 | 47.136645 | 36 | |
| 37 | 0.387953 | 41.884245 | 48.115755 | 37 | |
| 38 | 0.422191 | 40.876927 | 49.123073 | 38 | |
| 39 | 0.456429 | 40.042050 | 49.957950 | 39 | |
| 40 | 0.497514 | 39.211704 | 50.788296 | 40 | |
| 41 | 0.546817 | 38.419979 | 51.580021 | 41 | |
| 42 | 0.605980 | 37.704113 | 52.295887 | 42 | |
| 43 | 0.676975 | 37.099191 | 52.900809 | 43 | |
| 44 | 0.762170 | 36.630965 | 53.369035 | 44 | |
| 45 | 0.864404 | 36.308436 | 53.691564 | 45 | |
| 46 | 0.987084 | 36.119241 | 53.880759 | 46 | |
| 47 | 1.134300 | 36.031470 | 53.968530 | 47 | last reaction step |
Notice that adaptive variable time steps were automatically taken
uc.plot_history(show_intervals=True)
# Verify that the reaction has reached equilibrium
uc.is_in_equilibrium()
0: A <-> B
Current concentrations: [A] = 36.03 ; [B] = 53.97
1. Ratio of reactant/product concentrations, adjusted for reaction orders: 1.49782
Formula used: [B] / [A]
2. Ratio of forward/reverse reaction rates: 1.5
Discrepancy between the two values: 0.1456 %
Reaction IS in equilibrium (within 1% tolerance)
True