Skip to content
Closed
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
242 changes: 32 additions & 210 deletions addons/libRoadrunner/src/librr_intracellular.cpp

Large diffs are not rendered by default.

21 changes: 3 additions & 18 deletions addons/libRoadrunner/src/librr_intracellular.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,32 @@ class RoadRunnerIntracellular : public PhysiCell::Intracellular
{
private:
public:

// static long counter;

std::string sbml_filename;
// bool enabled = false;


int num_rows_result_table = 1;

// double time_step = 12;
// bool discrete_time = false;
// double time_tick = 0.5;
// double scaling = 1.0;

// std::map<std::string, double> initial_values;
std::map<std::string, double> parameters;
std::map<std::string, std::string> substrate_species;
std::map<std::string, std::string> custom_data_species;
std::map<std::string, std::string> phenotype_species;
std::map<std::string, int> species_result_column_index;

// rrc::RRHandle rrHandle = createRRInstance();
rrc::RRHandle rrHandle;
// rrc::RRHandle rrHandle;
// rrc::RRVectorPtr vptr;
rrc::RRCDataPtr result = 0; // start time, end time, and number of points

double next_librr_run = 0;
double update_time_step = 0.01;
double previous_update_time = 0.0;
double next_librr_run = 0.0;

RoadRunnerIntracellular();

RoadRunnerIntracellular(pugi::xml_node& node);

RoadRunnerIntracellular(RoadRunnerIntracellular* copy);

// rwh: review this
Intracellular* clone()
{
// return static_cast<Intracellular*>(new RoadRunnerIntracellular(this));
RoadRunnerIntracellular* clone = new RoadRunnerIntracellular(this);
clone->sbml_filename = this->sbml_filename;
clone->substrate_species = this->substrate_species;
clone->phenotype_species = this->phenotype_species;
clone->custom_data_species = this->custom_data_species;
Expand Down
6 changes: 2 additions & 4 deletions core/PhysiCell_cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3144,18 +3144,16 @@ Cell_Definition* initialize_cell_definition_from_pugixml( pugi::xml_node cd_node
// If it has already be copied
if (pParent != NULL && pParent->phenotype.intracellular != NULL)
{
// std::cout << "------ " << __FUNCTION__ << ": copying another\n";
pCD->phenotype.intracellular->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(node);
pCD->phenotype.intracellular = pIntra->getIntracellularModel();
pCD->phenotype.intracellular->validate_PhysiCell_tokens(pCD->phenotype);
pCD->phenotype.intracellular->validate_SBML_species();
}
pCD->phenotype.intracellular->validate_PhysiCell_tokens(pCD->phenotype);
pCD->phenotype.intracellular->validate_SBML_species();
}
#endif

Expand Down
8 changes: 6 additions & 2 deletions core/PhysiCell_cell_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,16 @@ void Cell_Container::update_all_cells(double t, double phenotype_dt_ , double me
if( (*all_cells)[i]->phenotype.intracellular != NULL && (*all_cells)[i]->phenotype.intracellular->need_update())
{
if ((*all_cells)[i]->functions.pre_update_intracellular != NULL)
(*all_cells)[i]->functions.pre_update_intracellular( (*all_cells)[i], (*all_cells)[i]->phenotype , diffusion_dt_ );
{
(*all_cells)[i]->functions.pre_update_intracellular((*all_cells)[i], (*all_cells)[i]->phenotype, diffusion_dt_);
}

(*all_cells)[i]->phenotype.intracellular->update( (*all_cells)[i], (*all_cells)[i]->phenotype , diffusion_dt_ );

if ((*all_cells)[i]->functions.post_update_intracellular != NULL)
(*all_cells)[i]->functions.post_update_intracellular( (*all_cells)[i], (*all_cells)[i]->phenotype , diffusion_dt_ );
{
(*all_cells)[i]->functions.post_update_intracellular((*all_cells)[i], (*all_cells)[i]->phenotype, diffusion_dt_);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
<max_time units="min">1440</max_time> <!-- 1 days * 24 h * 60 min -->
<time_units>min</time_units>
<space_units>micron</space_units>


<dt_intracellular units="min">0.01</dt_intracellular>
<dt_diffusion units="min">0.01</dt_diffusion>
<dt_mechanics units="min">0.1</dt_mechanics>
<dt_phenotype units="min">6</dt_phenotype>
Expand Down Expand Up @@ -307,7 +308,7 @@

<intracellular type="roadrunner">
<sbml_filename>./config/Toy_Metabolic_Model.xml</sbml_filename>
<intracellular_dt>0.01</intracellular_dt>
<intracellular_dt>0.1</intracellular_dt>
<map PC_substrate="oxygen" sbml_species="Oxygen"></map >
<map PC_substrate="lactate" sbml_species="Lactate"></map >
<map PC_substrate="glucose" sbml_species="Glucose"></map >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,80 +179,66 @@ void setup_tissue( void )
set_single_behavior( pCell , "custom:intra_lac" , parameters.doubles("initial_internal_lactate"));
set_single_behavior( pCell , "custom:intra_energy" , parameters.doubles("initial_energy"));

/* pCell->custom_data[i_Oxy_i] = parameters.doubles("initial_internal_oxygen");
pCell->custom_data[i_Glu_i] = parameters.doubles("initial_internal_glucose");
pCell->custom_data[i_Lac_i] = parameters.doubles("initial_internal_lactate");
pCell->custom_data[energy_vi] = parameters.doubles("initial_energy"); */

double cell_volume = pCell->phenotype.volume.total;

//std::cout << "oxygen custom data : " << pCell->custom_data[i_Oxy_i] << std::endl;
//std::cout << "oxygen custom data : SIGNAL" << get_single_signal( pCell, "custom:intra_oxy") << std::endl;


set_single_behavior( pCell , "custom:intra_oxy" , parameters.doubles("initial_internal_oxygen"));


pCell->phenotype.molecular.internalized_total_substrates[oxygen_substrate_index]= get_single_signal( pCell, "custom:intra_oxy") * cell_volume;
pCell->phenotype.molecular.internalized_total_substrates[glucose_substrate_index]= get_single_signal( pCell, "custom:intra_glu") * cell_volume;
pCell->phenotype.molecular.internalized_total_substrates[lactate_substrate_index]= get_single_signal( pCell, "custom:intra_lac") * cell_volume;
pCell->phenotype.intracellular->start();
(*all_cells)[i]->phenotype.intracellular->set_parameter_value("Energy",get_single_signal( pCell, "custom:intra_energy"));

pCell->phenotype.intracellular->set_parameter_value("Energy",get_single_signal( pCell, "custom:intra_energy"));

pCell->functions.pre_update_intracellular = pre_update_intracellular;
pCell->functions.post_update_intracellular = post_update_intracellular;
}

return;
}

void update_intracellular()
void pre_update_intracellular( Cell* pCell, Phenotype& phenotype, double dt )
{
// BioFVM Indices
static int oxygen_substrate_index = microenvironment.find_density_index( "oxygen" );
static int glucose_substrate_index = microenvironment.find_density_index( "glucose" );
static int lactate_substrate_index = microenvironment.find_density_index( "lactate");

#pragma omp parallel for
for( int i=0; i < (*all_cells).size(); i++ )
{
if( (*all_cells)[i]->is_out_of_domain == false )
{
// Cell Volume
double cell_volume = (*all_cells)[i]->phenotype.volume.total;

// Get Intracellular Concentrations
double oxy_val_int = get_single_signal((*all_cells)[i], "intracellular oxygen");
double glu_val_int = get_single_signal((*all_cells)[i], "intracellular glucose");
double lac_val_int = get_single_signal((*all_cells)[i], "intracellular lactate");

// Update SBML
(*all_cells)[i]->phenotype.intracellular->set_parameter_value("Oxygen",oxy_val_int);
(*all_cells)[i]->phenotype.intracellular->set_parameter_value("Glucose",glu_val_int);
(*all_cells)[i]->phenotype.intracellular->set_parameter_value("Lactate",lac_val_int);

// SBML Simulation
(*all_cells)[i]->phenotype.intracellular->update();

// Phenotype Simulation
(*all_cells)[i]->phenotype.intracellular->update_phenotype_parameters((*all_cells)[i]->phenotype);

// Internalized Chemical Update After SBML Simulation
(*all_cells)[i]->phenotype.molecular.internalized_total_substrates[oxygen_substrate_index] = (*all_cells)[i]->phenotype.intracellular->get_parameter_value("Oxygen") * cell_volume;
(*all_cells)[i]->phenotype.molecular.internalized_total_substrates[glucose_substrate_index] = (*all_cells)[i]->phenotype.intracellular->get_parameter_value("Glucose") * cell_volume;
(*all_cells)[i]->phenotype.molecular.internalized_total_substrates[lactate_substrate_index] = (*all_cells)[i]->phenotype.intracellular->get_parameter_value("Lactate") * cell_volume;


//Save custom data
set_single_behavior( (*all_cells)[i] , "custom:intra_oxy" , (*all_cells)[i]->phenotype.intracellular->get_parameter_value("Oxygen") );
set_single_behavior( (*all_cells)[i] , "custom:intra_glu" , (*all_cells)[i]->phenotype.intracellular->get_parameter_value("Glucose") );
set_single_behavior( (*all_cells)[i] , "custom:intra_lac" , (*all_cells)[i]->phenotype.intracellular->get_parameter_value("Lactate") );
set_single_behavior( (*all_cells)[i] , "custom:intra_energy" , (*all_cells)[i]->phenotype.intracellular->get_parameter_value("Energy") );

}
}

// Cell Volume
double cell_volume = pCell->phenotype.volume.total;

// Get Intracellular Concentrations
double oxy_val_int = get_single_signal(pCell, "intracellular oxygen");
double glu_val_int = get_single_signal(pCell, "intracellular glucose");
double lac_val_int = get_single_signal(pCell, "intracellular lactate");

// Update SBML
pCell->phenotype.intracellular->set_parameter_value("Oxygen",oxy_val_int);
pCell->phenotype.intracellular->set_parameter_value("Glucose",glu_val_int);
pCell->phenotype.intracellular->set_parameter_value("Lactate",lac_val_int);
}

void post_update_intracellular( Cell* pCell, Phenotype& phenotype, double dt )
{
// BioFVM Indices
static int oxygen_substrate_index = microenvironment.find_density_index( "oxygen" );
static int glucose_substrate_index = microenvironment.find_density_index( "glucose" );
static int lactate_substrate_index = microenvironment.find_density_index( "lactate");

// Cell Volume
double cell_volume = pCell->phenotype.volume.total;

// Phenotype Simulation
pCell->phenotype.intracellular->update_phenotype_parameters(pCell->phenotype);

// Internalized Chemical Update After SBML Simulation
pCell->phenotype.molecular.internalized_total_substrates[oxygen_substrate_index] = pCell->phenotype.intracellular->get_parameter_value("Oxygen") * cell_volume;
pCell->phenotype.molecular.internalized_total_substrates[glucose_substrate_index] = pCell->phenotype.intracellular->get_parameter_value("Glucose") * cell_volume;
pCell->phenotype.molecular.internalized_total_substrates[lactate_substrate_index] = pCell->phenotype.intracellular->get_parameter_value("Lactate") * cell_volume;


//Save custom data
set_single_behavior( pCell , "custom:intra_oxy" , pCell->phenotype.intracellular->get_parameter_value("Oxygen") );
set_single_behavior( pCell , "custom:intra_glu" , pCell->phenotype.intracellular->get_parameter_value("Glucose") );
set_single_behavior( pCell , "custom:intra_lac" , pCell->phenotype.intracellular->get_parameter_value("Lactate") );
set_single_behavior( pCell , "custom:intra_energy" , pCell->phenotype.intracellular->get_parameter_value("Energy") );
}

std::vector<std::string> my_coloring_function( Cell* pCell )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,8 @@ void setup_microenvironment( void );
// custom pathology coloring function

std::vector<std::string> my_coloring_function( Cell* );
void update_intracellular();
void pre_update_intracellular( Cell* pCell, Phenotype& phenotype, double dt );
void post_update_intracellular( Cell* pCell, Phenotype& phenotype, double dt );

// custom functions can go here

void predator_hunting_function( Cell* pCell, Phenotype& phenotype, double dt );
void predator_cycling_function( Cell* pCell, Phenotype& phenotype, double dt );

void prey_cycling_function( Cell* pCell , Phenotype& phenotype, double dt );
std::vector<std::vector<double>> create_cell_circle_positions(double cell_radius, double sphere_radius);
27 changes: 0 additions & 27 deletions sample_projects_intracellular/ode/ode_energy/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,6 @@ int main( int argc, char* argv[] )
report_file<<"simulated time\tnum cells\tnum division\tnum death\twall time"<<std::endl;
}

//
double intracellular_dt = 0.01;
double last_intracellular_time = 0.0;
double intracellular_dt_tolerance = 0.001 * intracellular_dt;
double next_intracellular_update = intracellular_dt;



// main loop

try
Expand Down Expand Up @@ -211,32 +203,13 @@ int main( int argc, char* argv[] )
// update the microenvironment
microenvironment.simulate_diffusion_decay( diffusion_dt );


/* double dt_intracellular = 1.0;
//std::cout << "Current_Time : " << PhysiCell_globals.current_time << " - FMOD : " << fmod(PhysiCell_globals.current_time,1.0) << std::endl;
if ( fabs((fmod (PhysiCell_globals.current_time, dt_intracellular) - 1 )) < 0.001 || (fmod (PhysiCell_globals.current_time, dt_intracellular) < 0.00001) )
{
std::cout << "DIVIDED" <<std::endl;
} */

// run PhysiCell
((Cell_Container *)microenvironment.agent_container)->update_all_cells( PhysiCell_globals.current_time );

/*
Custom add-ons could potentially go here.
*/

double time_since_last_intracellular = PhysiCell_globals.current_time - last_intracellular_time;

//update_intracellular();

if( PhysiCell_globals.current_time >= next_intracellular_update )
{
update_intracellular();

next_intracellular_update += intracellular_dt;
}

PhysiCell_globals.current_time += diffusion_dt;
}

Expand Down