{ "cells": [ { "cell_type": "markdown", "id": "3bbe8002-bdf3-490c-bde0-80dd3713a3d0", "metadata": {}, "source": [ "## An `A <-> B` reaction \n", "with 1st-order kinetics in both directions, taken to equilibrium,\n", "using a simple, **coarse fixed-timestep simulation.** \n", "\n", "In Part 2, below, perform some analysis of the results: in particular, examine the **reaction rates**. \n", "\n", "(See also the experiment _\"1D/reactions/reaction_1\"_ for a multi-compartment version) \n", "\n", "#### This experiment gets repeated in _\"react_2_b\"_ , with a more sophisticated approach, \n", "#### involving adaptive variable time steps" ] }, { "cell_type": "code", "execution_count": 1, "id": "0fac88df-1c44-4419-8479-a20369b06499", "metadata": {}, "outputs": [], "source": [ "LAST_REVISED = \"Nov. 9, 2024\"\n", "LIFE123_VERSION = \"1.0.0.rc.0\" # Library version this experiment is based on" ] }, { "cell_type": "code", "execution_count": 2, "id": "e2d818e7-05d8-4624-b9de-2ff263b879be", "metadata": {}, "outputs": [], "source": [ "#import set_path # Using MyBinder? Uncomment this before running the next cell!" ] }, { "cell_type": "code", "execution_count": 3, "id": "b0ce3cdd", "metadata": { "tags": [] }, "outputs": [], "source": [ "#import sys\n", "#sys.path.append(\"C:/some_path/my_env_or_install\") # CHANGE to the folder containing your venv or libraries installation!\n", "# NOTE: If any of the imports below can't find a module, uncomment the lines above, or try: import set_path \n", "\n", "import numpy as np\n", "import ipynbname\n", "\n", "from life123 import check_version, UniformCompartment, PlotlyHelper, GraphicLog" ] }, { "cell_type": "code", "execution_count": 4, "id": "4f75ae66-3d5c-474c-8d88-bd8a7ca92aef", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "OK\n" ] } ], "source": [ "check_version(LIFE123_VERSION)" ] }, { "cell_type": "code", "execution_count": 5, "id": "83c3cc5f-de21-4f66-9988-2806fbf0666d", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-> Output will be LOGGED into the file 'react_2_a.log.htm'\n" ] } ], "source": [ "# Initialize the HTML logging (for the graphics)\n", "log_file = ipynbname.name() + \".log.htm\" # Use the notebook base filename for the log file\n", " # IN CASE OF PROBLEMS, set manually to any desired name\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": "46703103-a97d-426c-bf6e-ad6e397a7ddb", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "66400086-eaa7-427c-9bdd-fb1de0346596", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "83eb30cd-1a3f-4732-8927-f5240c255d85", "metadata": {}, "source": [ "# PART 1 - simulation of the reaction" ] }, { "cell_type": "code", "execution_count": 6, "id": "72b4245c-de4e-480d-a501-3495b7ed8bc4", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of reactions: 1\n" ] } ], "source": [ "# Instantiate the simulator and specify the chemicals\n", "uc = UniformCompartment()\n", "\n", "# Reaction A <-> B , with 1st-order kinetics in both directions\n", "uc.add_reaction(reactants=\"A\", products=\"B\", \n", " forward_rate=3., reverse_rate=2.)\n", "\n", "print(\"Number of reactions: \", uc.number_of_reactions())" ] }, { "cell_type": "code", "execution_count": 7, "id": "00ea560d-9a49-4041-b119-6de11bfcc7af", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of reactions: 1 (at temp. 25 C)\n", "0: A <-> B (kF = 3 / kR = 2 / delta_G = -1,005.1 / K = 1.5) | 1st order in all reactants & products\n", "Set of chemicals involved in the above reactions: {'B', 'A'}\n" ] } ], "source": [ "uc.describe_reactions()" ] }, { "cell_type": "code", "execution_count": 8, "id": "cb582868-431c-4022-aa0e-a2f554f80d6c", "metadata": { "lines_to_next_cell": 2 }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[GRAPHIC ELEMENT SENT TO LOG FILE `react_2_a.log.htm`]\n" ] } ], "source": [ "# Send a plot of the network of reactions to the HTML log file\n", "uc.plot_reaction_network(\"vue_cytoscape_2\")" ] }, { "cell_type": "code", "execution_count": null, "id": "b5a0bc1d-2638-4eeb-bdec-0090906b5c5d", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 9, "id": "ae304704-c8d9-4cef-9e0b-2587bb3909ef", "metadata": {}, "outputs": [], "source": [ "# Initial concentrations of all the chemicals\n", "uc.set_conc({\"A\": 10., \"B\": 50.})" ] }, { "cell_type": "code", "execution_count": 10, "id": "a605dacf-2c67-403e-9aa9-5be25fc9f481", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SYSTEM STATE at Time t = 0:\n", "2 species:\n", " Species 0 (A). Conc: 10.0\n", " Species 1 (B). Conc: 50.0\n", "Set of chemicals involved in reactions: {'B', 'A'}\n" ] } ], "source": [ "uc.describe_state()" ] }, { "cell_type": "code", "execution_count": 11, "id": "0ff2c242-a15b-456d-ad56-0ba1041c0b4c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SYSTEM TIMEABcaption
00.010.050.0Set concentration
\n", "
" ], "text/plain": [ " SYSTEM TIME A B caption\n", "0 0.0 10.0 50.0 Set concentration" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "uc.get_history()" ] }, { "cell_type": "markdown", "id": "ab7147fe-712c-4c92-b61f-20ff51675ab8", "metadata": {}, "source": [ "### Test your intuition: \n", "#### given that this reaction operates mostly in the forward direction (kF = 3 , kR = 2 , K = 1.5), \n", "#### do you think that A will be consumed and B will be produced??\n", "We can take a sneak preview at the final equilibrium concentrations without actually running the simulation:" ] }, { "cell_type": "code", "execution_count": 12, "id": "12cac04d-dd61-4646-9339-8b70e22139e8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'A': 24.0, 'B': 36.0}" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "uc.find_equilibrium_conc(rxn_index=0) # This is an EXACT equilibrium solution, \n", " # for 1 reaction (the only reaction)" ] }, { "cell_type": "markdown", "id": "ee5b9d1c-3ebe-497a-a0e9-bfb02dcd0693", "metadata": {}, "source": [ "#### The reaction will actually proceed IN REVERSE, because of the large initial concentration of B (which we had set to 50), relative to the small initial concentration of A (10)\n", "Now, let's see the reaction in action!" ] }, { "cell_type": "code", "execution_count": null, "id": "d748df77-1b71-4d16-9e24-212d74a93ff4", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "fc516ca2-e62d-4784-b826-5372ff7f4c75", "metadata": { "tags": [] }, "source": [ "### Run the reaction" ] }, { "cell_type": "code", "execution_count": 13, "id": "50c7e478-ad0e-4aeb-9cea-dfed47cded21", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1 total step(s) taken in 0.007 sec\n" ] } ], "source": [ "# First step of reaction\n", "uc.single_compartment_react(initial_step=0.1, n_steps=1, variable_steps=False) # NOT using variable steps!" ] }, { "cell_type": "code", "execution_count": 14, "id": "c9115720-e66e-44f3-bb0a-fabec5b96673", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SYSTEM TIMEABcaption
00.010.050.0Set concentration
10.117.043.0last reaction step
\n", "
" ], "text/plain": [ " SYSTEM TIME A B caption\n", "0 0.0 10.0 50.0 Set concentration\n", "1 0.1 17.0 43.0 last reaction step" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "uc.get_history()" ] }, { "cell_type": "markdown", "id": "98ec8a03-7a9b-403a-8dcd-d9e19c49d656", "metadata": {}, "source": [ "We can already see the reaction proceeding in reverse..." ] }, { "cell_type": "code", "execution_count": 15, "id": "2502cd11-0df9-4303-8895-98401a1df7b8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "10 total step(s) taken in 0.020 sec\n" ] } ], "source": [ "# Numerous more fixed steps\n", "uc.single_compartment_react(initial_step=0.1, n_steps=10, variable_steps=False, \n", " snapshots={\"initial_caption\": \"2nd round of simulation\"})" ] }, { "cell_type": "code", "execution_count": 16, "id": "80fbaee3-bd6f-4197-9270-23374d46a4a7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SYSTEM TIMEABcaption
00.010.00000050.000000Set concentration
10.117.00000043.000000last reaction step
20.220.50000039.5000002nd round of simulation
30.322.25000037.750000
40.423.12500036.875000
50.523.56250036.437500
60.623.78125036.218750
70.723.89062536.109375
80.823.94531236.054688
90.923.97265636.027344
101.023.98632836.013672
111.123.99316436.006836last reaction step
\n", "
" ], "text/plain": [ " SYSTEM TIME A B caption\n", "0 0.0 10.000000 50.000000 Set concentration\n", "1 0.1 17.000000 43.000000 last reaction step\n", "2 0.2 20.500000 39.500000 2nd round of simulation\n", "3 0.3 22.250000 37.750000 \n", "4 0.4 23.125000 36.875000 \n", "5 0.5 23.562500 36.437500 \n", "6 0.6 23.781250 36.218750 \n", "7 0.7 23.890625 36.109375 \n", "8 0.8 23.945312 36.054688 \n", "9 0.9 23.972656 36.027344 \n", "10 1.0 23.986328 36.013672 \n", "11 1.1 23.993164 36.006836 last reaction step" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "uc.get_history()" ] }, { "cell_type": "markdown", "id": "c7650ed4-365e-43c2-b001-280297c68ece", "metadata": {}, "source": [ "## NOTE: for demonstration purposes, we're using FIXED time steps... \n", "## Typically, one would use the option for adaptive variable time steps (see experiment `react_2_b`)" ] }, { "cell_type": "markdown", "id": "c034956a-683c-4c3d-8134-ecac9e19a45c", "metadata": {}, "source": [ "### Check the final equilibrium" ] }, { "cell_type": "code", "execution_count": 17, "id": "b139f5e4-625f-4a5e-8f57-8f00244dced4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([23.99316406, 36.00683594])" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "uc.get_system_conc() # The current concentrations, in the order the chemicals were added " ] }, { "cell_type": "markdown", "id": "d25eedf3-89f8-4f8c-a49a-d2689103528b", "metadata": {}, "source": [ "NOTE: Consistent with the 3/2 ratio of forward/reverse rates (and the 1st order of the reactions), the systems settles in the following equilibrium:\n", "\n", "[A] = 23.99316406\n", " \n", "[B] = 36.00683594\n" ] }, { "cell_type": "code", "execution_count": 18, "id": "765f6f39-4b2e-4a86-b6a9-ace9d1941663", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0: A <-> B\n", "Final concentrations: [A] = 23.99 ; [B] = 36.01\n", "1. Ratio of reactant/product concentrations, adjusted for reaction orders: 1.50071\n", " Formula used: [B] / [A]\n", "2. Ratio of forward/reverse reaction rates: 1.5\n", "Discrepancy between the two values: 0.04749 %\n", "Reaction IS in equilibrium (within 1% tolerance)\n", "\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Verify that the reaction has reached equilibrium\n", "uc.is_in_equilibrium()" ] }, { "cell_type": "markdown", "id": "905adfdd-6d70-4dfc-bb34-c547c4d604b9", "metadata": {}, "source": [ "### As noted earlier, because of the high initial concentration of B relative to A, the overall reaction has proceeded IN REVERSE" ] }, { "cell_type": "markdown", "id": "6ac3dd4e-9dd0-4d3a-aa83-76102bd79524", "metadata": { "tags": [] }, "source": [ "## Plots of changes of concentration with time" ] }, { "cell_type": "code", "execution_count": 19, "id": "86976e6f-f453-41c3-9553-b27b1328db6b", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "hovertemplate": "Chemical=A
SYSTEM TIME=%{x}
Concentration=%{y}", "legendgroup": "A", "line": { "color": "darkturquoise", "dash": "solid" }, "marker": { "symbol": "circle" }, "mode": "lines", "name": "A", "orientation": "v", "showlegend": true, "type": "scatter", "x": [ 0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6, 0.7, 0.7999999999999999, 0.8999999999999999, 0.9999999999999999, 1.0999999999999999 ], "xaxis": "x", "y": [ 10, 17, 20.5, 22.25, 23.125, 23.5625, 23.78125, 23.890625, 23.9453125, 23.97265625, 23.986328125, 23.9931640625 ], "yaxis": "y" }, { "hovertemplate": "Chemical=B
SYSTEM TIME=%{x}
Concentration=%{y}", "legendgroup": "B", "line": { "color": "green", "dash": "solid" }, "marker": { "symbol": "circle" }, "mode": "lines", "name": "B", "orientation": "v", "showlegend": true, "type": "scatter", "x": [ 0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6, 0.7, 0.7999999999999999, 0.8999999999999999, 0.9999999999999999, 1.0999999999999999 ], "xaxis": "x", "y": [ 50, 43, 39.5, 37.75, 36.875, 36.4375, 36.21875, 36.109375, 36.0546875, 36.02734375, 36.013671875, 36.0068359375 ], "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.1, "x1": 0.1, "xref": "x", "y0": 0, "y1": 1, "yref": "y domain" }, { "line": { "color": "gray", "dash": "dot", "width": 1 }, "type": "line", "x0": 0.2, "x1": 0.2, "xref": "x", "y0": 0, "y1": 1, "yref": "y domain" }, { "line": { "color": "gray", "dash": "dot", "width": 1 }, "type": "line", "x0": 0.30000000000000004, "x1": 0.30000000000000004, "xref": "x", "y0": 0, "y1": 1, "yref": "y domain" }, { "line": { "color": "gray", "dash": "dot", "width": 1 }, "type": "line", "x0": 0.4, "x1": 0.4, "xref": "x", "y0": 0, "y1": 1, "yref": "y domain" }, { "line": { "color": "gray", "dash": "dot", "width": 1 }, "type": "line", "x0": 0.5, "x1": 0.5, "xref": "x", "y0": 0, "y1": 1, "yref": "y domain" }, { "line": { "color": "gray", "dash": "dot", "width": 1 }, "type": "line", "x0": 0.6, "x1": 0.6, "xref": "x", "y0": 0, "y1": 1, "yref": "y domain" }, { "line": { "color": "gray", "dash": "dot", "width": 1 }, "type": "line", "x0": 0.7, "x1": 0.7, "xref": "x", "y0": 0, "y1": 1, "yref": "y domain" }, { "line": { "color": "gray", "dash": "dot", "width": 1 }, "type": "line", "x0": 0.7999999999999999, "x1": 0.7999999999999999, "xref": "x", "y0": 0, "y1": 1, "yref": "y domain" }, { "line": { "color": "gray", "dash": "dot", "width": 1 }, "type": "line", "x0": 0.8999999999999999, "x1": 0.8999999999999999, "xref": "x", "y0": 0, "y1": 1, "yref": "y domain" }, { "line": { "color": "gray", "dash": "dot", "width": 1 }, "type": "line", "x0": 0.9999999999999999, "x1": 0.9999999999999999, "xref": "x", "y0": 0, "y1": 1, "yref": "y domain" }, { "line": { "color": "gray", "dash": "dot", "width": 1 }, "type": "line", "x0": 1.0999999999999999, "x1": 1.0999999999999999, "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` . Changes in concentrations with time (time steps shown in dashed lines)" }, "xaxis": { "anchor": "y", "autorange": true, "domain": [ 0, 1 ], "range": [ -0.0003604193971166448, 1.1003604193971166 ], "title": { "text": "SYSTEM TIME" }, "type": "linear" }, "yaxis": { "anchor": "x", "autorange": true, "domain": [ 0, 1 ], "range": [ 7.777777777777778, 52.22222222222222 ], "title": { "text": "Concentration" }, "type": "linear" } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "uc.plot_history(colors=['darkturquoise', 'green'], show_intervals=True)" ] }, { "cell_type": "markdown", "id": "dffad4cb-ec16-4ded-9766-b609244f4496", "metadata": {}, "source": [ "### Note the raggedness of the left-side (early times) of the curves. \n", "### In experiment `react_2_b` this simulation gets repeated with an _adaptive variable time resolution_ that takes smaller steps at the beginning, when the reaction is proceeding faster \n", "#### By contrast, here we used _FIXED_ time steps (shown in dashed lines), which generally gives poor results, unless taking a very large number of very small steps! In particular, the early steps we took were too large, and the later steps were unnecessarily small" ] }, { "cell_type": "code", "execution_count": null, "id": "e73955b7-21c5-4147-96f1-55bdad8092ba", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "3f3556f4-2474-4233-b6f9-d05ec856dd13", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "f72f4988-4e4b-4268-9f4a-e36300c9dcf1", "metadata": {}, "source": [ "# PART 2 - Now investigate A_dot, i.e. d[A]/dt" ] }, { "cell_type": "markdown", "id": "0ddc7f18-dcc7-4563-b6f7-75049d944669", "metadata": {}, "source": [ "There's no need to compute this; it is automatically saved during the reaction simulations" ] }, { "cell_type": "code", "execution_count": 20, "id": "3b77582e-514d-42bc-9ecd-b7c98b7043df", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SYSTEM TIMErxn0_rate
00.0-70.000000
10.1-35.000000
20.2-17.500000
30.3-8.750000
40.4-4.375000
50.5-2.187500
60.6-1.093750
70.7-0.546875
80.8-0.273438
90.9-0.136719
101.0-0.068359
\n", "
" ], "text/plain": [ " SYSTEM TIME rxn0_rate\n", "0 0.0 -70.000000\n", "1 0.1 -35.000000\n", "2 0.2 -17.500000\n", "3 0.3 -8.750000\n", "4 0.4 -4.375000\n", "5 0.5 -2.187500\n", "6 0.6 -1.093750\n", "7 0.7 -0.546875\n", "8 0.8 -0.273438\n", "9 0.9 -0.136719\n", "10 1.0 -0.068359" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rates_df = uc.get_rate_history()\n", "rates_df" ] }, { "cell_type": "markdown", "id": "7e469e8a-b8dc-47f9-a6f2-60688f192357", "metadata": {}, "source": [ "Note that **reaction rates** are defined for the reaction _products_; since `A` is a reactant (in reaction 0, our only reaction), we must flip its sign; since the stoichiometry of A is simply 1, no further adjustment needed." ] }, { "cell_type": "code", "execution_count": 21, "id": "4a78121a-b08f-4c8c-8163-4138e0dd41a1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SYSTEM TIMErxn0_rateA_dot
00.0-70.00000070.000000
10.1-35.00000035.000000
20.2-17.50000017.500000
30.3-8.7500008.750000
40.4-4.3750004.375000
50.5-2.1875002.187500
60.6-1.0937501.093750
70.7-0.5468750.546875
80.8-0.2734380.273438
90.9-0.1367190.136719
101.0-0.0683590.068359
\n", "
" ], "text/plain": [ " SYSTEM TIME rxn0_rate A_dot\n", "0 0.0 -70.000000 70.000000\n", "1 0.1 -35.000000 35.000000\n", "2 0.2 -17.500000 17.500000\n", "3 0.3 -8.750000 8.750000\n", "4 0.4 -4.375000 4.375000\n", "5 0.5 -2.187500 2.187500\n", "6 0.6 -1.093750 1.093750\n", "7 0.7 -0.546875 0.546875\n", "8 0.8 -0.273438 0.273438\n", "9 0.9 -0.136719 0.136719\n", "10 1.0 -0.068359 0.068359" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rates_df['A_dot'] = - rates_df['rxn0_rate'] # Add a column to the Pandas dataframe\n", "rates_df" ] }, { "cell_type": "code", "execution_count": 22, "id": "c78e828d-583a-45d0-b7d2-4fb979bdb586", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SYSTEM TIMEABcaption
00.010.00000050.000000Set concentration
10.117.00000043.000000last reaction step
20.220.50000039.5000002nd round of simulation
30.322.25000037.750000
40.423.12500036.875000
50.523.56250036.437500
60.623.78125036.218750
70.723.89062536.109375
80.823.94531236.054688
90.923.97265636.027344
101.023.98632836.013672
111.123.99316436.006836last reaction step
\n", "
" ], "text/plain": [ " SYSTEM TIME A B caption\n", "0 0.0 10.000000 50.000000 Set concentration\n", "1 0.1 17.000000 43.000000 last reaction step\n", "2 0.2 20.500000 39.500000 2nd round of simulation\n", "3 0.3 22.250000 37.750000 \n", "4 0.4 23.125000 36.875000 \n", "5 0.5 23.562500 36.437500 \n", "6 0.6 23.781250 36.218750 \n", "7 0.7 23.890625 36.109375 \n", "8 0.8 23.945312 36.054688 \n", "9 0.9 23.972656 36.027344 \n", "10 1.0 23.986328 36.013672 \n", "11 1.1 23.993164 36.006836 last reaction step" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "uc.get_history() # Revisited from earlier" ] }, { "cell_type": "markdown", "id": "50bfe622-cd5f-46ea-a433-db3a9901ce8d", "metadata": {}, "source": [ "Notice that we lack a rate for the last time value, in the above table, because no reaction simulation starting at that time has been performed" ] }, { "cell_type": "code", "execution_count": 23, "id": "cda9afb7-4e99-493f-a420-3109455e8534", "metadata": {}, "outputs": [], "source": [ "p1 = uc.plot_history(chemicals=\"A\", colors=\"darkturquoise\") # The plot of [A] from the system history" ] }, { "cell_type": "code", "execution_count": 24, "id": "4b4f3495-bab5-4c07-a569-d4b96a14bf04", "metadata": {}, "outputs": [], "source": [ "p2 = PlotlyHelper.plot_pandas(df=rates_df, x_var=\"SYSTEM TIME\", fields=\"A_dot\", colors=\"brown\") # The plot of A_dot, from rates_df" ] }, { "cell_type": "code", "execution_count": 25, "id": "c40ecc8d-8f0b-4c44-a7fe-1ddd3b3d463c", "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "hovertemplate": "A
SYSTEM TIME=%{x}
A=%{y}", "legendgroup": "", "line": { "color": "darkturquoise", "dash": "solid" }, "marker": { "symbol": "circle" }, "mode": "lines", "name": "A", "orientation": "v", "showlegend": true, "type": "scatter", "x": [ 0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6, 0.7, 0.7999999999999999, 0.8999999999999999, 0.9999999999999999, 1.0999999999999999 ], "xaxis": "x", "y": [ 10, 17, 20.5, 22.25, 23.125, 23.5625, 23.78125, 23.890625, 23.9453125, 23.97265625, 23.986328125, 23.9931640625 ], "yaxis": "y" }, { "hovertemplate": "A_dot
SYSTEM TIME=%{x}
A_dot=%{y}", "legendgroup": "", "line": { "color": "brown", "dash": "solid" }, "marker": { "symbol": "circle" }, "mode": "lines", "name": "A_dot", "orientation": "v", "showlegend": true, "type": "scatter", "x": [ 0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6, 0.7, 0.7999999999999999, 0.8999999999999999, 0.9999999999999999 ], "xaxis": "x", "y": [ 70, 35, 17.5, 8.75, 4.375, 2.1875, 1.09375, 0.546875, 0.2734375, 0.13671875, 0.068359375 ], "yaxis": "y" } ], "layout": { "autosize": true, "legend": { "title": { "text": "Plot" } }, "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": "Concentration of A with time, and its rate of change (A_dot)" }, "xaxis": { "autorange": true, "range": [ 0, 1.0999999999999999 ], "title": { "text": "SYSTEM TIME" }, "type": "linear" }, "yaxis": { "autorange": true, "range": [ -3.816731770833333, 73.88509114583333 ], "title": { "text": "[A] (turquoise) /
A_dot (brown)" }, "type": "linear" } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "PlotlyHelper.combine_plots([p1, p2], \n", " title=\"Concentration of A with time, and its rate of change (A_dot)\",\n", " y_label=\"[A] (turquoise) /
A_dot (brown)\",\n", " legend_title=\"Plot\",\n", " curve_labels=[\"A\", \"A_dot\"])" ] }, { "cell_type": "markdown", "id": "85d87078-8fc1-4166-95e1-343b546f9971", "metadata": {}, "source": [ "### At t=0 : \n", "[A]=10 and [A] has a high rate of change (70)\n", "### As the system approaches equilibrium : \n", "[A] approaches a value of 24, and its rate of change decays to zero." ] }, { "cell_type": "markdown", "id": "99cd0942-555b-444e-9c6f-ee1481a2a980", "metadata": {}, "source": [ "#### **NOTE:** The above curves are jagged because of _the large time steps taken_ (especially in the early times, when there's a lot of change.) \n", "## In experiment `react_2_b`, we revisit the same reaction using a better approach that employs **_adaptive variable time steps_**." ] }, { "cell_type": "code", "execution_count": null, "id": "531ce53b-7336-440e-bce4-716aafa6c692", "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.9.13" } }, "nbformat": 4, "nbformat_minor": 5 }