Welcome to the pypsdier’s documentation!¶
pypsdier is a python library to solve pde reaction-difussion equations, considering inmmobilized catalyst particles.
Try it out!¶
- In Google Colab.
- In MyBinder.
Introduction¶
Objective¶
Around 2008, we started the development of a numerical implementation of generic reaction diffusion equations for reactors using enzyme immobilization on small porous particles. The objective was (and still is) to provide a simple interface to solve reaction diffusion equations.
The immobilization of enzymes is a requisite for the re-use of these catalysts in repeated cycles in batch configuration or in continuous reactors. The recovery and/or retention of the enzyme catalyst is technical and economically feasible when micrometric or milimetric particles are used. The covalent attachment of the enzyme molecule to a porous solid support have shown high stabilization with different enzymes. Therefore, immobilization is neccessary and convenient for the efficient utilization of enzymes in technological processes and industrial settings.
Simulation of the concentrations of substrates and products is, nevertheless, harder than expected due to the complexity of the reaction and diffusion processes.
The reaction takes places then in a heterogeneous system composed by the solid catalysts particles and the bulk liquid. The catalysis process is carried out inside the particle porous instead of the bulk liquid solvent. The immediate consequence of this fact is that, along with the reaction, mass transfer occurs inside the particle and between the particle and the bulk medium. The modeling of this heterogeneous process must considers reaction and diffusion components in the reactor performance equation.
Installation¶
The repository for the code is hosted at https://github.com/sebastiandres/pypsdier.
The current implementation has been developed in Python 3. To use as a simulation engine, the libraries numpy, xlwt, scipy and matplotlib are needed.
Install from pypi¶
You can install the library from pypi. This is the safe way. Don’t stray from this path.
pip install pypsdier
Install from repository¶
You can install the library directly from the latest available version on github. This is good for testing the library, but might encounter some bugs, in which case you should let us know!
pip install git+https://github.com/sebastiandres/pypsdier.git
Examples¶
Example in Google colab¶
Here is an executable example using Google Colab. Requires a google account (but it’s worth it :).
Example in mybinder¶
Here is an executable example using MyBinder. Does not requires any account, but it will not store results.
Code example¶
To run all the next lines you need to install the library. We hope you’ll appreciate that all you need is to define the inputs and plot options, and run the simulation. Libraries and outputs are silently handled. Saving, plotting or exporting the results is trivially easy for the user.
We’ll define the simplest experiment possible.
The first thing is to setup the inputs and plotting options. This requires to define dictionaries with specific keys.
def MichaelisMenten(S, E0, k, K):
"""Definition for Michaelis Menten reaction with inputs E0 [mM], k [1/s] and K [mM]"""
return (-k*E0*S[0]/(K+S[0]), )
inputs = {}
inputs["SimulationTime"] = 120. # [s]
inputs["SavingTimeStep"] = 1. # [s]
inputs["CatalystVolume"] = 0.5 # [mL]
inputs["BulkVolume"] = 100.0 # [mL]
inputs["Names"] = ('Substrat',) # legend for the xls, reports and plots
inputs["InitialConcentrations"] = (1.3,) # [mM]
inputs["EffectiveDiffusionCoefficients"] = (5.3E-10,) # [m2/s]
inputs["CatalystParticleRadius"] = [40.0E-6, 60.0E-6, 80.0E-6] # [m]
inputs["CatalystParticleRadiusFrequency"] = [0.3, 0.5, 0.2] # []
inputs["ReactionFunction"] = MichaelisMenten # function
inputs["ReactionParameters"] = (41 , 0.13) # [1/s], [mM/s], parameters
inputs["CatalystEnzymeConcentration"] = 0.35 # [mM]
plot_options = {}
plot_options["title"] = "Michaelis Menten Reaction"
plot_options["label_x"] = "Reaction time [s]"
plot_options["label_y"] = "Concentration [mM]"
plot_options["ode_kwargs"] = {'label':'ode', 'color':'black', 'marker':'', 'markersize':6, 'linestyle':'dashed', 'linewidth':2}
plot_options["pde_kwargs"] = {'label':'pde', 'color':'black', 'marker':'', 'markersize':6, 'linestyle':'solid', 'linewidth':2}
plot_options["data_kwargs"] = {'label':'exp', 'color':'red', 'marker':'s', 'markersize':6, 'linestyle':'none', 'linewidth':2}
plot_options["data_x"] = [0.0, 30, 60, 90, 120]
plot_options["data_y"] = [1.3, 0.65, 0.25, 0.10, 0.0]
Creating a new simulation requires to use a new simulation interface.
import pypsdier
SIM = pypsdier.SimulationInterface()
SIM.new(inputs, plot_options)
To simulate you need to the corresponding method:
SIM.simulate("pde")
SIM.simulate("ode")
At any point of the code you can use the status method to know if the required libraries are installed, what are the inputs, plot options and simulation statuses.
SIM.status()
You can plot the results with the plot method. If needed, you can update the plot_options dictionary. Use plot? to know available plotting arguments.
SIM.plot()
You can generate and download a compressed simulation file, so you can late load your results
SIM.save("SIM.rde")
Or you can generate an excel file to explore the results to use a more familiar program.
SIM.export_xls("SIM.xls")
Equations¶
Variables and parameters¶
Let’s consider a substance \(S\). Let’s call:
- \(S_b(t)\): Concentration of the substance on the bulk (liquid) phase, outside all particles. The substance could be a substract or a product of the reaction. It is usually measured in mols per liter.
- \(V_b\): Total volume of the bulk (liquid) phase. Usually measured in liters.
- \(S(t,r,R_i)\): Concentration at time \(t\) and radial position \(r\), inside a particle of radius \(R_i\). Measured in the same units of \(S_b(t)\).
- \(f(R)\): Particle size distribution. Typically, this is a discrete approximation of the real (measurable but ultimately unknown) particle size distribution. For practical purposes we will consider a finite discrete distribution with \(N_R\) different particle sizes, where the probability \(p_i\) for a particle having radius \(R_i\) for \(i \in \{1, 2, \cdots, N_R \}\) with \(\sum_{i=1}^{N_R} p_i = 1\).
- \(V_R\): total volume of particles, experimentally obtained with the total weight and density of the catalyst particles. Measured in the same units as \(V_b\).
- \(D_S\): Effective diffusion coefficient of substance \(S\) inside the (porous) particle. It has the units meters squared / second.
- \(v_e\): Effective reaction rate at which the amount of substance \(S\) changes without considering diffusional restrictions. If \(v_e>0\) it is ussually called a product, while \(v_e<0\) is called a substract. This is usually measured in the units of \(S_b\) per second.
Impact of a particle distribution¶
We define \(N_R\) the number of different particle radii. A discrete particle size distribution has probability \(p_i\) for a particle having radius \(R_i\), for \(i \in \{1, 2, \cdots, N_R \}\) with \(\sum_{i=1}^{N_R} p_i = 1\). The probability \(p_i\) is interpreted in a frequentist approach: it is simply the fraction of particles of the size \(R_i\), given by \(p_i = n_i / n\) with \(n = \sum_{i=1}^{N_R} n_i\) being the total number of particles.
We can then work out explicitely the total number of particles from the total volume of the particles:
That is, the total number of particles is given by the total volume and the expected volume of a single particle.
Let’s consider a numerical example. Let’s imagine we have a total volume of \(V_R = 10 \ [m l] = 1.0\ E-8 \ [m^3]\) Let’s consider the following distribution \(p_1 = 0.4\) and \(p_2 = 0.6\), for \(R_1 = 0.9 R_0\) and \(R_2 = 1.1 R_0\), where \(R_0=6.5 \ E-9 \ [m]\) respectively.
We can compute the following values:
- The expected radius is \(E[R] = p_1 R_1 + p_2 R_2 = XxX\)
- The volume for a expected radius is \(\frac{4}{3} \pi (E[R])^3 = XxX\)
- The number of particles is \(V_R / \frac{4}{3} \pi (E[R])^3 = XxX\).
- The number of particles of size \(R_1\) and \(R_1\) are \(n_1 = p_1 n = XxX\) y \(n_1 = p_1 n = XxX\), respectively.
- The total surface is
How to model the effective reaction rate¶
The effective reaction rate \(v_e\) is a function of several terms, and occurs only inside the particles, where the catalist is attached to the surface of the porous structure. In a particle of radius \(R_i\), it would be:
Where:
- \(v(S, E, \textrm{other relevant parameters})\): the reaction rate, measured in the units of \(S_b\) per second.
- \(I(t)\): Enzime Inactivation. It only has time dependance, being bounded between 0 and 1 and decreasing: \(0 \leq I(t) \leq 1\). It has no units. It models tha catalyst inhibition growing over time.
- \(Z(r, R_i)\): Enzime radial distribution, that only has space dependance and being non-negative, \(0 < Z(r, R_i)\) and such that the total enzime applied to all particles is a known value \(E_0\):
Here we have used \(n_i\) the number of particles of size \(R_i\), and \(n\) the total number of particles, and the relationship between volume and particle size distibution:
The equations¶
The equations, boundary conditions and initial conditions are given for \(S_b(t)\) and \(S(t,r,R_i)\).
The reaction diffusion equation, for \(t>0\) and \(0<r<R_i\):
The boundary condition at the center of the particle for \(t>0\):
The boundary conditions at the surface of the particles are
and
The initial conditions are
Implementation¶
The Numerical Discretization¶
Consider the following discretization, with \(N_x\) intervals, thus having \(\Delta r_i = \frac{R_i}{N_x}\) and timestep \(\Delta t\).
Let’s define the approximations:
Consider the figure:
For each timestep \(\Delta t\), we have \(N_x+1\) unknowns in each particle size, and one unknown in the bulk phase, so the total number of unknown are \((N_x+1) N_R + 1\).
The time partial derivative can be discretized as:
The central implicit discretization for the first and second partial space derivatives are:
The one-sided discretization for the first space derivatives are:
The reaction-diffusion equation is:
The boundary condition at \(r=0\) gets discretized as
The continuity conditions at \(r=R_i\) are:
where \(\gamma_i=\frac{3 D_s V_c}{V_R E[R^3]} N_x^2 \Delta r_i\)
The initial condition at the surface of the particles are
The Numerical Implementation¶
We stack the vectors and explicitely replace \(\tilde{s}^{n}_{b} = \tilde{s}^{n}_{N_x, i}\), so the vector has size \(Nx N_R +1\). We will use the notation \(s^{n}_{j + i N_x} = \tilde{s}^{n}_{j,i}\) and \(s^{n}_{N_x N_R + 1} = s^{n}_{b}\).
For each time step, we must solve:
As the matrices are fixed (do not depend on the time variable), they can be computed and stored. A PLU factorization (Permutation Lower Upper) is computed for efficiently solve the equation in each time step.
The vectors and matrices are defined as:
Publications¶
Articles¶
List of articles related to pypsdier, from most recent to oldest.
Catalysts 2019, 9(11), 930.¶
- Title: Estimation of the effectiveness factor for immobilized enzyme catalysts through simple conversion assay.
- Authors: Valencia, P., Ibañez, F.
- Link: https://doi.org/10.3390/catal9110930
- Reproducible Computation: MyBinder , Colab.
Mathematical Methods in the Applied Sciences 2019, 42:4170-4183.¶
- Title: An inverse problem for an immobilized enzyme model.
- Authors: Gajardo, D., Mercado, A., Valencia, P.
- Link: https://doi.org/10.1002/mma.5637
- Reproducible Computation: MyBinder , Colab.
New Biotechnology 29(2), 218-226, 2012.¶
- Title: Batch reactor performance for enzymatic synthesis of cephalexin: Influence of catalyst enzyme loading and particle size.
- Authors: Valencia, P., Flores, S., Wilson, L., Illanes,
- Link: http://dx.doi.org/10.1016/j.nbt.2011.09.002
- Reproducible Computation: MyBinder , Colab.
Applied Biochemistry and Biotechnology, September 2011, Volume 165, Issue 2, pp 426-441.¶
- Title: Effect of Internal Diffusional Restrictions on the Hydrolysis of Penicillin G: Reactor Performance and Specific Productivity of 6-APA with Immobilized Penicillin Acylase.
- Authors: Pedro Valencia, Sebastián Flores, Lorena Wilson, Andrés Illanes.
- Link: http://dx.doi.org/10.1007/s12010-011-9262-7
- Reproducible Computation: MyBinder , Colab.
Journal of Biotechnology, Volume 150, Supplement, November 2010, Pages 77–78¶
- Title: Batch reactor performance for enzymatic synthesis of cephalexin: influence of catalyst enzyme loading and particle size.
- Authors: Pedro Valencia, Sebastián Flores, Lorena Wilson, Andrés Illanes.
- Link: http://dx.doi.org/10.1016/j.jbiotec.2010.08.200
- Reproducible Computation: MyBinder , Colab.
Journal of Biotechnology, Volume 150, Supplement, November 2010, Pages 388.¶
- Title: Temperature effect on heterogeneous enzyme catalyzed reaction: Thièle modulus and effectiveness factor analysis.
- Authors: Pedro Valencia, Sebastián Flores, Alik Abakarov.
- Link: http://dx.doi.org/10.1016/j.jbiotec.2010.09.491
- Reproducible Computation: MyBinder , Colab.
Biochemical Engineering Journal, Volume 49, Issue 2, 15 April 2010, Pages 256–263.¶
- Title: Effect of particle size distribution on the simulation of immobilized enzyme reactor performance.
- Authors: Pedro Valencia, Sebastián Flores, Lorena Wilson, Andrés Illanes.
- Link: http://dx.doi.org/10.1016/j.bej.2010.01.002
- Reproducible Computation: MyBinder , Colab.
List of aditional articles related to immobilized enzyme catalysts and difusional restrictions.
Biochemical Engineering Journal, Volume 91, 129-139, 2014.¶
- Title: Theoretical analysis of intrinsic reaction kinetics and the behavior of immobilized enzymas system for steady-state conditions.
- Authors: Praveen, T., Valencia, P., Rajendran, L.
- Link: http://dx.doi.org/10.1016/j.bej.2014.08.001
Enzyme and Microbial Technology, Volume 47, Issue 6, pp 268-276, 2010¶
- Title: Evaluation of the incidence of diffusional restrictions on the enzymatic reactions of hydrolysis of penicillin G and synthesis of cephalexin.
- Authors: Pedro Valencia, Lorena Wilson, Carolina Aguirre, Andrés Illanes.
- Link: http://dx.doi.org/10.1016/j.enzmictec.2010.07.010
Electronic Journal of Biotechnology, Volume 13, Issue 1, 15 January 2010, Pages 256–263.¶
- Title: Diffusional restrictions in glyoxyl-agarose immobilized penicillin G acylase of different particle size and protein loading.
- Authors: Andrés Illanes, José M. González, Juan M. Gómez, Pedro Valencia, Lorena Wilson.
- Link: http://dx.doi.org/10.2225/vol13-issue1-fulltext-12
Seminars¶
List of seminar publications, listed from most recent to oldest.
14th International Biotechnology Symposium, Rimini, Italy, September 2010.¶
- Title: Batch reactor performance for enzymatic synthesis of cephalexin: influence of catalyst enzyme loading and particle size.
- Authors: Pedro Valencia, Sebastián Flores, Lorena Wilson, Andrés Illanes.
- Link: http://www.ibs2010.org
- Reproducible Computation: MyBinder , Colab.
XXII Congreso Iberoamericano de Catálisis (CICAT), Chile, Viña del Mar, September 2010.¶
- Title: Efecto de las restricciones difusionales internas sobre la reacción de síntesis de cefalexina con penicilina acilasa inmovilizada.
- Authors: Pedro Valencia, Sebastián Flores, Lorena Wilson, Andrés Illanes.
- Link: http://www.cicat2010.cl/
- Reproducible Computation: MyBinder , Colab.
Documentation for Users¶
As a regular user of pypsdier, this is the only class and methods you should know and use.
-
class
simulation_interface.
SimulationInterface
¶ Bases:
object
GenericSimulationLibrary is a package encapsulates a methodology and tools for reproducible simulations. The main idea is to use python and/or jupyter notebooks to provide a lightweight and for-dummies easy “Simulation as a Service”. The framework puts emphasis on simplicity: for the client to install and use, for the programmer to distribute and update, and for everyone to store and reproduce results. The framework can be personalized and extended for a specific simulation need. Link: https://pypsdier.readthedocs.io/
-
download
(filename)¶ Utility to download file, using colab.
-
export_xls
(filename)¶ Creates an excel file and saves the plot data and simulation data. It helps providing a file format that final users might be more familiar with.
Parameters: filename (string) – Name for the file.
-
load
(filename)¶ Loads a simulation from a simulation file generated with the save method to restore the simulation.
Parameters: filename (string) – Name for the simulation file.
-
new
(inputs, plot_options=None)¶ Associates inputs and plot options to the simulation.
Parameters: - inputs (dict) – The inputs that will be used in the simulation. This can be completely personalized.
- plot_options (dict, optional) – The plot options, defaults to None
-
plot
(figsize=(12, 8), plot_type='all', filename='', display=True)¶ Conditionally imports the matplotlib library, and if possible, plots the experimental data given in plot_options, and the simulation data.
Parameters: - plot_type –
?
- figsize (tuple, optional) – Size of the figure
- filename (str, optional) – Filename to save the graph. If not provided, figure is not saved. Defaults to ‘’.
- display (bool, optional) – Boolean to show (True) or not show (False) the graph. Defaults to False
- plot_type –
-
save
(filename)¶ Saves the current state of the simulation, with all the provided information. The created file can be used with the load method to restore the simulation.
Parameters: filename (string) – Name for the simulation file.
-
simulate
(sim_type)¶ Function that encapsulates the numerical simulation. Stores the simulation internally.
Parameters: sim_typle – Type of simulation required. Only two options: ode or pde. Returns: Dictionary with the results of the simulation Return type: dict
-
status
()¶ Prints out the detected configuration: environment, python and library versions.
-
Acknowledgements¶
We would like to thank:
- The python ecosystem: python and a large list of libraries (numpy, scipy, matplotlib, among many others).
- The Jupyter Notebooks: the game changer in using python interactive and documentable.
- Colab and MyBinder: for making easy to share and run jupyter notebooks.
- Read the docs: for making very easy to make and share good documentation.
- This project is based on the framework proposed by GenericSimulationLibrary.
Links and References¶
Generic Simulation Library Repositories¶
This library extends the GenericSimulationLibrary framework.
Documentation for developers¶
As a developer of pypsdier, these are the other functions that you might want to understand, re-document, extend and/or improve.
pypsdier is based on the ideas of GeneralSimulationLibrary, a package encapsulates a methodology and tools for reproducible simulations.