#!/usr/bin/env python # coding: utf-8 # ### A minimalist, "get-stared", demonstration for the reaction `A <-> B`, # with 1st-order kinetics in both directions, taken to equilibrium. # # "No frills!" For advanced graphics, analysis, diagnostics, fine-tuning, etc, please see other experiments. # # LAST REVISED: June 23, 2024 (using v. 1.0 beta36) # In[1]: import set_path # Importing this module will add the project's home directory to sys.path # In[2]: from life123 import UniformCompartment # In[ ]: # ## Initialize the System # In[3]: # Instantiate the simulator and specify the chemicals dynamics = UniformCompartment(names=["A", "B"]) # Reaction A <-> B , with 1st-order kinetics in both directions dynamics.add_reaction(reactants="A", products="B", forward_rate=3., reverse_rate=2.) dynamics.describe_reactions() # In[4]: # Set the initial concentrations of all the chemicals dynamics.set_conc({"A": 80., "B": 10.}) # ## Run the reaction # In[5]: dynamics.single_compartment_react(initial_step=0.1, target_end_time=1.) # Using defaults for all other parameters # In[6]: dynamics.get_history() # The system's history, saved during the run of single_compartment_react() # ## Plots changes of concentration with time # Notice that adaptive variable time steps were automatically taken # In[7]: dynamics.plot_history(show_intervals=True) # In[8]: # Verify that the reaction has reached equilibrium dynamics.is_in_equilibrium() # In[ ]: