#!/usr/bin/env python # coding: utf-8 # ### A minimalist 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: Dec. 3, 2023 # In[1]: import set_path # Importing this module will add the project's home directory to sys.path # In[2]: from src.modules.reactions.reaction_dynamics import ReactionDynamics # In[ ]: # ## Initialize the System # In[3]: # Instantiate the simulator and specify the chemicals dynamics = ReactionDynamics(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, in their declared index order dynamics.set_conc([80., 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(colors=['red', 'green'], show_intervals=True) # In[8]: # Verify that the reaction has reached equilibrium dynamics.is_in_equilibrium() # In[ ]: