{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chemostat\n", "\n", "A chemostat can maintain a concentration of nutrients in a container by flowing in and flowing out nutrients each at a constant rate.\n", "Here we will set up a simulatable chemostat with a clonal and unevolving unicellular organism, and adjust the flow rate to observe the effect on the growth rate of the cells.\n", "More specifically, we will assume that a cell `C` replicates following metabolism of three units of the nutrient `N`, and that cells die memorylessly at a constant stochastic rate." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "nbsphinx": "hidden" }, "outputs": [], "source": [ "import random\n", "random.seed(0)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from pykappa.system import System\n", "\n", "system = System.from_ka(\n", " \"\"\"\n", " %init: 10 C(n{0}) // Start with a few cells\n", "\n", " %obs: 'C' |C()|\n", "\n", " . -> N() @ 1 // Nutrient inflow\n", " N() -> . @ 0.1 // Nutrient outflow\n", "\n", " // Metabolism\n", " C(n{0}), N() -> C(n{1}), . @ 0.5\n", " C(n{1}), N() -> C(n{2}), . @ 0.5\n", " C(n{2}), N() -> C(n{3}), . @ 0.5\n", "\n", " C(n{3}), . -> C(n{0}), C(n{0}) @ 0.1 // Cell division\n", " C() -> . @ 0.01 // Cell death\n", " \"\"\"\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we started with only, say, one cell, it would be reasonably likely that the population would die out before replicating sufficiently to virtually preclude extinction." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's start the chemostat and observe the population size:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "while system.time < 10 ** 3:\n", " system.update()\n", "system.monitor.plot();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's increase inflow of the nutrient without changing the outflow rate and observe that the population size increases:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "system.add_rule(\". -> N() @ 1\")\n", "\n", "while system.time < 5 * 10 ** 3:\n", " system.update()\n", "system.monitor.plot();" ] } ], "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 }