{
"cells": [
{
"cell_type": "markdown",
"id": "3bbe8002-bdf3-490c-bde0-80dd3713a3d0",
"metadata": {},
"source": [
"## A complex (multistep) reaction `A <-> C` derived from 2 coupled elementary reactions: \n",
"## `A <-> B` (slow) and `B <-> C` (fast) \n",
"A repeat of experiment `cascade_2_a`, with more DISSIMILAR elementary reactions.\n",
"\n",
"In PART 1, a time evolution of [A], [B] and [C] is obtained by simulation \n",
"In PART 2, the time functions generated in Part 1 are taken as a _starting point,_ to explore how to model the composite reaction `A <-> C` \n",
"\n",
"**Background**: please see experiment `cascade_2_a` \n",
"\n",
"LAST REVISED: June 23, 2024 (using v. 1.0 beta36)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "4d9b4808-b2ec-4b90-a604-f7fa69af39b8",
"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": "3924c013",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from experiments.get_notebook_info import get_notebook_basename\n",
"\n",
"from life123 import UniformCompartment\n",
"from life123.visualization.plotly_helper import PlotlyHelper"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "75411c8b-f0c5-411d-9e12-1eaa423449f9",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "9329208b-070f-4902-8f37-0f11ddf75ed6",
"metadata": {},
"source": [
"# PART 1 - We'll generate the time evolution of [A] and [C] by simulating coupled elementary reactions of KNOWN rate constants...\n",
"## but pretend you don't see this section! (because we later assume that those time evolutions are just GIVEN to us)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "72b4245c-de4e-480d-a501-3495b7ed8bc4",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of reactions: 2 (at temp. 25 C)\n",
"0: A <-> B (kF = 8 / kR = 2 / delta_G = -3,436.6 / K = 4) | 1st order in all reactants & products\n",
"1: B <-> C (kF = 80 / kR = 0.1 / delta_G = -16,571 / K = 800) | 1st order in all reactants & products\n",
"Set of chemicals involved in the above reactions: {'C', 'A', 'B'}\n"
]
}
],
"source": [
"# Instantiate the simulator and specify the chemicals\n",
"dynamics = UniformCompartment(names=[\"A\", \"B\", \"C\"], preset=\"mid\")\n",
"\n",
"# Reaction A <-> B (much slower, and with a much smaller K)\n",
"dynamics.add_reaction(reactants=\"A\", products=\"B\",\n",
" forward_rate=8., reverse_rate=2.) \n",
"\n",
"# Reaction B <-> C (much faster, and with a much larger K)\n",
"dynamics.add_reaction(reactants=\"B\", products=\"C\",\n",
" forward_rate=80., reverse_rate=0.1) # <===== THIS IS THE KEY DIFFERENCE FROM THE EARLIER EXPERIMENT `cascade_2_a`\n",
" \n",
"dynamics.describe_reactions()"
]
},
{
"cell_type": "markdown",
"id": "98a9fbe5-2090-4d38-9c5f-94fbf7c3eae2",
"metadata": {},
"source": [
"### Run the simulation"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "ae304704-c8d9-4cef-9e0b-2587bb3909ef",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SYSTEM STATE at Time t = 0:\n",
"3 species:\n",
" Species 0 (A). Conc: 50.0\n",
" Species 1 (B). Conc: 0.0\n",
" Species 2 (C). Conc: 0.0\n",
"Set of chemicals involved in reactions: {'C', 'A', 'B'}\n"
]
}
],
"source": [
"dynamics.set_conc({\"A\": 50.}, snapshot=True) # Set the initial concentrations of all the chemicals, in their index order\n",
"dynamics.describe_state()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "2502cd11-0df9-4303-8895-98401a1df7b8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Some steps were backtracked and re-done, to prevent negative concentrations or excessively large concentration changes\n",
"102 total step(s) taken\n",
"Number of step re-do's because of negative concentrations: 0\n",
"Number of step re-do's because of elective soft aborts: 1\n",
"Norm usage: {'norm_A': 15, 'norm_B': 16, 'norm_C': 14, 'norm_D': 14}\n"
]
}
],
"source": [
"dynamics.single_compartment_react(initial_step=0.01, duration=0.8,\n",
" snapshots={\"initial_caption\": \"1st reaction step\",\n",
" \"final_caption\": \"last reaction step\"},\n",
" variable_steps=True)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a2c0e793-5457-46a5-9150-388c9f562cf0",
"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}
SYSTEM TIME=%{x}
Concentration=%{y}
\n", " | SYSTEM TIME | \n", "A | \n", "C | \n", "caption | \n", "
---|---|---|---|---|
0 | \n", "0.000000 | \n", "50.000000 | \n", "0.000000 | \n", "Initialized state | \n", "
1 | \n", "0.004000 | \n", "48.400000 | \n", "0.000000 | \n", "1st reaction step | \n", "
2 | \n", "0.008000 | \n", "46.864000 | \n", "0.512000 | \n", "\n", " |
3 | \n", "0.010000 | \n", "46.124672 | \n", "0.931738 | \n", "\n", " |
4 | \n", "0.011000 | \n", "45.761562 | \n", "1.167132 | \n", "\n", " |
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
98 | \n", "0.758938 | \n", "0.121082 | \n", "49.805302 | \n", "\n", " |
99 | \n", "0.771777 | \n", "0.110536 | \n", "49.816969 | \n", "\n", " |
100 | \n", "0.784616 | \n", "0.101044 | \n", "49.827470 | \n", "\n", " |
101 | \n", "0.797455 | \n", "0.092501 | \n", "49.836921 | \n", "\n", " |
102 | \n", "0.810294 | \n", "0.084812 | \n", "49.845428 | \n", "last reaction step | \n", "
103 rows × 4 columns
\n", "\n", " | search_value | \n", "SYSTEM TIME | \n", "A | \n", "B | \n", "C | \n", "caption | \n", "
---|---|---|---|---|---|---|
19 | \n", "0.028 | \n", "0.02728 | \n", "40.260772 | \n", "3.8859 | \n", "5.853329 | \n", "\n", " |