{
"cells": [
{
"cell_type": "markdown",
"id": "3bbe8002-bdf3-490c-bde0-80dd3713a3d0",
"metadata": {},
"source": [
"## Association/Dissociation reaction `A + B <-> C`\n",
"#### with 1st-order kinetics for each species, taken to equilibrium.\n",
"#### Exploration of debugging and diagnostics options\n",
"(Adaptive variable time steps are used)\n",
"\n",
"_See also the experiment \"1D/reactions/reaction_4\"_ \n",
"\n",
"LAST REVISED: May 5, 2024"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "d28567a7-ae12-4df6-bf2f-8ea7b132596c",
"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": "4bbaa8f3",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from experiments.get_notebook_info import get_notebook_basename\n",
"\n",
"from src.modules.reactions.reaction_dynamics import ReactionDynamics\n",
"from src.modules.visualization.graphic_log import GraphicLog"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "83c3cc5f-de21-4f66-9988-2806fbf0666d",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-> Output will be LOGGED into the file 'react_3.log.htm'\n"
]
}
],
"source": [
"# Initialize the HTML logging (for the graphics)\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": null,
"id": "22559b04-73d8-4bd2-8c8d-c95dbdb0e862",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "9329208b-070f-4902-8f37-0f11ddf75ed6",
"metadata": {},
"source": [
"# Initialize the System\n",
"Specify the chemicals, the reactions, and the initial concentrations"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e328c104-126d-400b-89fe-c4bbe1dc2212",
"metadata": {},
"outputs": [],
"source": [
"# Instantiate the simulator and specify the chemicals\n",
"dynamics = ReactionDynamics(names=[\"A\", \"B\", \"C\"])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "1521d60a-b189-40d1-be43-013a6f5ac510",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of reactions: 1 (at temp. 25 C)\n",
"0: A + B <-> C (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', 'C', 'B'}\n"
]
}
],
"source": [
"# Reaction A + B <-> C , with 1st-order kinetics for each species\n",
"dynamics.add_reaction(reactants=[\"A\" , \"B\"], products=\"C\",\n",
" forward_rate=5., reverse_rate=2.)\n",
"\n",
"dynamics.describe_reactions()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "cb582868-431c-4022-aa0e-a2f554f80d6c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[GRAPHIC ELEMENT SENT TO LOG FILE `react_3.log.htm`]\n"
]
}
],
"source": [
"# Send a plot of the network of reactions to the HTML log file\n",
"dynamics.plot_reaction_network(\"vue_cytoscape_2\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "ae304704-c8d9-4cef-9e0b-2587bb3909ef",
"metadata": {},
"outputs": [],
"source": [
"# Set the initial concentrations of all the chemicals, in their index order\n",
"dynamics.set_conc([10., 50., 20.], snapshot=True)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "a605dacf-2c67-403e-9aa9-5be25fc9f481",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SYSTEM STATE at Time t = 0:\n",
"3 species:\n",
" Species 0 (A). Conc: 10.0\n",
" Species 1 (B). Conc: 50.0\n",
" Species 2 (C). Conc: 20.0\n",
"Set of chemicals involved in reactions: {'A', 'C', 'B'}\n"
]
}
],
"source": [
"dynamics.describe_state()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "0ff2c242-a15b-456d-ad56-0ba1041c0b4c",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" SYSTEM TIME | \n",
" A | \n",
" B | \n",
" C | \n",
" caption | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.0 | \n",
" 10.0 | \n",
" 50.0 | \n",
" 20.0 | \n",
" Initial state | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" SYSTEM TIME A B C caption\n",
"0 0.0 10.0 50.0 20.0 Initial state"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dynamics.get_history()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "42f757ce-98bb-4d3f-871d-78d059cba2a9",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "1767907f-a74c-484c-a5ef-ef134c96f928",
"metadata": {},
"source": [
"### Sneak preview of eventual equilibrum:\n",
"we can preview the final equilibrium concentrations without actually running the simulation"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "8e24fba5-d8af-475d-8701-573fb6eff788",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'A': 0.2948774087575341, 'B': 40.294877408757536, 'C': 29.705122591242464}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dynamics.find_equilibrium_conc(rxn_index=0) # This is an EXACT solution"
]
},
{
"cell_type": "markdown",
"id": "e1f57520-6b81-49fc-8b82-b9424a5fe70f",
"metadata": {},
"source": [
"The reaction will proceed forward, with `A` and `B` being consumed, and `C` being produced"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d460fc5b-8e07-4efc-bb27-1d5093612de7",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "fc516ca2-e62d-4784-b826-5372ff7f4c75",
"metadata": {
"tags": []
},
"source": [
"# Run the reaction"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "2502cd11-0df9-4303-8895-98401a1df7b8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* INFO: the tentative time step (0.004) leads to a least one norm value > its ABORT threshold:\n",
" -> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.6 (set to 0.0024) [Step started at t=0, and will rewind there]\n",
"* INFO: the tentative time step (0.0024) leads to a least one norm value > its ABORT threshold:\n",
" -> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.6 (set to 0.00144) [Step started at t=0, and will rewind there]\n",
"* INFO: the tentative time step (0.00144) leads to a least one norm value > its ABORT threshold:\n",
" -> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.6 (set to 0.000864) [Step started at t=0, and will rewind there]\n",
"Some steps were backtracked and re-done, to prevent negative concentrations or excessively large concentration changes\n",
"23 total step(s) taken\n"
]
}
],
"source": [
"dynamics.set_diagnostics() # To save diagnostic information about the call to single_compartment_react()\n",
"\n",
"# For repeatibility, we avoid the defaults, and instead specify a particular group of preset parameters \n",
"# applicable to the adaptive time steps.\n",
"# Here we use a \"fast\" heuristic: advance quickly thru time\n",
"dynamics.use_adaptive_preset(preset=\"fast\")\n",
"\n",
"dynamics.single_compartment_react(initial_step=0.004, reaction_duration=0.06,\n",
" variable_steps=True, explain_variable_steps=False,\n",
" snapshots={\"initial_caption\": \"1st reaction step\",\n",
" \"final_caption\": \"last reaction step\"})"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "80fbaee3-bd6f-4197-9270-23374d46a4a7",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" SYSTEM TIME | \n",
" A | \n",
" B | \n",
" C | \n",
" caption | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.000000 | \n",
" 10.000000 | \n",
" 50.000000 | \n",
" 20.000000 | \n",
" Initial state | \n",
"
\n",
" \n",
" | 1 | \n",
" 0.000864 | \n",
" 7.874560 | \n",
" 47.874560 | \n",
" 22.125440 | \n",
" 1st reaction step | \n",
"
\n",
" \n",
" | 2 | \n",
" 0.001555 | \n",
" 6.602265 | \n",
" 46.602265 | \n",
" 23.397735 | \n",
" | \n",
"
\n",
" \n",
" | 3 | \n",
" 0.002246 | \n",
" 5.571266 | \n",
" 45.571266 | \n",
" 24.428734 | \n",
" | \n",
"
\n",
" \n",
" | 4 | \n",
" 0.002938 | \n",
" 4.727594 | \n",
" 44.727594 | \n",
" 25.272406 | \n",
" | \n",
"
\n",
" \n",
" | 5 | \n",
" 0.003629 | \n",
" 4.031746 | \n",
" 44.031746 | \n",
" 25.968254 | \n",
" | \n",
"
\n",
" \n",
" | 6 | \n",
" 0.004666 | \n",
" 3.165305 | \n",
" 43.165305 | \n",
" 26.834695 | \n",
" | \n",
"
\n",
" \n",
" | 7 | \n",
" 0.005702 | \n",
" 2.512652 | \n",
" 42.512652 | \n",
" 27.487348 | \n",
" | \n",
"
\n",
" \n",
" | 8 | \n",
" 0.006739 | \n",
" 2.015898 | \n",
" 42.015898 | \n",
" 27.984102 | \n",
" | \n",
"
\n",
" \n",
" | 9 | \n",
" 0.007776 | \n",
" 1.634842 | \n",
" 41.634842 | \n",
" 28.365158 | \n",
" | \n",
"
\n",
" \n",
" | 10 | \n",
" 0.008813 | \n",
" 1.340804 | \n",
" 41.340804 | \n",
" 28.659196 | \n",
" | \n",
"
\n",
" \n",
" | 11 | \n",
" 0.009850 | \n",
" 1.112883 | \n",
" 41.112883 | \n",
" 28.887117 | \n",
" | \n",
"
\n",
" \n",
" | 12 | \n",
" 0.010886 | \n",
" 0.935595 | \n",
" 40.935595 | \n",
" 29.064405 | \n",
" | \n",
"
\n",
" \n",
" | 13 | \n",
" 0.011923 | \n",
" 0.797321 | \n",
" 40.797321 | \n",
" 29.202679 | \n",
" | \n",
"
\n",
" \n",
" | 14 | \n",
" 0.013478 | \n",
" 0.635211 | \n",
" 40.635211 | \n",
" 29.364789 | \n",
" | \n",
"
\n",
" \n",
" | 15 | \n",
" 0.015034 | \n",
" 0.525833 | \n",
" 40.525833 | \n",
" 29.474167 | \n",
" | \n",
"
\n",
" \n",
" | 16 | \n",
" 0.016589 | \n",
" 0.451805 | \n",
" 40.451805 | \n",
" 29.548195 | \n",
" | \n",
"
\n",
" \n",
" | 17 | \n",
" 0.018922 | \n",
" 0.376490 | \n",
" 40.376490 | \n",
" 29.623510 | \n",
" | \n",
"
\n",
" \n",
" | 18 | \n",
" 0.021254 | \n",
" 0.337393 | \n",
" 40.337393 | \n",
" 29.662607 | \n",
" | \n",
"
\n",
" \n",
" | 19 | \n",
" 0.024754 | \n",
" 0.306871 | \n",
" 40.306871 | \n",
" 29.693129 | \n",
" | \n",
"
\n",
" \n",
" | 20 | \n",
" 0.030002 | \n",
" 0.293965 | \n",
" 40.293965 | \n",
" 29.706035 | \n",
" | \n",
"
\n",
" \n",
" | 21 | \n",
" 0.037876 | \n",
" 0.295437 | \n",
" 40.295437 | \n",
" 29.704563 | \n",
" | \n",
"
\n",
" \n",
" | 22 | \n",
" 0.049685 | \n",
" 0.294082 | \n",
" 40.294082 | \n",
" 29.705918 | \n",
" | \n",
"
\n",
" \n",
" | 23 | \n",
" 0.067400 | \n",
" 0.296969 | \n",
" 40.296969 | \n",
" 29.703031 | \n",
" last reaction step | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" SYSTEM TIME A B C caption\n",
"0 0.000000 10.000000 50.000000 20.000000 Initial state\n",
"1 0.000864 7.874560 47.874560 22.125440 1st reaction step\n",
"2 0.001555 6.602265 46.602265 23.397735 \n",
"3 0.002246 5.571266 45.571266 24.428734 \n",
"4 0.002938 4.727594 44.727594 25.272406 \n",
"5 0.003629 4.031746 44.031746 25.968254 \n",
"6 0.004666 3.165305 43.165305 26.834695 \n",
"7 0.005702 2.512652 42.512652 27.487348 \n",
"8 0.006739 2.015898 42.015898 27.984102 \n",
"9 0.007776 1.634842 41.634842 28.365158 \n",
"10 0.008813 1.340804 41.340804 28.659196 \n",
"11 0.009850 1.112883 41.112883 28.887117 \n",
"12 0.010886 0.935595 40.935595 29.064405 \n",
"13 0.011923 0.797321 40.797321 29.202679 \n",
"14 0.013478 0.635211 40.635211 29.364789 \n",
"15 0.015034 0.525833 40.525833 29.474167 \n",
"16 0.016589 0.451805 40.451805 29.548195 \n",
"17 0.018922 0.376490 40.376490 29.623510 \n",
"18 0.021254 0.337393 40.337393 29.662607 \n",
"19 0.024754 0.306871 40.306871 29.693129 \n",
"20 0.030002 0.293965 40.293965 29.706035 \n",
"21 0.037876 0.295437 40.295437 29.704563 \n",
"22 0.049685 0.294082 40.294082 29.705918 \n",
"23 0.067400 0.296969 40.296969 29.703031 last reaction step"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dynamics.get_history()"
]
},
{
"cell_type": "markdown",
"id": "b1366038-2dea-4d69-a655-ae464ca22922",
"metadata": {},
"source": [
"## Note: \"A\" (now largely depleted) is the limiting reagent"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "1598a75b-0322-45ac-bf2c-21fd09049966",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"From time 0 to 0.000864, in 1 step of 0.000864\n",
"From time 0.000864 to 0.003629, in 4 steps of 0.000691\n",
"From time 0.003629 to 0.01192, in 8 steps of 0.00104\n",
"From time 0.01192 to 0.01659, in 3 steps of 0.00156\n",
"From time 0.01659 to 0.02125, in 2 steps of 0.00233\n",
"From time 0.02125 to 0.02475, in 1 step of 0.0035\n",
"From time 0.02475 to 0.03, in 1 step of 0.00525\n",
"From time 0.03 to 0.03788, in 1 step of 0.00787\n",
"From time 0.03788 to 0.04969, in 1 step of 0.0118\n",
"From time 0.04969 to 0.0674, in 1 step of 0.0177\n",
"(23 steps total)\n"
]
}
],
"source": [
"dynamics.explain_time_advance()"
]
},
{
"cell_type": "markdown",
"id": "9fb5f6b8-dde3-415d-9e90-b8d102bfd748",
"metadata": {},
"source": [
"### Notice how the reaction proceeds in smaller steps in the early times, when the concentrations are changing much more rapidly.\n",
"#### The argument argument _variable_steps=True_ dynamically adjusts the initial_step (which is initially found to be too large, leading to some backtracking)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "226c1b6e-6838-46f3-aab1-9cb20c409724",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
" \n",
" "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"hovertemplate": "x=%{x}
y=%{y}",
"legendgroup": "",
"line": {
"color": "#636efa",
"dash": "solid"
},
"marker": {
"symbol": "circle"
},
"mode": "lines",
"name": "",
"orientation": "v",
"showlegend": false,
"type": "scatter",
"x": [
0,
0.0008639999999999999,
0.0008639999999999999,
0.0036287999999999993,
0.0036287999999999993,
0.011923199999999997,
0.011923199999999997,
0.016588799999999994,
0.016588799999999994,
0.021254399999999993,
0.021254399999999993,
0.024753599999999994,
0.024753599999999994,
0.03000239999999999,
0.03000239999999999,
0.03787559999999999,
0.03787559999999999,
0.04968539999999999,
0.04968539999999999,
0.06740009999999999
],
"xaxis": "x",
"y": [
0.0008639999999999999,
0.0008639999999999999,
0.0006911999999999999,
0.0006911999999999999,
0.0010367999999999992,
0.0010367999999999992,
0.001555199999999998,
0.001555199999999998,
0.0023327999999999995,
0.0023327999999999995,
0.003499200000000001,
0.003499200000000001,
0.005248799999999998,
0.005248799999999998,
0.007873199999999997,
0.007873199999999997,
0.011809800000000002,
0.011809800000000002,
0.0177147,
0.0177147
],
"yaxis": "y"
}
],
"layout": {
"autosize": true,
"legend": {
"tracegroupgap": 0
},
"margin": {
"t": 60
},
"shapes": [
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0,
"x1": 0,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.0008639999999999999,
"x1": 0.0008639999999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.0015551999999999996,
"x1": 0.0015551999999999996,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.0022463999999999995,
"x1": 0.0022463999999999995,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.0029375999999999994,
"x1": 0.0029375999999999994,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.0036287999999999993,
"x1": 0.0036287999999999993,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.004665599999999999,
"x1": 0.004665599999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.005702399999999999,
"x1": 0.005702399999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.006739199999999999,
"x1": 0.006739199999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.007775999999999999,
"x1": 0.007775999999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.008812799999999999,
"x1": 0.008812799999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.009849599999999998,
"x1": 0.009849599999999998,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.010886399999999997,
"x1": 0.010886399999999997,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.011923199999999997,
"x1": 0.011923199999999997,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.013478399999999996,
"x1": 0.013478399999999996,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.015033599999999996,
"x1": 0.015033599999999996,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.016588799999999994,
"x1": 0.016588799999999994,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.018921599999999993,
"x1": 0.018921599999999993,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.021254399999999993,
"x1": 0.021254399999999993,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.024753599999999994,
"x1": 0.024753599999999994,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.03000239999999999,
"x1": 0.03000239999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.03787559999999999,
"x1": 0.03787559999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.04968539999999999,
"x1": 0.04968539999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.06740009999999999,
"x1": 0.06740009999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
}
],
"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": "Simulation step sizes"
},
"xaxis": {
"anchor": "y",
"autorange": true,
"domain": [
0,
1
],
"range": [
-4.786938920454545e-05,
0.06744796938920454
],
"title": {
"text": "SYSTEM TIME"
},
"type": "linear"
},
"yaxis": {
"anchor": "x",
"autorange": true,
"domain": [
0,
1
],
"range": [
-0.0002545500000000001,
0.01866045
],
"title": {
"text": "Step size"
},
"type": "linear"
}
}
},
"text/html": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"dynamics.plot_step_sizes(show_intervals=True)"
]
},
{
"cell_type": "markdown",
"id": "6ac3dd4e-9dd0-4d3a-aa83-76102bd79524",
"metadata": {
"tags": []
},
"source": [
"## Plots changes of concentration with time"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "5f73e330-2d43-4cef-b2a0-c6eb379eea2e",
"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": "red",
"dash": "solid"
},
"marker": {
"symbol": "circle"
},
"mode": "lines",
"name": "A",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.0008639999999999999,
0.0015551999999999996,
0.0022463999999999995,
0.0029375999999999994,
0.0036287999999999993,
0.004665599999999999,
0.005702399999999999,
0.006739199999999999,
0.007775999999999999,
0.008812799999999999,
0.009849599999999998,
0.010886399999999997,
0.011923199999999997,
0.013478399999999996,
0.015033599999999996,
0.016588799999999994,
0.018921599999999993,
0.021254399999999993,
0.024753599999999994,
0.03000239999999999,
0.03787559999999999,
0.04968539999999999,
0.06740009999999999
],
"xaxis": "x",
"y": [
10,
7.874560000000001,
6.6022649832669185,
5.571266196412786,
4.727593830730617,
4.031745738170395,
3.165304930294141,
2.512652422560647,
2.0158977994878757,
1.6348420991345631,
1.3408039110369463,
1.1128829584716142,
0.9355954461437876,
0.7973205671737157,
0.6352106326726121,
0.525833400282096,
0.45180455730262453,
0.37648974220125575,
0.3373928293875607,
0.30687098340433216,
0.29396529878725997,
0.295437049136851,
0.294082474812173,
0.29696851083086506
],
"yaxis": "y"
},
{
"hovertemplate": "Chemical=B
SYSTEM TIME=%{x}
concentration=%{y}",
"legendgroup": "B",
"line": {
"color": "violet",
"dash": "solid"
},
"marker": {
"symbol": "circle"
},
"mode": "lines",
"name": "B",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.0008639999999999999,
0.0015551999999999996,
0.0022463999999999995,
0.0029375999999999994,
0.0036287999999999993,
0.004665599999999999,
0.005702399999999999,
0.006739199999999999,
0.007775999999999999,
0.008812799999999999,
0.009849599999999998,
0.010886399999999997,
0.011923199999999997,
0.013478399999999996,
0.015033599999999996,
0.016588799999999994,
0.018921599999999993,
0.021254399999999993,
0.024753599999999994,
0.03000239999999999,
0.03787559999999999,
0.04968539999999999,
0.06740009999999999
],
"xaxis": "x",
"y": [
50,
47.87456,
46.60226498326692,
45.571266196412786,
44.72759383073062,
44.0317457381704,
43.16530493029415,
42.512652422560656,
42.01589779948788,
41.634842099134566,
41.34080391103695,
41.112882958471616,
40.935595446143786,
40.79732056717371,
40.63521063267261,
40.525833400282096,
40.45180455730262,
40.37648974220125,
40.337392829387554,
40.30687098340432,
40.29396529878725,
40.295437049136844,
40.294082474812164,
40.29696851083086
],
"yaxis": "y"
},
{
"hovertemplate": "Chemical=C
SYSTEM TIME=%{x}
concentration=%{y}",
"legendgroup": "C",
"line": {
"color": "green",
"dash": "solid"
},
"marker": {
"symbol": "circle"
},
"mode": "lines",
"name": "C",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.0008639999999999999,
0.0015551999999999996,
0.0022463999999999995,
0.0029375999999999994,
0.0036287999999999993,
0.004665599999999999,
0.005702399999999999,
0.006739199999999999,
0.007775999999999999,
0.008812799999999999,
0.009849599999999998,
0.010886399999999997,
0.011923199999999997,
0.013478399999999996,
0.015033599999999996,
0.016588799999999994,
0.018921599999999993,
0.021254399999999993,
0.024753599999999994,
0.03000239999999999,
0.03787559999999999,
0.04968539999999999,
0.06740009999999999
],
"xaxis": "x",
"y": [
20,
22.12544,
23.397735016733083,
24.428733803587217,
25.272406169269388,
25.96825426182961,
26.834695069705866,
27.48734757743936,
27.98410220051213,
28.36515790086544,
28.659196088963057,
28.887117041528388,
29.064404553856214,
29.202679432826287,
29.36478936732739,
29.474166599717908,
29.54819544269738,
29.62351025779875,
29.662607170612443,
29.69312901659567,
29.70603470121274,
29.70456295086315,
29.70591752518783,
29.70303148916914
],
"yaxis": "y"
}
],
"layout": {
"autosize": true,
"legend": {
"title": {
"text": "Chemical"
},
"tracegroupgap": 0
},
"shapes": [
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0,
"x1": 0,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.0008639999999999999,
"x1": 0.0008639999999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.0015551999999999996,
"x1": 0.0015551999999999996,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.0022463999999999995,
"x1": 0.0022463999999999995,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.0029375999999999994,
"x1": 0.0029375999999999994,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.0036287999999999993,
"x1": 0.0036287999999999993,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.004665599999999999,
"x1": 0.004665599999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.005702399999999999,
"x1": 0.005702399999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.006739199999999999,
"x1": 0.006739199999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.007775999999999999,
"x1": 0.007775999999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.008812799999999999,
"x1": 0.008812799999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.009849599999999998,
"x1": 0.009849599999999998,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.010886399999999997,
"x1": 0.010886399999999997,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.011923199999999997,
"x1": 0.011923199999999997,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.013478399999999996,
"x1": 0.013478399999999996,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.015033599999999996,
"x1": 0.015033599999999996,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.016588799999999994,
"x1": 0.016588799999999994,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.018921599999999993,
"x1": 0.018921599999999993,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.021254399999999993,
"x1": 0.021254399999999993,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.024753599999999994,
"x1": 0.024753599999999994,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.03000239999999999,
"x1": 0.03000239999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.03787559999999999,
"x1": 0.03787559999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.04968539999999999,
"x1": 0.04968539999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
},
{
"line": {
"color": "gray",
"dash": "dot",
"width": 1
},
"type": "line",
"x0": 0.06740009999999999,
"x1": 0.06740009999999999,
"xref": "x",
"y0": 0,
"y1": 1,
"yref": "y domain"
}
],
"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 + B <-> C` . Changes in concentrations with time (time steps shown in dashed lines)"
},
"xaxis": {
"anchor": "y",
"autorange": true,
"domain": [
0,
1
],
"range": [
-4.884065217391304e-05,
0.0674489406521739
],
"title": {
"text": "SYSTEM TIME"
},
"type": "linear"
},
"yaxis": {
"anchor": "x",
"autorange": true,
"domain": [
0,
1
],
"range": [
-2.4674810735023365,
52.7614463722896
],
"title": {
"text": "concentration"
},
"type": "linear"
}
}
},
"text/html": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"dynamics.plot_history(colors=['red', 'violet', 'green'], show_intervals=True)"
]
},
{
"cell_type": "markdown",
"id": "c02a8f55-a671-4771-86c9-fc4d1b126bf8",
"metadata": {},
"source": [
"### Check the final equilibrium"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "765f6f39-4b2e-4a86-b6a9-ace9d1941663",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0: A + B <-> C\n",
"Final concentrations: [A] = 0.297 ; [B] = 40.3 ; [C] = 29.7\n",
"1. Ratio of reactant/product concentrations, adjusted for reaction orders: 2.48209\n",
" Formula used: [C] / ([A][B])\n",
"2. Ratio of forward/reverse reaction rates: 2.5\n",
"Discrepancy between the two values: 0.7163 %\n",
"Reaction IS in equilibrium (within 1% tolerance)\n",
"\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Verify that the reaction has reached equilibrium\n",
"dynamics.is_in_equilibrium()"
]
},
{
"cell_type": "markdown",
"id": "e2ea05d1-6e9b-4f62-88e6-192e058078f6",
"metadata": {},
"source": [
"Compare with the values we saw earlier for the exact solution of the equilibrium values: \n",
"{'A': 0.2948774087575341, 'B': 40.294877408757536, 'C': 29.705122591242464} \n",
"\n",
"It's instructive to compare the exact values with the last few points from the simulation: "
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "fcc82495-c952-4200-b316-157aac1ef22f",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" SYSTEM TIME | \n",
" A | \n",
" B | \n",
" C | \n",
" caption | \n",
"
\n",
" \n",
" \n",
" \n",
" | 21 | \n",
" 0.037876 | \n",
" 0.295437 | \n",
" 40.295437 | \n",
" 29.704563 | \n",
" | \n",
"
\n",
" \n",
" | 22 | \n",
" 0.049685 | \n",
" 0.294082 | \n",
" 40.294082 | \n",
" 29.705918 | \n",
" | \n",
"
\n",
" \n",
" | 23 | \n",
" 0.067400 | \n",
" 0.296969 | \n",
" 40.296969 | \n",
" 29.703031 | \n",
" last reaction step | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" SYSTEM TIME A B C caption\n",
"21 0.037876 0.295437 40.295437 29.704563 \n",
"22 0.049685 0.294082 40.294082 29.705918 \n",
"23 0.067400 0.296969 40.296969 29.703031 last reaction step"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dynamics.get_history(tail=3)"
]
},
{
"cell_type": "markdown",
"id": "36087ae6-1bd5-4db1-881f-bf6e1dbd6439",
"metadata": {},
"source": [
"The 2nd-to-last simulation point, rather than the last one, is actually closer to the exact equilibrium values. \n",
"That's because by that time the variable steps are getting so large that they introduce some error. \n",
"If we were to run the simulation longer (not shown), we'd see the variable steps continuing to grow, and then suddenly being reduced; \n",
"then continued cycles of growth and reduction (\"hitting the brakes whenever getting too fast\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "635c27c1-37c9-4ca0-8684-03de92380fb6",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "5c747824-a170-439e-96a5-dd35bc81e08b",
"metadata": {},
"source": [
"# Everthing below is just for diagnostic insight \n",
"## into the adaptive variable time steps \n",
"This information is available because we made a call to `dynamics.set_diagnostics()` prior to running the simulation"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "06c8c7e9-edd9-45e1-b4a0-508f0b379c42",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" START_TIME | \n",
" Delta A | \n",
" Delta B | \n",
" Delta C | \n",
" norm_A | \n",
" norm_B | \n",
" action | \n",
" step_factor | \n",
" time_step | \n",
" caption | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.000000 | \n",
" -9.840000 | \n",
" -9.840000 | \n",
" 9.840000 | \n",
" 3.227520e+01 | \n",
" NaN | \n",
" ABORT | \n",
" 0.6 | \n",
" 0.004000 | \n",
" excessive norm value(s) | \n",
"
\n",
" \n",
" | 1 | \n",
" 0.000000 | \n",
" -5.904000 | \n",
" -5.904000 | \n",
" 5.904000 | \n",
" 1.161907e+01 | \n",
" NaN | \n",
" ABORT | \n",
" 0.6 | \n",
" 0.002400 | \n",
" excessive norm value(s) | \n",
"
\n",
" \n",
" | 2 | \n",
" 0.000000 | \n",
" -3.542400 | \n",
" -3.542400 | \n",
" 3.542400 | \n",
" 4.182866e+00 | \n",
" NaN | \n",
" ABORT | \n",
" 0.6 | \n",
" 0.001440 | \n",
" excessive norm value(s) | \n",
"
\n",
" \n",
" | 3 | \n",
" 0.000000 | \n",
" -2.125440 | \n",
" -2.125440 | \n",
" 2.125440 | \n",
" 1.505832e+00 | \n",
" NaN | \n",
" OK (high) | \n",
" 0.8 | \n",
" 0.000864 | \n",
" | \n",
"
\n",
" \n",
" | 4 | \n",
" 0.000864 | \n",
" -1.272295 | \n",
" -1.272295 | \n",
" 1.272295 | \n",
" 5.395782e-01 | \n",
" 0.161570 | \n",
" OK (stay) | \n",
" 1.0 | \n",
" 0.000691 | \n",
" | \n",
"
\n",
" \n",
" | 5 | \n",
" 0.001555 | \n",
" -1.030999 | \n",
" -1.030999 | \n",
" 1.030999 | \n",
" 3.543195e-01 | \n",
" 0.156158 | \n",
" OK (stay) | \n",
" 1.0 | \n",
" 0.000691 | \n",
" | \n",
"
\n",
" \n",
" | 6 | \n",
" 0.002246 | \n",
" -0.843672 | \n",
" -0.843672 | \n",
" 0.843672 | \n",
" 2.372610e-01 | \n",
" 0.151433 | \n",
" OK (stay) | \n",
" 1.0 | \n",
" 0.000691 | \n",
" | \n",
"
\n",
" \n",
" | 7 | \n",
" 0.002938 | \n",
" -0.695848 | \n",
" -0.695848 | \n",
" 0.695848 | \n",
" 1.614015e-01 | \n",
" 0.147189 | \n",
" OK (low) | \n",
" 1.5 | \n",
" 0.000691 | \n",
" | \n",
"
\n",
" \n",
" | 8 | \n",
" 0.003629 | \n",
" -0.866441 | \n",
" -0.866441 | \n",
" 0.866441 | \n",
" 2.502399e-01 | \n",
" 0.214905 | \n",
" OK (stay) | \n",
" 1.0 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 9 | \n",
" 0.004666 | \n",
" -0.652653 | \n",
" -0.652653 | \n",
" 0.652653 | \n",
" 1.419851e-01 | \n",
" 0.206189 | \n",
" OK (stay) | \n",
" 1.0 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 10 | \n",
" 0.005702 | \n",
" -0.496755 | \n",
" -0.496755 | \n",
" 0.496755 | \n",
" 8.225505e-02 | \n",
" 0.197701 | \n",
" OK (stay) | \n",
" 1.0 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 11 | \n",
" 0.006739 | \n",
" -0.381056 | \n",
" -0.381056 | \n",
" 0.381056 | \n",
" 4.840115e-02 | \n",
" 0.189025 | \n",
" OK (stay) | \n",
" 1.0 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 12 | \n",
" 0.007776 | \n",
" -0.294038 | \n",
" -0.294038 | \n",
" 0.294038 | \n",
" 2.881949e-02 | \n",
" 0.179857 | \n",
" OK (stay) | \n",
" 1.0 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 13 | \n",
" 0.008813 | \n",
" -0.227921 | \n",
" -0.227921 | \n",
" 0.227921 | \n",
" 1.731599e-02 | \n",
" 0.169988 | \n",
" OK (stay) | \n",
" 1.0 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 14 | \n",
" 0.009850 | \n",
" -0.177288 | \n",
" -0.177288 | \n",
" 0.177288 | \n",
" 1.047695e-02 | \n",
" 0.159305 | \n",
" OK (stay) | \n",
" 1.0 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 15 | \n",
" 0.010886 | \n",
" -0.138275 | \n",
" -0.138275 | \n",
" 0.138275 | \n",
" 6.373314e-03 | \n",
" 0.147793 | \n",
" OK (low) | \n",
" 1.5 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 16 | \n",
" 0.011923 | \n",
" -0.162110 | \n",
" -0.162110 | \n",
" 0.162110 | \n",
" 8.759877e-03 | \n",
" 0.203318 | \n",
" OK (stay) | \n",
" 1.0 | \n",
" 0.001555 | \n",
" | \n",
"
\n",
" \n",
" | 17 | \n",
" 0.013478 | \n",
" -0.109377 | \n",
" -0.109377 | \n",
" 0.109377 | \n",
" 3.987793e-03 | \n",
" 0.172190 | \n",
" OK (stay) | \n",
" 1.0 | \n",
" 0.001555 | \n",
" | \n",
"
\n",
" \n",
" | 18 | \n",
" 0.015034 | \n",
" -0.074029 | \n",
" -0.074029 | \n",
" 0.074029 | \n",
" 1.826757e-03 | \n",
" 0.140784 | \n",
" OK (low) | \n",
" 1.5 | \n",
" 0.001555 | \n",
" | \n",
"
\n",
" \n",
" | 19 | \n",
" 0.016589 | \n",
" -0.075315 | \n",
" -0.075315 | \n",
" 0.075315 | \n",
" 1.890774e-03 | \n",
" 0.166698 | \n",
" OK (stay) | \n",
" 1.0 | \n",
" 0.002333 | \n",
" | \n",
"
\n",
" \n",
" | 20 | \n",
" 0.018922 | \n",
" -0.039097 | \n",
" -0.039097 | \n",
" 0.039097 | \n",
" 5.095229e-04 | \n",
" 0.103846 | \n",
" OK (low) | \n",
" 1.5 | \n",
" 0.002333 | \n",
" | \n",
"
\n",
" \n",
" | 21 | \n",
" 0.021254 | \n",
" -0.030522 | \n",
" -0.030522 | \n",
" 0.030522 | \n",
" 3.105277e-04 | \n",
" 0.090464 | \n",
" OK (low) | \n",
" 1.5 | \n",
" 0.003499 | \n",
" | \n",
"
\n",
" \n",
" | 22 | \n",
" 0.024754 | \n",
" -0.012906 | \n",
" -0.012906 | \n",
" 0.012906 | \n",
" 5.551890e-05 | \n",
" 0.042056 | \n",
" OK (low) | \n",
" 1.5 | \n",
" 0.005249 | \n",
" | \n",
"
\n",
" \n",
" | 23 | \n",
" 0.030002 | \n",
" 0.001472 | \n",
" 0.001472 | \n",
" -0.001472 | \n",
" 7.220164e-07 | \n",
" 0.005007 | \n",
" OK (low) | \n",
" 1.5 | \n",
" 0.007873 | \n",
" | \n",
"
\n",
" \n",
" | 24 | \n",
" 0.037876 | \n",
" -0.001355 | \n",
" -0.001355 | \n",
" 0.001355 | \n",
" 6.116239e-07 | \n",
" 0.004585 | \n",
" OK (low) | \n",
" 1.5 | \n",
" 0.011810 | \n",
" | \n",
"
\n",
" \n",
" | 25 | \n",
" 0.049685 | \n",
" 0.002886 | \n",
" 0.002886 | \n",
" -0.002886 | \n",
" 2.776401e-06 | \n",
" 0.009814 | \n",
" OK (low) | \n",
" 1.5 | \n",
" 0.017715 | \n",
" | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" START_TIME Delta A Delta B Delta C norm_A norm_B \\\n",
"0 0.000000 -9.840000 -9.840000 9.840000 3.227520e+01 NaN \n",
"1 0.000000 -5.904000 -5.904000 5.904000 1.161907e+01 NaN \n",
"2 0.000000 -3.542400 -3.542400 3.542400 4.182866e+00 NaN \n",
"3 0.000000 -2.125440 -2.125440 2.125440 1.505832e+00 NaN \n",
"4 0.000864 -1.272295 -1.272295 1.272295 5.395782e-01 0.161570 \n",
"5 0.001555 -1.030999 -1.030999 1.030999 3.543195e-01 0.156158 \n",
"6 0.002246 -0.843672 -0.843672 0.843672 2.372610e-01 0.151433 \n",
"7 0.002938 -0.695848 -0.695848 0.695848 1.614015e-01 0.147189 \n",
"8 0.003629 -0.866441 -0.866441 0.866441 2.502399e-01 0.214905 \n",
"9 0.004666 -0.652653 -0.652653 0.652653 1.419851e-01 0.206189 \n",
"10 0.005702 -0.496755 -0.496755 0.496755 8.225505e-02 0.197701 \n",
"11 0.006739 -0.381056 -0.381056 0.381056 4.840115e-02 0.189025 \n",
"12 0.007776 -0.294038 -0.294038 0.294038 2.881949e-02 0.179857 \n",
"13 0.008813 -0.227921 -0.227921 0.227921 1.731599e-02 0.169988 \n",
"14 0.009850 -0.177288 -0.177288 0.177288 1.047695e-02 0.159305 \n",
"15 0.010886 -0.138275 -0.138275 0.138275 6.373314e-03 0.147793 \n",
"16 0.011923 -0.162110 -0.162110 0.162110 8.759877e-03 0.203318 \n",
"17 0.013478 -0.109377 -0.109377 0.109377 3.987793e-03 0.172190 \n",
"18 0.015034 -0.074029 -0.074029 0.074029 1.826757e-03 0.140784 \n",
"19 0.016589 -0.075315 -0.075315 0.075315 1.890774e-03 0.166698 \n",
"20 0.018922 -0.039097 -0.039097 0.039097 5.095229e-04 0.103846 \n",
"21 0.021254 -0.030522 -0.030522 0.030522 3.105277e-04 0.090464 \n",
"22 0.024754 -0.012906 -0.012906 0.012906 5.551890e-05 0.042056 \n",
"23 0.030002 0.001472 0.001472 -0.001472 7.220164e-07 0.005007 \n",
"24 0.037876 -0.001355 -0.001355 0.001355 6.116239e-07 0.004585 \n",
"25 0.049685 0.002886 0.002886 -0.002886 2.776401e-06 0.009814 \n",
"\n",
" action step_factor time_step caption \n",
"0 ABORT 0.6 0.004000 excessive norm value(s) \n",
"1 ABORT 0.6 0.002400 excessive norm value(s) \n",
"2 ABORT 0.6 0.001440 excessive norm value(s) \n",
"3 OK (high) 0.8 0.000864 \n",
"4 OK (stay) 1.0 0.000691 \n",
"5 OK (stay) 1.0 0.000691 \n",
"6 OK (stay) 1.0 0.000691 \n",
"7 OK (low) 1.5 0.000691 \n",
"8 OK (stay) 1.0 0.001037 \n",
"9 OK (stay) 1.0 0.001037 \n",
"10 OK (stay) 1.0 0.001037 \n",
"11 OK (stay) 1.0 0.001037 \n",
"12 OK (stay) 1.0 0.001037 \n",
"13 OK (stay) 1.0 0.001037 \n",
"14 OK (stay) 1.0 0.001037 \n",
"15 OK (low) 1.5 0.001037 \n",
"16 OK (stay) 1.0 0.001555 \n",
"17 OK (stay) 1.0 0.001555 \n",
"18 OK (low) 1.5 0.001555 \n",
"19 OK (stay) 1.0 0.002333 \n",
"20 OK (low) 1.5 0.002333 \n",
"21 OK (low) 1.5 0.003499 \n",
"22 OK (low) 1.5 0.005249 \n",
"23 OK (low) 1.5 0.007873 \n",
"24 OK (low) 1.5 0.011810 \n",
"25 OK (low) 1.5 0.017715 "
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dynamics.get_diagnostic_decisions_data() # diagnostic data about concentration changes at every step - EVEN aborted ones"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "4e3012c6-c870-411c-bb80-7e1076233ca3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Reaction: A + B <-> C\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" START_TIME | \n",
" Delta A | \n",
" Delta B | \n",
" Delta C | \n",
" time_step | \n",
" caption | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.000000 | \n",
" -9.840000 | \n",
" -9.840000 | \n",
" 9.840000 | \n",
" 0.004000 | \n",
" aborted: excessive norm value(s) | \n",
"
\n",
" \n",
" | 1 | \n",
" 0.000000 | \n",
" -5.904000 | \n",
" -5.904000 | \n",
" 5.904000 | \n",
" 0.002400 | \n",
" aborted: excessive norm value(s) | \n",
"
\n",
" \n",
" | 2 | \n",
" 0.000000 | \n",
" -3.542400 | \n",
" -3.542400 | \n",
" 3.542400 | \n",
" 0.001440 | \n",
" aborted: excessive norm value(s) | \n",
"
\n",
" \n",
" | 3 | \n",
" 0.000000 | \n",
" -2.125440 | \n",
" -2.125440 | \n",
" 2.125440 | \n",
" 0.000864 | \n",
" | \n",
"
\n",
" \n",
" | 4 | \n",
" 0.000864 | \n",
" -1.272295 | \n",
" -1.272295 | \n",
" 1.272295 | \n",
" 0.000691 | \n",
" | \n",
"
\n",
" \n",
" | 5 | \n",
" 0.001555 | \n",
" -1.030999 | \n",
" -1.030999 | \n",
" 1.030999 | \n",
" 0.000691 | \n",
" | \n",
"
\n",
" \n",
" | 6 | \n",
" 0.002246 | \n",
" -0.843672 | \n",
" -0.843672 | \n",
" 0.843672 | \n",
" 0.000691 | \n",
" | \n",
"
\n",
" \n",
" | 7 | \n",
" 0.002938 | \n",
" -0.695848 | \n",
" -0.695848 | \n",
" 0.695848 | \n",
" 0.000691 | \n",
" | \n",
"
\n",
" \n",
" | 8 | \n",
" 0.003629 | \n",
" -0.866441 | \n",
" -0.866441 | \n",
" 0.866441 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 9 | \n",
" 0.004666 | \n",
" -0.652653 | \n",
" -0.652653 | \n",
" 0.652653 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 10 | \n",
" 0.005702 | \n",
" -0.496755 | \n",
" -0.496755 | \n",
" 0.496755 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 11 | \n",
" 0.006739 | \n",
" -0.381056 | \n",
" -0.381056 | \n",
" 0.381056 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 12 | \n",
" 0.007776 | \n",
" -0.294038 | \n",
" -0.294038 | \n",
" 0.294038 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 13 | \n",
" 0.008813 | \n",
" -0.227921 | \n",
" -0.227921 | \n",
" 0.227921 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 14 | \n",
" 0.009850 | \n",
" -0.177288 | \n",
" -0.177288 | \n",
" 0.177288 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 15 | \n",
" 0.010886 | \n",
" -0.138275 | \n",
" -0.138275 | \n",
" 0.138275 | \n",
" 0.001037 | \n",
" | \n",
"
\n",
" \n",
" | 16 | \n",
" 0.011923 | \n",
" -0.162110 | \n",
" -0.162110 | \n",
" 0.162110 | \n",
" 0.001555 | \n",
" | \n",
"
\n",
" \n",
" | 17 | \n",
" 0.013478 | \n",
" -0.109377 | \n",
" -0.109377 | \n",
" 0.109377 | \n",
" 0.001555 | \n",
" | \n",
"
\n",
" \n",
" | 18 | \n",
" 0.015034 | \n",
" -0.074029 | \n",
" -0.074029 | \n",
" 0.074029 | \n",
" 0.001555 | \n",
" | \n",
"
\n",
" \n",
" | 19 | \n",
" 0.016589 | \n",
" -0.075315 | \n",
" -0.075315 | \n",
" 0.075315 | \n",
" 0.002333 | \n",
" | \n",
"
\n",
" \n",
" | 20 | \n",
" 0.018922 | \n",
" -0.039097 | \n",
" -0.039097 | \n",
" 0.039097 | \n",
" 0.002333 | \n",
" | \n",
"
\n",
" \n",
" | 21 | \n",
" 0.021254 | \n",
" -0.030522 | \n",
" -0.030522 | \n",
" 0.030522 | \n",
" 0.003499 | \n",
" | \n",
"
\n",
" \n",
" | 22 | \n",
" 0.024754 | \n",
" -0.012906 | \n",
" -0.012906 | \n",
" 0.012906 | \n",
" 0.005249 | \n",
" | \n",
"
\n",
" \n",
" | 23 | \n",
" 0.030002 | \n",
" 0.001472 | \n",
" 0.001472 | \n",
" -0.001472 | \n",
" 0.007873 | \n",
" | \n",
"
\n",
" \n",
" | 24 | \n",
" 0.037876 | \n",
" -0.001355 | \n",
" -0.001355 | \n",
" 0.001355 | \n",
" 0.011810 | \n",
" | \n",
"
\n",
" \n",
" | 25 | \n",
" 0.049685 | \n",
" 0.002886 | \n",
" 0.002886 | \n",
" -0.002886 | \n",
" 0.017715 | \n",
" | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" START_TIME Delta A Delta B Delta C time_step \\\n",
"0 0.000000 -9.840000 -9.840000 9.840000 0.004000 \n",
"1 0.000000 -5.904000 -5.904000 5.904000 0.002400 \n",
"2 0.000000 -3.542400 -3.542400 3.542400 0.001440 \n",
"3 0.000000 -2.125440 -2.125440 2.125440 0.000864 \n",
"4 0.000864 -1.272295 -1.272295 1.272295 0.000691 \n",
"5 0.001555 -1.030999 -1.030999 1.030999 0.000691 \n",
"6 0.002246 -0.843672 -0.843672 0.843672 0.000691 \n",
"7 0.002938 -0.695848 -0.695848 0.695848 0.000691 \n",
"8 0.003629 -0.866441 -0.866441 0.866441 0.001037 \n",
"9 0.004666 -0.652653 -0.652653 0.652653 0.001037 \n",
"10 0.005702 -0.496755 -0.496755 0.496755 0.001037 \n",
"11 0.006739 -0.381056 -0.381056 0.381056 0.001037 \n",
"12 0.007776 -0.294038 -0.294038 0.294038 0.001037 \n",
"13 0.008813 -0.227921 -0.227921 0.227921 0.001037 \n",
"14 0.009850 -0.177288 -0.177288 0.177288 0.001037 \n",
"15 0.010886 -0.138275 -0.138275 0.138275 0.001037 \n",
"16 0.011923 -0.162110 -0.162110 0.162110 0.001555 \n",
"17 0.013478 -0.109377 -0.109377 0.109377 0.001555 \n",
"18 0.015034 -0.074029 -0.074029 0.074029 0.001555 \n",
"19 0.016589 -0.075315 -0.075315 0.075315 0.002333 \n",
"20 0.018922 -0.039097 -0.039097 0.039097 0.002333 \n",
"21 0.021254 -0.030522 -0.030522 0.030522 0.003499 \n",
"22 0.024754 -0.012906 -0.012906 0.012906 0.005249 \n",
"23 0.030002 0.001472 0.001472 -0.001472 0.007873 \n",
"24 0.037876 -0.001355 -0.001355 0.001355 0.011810 \n",
"25 0.049685 0.002886 0.002886 -0.002886 0.017715 \n",
"\n",
" caption \n",
"0 aborted: excessive norm value(s) \n",
"1 aborted: excessive norm value(s) \n",
"2 aborted: excessive norm value(s) \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 \n",
"23 \n",
"24 \n",
"25 "
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dynamics.get_diagnostic_rxn_data(rxn_index=0) # diagnostic run data of the requested SINGLE reaction"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "a5cee533-a63c-4ff8-9427-e9b64cf4885a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" TIME | \n",
" A | \n",
" B | \n",
" C | \n",
" caption | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.000000 | \n",
" 10.000000 | \n",
" 50.000000 | \n",
" 20.000000 | \n",
" | \n",
"
\n",
" \n",
" | 1 | \n",
" 0.000864 | \n",
" 7.874560 | \n",
" 47.874560 | \n",
" 22.125440 | \n",
" | \n",
"
\n",
" \n",
" | 2 | \n",
" 0.001555 | \n",
" 6.602265 | \n",
" 46.602265 | \n",
" 23.397735 | \n",
" | \n",
"
\n",
" \n",
" | 3 | \n",
" 0.002246 | \n",
" 5.571266 | \n",
" 45.571266 | \n",
" 24.428734 | \n",
" | \n",
"
\n",
" \n",
" | 4 | \n",
" 0.002938 | \n",
" 4.727594 | \n",
" 44.727594 | \n",
" 25.272406 | \n",
" | \n",
"
\n",
" \n",
" | 5 | \n",
" 0.003629 | \n",
" 4.031746 | \n",
" 44.031746 | \n",
" 25.968254 | \n",
" | \n",
"
\n",
" \n",
" | 6 | \n",
" 0.004666 | \n",
" 3.165305 | \n",
" 43.165305 | \n",
" 26.834695 | \n",
" | \n",
"
\n",
" \n",
" | 7 | \n",
" 0.005702 | \n",
" 2.512652 | \n",
" 42.512652 | \n",
" 27.487348 | \n",
" | \n",
"
\n",
" \n",
" | 8 | \n",
" 0.006739 | \n",
" 2.015898 | \n",
" 42.015898 | \n",
" 27.984102 | \n",
" | \n",
"
\n",
" \n",
" | 9 | \n",
" 0.007776 | \n",
" 1.634842 | \n",
" 41.634842 | \n",
" 28.365158 | \n",
" | \n",
"
\n",
" \n",
" | 10 | \n",
" 0.008813 | \n",
" 1.340804 | \n",
" 41.340804 | \n",
" 28.659196 | \n",
" | \n",
"
\n",
" \n",
" | 11 | \n",
" 0.009850 | \n",
" 1.112883 | \n",
" 41.112883 | \n",
" 28.887117 | \n",
" | \n",
"
\n",
" \n",
" | 12 | \n",
" 0.010886 | \n",
" 0.935595 | \n",
" 40.935595 | \n",
" 29.064405 | \n",
" | \n",
"
\n",
" \n",
" | 13 | \n",
" 0.011923 | \n",
" 0.797321 | \n",
" 40.797321 | \n",
" 29.202679 | \n",
" | \n",
"
\n",
" \n",
" | 14 | \n",
" 0.013478 | \n",
" 0.635211 | \n",
" 40.635211 | \n",
" 29.364789 | \n",
" | \n",
"
\n",
" \n",
" | 15 | \n",
" 0.015034 | \n",
" 0.525833 | \n",
" 40.525833 | \n",
" 29.474167 | \n",
" | \n",
"
\n",
" \n",
" | 16 | \n",
" 0.016589 | \n",
" 0.451805 | \n",
" 40.451805 | \n",
" 29.548195 | \n",
" | \n",
"
\n",
" \n",
" | 17 | \n",
" 0.018922 | \n",
" 0.376490 | \n",
" 40.376490 | \n",
" 29.623510 | \n",
" | \n",
"
\n",
" \n",
" | 18 | \n",
" 0.021254 | \n",
" 0.337393 | \n",
" 40.337393 | \n",
" 29.662607 | \n",
" | \n",
"
\n",
" \n",
" | 19 | \n",
" 0.024754 | \n",
" 0.306871 | \n",
" 40.306871 | \n",
" 29.693129 | \n",
" | \n",
"
\n",
" \n",
" | 20 | \n",
" 0.030002 | \n",
" 0.293965 | \n",
" 40.293965 | \n",
" 29.706035 | \n",
" | \n",
"
\n",
" \n",
" | 21 | \n",
" 0.037876 | \n",
" 0.295437 | \n",
" 40.295437 | \n",
" 29.704563 | \n",
" | \n",
"
\n",
" \n",
" | 22 | \n",
" 0.049685 | \n",
" 0.294082 | \n",
" 40.294082 | \n",
" 29.705918 | \n",
" | \n",
"
\n",
" \n",
" | 23 | \n",
" 0.067400 | \n",
" 0.296969 | \n",
" 40.296969 | \n",
" 29.703031 | \n",
" | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" TIME A B C caption\n",
"0 0.000000 10.000000 50.000000 20.000000 \n",
"1 0.000864 7.874560 47.874560 22.125440 \n",
"2 0.001555 6.602265 46.602265 23.397735 \n",
"3 0.002246 5.571266 45.571266 24.428734 \n",
"4 0.002938 4.727594 44.727594 25.272406 \n",
"5 0.003629 4.031746 44.031746 25.968254 \n",
"6 0.004666 3.165305 43.165305 26.834695 \n",
"7 0.005702 2.512652 42.512652 27.487348 \n",
"8 0.006739 2.015898 42.015898 27.984102 \n",
"9 0.007776 1.634842 41.634842 28.365158 \n",
"10 0.008813 1.340804 41.340804 28.659196 \n",
"11 0.009850 1.112883 41.112883 28.887117 \n",
"12 0.010886 0.935595 40.935595 29.064405 \n",
"13 0.011923 0.797321 40.797321 29.202679 \n",
"14 0.013478 0.635211 40.635211 29.364789 \n",
"15 0.015034 0.525833 40.525833 29.474167 \n",
"16 0.016589 0.451805 40.451805 29.548195 \n",
"17 0.018922 0.376490 40.376490 29.623510 \n",
"18 0.021254 0.337393 40.337393 29.662607 \n",
"19 0.024754 0.306871 40.306871 29.693129 \n",
"20 0.030002 0.293965 40.293965 29.706035 \n",
"21 0.037876 0.295437 40.295437 29.704563 \n",
"22 0.049685 0.294082 40.294082 29.705918 \n",
"23 0.067400 0.296969 40.296969 29.703031 "
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dynamics.get_diagnostic_conc_data() # diagnostic concentration data saved during the run, regardless of how much history we requested to save"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1918451d",
"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
}