{ "cells": [ { "cell_type": "markdown", "id": "49bcb5b0-f19d-4b96-a5f1-e0ae30f66d8f", "metadata": {}, "source": [ "## Macromolecules : Binding Affinity and Fractional Occupancy\n", " \n", "\n", "LAST REVISED: June 23, 2024 (using v. 1.0 beta36)" ] }, { "cell_type": "code", "execution_count": 1, "id": "98adb66e-e336-4a4e-9a47-d48e9f0c8c68", "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": "c1ac7763", "metadata": { "tags": [] }, "outputs": [], "source": [ "from life123 import ChemData\n", "from life123 import UniformCompartment\n", "from life123 import MovieTabular\n", "\n", "import numpy as np\n", "\n", "import plotly.express as px" ] }, { "cell_type": "code", "execution_count": 3, "id": "23c15e66-52e4-495b-aa3d-ecddd8d16942", "metadata": { "lines_to_next_cell": 2 }, "outputs": [], "source": [ "# Initialize the system\n", "chem = ChemData(names=[\"A\", \"B\", \"C\"])" ] }, { "cell_type": "markdown", "id": "83fd43d2-6a90-4b24-ae2c-5a65718e416d", "metadata": {}, "source": [ "## Explore methods to manage the data structure for macromolecules" ] }, { "cell_type": "code", "execution_count": 4, "id": "e3aa4733-dd9d-485d-a899-a9a03ff40d87", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['M1']" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "chem.add_macromolecules(\"M1\")\n", "chem.get_macromolecules()" ] }, { "cell_type": "code", "execution_count": 5, "id": "acbd2b50-8bc1-4e23-8816-0da0ee85b461", "metadata": {}, "outputs": [], "source": [ "chem.set_binding_site_affinity(\"M1\", site_number=3, ligand=\"A\", Kd=1.0)\n", "chem.set_binding_site_affinity(\"M1\", site_number=8, ligand=\"B\", Kd=3.2)\n", "chem.set_binding_site_affinity(\"M1\", site_number=15, ligand=\"A\", Kd=10.0)\n", "\n", "chem.set_binding_site_affinity(\"M2\", site_number=1, ligand=\"C\", Kd=5.6) # \"M2\" will get automatically added\n", "chem.set_binding_site_affinity(\"M2\", site_number=2, ligand=\"A\", Kd=0.01)" ] }, { "cell_type": "code", "execution_count": 6, "id": "86e39939-7e26-4cfd-af63-a4a536966927", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "M1 :\n", " Site 3 - Kd (dissociation const) for A : 1.0\n", " Site 8 - Kd (dissociation const) for B : 3.2\n", " Site 15 - Kd (dissociation const) for A : 10.0\n", "M2 :\n", " Site 1 - Kd (dissociation const) for C : 5.6\n", " Site 2 - Kd (dissociation const) for A : 0.01\n" ] } ], "source": [ "chem.show_binding_affinities() # Review the values we have given for the dissociation constants" ] }, { "cell_type": "code", "execution_count": 7, "id": "fecbf8df-1e28-4b0b-99ec-d3d76923dfe4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[3, 8, 15]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "chem.get_binding_sites(\"M1\")" ] }, { "cell_type": "code", "execution_count": 8, "id": "0c805eec-10a2-44e1-b543-eeb8b39510a7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{3: 'A', 8: 'B', 15: 'A'}" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "chem.get_binding_sites_and_ligands(\"M1\")" ] }, { "cell_type": "code", "execution_count": 9, "id": "db43fb3f-0f1f-4d46-8371-b23b1deab647", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "chem.get_binding_sites(\"M2\")" ] }, { "cell_type": "code", "execution_count": 10, "id": "36a5710b-f3db-4478-a91d-2a3ad4a576da", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{1: 'C', 2: 'A'}" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "chem.get_binding_sites_and_ligands(\"M2\")" ] }, { "cell_type": "code", "execution_count": 11, "id": "afae6257-830f-4636-898f-c5af9529ab78", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "ChemicalAffinity(chemical='C', Kd=5.6)" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aff = chem.get_binding_site_affinity(macromolecule=\"M2\", site_number=1) # A \"NamedTuple\" gets returned\n", "aff" ] }, { "cell_type": "code", "execution_count": 12, "id": "4124f99a-e474-43cd-8854-ce71ad870987", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'C'" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aff.chemical" ] }, { "cell_type": "code", "execution_count": 13, "id": "647ee66c-f7c7-4677-9c05-2b309d06fd89", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5.6" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aff.Kd" ] }, { "cell_type": "code", "execution_count": null, "id": "cf6ed2ea-04b8-48d6-a20b-120f22b4732d", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "7899d8b1-3b0f-4243-895d-6ba51f0174d7", "metadata": {}, "source": [ "## Start setting up the dynamical system" ] }, { "cell_type": "code", "execution_count": 14, "id": "73fb80ce-a07c-464d-81e4-814955b613ee", "metadata": {}, "outputs": [], "source": [ "dynamics = UniformCompartment(chem_data=chem)" ] }, { "cell_type": "code", "execution_count": 15, "id": "85d19965-4a82-4868-9a1f-cbf6fc29b6cd", "metadata": {}, "outputs": [], "source": [ "dynamics.set_macromolecules() # By default, set counts to 1 for all the registered macromolecules" ] }, { "cell_type": "code", "execution_count": 16, "id": "ccd16fb4-f5de-474c-b85d-28a3f64e815b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SYSTEM STATE at Time t = 0:\n", "3 species:\n", " Species 0 (A). No concentrations set yet\n", " Species 1 (B). No concentrations set yet\n", " Species 2 (C). No concentrations set yet\n", "Macro-molecules, with their counts: {'M1': 1, 'M2': 1}\n", "Fractional Occupancy at the various binding sites for each macro-molecule:\n", " M1 || 3: 0.0 (A) | 8: 0.0 (B) | 15: 0.0 (A)\n", " M2 || 1: 0.0 (C) | 2: 0.0 (A)\n", "Set of chemicals involved in reactions: set()\n" ] } ], "source": [ "dynamics.describe_state()" ] }, { "cell_type": "markdown", "id": "9c712242-7dca-4a90-b743-df1e4e3fbc6e", "metadata": {}, "source": [ "### Inspect some class attributes (not to be directly modified by the end user!)" ] }, { "cell_type": "code", "execution_count": 17, "id": "71326536-e56b-4499-a78a-7149ccc9b727", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'M1': 1, 'M2': 1}" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dynamics.macro_system" ] }, { "cell_type": "code", "execution_count": 18, "id": "5ffd0c72-67cd-4150-ad8e-89382622c591", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'M1': {3: ('A', 0.0), 8: ('B', 0.0), 15: ('A', 0.0)},\n", " 'M2': {1: ('C', 0.0), 2: ('A', 0.0)}}" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dynamics.macro_system_state" ] }, { "cell_type": "markdown", "id": "0e771dda-1c0f-4fc0-ab21-049740643897", "metadata": {}, "source": [ "### Set the initial concentrations of all the ligands" ] }, { "cell_type": "code", "execution_count": 19, "id": "5563e467-a637-44fa-9ba1-d35ddd82c887", "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: 0.0\n", " Species 2 (C). Conc: 0.56\n", "Macro-molecules, with their counts: {'M1': 1, 'M2': 1}\n", "Fractional Occupancy at the various binding sites for each macro-molecule:\n", " M1 || 3: 0.0 (A) | 8: 0.0 (B) | 15: 0.0 (A)\n", " M2 || 1: 0.0 (C) | 2: 0.0 (A)\n", "Set of chemicals involved in reactions: set()\n" ] } ], "source": [ "dynamics.set_conc(conc={\"A\": 10., \"B\": 0., \"C\": 0.56})\n", "dynamics.describe_state()" ] }, { "cell_type": "markdown", "id": "ad018b3c-e331-4fa9-92d6-b49c63aff226", "metadata": {}, "source": [ "### Determine and adjust the fractional occupancy of the various sites on the macromolecules, based on the current ligand concentrations" ] }, { "cell_type": "code", "execution_count": 20, "id": "6c1dc8cb", "metadata": {}, "outputs": [], "source": [ "dynamics.update_occupancy()" ] }, { "cell_type": "code", "execution_count": 21, "id": "42c2f8f4-bea5-4d21-a1ad-4ab76d34cb3e", "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: 0.0\n", " Species 2 (C). Conc: 0.56\n", "Macro-molecules, with their counts: {'M1': 1, 'M2': 1}\n", "Fractional Occupancy at the various binding sites for each macro-molecule:\n", " M1 || 3: 0.8999999930397401 (A) | 8: 1.6007639537264433e-15 (B) | 15: 0.5 (A)\n", " M2 || 1: 0.10000000696026 (C) | 2: 0.9986301366689166 (A)\n", "Set of chemicals involved in reactions: set()\n" ] } ], "source": [ "dynamics.describe_state()" ] }, { "cell_type": "code", "execution_count": 22, "id": "660d99ff-ddd0-419b-b40a-25ac27aa1d1f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "M1 :\n", " Site 3 - Kd (dissociation const) for A : 1.0\n", " Site 8 - Kd (dissociation const) for B : 3.2\n", " Site 15 - Kd (dissociation const) for A : 10.0\n", "M2 :\n", " Site 1 - Kd (dissociation const) for C : 5.6\n", " Site 2 - Kd (dissociation const) for A : 0.01\n" ] } ], "source": [ "dynamics.chem_data.show_binding_affinities() # Review the values we had given for the dissociation constants" ] }, { "cell_type": "markdown", "id": "202f78e9-9c87-43b6-b2e0-9addce298262", "metadata": {}, "source": [ "#### Notes:\n", "**[B] = 0** => Occupancy of binding site 8 of M1 is also zero\n", "\n", "**[A] = 10.0** : \n", " * 10x the dissociation constant of A to site 3 of M1 (resulting in occupancy 0.9) \n", " * same as the dissociation constant of A to site 15 of M1 (occupancy 0.5) \n", " * 1,000x the dissociation constant of A to site 2 of M2 (occupancy almost 1, i.e. nearly saturated)\n", " \n", " \n", "**[C] = 0.56** => 1/10 of the dissociation constant of C to site 1 of M2 (occupancy 0.1)" ] }, { "cell_type": "code", "execution_count": null, "id": "1caef55c-558b-462a-8b5e-a1474fd78092", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "22d48dc6-5876-4982-b37d-c9209a2bd811", "metadata": {}, "source": [ "### Adjust the concentration of one ligand, [A], and update all the fractional occupancies accordingly" ] }, { "cell_type": "code", "execution_count": 23, "id": "222dc35e-0804-455a-8019-2372272a5899", "metadata": {}, "outputs": [], "source": [ "dynamics.set_single_conc(conc=1000., species_name=\"A\", snapshot=False)" ] }, { "cell_type": "code", "execution_count": 24, "id": "f4b30f28-1f55-46e7-a51d-60d0f580828f", "metadata": {}, "outputs": [], "source": [ "dynamics.update_occupancy()" ] }, { "cell_type": "code", "execution_count": 25, "id": "a3c63fb6-fb88-4c08-9617-3405032ffab2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SYSTEM STATE at Time t = 0:\n", "3 species:\n", " Species 0 (A). Conc: 1000.0\n", " Species 1 (B). Conc: 0.0\n", " Species 2 (C). Conc: 0.56\n", "Macro-molecules, with their counts: {'M1': 1, 'M2': 1}\n", "Fractional Occupancy at the various binding sites for each macro-molecule:\n", " M1 || 3: 0.9986301366689166 (A) | 8: 1.6007639537264433e-15 (B) | 15: 0.9878048761855343 (A)\n", " M2 || 1: 0.10000000696026 (C) | 2: 0.9999830651924357 (A)\n", "Set of chemicals involved in reactions: set()\n" ] } ], "source": [ "dynamics.describe_state()" ] }, { "cell_type": "markdown", "id": "85671b32-485d-46f9-a21d-e6f711e7ed73", "metadata": {}, "source": [ "#### Note how all the various binding sites for ligand A, across all macromolecules, now have a different value for the fractional occupancy (very close to 1 because of the large value of [A] relative to each of the dissociation constants for A.)\n", "The fractional occupancies for the other ligands (B and C) did not change" ] }, { "cell_type": "code", "execution_count": null, "id": "0468fcfe-8511-4c81-9f47-4b2f4a24d76a", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "08d7c9fd-1bfd-459a-bd45-e8c4bfb8130b", "metadata": {}, "source": [ "### Sweep the values of [A] across a wide range, and compute/store how the fractional occupancies of A change" ] }, { "cell_type": "code", "execution_count": 26, "id": "a4ef4ca6-0233-47d3-8209-d3e337a8392c", "metadata": {}, "outputs": [], "source": [ "history = MovieTabular(parameter_name=\"[A]\") # A convenient way to store a sequence of \"state snapshots\" as a Pandas dataframe" ] }, { "cell_type": "code", "execution_count": 27, "id": "60a76c7e-6eb4-423f-8103-683205aaf817", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "`MovieTabular` object with 0 snapshot(s) parametrized by `[A]`\n" ] } ], "source": [ "print(history)" ] }, { "cell_type": "code", "execution_count": 28, "id": "4cfdbf3f-cec9-4f6c-83bc-05fd408411a4", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[1.00000000e-03 1.13121657e-03 1.27965093e-03 1.44756233e-03\n", " 1.63750649e-03 1.85237447e-03 2.09543670e-03 2.37039271e-03\n", " 2.68142751e-03 3.03327522e-03 3.43129119e-03 3.88153345e-03\n", " 4.39085495e-03 4.96700787e-03 5.61876160e-03 6.35603621e-03\n", " 7.19005348e-03 8.13350762e-03 9.20075859e-03 1.04080506e-02\n", " 1.17737592e-02 1.33186715e-02 1.50663019e-02 1.70432503e-02\n", " 1.92796072e-02 2.18094111e-02 2.46711672e-02 2.79084331e-02\n", " 3.15704819e-02 3.57130522e-02 4.03991964e-02 4.57002403e-02\n", " 5.16968690e-02 5.84803548e-02 6.61539463e-02 7.48344401e-02\n", " 8.46539585e-02 9.57619605e-02 1.08327516e-01 1.22541881e-01\n", " 1.38621407e-01 1.56810832e-01 1.77387011e-01 2.00663126e-01\n", " 2.26993453e-01 2.56778755e-01 2.90472382e-01 3.28587172e-01\n", " 3.71703253e-01 4.20476878e-01 4.75650411e-01 5.38063626e-01\n", " 6.08666489e-01 6.88533617e-01 7.78880636e-01 8.81082680e-01\n", " 9.96695326e-01 1.12747827e+00 1.27542210e+00 1.44277861e+00\n", " 1.63209507e+00 1.84625298e+00 2.08851196e+00 2.36255934e+00\n", " 2.67256626e+00 3.02325124e+00 3.41995189e+00 3.86870625e+00\n", " 4.37634461e+00 4.95059353e+00 5.60019342e+00 6.33503159e+00\n", " 7.16629270e+00 8.10662903e+00 9.17035308e+00 1.03736553e+01\n", " 1.17348508e+01 1.32746577e+01 1.50165127e+01 1.69869280e+01\n", " 1.92158944e+01 2.17373381e+01 2.45896370e+01 2.78162048e+01\n", " 3.14661517e+01 3.55950322e+01 4.02656902e+01 4.55492159e+01\n", " 5.15260277e+01 5.82870963e+01 6.59353291e+01 7.45871367e+01\n", " 8.43742048e+01 9.54454985e+01 1.07969529e+02 1.22136920e+02\n", " 1.38163308e+02 1.56292623e+02 1.76800805e+02 2.00000000e+02]\n" ] } ], "source": [ "# Generate a sweep of [A] values along a log scale, from very low to very high (relative to the dissociation constants)\n", "start = 0.001\n", "stop = 200.\n", "num_points = 100\n", "\n", "log_values = np.logspace(np.log10(start), np.log10(stop), num=num_points)\n", "\n", "print(log_values)" ] }, { "cell_type": "code", "execution_count": 29, "id": "5d4be3d3-6eba-4aa2-a265-a869622a5221", "metadata": {}, "outputs": [], "source": [ "# Set [A] to each of the above values in turn, and determine/store the applicable fractional occupancies (for the sites where A binds)\n", "for A_conc in log_values:\n", " dynamics.set_single_conc(conc=A_conc, species_name=\"A\", snapshot=False)\n", " dynamics.update_occupancy()\n", " history.store(A_conc, {\"M1 site 3\": dynamics.get_occupancy(macromolecule=\"M1\", site_number=3), \n", " \"M1 site 15\": dynamics.get_occupancy(macromolecule=\"M1\", site_number=15), \n", " \"M2 site 2\": dynamics.get_occupancy(macromolecule=\"M2\", site_number=2)})" ] }, { "cell_type": "code", "execution_count": 30, "id": "6976557b-0e17-4dba-8d6b-29b47e48fd0e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | [A] | \n", "M1 site 3 | \n", "M1 site 15 | \n", "M2 site 2 | \n", "caption | \n", "
---|---|---|---|---|---|
0 | \n", "0.001000 | \n", "0.001370 | \n", "0.000152 | \n", "0.100000 | \n", "\n", " |
1 | \n", "0.001131 | \n", "0.001541 | \n", "0.000171 | \n", "0.111098 | \n", "\n", " |
2 | \n", "0.001280 | \n", "0.001733 | \n", "0.000193 | \n", "0.123259 | \n", "\n", " |
3 | \n", "0.001448 | \n", "0.001949 | \n", "0.000217 | \n", "0.136547 | \n", "\n", " |
4 | \n", "0.001638 | \n", "0.002191 | \n", "0.000244 | \n", "0.151021 | \n", "\n", " |
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
95 | \n", "122.136920 | \n", "0.989902 | \n", "0.915911 | \n", "0.999874 | \n", "\n", " |
96 | \n", "138.163308 | \n", "0.991013 | \n", "0.924540 | \n", "0.999888 | \n", "\n", " |
97 | \n", "156.292623 | \n", "0.992002 | \n", "0.932349 | \n", "0.999900 | \n", "\n", " |
98 | \n", "176.800805 | \n", "0.992884 | \n", "0.939403 | \n", "0.999912 | \n", "\n", " |
99 | \n", "200.000000 | \n", "0.993669 | \n", "0.945764 | \n", "0.999921 | \n", "\n", " |
100 rows × 5 columns
\n", "