def test_construct(self): file_handler = chaste.core.OutputFileHandler( "Python/TestMeshBasedCellPopulation") mesh_generator = chaste.mesh.HoneycombMeshGenerator(2, 2) mesh = mesh_generator.GetMesh() # Make the cells proliferative_type = chaste.cell_based.DefaultCellProliferativeType() cell_generator = chaste.cell_based.CellsGeneratorUniformCellCycleModel_2( ) cells = cell_generator.GenerateBasicRandom(mesh.GetNumNodes(), proliferative_type) # Make the cell population cell_population = chaste.cell_based.MeshBasedCellPopulation2_2( mesh, cells) cell_population.AddPopulationWriterVoronoiDataWriter() # Set up the visualizer scene = chaste.visualization.VtkScene2() scene.SetCellPopulation(cell_population) scene.SetSaveAsAnimation(True) scene.SetOutputFilePath(file_handler.GetOutputDirectoryFullPath() + "/cell_population") modifier = chaste.cell_based.VtkSceneModifier2() modifier.SetVtkScene(scene) # Set up the simulation simulator = chaste.cell_based.OffLatticeSimulation2_2(cell_population) simulator.SetOutputDirectory("Python/TestMeshBasedCellPopulation") simulator.SetEndTime(5.0) simulator.SetSamplingTimestepMultiple(12) force = chaste.cell_based.GeneralisedLinearSpringForce2_2() simulator.AddForce(force) simulator.AddSimulationModifier(modifier) simulator.Solve()
def test_monolayer(self): # JUPYTER_SETUP ## Next, we generate a mutable mesh. To create a `MutableMesh`, we can use the `HoneycombMeshGenerator`. ## This generates a honeycomb-shaped mesh, in which all nodes are equidistant. Here the first and second arguments define the size of the mesh - ## we have chosen a mesh that is 4 nodes (i.e. cells) wide, and 4 nodes high. chaste.core.OutputFileHandler( "Python/TestMeshBasedCellSimulationsTutorial") generator = chaste.mesh.HoneycombMeshGenerator(4, 4) mesh = generator.GetMesh() ## Having created a mesh, we now create some cells. To do this, we use the `CellsGenerator` helper class, ## which is specialized by the type of cell cycle model required (here `UniformCellCycleModel`) and the dimension. ## For a list of possible cell cycle models see subclasses of `AbstractCellCycleModel`. ## Note that some of these models will require information on the surrounding medium such as Oxygen concentration to work, ## see specific class documentation for details. We create an empty vector of cells and pass this into the method along with the mesh. ## The second argument represents the size of that the list of cells should become - one cell for each node, ## the third argument specifies the proliferative type of the cell. transit_type = chaste.cell_based.TransitCellProliferativeType() cell_generator = chaste.cell_based.CellsGeneratorUniformCellCycleModel_2( ) cells = cell_generator.GenerateBasicRandom(mesh.GetNumNodes(), transit_type) ## Now we have a mesh and a set of cells to go with it, we can create a `CellPopulation`. ## In general, this class associates a collection of cells with a mesh. For this test, because we have a `MutableMesh`, ## we use a particular type of cell population called a `MeshBasedCellPopulation`. cell_population = chaste.cell_based.MeshBasedCellPopulation2_2( mesh, cells) ## To view the results of this and the next test in Paraview it is necessary to explicitly ## generate the required .vtu files. cell_population.AddPopulationWriterVoronoiDataWriter() ## We can set up a `VtkScene` to do a quick visualization of the population before running the analysis. scene = chaste.visualization.VtkScene2() scene.SetCellPopulation(cell_population) # JUPYTER_SHOW_FIRST scene.Start() # JUPYTER_SHOW ## We then pass in the cell population into an `OffLatticeSimulation`, and set the output directory and end time. simulator = chaste.cell_based.OffLatticeSimulation2_2(cell_population) simulator.SetOutputDirectory( "Python/TestMeshBasedCellSimulationsTutorial") simulator.SetEndTime(10.0) ## For longer simulations, we may not want to output the results every time step. In this case we can use the following method, ## to print results every 12 time steps instead. As the default time step used by the simulator is 30 seconds, ## this method will cause the simulator to print results every 6 minutes (or 0.1 hours). simulator.SetSamplingTimestepMultiple(12) ## We must now create one or more force laws, which determine the mechanics of the centres of each cell in a cell population. ## For this test, we use one force law, based on the spring based model, and pass it to the `OffLatticeSimulation`. ## For a list of possible forces see subclasses of `AbstractForce`. Note that some of these forces are not compatible with mesh-based simulations, ## see the specific class documentation for details. If you try to use an incompatible class then you will receive a warning. force = chaste.cell_based.GeneralisedLinearSpringForce2_2() simulator.AddForce(force) ## Save snapshot images of the population during the simulation scene_modifier = chaste.cell_based.VtkSceneModifier2() scene_modifier.SetVtkScene(scene) scene_modifier.SetUpdateFrequency(100) simulator.AddSimulationModifier(scene_modifier) ## To run the simulation, we call `Solve()`. We can again do a quick rendering of the population at the end of the simulation scene.Start() simulator.Solve() scene.End()
def test_monolayer(self): # JUPYTER_SETUP ## The first thing we do is generate a nodes only mesh. To do this we first create a `MutableMesh` to use as a generating mesh. ## To do this we can use the `HoneycombMeshGenerator`. This generates a honeycomb-shaped mesh, in which all nodes are equidistant. ## Here the first and second arguments define the size of the mesh - we have chosen a mesh that is 2 nodes (i.e. cells) wide, and 2 nodes high. chaste.core.OutputFileHandler( "Python/TestNodeBasedCellSimulationsTutorial") generator = chaste.mesh.HoneycombMeshGenerator(2, 2) generating_mesh = generator.GetMesh() ## Once we have a MutableMesh we can generate a NodesOnlyMesh from it using the following commands. ## Note you can also generate the NodesOnlyMesh from a collection of nodes. mesh = chaste.mesh.NodesOnlyMesh2() ## To run node-based simulations you need to define a cut off length (second argument in `ConstructNodesWithoutMesh`), ## which defines the connectivity of the nodes by defining a radius of interaction. mesh.ConstructNodesWithoutMesh(generating_mesh, 1.5) ## Having created a mesh, we now create a (wrapped) vector of CellPtrs. To do this, we use the `CellsGenerator` helper class, ## which is specialized for the type of cell model required (here `UniformCellCycleModel`) and the dimension. ## We create an empty vector of cells and pass this into the method along with the mesh. ## The second argument represents the size of that the vector cells should become - one cell for each node, ## the third argument specifies the proliferative type of the cell. transit_type = chaste.cell_based.TransitCellProliferativeType() cell_generator = chaste.cell_based.CellsGeneratorUniformCellCycleModel_2( ) cells = cell_generator.GenerateBasicRandom(mesh.GetNumNodes(), transit_type) ## Now we have a mesh and a set of cells to go with it, we can create a `CellPopulation`. ## In general, this class associates a collection of cells with a mesh. For this test, ## because we have a `NodesOnlyMesh`, we use a particular type of cell population called a `NodeBasedCellPopulation`. cell_population = chaste.cell_based.NodeBasedCellPopulation2( mesh, cells) ## We can set up a `VtkScene` to do a quick visualization of the population before running the analysis. scene = chaste.visualization.VtkScene2() scene.SetCellPopulation(cell_population) # JUPYTER_SHOW_FIRST scene.Start() # JUPYTER_SHOW ## We then pass in the cell population into an `OffLatticeSimulation`, and set the output directory, output multiple and end time simulator = chaste.cell_based.OffLatticeSimulation2_2(cell_population) simulator.SetOutputDirectory( "Python/TestNodeBasedCellSimulationsTutorial") simulator.SetSamplingTimestepMultiple(100) simulator.SetEndTime(10.0) ## We now pass a force law to the simulation. force = chaste.cell_based.GeneralisedLinearSpringForce2_2() simulator.AddForce(force) ## Save snapshot images of the population during the simulation scene_modifier = chaste.cell_based.VtkSceneModifier2() scene_modifier.SetVtkScene(scene) scene_modifier.SetUpdateFrequency(100) simulator.AddSimulationModifier(scene_modifier) ## To run the simulation, we call `Solve()`. We can again do a quick rendering of the population at the end of the simulation scene.Start() simulator.Solve() scene.End() ## The next two lines are for test purposes only and are not part of this tutorial. ## If different simulation input parameters are being explored the lines should be removed. self.assertEqual(cell_population.GetNumRealCells(), 8) self.assertAlmostEqual( chaste.cell_based.SimulationTime.Instance().GetTime(), 10.0, 6)
def test_spheroid_on_sphere(self): # JUPYTER_SETUP ## In the third test we run a node-based simulation restricted to the surface of a sphere. chaste.core.OutputFileHandler( "Python/TestNodeBasedCellSimulationsRestrictedSpheroidTutorial") nodes = [] nodes.append(chaste.mesh.Node3(0, False, 0.5, 0.0, 0.0)) nodes.append(chaste.mesh.Node3(1, False, -0.5, 0.0, 0.0)) nodes.append(chaste.mesh.Node3(2, False, 0.0, 0.5, 0.0)) nodes.append(chaste.mesh.Node3(3, False, 0.0, -0.5, 0.0)) mesh = chaste.mesh.NodesOnlyMesh3() ## To run node-based simulations you need to define a cut off length (second argument in ConstructNodesWithoutMesh), ## which defines the connectivity of the nodes by defining a radius of interaction. mesh.ConstructNodesWithoutMesh(nodes, 1.5) transit_type = chaste.cell_based.TransitCellProliferativeType() cell_generator = chaste.cell_based.CellsGeneratorUniformCellCycleModel_3( ) cells = cell_generator.GenerateBasicRandom(mesh.GetNumNodes(), transit_type) cell_population = chaste.cell_based.NodeBasedCellPopulation3( mesh, cells) ## We can set up a `VtkScene` to do a quick visualization of the population before running the analysis. scene = chaste.visualization.VtkScene3() scene.SetCellPopulation(cell_population) scene.Start() # JUPYTER_SHOW simulator = chaste.cell_based.OffLatticeSimulation3_3(cell_population) simulator.SetOutputDirectory( "Python/TestNodeBasedCellSimulationsRestrictedSpheroidTutorial") simulator.SetSamplingTimestepMultiple(12) simulator.SetEndTime(10.0) ## We now pass a force law to the simulation. force = chaste.cell_based.GeneralisedLinearSpringForce3_3() simulator.AddForce(force) ## This time we create a CellPopulationBoundaryCondition and pass this to the OffLatticeSimulation. ## Here we use a SphereGeometryBoundaryCondition which restricts cells to lie on a sphere (in 3D) or circle (in 2D). ## For a list of possible boundary conditions see subclasses of AbstractCellPopulationBoundaryCondition. ## Note that some of these boundary conditions are not compatible with node-based simulations see the specific class documentation ## for details, if you try to use an incompatible class then you will receive a warning. ## First we set the centre (0,0,1) and radius of the sphere (1). centre = np.array([0.0, 0.0, 1.0]) radius = 5.0 point2 = chaste.mesh.ChastePoint3(centre) boundary_condition = chaste.cell_based.SphereGeometryBoundaryCondition3( cell_population, point2.rGetLocation(), radius) simulator.AddCellPopulationBoundaryCondition(boundary_condition) ## Save snapshot images of the population during the simulation scene_modifier = chaste.cell_based.VtkSceneModifier3() scene_modifier.SetVtkScene(scene) scene_modifier.SetUpdateFrequency(100) simulator.AddSimulationModifier(scene_modifier) ## To run the simulation, we call `Solve()`. We can again do a quick rendering of the population at the end of the simulation scene.Start() simulator.Solve() scene.End() ## The next two lines are for test purposes only and are not part of this tutorial. ## If different simulation input parameters are being explored the lines should be removed. self.assertEqual(cell_population.GetNumRealCells(), 8) self.assertAlmostEqual( chaste.cell_based.SimulationTime.Instance().GetTime(), 10.0, 6)
def test_spheroid(self): # JUPYTER_SETUP ## First, we generate a nodes only mesh. This time we specify the nodes manually by first creating a vector of nodes chaste.core.OutputFileHandler( "Python/TestNodeBasedCellSimulationsSpheroidTutorial") nodes = [] nodes.append(chaste.mesh.Node3(0, False, 0.5, 0.0, 0.0)) nodes.append(chaste.mesh.Node3(1, False, -0.5, 0.0, 0.0)) nodes.append(chaste.mesh.Node3(2, False, 0.0, 0.5, 0.0)) nodes.append(chaste.mesh.Node3(3, False, 0.0, -0.5, 0.0)) ## Finally a NodesOnlyMesh is created and the vector of nodes is passed to the ConstructNodesWithoutMesh method. mesh = chaste.mesh.NodesOnlyMesh3() ## To run node-based simulations you need to define a cut off length (second argument in ConstructNodesWithoutMesh), ## which defines the connectivity of the nodes by defining a radius of interaction. mesh.ConstructNodesWithoutMesh(nodes, 1.5) ## Having created a mesh, we now create a std::vector of CellPtrs. ## As before, we do this with the CellsGenerator helper class (this time with dimension 3). transit_type = chaste.cell_based.TransitCellProliferativeType() cell_generator = chaste.cell_based.CellsGeneratorUniformCellCycleModel_3( ) cells = cell_generator.GenerateBasicRandom(mesh.GetNumNodes(), transit_type) ## Now we have a mesh and a set of cells to go with it, we can create a `CellPopulation`. ## In general, this class associates a collection of cells with a mesh. For this test, ## because we have a `NodesOnlyMesh`, we use a particular type of cell population called a `NodeBasedCellPopulation`. cell_population = chaste.cell_based.NodeBasedCellPopulation3( mesh, cells) ## We can set up a `VtkScene` to do a quick visualization of the population before running the analysis. scene = chaste.visualization.VtkScene3() scene.SetCellPopulation(cell_population) scene.Start() # JUPYTER_SHOW ## We then pass in the cell population into an `OffLatticeSimulation`, and set the output directory, output multiple and end time simulator = chaste.cell_based.OffLatticeSimulation3_3(cell_population) simulator.SetOutputDirectory( "Python/TestNodeBasedCellSimulationsSpheroidTutorial") simulator.SetSamplingTimestepMultiple(12) simulator.SetEndTime(10.0) ## We now pass a force law to the simulation. force = chaste.cell_based.GeneralisedLinearSpringForce3_3() simulator.AddForce(force) ## Save snapshot images of the population during the simulation scene_modifier = chaste.cell_based.VtkSceneModifier3() scene_modifier.SetVtkScene(scene) scene_modifier.SetUpdateFrequency(100) simulator.AddSimulationModifier(scene_modifier) ## To run the simulation, we call `Solve()`. We can again do a quick rendering of the population at the end of the simulation scene.Start() simulator.Solve() scene.End() ## The next two lines are for test purposes only and are not part of this tutorial. ## If different simulation input parameters are being explored the lines should be removed. self.assertEqual(cell_population.GetNumRealCells(), 8) self.assertAlmostEqual( chaste.cell_based.SimulationTime.Instance().GetTime(), 10.0, 6)
def test_construct(self): generator = chaste.mesh.PottsMeshGenerator3(10, 0, 0, 10, 0, 0, 10, 0, 0) mesh = generator.GetMesh() self.assertEqual(mesh.GetNumNodes(), 1000)
def test_spheroid(self): # JUPYTER_SETUP ## This time we will use on off-lattice `MeshBased` cell population. Cell centres are joined with ## springs with a Delauney Triangulation used to identify neighbours. Cell area is given by the dual ## (Voronoi Tesselation). We start off with a small number of cells. We use a `MutableMesh` which ## can change connectivity over time and a `HoneycombMeshGenerator` to set it up with a simple ## honeycomb pattern. Here the first and second arguments define the size of the mesh - ## we have chosen a mesh that is 5 nodes (i.e. cells) wide, and 5 nodes high. The extra '2' argument puts ## two layers of non-cell elements around the mesh, which help to form a nicer voronoi tesselation ## for area calculations. chaste.core.OutputFileHandler("Python/TestSpheroidTutorial") generator = chaste.mesh.HoneycombMeshGenerator(5, 5) mesh = generator.GetMesh() ## We create some cells next, with a stem-like proliferative type. This means they will continually ## proliferate if there is enough oxygen, similar to how a tumour spheroid may behave. stem_type = chaste.cell_based.StemCellProliferativeType() cell_generator = chaste.cell_based.CellsGeneratorSimpleOxygenBasedCellCycleModel_2( ) cells = cell_generator.GenerateBasicRandom(mesh.GetNumNodes(), stem_type) ## Define when cells become apoptotic for eachCell in cells: cell_cycle_model = eachCell.GetCellCycleModel() eachCell.GetCellData().SetItem("oxygen", 30.0) cell_cycle_model.SetDimension(2) cell_cycle_model.SetStemCellG1Duration(4.0) cell_cycle_model.SetHypoxicConcentration(0.1) cell_cycle_model.SetQuiescentConcentration(0.3) cell_cycle_model.SetCriticalHypoxicDuration(8) g1_duration = cell_cycle_model.GetStemCellG1Duration() sg2m_duration = cell_cycle_model.GetSG2MDuration() rnum = chaste.core.RandomNumberGenerator.Instance().ranf() birth_time = -rnum * (g1_duration + sg2m_duration) eachCell.SetBirthTime(birth_time) ## Now we have a mesh and a set of cells to go with it, we can create a `CellPopulation` as before. cell_population = chaste.cell_based.MeshBasedCellPopulation2_2( mesh, cells) ## To view the results of this and the next test in Paraview it is necessary to explicitly generate the required .vtu files. cell_population.AddPopulationWriterVoronoiDataWriter() ## We then pass in the cell population into an `OffLatticeSimulation`, and set the output directory and end time. simulator = chaste.cell_based.OffLatticeSimulation2_2(cell_population) simulator.SetOutputDirectory("Python/TestSpheroidTutorial") simulator.SetEndTime(5.0) ## We ask for output every 12 increments simulator.SetSamplingTimestepMultiple(100) ## We define how the springs between cells behave using a force law. force = chaste.cell_based.GeneralisedLinearSpringForce2_2() simulator.AddForce(force) ## We set up a PDE for oxygen diffusion and consumption by cells, setting the rate of consumption to 0.1 pde = chaste.cell_based.CellwiseSourceEllipticPde2( cell_population, -0.5) ## We set a constant amount of oxygen on the edge of the spheroid bc = chaste.pde.ConstBoundaryCondition2(1.0) is_neumann_bc = False ## Set up a pde modifier to solve the PDE at each simulation time step #pde_modifier = chaste.cell_based.EllipticGrowingDomainPdeModifier2(pde, bc, is_neumann_bc) #pde_modifier.SetDependentVariableName("oxygen") #simulator.AddSimulationModifier(pde_modifier) ## As before, we set up a scene modifier for real-time visualization scene = chaste.visualization.VtkScene2() scene.SetCellPopulation(cell_population) scene.GetCellPopulationActorGenerator().SetColorByCellData(True) scene.GetCellPopulationActorGenerator().SetDataLabel("oxygen") scene.GetCellPopulationActorGenerator().SetShowCellCentres(True) scene.GetCellPopulationActorGenerator().SetShowVoronoiMeshEdges(False) # JUPYTER_SHOW_FIRST scene_modifier = chaste.cell_based.VtkSceneModifier2() scene_modifier.SetVtkScene(scene) scene_modifier.SetUpdateFrequency(100) simulator.AddSimulationModifier(scene_modifier) ## Eventually remove apoptotic cells killer = chaste.cell_based.ApoptoticCellKiller2(cell_population) simulator.AddCellKiller(killer) ## To run the simulation, we call `Solve()`. We can again do a quick rendering of the population at the end of the simulation scene.Start() simulator.Solve()