Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
1,247 changes: 645 additions & 602 deletions addons/libRoadrunner/src/librr_intracellular.cpp

Large diffs are not rendered by default.

102 changes: 66 additions & 36 deletions addons/libRoadrunner/src/librr_intracellular.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,76 @@
// #include "rrc_types.h"
#include "../roadrunner/include/rr/C/rrc_api.h"
#include "../roadrunner/include/rr/C/rrc_types.h"
#include <functional>
#include <algorithm>

// #include "rrc_utilities.h"
extern "C" rrc::RRHandle createRRInstance();
// #endif

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

class RoadRunnerMapping
{
public:
std::string physicell_name;
std::string sbml_species;
std::string io_type;
std::string physicell_dictionary_name;
int index;
MappingFunction value_map = [] (PhysiCell::Cell *pCell) {}; // default to a function that does nothing
bool mapping_initialized = false;

RoadRunnerMapping() {};
RoadRunnerMapping(std::string physicell_name, std::string sbml_species, std::string io_type)
: physicell_name(physicell_name), sbml_species(sbml_species), io_type(io_type) {};

void initialize_mapping(void);
};

MappingFunction select_signal_setter(const std::string& name, const std::string& sbml_species);

bool is_physicell_phenotype_token(const std::string& name);
MappingFunction select_phenotype_by_token_inputter(const std::string& name, const std::string& sbml_species);
MappingFunction select_phenotype_by_token_outputter(const std::string& name, const std::string& sbml_species);

void validate_mappings(std::vector<RoadRunnerMapping *> mappings, bool is_inputs);

std::vector<int> parse_ctr_token(const std::string &name);
void throw_invalid_ctr_token(const std::string& name);
void validate_cycle_mappings(std::vector<RoadRunnerMapping*> mappings, int num_of_phases);

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;
bool mappings_initialized = false;
void initialize_mappings();
std::vector<RoadRunnerMapping *> input_mappings;
std::vector<RoadRunnerMapping *> output_mappings;
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;
return static_cast<Intracellular*>(clone);
}

Expand All @@ -78,26 +96,36 @@ class RoadRunnerIntracellular : public PhysiCell::Intracellular
std::cout << "------ librr_intracellular: getIntracellularModel called\n";
return static_cast<Intracellular*>(this);
}
void initialize_intracellular_from_pugixml(pugi::xml_node& node);
// Need 'int' return type to avoid bizarre compile errors? But 'void' to match MaBoSS.

void initialize_intracellular_from_pugixml(pugi::xml_node &node);

// Need 'int' return type to avoid bizarre compile errors? But 'void' to match MaBoSS.
void start();

bool need_update();

// Need 'int' return type to avoid bizarre compile errors.
Comment thread
drbergman marked this conversation as resolved.
Outdated
void update();
void update(PhysiCell::Cell* cell, PhysiCell::Phenotype& phenotype, double dt) {
update();
update_phenotype_parameters(phenotype);
}
void update() {};
void update(PhysiCell::Cell* cell, PhysiCell::Phenotype& phenotype, double dt);

void pre_update(PhysiCell::Cell* cell);
void post_update(PhysiCell::Cell* cell);

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

int update_phenotype_parameters(PhysiCell::Phenotype& phenotype);

// 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)
{ return find_input_mapping(sbml_species); } // sbml_species is unique for inputs (above is for convenience)}

RoadRunnerMapping *find_output_mapping(std::string sbml_species); // sbml_species is unique for outputs (below is for convenience)
RoadRunnerMapping *find_output_mapping(std::string physicell_name, std::string sbml_species)
{ return find_output_mapping(physicell_name); } // sbml_species is unique for outputs (above is for convenience)}

Comment thread
drbergman marked this conversation as resolved.
Outdated
int update_phenotype_parameters(PhysiCell::Phenotype& phenotype) {return 0;}; // all handled within update
int validate_PhysiCell_tokens(PhysiCell::Phenotype& phenotype);
int validate_SBML_species();
void validate_SBML_species(std::vector<std::string> all_species, std::vector<RoadRunnerMapping*> mappings);
int create_custom_data_for_SBML(PhysiCell::Phenotype& phenotype);

double get_parameter_value(std::string name);
Expand All @@ -114,4 +142,6 @@ class RoadRunnerIntracellular : public PhysiCell::Intracellular
static void save_libRR(std::string path, std::string index);
};

RoadRunnerIntracellular* getRoadRunnerModel(PhysiCell::Phenotype& phenotype);

#endif
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
10 changes: 7 additions & 3 deletions core/PhysiCell_cell_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,20 @@ 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_);
}
}
}
}

if( time_since_last_cycle > phenotype_dt_ - 0.5 * diffusion_dt_ || !initialzed )
{
// Reset the max_radius in each voxel. It will be filled in set_total_volume
Expand Down
6 changes: 2 additions & 4 deletions core/PhysiCell_signal_behavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,8 @@ int find_signal_index( std::string signal_name )
auto search = signal_to_int.find( signal_name );
// safety first!
if( search != signal_to_int.end() )
{ return search->second; }

std::cout << "having trouble finding " << signal_name << std::endl;

{ return search->second; }

return -1;
}

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,23 +308,27 @@

<intracellular type="roadrunner">
<sbml_filename>./config/Toy_Metabolic_Model.xml</sbml_filename>
<intracellular_dt>0.01</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 >
<map PC_phenotype="da" sbml_species="apoptosis_rate"></map>
<map PC_phenotype="mms" sbml_species="migration_speed"></map>
<map PC_phenotype="ssr_lactate" sbml_species="Lac_Secretion_Rate"></map>
<map PC_phenotype="ctr_0_0" sbml_species="Transition_Rate"></map>
<intracellular_dt>0.1</intracellular_dt>
<map type="io" physicell_name="intracellular oxygen" sbml_species="Oxygen"></map >
<map type="io" physicell_name="intracellular lactate" sbml_species="Lactate"></map >
<map type="io" physicell_name="intracellular glucose" sbml_species="Glucose"></map >
<map type="output" physicell_name="apoptosis" sbml_species="apoptosis_rate"></map>
<map type="output" physicell_name="migration speed" sbml_species="migration_speed"></map>
<map type="output" physicell_name="lactate secretion" sbml_species="Lac_Secretion_Rate"></map>
<map type="output" physicell_name="exit from cycle phase 0" sbml_species="Transition_Rate"></map>
<map type="output" physicell_name="custom:intra_oxy" sbml_species="Oxygen"></map>
<map type="output" physicell_name="custom:intra_lac" sbml_species="Lactate"></map>
<map type="output" physicell_name="custom:intra_glu" sbml_species="Glucose"></map>
<map type="output" physicell_name="custom:intra_energy" sbml_species="Energy"></map>
</intracellular>

<molecular />
</phenotype>
<custom_data>
<intra_oxy units="mmHg">0.0</intra_oxy>
<intra_glu units="mM">0.0</intra_glu>
<intra_oxy units="mmHg">0.8</intra_oxy>
<intra_glu units="mM">15.0</intra_glu>
<intra_lac units="mM">0.0</intra_lac>
<intra_energy units="dimensionless">0.0</intra_energy>
<intra_energy units="dimensionless">450.0</intra_energy>
</custom_data>
</cell_definition>
</cell_definitions>
Expand All @@ -347,10 +352,6 @@

<user_parameters>
<random_seed type="int" units="dimensionless">0</random_seed>
<initial_internal_oxygen type="double" units="mmHg">0.8</initial_internal_oxygen>
<initial_internal_glucose type="double" units="mM">15</initial_internal_glucose>
<initial_internal_lactate type="double" units="mM">0</initial_internal_lactate>
<initial_energy type="double" units="dimensionless">450</initial_energy>
</user_parameters>

</PhysiCell_settings>
Loading