{
"cells": [
{
"cell_type": "markdown",
"id": "49bcb5b0-f19d-4b96-a5f1-e0ae30f66d8f",
"metadata": {},
"source": [
"# From finer to coarser resolution in advancing the two coupled reactions: \n",
"### `2 S <-> U` and `S <-> X` (both mostly forward)\n",
"\n",
"1st-order kinetics throughout. \n",
"\n",
"Notes: \n",
"* for an exploration of instabilities, see the experiment `negative_concentrations_1`\n",
"* for an accurate longer run of the same reactions (with the same initial conditions), see the experiment \"up_regulate_3\"\n",
"\n",
"LAST REVISED: Feb. 11, 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": [
"# Extend the sys.path variable, to contain the project's root directory\n",
"import set_path\n",
"set_path.add_ancestor_dir_to_syspath(2) # The number of levels to go up \n",
" # to reach the project's home, from the folder containing this notebook"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "01bae555-3dcf-42c1-bddc-9477a37f49f8",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from experiments.get_notebook_info import get_notebook_basename\n",
"\n",
"from src.modules.reactions.reaction_data import ReactionData as chem\n",
"from src.modules.reactions.reaction_dynamics import ReactionDynamics\n",
"\n",
"import numpy as np\n",
"import plotly.express as px\n",
"from src.modules.visualization.graphic_log 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 'large_time_steps_2.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_1\"],\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: 2 (at temp. 25 C)\n",
"0: 2 S <-> U (kF = 8 / kR = 2 / Delta_G = -3,436.56 / K = 4) | 1st order in all reactants & products\n",
"1: S <-> X (kF = 6 / kR = 3 / Delta_G = -1,718.28 / K = 2) | 1st order in all reactants & products\n",
"[GRAPHIC ELEMENT SENT TO LOG FILE `large_time_steps_2.log.htm`]\n"
]
}
],
"source": [
"# Initialize the system\n",
"chem_data = chem(names=[\"U\", \"X\", \"S\"])\n",
"\n",
"# Reaction 2 S <-> U , with 1st-order kinetics for all species (mostly forward)\n",
"chem_data.add_reaction(reactants=[(2, \"S\")], products=\"U\",\n",
" forward_rate=8., reverse_rate=2.)\n",
"\n",
"# Reaction S <-> X , with 1st-order kinetics for all species (mostly forward)\n",
"chem_data.add_reaction(reactants=\"S\", products=\"X\",\n",
" forward_rate=6., reverse_rate=3.)\n",
"\n",
"chem_data.describe_reactions()\n",
"\n",
"# Send the plot of the reaction network to the HTML log file\n",
"graph_data = chem_data.prepare_graph_network()\n",
"GraphicLog.export_plot(graph_data, \"vue_cytoscape_1\")"
]
},
{
"cell_type": "markdown",
"id": "ebbd7aab-2456-40de-981b-f1f36970450c",
"metadata": {},
"source": [
"# Run 1 : extremely small fixed time steps (no substeps)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "01ab7066-ce52-4c37-9608-b2cea9a1afac",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"800 total step(s) taken\n",
"From time 0 to 0.8, in 800 FULL steps of 0.001\n",
"(for a grand total of the equivalent of 800 FULL steps)\n"
]
}
],
"source": [
"dynamics = ReactionDynamics(reaction_data=chem_data)\n",
"dynamics.set_conc(conc={\"U\": 50., \"X\": 100., \"S\": 0.})\n",
"#dynamics.describe_state()\n",
"\n",
"dynamics.set_diagnostics() # To save diagnostic information about the call to single_compartment_react()\n",
"\n",
"dynamics.single_compartment_react(time_step=0.001, stop_time=0.8)\n",
"\n",
"df = dynamics.get_history()\n",
"#df\n",
"dynamics.explain_time_advance()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "555ff38c-9305-40b5-b047-d8417477d2c0",
"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=U
SYSTEM TIME=%{x}
concentration=%{y}
SYSTEM TIME=%{x}
concentration=%{y}
SYSTEM TIME=%{x}
concentration=%{y}