{
"cells": [
{
"cell_type": "markdown",
"id": "54d8ecb1-ea4d-4985-9d5a-e838e264c308",
"metadata": {},
"source": [
"## One-bin `A <-> 2C + D`, with 1st-order kinetics for each species, taken to equilibrium\n",
"\n",
"Diffusion not applicable (just 1 bin)\n",
"\n",
"LAST REVISED: May 6, 2024"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "7d9e829a-3644-4769-8c4e-5596b678337f",
"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": "371d264e",
"metadata": {},
"outputs": [],
"source": [
"from experiments.get_notebook_info import get_notebook_basename\n",
"\n",
"from src.modules.chemicals.chem_data import ChemData as chem\n",
"from src.life_1D.bio_sim_1d import BioSim1D\n",
"\n",
"import plotly.express as px\n",
"from src.modules.visualization.graphic_log import GraphicLog"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "3c9c6dc0-8c6d-431d-a9d8-0a33780a2441",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-> Output will be LOGGED into the file 'reaction_5.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": "6ad40924-3c41-494f-8682-ec8efc540537",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SYSTEM STATE at Time t = 0:\n",
"1 bins and 3 species:\n",
" Species 0 (A). Diff rate: None. Conc: [4.]\n",
" Species 1 (C). Diff rate: None. Conc: [7.]\n",
" Species 2 (D). Diff rate: None. Conc: [2.]\n"
]
}
],
"source": [
"# Initialize the system\n",
"chem_data = chem(names=[\"A\", \"C\", \"D\"]) # NOTE: Diffusion not applicable (just 1 bin)\n",
"\n",
"\n",
"\n",
"# Reaction A <-> 2C + D , with 1st-order kinetics for each species\n",
"chem_data.add_reaction(reactants=[(\"A\")], products=[(2, \"C\", 1) , (\"D\")],\n",
" forward_rate=5., reverse_rate=2.)\n",
"\n",
"bio = BioSim1D(n_bins=1, chem_data=chem_data)\n",
"\n",
"bio.set_all_uniform_concentrations( [4., 7., 2.] )\n",
"\n",
"bio.describe_state()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "e8ec69e3-dc27-4d6e-90d8-c5636dc061c8",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" SYSTEM TIME | \n",
" A | \n",
" C | \n",
" D | \n",
" caption | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0 | \n",
" 4.0 | \n",
" 7.0 | \n",
" 2.0 | \n",
" Initial state | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" SYSTEM TIME A C D caption\n",
"0 0 4.0 7.0 2.0 Initial state"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Save the state of the concentrations of all species at bin 0\n",
"bio.add_snapshot(bio.bin_snapshot(bin_address = 0), caption=\"Initial state\")\n",
"bio.get_history()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "2fec356a-3018-4ac9-9a09-066bd69c2098",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of reactions: 1 (at temp. 25 C)\n",
"0: A <-> 2 C + D (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: {'D', 'A', 'C'}\n"
]
}
],
"source": [
"chem_data.describe_reactions()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "8c9cea88-b766-4145-843b-9b109334d487",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[GRAPHIC ELEMENT SENT TO LOG FILE `reaction_5.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": "39837c2b-aa44-4a5f-b2a2-747b889ca9fc",
"metadata": {
"tags": []
},
"source": [
"### First step"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "8de0fb5d-419d-4976-b57d-b7656f7f0358",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SYSTEM STATE at Time t = 0.2:\n",
"1 bins and 3 species:\n",
" Species 0 (A). Diff rate: None. Conc: [5.6]\n",
" Species 1 (C). Diff rate: None. Conc: [3.8]\n",
" Species 2 (D). Diff rate: None. Conc: [0.4]\n"
]
}
],
"source": [
"# First step\n",
"bio.react(time_step=0.2, n_steps=1)\n",
"bio.describe_state()"
]
},
{
"cell_type": "markdown",
"id": "a128c0ed-ed29-4fa9-ac8d-995df08cc60c",
"metadata": {},
"source": [
"--- \n",
" Note: the above values are quite inaccurate because of the large time step 0.2\n",
"\n",
" For example, the value for the concentration of D (0.4) is a wild overshot from the initial 2.0 to the equilibrium value of 1.68941267\n",
" \n",
" A more precise calculation with bio.react(time_step=0.1, n_steps=2) gives conc_D(0.2) = 2.304\n",
" \n",
" An even more precise calculation with bio.react(time_step=0.05, n_steps=4) gives conc_D(0.2) = 1.69037202\n",
" \n",
" I.e. the system is almost at equilibrium already at t=0.2 !\n",
" \n",
" TODO: explore the early dynamics of the system in a separate experiment\n",
"---"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "57bb972b-bf2e-492c-824a-49fe5b4d53a9",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" SYSTEM TIME | \n",
" A | \n",
" C | \n",
" D | \n",
" caption | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.0 | \n",
" 4.0 | \n",
" 7.0 | \n",
" 2.0 | \n",
" Initial state | \n",
"
\n",
" \n",
" | 1 | \n",
" 0.2 | \n",
" 5.6 | \n",
" 3.8 | \n",
" 0.4 | \n",
" | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" SYSTEM TIME A C D caption\n",
"0 0.0 4.0 7.0 2.0 Initial state\n",
"1 0.2 5.6 3.8 0.4 "
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Save the state of the concentrations of all species at bin 0\n",
"bio.add_snapshot(bio.bin_snapshot(bin_address = 0))\n",
"bio.get_history()"
]
},
{
"cell_type": "markdown",
"id": "6d201c6c-1cb7-4902-a3c3-d3f33514ffa7",
"metadata": {},
"source": [
"### Numerous more steps"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "19212806-2baa-43c6-8083-f3cbc4916d89",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SYSTEM STATE at Time t = 1.7:\n",
"1 bins and 3 species:\n",
" Species 0 (A). Diff rate: None. Conc: [4.31058733]\n",
" Species 1 (C). Diff rate: None. Conc: [6.37882534]\n",
" Species 2 (D). Diff rate: None. Conc: [1.68941267]\n"
]
}
],
"source": [
"# Numerous more steps\n",
"bio.react(time_step=0.05, n_steps=30, snapshots={\"sample_bin\": 0})\n",
"\n",
"bio.describe_state()"
]
},
{
"cell_type": "markdown",
"id": "dd1dfc16-d0e0-446f-a02a-cbd6ec40db7b",
"metadata": {
"tags": []
},
"source": [
"### Equilibrium"
]
},
{
"cell_type": "markdown",
"id": "622e8969-dc8c-44ea-be61-05824b1f8d5c",
"metadata": {},
"source": [
"Consistent with the 5/2 ratio of forward/reverse rates (and the 1st order reactions),\n",
"the systems settles in the following equilibrium: \n",
"[A] = 4.31058733 , [C] = 6.37882534 , [D] = 1.68941267"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "52260eec-31d6-42a0-8ea9-a4122851c328",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A <-> 2 C + D\n",
"Final concentrations: [A] = 4.311 ; [C] = 6.379 ; [D] = 1.689\n",
"1. Ratio of reactant/product concentrations, adjusted for reaction orders: 2.5\n",
" Formula used: ([C][D]) / [A]\n",
"2. Ratio of forward/reverse reaction rates: 2.5\n",
"Discrepancy between the two values: 0 %\n",
"Reaction IS in equilibrium (within 1% tolerance)\n",
"\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Verify that the reaction has reached equilibrium\n",
"bio.reaction_dynamics.is_in_equilibrium(rxn_index=0, conc=bio.bin_snapshot(bin_address = 0))"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "9c836591-3896-44ac-8d0b-6fc948411f2a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" SYSTEM TIME | \n",
" A | \n",
" C | \n",
" D | \n",
" caption | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.00 | \n",
" 4.000000 | \n",
" 7.000000 | \n",
" 2.000000 | \n",
" Initial state | \n",
"
\n",
" \n",
" | 1 | \n",
" 0.20 | \n",
" 5.600000 | \n",
" 3.800000 | \n",
" 0.400000 | \n",
" | \n",
"
\n",
" \n",
" | 2 | \n",
" 0.25 | \n",
" 4.352000 | \n",
" 6.296000 | \n",
" 1.648000 | \n",
" | \n",
"
\n",
" \n",
" | 3 | \n",
" 0.30 | \n",
" 4.301581 | \n",
" 6.396838 | \n",
" 1.698419 | \n",
" | \n",
"
\n",
" \n",
" | 4 | \n",
" 0.35 | \n",
" 4.312637 | \n",
" 6.374726 | \n",
" 1.687363 | \n",
" | \n",
"
\n",
" \n",
" | 5 | \n",
" 0.40 | \n",
" 4.310125 | \n",
" 6.379749 | \n",
" 1.689875 | \n",
" | \n",
"
\n",
" \n",
" | 6 | \n",
" 0.45 | \n",
" 4.310692 | \n",
" 6.378617 | \n",
" 1.689308 | \n",
" | \n",
"
\n",
" \n",
" | 7 | \n",
" 0.50 | \n",
" 4.310564 | \n",
" 6.378872 | \n",
" 1.689436 | \n",
" | \n",
"
\n",
" \n",
" | 8 | \n",
" 0.55 | \n",
" 4.310593 | \n",
" 6.378815 | \n",
" 1.689407 | \n",
" | \n",
"
\n",
" \n",
" | 9 | \n",
" 0.60 | \n",
" 4.310586 | \n",
" 6.378828 | \n",
" 1.689414 | \n",
" | \n",
"
\n",
" \n",
" | 10 | \n",
" 0.65 | \n",
" 4.310588 | \n",
" 6.378825 | \n",
" 1.689412 | \n",
" | \n",
"
\n",
" \n",
" | 11 | \n",
" 0.70 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 12 | \n",
" 0.75 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 13 | \n",
" 0.80 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 14 | \n",
" 0.85 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 15 | \n",
" 0.90 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 16 | \n",
" 0.95 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 17 | \n",
" 1.00 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 18 | \n",
" 1.05 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 19 | \n",
" 1.10 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 20 | \n",
" 1.15 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 21 | \n",
" 1.20 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 22 | \n",
" 1.25 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 23 | \n",
" 1.30 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 24 | \n",
" 1.35 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 25 | \n",
" 1.40 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 26 | \n",
" 1.45 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 27 | \n",
" 1.50 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 28 | \n",
" 1.55 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 29 | \n",
" 1.60 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 30 | \n",
" 1.65 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
" | 31 | \n",
" 1.70 | \n",
" 4.310587 | \n",
" 6.378825 | \n",
" 1.689413 | \n",
" | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" SYSTEM TIME A C D caption\n",
"0 0.00 4.000000 7.000000 2.000000 Initial state\n",
"1 0.20 5.600000 3.800000 0.400000 \n",
"2 0.25 4.352000 6.296000 1.648000 \n",
"3 0.30 4.301581 6.396838 1.698419 \n",
"4 0.35 4.312637 6.374726 1.687363 \n",
"5 0.40 4.310125 6.379749 1.689875 \n",
"6 0.45 4.310692 6.378617 1.689308 \n",
"7 0.50 4.310564 6.378872 1.689436 \n",
"8 0.55 4.310593 6.378815 1.689407 \n",
"9 0.60 4.310586 6.378828 1.689414 \n",
"10 0.65 4.310588 6.378825 1.689412 \n",
"11 0.70 4.310587 6.378825 1.689413 \n",
"12 0.75 4.310587 6.378825 1.689413 \n",
"13 0.80 4.310587 6.378825 1.689413 \n",
"14 0.85 4.310587 6.378825 1.689413 \n",
"15 0.90 4.310587 6.378825 1.689413 \n",
"16 0.95 4.310587 6.378825 1.689413 \n",
"17 1.00 4.310587 6.378825 1.689413 \n",
"18 1.05 4.310587 6.378825 1.689413 \n",
"19 1.10 4.310587 6.378825 1.689413 \n",
"20 1.15 4.310587 6.378825 1.689413 \n",
"21 1.20 4.310587 6.378825 1.689413 \n",
"22 1.25 4.310587 6.378825 1.689413 \n",
"23 1.30 4.310587 6.378825 1.689413 \n",
"24 1.35 4.310587 6.378825 1.689413 \n",
"25 1.40 4.310587 6.378825 1.689413 \n",
"26 1.45 4.310587 6.378825 1.689413 \n",
"27 1.50 4.310587 6.378825 1.689413 \n",
"28 1.55 4.310587 6.378825 1.689413 \n",
"29 1.60 4.310587 6.378825 1.689413 \n",
"30 1.65 4.310587 6.378825 1.689413 \n",
"31 1.70 4.310587 6.378825 1.689413 "
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bio.get_history()"
]
},
{
"cell_type": "markdown",
"id": "16c85241-2b62-4ac8-bd44-f6231f6ef685",
"metadata": {},
"source": [
"C and D get depleted, while A gets produced.\n",
"A wild overshoot is present at t=0.2"
]
},
{
"cell_type": "markdown",
"id": "c8219705-f08b-41c1-b585-9a01ff80f4ab",
"metadata": {
"tags": []
},
"source": [
"# Plots of changes of concentration with time"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "115692eb-8fc8-48b6-8f20-7053a7e9de54",
"metadata": {
"tags": []
},
"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}",
"legendgroup": "A",
"line": {
"color": "navy",
"dash": "solid"
},
"marker": {
"symbol": "circle"
},
"mode": "lines",
"name": "A",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.2,
0.25,
0.3,
0.35,
0.39999999999999997,
0.44999999999999996,
0.49999999999999994,
0.5499999999999999,
0.6,
0.65,
0.7000000000000001,
0.7500000000000001,
0.8000000000000002,
0.8500000000000002,
0.9000000000000002,
0.9500000000000003,
1.0000000000000002,
1.0500000000000003,
1.1000000000000003,
1.1500000000000004,
1.2000000000000004,
1.2500000000000004,
1.3000000000000005,
1.3500000000000005,
1.4000000000000006,
1.4500000000000006,
1.5000000000000007,
1.5500000000000007,
1.6000000000000008,
1.6500000000000008,
1.7000000000000008
],
"xaxis": "x",
"y": [
4,
5.6,
4.351999999999999,
4.3015808,
4.312636915785728,
4.310125447697398,
4.3106916519678125,
4.310563782331762,
4.310592648763124,
4.310586131626044,
4.31058760296257,
4.3105872707859065,
4.310587345779779,
4.310587328848781,
4.310587332671209,
4.310587331808239,
4.310587332003067,
4.3105873319590815,
4.310587331969011,
4.31058733196677,
4.310587331967276,
4.310587331967161,
4.310587331967187,
4.310587331967182,
4.3105873319671835,
4.310587331967183,
4.310587331967183,
4.310587331967183,
4.310587331967183,
4.310587331967183,
4.310587331967183,
4.310587331967183
],
"yaxis": "y"
},
{
"hovertemplate": "Chemical=C
SYSTEM TIME=%{x}
concentration=%{y}",
"legendgroup": "C",
"line": {
"color": "violet",
"dash": "solid"
},
"marker": {
"symbol": "circle"
},
"mode": "lines",
"name": "C",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.2,
0.25,
0.3,
0.35,
0.39999999999999997,
0.44999999999999996,
0.49999999999999994,
0.5499999999999999,
0.6,
0.65,
0.7000000000000001,
0.7500000000000001,
0.8000000000000002,
0.8500000000000002,
0.9000000000000002,
0.9500000000000003,
1.0000000000000002,
1.0500000000000003,
1.1000000000000003,
1.1500000000000004,
1.2000000000000004,
1.2500000000000004,
1.3000000000000005,
1.3500000000000005,
1.4000000000000006,
1.4500000000000006,
1.5000000000000007,
1.5500000000000007,
1.6000000000000008,
1.6500000000000008,
1.7000000000000008
],
"xaxis": "x",
"y": [
7,
3.8,
6.296,
6.3968384,
6.374726168428544,
6.379749104605204,
6.378616696064373,
6.378872435336473,
6.37881470247375,
6.378827736747909,
6.378824794074859,
6.378825458428185,
6.378825308440439,
6.378825342302434,
6.378825334657579,
6.37882533638352,
6.378825335993863,
6.378825336081833,
6.378825336061973,
6.378825336066456,
6.378825336065444,
6.378825336065673,
6.3788253360656215,
6.378825336065633,
6.37882533606563,
6.378825336065631,
6.378825336065631,
6.378825336065631,
6.378825336065631,
6.378825336065631,
6.378825336065631,
6.378825336065631
],
"yaxis": "y"
},
{
"hovertemplate": "Chemical=D
SYSTEM TIME=%{x}
concentration=%{y}",
"legendgroup": "D",
"line": {
"color": "red",
"dash": "solid"
},
"marker": {
"symbol": "circle"
},
"mode": "lines",
"name": "D",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.2,
0.25,
0.3,
0.35,
0.39999999999999997,
0.44999999999999996,
0.49999999999999994,
0.5499999999999999,
0.6,
0.65,
0.7000000000000001,
0.7500000000000001,
0.8000000000000002,
0.8500000000000002,
0.9000000000000002,
0.9500000000000003,
1.0000000000000002,
1.0500000000000003,
1.1000000000000003,
1.1500000000000004,
1.2000000000000004,
1.2500000000000004,
1.3000000000000005,
1.3500000000000005,
1.4000000000000006,
1.4500000000000006,
1.5000000000000007,
1.5500000000000007,
1.6000000000000008,
1.6500000000000008,
1.7000000000000008
],
"xaxis": "x",
"y": [
2,
0.3999999999999999,
1.6480000000000001,
1.6984192,
1.687363084214272,
1.6898745523026022,
1.6893083480321869,
1.6894362176682367,
1.6894073512368748,
1.6894138683739546,
1.6894123970374295,
1.6894127292140924,
1.6894126542202195,
1.689412671151217,
1.689412667328789,
1.6894126681917596,
1.689412667996931,
1.6894126680409165,
1.6894126680309862,
1.689412668033228,
1.689412668032722,
1.6894126680328363,
1.6894126680328105,
1.6894126680328163,
1.689412668032815,
1.6894126680328154,
1.6894126680328152,
1.6894126680328152,
1.6894126680328152,
1.6894126680328152,
1.6894126680328152,
1.6894126680328152
],
"yaxis": "y"
}
],
"layout": {
"autosize": true,
"legend": {
"title": {
"text": "Chemical"
},
"tracegroupgap": 0
},
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
},
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "bar"
}
],
"barpolar": [
{
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
},
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "barpolar"
}
],
"carpet": [
{
"aaxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"baxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"type": "carpet"
}
],
"choropleth": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "choropleth"
}
],
"contour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"fillpattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter3d"
}
],
"scattercarpet": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattercarpet"
}
],
"scattergeo": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergeo"
}
],
"scattergl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergl"
}
],
"scattermapbox": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermapbox"
}
],
"scatterpolar": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolar"
}
],
"scatterpolargl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolargl"
}
],
"scatterternary": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterternary"
}
],
"surface": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"autotypenumbers": "strict",
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"colorscale": {
"diverging": [
[
0,
"#8e0152"
],
[
0.1,
"#c51b7d"
],
[
0.2,
"#de77ae"
],
[
0.3,
"#f1b6da"
],
[
0.4,
"#fde0ef"
],
[
0.5,
"#f7f7f7"
],
[
0.6,
"#e6f5d0"
],
[
0.7,
"#b8e186"
],
[
0.8,
"#7fbc41"
],
[
0.9,
"#4d9221"
],
[
1,
"#276419"
]
],
"sequential": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#636efa",
"#EF553B",
"#00cc96",
"#ab63fa",
"#FFA15A",
"#19d3f3",
"#FF6692",
"#B6E880",
"#FF97FF",
"#FECB52"
],
"font": {
"color": "#2a3f5f"
},
"geo": {
"bgcolor": "white",
"lakecolor": "white",
"landcolor": "#E5ECF6",
"showlakes": true,
"showland": true,
"subunitcolor": "white"
},
"hoverlabel": {
"align": "left"
},
"hovermode": "closest",
"mapbox": {
"style": "light"
},
"paper_bgcolor": "white",
"plot_bgcolor": "#E5ECF6",
"polar": {
"angularaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"radialaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"scene": {
"xaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"yaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"zaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
}
},
"shapedefaults": {
"line": {
"color": "#2a3f5f"
}
},
"ternary": {
"aaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"baxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"caxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"title": {
"x": 0.05
},
"xaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"title": {
"text": "Reaction A <-> 2C + D . Changes in concentrations"
},
"xaxis": {
"anchor": "y",
"autorange": true,
"domain": [
0,
1
],
"range": [
0,
1.7000000000000008
],
"title": {
"text": "SYSTEM TIME"
},
"type": "linear"
},
"yaxis": {
"anchor": "x",
"autorange": true,
"domain": [
0,
1
],
"range": [
0.03333333333333327,
7.366666666666666
],
"title": {
"text": "concentration"
},
"type": "linear"
}
}
},
"text/html": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig = px.line(data_frame=bio.get_history(), x=\"SYSTEM TIME\", y=[\"A\", \"C\", \"D\"], \n",
" title=\"Reaction A <-> 2C + D . Changes in concentrations\",\n",
" color_discrete_sequence = ['navy', 'violet', 'red'],\n",
" labels={\"value\":\"concentration\", \"variable\":\"Chemical\"})\n",
"fig.show()"
]
},
{
"cell_type": "markdown",
"id": "42921718-2075-4098-b55d-60a9df1e5f93",
"metadata": {},
"source": [
"### Notice the **wild overshoot** present at t=0.2 ! (Too large a time step, early in the reaction!)\n",
"Variable, adaptive time steps are explored at length in the _\"reactions_single_compartment\"_ experiments"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6b46289d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}