{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Linear polymerization\n", "\n", "This example demonstrates a simple polymerization process in which monomers `M` can bind each other to form linear chains.\n", "There's a lower rate of depolymerization, and chains can be terminated by capping agents `C`." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "nbsphinx": "hidden" }, "outputs": [], "source": [ "import random\n", "random.seed(42)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from pykappa.system import System\n", "\n", "system = System.from_ka(\n", " \"\"\"\n", " %init: 1000 M(l[.], r[.])\n", "\n", " %obs: 'Free monomer' |M(l[.], r[.])|\n", "\n", " M(r[.]), M(l[.]) -> M(r[1]), M(l[1]) @ 1 // Polymerization\n", " M(r[1]), M(l[1]) -> M(r[.]), M(l[.]) @ 0.1 // Depolymerization\n", " \n", " // Chain capping\n", " M(r[.]), C(m[.]) -> M(r[1]), C(m[1]) @ 0.05\n", " M(l[.]), C(m[.]) -> M(l[1]), C(m[1]) @ 0.05\n", " \n", " // Cap removal\n", " M(r[1]), C(m[1]) -> M(r[.]), C(m[.]) @ 0.01\n", " M(l[1]), C(m[1]) -> M(l[.]), C(m[.]) @ 0.01\n", " \"\"\"\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Simulate for a bit:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "while system.time < 100:\n", " system.update()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "\n", "def polymer_len_plot(system):\n", " plt.hist([len(component) for component in system.mixture if len(component) > 1])\n", " plt.xlabel(\"Polymer length\")\n", " plt.ylabel(\"Count\");\n", "\n", "print(f\"Free monomers: {system['Free monomer']}\")\n", "polymer_len_plot(system)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's add some of the capping agent:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "system.mixture.instantiate(\"C(m[.])\", 500)\n", "\n", "while system.time < 200:\n", " system.update()\n", "\n", "print(f\"Free monomers: {system['Free monomer']}\")\n", "polymer_len_plot(system)" ] } ], "metadata": { "kernelspec": { "display_name": "standard", "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.12.3" } }, "nbformat": 4, "nbformat_minor": 2 }