This tutorial is automatically generated from TestCellBasedDemoTutorial.hpp at revision 409e06cb314b. Note that the code is given in full at the bottom of the page.
Examples showing how to create, run and cell-based simulations in Chaste#
This tutorial is designed to give you a quick introduction to running cell-based
simulations in Chaste. Full details are postponed until later tutorials.
We begin with a simple monolayer simulation and see how to:
We begin by including the necessary header files. These will be described in detail in
subsequent cell-based tutorials.
Next, we define the test class which inherits from AbstractCellBasedTestSuite.
We inherit from AbstractCellBasedTestSuite rather than CxxTest::TestSuite directly because
this class sets up and destroys some singleton objects for us. Singletons are objects that we want to exist only
once in each simulation and will be covered in detail in later tutorials.
Since we are using AbstractCellBasedTestSuite the singleton SimulationTime is initialised to zero at the beginning of the test and destroyed at the end
of the test; RandomNumberGenerator is re-seeded with zero at the beginning and destroyed at the end of the test;
and CellPropertyRegistry (which stores CellProperties, you learn about these in a later tutorial
CreatingAndUsingANewCellProperty) is cleared at the beginning of the test.
This makes for cleaner code.
In the first test, we run a simple vertex-based simulation of an epithelial monolayer.
Each cell in the simulation is assigned a simple stochastic cell-cycle model, the cells will divide randomly and never stop proliferating.
The first thing we define is a 2D (specified by the <2,2>) mesh which holds the spatial information of the simulation. To do this we use one of a
number of MeshGenerators.
We now generate a collection of cells. We do this by using a CellsGenerator and we specify the proliferative
behaviour of the cell by choosing a CellCycleModel, here we choose a UniformG1GenerationalCellCycleModel where
each cell is given a division time, drawn from a uniform distribution when it is created.
(Note that here we need to use a phase based cell cycle model so that we can use the target area modifiers which are needed by the vertex
based simulations).
For a vertex simulation
we need as may cells as elements in the mesh.
We now create a CellPopulation object (passing in the mesh and cells) to connect the mesh and the cells together.
Here that is a VertexBasedCellPopulation and the dimension is <2>.
We now create an OffLatticeSimulation object and pass in the
CellPopulation. We also set some options on the simulation
like output directory, output multiple (so we don’t visualize every
timestep), and end time.
To specify how cells move around, we create a “shared pointer” to a
Force object and pass it to the OffLatticeSimulation. This is done using the MAKE_PTR macro as follows.
We now pass a “target area modifier” to the simulation.
This modifies the target area of individual cells and thus alters the relative forces
between neighbouring cells.
Finally we call the Solve method on the simulation to run the simulation.
The next two lines are for test purposes only and are not part of this tutorial.
We are checking that we reached the end time of the simulation
with the correct number of cells. If different simulation input parameters are being explored
the lines should be removed.
To visualize the results, open a new terminal, cd to the Chaste directory,
then cd to anim. Then do: java Visualize2dVertexCells $CHASTE_TEST_OUTPUT/CellBasedDemo1/results_from_time_0.
We may have to do: javac Visualize2dVertexCells.java beforehand to create the
java executable.
The make_a_movie script can be used to generate a video based on the results of your simulation.
To do this, first visualize the results using Visualize2dVertexCells as described above. Click
on the box marked “Output” and play through the whole simulation to generate a sequence of .png
images, one for each time step. Next, still in the anim folder, do: ./make_a_movie.
This reads in the .png files and creates a video file called simulation.mpeg.
Results can also be visualized using Paraview. See the Visualizing With Paraview tutorial for more information.
We next show how to modify the previous test to implement a ’node-based’ simulation,
in which cells are represented by overlapping spheres (actually circles, since we’re
in 2D).
We now need to create a NodesOnlyMesh we do this by first creating a MutableMesh
and passing this to a helper method ConstructNodesWithoutMesh along with a interaction cut off length
that defines the connectivity in the mesh.
We create the cells as before, only this time we need one cell per node.
This time we create a NodeBasedCellPopulation as we are using a NodesOnlyMesh.
We create an OffLatticeSimulation object as before, all we change is the output directory
and output results more often as a larger default timestep is used for these simulations.
We use a different Force which is suitable for node based simulations.
In all types of simulation you may specify how cells are removed from the simulation by specifying
a CellKiller. You create these in the same was as the Force and pass them to the CellBasedSimulation.
Note that here the constructor for RandomCellKiller requires some arguments to be passed to it, therefore we use the
MAKE_PTR_ARGS macro.
Again we call the Solve method on the simulation to run the simulation.
The next two lines are for test purposes only and are not part of this tutorial.
Again, we are checking that we reached the end time of the simulation
with the correct number of cells.
To visualize the results, open a new terminal, cd to the Chaste directory,
then cd to anim. Then do: java Visualize2dCentreCells $CHASTE_TEST_OUTPUT/CellBasedDemo2/results_from_time_0.
We may have to do: javac Visualize2dCentreCells.java beforehand to create the
java executable.
As described above, the make_a_movie script can be used to generate a video based on the results of your simulation.
We next show how to modify the previous test to implement a ‘mesh-based’ simulation,
in which cells are represented by their centres and a Voronoi tessellation is used to
find nearest neighbours.
This time we just create a MutableMesh and use that to specify the spatial locations of cells.
We create the same number of cells as the previous test.
This time we create a MeshBasedCellPopulation as we are using a MutableMesh.
To view the results of this and the subsequent mesh based tutorials in Paraview it is necessary to explicitly
generate the required .vtu files. This is detailed in the VisualizingWithParaview tutorial.
Note that the results in Paraview may appear different to those in the java based visualizer. This is related
to the different methods used to generate voronoi tesselations in each and is resolved through the use of
‘ghost nodes’, as shown in the next test.
We create an OffLatticeSimulation object as before, all we change is the output directory.
We use a different Force which is suitable for mesh based simulations.
Again we call the Solve method on the simulation to run the simulation.
The next two lines are for test purposes only and are not part of this tutorial.
The results may be visualized using Visualize2dCentreCells as described in the
previous test, with the results directory changed from CellBasedDemo2 to CellBasedDemo3.
Test 4 - basic mesh-based simulation with ghost nodes#
We next show how to modify the previous test to include ‘ghost nodes’, which do not
correspond to cells but are sometimes needed when using a Voronoi tessellation. We
will discuss ghost nodes in more detail in subsequent cell-based tutorials.
This time we just create a MutableMesh and use that to specify the spatial locations of cells.
Here we pass an extra argument to the HoneycombMeshGenerator which adds another 2 rows of
nodes round the mesh, known as ghost nodes.
We only want to create cells for non ghost nodes. To find these we get them from the HoneycombMeshGenerator
using the method GetCellLocationIndices. We also use a different CellCycleModel. Here we use a
TysonNovakCellCycleModel which solves a coupled set of ODEs for each cell to calculate when each cell divides.
This time we create a MeshBasedCellPopulation as we are using a MutableMesh and have ghost nodes.
We also need to pass the indices of non ghost nodes as an extra argument.
Again Paraview output is explicitly requested.
We create an OffLatticeSimulation object as before, all we change is the output directory and the end time.
The Tyson Novak model is for yeast cells and therefore cells proliferate much more often and so we run the simulation for
less time to keep cell numbers relatively small for this demo.
We use the same Force as before and run the simulation in the same way.
The next two lines are for test purposes only and are not part of this tutorial.
The results may be visualized using Visualize2dCentreCells as described in the
previous test, with the results directory changed from CellBasedDemo3 to CellBasedDemo4.
We next show how to modify the previous test to implement a periodic boundary to the
left and right of the domain.
We now want to impose periodic boundaries on the domain. To do this we create a Cylindrical2dMesh
using a CylindricalHoneycombMeshGenerator.
Again we create one cell for each non ghost node. Note that we have changed back to using a UniformG1GenerationalCellCycleModel.
We use the same CellPopulation, CellBasedSimulation (only changing the output directory and end time) and Force as before and run the simulation.
Again Paraview output is explicitly requested.
The next two lines are for test purposes only and are not part of this tutorial.
The results may be visualized using Visualize2dCentreCells as described in the
previous test, with the results directory changed from CellBasedDemo4 to CellBasedDemo5.
Test 6 - basic periodic mesh-based simulation with obstructions#
We next show how to modify the previous test to include one
or more ‘obstructions’ within the domain.
We make the same Mesh, Cells, CellPopulation,
CellBasedSimulation and forces as before, all we change is the output directory.
We now want to impose the condition y>0 on the cells. To do this we create a “shared pointer” to a PlaneBoundaryCondition.
Much like the RandomCellKiller earlier we pass arguments to the constructor (a point (0,0) on the plane (line in 2D) and an outward pointing normal to the plane (0,-1) ) using the MAKE_PTR_ARGS macro.
Finally we call the Solve method as in all other simulations.
The next two lines are for test purposes only and are not part of this tutorial.
The results may be visualized using Visualize2dCentreCells as described in the
previous test, with the results directory changed from CellBasedDemo5 to CellBasedDemo6.
In the final test we show how to modify the earlier tests (using off lattice models) to implement a ‘Potts-based’ simulation,
in which cells are represented by collections of sites on a fixed lattice.
In common with the off lattice simulations we begin by creating a mesh. Here we use the PottsMeshGenerator
class to generate a PottsMesh each element in the mesh is a collection of lattice sites (represented by nodes at their centres).
All the connectivity between lattice sites is defined by the PottsMeshGenerator,
and there are arguments to make the domains periodic.
We generate one cell for each element as in vertex based simulations.
As we have a PottsMesh we use a PottsBasedCellPopulation. Note here we also change the
“temperature” of the Potts simulation to make cells more motile.
As a Potts simulation is restricted to a lattice we create a OnSimulation object and pass in the CellPopulation in much the same
way as an OffLatticeSimulation in the above examples. We also set some
options on the simulation like output directory and end time.
In order to specify how cells move around we create “shared pointers” to
UpdateRule objects and pass them to the OnLatticeSimulation.
This is analogous to Forces in earlier examples.
We can add CellKillers as before.
Again we run the simulation by calling the Solve method.
The next two lines are for test purposes only and are not part of this tutorial.
To visualize the results, open a new terminal, cd to the Chaste directory,
then cd to anim. Then do: java Visualize2dVertexCells $CHASTE_TEST_OUTPUT/CellBasedDemo7/results_from_time_0.
We may have to do: javac Visualize2dVertexCells.java beforehand to create the
java executable.