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