Chaste  Release::3.4
RandomCellKiller.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 "RandomCellKiller.hpp"
37 
38 template<unsigned DIM>
39 RandomCellKiller<DIM>::RandomCellKiller(AbstractCellPopulation<DIM>* pCellPopulation, double probabilityOfDeathInAnHour)
40  : AbstractCellKiller<DIM>(pCellPopulation),
41  mProbabilityOfDeathInAnHour(probabilityOfDeathInAnHour)
42 {
44  {
45  EXCEPTION("Probability of death must be between zero and one");
46  }
47 }
48 
49 template<unsigned DIM>
51 {
52  return mProbabilityOfDeathInAnHour;
53 }
54 
55 template<unsigned DIM>
57 {
58  /*
59  * We assume a constant time step and that there are an integer number (n = 1/dt)
60  * of time steps per hour. We also assume that this method is called every time step
61  * and that the probabilities of dying at different times are independent.
62  *
63  * Let q=mProbabilityOfDeathInAnHour and p="probability of death in a given time step".
64  *
65  * Probability of not dying in an hour:
66  * (1-q) = (1-p)^n = (1-p)^(1/dt).
67  *
68  * Rearranging for p:
69  * p = 1 - (1-q)^dt.
70  */
71  double death_prob_this_timestep = 1.0 - pow((1.0 - mProbabilityOfDeathInAnHour), SimulationTime::Instance()->GetTimeStep());
72 
73  if (!pCell->HasApoptosisBegun() &&
74  RandomNumberGenerator::Instance()->ranf() < death_prob_this_timestep)
75  {
76  pCell->StartApoptosis();
77  }
78 }
79 
80 template<unsigned DIM>
82 {
83  for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
84  cell_iter != this->mpCellPopulation->End();
85  ++cell_iter)
86  {
87  CheckAndLabelSingleCellForApoptosis(*cell_iter);
88  }
89 }
90 
91 template<unsigned DIM>
93 {
94  *rParamsFile << "\t\t\t<ProbabilityOfDeathInAnHour>" << mProbabilityOfDeathInAnHour << "</ProbabilityOfDeathInAnHour>\n";
95 
96  // Call method on direct parent class
98 }
99 
100 // Explicit instantiation
101 template class RandomCellKiller<1>;
102 template class RandomCellKiller<2>;
103 template class RandomCellKiller<3>;
104 
105 // Serialization for Boost >= 1.36
double mProbabilityOfDeathInAnHour
#define EXCEPTION(message)
Definition: Exception.hpp:143
double GetDeathProbabilityInAnHour() const
static SimulationTime * Instance()
void OutputCellKillerParameters(out_stream &rParamsFile)
RandomCellKiller(AbstractCellPopulation< DIM > *pCellPopulation, double probabilityOfDeathInAnHour)
void CheckAndLabelSingleCellForApoptosis(CellPtr pCell)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
static RandomNumberGenerator * Instance()
virtual void OutputCellKillerParameters(out_stream &rParamsFile)=0
void CheckAndLabelCellsForApoptosisOrDeath()