{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "2bXhwsreMfAn" }, "source": [ "# Cell Lysis modelling" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Code implemented by Mariana Albino, marial@kt.dtu.dk" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "_U_AbENA8F7L" }, "outputs": [], "source": [ "# import libraries\n", "import numpy as np\n", "import scipy\n", "import plotly.express as px\n", "import plotly.graph_objects as go\n", "from scipy.integrate import solve_ivp\n", "from plotly.subplots import make_subplots" ] }, { "cell_type": "markdown", "metadata": { "id": "0N_uSEPwwc_R" }, "source": [ "## Bead mill" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "I_4IjOk9wV9v" }, "outputs": [], "source": [ "def ode_fcn(t, y, k, Rm):\n", " # define parameters\n", " R = y[0]\n", "\n", " # ODE\n", " dR_dt = k*(Rm-R)\n", " dy = [dR_dt]\n", "\n", " return dy\n", "\n", "def solver(R_0, k ,Rm ,t_end):\n", " #define the function to solve\n", " fun = lambda t, y: ode_fcn(t,y,k,Rm)\n", "\n", " #set initial value for parameters\n", " y0 = [R_0]\n", "\n", " #set time span\n", " t_span = np.arange(0, t_end, 0.1) #(t_start, t_end, t_step)\n", "\n", " #solve the differential equation\n", " sol = solve_ivp(fun, [t_span[0], t_span[-1]], y0, method='LSODA', t_eval=t_span, rtol=1e-6, atol=1e-6)\n", "\n", " #extract the solution\n", " t = sol.t.tolist()\n", " y = sol.y.T\n", "\n", " #asign the solution to variables\n", " R = y[:, 0]\n", " Y = y[:,0]/Rm*100\n", "\n", " return t, R, Y" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "KtOgJ4hp7B-b" }, "outputs": [], "source": [ "\"\"\" Set Process Parameters for run generation \"\"\"\n", "R_0 = 0 #R at time 0\n", "R_m = 10 #Rm\n", "K = 0.5\n", "\n", "TIME_END = 5 #how much time should be simulated\n", "\n", "t, R , Y = solver(R_0, K, R_m, TIME_END) #run the solver function" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "id": "YryhIgGB7-d3", "outputId": "905efe0d-49be-4b9e-c475-295f4051b600" }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n", "