{ "cells": [ { "cell_type": "markdown", "id": "f43cd6af-d772-43f7-a4da-30bcc41c7e50", "metadata": {}, "source": [ "## A strong, localized transient concentration gets mopped up by a fast chemical reaction before it has a chance to diffuse far\n", "A sizable transient injection of a chemical `A` near one end of the system, normally diffuses to the opposite end... \n", "But if it reacts on a faster timescale, virtually none of it will make it to the far end. \n", "It's a *racing condition* between the rate of diffusion of `A`, and the rate at which it's consumed by the plentiful `B` in the reaction `A + B <-> C` \n", "When the reaction is fast, relative to `A`'s diffusion, then only `C` (rather than `A`) will make it in substantial amounts to the far end of the system. \n", "\n", "PART 1 explores the diffusion without the concomitant reaction. \n", "PART 2 rewinds to the original initial states and carries out the reaction-diffusion. \n", "\n", "**Recommended background:** experiment `1D/diffusion/localized_transient`" ] }, { "cell_type": "markdown", "id": "6398f935-72f9-458e-90ab-f02a05132302", "metadata": {}, "source": [ "### TAGS : \"reactions 1D\", \"diffusion 1D\"" ] }, { "cell_type": "code", "execution_count": 1, "id": "2b6f0de7-d66f-4f4e-8850-8a092fca20b8", "metadata": {}, "outputs": [], "source": [ "LAST_REVISED = \"Aug. 28, 2025\"\n", "LIFE123_VERSION = \"1.0.0rc6\" # Library version this experiment is based on" ] }, { "cell_type": "code", "execution_count": 2, "id": "806647d0-4c0b-4abf-8d86-53460378d93e", "metadata": {}, "outputs": [], "source": [ "#import set_path # Using MyBinder? Uncomment this before running the next cell!" ] }, { "cell_type": "code", "execution_count": 3, "id": "f6e0f263", "metadata": {}, "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", "from life123 import BioSim1D, ChemData, ReactionRegistry, PlotlyHelper, check_version" ] }, { "cell_type": "code", "execution_count": 4, "id": "fe26e828-4428-4754-af9b-b54739b3a109", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "OK\n" ] } ], "source": [ "check_version(LIFE123_VERSION)" ] }, { "cell_type": "code", "execution_count": null, "id": "79045ff7-ed3f-4c3a-be79-9f8a4476f3de", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "e9c62aaf-525f-46ef-b923-ec3083f8a4c0", "metadata": {}, "source": [ "## Initialize the Chemical Data and the Reactions; they will be used in both Part 1 and Part 2" ] }, { "cell_type": "code", "execution_count": 5, "id": "aeb04519-513f-4509-b7e0-5d42f1196613", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of reactions: 1\n", "0: A + B <-> C (Elementary Synthesis reaction) (kF = 0.1 / kR = 0.02 / K = 5)\n", "Chemicals involved in the above reactions: {\"A\" (red), \"B\" (turquoise), \"C\" (green)}\n" ] } ], "source": [ "# Initialize the chemical data\n", "chem_data = ChemData(names=[\"A\", \"B\", \"C\"], diffusion_rates=[100., 80., 120.], \n", " plot_colors=[\"red\", \"turquoise\", \"green\"]) \n", "\n", "rxns = ReactionRegistry(chem_data=chem_data)\n", "\n", "# Reaction A + B <-> C , with 1st-order kinetics for each species; note that it's mostly in the forward direction\n", "rxns.add_reaction(reactants=[\"A\", \"B\"], products=\"C\", kF=0.1, kR=0.02)\n", "rxns.describe_reactions()" ] }, { "cell_type": "code", "execution_count": null, "id": "409e1d41-2a65-4668-8b44-f5c0c36f1a35", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "8221d2c0-4b6c-49b5-b24d-97c153e2a892", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "61159758-dedb-466f-b795-79b07d744302", "metadata": {}, "source": [ "# PART 1 - JUST DIFFUSION, no reactions" ] }, { "cell_type": "code", "execution_count": 6, "id": "5afedbcc-a438-4c84-9b3c-22460c3a1904", "metadata": {}, "outputs": [], "source": [ "bio1 = BioSim1D(n_bins=50, chem_data=chem_data, reactions=rxns)" ] }, { "cell_type": "code", "execution_count": 7, "id": "c984f746-d373-4a8a-89a4-9c3f0a3fca69", "metadata": {}, "outputs": [], "source": [ "# Set up the initial bell-shape concentration of `A`, with the very narrow peak close to one end of the system,\n", "# centered at 1/10 of the width of the system, i.e. at bin 30\n", "bio1.inject_bell_curve(chem_label=\"A\", center=0.2, sd=0.06, max_amplitude=100., bias=0.)" ] }, { "cell_type": "code", "execution_count": 8, "id": "cd5b5823-d0d0-47be-a4d3-0f636def4d6b", "metadata": { "tags": [] }, "outputs": [], "source": [ "# Chemical `B`, by contrast, is uniformly distributed\n", "bio1.set_uniform_concentration(chem_label=\"B\", conc=100.)" ] }, { "cell_type": "code", "execution_count": null, "id": "fd77de9f-a68c-491b-a586-b4e85fcaff78", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 9, "id": "543d4c99-5d9b-4ea0-9a2d-d78b03d9b45d", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SYSTEM STATE at Time t = 0:\n", "50 bins and 3 chemical species\n" ] }, { "data": { "text/html": [ "
| \n", " | Species | \n", "Diff rate | \n", "Bin 0 | \n", "Bin 1 | \n", "Bin 2 | \n", "Bin 3 | \n", "Bin 4 | \n", "Bin 5 | \n", "Bin 6 | \n", "Bin 7 | \n", "... | \n", "Bin 40 | \n", "Bin 41 | \n", "Bin 42 | \n", "Bin 43 | \n", "Bin 44 | \n", "Bin 45 | \n", "Bin 46 | \n", "Bin 47 | \n", "Bin 48 | \n", "Bin 49 | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "A | \n", "100.0 | \n", "0.386592 | \n", "1.133778 | \n", "2.961818 | \n", "6.891982 | \n", "14.285167 | \n", "26.374356 | \n", "43.374429 | \n", "63.539099 | \n", "... | \n", "1.223049e-21 | \n", "3.506984e-23 | \n", "8.957339e-25 | \n", "2.037885e-26 | \n", "4.129863e-28 | \n", "7.454988e-30 | \n", "1.198709e-31 | \n", "1.716863e-33 | \n", "2.190349e-35 | \n", "2.489121e-37 | \n", "
| 1 | \n", "B | \n", "80.0 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "... | \n", "1.000000e+02 | \n", "1.000000e+02 | \n", "1.000000e+02 | \n", "1.000000e+02 | \n", "1.000000e+02 | \n", "1.000000e+02 | \n", "1.000000e+02 | \n", "1.000000e+02 | \n", "1.000000e+02 | \n", "1.000000e+02 | \n", "
| 2 | \n", "C | \n", "120.0 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "... | \n", "0.000000e+00 | \n", "0.000000e+00 | \n", "0.000000e+00 | \n", "0.000000e+00 | \n", "0.000000e+00 | \n", "0.000000e+00 | \n", "0.000000e+00 | \n", "0.000000e+00 | \n", "0.000000e+00 | \n", "0.000000e+00 | \n", "
3 rows × 52 columns
\n", "| \n", " | Bin 1 | \n", "Bin 2 | \n", "Bin 3 | \n", "Bin 4 | \n", "Bin 5 | \n", "Bin 6 | \n", "Bin 7 | \n", "Bin 8 | \n", "Bin 9 | \n", "Bin 10 | \n", "Bin 11 | \n", "Bin 12 | \n", "Bin 13 | \n", "Bin 14 | \n", "Bin 15 | \n", "Bin 16 | \n", "Bin 17 | \n", "Bin 18 | \n", "Bin 19 | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "1.133778 | \n", "2.961818 | \n", "6.891982 | \n", "14.285167 | \n", "26.374356 | \n", "43.374429 | \n", "63.539099 | \n", "82.909386 | \n", "96.365531 | \n", "99.768882 | \n", "92.007635 | \n", "75.580193 | \n", "55.302848 | \n", "36.044779 | \n", "20.926308 | \n", "10.821768 | \n", "4.984932 | \n", "2.045387 | \n", "0.747562 | \n", "
| 1 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "100.000000 | \n", "
| 2 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "