Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,17 @@ template_BM:
mkdir ./scripts/
cp ./sample_projects_intracellular/boolean/template_BM/scripts/* ./scripts/

spheroid_tnf:
cp ./sample_projects_intracellular/spheroid_tnf/custom_modules/* ./custom_modules/
touch main.cpp && cp main.cpp main-backup.cpp
cp ./sample_projects_intracellular/spheroid_tnf/main.cpp ./main.cpp
cp Makefile Makefile-backup
cp ./sample_projects_intracellular/spheroid_tnf/Makefile .
cp ./config/PhysiCell_settings.xml ./config/PhysiCell_settings-backup.xml
cp -r ./sample_projects_intracellular/spheroid_tnf/config/* ./config/
mkdir ./scripts/
cp ./sample_projects_intracellular/spheroid_tnf/scripts/* ./scripts/

# early examples for convergence testing

physicell_test_mech1: $(PhysiCell_OBJECTS) ./examples/PhysiCell_test_mechanics_1.cpp
Expand Down
25 changes: 21 additions & 4 deletions addons/PhysiBoSS/src/maboss_intracellular.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ MaBoSSIntracellular::MaBoSSIntracellular(pugi::xml_node& node)

MaBoSSIntracellular::MaBoSSIntracellular(MaBoSSIntracellular* copy)
{
pre_update_intracellular = copy->pre_update_intracellular;
post_update_intracellular = copy->post_update_intracellular;
intracellular_type = copy->intracellular_type;
bnd_filename = copy->bnd_filename;
cfg_filename = copy->cfg_filename;
Expand Down Expand Up @@ -424,7 +426,14 @@ void MaBoSSIntracellular::initialize_intracellular_from_pugixml(pugi::xml_node&
}

MaBoSSIntracellular* getMaBoSSModel(PhysiCell::Phenotype& phenotype) {
return static_cast<MaBoSSIntracellular*>(phenotype.intracellular);
for (auto* intracellular : phenotype.intracellulars)
{
if (intracellular->intracellular_type == "maboss")
{
return static_cast<MaBoSSIntracellular*>(intracellular);
}
}
return nullptr;
}

void MaBoSSIntracellular::display(std::ostream& os)
Expand Down Expand Up @@ -480,8 +489,16 @@ void MaBoSSIntracellular::save(std::string filename)
state_file << "ID,state" << std::endl;

for( auto cell : *PhysiCell::all_cells )
if (cell->phenotype.intracellular != NULL && cell->phenotype.intracellular->intracellular_type == "maboss")
state_file << cell->ID << "," << static_cast<MaBoSSIntracellular*>(cell->phenotype.intracellular)->get_state() << std::endl;

{
if (cell->phenotype.intracellulars.size() > 0)
{
// This only works if there is one maboss intracellular model per cell, which is the ok
for (auto& intracellular : cell->phenotype.intracellulars) {
if (intracellular->intracellular_type == "maboss") {
state_file << cell->ID << "," << static_cast<MaBoSSIntracellular*>(intracellular)->get_state() << std::endl;
}
}
}
}
state_file.close();
}
8 changes: 4 additions & 4 deletions addons/PhysiBoSS/src/maboss_intracellular.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class MaBoSSIntracellular : public PhysiCell::Intracellular {
MaBoSSIntracellular(MaBoSSIntracellular* copy);

Intracellular* clone() {
return static_cast<Intracellular*>(new MaBoSSIntracellular(this));
return static_cast<PhysiCell::Intracellular*>(new MaBoSSIntracellular(this));
}
Intracellular* getIntracellularModel() {
return static_cast<Intracellular*>(this);
return static_cast<PhysiCell::Intracellular*>(this);
}

void initialize_intracellular_from_pugixml(pugi::xml_node& node);
Expand All @@ -80,9 +80,9 @@ class MaBoSSIntracellular : public PhysiCell::Intracellular {
return PhysiCell::PhysiCell_globals.current_time >= this->next_physiboss_run;
}

void inherit(PhysiCell::Cell * cell) {
void inherit(PhysiCell::Intracellular* intracellular) {
maboss.inherit_state(
static_cast<MaBoSSIntracellular*>(cell->phenotype.intracellular)->maboss.get_maboss_state(),
static_cast<MaBoSSIntracellular*>(intracellular)->maboss.get_maboss_state(),
inherit_state, inherit_nodes
);
}
Expand Down
166 changes: 82 additions & 84 deletions addons/libRoadrunner/src/librr_intracellular.cpp

Large diffs are not rendered by default.

20 changes: 15 additions & 5 deletions addons/libRoadrunner/src/librr_intracellular.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
// #include "rrc_utilities.h"
extern "C" rrc::RRHandle createRRInstance();
// #endif
class RoadRunnerIntracellular;

typedef std::function<void(PhysiCell::Cell* pCell)> MappingFunction;
typedef std::function<void(PhysiCell::Cell* pCell, RoadRunnerIntracellular *intracellular)> MappingFunction;

class RoadRunnerMapping
{
Expand All @@ -35,7 +36,7 @@ class RoadRunnerMapping
std::string io_type;
std::string physicell_dictionary_name;
int index;
MappingFunction value_map = [] (PhysiCell::Cell *pCell) {}; // default to a function that does nothing
MappingFunction value_map = [] (PhysiCell::Cell *pCell, RoadRunnerIntracellular *intracellular) {}; // default to a function that does nothing
bool mapping_initialized = false;

RoadRunnerMapping() {};
Expand Down Expand Up @@ -72,7 +73,7 @@ class RoadRunnerIntracellular : public PhysiCell::Intracellular
std::vector<RoadRunnerMapping *> output_mappings;
std::map<std::string, int> species_result_column_index;

rrc::RRHandle rrHandle;
rrc::RRHandle rrHandle = NULL;
rrc::RRCDataPtr result = 0; // start time, end time, and number of points

double update_time_step = 0.01;
Expand All @@ -85,6 +86,15 @@ class RoadRunnerIntracellular : public PhysiCell::Intracellular

RoadRunnerIntracellular(RoadRunnerIntracellular* copy);

~RoadRunnerIntracellular()
{
if (this->rrHandle != NULL)
{
rrc::freeRRInstance(this->rrHandle);
this->rrHandle = NULL;
}
}

Intracellular* clone()
{
RoadRunnerIntracellular* clone = new RoadRunnerIntracellular(this);
Expand All @@ -110,8 +120,8 @@ class RoadRunnerIntracellular : public PhysiCell::Intracellular
void pre_update(PhysiCell::Cell* cell);
void post_update(PhysiCell::Cell* cell);

void inherit(PhysiCell::Cell * cell) {}

void inherit(PhysiCell::Intracellular * intracellular) {}
// These find_<IO>_mapping functions are not currently used, but since I made them, we'll keep them around.
RoadRunnerMapping *find_input_mapping(std::string sbml_species); // sbml_species is unique for inputs (below is for convenience)
RoadRunnerMapping *find_input_mapping(std::string physicell_name, std::string sbml_species)
Expand Down
118 changes: 101 additions & 17 deletions core/PhysiCell_cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,10 +666,12 @@ Cell* Cell::divide( )
// pAttackTarget was cleared above, so the daughter inherits a NULL one
child->phenotype = phenotype;

if (child->phenotype.intracellular){
child->phenotype.intracellular->start();
child->phenotype.intracellular->inherit(this);
for (size_t i=0; i < child->phenotype.intracellulars.size(); i++)
{
child->phenotype.intracellulars[i]->start();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noting here that if we need to decide how to proceed with #425. the call to start() here would not be necessary. and I think we could make the inherit call unnecessary.

child->phenotype.intracellulars[i]->inherit(this->phenotype.intracellulars[i]);
}

// #ifdef ADDON_PHYSIDFBA
// child->fba_model = this->fba_model;
// #endif
Expand Down Expand Up @@ -1137,8 +1139,8 @@ Cell* create_cell( Cell_Definition& cd )
pNew->functions = cd.functions;

pNew->phenotype = cd.phenotype;
if (pNew->phenotype.intracellular)
pNew->phenotype.intracellular->start();
for (auto* intracellular: pNew->phenotype.intracellulars)
intracellular->start();
Comment on lines +1142 to +1143

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're confident we don't need to inherit here? I honestly don't know.


pNew->is_movable = cd.is_movable; // true;
pNew->is_out_of_domain = false;
Expand Down Expand Up @@ -1949,9 +1951,9 @@ void display_cell_definitions( std::ostream& os )


// intracellular
if (pCD->phenotype.intracellular != NULL)
for (auto intracellular: pCD->phenotype.intracellulars)
{
pCD->phenotype.intracellular->display(os);
intracellular->display(os);
}

Custom_Cell_Data* pCCD = &(pCD->custom_data);
Expand Down Expand Up @@ -3192,13 +3194,13 @@ Cell_Definition* initialize_cell_definition_from_pugixml( pugi::xml_node cd_node
#ifdef ADDON_PHYSIBOSS
if (model_type == "maboss") {
// If it has already be copied
if (pParent != NULL && pParent->phenotype.intracellular != NULL) {
pCD->phenotype.intracellular->initialize_intracellular_from_pugixml(node);
if (pParent != NULL && pParent->phenotype.intracellulars.size() > 0) {
pCD->phenotype.intracellulars[0]->initialize_intracellular_from_pugixml(node);

// Otherwise we need to create a new one
} else {
MaBoSSIntracellular* pIntra = new MaBoSSIntracellular(node);
pCD->phenotype.intracellular = pIntra->getIntracellularModel();
pCD->phenotype.intracellulars.push_back(pIntra->getIntracellularModel());
Comment on lines -3195 to +3203

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code diff is hard for me to understand.

If the parent has an intracellular model,
    initialize the first intracellular of this cell def from the node.
else
    push a new one onto the end

Assuming that pCD inherits its intracellulars from pParent, we can't guarantee they share the same intracellular type. Also, why are we only updating the first entry here? I'll look for where we update further entries below.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found where further entries are updated below. I'm wondering now if this here is dead code.

}
}
#endif
Expand All @@ -3207,15 +3209,21 @@ Cell_Definition* initialize_cell_definition_from_pugixml( pugi::xml_node cd_node
if (model_type == "roadrunner")
{
// If it has already be copied
if (pParent != NULL && pParent->phenotype.intracellular != NULL)
if (pParent != NULL && pParent->phenotype.intracellulars.size() > 0)
{
pCD->phenotype.intracellular->initialize_intracellular_from_pugixml(node);
// std::cout << "------ " << __FUNCTION__ << ": copying another\n";
pCD->phenotype.intracellulars[0]->initialize_intracellular_from_pugixml(node);
pCD->phenotype.intracellulars[0]->validate_PhysiCell_tokens(pCD->phenotype);
pCD->phenotype.intracellulars[0]->validate_SBML_species();
}
// Otherwise we need to create a new one
else
{
RoadRunnerIntracellular* pIntra = new RoadRunnerIntracellular(node);
pCD->phenotype.intracellular = pIntra->getIntracellularModel();
pIntra->validate_PhysiCell_tokens(pCD->phenotype);
pIntra->validate_SBML_species();
pCD->phenotype.intracellulars.push_back(pIntra->getIntracellularModel());

}
pCD->phenotype.intracellular->validate_PhysiCell_tokens(pCD->phenotype);
pCD->phenotype.intracellular->validate_SBML_species();
Expand All @@ -3225,22 +3233,98 @@ Cell_Definition* initialize_cell_definition_from_pugixml( pugi::xml_node cd_node
#ifdef ADDON_PHYSIDFBA
if (model_type == "dfba") {
// If it has already be copied
if (pParent != NULL && pParent->phenotype.intracellular != NULL) {
pCD->phenotype.intracellular->initialize_intracellular_from_pugixml(node);
if (pParent != NULL && pParent->phenotype.intracellulars.size() > 0) {
pCD->phenotype.intracellulars[0]->initialize_intracellular_from_pugixml(node);
// Otherwise we need to create a new one
} else {
dFBAIntracellular* pIntra = new dFBAIntracellular(node);
pCD->phenotype.intracellular = pIntra->getIntracellularModel();
pCD->phenotype.intracellulars.push_back(pIntra->getIntracellularModel());
}
}
#endif

} else{

pCD->phenotype.intracellular = NULL;
pCD->phenotype.intracellulars.clear();

}

node = cd_node.child( "phenotype" );
node = node.child( "intracellulars" );
if( node )
{
//If there are intracellular models, we clear whatever existed before, including if there was an old format intracellular model
pCD->phenotype.intracellulars.clear();

pugi::xml_node intracellular = node.child( "intracellular" );
size_t intracellular_count = 0;
while( intracellular )
{
// which substrate?


std::string model_type = intracellular.attribute( "type" ).value();


#ifdef ADDON_PHYSIBOSS
if (model_type == "maboss") {
// If it has already be copied
if (pParent != NULL && pParent->phenotype.intracellulars.size() >= intracellular_count) {
pCD->phenotype.intracellulars[intracellular_count]->initialize_intracellular_from_pugixml(intracellular);

// Otherwise we need to create a new one
} else {
MaBoSSIntracellular* pIntra = new MaBoSSIntracellular(intracellular);
pCD->phenotype.intracellulars.push_back(pIntra->getIntracellularModel());
}
}
#endif

#ifdef ADDON_ROADRUNNER
if (model_type == "roadrunner")
{
// If it has already be copied
if (pParent != NULL && pParent->phenotype.intracellulars.size() >= intracellular_count)
{
// std::cout << "------ " << __FUNCTION__ << ": copying another\n";
pCD->phenotype.intracellulars[intracellular_count]->initialize_intracellular_from_pugixml(node);
}
// Otherwise we need to create a new one
else
{
std::cout << "\n------ " << __FUNCTION__ << ": creating new RoadRunnerIntracellular\n";
RoadRunnerIntracellular* pIntra = new RoadRunnerIntracellular(intracellular);
pIntra->validate_PhysiCell_tokens(pCD->phenotype);
pIntra->validate_SBML_species();
pCD->phenotype.intracellulars.push_back(pIntra->getIntracellularModel());

}
}
#endif

#ifdef ADDON_PHYSIDFBA
if (model_type == "dfba") {
// If it has already be copied
if (pParent != NULL && pParent->phenotype.intracellulars.size() > intracellular_count) {
pCD->phenotype.intracellulars[intracellular_count]->initialize_intracellular_from_pugixml(intracellular);
// Otherwise we need to create a new one
} else {
PhysiCelldFBA::dFBAIntracellular* pIntra = new PhysiCelldFBA::dFBAIntracellular(intracellular);
pCD->phenotype.intracellulars.push_back(pIntra->getIntracellularModel());
}
}
#endif
Comment on lines +3269 to +3316

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! This is what I was looking for. so what's the part above meant for then?


// } else{

// pCD->phenotype.intracellulars.clear();

// }
intracellular = intracellular.next_sibling( "intracellular" );
intracellular_count += 1;
}
}

// set up custom data
node = cd_node.child( "custom_data" );
pugi::xml_node node1 = node.first_child();
Expand Down
32 changes: 21 additions & 11 deletions core/PhysiCell_cell_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,20 +286,27 @@ void Cell_Container::update_all_cells(double t, double phenotype_dt_ , double me
void Cell_Container::update_all_cells_intracellular( void )
{
bool anything_to_update = false; // Use a simple boolean for reduction
std::vector<bool> ready_to_update_intracellular = std::vector<bool>( (*all_cells).size(), false );
std::vector<std::vector<int> > ready_to_update_intracellular = std::vector<std::vector<int> >( (*all_cells).size() );

#pragma omp parallel for reduction(||:anything_to_update)
for( int i=0; i < (*all_cells).size(); i++ )
{
if( (*all_cells)[i]->is_out_of_domain == false ) {
if( (*all_cells)[i]->phenotype.intracellular != NULL && (*all_cells)[i]->phenotype.intracellular->need_update())
if( (*all_cells)[i]->is_out_of_domain == false && (*all_cells)[i]->phenotype.intracellulars.size() > 0)
{
int j=0;
for (auto * intracellular: (*all_cells)[i]->phenotype.intracellulars)
{
ready_to_update_intracellular[i] = true;
anything_to_update = true; // Set to true if any cell needs an update
if ((*all_cells)[i]->functions.pre_update_intracellular != NULL)
if (intracellular->need_update())
{
(*all_cells)[i]->functions.pre_update_intracellular((*all_cells)[i], (*all_cells)[i]->phenotype, diffusion_dt);
ready_to_update_intracellular[i].push_back(j); // Mark this cell for update

anything_to_update = true; // Set to true if any cell needs an update
if (intracellular->pre_update_intracellular != NULL)
{
intracellular->pre_update_intracellular((*all_cells)[i], (*all_cells)[i]->phenotype, diffusion_dt);
}
}
j++;
}
}
}
Expand All @@ -310,18 +317,21 @@ void Cell_Container::update_all_cells_intracellular( void )
#pragma omp parallel for
for ( int i=0; i < (*all_cells).size(); i++ )
{
if (ready_to_update_intracellular[i])
for (int j : ready_to_update_intracellular[i])
{
(*all_cells)[i]->phenotype.intracellular->update((*all_cells)[i], (*all_cells)[i]->phenotype, diffusion_dt);
(*all_cells)[i]->phenotype.intracellulars[j]->update((*all_cells)[i], (*all_cells)[i]->phenotype, diffusion_dt);
}
}

#pragma omp parallel for
for ( int i=0; i < (*all_cells).size(); i++ )
{
if (ready_to_update_intracellular[i] && (*all_cells)[i]->functions.post_update_intracellular != NULL)
for (int j : ready_to_update_intracellular[i])
{
(*all_cells)[i]->functions.post_update_intracellular((*all_cells)[i], (*all_cells)[i]->phenotype, diffusion_dt);
if ((*all_cells)[i]->phenotype.intracellulars[j]->post_update_intracellular != NULL)
{
(*all_cells)[i]->phenotype.intracellulars[j]->post_update_intracellular((*all_cells)[i], (*all_cells)[i]->phenotype, diffusion_dt);
}
}
}
}
Expand Down
Loading
Loading