<jupyter_start><jupyter_text>**One-bin A  2C + D, with 1st-order kinetics for each species,taken to equilibrium**LAST REVISED: June 13, 2022<jupyter_code>import set_path
set_path.add_ancestor_dir_to_syspath(3)  # The number of levels to go up 
                                         # to reach the project's home from the folder containing this notebook
from modules.chemicals.chemicals import Chemicals as chem
from modules.reactions.reactions import Reactions
from life_1D.bio_sim_1d import BioSim1D as bio

from modules.html_log.html_log import HtmlLog as log
# Initialize the system
chem_data = chem(diffusion_rates=[0.1, 0.1, 0.1], names=["A", "C", "D"])    # NOTE: diffusion_rates not used for now

rxn = Reactions(chem_data)

# Reaction A <-> 2C + D , with 1st-order kinetics for each species
rxn.add_reaction(reactants=[("A")], products=[(2, "C") , ("D")],
                 forward_rate=5., reverse_rate=2.)

bio.initialize_system(n_bins=1, chem_data=chem_data, reactions=rxn)

bio.set_all_uniform_concentrations( [4., 7., 2.] )

bio.describe_state()
rxn.describe_reactions()
rxn._internal_reactions_data()    # Low-level view of the reactions data
# First step
bio.react(time_step=0.2, n_steps=1)
bio.describe_state()<jupyter_output>1 bins and 3 species:

  Species 0 (A). Diff rate: 0.1. Conc:  [5.6]
  Species 1 (C). Diff rate: 0.1. Conc:  [3.8]
  Species 2 (D). Diff rate: 0.1. Conc:  [0.4]<jupyter_text>---       Note:  the above values are quite inaccurate because of the large time step 0.2    For example, the value for the concentration of D (0.4) is a wild overshot from the initial 2.0 to the equilibrium value of 1.68941267           A more precise calculation with bio.react(time_step=0.1, n_steps=2) gives conc_D(0.2) = 2.304           An even more precise calculation with bio.react(time_step=0.05, n_steps=4) gives conc_D(0.2) = 1.69037202           I.e. the system is almost at equilibrium already at t=0.2 !        TODO: explore the early dynamics of the system in a separate experiment---<jupyter_code># Numerous more steps
bio.react(time_step=0.05, n_steps=30)

bio.describe_state()<jupyter_output>1 bins and 3 species:

  Species 0 (A). Diff rate: 0.1. Conc:  [4.31058733]
  Species 1 (C). Diff rate: 0.1. Conc:  [6.37882534]
  Species 2 (D). Diff rate: 0.1. Conc:  [1.68941267]<jupyter_text>Consistent with the 5/2 ratio of forward/reverse rates (and the 1st order reactions),the systems settles in the following equilibrium:  [A] = 4.31058733 , [B] = 6.37882534 , [C] = 1.68941267<jupyter_code>A_eq = bio.bin_concentration(0, 0)
C_eq = bio.bin_concentration(0, 1)
D_eq = bio.bin_concentration(0, 2)
print(f"Ratio of equilibrium concentrations (C_eq * D_eq / A_eq) : {C_eq * D_eq / A_eq}")
print(f"Ratio of forward/reverse rates: {rxn.get_forward_rate(0) / rxn.get_reverse_rate(0)}")<jupyter_output>Ratio of equilibrium concentrations (C_eq * D_eq / A_eq) : 2.4999999999999996
Ratio of forward/reverse rates: 2.5
{'fraction_non_alphanumeric': 0.11514945652173914, 'fraction_numerical': 0.06385869565217392, 'mean_word_length': 4.0, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '650513', 'license': 'MIT', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1051, 'n_words': 316, 'path': 'experiments/life_1D/reaction/reaction_5.ipynb', 'repo_name': 'BrainAnnex/life123', 'size': '2944'}