Chaste  Build::
Owen11CaBasedDivisionRule.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 "Owen11CaBasedDivisionRule.hpp"
37 #include "RandomNumberGenerator.hpp"
38 #include "BaseUnits.hpp"
39 #include "CancerCellMutationState.hpp"
40 #include "QuiescentCancerCellMutationState.hpp"
41 
42 template<unsigned SPACE_DIM>
44  : AbstractCaBasedDivisionRule<SPACE_DIM>(),
45  mpVesselNetwork(),
46  mpRegularGrid(),
47  mReferenceLengthScale(BaseUnits::Instance()->GetReferenceLengthScale()),
48  mCancerCellCarryingCapacity(2)
49 {
50 }
51 
52 template<unsigned SPACE_DIM>
54 {
55 }
56 
57 template<unsigned SPACE_DIM>
59 {
60  bool is_room = false;
61 
62  if(mpVesselNetwork and SPACE_DIM>1)
63  {
64  if(!mpRegularGrid)
65  {
66  EXCEPTION("A regular grid is required for determining vessel based lattice occupancy");
67  }
68  }
69 
70  // Get node index corresponding to this cell
71  unsigned node_index = rCellPopulation.GetLocationIndexUsingCell(pParentCell);
72 
73  // Check if we can divide into self
74  unsigned num_cells_at_site = 0;
75  if(mpVesselNetwork and SPACE_DIM>1)
76  {
77  if(mpRegularGrid->IsSegmentAtLatticeSite(node_index, false))
78  {
79  num_cells_at_site = 1;
80  }
81  }
82  num_cells_at_site += rCellPopulation.GetCellsUsingLocationIndex(node_index).size();
83  if(pParentCell->GetMutationState()->IsType<CancerCellMutationState>() ||
84  pParentCell->GetMutationState()->IsType<QuiescentCancerCellMutationState>())
85  {
86  if(num_cells_at_site<mCancerCellCarryingCapacity)
87  {
88  return true;
89  }
90  }
91  else
92  {
93  if(num_cells_at_site<1)
94  {
95  return true;
96  }
97  }
98 
99  // Get the set of neighbouring node indices
100  std::set<unsigned> neighbouring_node_indices = static_cast<PottsMesh<SPACE_DIM>*>(&(rCellPopulation.rGetMesh()))->GetMooreNeighbouringNodeIndices(node_index);
101 
102  // Iterate through the neighbours to see if there are any available sites
103  for (std::set<unsigned>::iterator neighbour_iter = neighbouring_node_indices.begin();
104  neighbour_iter != neighbouring_node_indices.end();
105  ++neighbour_iter)
106  {
107  num_cells_at_site = 0;
108 
109  if(mpVesselNetwork and SPACE_DIM>1)
110  {
111  if(mpRegularGrid->IsSegmentAtLatticeSite(*neighbour_iter, false))
112  {
113  num_cells_at_site = 1;
114  }
115  }
116 
117  num_cells_at_site += rCellPopulation.GetCellsUsingLocationIndex(*neighbour_iter).size();
118  if(pParentCell->GetMutationState()->IsType<CancerCellMutationState>() ||
119  pParentCell->GetMutationState()->IsType<QuiescentCancerCellMutationState>())
120  {
121  if(num_cells_at_site<mCancerCellCarryingCapacity)
122  {
123  return true;
124  }
125  }
126  else
127  {
128  if(num_cells_at_site<1)
129  {
130  return true;
131  }
132  }
133  }
134 
135  return is_room;
136 }
137 
144 template<>
146 {
147  EXCEPTION("This division rule is not supported in 1D");
148  return false;
149 }
150 
151 template<unsigned SPACE_DIM>
153  CellPtr pParentCell,
154  CaBasedCellPopulation<SPACE_DIM>& rCellPopulation)
155 {
156  if (!IsRoomToDivide(pParentCell,rCellPopulation))
157  {
158  EXCEPTION("Trying to divide when there is no room to divide, check your division rule");
159  }
160 
161  if(mpVesselNetwork and SPACE_DIM>1)
162  {
163  if(!mpRegularGrid)
164  {
165  EXCEPTION("A regular grid is required for determining vessel based lattice occupancy");
166  }
167  }
168 
169  // Get node index corresponding to the parent cell
170  unsigned parent_node_index = rCellPopulation.GetLocationIndexUsingCell(pParentCell);
171 
172  // Check if we can divide into own location, cancer cells only
173  if(pParentCell->GetMutationState()->IsType<CancerCellMutationState>() ||
174  pParentCell->GetMutationState()->IsType<QuiescentCancerCellMutationState>())
175  {
176  unsigned num_cells_at_site = 0;
177  if(mpVesselNetwork and SPACE_DIM>1)
178  {
179  if(mpRegularGrid->IsSegmentAtLatticeSite(parent_node_index, false))
180  {
181  num_cells_at_site = 1;
182  }
183  }
184  num_cells_at_site += rCellPopulation.GetCellsUsingLocationIndex(parent_node_index).size();
185  if(num_cells_at_site<mCancerCellCarryingCapacity)
186  {
187  return parent_node_index;
188  }
189  }
190 
191  // Otherwise check neighbours
192  PottsMesh<SPACE_DIM>* static_cast_mesh = static_cast<PottsMesh<SPACE_DIM>*>(&(rCellPopulation.rGetMesh()));
193 
194  // Get the set of neighbouring node indices
195  std::set<unsigned> neighbouring_node_indices = static_cast_mesh->GetMooreNeighbouringNodeIndices(parent_node_index);
196  unsigned num_neighbours = neighbouring_node_indices.size();
197 
198  // Each node must have at least one neighbour
199  assert(!neighbouring_node_indices.empty());
200 
201  std::vector<double> neighbouring_node_propensities;
202  std::vector<unsigned> neighbouring_node_indices_vector;
203 
204  double total_propensity = 0.0;
205 
206  // Select neighbour at random
207  for (std::set<unsigned>::iterator neighbour_iter = neighbouring_node_indices.begin();
208  neighbour_iter != neighbouring_node_indices.end();
209  ++neighbour_iter)
210  {
211  neighbouring_node_indices_vector.push_back(*neighbour_iter);
212 
213  // Simplify the Owen model a little, assume division propensity is independent of oxygen
214  double propensity_dividing_into_neighbour = 0.0;
215  unsigned num_cells_at_site = 0;
216  if(mpVesselNetwork and SPACE_DIM>1)
217  {
218  if(mpRegularGrid->IsSegmentAtLatticeSite(*neighbour_iter, false))
219  {
220  num_cells_at_site = 1;
221  }
222  }
223  num_cells_at_site += rCellPopulation.GetCellsUsingLocationIndex(*neighbour_iter).size();
224  if(pParentCell->GetMutationState()->IsType<CancerCellMutationState>() ||
225  pParentCell->GetMutationState()->IsType<QuiescentCancerCellMutationState>())
226  {
227  if(num_cells_at_site<mCancerCellCarryingCapacity)
228  {
229  propensity_dividing_into_neighbour = 1.0;
230  }
231  }
232  else
233  {
234  if(num_cells_at_site<1)
235  {
236  propensity_dividing_into_neighbour = 1.0;
237  }
238  }
239 
240  neighbouring_node_propensities.push_back(propensity_dividing_into_neighbour);
241  total_propensity += propensity_dividing_into_neighbour;
242  }
243  assert(total_propensity > 0); // If this trips the cell can't divide, so we need to include this in the IsSiteAvailable() method
244 
245  for (unsigned i=0; i<num_neighbours; i++)
246  {
247  neighbouring_node_propensities[i] /= total_propensity;
248  }
249 
250  // Sample random number to specify which move to make
251  RandomNumberGenerator* p_gen = RandomNumberGenerator::Instance();
252  double random_number = p_gen->ranf();
253 
254  double total_probability = 0.0;
255  unsigned daughter_node_index = UNSIGNED_UNSET;
256 
257  unsigned counter;
258  for (counter=0; counter < num_neighbours; counter++)
259  {
260  total_probability += neighbouring_node_propensities[counter];
261  if (total_probability >= random_number)
262  {
263  // Divide the parent cell to this neighbour location
264  daughter_node_index = neighbouring_node_indices_vector[counter];
265  break;
266  }
267  }
268  // This loop should always break as sum(neighbouring_node_propensities) = 1
269 
270  assert(daughter_node_index != UNSIGNED_UNSET);
271  assert(daughter_node_index < static_cast_mesh->GetNumNodes());
272 
273  return daughter_node_index;
274 }
275 
283 template<>
285  CellPtr pParentCell,
286  CaBasedCellPopulation<1>& rCellPopulation)
287 {
288  EXCEPTION("This division rule is not supported in 1D");
289  return 0;
290 }
291 
292 template<unsigned SPACE_DIM>
294 {
295  mpVesselNetwork = pVesselNetwork;
296 }
297 
298 template<unsigned SPACE_DIM>
299 void Owen11CaBasedDivisionRule<SPACE_DIM>::SetReferenceLengthScale(units::quantity<unit::length> referenceLengthScale)
300 {
301  mReferenceLengthScale = referenceLengthScale;
302 }
303 
304 template<unsigned SPACE_DIM>
306 {
307  mpRegularGrid = pRegularGrid;
308 }
309 
310 // Explicit instantiation
311 template class Owen11CaBasedDivisionRule<2>;
312 template class Owen11CaBasedDivisionRule<3>;
313 
314 // Serialization for Boost >= 1.36
315 #include "SerializationExportWrapperForCpp.hpp"
316 EXPORT_TEMPLATE_CLASS_SAME_DIMS(Owen11CaBasedDivisionRule)
boost::shared_ptr< VesselNetwork< SPACE_DIM > > mpVesselNetwork
virtual bool IsRoomToDivide(CellPtr pParentCell, CaBasedCellPopulation< SPACE_DIM > &rCellPopulation)
void SetReferenceLengthScale(units::quantity< unit::length > referenceLengthScale)
virtual unsigned CalculateDaughterNodeIndex(CellPtr pNewCell, CellPtr pParentCell, CaBasedCellPopulation< SPACE_DIM > &rCellPopulation)
void SetVesselNetwork(boost::shared_ptr< VesselNetwork< SPACE_DIM > > pVesselNetwork)
void SetRegularGrid(boost::shared_ptr< RegularGrid< SPACE_DIM > > mpRegularGrid)
boost::shared_ptr< RegularGrid< SPACE_DIM > > mpRegularGrid
units::quantity< unit::length > mReferenceLengthScale