{ "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", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#create the result plots\n", "fig = px.line(x=t, y=R) #plot time vs. R\n", "fig2=px.line(x=t, y=Y) #plot time vs. Y\n", "\n", "#Define the settings for the figures\n", "fig.update_layout(title=\"Evolution of R\",xaxis_title=\"t\",yaxis_title=\"R\",width=1000)\n", "fig2.update_layout(title=\"Evolution of Yield\",xaxis_title=\"t\",yaxis_title=\"Y (%)\", width=1000)\n", "\n", "#Display the figures\n", "fig.show()\n", "fig2.show()" ] }, { "cell_type": "markdown", "metadata": { "id": "V7lbKvna_JZ6" }, "source": [ "## **High pressure homogeniser**" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "B-GL13YXEu9g" }, "outputs": [], "source": [ "def ode_fcn_hph(n, y, k, Rm, P, a):\n", " # define parameters\n", " R = y[0]\n", "\n", " # mass balances\n", " dR_dt = k*(P**a)*(Rm-R)\n", " dy = [dR_dt]\n", " return dy\n", "\n", "def solver_hph(R_0, k ,Rm , P, a ,N):\n", " fun = lambda n, y: ode_fcn_hph(n,y,k,Rm, P, a)\n", " y0 = [R_0]\n", " N_span = np.arange(0, N+1, 1)\n", " sol = solve_ivp(fun, [N_span[0], N_span[-1]], y0, method='LSODA', t_eval=N_span, rtol=1e-6, atol=1e-6)\n", " n = sol.t.tolist()\n", " y = sol.y.T\n", " R = y[:, 0]\n", " Y = y[:,0]/Rm*100\n", "\n", " return n, R, Y\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "id": "OlXbmCHAF1CH", "outputId": "97bdcf02-30aa-4da2-c3c6-6501cc1688fa" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "\"\"\" Set Process Parameters for run generation \"\"\"\n", "R_0_hph = 0\n", "R_m_hph = 100\n", "K_hph = 5.9e-4\n", "a = 1.77 #alpha=0.9-2.9 (2.2 E. coli; 2.9 S. cerevisiae)\n", "N=10\n", "\n", "#range of P to test\n", "P = [50, 75, 100, 125]\n", "\n", "\n", "#list to store the results of the iteration\n", "all_results = []\n", "#open two figures\n", "fig_hph = make_subplots()\n", "fig2_hph = make_subplots()\n", "\n", "#iterate the solver function for all p values\n", "for p in P:\n", " n, R_hph, Y_hph = solver_hph(R_0_hph, K_hph, R_m_hph, p, a, N)\n", " all_results.append((n, R_hph, Y_hph))\n", "\n", " #add result for current P to the figures\n", " fig_hph.add_trace(go.Scatter(x=n,y=R_hph, mode='markers+lines',name=p))\n", " fig2_hph.add_trace(go.Scatter(x=n,y=Y_hph, mode='markers+lines',name=p))\n", "\n", "#Define the settings for the figures\n", "fig_hph.update_layout(showlegend=True,legend_title='Pressure', title=\"Evolution of R\",xaxis_title=\"N\",yaxis_title=\"R\",width=1000)\n", "fig2_hph.update_layout(showlegend=True,legend_title='Pressure', title=\"Evolution of Yield\",xaxis_title=\"N\",yaxis_title=\"Y (%)\",width=1000)\n", "\n", "#Display the figures\n", "fig_hph.show()\n", "fig2_hph.show()\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "3JAfgHhOH9Vp" }, "outputs": [], "source": [] } ], "metadata": { "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }