AbstractCellPopulation.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 "AbstractCellPopulation.hpp"
00030 #include "AbstractOdeBasedCellCycleModel.hpp"
00031 #include "PetscTools.hpp"
00032 
00033 template<unsigned DIM>
00034 AbstractCellPopulation<DIM>::AbstractCellPopulation(std::vector<CellPtr>& rCells,
00035                                     const std::vector<unsigned> locationIndices)
00036     : mCells(rCells.begin(), rCells.end()),
00037       mCellPopulationContainsMesh(false),
00038       mpCellPropertyRegistry(CellPropertyRegistry::Instance()->TakeOwnership()),
00039       mDampingConstantNormal(1.0),
00040       mDampingConstantMutant(1.0),
00041       mOutputCellIdData(false),
00042       mOutputCellMutationStates(false),
00043       mOutputCellAncestors(false),
00044       mOutputCellProliferativeTypes(false),
00045       mOutputCellVariables(false),
00046       mOutputCellCyclePhases(false),
00047       mOutputCellAges(false),
00048       mOutputCellVolumes(false)
00049 {
00050     // There must be at least one cell
00051     assert(!mCells.empty());
00052 
00053     // To avoid double-counting problems, clear the passed-in cells vector
00054     rCells.clear();
00055 
00056     if (!locationIndices.empty())
00057     {
00058         // There must be a one-one correspondence between cells and location indices
00059         if (mCells.size() != locationIndices.size())
00060         {
00061             EXCEPTION("There is not a one-one correspondence between cells and location indices");
00062         }
00063     }
00064 
00065     // Set up the map between location indices and cells
00066     std::list<CellPtr>::iterator it = mCells.begin();
00067     for (unsigned i=0; it != mCells.end(); ++it, ++i)
00068     {
00069         unsigned index = locationIndices.empty() ? i : locationIndices[i]; // assume that the ordering matches
00070         mLocationCellMap[index] = *it;
00071         mCellLocationMap[(*it).get()] = index;
00072 
00073         // Give each cell a pointer to the property registry (we have taken ownership in this constructor).
00074         (*it)->rGetCellPropertyCollection().SetCellPropertyRegistry(mpCellPropertyRegistry.get());
00075     }
00076 
00077     /*
00078      * Initialise cell counts to zero.
00079      * 
00080      * Note: In its current form the code requires each cell-cycle model
00081      * to comprise four phases (G1, S, G2, M) and requires a cell to have
00082      * one of three possible proliferative types (STEM, TRANSIT and
00083      * DIFFERENTIATED). This is reflected in the explicit use of the
00084      * variables NUM_CELL_PROLIFERATIVE_TYPES and NUM_CELL_CYCLE_PHASES
00085      * below.
00086      */
00087     mCellProliferativeTypeCount = std::vector<unsigned>(NUM_CELL_PROLIFERATIVE_TYPES);
00088     for (unsigned i=0; i<mCellProliferativeTypeCount.size(); i++)
00089     {
00090         mCellProliferativeTypeCount[i] = 0;
00091     }
00092 
00093     mCellCyclePhaseCount = std::vector<unsigned>(NUM_CELL_CYCLE_PHASES);
00094     for (unsigned i=0; i<mCellCyclePhaseCount.size(); i++)
00095     {
00096         mCellCyclePhaseCount[i] = 0;
00097     }
00098 }
00099 
00100 template<unsigned DIM>
00101 AbstractCellPopulation<DIM>::~AbstractCellPopulation()
00102 {
00103 }
00104 
00105 template<unsigned DIM>
00106 void AbstractCellPopulation<DIM>::InitialiseCells()
00107 {
00108     for (typename AbstractCellPopulation<DIM>::Iterator cell_iter=this->Begin(); cell_iter!=this->End(); ++cell_iter)
00109     {
00110         cell_iter->InitialiseCellCycleModel();
00111     }
00112 }
00113 
00114 template<unsigned DIM>
00115 std::list<CellPtr>& AbstractCellPopulation<DIM>::rGetCells()
00116 {
00117     return mCells;
00118 }
00119 
00120 template<unsigned DIM>
00121 bool AbstractCellPopulation<DIM>::IsMeshBasedCellPopulation()
00122 {
00123     return mCellPopulationContainsMesh;
00124 }
00125 
00126 template<unsigned DIM>
00127 unsigned AbstractCellPopulation<DIM>::GetNumRealCells()
00128 {
00129     unsigned counter = 0;
00130     for (typename AbstractCellPopulation<DIM>::Iterator cell_iter=this->Begin(); cell_iter!=this->End(); ++cell_iter)
00131     {
00132         counter++;
00133     }
00134     return counter;
00135 }
00136 
00137 template<unsigned DIM>
00138 void AbstractCellPopulation<DIM>::SetCellAncestorsToLocationIndices()
00139 {
00140     for (typename AbstractCellPopulation<DIM>::Iterator cell_iter=this->Begin(); cell_iter!=this->End(); ++cell_iter)
00141     {
00142         cell_iter->SetAncestor(mCellLocationMap[(*cell_iter).get()]);
00143     }
00144 }
00145 
00146 template<unsigned DIM>
00147 std::set<unsigned> AbstractCellPopulation<DIM>::GetCellAncestors()
00148 {
00149     std::set<unsigned> remaining_ancestors;
00150     for (typename AbstractCellPopulation<DIM>::Iterator cell_iter=this->Begin(); cell_iter!=this->End(); ++cell_iter)
00151     {
00152         remaining_ancestors.insert(cell_iter->GetAncestor());
00153     }
00154     return remaining_ancestors;
00155 }
00156 
00157 template<unsigned DIM>
00158 std::vector<unsigned> AbstractCellPopulation<DIM>::GetCellMutationStateCount()
00159 {
00160     if (!mOutputCellMutationStates)
00161     {
00162         EXCEPTION("Call SetOutputCellMutationStates(true) before using this function");
00163     }
00164 
00165     // An ordering must have been specified for cell mutation states
00166     SetDefaultMutationStateOrdering();
00167 
00168     const std::vector<boost::shared_ptr<AbstractCellProperty> >& r_cell_properties =
00169         mpCellPropertyRegistry->rGetAllCellProperties();
00170 
00171     std::vector<unsigned> cell_mutation_state_count;
00172     for (unsigned i=0; i<r_cell_properties.size(); i++)
00173     {
00174         if (r_cell_properties[i]->IsSubType<AbstractCellMutationState>())
00175         {
00176             cell_mutation_state_count.push_back(r_cell_properties[i]->GetCellCount());
00177         }
00178     }
00179 
00180     return cell_mutation_state_count;
00181 }
00182 
00183 template<unsigned DIM>
00184 const std::vector<unsigned>& AbstractCellPopulation<DIM>::rGetCellProliferativeTypeCount() const
00185 {
00186     if (!mOutputCellProliferativeTypes)
00187     {
00188         EXCEPTION("Call SetOutputCellProliferativeTypes(true) before using this function");
00189     }
00190     return mCellProliferativeTypeCount;
00191 }
00192 
00193 template<unsigned DIM>
00194 const std::vector<unsigned>& AbstractCellPopulation<DIM>::rGetCellCyclePhaseCount() const
00195 {
00196     if (!mOutputCellCyclePhases)
00197     {
00198         EXCEPTION("Call SetOutputCellCyclePhases(true) before using this function");
00199     }
00200     return mCellCyclePhaseCount;
00201 }
00202 
00203 template<unsigned DIM>
00204 CellPtr AbstractCellPopulation<DIM>::GetCellUsingLocationIndex(unsigned index)
00205 {
00206     // Get a pointer to the cell corresponding to this location index
00207     CellPtr p_cell = mLocationCellMap[index];
00208 
00209     // Unless this pointer is null, return the cell
00210     if (p_cell)
00211     {
00212         return p_cell;
00213     }
00214     else
00215     {
00216         EXCEPTION("Location index input argument does not correspond to a Cell");
00217     }
00218 }
00219 
00220 template<unsigned DIM>
00221 unsigned AbstractCellPopulation<DIM>::GetLocationIndexUsingCell(CellPtr pCell)
00222 {
00223     return mCellLocationMap[pCell.get()];
00224 }
00225 
00226 template<unsigned DIM>
00227 boost::shared_ptr<CellPropertyRegistry> AbstractCellPopulation<DIM>::GetCellPropertyRegistry()
00228 {
00229     return mpCellPropertyRegistry;
00230 }
00231 
00232 template<unsigned DIM>
00233 void AbstractCellPopulation<DIM>::SetDefaultMutationStateOrdering()
00234 {
00235     boost::shared_ptr<CellPropertyRegistry> p_registry = GetCellPropertyRegistry();
00236     if (!p_registry->HasOrderingBeenSpecified())
00237     {
00238         std::vector<boost::shared_ptr<AbstractCellProperty> > mutations;
00239         mutations.push_back(p_registry->Get<WildTypeCellMutationState>());
00240         mutations.push_back(p_registry->Get<ApcOneHitCellMutationState>());
00241         mutations.push_back(p_registry->Get<ApcTwoHitCellMutationState>());
00242         mutations.push_back(p_registry->Get<BetaCateninOneHitCellMutationState>());
00243         p_registry->SpecifyOrdering(mutations);
00244     }
00245 }
00246 
00248 //                             Output methods                               //
00250 
00251 
00252 template<unsigned DIM>
00253 void AbstractCellPopulation<DIM>::CreateOutputFiles(const std::string& rDirectory, bool cleanOutputDirectory)
00254 {
00255     OutputFileHandler output_file_handler(rDirectory, cleanOutputDirectory);
00256     mpVizNodesFile = output_file_handler.OpenOutputFile("results.viznodes");
00257     mpVizBoundaryNodesFile = output_file_handler.OpenOutputFile("results.vizboundarynodes");
00258     mpVizCellProliferativeTypesFile = output_file_handler.OpenOutputFile("results.vizcelltypes");
00259 
00260     if (mOutputCellAncestors)
00261     {
00262         mpVizCellAncestorsFile = output_file_handler.OpenOutputFile("results.vizancestors");
00263     }
00264     if (mOutputCellMutationStates)
00265     {
00266         // An ordering must be specified for cell mutation states
00267         SetDefaultMutationStateOrdering();
00268 
00269         mpCellMutationStatesFile = output_file_handler.OpenOutputFile("cellmutationstates.dat");
00270 
00271         *mpCellMutationStatesFile << "Time\t ";
00272 
00273         const std::vector<boost::shared_ptr<AbstractCellProperty> >& r_cell_properties =
00274             mpCellPropertyRegistry->rGetAllCellProperties();
00275 
00276         std::vector<unsigned> cell_mutation_state_count;
00277         for (unsigned i=0; i<r_cell_properties.size(); i++)
00278         {
00279             if (r_cell_properties[i]->IsSubType<AbstractCellMutationState>())
00280             {
00281                 *mpCellMutationStatesFile << r_cell_properties[i]->GetIdentifier() << "\t ";
00282             }
00283         }
00284         *mpCellMutationStatesFile << "\n";
00285     }
00286     if (mOutputCellProliferativeTypes)
00287     {
00288         mpCellProliferativeTypesFile = output_file_handler.OpenOutputFile("celltypes.dat");
00289     }
00290     if (mOutputCellVariables)
00291     {
00292         mpCellVariablesFile = output_file_handler.OpenOutputFile("cellvariables.dat");
00293     }
00294     if (mOutputCellCyclePhases)
00295     {
00296         mpCellCyclePhasesFile = output_file_handler.OpenOutputFile("cellcyclephases.dat");
00297     }
00298     if (mOutputCellAges)
00299     {
00300         mpCellAgesFile = output_file_handler.OpenOutputFile("cellages.dat");
00301     }
00302     if (mOutputCellIdData)
00303     {
00304         mpCellIdFile = output_file_handler.OpenOutputFile("loggedcell.dat");
00305     }
00306 
00307     mDirPath = rDirectory;
00308 #ifdef CHASTE_VTK
00309     mpVtkMetaFile = output_file_handler.OpenOutputFile("results.pvd");
00310     *mpVtkMetaFile << "<?xml version=\"1.0\"?>\n";
00311     *mpVtkMetaFile << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\" compressor=\"vtkZLibDataCompressor\">\n";
00312     *mpVtkMetaFile << "    <Collection>\n";
00313 #endif //CHASTE_VTK
00314 }
00315 
00316 template<unsigned DIM>
00317 void AbstractCellPopulation<DIM>::CloseOutputFiles()
00318 {
00319     mpVizNodesFile->close();
00320     mpVizBoundaryNodesFile->close();
00321     mpVizCellProliferativeTypesFile->close();
00322 
00323     if (mOutputCellMutationStates)
00324     {
00325         mpCellMutationStatesFile->close();
00326     }
00327     if (mOutputCellProliferativeTypes)
00328     {
00329         mpCellProliferativeTypesFile->close();
00330     }
00331     if (mOutputCellVariables)
00332     {
00333         mpCellVariablesFile->close();
00334     }
00335     if (mOutputCellCyclePhases)
00336     {
00337         mpCellCyclePhasesFile->close();
00338     }
00339     if (mOutputCellAncestors)
00340     {
00341         mpVizCellAncestorsFile->close();
00342     }
00343     if (mOutputCellAges)
00344     {
00345         mpCellAgesFile->close();
00346     }
00347     if (mOutputCellIdData)
00348     {
00349         mpCellIdFile->close();
00350     }
00351 #ifdef CHASTE_VTK
00352     *mpVtkMetaFile << "    </Collection>\n";
00353     *mpVtkMetaFile << "</VTKFile>\n";
00354     mpVtkMetaFile->close();
00355 #endif //CHASTE_VTK
00356 }
00357 
00358 template<unsigned DIM>
00359 void AbstractCellPopulation<DIM>::GenerateCellResults(unsigned locationIndex,
00360                                               std::vector<unsigned>& rCellProliferativeTypeCounter,
00361                                               std::vector<unsigned>& rCellCyclePhaseCounter)
00362 {
00363     unsigned colour = STEM_COLOUR;
00364 
00365     CellPtr p_cell = mLocationCellMap[locationIndex];
00366 
00367     if (mOutputCellCyclePhases)
00368     {
00369         // Update rCellCyclePhaseCounter
00370         switch (p_cell->GetCellCycleModel()->GetCurrentCellCyclePhase())
00371         {
00372             case G_ZERO_PHASE:
00373                 rCellCyclePhaseCounter[0]++;
00374                 break;
00375             case G_ONE_PHASE:
00376                 rCellCyclePhaseCounter[1]++;
00377                 break;
00378             case S_PHASE:
00379                 rCellCyclePhaseCounter[2]++;
00380                 break;
00381             case G_TWO_PHASE:
00382                 rCellCyclePhaseCounter[3]++;
00383                 break;
00384              case M_PHASE:
00385                 rCellCyclePhaseCounter[4]++;
00386                 break;
00387             default:
00388                 NEVER_REACHED;
00389         }
00390     }
00391 
00392     if (mOutputCellAncestors)
00393     {
00394         // Set colour dependent on cell ancestor and write to file
00395         colour = p_cell->GetAncestor();
00396         if (colour == UNSIGNED_UNSET)
00397         {
00398             // Set the file to -1 to mark this case.
00399             colour = 1;
00400             *mpVizCellAncestorsFile << "-";
00401         }
00402         *mpVizCellAncestorsFile << colour << " ";
00403     }
00404 
00405     // Set colour dependent on cell type
00406     switch (p_cell->GetCellCycleModel()->GetCellProliferativeType())
00407     {
00408         case STEM:
00409             colour = STEM_COLOUR;
00410             if (mOutputCellProliferativeTypes)
00411             {
00412                 rCellProliferativeTypeCounter[0]++;
00413             }
00414             break;
00415         case TRANSIT:
00416             colour = TRANSIT_COLOUR;
00417             if (mOutputCellProliferativeTypes)
00418             {
00419                 rCellProliferativeTypeCounter[1]++;
00420             }
00421             break;
00422         case DIFFERENTIATED:
00423             colour = DIFFERENTIATED_COLOUR;
00424             if (mOutputCellProliferativeTypes)
00425             {
00426                 rCellProliferativeTypeCounter[2]++;
00427             }
00428             break;
00429         default:
00430             NEVER_REACHED;
00431     }
00432 
00433     if (mOutputCellMutationStates)
00434     {
00435         // Set colour dependent on cell mutation state
00436         if (!p_cell->GetMutationState()->IsType<WildTypeCellMutationState>())
00437         {
00438             colour = p_cell->GetMutationState()->GetColour();
00439         }
00440         if (p_cell->HasCellProperty<CellLabel>())
00441         {
00442             CellPropertyCollection collection = p_cell->rGetCellPropertyCollection().GetProperties<CellLabel>();
00443             boost::shared_ptr<CellLabel> p_label = boost::static_pointer_cast<CellLabel>(collection.GetProperty());
00444             colour = p_label->GetColour();
00445         }
00446     }
00447 
00448     if (p_cell->HasCellProperty<ApoptoticCellProperty>() || p_cell->HasApoptosisBegun())
00449     {
00450         // For any type of cell set the colour to this if it is undergoing apoptosis
00451         colour = APOPTOSIS_COLOUR;
00452     }
00453 
00454     // Write cell variable data to file if required
00455     if (mOutputCellVariables && dynamic_cast<AbstractOdeBasedCellCycleModel*>(p_cell->GetCellCycleModel()) )
00456     {
00457         // Write location index corresponding to cell
00458         *mpCellVariablesFile << locationIndex << " ";
00459 
00460         // Write cell variables
00461         std::vector<double> proteins = (static_cast<AbstractOdeBasedCellCycleModel*>(p_cell->GetCellCycleModel()))->GetProteinConcentrations();
00462         for (unsigned i=0; i<proteins.size(); i++)
00463         {
00464             *mpCellVariablesFile << proteins[i] << " ";
00465         }
00466     }
00467 
00468     // Write cell age data to file if required
00469     if (mOutputCellAges)
00470     {
00471         // Write location index corresponding to cell
00472         *mpCellAgesFile << locationIndex << " ";
00473 
00474         // Write cell location
00475         c_vector<double, DIM> cell_location = GetLocationOfCellCentre(p_cell);
00476 
00477         for (unsigned i=0; i<DIM; i++)
00478         {
00479             *mpCellAgesFile << cell_location[i] << " ";
00480         }
00481 
00482         // Write cell age
00483         *mpCellAgesFile << p_cell->GetAge() << " ";
00484     }
00485 
00486     *mpVizCellProliferativeTypesFile << colour << " ";
00487 }
00488 
00489 template<unsigned DIM>
00490 void AbstractCellPopulation<DIM>::WriteCellResultsToFiles(std::vector<unsigned>& rCellProliferativeTypeCounter,
00491                                                   std::vector<unsigned>& rCellCyclePhaseCounter)
00492 {
00493     *mpVizCellProliferativeTypesFile << "\n";
00494 
00495     if (mOutputCellAncestors)
00496     {
00497         *mpVizCellAncestorsFile << "\n";
00498     }
00499 
00500     // Write cell mutation state data to file if required
00501     if (mOutputCellMutationStates)
00502     {
00503         std::vector<unsigned> mutation_state_count = GetCellMutationStateCount();
00504 
00505         for (unsigned i=0; i<mutation_state_count.size(); i++)
00506         {
00507             *mpCellMutationStatesFile << mutation_state_count[i] << "\t";
00508         }
00509         *mpCellMutationStatesFile << "\n";
00510     }
00511 
00512     // Write cell type data to file if required
00513     if (mOutputCellProliferativeTypes)
00514     {
00515         for (unsigned i=0; i<mCellProliferativeTypeCount.size(); i++)
00516         {
00517             mCellProliferativeTypeCount[i] = rCellProliferativeTypeCounter[i];
00518             *mpCellProliferativeTypesFile << rCellProliferativeTypeCounter[i] << "\t";
00519         }
00520         *mpCellProliferativeTypesFile << "\n";
00521     }
00522 
00523     if (mOutputCellVariables)
00524     {
00525         *mpCellVariablesFile << "\n";
00526     }
00527 
00528     // Write cell cycle phase data to file if required
00529     if (mOutputCellCyclePhases)
00530     {
00531         for (unsigned i=0; i<mCellCyclePhaseCount.size(); i++)
00532         {
00533             mCellCyclePhaseCount[i] = rCellCyclePhaseCounter[i];
00534             *mpCellCyclePhasesFile << rCellCyclePhaseCounter[i] << "\t";
00535         }
00536         *mpCellCyclePhasesFile << "\n";
00537     }
00538 
00539     // Write cell age data to file if required
00540     if (mOutputCellAges)
00541     {
00542         *mpCellAgesFile << "\n";
00543     }
00544 }
00545 
00546 template<unsigned DIM>
00547 void AbstractCellPopulation<DIM>::WriteTimeAndNodeResultsToFiles()
00548 {
00549     double time = SimulationTime::Instance()->GetTime();
00550 
00551     *mpVizNodesFile << time << "\t";
00552     *mpVizBoundaryNodesFile << time << "\t";
00553 
00554     // Write node data to file
00555     for (unsigned node_index=0; node_index<GetNumNodes(); node_index++)
00556     {
00557         if ( !GetNode(node_index)->IsDeleted())
00558         {
00559             const c_vector<double,DIM>& position = GetNode(node_index)->rGetLocation();
00560 
00561             for (unsigned i=0; i<DIM; i++)
00562             {
00563                 *mpVizNodesFile << position[i] << " ";
00564             }
00565             *mpVizBoundaryNodesFile << GetNode(node_index)->IsBoundaryNode() << " ";
00566         }
00567     }
00568     *mpVizNodesFile << "\n";
00569     *mpVizBoundaryNodesFile << "\n";
00570 }
00571 
00572 template<unsigned DIM>
00573 void AbstractCellPopulation<DIM>::WriteResultsToFiles()
00574 {
00575     WriteTimeAndNodeResultsToFiles();
00576 
00577     double time = SimulationTime::Instance()->GetTime();
00578 
00579     *mpVizCellProliferativeTypesFile << time << "\t";
00580 
00581     if (mOutputCellAncestors)
00582     {
00583         *mpVizCellAncestorsFile << time << "\t";
00584     }
00585     if (mOutputCellMutationStates)
00586     {
00587         *mpCellMutationStatesFile << time << "\t";
00588     }
00589     if (mOutputCellProliferativeTypes)
00590     {
00591         *mpCellProliferativeTypesFile << time << "\t";
00592     }
00593     if (mOutputCellVariables)
00594     {
00595         *mpCellVariablesFile << time << "\t";
00596     }
00597     if (mOutputCellCyclePhases)
00598     {
00599         *mpCellCyclePhasesFile << time << "\t";
00600     }
00601     if (mOutputCellAges)
00602     {
00603         *mpCellAgesFile << time << "\t";
00604     }
00605 
00606     GenerateCellResultsAndWriteToFiles();
00607 
00608     // Write logged cell data if required
00609     if (mOutputCellIdData)
00610     {
00611         WriteCellIdDataToFile();
00612     }
00613 
00614     WriteVtkResultsToFile();
00615 }
00616 
00617 template<unsigned DIM>
00618 void AbstractCellPopulation<DIM>::WriteCellIdDataToFile()
00619 {
00620     // Write time to file
00621     *mpCellIdFile << SimulationTime::Instance()->GetTime();
00622 
00623     for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = Begin();
00624          cell_iter != End();
00625          ++cell_iter)
00626     {
00627         unsigned cell_id = cell_iter->GetCellId();
00628         unsigned location_index = mCellLocationMap[(*cell_iter).get()];
00629         *mpCellIdFile << " " << cell_id << " " << location_index;
00630 
00631         c_vector<double, DIM> coords = GetLocationOfCellCentre(*cell_iter);
00632         for (unsigned i=0; i<DIM; i++)
00633         {
00634             *mpCellIdFile << " " << coords[i];
00635         }
00636     }
00637     *mpCellIdFile << "\n";
00638 }
00639 
00640 template<unsigned DIM>
00641 void AbstractCellPopulation<DIM>::OutputCellPopulationInfo(out_stream& rParamsFile)
00642 {
00643     std::string cell_population_type = GetIdentifier();
00644 
00645     *rParamsFile << "\t<" << cell_population_type << ">\n";
00646     OutputCellPopulationParameters(rParamsFile);
00647     *rParamsFile << "\t</" << cell_population_type << ">\n";
00648     *rParamsFile << "\n";
00649     *rParamsFile << "\t<CellCycleModels>\n";
00650 
00651     /*
00652      * Loop over cells and generate a set of cell-cycle model classes
00653      * that are present in the population.
00654      * 
00655      * \todo this currently ignores different parameter regimes (#1453)
00656      */
00657     std::set<std::string> unique_cell_cycle_models;
00658     std::vector<CellPtr> first_cell_with_unique_CCM;
00659     for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->Begin();
00660          cell_iter != this->End();
00661          ++cell_iter)
00662     {
00663         std::string identifier = cell_iter->GetCellCycleModel()->GetIdentifier();
00664         if (unique_cell_cycle_models.count(identifier) == 0)
00665         {
00666             unique_cell_cycle_models.insert(identifier);
00667             first_cell_with_unique_CCM.push_back((*cell_iter));
00668         }
00669     }
00670 
00671     // Loop over unique cell-cycle models
00672     for (unsigned i=0; i<first_cell_with_unique_CCM.size(); i++)
00673     {
00674         // Output cell-cycle model details
00675         first_cell_with_unique_CCM[i]->GetCellCycleModel()->OutputCellCycleModelInfo(rParamsFile);
00676     }
00677 
00678     *rParamsFile << "\t</CellCycleModels>\n";
00679 }
00680 
00681 template<unsigned DIM>
00682 void AbstractCellPopulation<DIM>::OutputCellPopulationParameters(out_stream& rParamsFile)
00683 {
00684     *rParamsFile << "\t\t<DampingConstantNormal>" << mDampingConstantNormal << "</DampingConstantNormal>\n";
00685     *rParamsFile << "\t\t<DampingConstantMutant>" << mDampingConstantMutant << "</DampingConstantMutant>\n";
00686     *rParamsFile << "\t\t<OutputCellIdData>" << mOutputCellIdData << "</OutputCellIdData> \n";
00687     *rParamsFile << "\t\t<OutputCellMutationStates>" << mOutputCellMutationStates << "</OutputCellMutationStates> \n";
00688     *rParamsFile << "\t\t<OutputCellAncestors>" << mOutputCellAncestors << "</OutputCellAncestors> \n";
00689     *rParamsFile << "\t\t<OutputCellProliferativeTypes>" << mOutputCellProliferativeTypes << "</OutputCellProliferativeTypes> \n";
00690     *rParamsFile << "\t\t<OutputCellVariables>" << mOutputCellVariables << "</OutputCellVariables> \n";
00691     *rParamsFile << "\t\t<OutputCellCyclePhases>" << mOutputCellCyclePhases << "</OutputCellCyclePhases> \n";
00692     *rParamsFile << "\t\t<OutputCellAges>" << mOutputCellAges << "</OutputCellAges> \n";
00693     *rParamsFile << "\t\t<OutputCellVolumes>" << mOutputCellVolumes << "</OutputCellVolumes> \n";
00694 }
00695 
00697 // Getter methods
00699 
00700 template<unsigned DIM>
00701 double AbstractCellPopulation<DIM>::GetDampingConstantNormal()
00702 {
00703     return mDampingConstantNormal;
00704 }
00705 
00706 template<unsigned DIM>
00707 double AbstractCellPopulation<DIM>::GetDampingConstantMutant()
00708 {
00709     return mDampingConstantMutant;
00710 }
00711 
00712 template<unsigned DIM>
00713 bool AbstractCellPopulation<DIM>::GetOutputCellIdData()
00714 {
00715     return mOutputCellIdData;
00716 }
00717 
00718 template<unsigned DIM>
00719 bool AbstractCellPopulation<DIM>::GetOutputCellMutationStates()
00720 {
00721     return mOutputCellMutationStates;
00722 }
00723 
00724 template<unsigned DIM>
00725 bool AbstractCellPopulation<DIM>::GetOutputCellAncestors()
00726 {
00727     return mOutputCellAncestors;
00728 }
00729 
00730 template<unsigned DIM>
00731 bool AbstractCellPopulation<DIM>::GetOutputCellProliferativeTypes()
00732 {
00733     return mOutputCellProliferativeTypes;
00734 }
00735 
00736 template<unsigned DIM>
00737 bool AbstractCellPopulation<DIM>::GetOutputCellVariables()
00738 {
00739     return mOutputCellVariables;
00740 }
00741 
00742 template<unsigned DIM>
00743 bool AbstractCellPopulation<DIM>::GetOutputCellCyclePhases()
00744 {
00745     return mOutputCellCyclePhases;
00746 }
00747 
00748 template<unsigned DIM>
00749 bool AbstractCellPopulation<DIM>::GetOutputCellAges()
00750 {
00751     return mOutputCellAges;
00752 }
00753 
00754 template<unsigned DIM>
00755 bool AbstractCellPopulation<DIM>::GetOutputCellVolumes()
00756 {
00757     return mOutputCellVolumes;
00758 }
00759 
00761 // Setter methods
00763 
00764 template<unsigned DIM>
00765 void AbstractCellPopulation<DIM>::SetDampingConstantNormal(double dampingConstantNormal)
00766 {
00767     assert(dampingConstantNormal > 0.0);
00768     mDampingConstantNormal = dampingConstantNormal;
00769 }
00770 
00771 template<unsigned DIM>
00772 void AbstractCellPopulation<DIM>::SetDampingConstantMutant(double dampingConstantMutant)
00773 {
00774     assert(dampingConstantMutant > 0.0);
00775     mDampingConstantMutant = dampingConstantMutant;
00776 }
00777 
00778 template<unsigned DIM>
00779 void AbstractCellPopulation<DIM>::SetOutputCellIdData(bool writeCellIdData)
00780 {
00781     mOutputCellIdData = writeCellIdData;
00782 }
00783 
00784 template<unsigned DIM>
00785 void AbstractCellPopulation<DIM>::SetOutputCellMutationStates(bool outputCellMutationStates)
00786 {
00787     mOutputCellMutationStates = outputCellMutationStates;
00788 }
00789 
00790 template<unsigned DIM>
00791 void AbstractCellPopulation<DIM>::SetOutputCellAncestors(bool outputCellAncestors)
00792 {
00793     mOutputCellAncestors = outputCellAncestors;
00794 }
00795 
00796 template<unsigned DIM>
00797 void AbstractCellPopulation<DIM>::SetOutputCellProliferativeTypes(bool outputCellProliferativeTypes)
00798 {
00799     mOutputCellProliferativeTypes = outputCellProliferativeTypes;
00800 }
00801 
00802 template<unsigned DIM>
00803 void AbstractCellPopulation<DIM>::SetOutputCellVariables(bool outputCellVariables)
00804 {
00805     mOutputCellVariables = outputCellVariables;
00806 }
00807 
00808 template<unsigned DIM>
00809 void AbstractCellPopulation<DIM>::SetOutputCellCyclePhases(bool outputCellCyclePhases)
00810 {
00811     mOutputCellCyclePhases = outputCellCyclePhases;
00812 }
00813 
00814 template<unsigned DIM>
00815 void AbstractCellPopulation<DIM>::SetOutputCellAges(bool outputCellAges)
00816 {
00817     mOutputCellAges = outputCellAges;
00818 }
00819 
00820 template<unsigned DIM>
00821 void AbstractCellPopulation<DIM>::SetOutputCellVolumes(bool outputCellVolumes)
00822 {
00823     mOutputCellVolumes = outputCellVolumes;
00824 }
00825 
00827 // Explicit instantiation
00829 
00830 template class AbstractCellPopulation<1>;
00831 template class AbstractCellPopulation<2>;
00832 template class AbstractCellPopulation<3>;

Generated on Tue May 31 14:31:40 2011 for Chaste by  doxygen 1.5.5