Chaste  Build::
Owen11CellPopulationGenerator.cpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4  All rights reserved.
5 
6  University of Oxford means the Chancellor, Masters and Scholars of the
7  University of Oxford, having an administrative office at Wellington
8  Square, Oxford OX1 2JD, UK.
9 
10  This file is part of Chaste.
11 
12  Redistribution and use in source and binary forms, with or without
13  modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34  */
35 
36 #include "Owen11CellPopulationGenerator.hpp"
37 #include "BaseUnits.hpp"
38 #include "CancerCellMutationState.hpp"
39 #include "StalkCellMutationState.hpp"
40 #include "Cell.hpp"
41 #include "DefaultCellProliferativeType.hpp"
42 #include "Owen2011OxygenBasedCellCycleModel.hpp"
43 #include "VesselNetworkCellPopulationInteractor.hpp"
44 #include "CellLabelWriter.hpp"
45 #include "CellMutationStatesWriter.hpp"
46 #include "CellProliferativePhasesCountWriter.hpp"
47 #include "CellProliferativeTypesWriter.hpp"
48 #include "CellProliferativePhasesWriter.hpp"
49 #include "CellsGenerator.hpp"
50 #include "PottsMesh.hpp"
51 #include "Exception.hpp"
52 #include "Owen11CaUpdateRule.hpp"
53 #include "Owen11CaBasedDivisionRule.hpp"
54 #include "Owen11Parameters.hpp"
55 #include "Secomb04Parameters.hpp"
56 #include "GenericParameters.hpp"
57 #include "BaseUnits.hpp"
58 #include "RandomNumberGenerator.hpp"
59 
60 template<unsigned DIM>
62  mpVesselNetwork(),
63  mpRegularGrid(),
64  mpPottsMeshGenerator(),
65  mpCancerCellMutationState(boost::shared_ptr<CancerCellMutationState>(new CancerCellMutationState)),
66  mpNormalCellMutationState(),
67  mpStalkCellMutationState(boost::shared_ptr<StalkCellMutationState>(new StalkCellMutationState)),
68  mReferenceLength(BaseUnits::Instance()->GetReferenceLengthScale()),
69  mTumourRadius(0.0*unit::metres),
70  mCellPopulationReferenceLength(BaseUnits::Instance()->GetReferenceLengthScale())
71 {
72 
73 }
74 
75 template<unsigned DIM>
76 boost::shared_ptr<Owen11CellPopulationGenerator<DIM> > Owen11CellPopulationGenerator<DIM>::Create()
77 {
78  MAKE_PTR(Owen11CellPopulationGenerator<DIM>, pSelf);
79  return pSelf;
80 }
81 
82 template<unsigned DIM>
84 {
85 
86 }
87 
88 template<unsigned DIM>
90 {
91  mpVesselNetwork = pNetwork;
92 }
93 
94 template<unsigned DIM>
96 {
97  mpRegularGrid = pGrid;
98 }
99 
100 template<unsigned DIM>
101 void Owen11CellPopulationGenerator<DIM>::SetReferenceLengthScale(units::quantity<unit::length> lengthScale)
102 {
103  mReferenceLength = lengthScale;
104 }
105 
106 template<unsigned DIM>
107 void Owen11CellPopulationGenerator<DIM>::SetTumourRadius(units::quantity<unit::length> tumourRadius)
108 {
109  mTumourRadius = tumourRadius;
110 }
111 
112 template<unsigned DIM>
113 boost::shared_ptr<CaBasedCellPopulation<DIM> > Owen11CellPopulationGenerator<DIM>::Update()
114 {
115  if(!mpRegularGrid)
116  {
117  EXCEPTION("A regular grid is required to set of the cell population");
118  }
119 
120  unsigned extents_z = 1;
121  if(DIM==3)
122  {
123  extents_z = mpRegularGrid->GetExtents()[2];
124  }
125 
126  mpPottsMeshGenerator = boost::shared_ptr<PottsMeshGenerator<DIM> >(new PottsMeshGenerator<DIM>(mpRegularGrid->GetExtents()[0], 0, 0,
127  mpRegularGrid->GetExtents()[1], 0, 0,
128  extents_z, 0, 0));
129 
130  PottsMesh<DIM>* p_mesh = mpPottsMeshGenerator->GetMesh();
131 
132  // There is a bug in Chaste causing index out of bounds for large grid spacing. It may be better to use a scaling here
133  // so grid spacing is always one.
134  if(DIM==2)
135  {
136  p_mesh->Scale(mpRegularGrid->GetSpacing()/mCellPopulationReferenceLength,
138  }
139  else
140  {
141  p_mesh->Scale(mpRegularGrid->GetSpacing()/mCellPopulationReferenceLength,
144  }
145 
146  std::vector<unsigned> location_indices;
147  for (unsigned index=0; index < p_mesh->GetNumNodes(); index++)
148  {
149  location_indices.push_back(index);
150  }
151 
152  // Fill the grid with cells
153  std::vector<CellPtr> cells;
154  MAKE_PTR(DefaultCellProliferativeType, p_diff_type);
155  CellsGenerator<Owen2011OxygenBasedCellCycleModel, DIM> cells_generator;
156 
157 // MAKE_PTR(StemCellProliferativeType, p_stem_type);
158 //
159 // double oxygen_concentration = 30.0;
160 // for (unsigned i = 0; i < location_indices.size(); i++)
161 // {
162 // // Assign an oxygen based cell cycle model, which requires a dimension to be set.
163 // Owen2011OxygenBasedCellCycleModel* const p_model = new Owen2011OxygenBasedCellCycleModel;
164 // p_model->SetDimension(2);
165 // CellPtr p_cell(new Cell(p_state, p_model));
166 // p_cell->SetCellProliferativeType(p_stem_type);
167 // p_cell->SetApoptosisTime(30);
168 // cells.push_back(p_cell);
169 // p_cell->GetCellData()->SetItem("oxygen", oxygen_concentration);
170 // }
171 
172  // // Create a tumour cells in a cylinder in the middle of the domain
173  // boost::shared_ptr<Part<3> > p_tumour_cell_region = GetInitialTumourCellRegion();
174  // std::vector<unsigned> location_indices = p_tumour_cell_region->GetContainingGridIndices(num_x, num_y, num_z, spacing);
175  //
176  // std::vector<Node<3>*> nodes;
177  // for(unsigned idx=0; idx<location_indices.size(); idx++)
178  // {
179  // c_vector<double, 3> location = Grid::GetLocationOf1dIndex(location_indices[idx], num_x, num_y, spacing);
180  // nodes.push_back(new Node<3>(idx, location, false));
181  // }
182  // NodesOnlyMesh<3> mesh;
183  // mesh.ConstructNodesWithoutMesh(nodes, 1.5 * spacing);
184  // std::vector<CellPtr> cells;
185  // CellsGenerator<SimpleOxygenBasedCellCycleModel, 3> cells_generator;
186  // cells_generator.GenerateBasic(cells, mesh.GetNumNodes());
187  // NodeBasedCellPopulation<3> cell_population(mesh, cells);
188  // cell_population.SetAbsoluteMovementThreshold(2.0 * spacing);
189  // cell_population.AddCellWriter<CellLabelWriter>();
190 
191  cells_generator.GenerateBasicRandom(cells, p_mesh->GetNumNodes(), p_diff_type);
192  boost::shared_ptr<CaBasedCellPopulation<DIM> > p_cell_population =
193  boost::shared_ptr<CaBasedCellPopulation<DIM> >(new CaBasedCellPopulation<DIM> (*p_mesh, cells, location_indices, 2));
194 
195  // Label stalk cells if the is a vessel network
196  if(mpVesselNetwork)
197  {
199  interactor.SetVesselNetwork(mpVesselNetwork);
200  interactor.PartitionNetworkOverCells(*p_cell_population, mCellPopulationReferenceLength);
201 // interactor.LabelVesselsInCellPopulation(*p_cell_population, mpStalkCellMutationState, mpStalkCellMutationState);
202  }
203 
204  // Set up tumour cells in the centre of the domain
205  if(DIM==2)
206  {
207  DimensionalChastePoint<DIM> origin(double(mpRegularGrid->GetExtents()[0])*mpRegularGrid->GetSpacing()/(2.0*mReferenceLength),
208  double(mpRegularGrid->GetExtents()[1])*mpRegularGrid->GetSpacing()/(2.0*mReferenceLength),
209  0.0, mReferenceLength);
210  boost::shared_ptr<Part<DIM> > p_sub_domain = Part<DIM>::Create();
211  boost::shared_ptr<Polygon<DIM> > circle = p_sub_domain->AddCircle(mTumourRadius, origin);
212  for (unsigned ind = 0; ind < p_mesh->GetNumNodes(); ind++)
213  {
214  if (p_sub_domain->IsPointInPart(DimensionalChastePoint<DIM>(p_mesh->GetNode(ind)->rGetLocation(), mCellPopulationReferenceLength)))
215  {
216  p_cell_population->GetCellUsingLocationIndex(ind)->SetMutationState(mpCancerCellMutationState);
217  }
218  }
219  }
220  else
221  {
222  double dimensionless_spacing = mpRegularGrid->GetSpacing()/mReferenceLength;
223  c_vector<double, DIM> dimensionless_origin = mpRegularGrid->GetOrigin().GetLocation(mReferenceLength);
224 
225  DimensionalChastePoint<DIM> origin(double(mpRegularGrid->GetExtents()[0])*dimensionless_spacing/2.0 + dimensionless_origin[0],
226  double(mpRegularGrid->GetExtents()[1])*dimensionless_spacing/2.0 + dimensionless_origin[0],
227  double(mpRegularGrid->GetExtents()[2])*dimensionless_spacing/2.0 + dimensionless_origin[0],
229 
230  for(unsigned idx=0; idx<mpRegularGrid->GetNumberOfPoints(); idx++)
231  {
232  units::quantity<unit::length> distance = mpRegularGrid->GetLocationOf1dIndex(idx).GetDistance(origin);
233  if(distance<=mTumourRadius)
234  {
235  p_cell_population->GetCellUsingLocationIndex(idx)->SetMutationState(mpCancerCellMutationState);
236  }
237  }
238  }
239 
240  // Set up the cell cycle model . Note that Cell Based Chaste does not use dimensional analysis so we need to be careful with units.
241  units::quantity<unit::pressure> initial_oxygen_tension(30.0*unit::mmHg);
242  units::quantity<unit::solubility> solubility = Secomb04Parameters::mpOxygenVolumetricSolubility->GetValue("Owen11CellPopulationGenerator") *
243  GenericParameters::mpGasConcentrationAtStp->GetValue("Owen11CellPopulationGenerator");
244  units::quantity<unit::concentration> initial_oxygen_concentration = initial_oxygen_tension*solubility;
245 
246  std::list<CellPtr> cells_updated = p_cell_population->rGetCells();
247  std::list<CellPtr>::iterator it;
248  for (it = cells_updated.begin(); it != cells_updated.end(); ++it)
249  {
250  (*it)->GetCellData()->SetItem("Phi", 0.99*RandomNumberGenerator::Instance()->ranf());
251  (*it)->GetCellData()->SetItem("oxygen", initial_oxygen_concentration/BaseUnits::Instance()->GetReferenceConcentrationScale());
252  (*it)->GetCellData()->SetItem("VEGF", 0.0);
253  (*it)->GetCellData()->SetItem("p53", 0.0);
254  (*it)->GetCellData()->SetItem("Number_of_cancerous_neighbours", 0.0);
255  (*it)->GetCellData()->SetItem("Number_of_normal_neighbours", 0.0);
256 // (*it)->SetApoptosisTime(24); //hours
257  }
258 
259  // Specify an update rule
260  MAKE_PTR(Owen11CaUpdateRule<DIM>, p_update_rule);
261  p_update_rule->SetVesselNetwork(mpVesselNetwork);
262  p_update_rule->SetRegularGrid(mpRegularGrid);
263 
264  MAKE_PTR(Owen11CaBasedDivisionRule<DIM>, p_division_rule);
265  p_division_rule->SetVesselNetwork(mpVesselNetwork);
266  p_division_rule->SetRegularGrid(mpRegularGrid);
267 
268  p_cell_population->RemoveAllUpdateRules();
269  p_cell_population->AddUpdateRule(p_update_rule);
270  p_cell_population->SetCaBasedDivisionRule(p_division_rule);
271 
272  return p_cell_population;
273 }
274 
275 //template class Owen11CellPopulationGenerator<1> ;
276 template class Owen11CellPopulationGenerator<2> ;
277 template class Owen11CellPopulationGenerator<3> ;
units::quantity< unit::length > mReferenceLength
void SetRegularGrid(boost::shared_ptr< RegularGrid< DIM > > pGrid)
boost::shared_ptr< RegularGrid< DIM > > mpRegularGrid
boost::shared_ptr< AbstractCellMutationState > mpCancerCellMutationState
void SetReferenceLengthScale(units::quantity< unit::length > lengthScale)
void SetVesselNetwork(boost::shared_ptr< VesselNetwork< DIM > > pNetwork)
boost::shared_ptr< PottsMeshGenerator< DIM > > mpPottsMeshGenerator
void PartitionNetworkOverCells(AbstractCellPopulation< DIM > &rCellPopulation, units::quantity< unit::length > cellLengthScale, double threshold=1.25e-6)
boost::shared_ptr< CaBasedCellPopulation< DIM > > Update()
static const boost::shared_ptr< ParameterInstance< unit::volumetric_solubility > > mpOxygenVolumetricSolubility
static BaseUnits * Instance()
Definition: BaseUnits.cpp:53
units::quantity< unit::length > mCellPopulationReferenceLength
static boost::shared_ptr< Part< DIM > > Create()
Definition: Part.cpp:63
void SetVesselNetwork(boost::shared_ptr< VesselNetwork< DIM > > pNetwork)
boost::shared_ptr< VesselNetwork< DIM > > mpVesselNetwork
static boost::shared_ptr< Owen11CellPopulationGenerator< DIM > > Create()
units::quantity< unit::length > mTumourRadius
static const boost::shared_ptr< ParameterInstance< unit::concentration > > mpGasConcentrationAtStp
void SetTumourRadius(units::quantity< unit::length > tumourRadius)