{ "cells": [ { "cell_type": "markdown", "id": "4e50d971", "metadata": {}, "source": [ "### `A <-> 3B` reaction, taken to equilibrium. \n", "#### A hypothetical scenario with 1st-order kinetics in both directions. \n", "### Examine State Space trajectory, using [A] and [B] as state variables\n", "\n", "1st-order kinetics in both directions\n", "\n", "See also the experiment `1D/reaction/reaction_2`\n", "\n", "LAST REVISED: June 23, 2024 (using v. 1.0 beta36)" ] }, { "cell_type": "code", "execution_count": 1, "id": "84bf7d8f-3ad4-4b5a-8b26-321122660f41", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Added 'D:\\Docs\\- MY CODE\\BioSimulations\\life123-Win7' to sys.path\n" ] } ], "source": [ "import set_path # Importing this module will add the project's home directory to sys.path" ] }, { "cell_type": "code", "execution_count": 2, "id": "8f60b9ca", "metadata": {}, "outputs": [], "source": [ "from experiments.get_notebook_info import get_notebook_basename\n", "\n", "from life123 import ChemData\n", "from life123 import UniformCompartment\n", "\n", "import plotly.express as px\n", "import plotly.graph_objects as go\n", "from life123 import GraphicLog" ] }, { "cell_type": "code", "execution_count": 3, "id": "180bfbdd", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-> Output will be LOGGED into the file 'state_space_1.log.htm'\n" ] } ], "source": [ "# Initialize the HTML logging\n", "log_file = get_notebook_basename() + \".log.htm\" # Use the notebook base filename for the log file\n", "\n", "# Set up the use of some specified graphic (Vue) components\n", "GraphicLog.config(filename=log_file,\n", " components=[\"vue_cytoscape_2\"],\n", " extra_js=\"https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.21.2/cytoscape.umd.js\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "610ce687-64a0-4ad8-a7df-a7d204b94684", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of reactions: 1 (at temp. 25 C)\n", "0: A <-> 3 B (kF = 5 / kR = 2 / delta_G = -2,271.4 / K = 2.5) | 1st order in all reactants & products\n", "Set of chemicals involved in the above reactions: {'A', 'B'}\n" ] } ], "source": [ "# Initialize the system\n", "chem_data = ChemData(names=[\"A\", \"B\"])\n", "\n", "\n", "# Reaction A <-> 3B , with 1st-order kinetics in both directions\n", "chem_data.add_reaction(reactants=\"A\", products=[(3,\"B\",1)], forward_rate=5., reverse_rate=2.)\n", "\n", "chem_data.describe_reactions()" ] }, { "cell_type": "code", "execution_count": 5, "id": "0423bb64-0481-4ea8-a566-f2d10d82574a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SYSTEM STATE at Time t = 0:\n", "2 species:\n", " Species 0 (A). Conc: 10.0\n", " Species 1 (B). Conc: 50.0\n", "Set of chemicals involved in reactions: {'A', 'B'}\n" ] } ], "source": [ "dynamics = UniformCompartment(chem_data=chem_data)\n", "dynamics.set_conc(conc={\"A\": 10., \"B\": 50.},\n", " snapshot=True)\n", "dynamics.describe_state()" ] }, { "cell_type": "code", "execution_count": 6, "id": "4b5e75e5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[GRAPHIC ELEMENT SENT TO LOG FILE `state_space_1.log.htm`]\n" ] } ], "source": [ "# Send the plot to the HTML log file\n", "chem_data.plot_reaction_network(\"vue_cytoscape_2\")" ] }, { "cell_type": "markdown", "id": "dfb4e9e3", "metadata": { "tags": [] }, "source": [ "### To equilibrium" ] }, { "cell_type": "code", "execution_count": 7, "id": "c3ed24bd-c237-491f-a2b9-676fc666b087", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "10 total step(s) taken\n" ] } ], "source": [ "dynamics.single_compartment_react(initial_step=0.05, n_steps=10, variable_steps=False)" ] }, { "cell_type": "code", "execution_count": 8, "id": "56e68446-bc47-4b0d-b772-bc206bacaec4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | SYSTEM TIME | \n", "A | \n", "B | \n", "caption | \n", "
|---|---|---|---|---|
| 0 | \n", "0.00 | \n", "10.000000 | \n", "50.000000 | \n", "Initialized state | \n", "
| 1 | \n", "0.05 | \n", "12.500000 | \n", "42.500000 | \n", "\n", " |
| 2 | \n", "0.10 | \n", "13.625000 | \n", "39.125000 | \n", "\n", " |
| 3 | \n", "0.15 | \n", "14.131250 | \n", "37.606250 | \n", "\n", " |
| 4 | \n", "0.20 | \n", "14.359063 | \n", "36.922812 | \n", "\n", " |
| 5 | \n", "0.25 | \n", "14.461578 | \n", "36.615266 | \n", "\n", " |
| 6 | \n", "0.30 | \n", "14.507710 | \n", "36.476870 | \n", "\n", " |
| 7 | \n", "0.35 | \n", "14.528470 | \n", "36.414591 | \n", "\n", " |
| 8 | \n", "0.40 | \n", "14.537811 | \n", "36.386566 | \n", "\n", " |
| 9 | \n", "0.45 | \n", "14.542015 | \n", "36.373955 | \n", "\n", " |
| 10 | \n", "0.50 | \n", "14.543907 | \n", "36.368280 | \n", "\n", " |