Chaste  Release::3.4
CryptSimulation2d.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 "CryptSimulation2d.hpp"
37 #include "WntConcentration.hpp"
38 #include "VanLeeuwen2009WntSwatCellCycleModelHypothesisOne.hpp"
39 #include "VanLeeuwen2009WntSwatCellCycleModelHypothesisTwo.hpp"
40 #include "CellBetaCateninWriter.hpp"
41 #include "MeshBasedCellPopulation.hpp"
42 #include "SmartPointers.hpp"
43 
45  bool deleteCellPopulationInDestructor,
46  bool initialiseCells)
47  : OffLatticeSimulation<2>(rCellPopulation,
48  deleteCellPopulationInDestructor,
49  initialiseCells),
50  mUsingMeshBasedCellPopulation(false)
51 {
52  /* Throw an exception message if not using a MeshBasedCellPopulation or a VertexBasedCellPopulation.
53  * This is to catch NodeBasedCellPopulations as AbstactOnLatticeBasedCellPopulations are caught in
54  * the OffLatticeSimulation constructor.
55  */
56  if ( (dynamic_cast<VertexBasedCellPopulation<2>*>(&rCellPopulation) == NULL)
57  &&(dynamic_cast<MeshBasedCellPopulation<2>*>(&rCellPopulation) == NULL) )
58  {
59  EXCEPTION("CryptSimulation2d is to be used with MeshBasedCellPopulation or VertexBasedCellPopulation (or subclasses) only");
60  }
61 
62  if (dynamic_cast<MeshBasedCellPopulation<2>*>(&mrCellPopulation))
63  {
65  }
66 
68  {
69  // Pass a CryptSimulationBoundaryCondition object into mBoundaryConditions
70  MAKE_PTR_ARGS(CryptSimulationBoundaryCondition<2>, p_bc, (&rCellPopulation));
72  }
73 }
74 
76 {
77 }
78 
79 c_vector<double, 2> CryptSimulation2d::CalculateCellDivisionVector(CellPtr pParentCell)
80 {
82  {
83  // Location of parent and daughter cells
84  c_vector<double, 2> parent_coords = mrCellPopulation.GetLocationOfCellCentre(pParentCell);
85  c_vector<double, 2> daughter_coords;
86 
87  // Get separation parameter
88  double separation =
89  static_cast<MeshBasedCellPopulation<2>*>(&mrCellPopulation)->GetMeinekeDivisionSeparation();
90 
91  // Make a random direction vector of the required length
92  c_vector<double, 2> random_vector;
93 
94  /*
95  * Pick a random direction and move the parent cell backwards by 0.5*separation
96  * in that direction and return the position of the daughter cell 0.5*separation
97  * forwards in that direction.
98  */
99  double random_angle = RandomNumberGenerator::Instance()->ranf();
100  random_angle *= 2.0*M_PI;
101 
102  random_vector(0) = 0.5*separation*cos(random_angle);
103  random_vector(1) = 0.5*separation*sin(random_angle);
104 
105  c_vector<double, 2> proposed_new_parent_coords = parent_coords - random_vector;
106  c_vector<double, 2> proposed_new_daughter_coords = parent_coords + random_vector;
107 
108  if ((proposed_new_parent_coords(1) >= 0.0) && (proposed_new_daughter_coords(1) >= 0.0))
109  {
110  // We are not too close to the bottom of the cell population, so move parent
111  parent_coords = proposed_new_parent_coords;
112  daughter_coords = proposed_new_daughter_coords;
113  }
114  else
115  {
116  proposed_new_daughter_coords = parent_coords + 2.0*random_vector;
117  while (proposed_new_daughter_coords(1) < 0.0)
118  {
119  random_angle = RandomNumberGenerator::Instance()->ranf();
120  random_angle *= 2.0*M_PI;
121 
122  random_vector(0) = separation*cos(random_angle);
123  random_vector(1) = separation*sin(random_angle);
124  proposed_new_daughter_coords = parent_coords + random_vector;
125  }
126  daughter_coords = proposed_new_daughter_coords;
127  }
128 
129  assert(daughter_coords(1) >= 0.0); // to make sure dividing cells stay in the cell population
130  assert(parent_coords(1) >= 0.0); // to make sure dividing cells stay in the cell population
131 
132  // Set the parent to use this location
133  ChastePoint<2> parent_coords_point(parent_coords);
134 
135  unsigned node_index = mrCellPopulation.GetLocationIndexUsingCell(pParentCell);
136  mrCellPopulation.SetNode(node_index, parent_coords_point);
137 
138  return daughter_coords;
139  }
140  else // using a VertexBasedCellPopulation
141  {
142  // Let's check we're a VertexBasedCellPopulation when we're in debug mode...
143  assert(dynamic_cast<VertexBasedCellPopulation<2>*>(&(this->mrCellPopulation)));
144 
145  VertexBasedCellPopulation<2>* p_vertex_population = dynamic_cast<VertexBasedCellPopulation<2>*>(&(this->mrCellPopulation));
146  c_vector<double, 2> axis_of_division = p_vertex_population->
147  GetVertexBasedDivisionRule()->CalculateCellDivisionVector(pParentCell, *p_vertex_population);
148 
149  // We don't need to prescribe how 'stem' cells divide if Wnt is present
150  bool is_wnt_included = WntConcentration<2>::Instance()->IsWntSetUp();
151  if (!is_wnt_included)
152  {
154  if (pParentCell->GetCellProliferativeType()->IsType<StemCellProliferativeType>())
155  {
156  axis_of_division(0) = 1.0;
157  axis_of_division(1) = 0.0;
158  }
159  }
160  return axis_of_division;
161  }
162 }
163 
165 {
166  // First call method on base class
168 
169  /*
170  * To check if beta-catenin results will be written to file, we test if the first
171  * cell has a cell-cycle model that is a subclass of AbstractVanLeeuwen2009WntSwatCellCycleModel.
172  * In doing so, we assume that all cells in the simulation have the same cell-cycle
173  * model.
174  */
175  if (dynamic_cast<AbstractVanLeeuwen2009WntSwatCellCycleModel*>(this->mrCellPopulation.Begin()->GetCellCycleModel()))
176  {
177  mrCellPopulation.AddCellWriter<CellBetaCateninWriter>();
178  }
179 
180  if (dynamic_cast<AbstractVanLeeuwen2009WntSwatCellCycleModel*>(mrCellPopulation.Begin()->GetCellCycleModel()))
181  {
182  *mpVizSetupFile << "BetaCatenin\n";
183  }
184 }
185 
187 {
188  // The CryptSimulationBoundaryCondition object is the first element of mBoundaryConditions
189  boost::static_pointer_cast<CryptSimulationBoundaryCondition<2> >(mBoundaryConditions[0])->SetUseJiggledBottomCells(true);
190 }
191 
193 {
194  /*
195  * We use a different height threshold depending on which type of cell
196  * population we are using, a MeshBasedCellPopulationWithGhostNodes or
197  * a VertexBasedCellPopulation.
198  */
199  double threshold_height = 1.0;
201  {
202  threshold_height = 0.5;
203  }
204 
205  unsigned index = 0;
206  for (AbstractCellPopulation<2>::Iterator cell_iter = mrCellPopulation.Begin();
207  cell_iter != mrCellPopulation.End();
208  ++cell_iter)
209  {
210  if (mrCellPopulation.GetLocationOfCellCentre(*cell_iter)[1] < threshold_height)
211  {
212  MAKE_PTR_ARGS(CellAncestor, p_cell_ancestor, (index++));
213  cell_iter->SetAncestor(p_cell_ancestor);
214  }
215  }
216 }
217 
219 {
220  double width = mrCellPopulation.GetWidth(0);
221  bool use_jiggled_bottom_cells = boost::static_pointer_cast<CryptSimulationBoundaryCondition<2> >(mBoundaryConditions[0])->GetUseJiggledBottomCells();
222 
223  *rParamsFile << "\t\t<CryptCircumference>" << width << "</CryptCircumference>\n";
224  *rParamsFile << "\t\t<UseJiggledBottomCells>" << use_jiggled_bottom_cells << "</UseJiggledBottomCells>\n";
225 
226  // Call method on direct parent class
228 }
229 
230 // Serialization for Boost >= 1.36
static void Destroy()
#define EXCEPTION(message)
Definition: Exception.hpp:143
std::vector< boost::shared_ptr< AbstractCellPopulationBoundaryCondition< ELEMENT_DIM, ELEMENT_DIM > > > mBoundaryConditions
CryptSimulation2d(AbstractCellPopulation< 2 > &rCellPopulation, bool deleteCellPopulationInDestructor=false, bool initialiseCells=true)
static WntConcentration * Instance()
static RandomNumberGenerator * Instance()
void OutputSimulationParameters(out_stream &rParamsFile)
c_vector< double, 2 > CalculateCellDivisionVector(CellPtr pParentCell)
#define CHASTE_CLASS_EXPORT(T)
#define MAKE_PTR_ARGS(TYPE, NAME, ARGS)
virtual void OutputSimulationParameters(out_stream &rParamsFile)
void AddCellPopulationBoundaryCondition(boost::shared_ptr< AbstractCellPopulationBoundaryCondition< ELEMENT_DIM, ELEMENT_DIM > > pBoundaryCondition)
AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM > & mrCellPopulation