In this blog I will show you can configure the Dune Copasi simulation environment to perform a very simple cardiac electrophysiology simulation. I will show you how you can simulate the Mitchell-Schaeffer cardiomyocyte electrophysiology model in a 2D environment. First, I will show you how you can obtain a working version of Dune Copasi within a docker environment. Thereafter, I will introduce the electrophysiology model and how to implement it.
We will simulate the Mitchell-Schaefer model where we stimulate the bottom left corner using a Gaussian point source. This will result in the activation and repolarization of our 2D square grid. Lets get started.
Running Dune Copasi in Dockerβ
The first step is to obtain the docker image of Dune Copasi. This can simply be done by pulling it from the repository.
docker pull registry.dune-project.org/copasi/dune-copasi/dune-copasi:v2.0.1
docker tag registry.dune-project.org/copasi/dune-copasi/dune-copasi:v2.0.1 dune-copasi
We also create a working directory where we will save the simulation files.
mkdir -m o+rw workdir && cd workdir
Having fetched the docker container we are now set to test the Dune Copasi solver. To do this we will create a simple initialization file. We write the code of the minimal example to the file test.ini
:
[grid]
dimension = 2
extensions = 2 2
origin = -1 -1
refinement_level = 5
[compartments.domain]
type = expression
expression = 1
[parser_context]
diffusion.type = constant
diffusion.value = 0.005
gauss.type = function
gauss.expression = x, y, z: exp(-(x^2+y^2+z^2)/(4*diffusion)) / (4*3.14159265359*diffusion)
[model.scalar_field.u]
compartment = domain
cross_diffusion.u.expression = diffusion
initial.expression = gauss(position_x, position_y, position_z)
storage.expression = 1
[model.time_step_operator]
time_begin = 1
time_end = 4
By parsing this initialization file to the Dune Copasi solver it will exactly know how to construct the problem and the simulation will be started. This can be done by:
docker run -v $PWD:/dunecopasi dune-copasi --config=test.ini
The Dune Copasi solver will now construct the problem and start running. Once it finished you should get the message dune-copasi successfully finished :)
. You now just solved the heat equation with an initial Gaussian distribution (we did not save it though ;)). Although this example was rather simple it does nicely illustrate the use of the Dune Copasi solver. You define the problem that you want to solve in your initialization file and pass this to Dune Copasi which does all the rest! For now do not bother too much about the syntax of the initialization file, we will explain everything once we construct our electrophysiology model. However, before implementing the initialization file of our cardiac electrophysiology simulation we will describe, in the next section, the equations that we want to implement.
The mathematical model of cardiac electrophysiologyβ
The Mitchell-Schaeffer model of cell electrophysiologyβ
Cardiomyocytes maintain an ion concentration gradient between the intracellular and extracellular space. This ion concentration gradient results in a potential across the cell membrane (i.e. the transmembrane potential). A typical resting membrane potential is around . A disturbance of this resting state can result in a cardiac action potential. This is a brief change in membrane potential of heart cells resulting in a typical transmembrane potential waveform. This typical waveform is determined by the dynamics of the ion channels in the cell membrane. In the very simple Mitchell-Schaeffer model the action potential is described by 2 ion channel currents. The governing equations are given by
where and are time-scale variables, and describe the respective inward and outward current, is the normalized transmembrane potential and is a gating variable. The dynamics of the gating variable are given by
where and are time-scale variables for the gating variable and defines the critical threshold for depolarization.
The bi-domain equation of cardiac electrophysiologyβ
In the section above we described a model capturing the basic electrophysiology of cardiomyocytes. Now we want to extend this by coupling multiple cardiomyocytes yielding a spatial description of the cardiac electrophysiology. To obtain this we will depart from Ohm's law stating
In our specific case we have two compartments. We will use an intracellular and extracellular current density and potential. We obtain
Furthermore, we assume that any current leaving the intracellular space flows into the extracellular (and vice-versa) and that there is no charge accumulation. Therefore, the change in current density in the extracellular space has to be equal to the current flowing into the intracellular space. Using Gauss' law (i.e. the divergence theorem) this can be written as
The current flowing from the intracellular into the extracellular space is nothing else than the transmembrane current (per surface area). The conservation of current can be rewritten as