def test_construct(self):

        file_handler = chaste.core.OutputFileHandler(
            "Python/TestVertexBasedCellPopulation")

        # Set up the mesh
        mesh_generator = chaste.mesh.HoneycombVertexMeshGenerator(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.GetNumElements(),
                                                   proliferative_type)

        # Make the cell population
        cell_population = chaste.cell_based.VertexBasedCellPopulation2(
            mesh, cells)

        # 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)

        force = chaste.cell_based.NagaiHondaForce2()
        target_area_modifier = chaste.cell_based.SimpleTargetAreaModifier2()
        target_area_modifier.SetGrowthDuration(1.0)

        # Set up the simulation
        simulator = chaste.cell_based.OffLatticeSimulation2_2(cell_population)
        simulator.SetOutputDirectory("Python/TestVertexBasedCellPopulation")
        simulator.SetEndTime(0.2)
        simulator.AddForce(force)
        simulator.SetSamplingTimestepMultiple(200)
        simulator.AddSimulationModifier(modifier)
        simulator.AddSimulationModifier(target_area_modifier)

        simulator.Solve()
    def test_monolayer(self):

        # JUPYTER_SETUP

        ## First, we generate a vertex mesh using a HoneycombVertexMeshGenerator.

        generator = chaste.mesh.HoneycombVertexMeshGenerator(5, 15)
        mesh = generator.GetMesh()

        ## Now set up the cells, again we want to avoid proliferation.

        differentiated_type = chaste.cell_based.DifferentiatedCellProliferativeType(
        )
        cell_generator = chaste.cell_based.CellsGeneratorUniformG1GenerationalCellCycleModel_2(
        )
        cells = cell_generator.GenerateBasicRandom(mesh.GetNumElements(),
                                                   differentiated_type)

        ## Next, create the cell population

        cell_population = chaste.cell_based.VertexBasedCellPopulation2(
            mesh, cells)

        ## Pass 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/TestTensileTest")
        simulator.SetEndTime(1.0)
        simulator.SetSamplingTimestepMultiple(1000)

        ## Now create a force law

        force = chaste.cell_based.NagaiHondaForce2()
        simulator.AddForce(force)

        ## A `NagaiHondaForce` assumes that each cell has a target area. The target areas of cells are used to determine
        ## pressure forces on each vertex and eventually determine the size of each cell in the simulation.
        ## In order to assign target areas to cells and update them in each time step we add a `SimpleTargetAreaModifier`
        ## to the simulation, which inherits from `AbstractTargetAreaModifier`.

        growth_modifier = chaste.cell_based.SimpleTargetAreaModifier2()
        simulator.AddSimulationModifier(growth_modifier)

        ## For our tensile test we will fix the bottom of the sheet and subject the top to an applied displacement. We neglect
        ## fixing lateral degress of freedom for simplicity, since we are using an over-damped mechanical model.

        my_point = np.array([0.0, 0.0])
        normal = np.array([0.0, -1.0])
        bc = chaste.cell_based.AttractingPlaneBoundaryCondition2_2(
            cell_population, my_point, normal)
        simulator.AddCellPopulationBoundaryCondition(bc)
        point = np.array([0.0, 15.5])
        normal = np.array([0.0, -1.0])
        bc2 = chaste.cell_based.AttractingPlaneBoundaryCondition2_2(
            cell_population, point, normal)
        simulator.AddCellPopulationBoundaryCondition(bc2)

        ## We want to displace our top boundary over time. We could write a custom boundary condition class to do this.
        ## A more simple alternative is to modify the the position of the point describing our boundary plane in `bc2`
        ## as the simulation progresses. As per earlier tutorials we make a new `SimulationModifier` class to do this.

        class BoundaryConditionModifier(
                chaste.cell_based.PythonSimulationModifier2):
            """ Class for time varying boundary conditions
            """
            def __init__(self, boundary_condition):
                self.boundary_condition = boundary_condition
                self.original_location = boundary_condition.rGetPointOnPlane()
                self.velocity = 0.5  # cell lengths per time
                super(BoundaryConditionModifier, self).__init__()

            def UpdateAtEndOfTimeStep(self, cell_population):
                """ Move the boundary upwards at the specified velocity
                """

                total_time = chaste.cell_based.SimulationTime.Instance(
                ).GetTime()
                new_location = [
                    self.original_location[0],
                    self.original_location[1] + self.velocity * total_time
                ]
                self.boundary_condition.SetPointOnPlane(np.array(new_location))

            def SetupSolve(self, cell_population, output_directory):
                """ Make sure the cell population is in the correct state at the start of the simulation
                """

                cell_population.Update()

        bc_modifier = BoundaryConditionModifier(bc2)
        simulator.AddSimulationModifier(bc_modifier)

        ## PyChaste can do simple 3D rendering with VTK. We set up a `VtkScene` so that we can see the population
        ## evovle in real time.

        scene = chaste.visualization.VtkScene2()
        scene.SetCellPopulation(cell_population)
        # JUPYTER_SHOW_FIRST

        scene_modifier = chaste.cell_based.VtkSceneModifier2()
        scene_modifier.SetVtkScene(scene)
        scene_modifier.SetUpdateFrequency(1000)
        simulator.AddSimulationModifier(scene_modifier)

        ## To run the simulation, we call `Solve()`.

        scene.Start()
        simulator.Solve()
    def test_monolayer(self):

        # JUPYTER_SETUP

        ## First, we generate a vertex mesh. To create a MutableVertexMesh, we can use the HoneycombVertexMeshGenerator.
        ## 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 elements (i.e. cells) wide, and 2 elements high.

        chaste.core.OutputFileHandler(
            "Python/TestVertexBasedCellSimulationsTutorial")
        generator = chaste.mesh.HoneycombVertexMeshGenerator(2, 2)
        mesh = generator.GetMesh()

        ## Having created a mesh, we now create a std::vector of CellPtrs. To do this, we use the CellsGenerator helper class,
        ## which is templated over the type of cell model required
        ## 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 element,
        ## the third argument specifies the proliferative type of the cell.

        transit_type = chaste.cell_based.TransitCellProliferativeType()
        cell_generator = chaste.cell_based.CellsGeneratorUniformG1GenerationalCellCycleModel_2(
        )
        cells = cell_generator.GenerateBasicRandom(mesh.GetNumElements(),
                                                   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 MutableVertexMesh,
        ## we use a particular type of cell population called a VertexBasedCellPopulation.

        cell_population = chaste.cell_based.VertexBasedCellPopulation2(
            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/TestVertexBasedCellSimulationsTutorial")
        simulator.SetEndTime(5.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 50 time steps instead.
        ## As the default time step used by the simulator (for vertex based simulations), is 0.02 hours, this method
        ## will cause the simulator to print results every 6 minutes (i.e. 0.1 hours).

        simulator.SetSamplingTimestepMultiple(50)

        ## We must now create one or more force laws, which determine the mechanics of the vertices of each cell in a cell population.
        ## For this test, we use one force law, based on the Nagai-Honda mechanics, 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 vertex-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.NagaiHondaForce2()
        simulator.AddForce(force)

        ## A NagaiHondaForce assumes that each cell has a target area. The target areas of cells are used to determine
        ## pressure forces on each vertex and eventually determine the size of each cell in the simulation.
        ## In order to assign target areas to cells and update them in each time step we add a SimpleTargetAreaModifier
        ## to the simulation, which inherits from AbstractTargetAreaModifier.

        growth_modifier = chaste.cell_based.SimpleTargetAreaModifier2()
        simulator.AddSimulationModifier(growth_modifier)

        ## 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(), 7)
        self.assertAlmostEqual(
            chaste.cell_based.SimulationTime.Instance().GetTime(), 5.0, 6)
    def test_periodic_monolayer(self):

        # JUPYTER_SETUP

        ## First, we generate a periodic vertex mesh. To create a Cylindrical2dVertexMesh, we can use the CylindricalHoneycombVertexMeshGenerator.
        ## This generates a honeycomb-shaped mesh, in which all nodes are equidistant and the right hand side is associated with the left hand side.
        ## Here the first and second arguments define the size of the mesh - we have chosen a mesh that is
        ## 4 elements (i.e. cells) wide, and 4 elements high.

        generator = chaste.mesh.CylindricalHoneycombVertexMeshGenerator(4, 4)
        mesh = generator.GetCylindricalMesh()

        ## Having created a mesh, we now create a VectorSharedPtrCells. This is exactly the same as the above test.

        transit_type = chaste.cell_based.TransitCellProliferativeType()
        cell_generator = chaste.cell_based.CellsGeneratorUniformG1GenerationalCellCycleModel_2(
        )
        cells = cell_generator.GenerateBasicRandom(mesh.GetNumElements(),
                                                   transit_type)

        ## Now we have a mesh and a set of cells to go with it, we can create a CellPopulation. This is also the same as in the above test.

        cell_population = chaste.cell_based.VertexBasedCellPopulation2(
            mesh, cells)

        ## 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/TestPeriodicVertexBasedCellPopulation")
        simulator.SetEndTime(1.0)
        simulator.SetSamplingTimestepMultiple(50)

        ## We now make a pointer to an appropriate force and pass it to the OffLatticeSimulation.

        force = chaste.cell_based.NagaiHondaForce2()
        simulator.AddForce(force)

        ## We also make a pointer to the target area modifier and add it to the simulator.

        growth_modifier = chaste.cell_based.SimpleTargetAreaModifier2()
        simulator.AddSimulationModifier(growth_modifier)

        ## We now create one or more CellPopulationBoundaryConditions, which determine any conditions which each cell in a cell population must satisfy.
        ## For this test, we use a PlaneBoundaryCondition, and pass it to the OffLatticeSimulation. For a list of possible boundary condition
        ## see subclasses of AbstractCellPopulationBoundaryCondition.
        ## Note that some of these boundary conditions are not compatible with vertex-based simulations see the specific class documentation
        ## for details, if you try to use an incompatible class then you will receive a warning.
        ## The first step is to define a point on the plane boundary and a normal to the plane.

        point = np.array([0.0, 0.0])
        normal = np.array([0.0, -1.0])

        ## We can now make a PlaneBoundaryCondition (passing the point and normal to the plane) and pass it to the OffLatticeSimulation.
        bc = chaste.cell_based.PlaneBoundaryCondition2_2(
            cell_population, point, normal)
        simulator.AddCellPopulationBoundaryCondition(bc)

        ## We now create one or more CellKillers, which determine how cells are removed from the simulation.
        ## For this test, we use a PlaneBasedCellKiller, and pass it to the OffLatticeSimulation.
        ## For a list of possible cell killers see subclasses of AbstractCellKiller.
        ## The first step is to define a point on the plane boundary and a normal to the plane.

        point = np.array([0.0, 3.0])
        normal = np.array([0.0, 1.0])

        ## Finally we now make a PlaneBasedCellKiller (passing the point and normal to the plane) and pass it to the OffLatticeSimulation.

        killer = chaste.cell_based.PlaneBasedCellKiller2(
            cell_population, point, normal)
        simulator.AddCellKiller(killer)

        ## To run the simulation, we call `Solve()`.

        simulator.Solve()

        ## 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(), 12)
        self.assertAlmostEqual(
            chaste.cell_based.SimulationTime.Instance().GetTime(), 1.0, 6)
Пример #5
0
    def test_potts_monolayer_cell_sorting(self):

        # JUPYTER_SETUP

        ## First, we generate a `Potts` mesh. To create a `PottsMesh`, we can use the `PottsMeshGenerator`.
        ## This generates a regular square-shaped mesh, in which all elements are the same size.
        ## We have chosen an 8 by 8 block of elements each consisting of 4 by 4 ( = 16) lattice sites.

        generator = chaste.mesh.PottsMeshGenerator2(50, 8, 4, 50, 8, 4)
        mesh = generator.GetMesh()

        ## Having created a mesh, we now create some cells. To do this, we the `CellsGenerator` helper class,
        ## as before but this time the third argument is set to make all cells non-proliferative.

        differentiated_type = chaste.cell_based.DifferentiatedCellProliferativeType(
        )
        cell_generator = chaste.cell_based.CellsGeneratorUniformCellCycleModel_2(
        )
        cells = cell_generator.GenerateBasicRandom(mesh.GetNumElements(),
                                                   differentiated_type)

        ## Before we make a CellPopulation we make a cell label and then assign this label to some randomly chosen cells.

        label = chaste.cell_based.CellLabel()
        for eachCell in cells:
            if (chaste.core.RandomNumberGenerator.Instance().ranf() < 0.5):
                eachCell.AddCellProperty(label)

        ## Now we have a mesh and a set of cells to go with it, we can create a `CellPopulation`.

        cell_population = chaste.cell_based.PottsBasedCellPopulation2(
            mesh, cells)

        ## In order to visualize labelled cells we need to use the following command.

        cell_population.AddCellWriterCellLabelWriter()

        ## PyChaste can do simple 3D rendering with VTK. We set up a VtkScene so that we can
        ## see the population evovle in real time.

        scene = chaste.visualization.VtkScene2()
        scene.SetCellPopulation(cell_population)
        scene.GetCellPopulationActorGenerator().SetShowPottsMeshEdges(True)
        # 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.OnLatticeSimulation2(cell_population)
        simulator.SetOutputDirectory("Python/TestCellSorting")
        simulator.SetEndTime(20.0)
        simulator.SetSamplingTimestepMultiple(10)

        ## We must now create one or more update rules, which determine the Hamiltonian in the Potts simulation.
        ## For this test, we use two update rules based upon a volume constraint (`VolumeConstraintPottsUpdateRule`) and
        ## differential adhesion between cells (`DifferentialAdhesionPottsUpdateRule`), set appropriate parameters, and
        ## pass them to the `OnLatticeSimulation`.

        volume_constraint_update_rule = chaste.cell_based.VolumeConstraintPottsUpdateRule2(
        )
        volume_constraint_update_rule.SetMatureCellTargetVolume(16)
        volume_constraint_update_rule.SetDeformationEnergyParameter(0.2)
        simulator.AddUpdateRule(volume_constraint_update_rule)

        ## We repeat the process for any other update rules.

        differential_adhesion_update_rule = chaste.cell_based.DifferentialAdhesionPottsUpdateRule2(
        )
        differential_adhesion_update_rule.SetLabelledCellLabelledCellAdhesionEnergyParameter(
            0.16)
        differential_adhesion_update_rule.SetLabelledCellCellAdhesionEnergyParameter(
            0.11)
        differential_adhesion_update_rule.SetCellCellAdhesionEnergyParameter(
            0.02)
        differential_adhesion_update_rule.SetLabelledCellBoundaryAdhesionEnergyParameter(
            0.16)
        differential_adhesion_update_rule.SetCellBoundaryAdhesionEnergyParameter(
            0.16)
        simulator.AddUpdateRule(differential_adhesion_update_rule)

        ## Set up plotting

        scene_modifier = chaste.cell_based.VtkSceneModifier2()
        scene_modifier.SetVtkScene(scene)
        scene_modifier.SetUpdateFrequency(1000)
        simulator.AddSimulationModifier(scene_modifier)

        ## To run the simulation, we call `Solve()`.

        scene.Start()
        simulator.Solve()
Пример #6
0
    def test_monolayer(self):

        # JUPYTER_SETUP

        ## First, we generate a Potts mesh. To create a PottsMesh, we can use the PottsMeshGenerator.
        ## This generates a regular square-shaped mesh, in which all elements are the same size.
        ## Here the first three arguments specify the domain width; the number of elements across; and the width of elements.
        ## The second set of three arguments specify the domain height; the number of elements up; and the height of individual elements.
        ## We have chosen a 2 by 2 block of elements, each consisting of 4 by 4 ( = 16) lattice sites.

        chaste.core.OutputFileHandler(
            "Python/TestPottsBasedCellSimulationsTutorial")
        generator = chaste.mesh.PottsMeshGenerator2(50, 2, 4, 50, 2, 4)
        mesh = generator.GetMesh()

        ## Having created a mesh, we now create a vector of CellPtrs. To do this, we the CellsGenerator helper class,
        ## which is templated over the type of cell model required 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 element.
        ## Third argument makes all cells proliferate.

        cell_generator = chaste.cell_based.CellsGeneratorUniformCellCycleModel_2(
        )
        cells = cell_generator.GenerateBasic(mesh.GetNumElements())

        ## 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 PottsMesh,
        ## we use a particular type of cell population called a PottsBasedCellPopulation.

        cell_population = chaste.cell_based.PottsBasedCellPopulation2(
            mesh, cells)

        ## We can set the "Temperature" to be used in the Potts Simulation using the optional command below. The default value is 0.1.

        cell_population.SetTemperature(0.1)

        ## By default the Potts simulation will make 1 sweep over the whole domain per timestep.
        ## To use a different number of sweeps per timestep use the command.

        cell_population.SetNumSweepsPerTimestep(1)

        ## 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)
        scene.GetCellPopulationActorGenerator().SetShowPottsMeshEdges(True)
        # 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.OnLatticeSimulation2(cell_population)
        simulator.SetOutputDirectory(
            "Python/TestPottsBasedCellSimulationsTutorial")
        simulator.SetEndTime(50.0)

        ## The default timestep is 0.1, but can be changed using the below command. The timestep is used in conjunction with the "Temperature"
        ## and number of sweeps per timestep to specify the relationship between cell movement and proliferation.
        ## We also set the simulation to only output every 10 steps i.e. once per hour.

        simulator.SetDt(0.1)
        simulator.SetSamplingTimestepMultiple(10)

        ## We must now create one or more update rules, which determine the Hamiltonian in the Potts simulation.
        ## For this test, we use two update rules based upon a volume constraint (VolumeConstraintPottsUpdateRule)
        ## and adhesion between cells (AdhesionPottsUpdateRule) and pass them to the OnLatticeSimulation.
        ## For a list of possible update rules see subclasses of AbstractPottsUpdateRule.

        volume_constraint_update_rule = chaste.cell_based.VolumeConstraintPottsUpdateRule2(
        )

        ## Set an appropriate target volume in number of lattice sites. Here we use the default value of 16 lattice sites.

        volume_constraint_update_rule.SetMatureCellTargetVolume(16)

        ## You can also vary the deformation energy parameter.
        ## The larger the parameter the more cells will try to maintain target volume. Here we use the default value of 0.2.

        volume_constraint_update_rule.SetDeformationEnergyParameter(0.2)

        ## Finally we add the update rule to the simulator.

        simulator.AddUpdateRule(volume_constraint_update_rule)

        ## We repeat the process for any other update rules.

        adhesion_update_rule = chaste.cell_based.AdhesionPottsUpdateRule2()
        simulator.AddUpdateRule(adhesion_update_rule)

        ## 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()

        ## 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(), 41)
        self.assertAlmostEqual(
            chaste.cell_based.SimulationTime.Instance().GetTime(), 50.0, 6)
Пример #7
0
    def test_potts_spheroid_cell_sorting(self):

        # JUPYTER_SETUP

        ## First, we generate a Potts mesh. To create a PottsMesh, we can use the PottsMeshGenerator.
        ## This generates a regular square-shaped mesh, in which all elements are the same size.
        ## Here the first three arguments specify the domain width; the number of elements across; and the width of elements.
        ## The second set of three arguments specify the domain height; the number of elements up; and the height of individual elements.
        ## The third set of three arguments specify the domain depth; the number of elements deep; and the depth of individual elements.
        ## We have chosen an 4 by 4 by 4 ( = 64) block of elements each consisting of 2 by 2 by 2 ( = 8) lattice sites.

        generator = chaste.mesh.PottsMeshGenerator3(10, 4, 2, 10, 4, 2, 10, 4,
                                                    2)
        mesh = generator.GetMesh()

        ## Having created a mesh, we now create a VectorSharedPtrCells. To do this, we the CellsGenerator helper class,
        ## as before but this time the third argument is set to make all cells non-proliferative.

        differentiated_type = chaste.cell_based.DifferentiatedCellProliferativeType(
        )
        cell_generator = chaste.cell_based.CellsGeneratorUniformCellCycleModel_3(
        )
        cells = cell_generator.GenerateBasicRandom(mesh.GetNumElements(),
                                                   differentiated_type)

        ## As for the 2D case before we make a CellPopulation we make a pointer to a cell label and then assign this label to some randomly chosen cells.

        label = chaste.cell_based.CellLabel()
        for eachCell in cells:
            if (chaste.core.RandomNumberGenerator.Instance().ranf() < 0.5):
                eachCell.AddCellProperty(label)

        ## Now we have a mesh and a set of cells to go with it, we can create a CellPopulation.

        cell_population = chaste.cell_based.PottsBasedCellPopulation3(
            mesh, cells)

        ## In order to visualize labelled cells we need to use the following command.

        cell_population.AddCellWriterCellLabelWriter()

        ## We then pass in the cell population into an `OffLatticeSimulation`, and set the output directory and end time

        simulator = chaste.cell_based.OnLatticeSimulation3(cell_population)
        simulator.SetOutputDirectory("Python/TestPottsBasedCellSorting3D")
        simulator.SetEndTime(20.0)
        simulator.SetSamplingTimestepMultiple(10)

        ## We must now create one or more update rules, which determine the Hamiltonian in the Potts simulation.
        ## Now set the target volume to be appropriate for this 3D simulation.

        volume_constraint_update_rule = chaste.cell_based.VolumeConstraintPottsUpdateRule3(
        )
        volume_constraint_update_rule.SetMatureCellTargetVolume(8)
        volume_constraint_update_rule.SetDeformationEnergyParameter(0.2)
        simulator.AddUpdateRule(volume_constraint_update_rule)

        ## We use the same differential adhesion parameters as in the 2D case.

        differential_adhesion_update_rule = chaste.cell_based.DifferentialAdhesionPottsUpdateRule3(
        )
        differential_adhesion_update_rule.SetLabelledCellLabelledCellAdhesionEnergyParameter(
            0.16)
        differential_adhesion_update_rule.SetLabelledCellCellAdhesionEnergyParameter(
            0.11)
        differential_adhesion_update_rule.SetCellCellAdhesionEnergyParameter(
            0.02)
        differential_adhesion_update_rule.SetLabelledCellBoundaryAdhesionEnergyParameter(
            0.16)
        differential_adhesion_update_rule.SetCellBoundaryAdhesionEnergyParameter(
            0.16)
        simulator.AddUpdateRule(differential_adhesion_update_rule)

        ## To run the simulation, we call `Solve()`.

        simulator.Solve()

        ## 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(), 64)
        self.assertAlmostEqual(
            chaste.cell_based.SimulationTime.Instance().GetTime(), 20.0, 6)
Пример #8
0
    def test_potts_monolayer_cell_sorting(self):

        # JUPYTER_SETUP

        ## First, we generate a Potts mesh. To create a PottsMesh, we can use the PottsMeshGenerator.
        ## This generates a regular square-shaped mesh, in which all elements are the same size.
        ## We have chosen an 8 by 8 block of elements each consisting of 4 by 4 ( = 16) lattice sites.

        generator = chaste.mesh.PottsMeshGenerator2(50, 8, 4, 50, 8, 4)
        mesh = generator.GetMesh()

        ## Having created a mesh, we now create a VectorSharedPtrCells. To do this, we the CellsGenerator helper class,
        ## as before but this time the third argument is set to make all cells non-proliferative.

        differentiated_type = chaste.cell_based.DifferentiatedCellProliferativeType(
        )
        cell_generator = chaste.cell_based.CellsGeneratorUniformCellCycleModel_2(
        )
        cells = cell_generator.GenerateBasicRandom(mesh.GetNumElements(),
                                                   differentiated_type)

        ## Before we make a CellPopulation we make a cell label and then assign this label to some randomly chosen cells.

        label = chaste.cell_based.CellLabel()
        for eachCell in cells:
            if (chaste.core.RandomNumberGenerator.Instance().ranf() < 0.5):
                eachCell.AddCellProperty(label)

        ## Now we have a mesh and a set of cells to go with it, we can create a CellPopulation.

        cell_population = chaste.cell_based.PottsBasedCellPopulation2(
            mesh, cells)

        ## In order to visualize labelled cells we need to use the following command.

        cell_population.AddCellWriterCellLabelWriter()

        ## We then pass in the cell population into an `OffLatticeSimulation`, and set the output directory and end time

        simulator = chaste.cell_based.OnLatticeSimulation2(cell_population)
        simulator.SetOutputDirectory("Python/TestPottsBasedCellSorting")
        simulator.SetEndTime(20.0)
        simulator.SetSamplingTimestepMultiple(10)

        ## We must now create one or more update rules, which determine the Hamiltonian in the Potts simulation.
        ## For this test, we use two update rules based upon a volume constraint (VolumeConstraintPottsUpdateRule) and
        ## differential adhesion between cells (DifferentialAdhesionPottsUpdateRule), set appropriate parameters, and
        ## pass them to the OnLatticeSimulation.

        volume_constraint_update_rule = chaste.cell_based.VolumeConstraintPottsUpdateRule2(
        )
        volume_constraint_update_rule.SetMatureCellTargetVolume(16)
        volume_constraint_update_rule.SetDeformationEnergyParameter(0.2)
        simulator.AddUpdateRule(volume_constraint_update_rule)

        ## We repeat the process for any other update rules.

        differential_adhesion_update_rule = chaste.cell_based.DifferentialAdhesionPottsUpdateRule2(
        )
        differential_adhesion_update_rule.SetLabelledCellLabelledCellAdhesionEnergyParameter(
            0.16)
        differential_adhesion_update_rule.SetLabelledCellCellAdhesionEnergyParameter(
            0.11)
        differential_adhesion_update_rule.SetCellCellAdhesionEnergyParameter(
            0.02)
        differential_adhesion_update_rule.SetLabelledCellBoundaryAdhesionEnergyParameter(
            0.16)
        differential_adhesion_update_rule.SetCellBoundaryAdhesionEnergyParameter(
            0.16)
        simulator.AddUpdateRule(differential_adhesion_update_rule)

        ## To run the simulation, we call `Solve()`.

        simulator.Solve()

        ## 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(), 64)
        self.assertAlmostEqual(
            chaste.cell_based.SimulationTime.Instance().GetTime(), 20.0, 6)