#!/usr/bin/env python # coding: utf-8 # ### A simple `A <-> B` reaction between 2 species with initial uniform concentrations across 3 bins, # with 1st-order kinetics in both directions, taken to equilibrium # # Diffusion NOT taken into account # # See also the experiment `reactions_single_compartment/react_1` # ### TAGS : "reactions 1D", "quick-start" # In[1]: LAST_REVISED = "June 6, 2025" LIFE123_VERSION = "1.0.0rc6" # Library version this experiment is based on # In[2]: #import set_path # Using MyBinder? Uncomment this before running the next cell! # In[3]: #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 life123 import ChemData, BioSim1D, check_version # In[4]: check_version(LIFE123_VERSION) # In[ ]: # # Initialize the System # In[5]: # Initialize the system chem_data = ChemData(names=["A", "B"]) # Diffusion NOT taken into account bio = BioSim1D(n_bins=3, chem_data=chem_data) # We'll specify the reactions later bio.set_uniform_concentration(chem_label="A", conc=10.) # Same across all bins bio.set_uniform_concentration(chem_label="B", conc=50.) # Same across all bins bio.describe_state() # In[ ]: # ## Enable History # In[6]: # Let's enable history - by default for all chemicals and all bins bio.enable_history(take_snapshot=True) # In[7]: bio.get_bin_history(bin_address=0) # In[8]: bio.get_bin_history(bin_address=1) # In[9]: bio.get_bin_history(bin_address=2) # In[ ]: # In[10]: # Specify the reaction reactions = bio.get_reactions() # Reaction A <-> B , with 1st-order kinetics in both directions reactions.add_reaction(reactants="A", products="B", forward_rate=3., reverse_rate=2.) reactions.describe_reactions() # In[ ]: # ### First Reaction Step # In[11]: # First step of reaction bio.react(time_step=0.1, n_steps=1) bio.describe_state() # NOTE: the concentration of the chemical species `A` is increasing, while that of `B` is decreasing. # All bins have identical concentrations; so, there's no diffusion (and we're not attempting to compute it; didn't specify diffusion rates) # In[12]: bio.get_bin_history(bin_address=0) # In[ ]: # ### Several more reaction steps # In[13]: # Several more steps bio.react(time_step=0.1, n_steps=10) bio.describe_state() # In[14]: bio.get_bin_history(bin_address=0) # In[15]: bio.get_bin_history(bin_address=2) # In[ ]: # ### Equilibrium # NOTE: Consistent with the 3/2 ratio of forward/reverse rates (and the 1st order reactions), # the systems settles in the following equilibrium: # # In[16]: bio.bin_snapshot(bin_address=0) # In[17]: # Verify that the reaction has reached equilibrium bio.get_reaction_handler().is_in_equilibrium(conc=bio.bin_snapshot(bin_address=0)) # In[ ]: # ## Plots of changes of concentration with time # In[18]: bio.plot_history_single_bin(bin_address=0, title="Reaction A <-> B . Concentrations at bin 0") # In[19]: # Same plot, but with a smoothed line bio.plot_history_single_bin(bin_address=0, title="Reaction A <-> B . Concentrations at bin 0", smoothed=True) # ## For more in-depth analysis of this reaction, see the experiment `reactions_single_compartment/react_1` # In[ ]: