{ "cells": [ { "cell_type": "markdown", "id": "49bcb5b0-f19d-4b96-a5f1-e0ae30f66d8f", "metadata": {}, "source": [ "## A cycle of reactions between `A`, `B` and `C` : (1) `A <-> B <-> C `\n", "#### the \"closing\" of the above cycle (the \"return\" path from `C` to `A`) is coupled with an \"energy donor\" reaction:\n", "## (2) `C + E_High <-> A + E_Low`\n", "#### where `E_High` and `E_Low` are, respectively, the high- and low- energy molecules that drive the cycle (for example, think of ATP/ADP). \n", "Comparisons are made between results obtained with 3 different time resolutions.\n", "\n", "All 1st-order kinetics. \n", "\n", "LAST REVISED: June 23, 2024 (using v. 1.0 beta36)" ] }, { "cell_type": "code", "execution_count": 1, "id": "10fcf04b-b30a-4c69-9488-1772ed805616", "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": "c37d4586", "metadata": { "tags": [] }, "outputs": [], "source": [ "from experiments.get_notebook_info import get_notebook_basename\n", "\n", "from life123 import ChemData\n", "from life123 import UniformCompartment\n", "from life123 import Numerical as num\n", "\n", "from life123 import GraphicLog" ] }, { "cell_type": "code", "execution_count": 3, "id": "cc53849f-351d-49e0-bfa8-22f8d8e22f8e", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-> Output will be LOGGED into the file 'cycles_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": "markdown", "id": "d6d3ca49-589d-49b7-8424-37c7b01bcacf", "metadata": {}, "source": [ "### Initialize the system" ] }, { "cell_type": "code", "execution_count": 4, "id": "23c15e66-52e4-495b-aa3d-ecddd8d16942", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of reactions: 3 (at temp. 25 C)\n", "0: A <-> B (kF = 9 / kR = 3 / delta_G = -2,723.4 / K = 3) | 1st order in all reactants & products\n", "1: B <-> C (kF = 8 / kR = 4 / delta_G = -1,718.3 / K = 2) | 1st order in all reactants & products\n", "2: C + E_high <-> A + E_low (kF = 1 / kR = 0.2 / delta_G = -3,989.7 / K = 5) | 1st order in all reactants & products\n", "Set of chemicals involved in the above reactions: {'E_high', 'C', 'B', 'E_low', 'A'}\n", "[GRAPHIC ELEMENT SENT TO LOG FILE `cycles_1.log.htm`]\n" ] } ], "source": [ "# Initialize the system\n", "chem_data = ChemData(names=[\"A\", \"B\", \"C\", \"E_high\", \"E_low\"])\n", "\n", "# Reaction A <-> B, mostly in forward direction (favored energetically)\n", "# Note: all reactions in this experiment have 1st-order kinetics for all species\n", "chem_data.add_reaction(reactants=\"A\", products=\"B\",\n", " forward_rate=9., reverse_rate=3.)\n", "\n", "# Reaction B <-> C, also favored energetically\n", "chem_data.add_reaction(reactants=\"B\", products=\"C\",\n", " forward_rate=8., reverse_rate=4.)\n", "\n", "# Reaction C + E_High <-> A + E_Low, also favored energetically, but kinetically slow\n", "# Note that, thanks to the energy donation from E, we can go \"upstream\" from C, to the higher-energy level of \"A\"\n", "chem_data.add_reaction(reactants=[\"C\" , \"E_high\"], products=[\"A\", \"E_low\"],\n", " forward_rate=1., reverse_rate=0.2)\n", "\n", "chem_data.describe_reactions()\n", "\n", "# Send the plot of the reaction network to the HTML log file\n", "chem_data.plot_reaction_network(\"vue_cytoscape_2\")" ] }, { "cell_type": "markdown", "id": "d1d0eabb-b5b1-4e15-846d-5e483a5a24a7", "metadata": {}, "source": [ "### Set the initial concentrations of all the chemicals" ] }, { "cell_type": "code", "execution_count": 5, "id": "e4ff6a84-f5d5-4645-9c56-d9e981c108df", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'A': 100.0, 'E_high': 1000.0}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "initial_conc = {\"A\": 100., \"E_high\": 1000.} # Note the abundant energy source \"E_high\"; anything not specified will default to zero\n", "initial_conc" ] }, { "cell_type": "code", "execution_count": null, "id": "7d01270d-e173-44c5-b101-7a7661cc869a", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "cc7ffb34-d31e-4543-ad53-09786f9ecebc", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "e9403630-eb9f-49d7-8888-d973028ab4f4", "metadata": { "incorrectly_encoded_metadata": "tags=[] jp-MarkdownHeadingCollapsed=true tags=[] jp-MarkdownHeadingCollapsed=true jp-MarkdownHeadingCollapsed=true tags=[] jp-MarkdownHeadingCollapsed=true jp-MarkdownHeadingCollapsed=true tags=[] jp-MarkdownHeadingCollapsed=true", "tags": [] }, "source": [ "# Run # 1 : FIXED time resolution, with COARSE time steps - broken up in 3 time intervals \n", "(trial and error, not shown, reveals that increasing any of the time steps below, leads to \"excessive time step\" errors; \n", "note: fixed time resolution is generelly NOT recommended, except for double-checks and error analysis)" ] }, { "cell_type": "code", "execution_count": 6, "id": "e80645d6-eb5b-4c78-8b46-ae126d2cb2cf", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SYSTEM STATE at Time t = 0:\n", "5 species:\n", " Species 0 (A). Conc: 100.0\n", " Species 1 (B). Conc: 0.0\n", " Species 2 (C). Conc: 0.0\n", " Species 3 (E_high). Conc: 1000.0\n", " Species 4 (E_low). Conc: 0.0\n", "Set of chemicals involved in reactions: {'E_high', 'C', 'B', 'E_low', 'A'}\n" ] } ], "source": [ "dynamics = UniformCompartment(chem_data=chem_data)\n", "dynamics.set_conc(conc=initial_conc, snapshot=True)\n", "dynamics.describe_state()" ] }, { "cell_type": "code", "execution_count": 7, "id": "d77cd506-65b0-4604-94e7-a9fa226ede08", "metadata": {}, "outputs": [], "source": [ "dynamics.set_diagnostics() # To save diagnostic information about the call to single_compartment_react()" ] }, { "cell_type": "markdown", "id": "0b46b395-3f68-4dbd-b0c5-d67a0e623726", "metadata": { "tags": [] }, "source": [ "### We'll split the simulation in three segments (apparent from the graphs of the runs, further down): \n", "Time [0-0.03] fast changes \n", "Time [0.03-5.] medium changes \n", "Time [5.-8.] slow changes, as we approach equilibrium " ] }, { "cell_type": "code", "execution_count": 8, "id": "50ddd8e3-58c6-41f8-b874-ddc9a1d64d30", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "38 total step(s) taken\n" ] } ], "source": [ "dynamics.single_compartment_react(initial_step=0.0008, target_end_time=0.03, variable_steps=False)\n", "#dynamics.get_history()" ] }, { "cell_type": "code", "execution_count": 9, "id": "fbf24a85-b152-4b24-b350-00bed12e7bb9", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4970 total step(s) taken\n" ] } ], "source": [ "dynamics.single_compartment_react(initial_step=0.001, target_end_time=5., variable_steps=False)\n", "#dynamics.get_history()" ] }, { "cell_type": "code", "execution_count": 10, "id": "938b9678-900a-4d6b-8cac-68d62545b09e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "600 total step(s) taken\n" ] } ], "source": [ "dynamics.single_compartment_react(initial_step=0.005, target_end_time=8., variable_steps=False)" ] }, { "cell_type": "code", "execution_count": 11, "id": "813314da-3859-4bf1-9cae-764da773c40f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | SYSTEM TIME | \n", "A | \n", "B | \n", "C | \n", "E_high | \n", "E_low | \n", "caption | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "0.0000 | \n", "100.000000 | \n", "0.000000 | \n", "0.000000 | \n", "1000.000000 | \n", "0.000000 | \n", "Initialized state | \n", "
1 | \n", "0.0008 | \n", "99.280000 | \n", "0.720000 | \n", "0.000000 | \n", "1000.000000 | \n", "0.000000 | \n", "\n", " |
2 | \n", "0.0016 | \n", "98.566912 | \n", "1.428480 | \n", "0.004608 | \n", "1000.000000 | \n", "0.000000 | \n", "\n", " |
3 | \n", "0.0024 | \n", "97.864345 | \n", "2.125606 | \n", "0.010049 | \n", "999.996314 | \n", "0.003686 | \n", "\n", " |
4 | \n", "0.0032 | \n", "97.172805 | \n", "2.811556 | \n", "0.015639 | \n", "999.988332 | \n", "0.011668 | \n", "\n", " |
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
5604 | \n", "7.9804 | \n", "10.018545 | \n", "30.006917 | \n", "59.974537 | \n", "32.331113 | \n", "967.668887 | \n", "\n", " |
5605 | \n", "7.9854 | \n", "10.018398 | \n", "30.006862 | \n", "59.974740 | \n", "32.330530 | \n", "967.669470 | \n", "\n", " |
5606 | \n", "7.9904 | \n", "10.018251 | \n", "30.006808 | \n", "59.974942 | \n", "32.329952 | \n", "967.670048 | \n", "\n", " |
5607 | \n", "7.9954 | \n", "10.018105 | \n", "30.006753 | \n", "59.975142 | \n", "32.329378 | \n", "967.670622 | \n", "\n", " |
5608 | \n", "8.0004 | \n", "10.017961 | \n", "30.006699 | \n", "59.975340 | \n", "32.328809 | \n", "967.671191 | \n", "\n", " |
5609 rows × 7 columns
\n", "\n", " | SYSTEM TIME | \n", "A | \n", "B | \n", "C | \n", "E_high | \n", "E_low | \n", "caption | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "0.000000 | \n", "100.000000 | \n", "0.000000 | \n", "0.000000 | \n", "1000.000000 | \n", "0.000000 | \n", "Initialized state | \n", "
1 | \n", "0.000100 | \n", "99.910000 | \n", "0.090000 | \n", "0.000000 | \n", "1000.000000 | \n", "0.000000 | \n", "\n", " |
2 | \n", "0.000210 | \n", "99.811119 | \n", "0.188802 | \n", "0.000079 | \n", "1000.000000 | \n", "0.000000 | \n", "\n", " |
3 | \n", "0.000265 | \n", "99.761748 | \n", "0.238094 | \n", "0.000158 | \n", "999.999996 | \n", "0.000004 | \n", "\n", " |
4 | \n", "0.000293 | \n", "99.737081 | \n", "0.262713 | \n", "0.000206 | \n", "999.999991 | \n", "0.000009 | \n", "\n", " |
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
1907 | \n", "7.920378 | \n", "10.018699 | \n", "30.006975 | \n", "59.974327 | \n", "32.331717 | \n", "967.668283 | \n", "\n", " |
1908 | \n", "7.939029 | \n", "10.018143 | \n", "30.006767 | \n", "59.975090 | \n", "32.329524 | \n", "967.670476 | \n", "\n", " |
1909 | \n", "7.959545 | \n", "10.017545 | \n", "30.006546 | \n", "59.975909 | \n", "32.327188 | \n", "967.672812 | \n", "\n", " |
1910 | \n", "7.982112 | \n", "10.016934 | \n", "30.006310 | \n", "59.976756 | \n", "32.324679 | \n", "967.675321 | \n", "\n", " |
1911 | \n", "8.006936 | \n", "10.016136 | \n", "30.006062 | \n", "59.977802 | \n", "32.322163 | \n", "967.677837 | \n", "\n", " |
1912 rows × 7 columns
\n", "\n", " | SYSTEM TIME | \n", "A | \n", "B | \n", "C | \n", "E_high | \n", "E_low | \n", "caption | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "0.0000 | \n", "100.000000 | \n", "0.000000 | \n", "0.000000 | \n", "1000.000000 | \n", "0.000000 | \n", "Initialized state | \n", "
1 | \n", "0.0004 | \n", "99.640000 | \n", "0.360000 | \n", "0.000000 | \n", "1000.000000 | \n", "0.000000 | \n", "\n", " |
2 | \n", "0.0008 | \n", "99.281728 | \n", "0.717120 | \n", "0.001152 | \n", "1000.000000 | \n", "0.000000 | \n", "\n", " |
3 | \n", "0.0012 | \n", "98.925635 | \n", "1.071381 | \n", "0.002984 | \n", "999.999539 | \n", "0.000461 | \n", "\n", " |
4 | \n", "0.0016 | \n", "98.571979 | \n", "1.422804 | \n", "0.005218 | \n", "999.998349 | \n", "0.001651 | \n", "\n", " |
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
11211 | \n", "7.9900 | \n", "10.018459 | \n", "30.006885 | \n", "59.974656 | \n", "32.330771 | \n", "967.669229 | \n", "\n", " |
11212 | \n", "7.9925 | \n", "10.018385 | \n", "30.006858 | \n", "59.974757 | \n", "32.330481 | \n", "967.669519 | \n", "\n", " |
11213 | \n", "7.9950 | \n", "10.018312 | \n", "30.006830 | \n", "59.974858 | \n", "32.330192 | \n", "967.669808 | \n", "\n", " |
11214 | \n", "7.9975 | \n", "10.018239 | \n", "30.006803 | \n", "59.974958 | \n", "32.329904 | \n", "967.670096 | \n", "\n", " |
11215 | \n", "8.0000 | \n", "10.018166 | \n", "30.006776 | \n", "59.975058 | \n", "32.329618 | \n", "967.670382 | \n", "\n", " |
11216 rows × 7 columns
\n", "