VertexCryptSimulation2d.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 #include "VertexCryptSimulation2d.hpp"
00030 #include "WntConcentration.hpp"
00031 #include "VanLeeuwen2009WntSwatCellCycleModelHypothesisOne.hpp"
00032 #include "VanLeeuwen2009WntSwatCellCycleModelHypothesisTwo.hpp"
00033 
00034 VertexCryptSimulation2d::VertexCryptSimulation2d(AbstractCellPopulation<2>& rCellPopulation,
00035                                                  bool deleteCellPopulationAndForceCollection,
00036                                                  bool initialiseCells)
00037     : CellBasedSimulation<2>(rCellPopulation,
00038                              deleteCellPopulationAndForceCollection,
00039                              initialiseCells),
00040       mUseJiggledBottomCells(false),
00041       mWriteBetaCatenin(false)
00042 {
00043     /*
00044      * To check if beta-catenin results will be written to file, we test if the first
00045      * cell has a cell cycle model that is a subclass of AbstractVanLeeuwen2009WntSwatCellCycleModel.
00046      * In doing so, we assume that all cells in the simulation have the same cell cycle
00047      * model.
00048      */
00049     if (dynamic_cast<AbstractVanLeeuwen2009WntSwatCellCycleModel*>(mrCellPopulation.Begin()->GetCellCycleModel()))
00050     {
00051         mWriteBetaCatenin = true;
00052     }
00053 }
00054 
00055 c_vector<double, 2> VertexCryptSimulation2d::CalculateCellDivisionVector(CellPtr pParentCell)
00056 {
00057     c_vector<double, 2> axis_of_division = zero_vector<double>(2);
00058 
00059     // We don't need to prescribe how 'stem' cells divide if Wnt is present
00060     bool is_wnt_included = WntConcentration<2>::Instance()->IsWntSetUp();
00061     if (!is_wnt_included)
00062     {
00063         WntConcentration<2>::Destroy();
00064         if (pParentCell->GetCellCycleModel()->GetCellProliferativeType() == STEM)
00065         {
00066             axis_of_division(0) = 1.0;
00067             axis_of_division(1) = 0.0;
00068         }
00069     }
00070     return axis_of_division;
00071 }
00072 
00073 void VertexCryptSimulation2d::WriteVisualizerSetupFile()
00074 {
00075     *mpVizSetupFile << "MeshWidth\t" << mrCellPopulation.GetWidth(0) << "\n";
00076 }
00077 
00078 void VertexCryptSimulation2d::SetupWriteBetaCatenin()
00079 {
00080     OutputFileHandler output_file_handler(this->mSimulationOutputDirectory + "/", false);
00081     mVizBetaCateninResultsFile = output_file_handler.OpenOutputFile("results.vizbetacatenin");
00082     *mpVizSetupFile << "BetaCatenin\n";
00083 }
00084 
00085 void VertexCryptSimulation2d::WriteBetaCatenin(double time)
00086 {
00087     *mVizBetaCateninResultsFile <<  time << "\t";
00088 
00089     unsigned global_index;
00090     double x;
00091     double y;
00092     double b_cat_membrane;
00093     double b_cat_cytoplasm;
00094     double b_cat_nuclear;
00095 
00096     for (AbstractCellPopulation<2>::Iterator cell_iter = mrCellPopulation.Begin();
00097          cell_iter != mrCellPopulation.End();
00098          ++cell_iter)
00099     {
00100         global_index = mrCellPopulation.GetLocationIndexUsingCell(*cell_iter);
00101         x = mrCellPopulation.GetLocationOfCellCentre(*cell_iter)[0];
00102         y = mrCellPopulation.GetLocationOfCellCentre(*cell_iter)[1];
00103 
00104         // We should only be calling this code block if mWriteBetaCatenin has been set to true in the constructor
00105         assert(mWriteBetaCatenin);
00106 
00107         AbstractVanLeeuwen2009WntSwatCellCycleModel* p_model = dynamic_cast<AbstractVanLeeuwen2009WntSwatCellCycleModel*>(cell_iter->GetCellCycleModel());
00108         b_cat_membrane = p_model->GetMembraneBoundBetaCateninLevel();
00109         b_cat_cytoplasm = p_model->GetCytoplasmicBetaCateninLevel();
00110         b_cat_nuclear = p_model->GetNuclearBetaCateninLevel();
00111 
00112         *mVizBetaCateninResultsFile << global_index << " " << x << " " << y << " " << b_cat_membrane << " " << b_cat_cytoplasm << " " << b_cat_nuclear << " ";
00113     }
00114 
00115     *mVizBetaCateninResultsFile << "\n";
00116 }
00117 
00118 void VertexCryptSimulation2d::SetupSolve()
00119 {
00120     /*
00121      * If there are any cells in the simulation, and mWriteBetaCatenin has been set to true in the constructor,
00122      * then set up the beta-catenin results file and write the initial conditions to file.
00123      */
00124     bool any_cells_present = (mrCellPopulation.Begin() != mrCellPopulation.End());
00125     if (any_cells_present && mWriteBetaCatenin)
00126     {
00127         SetupWriteBetaCatenin();
00128         double current_time = SimulationTime::Instance()->GetTime();
00129         WriteBetaCatenin(current_time);
00130     }
00131 }
00132 
00133 void VertexCryptSimulation2d::PostSolve()
00134 {
00135     SimulationTime* p_time = SimulationTime::Instance();
00136 
00137     if ((p_time->GetTimeStepsElapsed()+1)%mSamplingTimestepMultiple==0)
00138     {
00139         /*
00140          * If there are any cells in the simulation, and mWriteBetaCatenin has been set
00141          * to true in the constructor, then set up the beta-catenin results file and
00142          * write the initial conditions to file.
00143          */
00144         bool any_cells_present = (mrCellPopulation.Begin() != mrCellPopulation.End());
00145         if (any_cells_present && mWriteBetaCatenin)
00146         {
00147             double time_next_step = p_time->GetTime() + p_time->GetTimeStep();
00148             WriteBetaCatenin(time_next_step);
00149         }
00150     }
00151 }
00152 
00153 void VertexCryptSimulation2d::AfterSolve()
00154 {
00155     /*
00156      * If there are any cells in the simulation, and mWriteBetaCatenin has been set
00157      * to true in the constructor, then close the beta-catenin results file.
00158      */
00159     bool any_cells_present = (mrCellPopulation.Begin() != mrCellPopulation.End());
00160     if (any_cells_present && mWriteBetaCatenin)
00161     {
00162         mVizBetaCateninResultsFile->close();
00163     }
00164 }
00165 
00166 void VertexCryptSimulation2d::UseJiggledBottomCells()
00167 {
00168     mUseJiggledBottomCells = true;
00169 }
00170 
00171 void VertexCryptSimulation2d::ApplyCellPopulationBoundaryConditions(const std::vector< c_vector<double, 2> >& rOldLocations)
00172 {
00173     bool is_wnt_included = WntConcentration<2>::Instance()->IsWntSetUp();
00174     if (!is_wnt_included)
00175     {
00176         WntConcentration<2>::Destroy();
00177     }
00178 
00179     // Iterate over all nodes and update their positions according to the boundary conditions
00180     unsigned num_nodes = mrCellPopulation.GetNumNodes();
00181     for (unsigned node_index=0; node_index<num_nodes; node_index++)
00182     {
00183         Node<2>* p_node = mrCellPopulation.GetNode(node_index);
00184         c_vector<double, 2> old_location = rOldLocations[node_index];
00185 
00186         if (!is_wnt_included)
00187         {
00193             if (rOldLocations[node_index][1] < DBL_EPSILON)
00194             {
00195                 // Return node to its old height, but allow it to slide left or right
00196                 p_node->rGetModifiableLocation()[1] = rOldLocations[node_index][1];
00197             }
00198         }
00199 
00200         // Any node that has moved below the bottom of the crypt must be moved back up
00201         if (p_node->rGetLocation()[1] < 0.0)
00202         {
00203             p_node->rGetModifiableLocation()[1] = 0.0;
00204             if (this->mUseJiggledBottomCells)
00205             {
00206                 // Give the node a push upwards so that it doesn't get stuck on the bottom of the crypt.
00207                 p_node->rGetModifiableLocation()[1] = 0.05*mpRandomGenerator->ranf();
00208             }
00209         }
00210         assert(p_node->rGetLocation()[1] >= 0.0);
00211     }
00212 }
00213 
00214 void VertexCryptSimulation2d::SetBottomCellAncestors()
00215 {
00216     unsigned index = 0;
00217     for (AbstractCellPopulation<2>::Iterator cell_iter = mrCellPopulation.Begin();
00218          cell_iter != mrCellPopulation.End();
00219          ++cell_iter)
00220     {
00221         if (mrCellPopulation.GetLocationOfCellCentre(*cell_iter)[1] < 1.0)
00222         {
00223             cell_iter->SetAncestor(index++);
00224         }
00225     }
00226 }
00227 
00228 void VertexCryptSimulation2d::OutputSimulationParameters(out_stream& rParamsFile)
00229 {
00230     *rParamsFile << "\t\t<CryptCircumference>" << mrCellPopulation.GetWidth(0) << "</CryptCircumference>\n";
00231     *rParamsFile << "\t\t<UseJiggledBottomCells>" << mUseJiggledBottomCells << "</UseJiggledBottomCells>\n";
00232 
00233     // Call method on direct parent class
00234     CellBasedSimulation<2>::OutputSimulationParameters(rParamsFile);
00235 }
00236 
00237 // Serialization for Boost >= 1.36
00238 #include "SerializationExportWrapperForCpp.hpp"
00239 CHASTE_CLASS_EXPORT(VertexCryptSimulation2d)

Generated on Mon Nov 1 12:35:16 2010 for Chaste by  doxygen 1.5.5