{
"cells": [
{
"cell_type": "markdown",
"id": "49bcb5b0-f19d-4b96-a5f1-e0ae30f66d8f",
"metadata": {},
"source": [
"## Comparing the reaction `A` <-> `B` with and without an enzyme\n",
"\n",
"LAST REVISED: June 4, 2023"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "d9efa3fd-e95d-4e1c-878a-81ae932b2709",
"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": "01bae555-3dcf-42c1-bddc-9477a37f49f8",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from src.modules.reactions.reaction_data import ChemData\n",
"from src.modules.reactions.reaction_dynamics import ReactionDynamics\n",
"\n",
"import numpy as np\n",
"import plotly.express as px"
]
},
{
"cell_type": "markdown",
"id": "d6d3ca49-589d-49b7-8424-37c7b01bcacf",
"metadata": {},
"source": [
"# 1. WITHOUT ENZYME\n",
"### `A` <-> `B`"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "23c15e66-52e4-495b-aa3d-ecddd8d16942",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of reactions: 1 (at temp. 25 C)\n",
"0: A <-> B (kF = 1 / kR = 0.2 / Delta_G = -3,989.73 / K = 5.00001) | 1st order in all reactants & products\n"
]
}
],
"source": [
"# Initialize the system\n",
"chem_data = ChemData(names=[\"A\", \"B\"])\n",
"\n",
"# Reaction A <-> B , with 1st-order kinetics, and a forward rate that is slower than it would be with the enzyme of part 2\n",
"chem_data.add_reaction(reactants=\"A\", products=\"B\",\n",
" forward_rate=1., delta_G=-3989.73)\n",
"\n",
"chem_data.describe_reactions()"
]
},
{
"cell_type": "markdown",
"id": "0e771dda-1c0f-4fc0-ab21-049740643897",
"metadata": {},
"source": [
"### Set the initial concentrations of all the chemicals"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "5563e467-a637-44fa-9ba1-d35ddd82c887",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SYSTEM STATE at Time t = 0:\n",
"2 species:\n",
" Species 0 (A). Conc: 20.0\n",
" Species 1 (B). Conc: 0.0\n"
]
}
],
"source": [
"dynamics = ReactionDynamics(reaction_data=chem_data)\n",
"dynamics.set_conc(conc={\"A\": 20., \"B\": 0.},\n",
" snapshot=True)\n",
"dynamics.describe_state()"
]
},
{
"cell_type": "markdown",
"id": "651941bb-7098-4065-a598-e50c0b641ab3",
"metadata": {
"tags": []
},
"source": [
"### Take the initial system to equilibrium"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "76f24d9a-a788-41d8-90a4-db87386f91aa",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* INFO: the tentative time step (0.1) leads to a least one norm value > its ABORT threshold:\n",
" -> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.5 (set to 0.05) [Step started at t=0, and will rewind there]\n",
"30 total step(s) taken\n"
]
}
],
"source": [
"dynamics.set_diagnostics() # To save diagnostic information about the call to single_compartment_react()\n",
"\n",
"# All of these settings are currently close to the default values... but subject to change; set for repeatability\n",
"dynamics.set_thresholds(norm=\"norm_A\", low=0.5, high=0.8, abort=1.44)\n",
"dynamics.set_thresholds(norm=\"norm_B\", low=0.08, high=0.5, abort=1.5)\n",
"dynamics.set_step_factors(upshift=1.5, downshift=0.5, abort=0.5)\n",
"dynamics.set_error_step_factor(0.5)\n",
"\n",
"dynamics.single_compartment_react(initial_step=0.1, reaction_duration=3.0,\n",
" variable_steps=True, explain_variable_steps=False)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "b0543cac-f3cd-453c-ae9b-c00f01e61fa8",
"metadata": {},
"outputs": [],
"source": [
"#dynamics.explain_time_advance()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "4a19ad2a-fbd2-420a-b958-2daf88bcc841",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
" \n",
" "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"hovertemplate": "Chemical=A
SYSTEM TIME=%{x}
concentration=%{y}
SYSTEM TIME=%{x}
concentration=%{y}
| \n", " | SYSTEM TIME | \n", "A | \n", "B | \n", "E | \n", "caption | \n", "
|---|---|---|---|---|---|
| 0 | \n", "0.000000 | \n", "20.000000 | \n", "0.000000 | \n", "30.0 | \n", "Initial state | \n", "
| 1 | \n", "0.000250 | \n", "18.500000 | \n", "1.500000 | \n", "30.0 | \n", "\n", " |
| 2 | \n", "0.000500 | \n", "17.135000 | \n", "2.865000 | \n", "30.0 | \n", "\n", " |
| 3 | \n", "0.000625 | \n", "16.513925 | \n", "3.486075 | \n", "30.0 | \n", "\n", " |
| 4 | \n", "0.000750 | \n", "15.920798 | \n", "4.079202 | \n", "30.0 | \n", "\n", " |
| 5 | \n", "0.000875 | \n", "15.354362 | \n", "4.645638 | \n", "30.0 | \n", "\n", " |
| 6 | \n", "0.001000 | \n", "14.813416 | \n", "5.186584 | \n", "30.0 | \n", "\n", " |
| 7 | \n", "0.001125 | \n", "14.296812 | \n", "5.703188 | \n", "30.0 | \n", "\n", " |
| 8 | \n", "0.001250 | \n", "13.803456 | \n", "6.196544 | \n", "30.0 | \n", "\n", " |
| 9 | \n", "0.001375 | \n", "13.332300 | \n", "6.667700 | \n", "30.0 | \n", "\n", " |
| 10 | \n", "0.001525 | \n", "12.792356 | \n", "7.207644 | \n", "30.0 | \n", "\n", " |
| 11 | \n", "0.001675 | \n", "12.281569 | \n", "7.718431 | \n", "30.0 | \n", "\n", " |
| 12 | \n", "0.001855 | \n", "11.701723 | \n", "8.298277 | \n", "30.0 | \n", "\n", " |
| 13 | \n", "0.002071 | \n", "11.050997 | \n", "8.949003 | \n", "30.0 | \n", "\n", " |
| 14 | \n", "0.002330 | \n", "10.330846 | \n", "9.669154 | \n", "30.0 | \n", "\n", " |
| 15 | \n", "0.002589 | \n", "9.677894 | \n", "10.322106 | \n", "30.0 | \n", "\n", " |
| 16 | \n", "0.002900 | \n", "8.967465 | \n", "11.032535 | \n", "30.0 | \n", "\n", " |
| 17 | \n", "0.003274 | \n", "8.210411 | \n", "11.789589 | \n", "30.0 | \n", "\n", " |
| 18 | \n", "0.003647 | \n", "7.555081 | \n", "12.444919 | \n", "30.0 | \n", "\n", " |
| 19 | \n", "0.004095 | \n", "6.874353 | \n", "13.125647 | \n", "30.0 | \n", "\n", " |
| 20 | \n", "0.004543 | \n", "6.303387 | \n", "13.696613 | \n", "30.0 | \n", "\n", " |
| 21 | \n", "0.004991 | \n", "5.824486 | \n", "14.175514 | \n", "30.0 | \n", "\n", " |
| 22 | \n", "0.005528 | \n", "5.342468 | \n", "14.657532 | \n", "30.0 | \n", "\n", " |
| 23 | \n", "0.006066 | \n", "4.953716 | \n", "15.046284 | \n", "30.0 | \n", "\n", " |
| 24 | \n", "0.006711 | \n", "4.577479 | \n", "15.422521 | \n", "30.0 | \n", "\n", " |
| 25 | \n", "0.007485 | \n", "4.230824 | \n", "15.769176 | \n", "30.0 | \n", "\n", " |
| 26 | \n", "0.008413 | \n", "3.930744 | \n", "16.069256 | \n", "30.0 | \n", "\n", " |
| 27 | \n", "0.009528 | \n", "3.691047 | \n", "16.308953 | \n", "30.0 | \n", "\n", " |
| 28 | \n", "0.010865 | \n", "3.518817 | \n", "16.481183 | \n", "30.0 | \n", "\n", " |
| 29 | \n", "0.012470 | \n", "3.411650 | \n", "16.588350 | \n", "30.0 | \n", "\n", " |
| 30 | \n", "0.014396 | \n", "3.357349 | \n", "16.642651 | \n", "30.0 | \n", "\n", " |
| 31 | \n", "0.016707 | \n", "3.337366 | \n", "16.662634 | \n", "30.0 | \n", "\n", " |
| 32 | \n", "0.019480 | \n", "3.333337 | \n", "16.666663 | \n", "30.0 | \n", "\n", " |
| 33 | \n", "0.022808 | \n", "3.333329 | \n", "16.666671 | \n", "30.0 | \n", "\n", " |
| 34 | \n", "0.026802 | \n", "3.333331 | \n", "16.666669 | \n", "30.0 | \n", "\n", " |
| 35 | \n", "0.031594 | \n", "3.333330 | \n", "16.666670 | \n", "30.0 | \n", "\n", " |
| 36 | \n", "0.037345 | \n", "3.333331 | \n", "16.666669 | \n", "30.0 | \n", "\n", " |
| 37 | \n", "0.044245 | \n", "3.333329 | \n", "16.666671 | \n", "30.0 | \n", "\n", " |
| 38 | \n", "0.052526 | \n", "3.333331 | \n", "16.666669 | \n", "30.0 | \n", "\n", " |
| 39 | \n", "0.062463 | \n", "3.333327 | \n", "16.666673 | \n", "30.0 | \n", "\n", " |
| 40 | \n", "0.074388 | \n", "3.333341 | \n", "16.666659 | \n", "30.0 | \n", "\n", " |
| 41 | \n", "0.088697 | \n", "3.333284 | \n", "16.666716 | \n", "30.0 | \n", "\n", " |
| 42 | \n", "0.105869 | \n", "3.333567 | \n", "16.666433 | \n", "30.0 | \n", "\n", " |