<jupyter_start><jupyter_text>**A simple A  B reaction between 2 species with initial uniform concentrations,with 1st-order kinetics in both directions, taken to equilibrium**Diffusion (non-applicable) not doneLAST 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], names=["A", "B"])  # diffusion_rates NOT used for now
bio.initialize_system(n_bins=3, chem_data=chem_data)

bio.set_uniform_concentration(species_index=0, conc=10.)
bio.set_uniform_concentration(species_index=1, conc=50.)

bio.describe_state(show_diffusion_rates=True)
rxn = Reactions(chem_data)

# Reaction A -> B , with 1st-order kinetics in both directions
rxn.add_reaction(reactants=["A"], products=["B"], forward_rate=3., reverse_rate=2.)

bio.all_reactions = rxn

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

  Species 0 (A). Diff rate: 0.1. Conc:  [17. 17. 17.]
  Species 1 (B). Diff rate: 0.1. Conc:  [43. 43. 43.]<jupyter_text>NOTE: the concentration of species A is increasing, while that of species B is decreasing.All bins have identical concentrations; so, there's no diffusion:[[17. 17. 17.] [43. 43. 43.]]<jupyter_code># Numerous more steps
bio.react(time_step=0.1, n_steps=10)

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

  Species 0 (A). Diff rate: 0.1. Conc:  [23.99316406 23.99316406 23.99316406]
  Species 1 (B). Diff rate: 0.1. Conc:  [36.00683594 36.00683594 36.00683594]<jupyter_text>NOTE: Consistent with the 3/2 ratio of forward/reverse rates (and the 1st order reactions), the systems settles in the following equilibrium:[A] = 23.99316406 [B] = 36.00683594<jupyter_code>A_eq = bio.bin_concentration(0, 0)
B_eq = bio.bin_concentration(0, 1)
print(f"Ratio of equilibrium concentrations: {B_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: 1.5007122797020636
Ratio of forward/reverse rates: 1.5
{'fraction_non_alphanumeric': 0.10802469135802469, 'fraction_numerical': 0.06983024691358025, 'mean_word_length': 5.173809523809524, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '626252', 'license': 'MIT', 'n_tokens_mistral': 1037, 'n_tokens_neox': 884, 'n_words': 253, 'path': 'experiments/life_1D/reaction/reaction_1.ipynb', 'repo_name': 'BrainAnnex/life123', 'size': '2592'}