{ "cells": [ { "cell_type": "markdown", "id": "19564ec4-168a-481e-ba02-6d3fe0ce5fef", "metadata": {}, "source": [ "### Exploring the data structures of MEMBRANES, and reactions in them \n", "#### - with NO DIFFUSION\n", "\n", "LAST REVISED: July 14, 2023" ] }, { "cell_type": "code", "execution_count": 1, "id": "51fce5bd-df35-4b06-8a3b-50901e1e3a0d", "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": "14506983", "metadata": {}, "outputs": [], "source": [ "from src.modules.chemicals.chem_data import ChemData as chem\n", "\n", "from src.life_1D.bio_sim_1d import BioSim1D" ] }, { "cell_type": "code", "execution_count": 3, "id": "81b9c228-ab44-48ce-b0a1-99b52bcbaf98", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SYSTEM STATE at Time t = 0:\n", "5 bins and 3 species:\n", " Species 0 (A). Diff rate: None. Conc: |4.0|4.0()4.0|4.0|4.0|4.0|\n", " Species 1 (B). Diff rate: None. Conc: |8.0|8.0()8.0|8.0|8.0|8.0|\n", " Species 2 (C). Diff rate: None. Conc: |12.0|12.0()12.0|12.0|12.0|12.0|\n" ] } ], "source": [ "chem_data = chem(names=[\"A\", \"B\", \"C\"]) # NOTE: Diffusion not done\n", "bio = BioSim1D(n_bins=5, chem_data=chem_data)\n", "\n", "bio.set_membranes(membrane_pos=[1]) # A single membrane, passing thru bin 1\n", "\n", "bio.set_all_uniform_concentrations(conc_list=[4., 8., 12.])\n", "\n", "bio.describe_state()" ] }, { "cell_type": "code", "execution_count": 4, "id": "5816fe14-c3d4-48ee-8e2e-fac3af6ea662", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SYSTEM STATE at Time t = 0:\n", "5 bins and 3 species:\n", " Species 0 (A). Diff rate: None. Conc: |4.0|10.0()55.0|4.0|4.0|4.0|\n", " Species 1 (B). Diff rate: None. Conc: |8.0|20.0()8.0|8.0|8.0|8.0|\n", " Species 2 (C). Diff rate: None. Conc: |12.0|30.0()30.0|12.0|12.0|12.0|\n" ] } ], "source": [ "bio.set_bin_conc(bin_address=1, species_name=\"A\", conc=10.)\n", "bio.set_bin_conc(bin_address=1, species_name=\"A\", conc=55., across_membrane=True)\n", "bio.set_bin_conc(bin_address=1, species_name=\"B\", conc=20.)\n", "bio.set_bin_conc(bin_address=1, species_name=\"C\", conc=30., both_sides=True)\n", "\n", "bio.describe_state()" ] }, { "cell_type": "code", "execution_count": 5, "id": "45084a50-2421-4f5d-995b-227f5e4d623e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SYSTEM STATE at Time t = 0:\n", "5 bins and 3 species:\n", " Species 0 (A). Diff rate: None. Conc: |4.0|10.0()55.0|4.0|4.0|55.0|\n", " Species 1 (B). Diff rate: None. Conc: |8.0|20.0()8.0|8.0|8.0|8.0|\n", " Species 2 (C). Diff rate: None. Conc: |12.0|30.0()30.0|12.0|12.0|30.0|\n" ] } ], "source": [ "# Make the last bin match all the concentrations of the \"post-membrane\" section of bin 1\n", "bio.set_bin_conc(bin_address=4, species_name=\"A\", conc=55.)\n", "bio.set_bin_conc(bin_address=4, species_name=\"C\", conc=30.)\n", "\n", "bio.describe_state()" ] }, { "cell_type": "code", "execution_count": 6, "id": "fc5b6db9-5b30-4319-85ce-6730c0ec5fb9", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of reactions: 1 (at temp. 25 C)\n", "0: A + B <-> C (kF = 8 / kR = 2 / Delta_G = -3,436.56 / K = 4) | 1st order in all reactants & products\n" ] } ], "source": [ "# Reaction A + B <-> C , with 1st-order kinetics in both directions, mostly forward\n", "bio.chem_data.add_reaction(reactants=[\"A\", \"B\"], products=[\"C\"], forward_rate=8., reverse_rate=2.)\n", "\n", "bio.chem_data.describe_reactions()" ] }, { "cell_type": "code", "execution_count": 7, "id": "6abf3304-caff-4d4b-9c93-a71c949f2726", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SYSTEM STATE at Time t = 0.002:\n", "5 bins and 3 species:\n", " Species 0 (A). Diff rate: None. Conc: |3.536|6.92()48.08|3.536|3.536|48.08|\n", " Species 1 (B). Diff rate: None. Conc: |7.536|16.92()1.08|7.536|7.536|1.08|\n", " Species 2 (C). Diff rate: None. Conc: |12.464|33.08()36.92|12.464|12.464|36.92|\n" ] } ], "source": [ "bio.react(time_step=0.002, n_steps=1)\n", "bio.describe_state()" ] }, { "cell_type": "markdown", "id": "2468c2e9-18be-4b46-b51a-ace15531fc3d", "metadata": {}, "source": [ "### Note how (in the absence of diffusion, which we're neglecting) the concentrations on the \"post-membrane side\" of bin 1 continue to match those of bin 5" ] }, { "cell_type": "markdown", "id": "d19d67cd-a3d7-4fb5-ba16-c820c55344a8", "metadata": {}, "source": [ "## Now continue to reaction equilibrium" ] }, { "cell_type": "code", "execution_count": 8, "id": "68cbe07b-0920-4c09-8b7a-800999c1175a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SYSTEM STATE at Time t = 0.202:\n", "5 bins and 3 species:\n", " Species 0 (A). Diff rate: None. Conc: |0.7932534523016194|0.8970947370566021()47.20020986266437|0.7932534523016194|0.7932534523016194|47.20020986266437|\n", " Species 1 (B). Diff rate: None. Conc: |4.793253452301623|10.897094737056594()0.20020986266437912|4.793253452301623|4.793253452301623|0.20020986266437912|\n", " Species 2 (C). Diff rate: None. Conc: |15.206746547698396|39.10290526294337()37.79979013733563|15.206746547698396|15.206746547698396|37.79979013733563|\n" ] } ], "source": [ "bio.react(time_step=0.002, n_steps=100)\n", "bio.describe_state()" ] }, { "cell_type": "markdown", "id": "4efbc61b-efa9-49eb-b1f3-0c901fffdd8a", "metadata": {}, "source": [ "### The system has now reached equilibrium\n", "### in individual bins, which remain separate because we're NOT doing diffusion in this experiment" ] }, { "cell_type": "markdown", "id": "07ac2214-aec4-4b1f-8ad7-328c729cc35c", "metadata": {}, "source": [ "Verify the equilibrium in each of the active bins" ] }, { "cell_type": "code", "execution_count": 9, "id": "c92cf0dc-9055-4b4a-8692-7f32b1ac435e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "A + B <-> C\n", "Final concentrations: [C] = 15.21 ; [A] = 0.7933 ; [B] = 4.793\n", "1. Ratio of reactant/product concentrations, adjusted for reaction orders: 3.99939\n", " Formula used: [C] / ([A][B])\n", "2. Ratio of forward/reverse reaction rates: 4.0\n", "Discrepancy between the two values: 0.01521 %\n", "Reaction IS in equilibrium (within 1% tolerance)\n", "\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bio.reaction_dynamics.is_in_equilibrium(rxn_index=0, conc={\"A\": 0.7932534523016195, \"B\": 4.793253452301622, \"C\": 15.206746547698396})\n", "# A was largely the limiting reagent" ] }, { "cell_type": "code", "execution_count": 10, "id": "b9b74e29-de37-4257-9693-ab226eda6449", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "A + B <-> C\n", "Final concentrations: [C] = 39.1 ; [A] = 0.8971 ; [B] = 10.9\n", "1. Ratio of reactant/product concentrations, adjusted for reaction orders: 4\n", " Formula used: [C] / ([A][B])\n", "2. Ratio of forward/reverse reaction rates: 4.0\n", "Discrepancy between the two values: 2.259e-07 %\n", "Reaction IS in equilibrium (within 1% tolerance)\n", "\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bio.reaction_dynamics.is_in_equilibrium(rxn_index=0, conc={\"A\": 0.897094737056602, \"B\": 10.897094737056594, \"C\": 39.10290526294337})\n", "# A was largely the limiting reagent" ] }, { "cell_type": "code", "execution_count": 11, "id": "7cc098bc-3d68-4f4d-a754-e5c8cedd7e9c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "A + B <-> C\n", "Final concentrations: [C] = 37.8 ; [A] = 47.2 ; [B] = 0.2002\n", "1. Ratio of reactant/product concentrations, adjusted for reaction orders: 4\n", " Formula used: [C] / ([A][B])\n", "2. Ratio of forward/reverse reaction rates: 4.0\n", "Discrepancy between the two values: 0 %\n", "Reaction IS in equilibrium (within 1% tolerance)\n", "\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bio.reaction_dynamics.is_in_equilibrium(rxn_index=0, conc={\"A\": 47.20020986266437, \"B\": 0.20020986266437912, \"C\": 37.79979013733563})\n", "# This time, with ample [A], the limiting reagent was B" ] }, { "cell_type": "code", "execution_count": null, "id": "f7b5f5b7", "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 }