{ "cells": [ { "cell_type": "markdown", "id": "58ff55b9-7d22-47fe-8d5b-1d29d2194498", "metadata": {}, "source": [ "# Diffusion of 1 chemical in 2D\n", "\n", "## An initial concentration pulse of a single chemical (near the left edge of the system, and halfway vertically), diffusing towards equilibrium\n", "\n", "The system starts out with a \"concentration pulse\" in just one bin - i.e. that bin is initially the only one with a non-zero concentration of the only chemical species.\n", "Then the system is left undisturbed, and followed to diffusive equilibrium.\n", "\n", "(Note: this is the 2D counterpart of the 1D experiment by the same name)" ] }, { "cell_type": "markdown", "id": "2f8f4779-dfe5-468e-8109-1669b4a5e3fa", "metadata": {}, "source": [ "### TAGS : \"diffusion 2D\", \"quick-start\"" ] }, { "cell_type": "code", "execution_count": 1, "id": "b2d81d16-f539-4e31-ab7b-e3f64a0f8e0d", "metadata": {}, "outputs": [], "source": [ "LAST_REVISED = \"Jan. 22, 2025\"\n", "LIFE123_VERSION = \"1.0.0rc2\" # Library version this experiment is based on" ] }, { "cell_type": "code", "execution_count": 2, "id": "88b7ee23-fc65-4cf8-b613-af1301073515", "metadata": {}, "outputs": [], "source": [ "#import set_path # Using MyBinder? Uncomment this before running the next cell!" ] }, { "cell_type": "code", "execution_count": 3, "id": "f6b53bd5", "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 BioSim2D, ChemData, check_version" ] }, { "cell_type": "code", "execution_count": 4, "id": "008a6f6e-0bae-4d70-b486-43dda6214bf4", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "OK\n" ] } ], "source": [ "check_version(LIFE123_VERSION)" ] }, { "cell_type": "code", "execution_count": null, "id": "428cde1a-90d0-46ee-a52e-aaf043c1923a", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 5, "id": "4f7885eb-2bd2-4d28-bca9-8e4685f4fd9d", "metadata": {}, "outputs": [], "source": [ "# Prepare the initial system, with a single non-zero bin, near the left edge of the system, positioned halfway vertically\n", "chem_data = ChemData(names=\"A\", diffusion_rates=0.02)\n", "\n", "bio = BioSim2D(x_bins=8, y_bins=5, chem_data=chem_data)" ] }, { "cell_type": "code", "execution_count": 6, "id": "1df77fcd-69c2-4e63-8464-e469f72a5c26", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SYSTEM STATE at Time t = 0:\n", "Species `A`:\n", " 0 1 2 3 4 5 6 7\n", "4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n", "3 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n", "2 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n", "1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n", "0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n" ] } ], "source": [ "bio.describe_state()" ] }, { "cell_type": "code", "execution_count": null, "id": "1f4571d4-18ba-4ee9-9d65-37642bf51a78", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "670d0f44", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "942396a5-48d4-408a-a840-f5828f0ab8ae", "metadata": {}, "source": [ "## Request history-keeping for some bins" ] }, { "cell_type": "code", "execution_count": 7, "id": "8fb2007a-c5dc-487d-b4e0-8341cfbe898f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "History enabled for bins [(1, 2), (7, 4)] and chemicals None (None means 'all')\n" ] } ], "source": [ "bio.enable_history(bins=[(1,2), (7,4)], frequency=3) # Request to save the concentration history at those bins \n", " # (the one with the initial injection, and one far away in a corner)" ] }, { "cell_type": "code", "execution_count": null, "id": "050808a5-497e-4016-a4e1-1fce2f32a213", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "1fce66ff-3159-4c1e-ac92-fcf4fd829645", "metadata": {}, "source": [ "## Apply the initial concentration pulse" ] }, { "cell_type": "code", "execution_count": 8, "id": "eed41906-989b-473e-945f-6caeccab4385", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SYSTEM STATE at Time t = 0:\n", "Species `A`:\n", " 0 1 2 3 4 5 6 7\n", "4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n", "3 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n", "2 0.0 10.0 0.0 0.0 0.0 0.0 0.0 0.0\n", "1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n", "0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n" ] } ], "source": [ "bio.set_bin_conc(bin_address = (1,2), chem_label=\"A\", conc=10.)\n", "\n", "bio.describe_state()" ] }, { "cell_type": "code", "execution_count": 9, "id": "926d5808-2048-424a-94b2-92d2169726bb", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | 0 | \n", "1 | \n", "2 | \n", "3 | \n", "4 | \n", "5 | \n", "6 | \n", "7 | \n", "
|---|---|---|---|---|---|---|---|---|
| 4 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 3 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 2 | \n", "0.0 | \n", "10.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 1 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| \n", " | SYSTEM TIME | \n", "A | \n", "
|---|---|---|
| 0 | \n", "0.3 | \n", "9.762391 | \n", "
| 1 | \n", "0.6 | \n", "9.531824 | \n", "
| 2 | \n", "0.9 | \n", "9.308067 | \n", "
| 3 | \n", "1.2 | \n", "9.090898 | \n", "
| 4 | \n", "1.5 | \n", "8.880100 | \n", "
| ... | \n", "... | \n", "... | \n", "
| 5968 | \n", "1808.7 | \n", "0.251401 | \n", "
| 5969 | \n", "1809.0 | \n", "0.251400 | \n", "
| 5970 | \n", "1809.3 | \n", "0.251399 | \n", "
| 5971 | \n", "1809.6 | \n", "0.251398 | \n", "
| 5972 | \n", "1809.9 | \n", "0.251396 | \n", "
5973 rows × 2 columns
\n", "