{
"cells": [
{
"cell_type": "markdown",
"id": "80abc7ee-f50e-48b7-9ea7-15ce6226b0bf",
"metadata": {},
"source": [
"## One-bin `2A <-> B` reaction, \n",
"### COMPARING 1st-order and 2nd-order kinetics in *forward* direction; reverse direction 1-st order\n",
"\n",
"Diffusion not applicable (just 1 bin)\n",
"\n",
"See also the experiment _\"reactions_single_compartment/react_4\"_ \n",
"\n",
"LAST REVISED: May 6, 2024"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "9bbb329b-3c10-45dd-8d43-bba25487f64f",
"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": "f86597fb",
"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.html_log.html_log import HtmlLog as log\n",
"from src.modules.visualization.graphic_log import GraphicLog"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "ecba68b6-d062-47fe-9a17-ec339907323e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-> Output will be LOGGED into the file 'reaction_7.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": "43fb42a4-1582-45b5-9c8b-be146cb72236",
"metadata": {},
"source": [
"# INITIALLY, with 1st-order kinetics in both directions"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "72d71ac8-3f7d-47b5-94ba-142fca566ff4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SYSTEM STATE at Time t = 0:\n",
"1 bins and 2 species:\n",
" Species 0 (A). Diff rate: None. Conc: [3.]\n",
" Species 1 (B). Diff rate: None. Conc: [5.]\n"
]
}
],
"source": [
"# Initialize the system\n",
"chem_data = chem(names=[\"A\", \"B\"]) # NOTE: Diffusion not applicable (just 1 bin)\n",
"\n",
"\n",
"\n",
"# Reaction 2A <-> B , FOR NOW with 1st-order kinetics in both directions\n",
"chem_data.add_reaction(reactants=[(2, \"A\", 1)], products=[\"B\"], forward_rate=5., reverse_rate=2.)\n",
"\n",
"bio = BioSim1D(n_bins=1, chem_data=chem_data)\n",
"\n",
"bio.set_all_uniform_concentrations( [3., 5.] )\n",
"\n",
"bio.describe_state()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "35163098-208e-4ba1-a115-e02463df2750",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" SYSTEM TIME | \n",
" A | \n",
" B | \n",
" caption | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0 | \n",
" 3.0 | \n",
" 5.0 | \n",
" Initial state | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" SYSTEM TIME A B caption\n",
"0 0 3.0 5.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": "b472b184-9e22-45d4-ab18-b2507a83334a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of reactions: 1 (at temp. 25 C)\n",
"0: 2 A <-> B (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: {'A', 'B'}\n"
]
}
],
"source": [
"chem_data.describe_reactions()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "3be8b568-fc3c-41a3-98dd-6ad6983f2bc9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Reaction 2A B is 1st order in all species:\n",
"[GRAPHIC ELEMENT SENT TO LOG FILE `reaction_7.log.htm`]\n"
]
}
],
"source": [
"# Send a header and a plot to the HTML log file\n",
"log.write(\"Reaction 2A <-> B is 1st order in all species:\",\n",
" style=log.h2)\n",
"\n",
"chem_data.plot_reaction_network(\"vue_cytoscape_2\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "4ee91e87-4800-41d6-bc21-223ac1e493b3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SYSTEM STATE at Time t = 0.02:\n",
"1 bins and 2 species:\n",
" Species 0 (A). Diff rate: None. Conc: [2.8]\n",
" Species 1 (B). Diff rate: None. Conc: [5.1]\n"
]
}
],
"source": [
"# First step\n",
"bio.react(time_step=0.02, n_steps=1, snapshots={\"sample_bin\": 0})\n",
"bio.describe_state()"
]
},
{
"cell_type": "markdown",
"id": "fb58f958-29fc-4a43-ad33-751ef02c3cc2",
"metadata": {},
"source": [
"Small conc. changes so far: [A] = 2.8 , [B] = 5.1"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "86a7497e-cd17-4f4d-b9b1-9bfd786c865f",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" SYSTEM TIME | \n",
" A | \n",
" B | \n",
" caption | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.00 | \n",
" 3.0 | \n",
" 5.0 | \n",
" Initial state | \n",
"
\n",
" \n",
" | 1 | \n",
" 0.02 | \n",
" 2.8 | \n",
" 5.1 | \n",
" | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" SYSTEM TIME A B caption\n",
"0 0.00 3.0 5.0 Initial state\n",
"1 0.02 2.8 5.1 "
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bio.get_history()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "1e458105-4a8d-4f81-9776-7bde2c92b630",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SYSTEM STATE at Time t = 0.42:\n",
"1 bins and 2 species:\n",
" Species 0 (A). Diff rate: None. Conc: [2.16928427]\n",
" Species 1 (B). Diff rate: None. Conc: [5.41535786]\n"
]
}
],
"source": [
"# Numerous more steps, to equilibrium\n",
"bio.react(time_step=0.02, n_steps=20, snapshots={\"sample_bin\": 0})\n",
"\n",
"bio.describe_state()"
]
},
{
"cell_type": "markdown",
"id": "bb5ee324-b0e9-4823-82ae-815aab494b57",
"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] = 2.16928427 , [B] = 5.41535786"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "c3a088c4-c904-4d23-9940-307d9ca9a80f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2 A <-> B\n",
"Final concentrations: [A] = 2.169 ; [B] = 5.415\n",
"1. Ratio of reactant/product concentrations, adjusted for reaction orders: 2.49638\n",
" Formula used: [B] / [A]\n",
"2. Ratio of forward/reverse reaction rates: 2.5\n",
"Discrepancy between the two values: 0.1448 %\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": "7508667b-5e7f-4eed-ba41-a478f4d068b6",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" SYSTEM TIME | \n",
" A | \n",
" B | \n",
" caption | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.00 | \n",
" 3.000000 | \n",
" 5.000000 | \n",
" Initial state | \n",
"
\n",
" \n",
" | 1 | \n",
" 0.02 | \n",
" 2.800000 | \n",
" 5.100000 | \n",
" | \n",
"
\n",
" \n",
" | 2 | \n",
" 0.04 | \n",
" 2.648000 | \n",
" 5.176000 | \n",
" | \n",
"
\n",
" \n",
" | 3 | \n",
" 0.06 | \n",
" 2.532480 | \n",
" 5.233760 | \n",
" | \n",
"
\n",
" \n",
" | 4 | \n",
" 0.08 | \n",
" 2.444685 | \n",
" 5.277658 | \n",
" | \n",
"
\n",
" \n",
" | 5 | \n",
" 0.10 | \n",
" 2.377960 | \n",
" 5.311020 | \n",
" | \n",
"
\n",
" \n",
" | 6 | \n",
" 0.12 | \n",
" 2.327250 | \n",
" 5.336375 | \n",
" | \n",
"
\n",
" \n",
" | 7 | \n",
" 0.14 | \n",
" 2.288710 | \n",
" 5.355645 | \n",
" | \n",
"
\n",
" \n",
" | 8 | \n",
" 0.16 | \n",
" 2.259420 | \n",
" 5.370290 | \n",
" | \n",
"
\n",
" \n",
" | 9 | \n",
" 0.18 | \n",
" 2.237159 | \n",
" 5.381421 | \n",
" | \n",
"
\n",
" \n",
" | 10 | \n",
" 0.20 | \n",
" 2.220241 | \n",
" 5.389880 | \n",
" | \n",
"
\n",
" \n",
" | 11 | \n",
" 0.22 | \n",
" 2.207383 | \n",
" 5.396309 | \n",
" | \n",
"
\n",
" \n",
" | 12 | \n",
" 0.24 | \n",
" 2.197611 | \n",
" 5.401194 | \n",
" | \n",
"
\n",
" \n",
" | 13 | \n",
" 0.26 | \n",
" 2.190184 | \n",
" 5.404908 | \n",
" | \n",
"
\n",
" \n",
" | 14 | \n",
" 0.28 | \n",
" 2.184540 | \n",
" 5.407730 | \n",
" | \n",
"
\n",
" \n",
" | 15 | \n",
" 0.30 | \n",
" 2.180251 | \n",
" 5.409875 | \n",
" | \n",
"
\n",
" \n",
" | 16 | \n",
" 0.32 | \n",
" 2.176990 | \n",
" 5.411505 | \n",
" | \n",
"
\n",
" \n",
" | 17 | \n",
" 0.34 | \n",
" 2.174513 | \n",
" 5.412744 | \n",
" | \n",
"
\n",
" \n",
" | 18 | \n",
" 0.36 | \n",
" 2.172630 | \n",
" 5.413685 | \n",
" | \n",
"
\n",
" \n",
" | 19 | \n",
" 0.38 | \n",
" 2.171199 | \n",
" 5.414401 | \n",
" | \n",
"
\n",
" \n",
" | 20 | \n",
" 0.40 | \n",
" 2.170111 | \n",
" 5.414945 | \n",
" | \n",
"
\n",
" \n",
" | 21 | \n",
" 0.42 | \n",
" 2.169284 | \n",
" 5.415358 | \n",
" | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" SYSTEM TIME A B caption\n",
"0 0.00 3.000000 5.000000 Initial state\n",
"1 0.02 2.800000 5.100000 \n",
"2 0.04 2.648000 5.176000 \n",
"3 0.06 2.532480 5.233760 \n",
"4 0.08 2.444685 5.277658 \n",
"5 0.10 2.377960 5.311020 \n",
"6 0.12 2.327250 5.336375 \n",
"7 0.14 2.288710 5.355645 \n",
"8 0.16 2.259420 5.370290 \n",
"9 0.18 2.237159 5.381421 \n",
"10 0.20 2.220241 5.389880 \n",
"11 0.22 2.207383 5.396309 \n",
"12 0.24 2.197611 5.401194 \n",
"13 0.26 2.190184 5.404908 \n",
"14 0.28 2.184540 5.407730 \n",
"15 0.30 2.180251 5.409875 \n",
"16 0.32 2.176990 5.411505 \n",
"17 0.34 2.174513 5.412744 \n",
"18 0.36 2.172630 5.413685 \n",
"19 0.38 2.171199 5.414401 \n",
"20 0.40 2.170111 5.414945 \n",
"21 0.42 2.169284 5.415358 "
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = bio.get_history()\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "7a77d5dc-035c-40b7-bd82-44bcfdef3ac6",
"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.02,
0.04,
0.06,
0.08,
0.1,
0.12000000000000001,
0.14,
0.16,
0.18,
0.19999999999999998,
0.21999999999999997,
0.23999999999999996,
0.25999999999999995,
0.27999999999999997,
0.3,
0.32,
0.34,
0.36000000000000004,
0.38000000000000006,
0.4000000000000001,
0.4200000000000001
],
"xaxis": "x",
"y": [
3,
2.8,
2.6479999999999997,
2.5324799999999996,
2.4446847999999997,
2.3779604479999996,
2.32724994048,
2.2887099547647995,
2.2594195656212475,
2.237158869872148,
2.2202407411028324,
2.2073829632381528,
2.197611052060996,
2.1901843995663572,
2.1845401436704317,
2.180250509189528,
2.1769903869840412,
2.174512694107871,
2.172629647521982,
2.171198532116706,
2.1701108844086967,
2.1692842721506094
],
"yaxis": "y"
},
{
"hovertemplate": "Chemical=B
SYSTEM TIME=%{x}
concentration=%{y}",
"legendgroup": "B",
"line": {
"color": "orange",
"dash": "solid"
},
"marker": {
"symbol": "circle"
},
"mode": "lines",
"name": "B",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.02,
0.04,
0.06,
0.08,
0.1,
0.12000000000000001,
0.14,
0.16,
0.18,
0.19999999999999998,
0.21999999999999997,
0.23999999999999996,
0.25999999999999995,
0.27999999999999997,
0.3,
0.32,
0.34,
0.36000000000000004,
0.38000000000000006,
0.4000000000000001,
0.4200000000000001
],
"xaxis": "x",
"y": [
5,
5.1,
5.175999999999999,
5.233759999999999,
5.2776575999999995,
5.311019775999999,
5.336375029759999,
5.355645022617599,
5.370290217189376,
5.381420565063926,
5.389879629448584,
5.396308518380923,
5.401194473969502,
5.404907800216821,
5.407729928164784,
5.409874745405236,
5.411504806507979,
5.412743652946064,
5.413685176239008,
5.414400733941646,
5.414944557795651,
5.415357863924695
],
"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": "2A <-> B : changes in concentrations with time"
},
"xaxis": {
"anchor": "y",
"autorange": true,
"domain": [
0,
1
],
"range": [
0,
0.4200000000000001
],
"title": {
"text": "SYSTEM TIME"
},
"type": "linear"
},
"yaxis": {
"anchor": "x",
"autorange": true,
"domain": [
0,
1
],
"range": [
1.9889468503853824,
5.595695285689922
],
"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\", \"B\"], \n",
" title=\"2A <-> B : changes in concentrations with time\",\n",
" color_discrete_sequence = ['navy', 'orange'],\n",
" labels={\"value\":\"concentration\", \"variable\":\"Chemical\"})\n",
"fig.show()"
]
},
{
"cell_type": "markdown",
"id": "c3d00af0-3222-4cba-8367-3345cea820f4",
"metadata": {},
"source": [
"A gets depleted, while B gets produced."
]
},
{
"cell_type": "markdown",
"id": "ab27ab50-7be4-4257-a6cc-2ef163539e1f",
"metadata": {},
"source": [
"#### Let's verify that the stoichiometry is being respected"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "e88539b9-28e1-4b07-9b68-169d1e650e4f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(array([3., 5.], dtype=float32), array([2.8, 5.1], dtype=float32))"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# We'll check the first two arrays of concentrations, from the run's history\n",
"arr0 = bio.reaction_dynamics.get_historical_concentrations(row=0, df=df)\n",
"arr1 = bio.reaction_dynamics.get_historical_concentrations(row=1, df=df)\n",
"arr0, arr1"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "f1d42c06-f5bc-447d-93c0-bf7c4b1c824d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bio.reaction_dynamics.stoichiometry_checker(rxn_index=0, \n",
" conc_arr_before = arr0, \n",
" conc_arr_after = arr1)"
]
},
{
"cell_type": "markdown",
"id": "6c277db7-6b2b-4e74-b50e-4746cff17e90",
"metadata": {},
"source": [
"# STARTING OVER, this time with 2nd-order kinetics in the forward reaction"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "162100c5-e9d4-498b-81ee-be7b71e7f542",
"metadata": {},
"outputs": [],
"source": [
"bio.reaction_dynamics.clear_reactions()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "9c09f158-2d64-49d6-8d0c-6d3a8b7eff4b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Reaction 2A <-> B , NOW WITH 2nd-order kinetics in the forward direction\n",
"chem_data.add_reaction(reactants=[(2, \"A\", 2)], products=[\"B\"], forward_rate=5., reverse_rate=2.)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "f2dea24e-6f87-4f76-a513-176916934edb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SYSTEM STATE at Time t = 0.42:\n",
"1 bins and 2 species:\n",
" Species 0 (A). Diff rate: None. Conc: [3.]\n",
" Species 1 (B). Diff rate: None. Conc: [5.]\n"
]
}
],
"source": [
"# RESET the concentrations to their original values\n",
"bio.set_all_uniform_concentrations( [3., 5.] )\n",
"\n",
"bio.describe_state()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "8c2155d6-cb42-49e3-8247-c858b0c65860",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" SYSTEM TIME | \n",
" A | \n",
" B | \n",
" caption | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.00 | \n",
" 3.000000 | \n",
" 5.000000 | \n",
" Initial state | \n",
"
\n",
" \n",
" | 1 | \n",
" 0.02 | \n",
" 2.800000 | \n",
" 5.100000 | \n",
" | \n",
"
\n",
" \n",
" | 2 | \n",
" 0.04 | \n",
" 2.648000 | \n",
" 5.176000 | \n",
" | \n",
"
\n",
" \n",
" | 3 | \n",
" 0.06 | \n",
" 2.532480 | \n",
" 5.233760 | \n",
" | \n",
"
\n",
" \n",
" | 4 | \n",
" 0.08 | \n",
" 2.444685 | \n",
" 5.277658 | \n",
" | \n",
"
\n",
" \n",
" | 5 | \n",
" 0.10 | \n",
" 2.377960 | \n",
" 5.311020 | \n",
" | \n",
"
\n",
" \n",
" | 6 | \n",
" 0.12 | \n",
" 2.327250 | \n",
" 5.336375 | \n",
" | \n",
"
\n",
" \n",
" | 7 | \n",
" 0.14 | \n",
" 2.288710 | \n",
" 5.355645 | \n",
" | \n",
"
\n",
" \n",
" | 8 | \n",
" 0.16 | \n",
" 2.259420 | \n",
" 5.370290 | \n",
" | \n",
"
\n",
" \n",
" | 9 | \n",
" 0.18 | \n",
" 2.237159 | \n",
" 5.381421 | \n",
" | \n",
"
\n",
" \n",
" | 10 | \n",
" 0.20 | \n",
" 2.220241 | \n",
" 5.389880 | \n",
" | \n",
"
\n",
" \n",
" | 11 | \n",
" 0.22 | \n",
" 2.207383 | \n",
" 5.396309 | \n",
" | \n",
"
\n",
" \n",
" | 12 | \n",
" 0.24 | \n",
" 2.197611 | \n",
" 5.401194 | \n",
" | \n",
"
\n",
" \n",
" | 13 | \n",
" 0.26 | \n",
" 2.190184 | \n",
" 5.404908 | \n",
" | \n",
"
\n",
" \n",
" | 14 | \n",
" 0.28 | \n",
" 2.184540 | \n",
" 5.407730 | \n",
" | \n",
"
\n",
" \n",
" | 15 | \n",
" 0.30 | \n",
" 2.180251 | \n",
" 5.409875 | \n",
" | \n",
"
\n",
" \n",
" | 16 | \n",
" 0.32 | \n",
" 2.176990 | \n",
" 5.411505 | \n",
" | \n",
"
\n",
" \n",
" | 17 | \n",
" 0.34 | \n",
" 2.174513 | \n",
" 5.412744 | \n",
" | \n",
"
\n",
" \n",
" | 18 | \n",
" 0.36 | \n",
" 2.172630 | \n",
" 5.413685 | \n",
" | \n",
"
\n",
" \n",
" | 19 | \n",
" 0.38 | \n",
" 2.171199 | \n",
" 5.414401 | \n",
" | \n",
"
\n",
" \n",
" | 20 | \n",
" 0.40 | \n",
" 2.170111 | \n",
" 5.414945 | \n",
" | \n",
"
\n",
" \n",
" | 21 | \n",
" 0.42 | \n",
" 2.169284 | \n",
" 5.415358 | \n",
" | \n",
"
\n",
" \n",
" | 22 | \n",
" 0.42 | \n",
" 3.000000 | \n",
" 5.000000 | \n",
" RESET all concentrations to initial values | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" SYSTEM TIME A B \\\n",
"0 0.00 3.000000 5.000000 \n",
"1 0.02 2.800000 5.100000 \n",
"2 0.04 2.648000 5.176000 \n",
"3 0.06 2.532480 5.233760 \n",
"4 0.08 2.444685 5.277658 \n",
"5 0.10 2.377960 5.311020 \n",
"6 0.12 2.327250 5.336375 \n",
"7 0.14 2.288710 5.355645 \n",
"8 0.16 2.259420 5.370290 \n",
"9 0.18 2.237159 5.381421 \n",
"10 0.20 2.220241 5.389880 \n",
"11 0.22 2.207383 5.396309 \n",
"12 0.24 2.197611 5.401194 \n",
"13 0.26 2.190184 5.404908 \n",
"14 0.28 2.184540 5.407730 \n",
"15 0.30 2.180251 5.409875 \n",
"16 0.32 2.176990 5.411505 \n",
"17 0.34 2.174513 5.412744 \n",
"18 0.36 2.172630 5.413685 \n",
"19 0.38 2.171199 5.414401 \n",
"20 0.40 2.170111 5.414945 \n",
"21 0.42 2.169284 5.415358 \n",
"22 0.42 3.000000 5.000000 \n",
"\n",
" caption \n",
"0 Initial state \n",
"1 \n",
"2 \n",
"3 \n",
"4 \n",
"5 \n",
"6 \n",
"7 \n",
"8 \n",
"9 \n",
"10 \n",
"11 \n",
"12 \n",
"13 \n",
"14 \n",
"15 \n",
"16 \n",
"17 \n",
"18 \n",
"19 \n",
"20 \n",
"21 \n",
"22 RESET all concentrations to initial values "
]
},
"execution_count": 19,
"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",
" caption = \"RESET all concentrations to initial values\")\n",
"bio.get_history()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "68b1c2fa-fc50-4f33-a4f0-55d231939752",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of reactions: 1 (at temp. 25 C)\n",
"0: 2 A <-> B (kF = 5 / kR = 2 / delta_G = -2,271.4 / K = 2.5) | 2-th order in reactant A\n",
"Set of chemicals involved in the above reactions: {'A', 'B'}\n"
]
}
],
"source": [
"chem_data.describe_reactions()"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "9c9e81e0-b5b3-45eb-a4eb-0ab157dcf9db",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Reaction 2A B is 2nd order in A, and 1st order in B:\n",
"[GRAPHIC ELEMENT SENT TO LOG FILE `reaction_7.log.htm`]\n"
]
}
],
"source": [
"# Send a header and a plot to the HTML log file\n",
"log.write(\"Reaction 2A <-> B is 2nd order in A, and 1st order in B:\",\n",
" style=log.h2)\n",
"chem_data.plot_reaction_network(\"vue_cytoscape_2\")"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "ab938afe-a818-4e9c-bc2d-d347aa0d0a23",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SYSTEM STATE at Time t = 0.44:\n",
"1 bins and 2 species:\n",
" Species 0 (A). Diff rate: None. Conc: [1.6]\n",
" Species 1 (B). Diff rate: None. Conc: [5.7]\n"
]
}
],
"source": [
"# First step\n",
"bio.react(time_step=0.02, n_steps=1, snapshots={\"sample_bin\": 0})\n",
"bio.describe_state()"
]
},
{
"cell_type": "markdown",
"id": "0c8b4979-26aa-4b43-baa9-b65547d3ba24",
"metadata": {},
"source": [
"[A] = 1.6 , [B] = 5.7\n",
"_(Contrast with the counterpart in the 1st order kinetics: [A] = 2.8 , [B] = 5.1)_"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "a964cc75-e378-493a-aa5c-27da363c7baf",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" SYSTEM TIME | \n",
" A | \n",
" B | \n",
" caption | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.00 | \n",
" 3.000000 | \n",
" 5.000000 | \n",
" Initial state | \n",
"
\n",
" \n",
" | 1 | \n",
" 0.02 | \n",
" 2.800000 | \n",
" 5.100000 | \n",
" | \n",
"
\n",
" \n",
" | 2 | \n",
" 0.04 | \n",
" 2.648000 | \n",
" 5.176000 | \n",
" | \n",
"
\n",
" \n",
" | 3 | \n",
" 0.06 | \n",
" 2.532480 | \n",
" 5.233760 | \n",
" | \n",
"
\n",
" \n",
" | 4 | \n",
" 0.08 | \n",
" 2.444685 | \n",
" 5.277658 | \n",
" | \n",
"
\n",
" \n",
" | 5 | \n",
" 0.10 | \n",
" 2.377960 | \n",
" 5.311020 | \n",
" | \n",
"
\n",
" \n",
" | 6 | \n",
" 0.12 | \n",
" 2.327250 | \n",
" 5.336375 | \n",
" | \n",
"
\n",
" \n",
" | 7 | \n",
" 0.14 | \n",
" 2.288710 | \n",
" 5.355645 | \n",
" | \n",
"
\n",
" \n",
" | 8 | \n",
" 0.16 | \n",
" 2.259420 | \n",
" 5.370290 | \n",
" | \n",
"
\n",
" \n",
" | 9 | \n",
" 0.18 | \n",
" 2.237159 | \n",
" 5.381421 | \n",
" | \n",
"
\n",
" \n",
" | 10 | \n",
" 0.20 | \n",
" 2.220241 | \n",
" 5.389880 | \n",
" | \n",
"
\n",
" \n",
" | 11 | \n",
" 0.22 | \n",
" 2.207383 | \n",
" 5.396309 | \n",
" | \n",
"
\n",
" \n",
" | 12 | \n",
" 0.24 | \n",
" 2.197611 | \n",
" 5.401194 | \n",
" | \n",
"
\n",
" \n",
" | 13 | \n",
" 0.26 | \n",
" 2.190184 | \n",
" 5.404908 | \n",
" | \n",
"
\n",
" \n",
" | 14 | \n",
" 0.28 | \n",
" 2.184540 | \n",
" 5.407730 | \n",
" | \n",
"
\n",
" \n",
" | 15 | \n",
" 0.30 | \n",
" 2.180251 | \n",
" 5.409875 | \n",
" | \n",
"
\n",
" \n",
" | 16 | \n",
" 0.32 | \n",
" 2.176990 | \n",
" 5.411505 | \n",
" | \n",
"
\n",
" \n",
" | 17 | \n",
" 0.34 | \n",
" 2.174513 | \n",
" 5.412744 | \n",
" | \n",
"
\n",
" \n",
" | 18 | \n",
" 0.36 | \n",
" 2.172630 | \n",
" 5.413685 | \n",
" | \n",
"
\n",
" \n",
" | 19 | \n",
" 0.38 | \n",
" 2.171199 | \n",
" 5.414401 | \n",
" | \n",
"
\n",
" \n",
" | 20 | \n",
" 0.40 | \n",
" 2.170111 | \n",
" 5.414945 | \n",
" | \n",
"
\n",
" \n",
" | 21 | \n",
" 0.42 | \n",
" 2.169284 | \n",
" 5.415358 | \n",
" | \n",
"
\n",
" \n",
" | 22 | \n",
" 0.42 | \n",
" 3.000000 | \n",
" 5.000000 | \n",
" RESET all concentrations to initial values | \n",
"
\n",
" \n",
" | 23 | \n",
" 0.44 | \n",
" 1.600000 | \n",
" 5.700000 | \n",
" | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" SYSTEM TIME A B \\\n",
"0 0.00 3.000000 5.000000 \n",
"1 0.02 2.800000 5.100000 \n",
"2 0.04 2.648000 5.176000 \n",
"3 0.06 2.532480 5.233760 \n",
"4 0.08 2.444685 5.277658 \n",
"5 0.10 2.377960 5.311020 \n",
"6 0.12 2.327250 5.336375 \n",
"7 0.14 2.288710 5.355645 \n",
"8 0.16 2.259420 5.370290 \n",
"9 0.18 2.237159 5.381421 \n",
"10 0.20 2.220241 5.389880 \n",
"11 0.22 2.207383 5.396309 \n",
"12 0.24 2.197611 5.401194 \n",
"13 0.26 2.190184 5.404908 \n",
"14 0.28 2.184540 5.407730 \n",
"15 0.30 2.180251 5.409875 \n",
"16 0.32 2.176990 5.411505 \n",
"17 0.34 2.174513 5.412744 \n",
"18 0.36 2.172630 5.413685 \n",
"19 0.38 2.171199 5.414401 \n",
"20 0.40 2.170111 5.414945 \n",
"21 0.42 2.169284 5.415358 \n",
"22 0.42 3.000000 5.000000 \n",
"23 0.44 1.600000 5.700000 \n",
"\n",
" caption \n",
"0 Initial state \n",
"1 \n",
"2 \n",
"3 \n",
"4 \n",
"5 \n",
"6 \n",
"7 \n",
"8 \n",
"9 \n",
"10 \n",
"11 \n",
"12 \n",
"13 \n",
"14 \n",
"15 \n",
"16 \n",
"17 \n",
"18 \n",
"19 \n",
"20 \n",
"21 \n",
"22 RESET all concentrations to initial values \n",
"23 "
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bio.get_history()"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "95e9aab1-a16d-46b7-9b97-82ab60011e6b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SYSTEM STATE at Time t = 0.84:\n",
"1 bins and 2 species:\n",
" Species 0 (A). Diff rate: None. Conc: [1.51554944]\n",
" Species 1 (B). Diff rate: None. Conc: [5.74222528]\n"
]
}
],
"source": [
"# Numerous more steps\n",
"bio.react(time_step=0.02, n_steps=20, snapshots={\"sample_bin\": 0})\n",
"\n",
"bio.describe_state()"
]
},
{
"cell_type": "markdown",
"id": "bec6b756-4269-4ab5-b4e8-7ba989b4454e",
"metadata": {},
"source": [
"The systems settles in the following equilibrium: [A] = 1.51554944 , [B] = 5.74222528"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "8c2e158b-091f-485d-b5fd-a1dd21bcf6f0",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2 A <-> B\n",
"Final concentrations: [A] = 1.516 ; [B] = 5.742\n",
"1. Ratio of reactant/product concentrations, adjusted for reaction orders: 2.5\n",
" Formula used: [B] / [A]^2 \n",
"2. Ratio of forward/reverse reaction rates: 2.5\n",
"Discrepancy between the two values: 1.041e-08 %\n",
"Reaction IS in equilibrium (within 1% tolerance)\n",
"\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 25,
"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": 26,
"id": "3eeeb74b-0427-48ce-a2e3-9a876c0c66a0",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" SYSTEM TIME | \n",
" A | \n",
" B | \n",
" caption | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.00 | \n",
" 3.000000 | \n",
" 5.000000 | \n",
" Initial state | \n",
"
\n",
" \n",
" | 1 | \n",
" 0.02 | \n",
" 2.800000 | \n",
" 5.100000 | \n",
" | \n",
"
\n",
" \n",
" | 2 | \n",
" 0.04 | \n",
" 2.648000 | \n",
" 5.176000 | \n",
" | \n",
"
\n",
" \n",
" | 3 | \n",
" 0.06 | \n",
" 2.532480 | \n",
" 5.233760 | \n",
" | \n",
"
\n",
" \n",
" | 4 | \n",
" 0.08 | \n",
" 2.444685 | \n",
" 5.277658 | \n",
" | \n",
"
\n",
" \n",
" | 5 | \n",
" 0.10 | \n",
" 2.377960 | \n",
" 5.311020 | \n",
" | \n",
"
\n",
" \n",
" | 6 | \n",
" 0.12 | \n",
" 2.327250 | \n",
" 5.336375 | \n",
" | \n",
"
\n",
" \n",
" | 7 | \n",
" 0.14 | \n",
" 2.288710 | \n",
" 5.355645 | \n",
" | \n",
"
\n",
" \n",
" | 8 | \n",
" 0.16 | \n",
" 2.259420 | \n",
" 5.370290 | \n",
" | \n",
"
\n",
" \n",
" | 9 | \n",
" 0.18 | \n",
" 2.237159 | \n",
" 5.381421 | \n",
" | \n",
"
\n",
" \n",
" | 10 | \n",
" 0.20 | \n",
" 2.220241 | \n",
" 5.389880 | \n",
" | \n",
"
\n",
" \n",
" | 11 | \n",
" 0.22 | \n",
" 2.207383 | \n",
" 5.396309 | \n",
" | \n",
"
\n",
" \n",
" | 12 | \n",
" 0.24 | \n",
" 2.197611 | \n",
" 5.401194 | \n",
" | \n",
"
\n",
" \n",
" | 13 | \n",
" 0.26 | \n",
" 2.190184 | \n",
" 5.404908 | \n",
" | \n",
"
\n",
" \n",
" | 14 | \n",
" 0.28 | \n",
" 2.184540 | \n",
" 5.407730 | \n",
" | \n",
"
\n",
" \n",
" | 15 | \n",
" 0.30 | \n",
" 2.180251 | \n",
" 5.409875 | \n",
" | \n",
"
\n",
" \n",
" | 16 | \n",
" 0.32 | \n",
" 2.176990 | \n",
" 5.411505 | \n",
" | \n",
"
\n",
" \n",
" | 17 | \n",
" 0.34 | \n",
" 2.174513 | \n",
" 5.412744 | \n",
" | \n",
"
\n",
" \n",
" | 18 | \n",
" 0.36 | \n",
" 2.172630 | \n",
" 5.413685 | \n",
" | \n",
"
\n",
" \n",
" | 19 | \n",
" 0.38 | \n",
" 2.171199 | \n",
" 5.414401 | \n",
" | \n",
"
\n",
" \n",
" | 20 | \n",
" 0.40 | \n",
" 2.170111 | \n",
" 5.414945 | \n",
" | \n",
"
\n",
" \n",
" | 21 | \n",
" 0.42 | \n",
" 2.169284 | \n",
" 5.415358 | \n",
" | \n",
"
\n",
" \n",
" | 22 | \n",
" 0.42 | \n",
" 3.000000 | \n",
" 5.000000 | \n",
" RESET all concentrations to initial values | \n",
"
\n",
" \n",
" | 23 | \n",
" 0.44 | \n",
" 1.600000 | \n",
" 5.700000 | \n",
" | \n",
"
\n",
" \n",
" | 24 | \n",
" 0.46 | \n",
" 1.544000 | \n",
" 5.728000 | \n",
" | \n",
"
\n",
" \n",
" | 25 | \n",
" 0.48 | \n",
" 1.525453 | \n",
" 5.737274 | \n",
" | \n",
"
\n",
" \n",
" | 26 | \n",
" 0.50 | \n",
" 1.519033 | \n",
" 5.740483 | \n",
" | \n",
"
\n",
" \n",
" | 27 | \n",
" 0.52 | \n",
" 1.516780 | \n",
" 5.741610 | \n",
" | \n",
"
\n",
" \n",
" | 28 | \n",
" 0.54 | \n",
" 1.515984 | \n",
" 5.742008 | \n",
" | \n",
"
\n",
" \n",
" | 29 | \n",
" 0.56 | \n",
" 1.515703 | \n",
" 5.742148 | \n",
" | \n",
"
\n",
" \n",
" | 30 | \n",
" 0.58 | \n",
" 1.515604 | \n",
" 5.742198 | \n",
" | \n",
"
\n",
" \n",
" | 31 | \n",
" 0.60 | \n",
" 1.515569 | \n",
" 5.742216 | \n",
" | \n",
"
\n",
" \n",
" | 32 | \n",
" 0.62 | \n",
" 1.515556 | \n",
" 5.742222 | \n",
" | \n",
"
\n",
" \n",
" | 33 | \n",
" 0.64 | \n",
" 1.515552 | \n",
" 5.742224 | \n",
" | \n",
"
\n",
" \n",
" | 34 | \n",
" 0.66 | \n",
" 1.515550 | \n",
" 5.742225 | \n",
" | \n",
"
\n",
" \n",
" | 35 | \n",
" 0.68 | \n",
" 1.515550 | \n",
" 5.742225 | \n",
" | \n",
"
\n",
" \n",
" | 36 | \n",
" 0.70 | \n",
" 1.515550 | \n",
" 5.742225 | \n",
" | \n",
"
\n",
" \n",
" | 37 | \n",
" 0.72 | \n",
" 1.515549 | \n",
" 5.742225 | \n",
" | \n",
"
\n",
" \n",
" | 38 | \n",
" 0.74 | \n",
" 1.515549 | \n",
" 5.742225 | \n",
" | \n",
"
\n",
" \n",
" | 39 | \n",
" 0.76 | \n",
" 1.515549 | \n",
" 5.742225 | \n",
" | \n",
"
\n",
" \n",
" | 40 | \n",
" 0.78 | \n",
" 1.515549 | \n",
" 5.742225 | \n",
" | \n",
"
\n",
" \n",
" | 41 | \n",
" 0.80 | \n",
" 1.515549 | \n",
" 5.742225 | \n",
" | \n",
"
\n",
" \n",
" | 42 | \n",
" 0.82 | \n",
" 1.515549 | \n",
" 5.742225 | \n",
" | \n",
"
\n",
" \n",
" | 43 | \n",
" 0.84 | \n",
" 1.515549 | \n",
" 5.742225 | \n",
" | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" SYSTEM TIME A B \\\n",
"0 0.00 3.000000 5.000000 \n",
"1 0.02 2.800000 5.100000 \n",
"2 0.04 2.648000 5.176000 \n",
"3 0.06 2.532480 5.233760 \n",
"4 0.08 2.444685 5.277658 \n",
"5 0.10 2.377960 5.311020 \n",
"6 0.12 2.327250 5.336375 \n",
"7 0.14 2.288710 5.355645 \n",
"8 0.16 2.259420 5.370290 \n",
"9 0.18 2.237159 5.381421 \n",
"10 0.20 2.220241 5.389880 \n",
"11 0.22 2.207383 5.396309 \n",
"12 0.24 2.197611 5.401194 \n",
"13 0.26 2.190184 5.404908 \n",
"14 0.28 2.184540 5.407730 \n",
"15 0.30 2.180251 5.409875 \n",
"16 0.32 2.176990 5.411505 \n",
"17 0.34 2.174513 5.412744 \n",
"18 0.36 2.172630 5.413685 \n",
"19 0.38 2.171199 5.414401 \n",
"20 0.40 2.170111 5.414945 \n",
"21 0.42 2.169284 5.415358 \n",
"22 0.42 3.000000 5.000000 \n",
"23 0.44 1.600000 5.700000 \n",
"24 0.46 1.544000 5.728000 \n",
"25 0.48 1.525453 5.737274 \n",
"26 0.50 1.519033 5.740483 \n",
"27 0.52 1.516780 5.741610 \n",
"28 0.54 1.515984 5.742008 \n",
"29 0.56 1.515703 5.742148 \n",
"30 0.58 1.515604 5.742198 \n",
"31 0.60 1.515569 5.742216 \n",
"32 0.62 1.515556 5.742222 \n",
"33 0.64 1.515552 5.742224 \n",
"34 0.66 1.515550 5.742225 \n",
"35 0.68 1.515550 5.742225 \n",
"36 0.70 1.515550 5.742225 \n",
"37 0.72 1.515549 5.742225 \n",
"38 0.74 1.515549 5.742225 \n",
"39 0.76 1.515549 5.742225 \n",
"40 0.78 1.515549 5.742225 \n",
"41 0.80 1.515549 5.742225 \n",
"42 0.82 1.515549 5.742225 \n",
"43 0.84 1.515549 5.742225 \n",
"\n",
" caption \n",
"0 Initial state \n",
"1 \n",
"2 \n",
"3 \n",
"4 \n",
"5 \n",
"6 \n",
"7 \n",
"8 \n",
"9 \n",
"10 \n",
"11 \n",
"12 \n",
"13 \n",
"14 \n",
"15 \n",
"16 \n",
"17 \n",
"18 \n",
"19 \n",
"20 \n",
"21 \n",
"22 RESET all concentrations to initial values \n",
"23 \n",
"24 \n",
"25 \n",
"26 \n",
"27 \n",
"28 \n",
"29 \n",
"30 \n",
"31 \n",
"32 \n",
"33 \n",
"34 \n",
"35 \n",
"36 \n",
"37 \n",
"38 \n",
"39 \n",
"40 \n",
"41 \n",
"42 \n",
"43 "
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df2 = bio.get_history()\n",
"df2"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "16ec259b-98fe-4660-8123-83fdf55b74fb",
"metadata": {},
"outputs": [
{
"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.02,
0.04,
0.06,
0.08,
0.1,
0.12000000000000001,
0.14,
0.16,
0.18,
0.19999999999999998,
0.21999999999999997,
0.23999999999999996,
0.25999999999999995,
0.27999999999999997,
0.3,
0.32,
0.34,
0.36000000000000004,
0.38000000000000006,
0.4000000000000001,
0.4200000000000001,
0.4200000000000001,
0.4400000000000001,
0.46000000000000013,
0.48000000000000015,
0.5000000000000001,
0.5200000000000001,
0.5400000000000001,
0.5600000000000002,
0.5800000000000002,
0.6000000000000002,
0.6200000000000002,
0.6400000000000002,
0.6600000000000003,
0.6800000000000003,
0.7000000000000003,
0.7200000000000003,
0.7400000000000003,
0.7600000000000003,
0.7800000000000004,
0.8000000000000004,
0.8200000000000004,
0.8400000000000004
],
"xaxis": "x",
"y": [
3,
2.8,
2.6479999999999997,
2.5324799999999996,
2.4446847999999997,
2.3779604479999996,
2.32724994048,
2.2887099547647995,
2.2594195656212475,
2.237158869872148,
2.2202407411028324,
2.2073829632381528,
2.197611052060996,
2.1901843995663572,
2.1845401436704317,
2.180250509189528,
2.1769903869840412,
2.174512694107871,
2.172629647521982,
2.171198532116706,
2.1701108844086967,
2.1692842721506094,
3,
1.5999999999999999,
1.544,
1.5254528,
1.519033438994432,
1.5167795836780045,
1.5159843392384003,
1.5157032623056466,
1.5156038559406249,
1.515568692074582,
1.5155562523122668,
1.5155518514352155,
1.515550294500065,
1.5155497436882157,
1.5155495488220039,
1.515549479882208,
1.5155494554926734,
1.5155494468641386,
1.5155494438115338,
1.5155494427315825,
1.515549442349517,
1.5155494422143498
],
"yaxis": "y"
},
{
"hovertemplate": "Chemical=B
SYSTEM TIME=%{x}
concentration=%{y}",
"legendgroup": "B",
"line": {
"color": "orange",
"dash": "solid"
},
"marker": {
"symbol": "circle"
},
"mode": "lines",
"name": "B",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.02,
0.04,
0.06,
0.08,
0.1,
0.12000000000000001,
0.14,
0.16,
0.18,
0.19999999999999998,
0.21999999999999997,
0.23999999999999996,
0.25999999999999995,
0.27999999999999997,
0.3,
0.32,
0.34,
0.36000000000000004,
0.38000000000000006,
0.4000000000000001,
0.4200000000000001,
0.4200000000000001,
0.4400000000000001,
0.46000000000000013,
0.48000000000000015,
0.5000000000000001,
0.5200000000000001,
0.5400000000000001,
0.5600000000000002,
0.5800000000000002,
0.6000000000000002,
0.6200000000000002,
0.6400000000000002,
0.6600000000000003,
0.6800000000000003,
0.7000000000000003,
0.7200000000000003,
0.7400000000000003,
0.7600000000000003,
0.7800000000000004,
0.8000000000000004,
0.8200000000000004,
0.8400000000000004
],
"xaxis": "x",
"y": [
5,
5.1,
5.175999999999999,
5.233759999999999,
5.2776575999999995,
5.311019775999999,
5.336375029759999,
5.355645022617599,
5.370290217189376,
5.381420565063926,
5.389879629448584,
5.396308518380923,
5.401194473969502,
5.404907800216821,
5.407729928164784,
5.409874745405236,
5.411504806507979,
5.412743652946064,
5.413685176239008,
5.414400733941646,
5.414944557795651,
5.415357863924695,
5,
5.7,
5.728,
5.7372736,
5.740483280502784,
5.741610208160997,
5.7420078303808,
5.742148368847177,
5.742198072029688,
5.74221565396271,
5.742221873843867,
5.742224074282393,
5.742224852749968,
5.7422251281558925,
5.7422252255889985,
5.7422252600588966,
5.7422252722536635,
5.742225276567931,
5.742225278094233,
5.7422252786342085,
5.7422252788252415,
5.742225278892825
],
"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": "2A <-> B : changes in concentrations (the jump at 0.42 is the concentration reset)"
},
"xaxis": {
"anchor": "y",
"autorange": true,
"domain": [
0,
1
],
"range": [
0,
0.8400000000000004
],
"title": {
"text": "SYSTEM TIME"
},
"type": "linear"
},
"yaxis": {
"anchor": "x",
"autorange": true,
"domain": [
0,
1
],
"range": [
1.2807341179544345,
5.97704060315274
],
"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\", \"B\"], \n",
" title=\"2A <-> B : changes in concentrations (the jump at 0.42 is the concentration reset)\",\n",
" color_discrete_sequence = ['navy', 'orange'],\n",
" labels={\"value\":\"concentration\", \"variable\":\"Chemical\"})\n",
"fig.show()"
]
},
{
"cell_type": "markdown",
"id": "3fd3bce2-7095-43a4-9ef0-764714be1301",
"metadata": {},
"source": [
"**Compared to first-order kinetics in A**, the (2nd order in A) reaction now takes place much more quickly, and proceeds to almost complete depletion of A"
]
},
{
"cell_type": "markdown",
"id": "ea064b52-efc9-4fb6-94c7-9a22264bc751",
"metadata": {},
"source": [
"#### Let's verify that the stoichiometry is still being respected"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "8798e44e-7a1b-41ba-af64-5a4b1e7cf687",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(array([3., 5.], dtype=float32), array([1.6, 5.7], dtype=float32))"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# We'll check the first two arrays of concentrations, from the run's history\n",
"arr0 = bio.reaction_dynamics.get_historical_concentrations(row=22, df=df2) # Row 22 is the conc. reset\n",
"arr1 = bio.reaction_dynamics.get_historical_concentrations(row=23, df=df2)\n",
"arr0, arr1"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "bdbcef17-1fc3-4547-8afe-7c932a586dc3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bio.reaction_dynamics.stoichiometry_checker(rxn_index=0, \n",
" conc_arr_before = arr0, \n",
" conc_arr_after = arr1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0ebe7c58",
"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
}