Commit e19aca7a authored by Randy Heiland's avatar Randy Heiland
Browse files

cleanup

parent 3b61c022
Using PhysiCell version 1.7.1
Please cite DOI: 10.1371/journal.pcbi.1005991
Project website: http://PhysiCell.MathCancer.org
/*
#############################################################################
# If you use BioFVM in your project, please cite BioFVM and the version #
# number, such as below: #
# #
# We solved the diffusion equations using BioFVM (Version 1.1.7) [1] #
# #
# [1] A. Ghaffarizadeh, S.H. Friedman, and P. Macklin, BioFVM: an efficient #
# parallelized diffusive transport solver for 3-D biological simulations,#
# Bioinformatics 32(8): 1256-8, 2016. DOI: 10.1093/bioinformatics/btv730 #
# #
#############################################################################
# #
# BSD 3-Clause License (see https://opensource.org/licenses/BSD-3-Clause) #
# #
# Copyright (c) 2015-2017, Paul Macklin and the BioFVM Project #
# All rights reserved. #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions are #
# met: #
# #
# 1. Redistributions of source code must retain the above copyright notice, #
# this list of conditions and the following disclaimer. #
# #
# 2. Redistributions in binary form must reproduce the above copyright #
# notice, this list of conditions and the following disclaimer in the #
# documentation and/or other materials provided with the distribution. #
# #
# 3. Neither the name of the copyright holder nor the names of its #
# contributors may be used to endorse or promote products derived from this #
# software without specific prior written permission. #
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS #
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED #
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A #
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER #
# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, #
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, #
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR #
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF #
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS #
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
# #
#############################################################################
*/
#ifndef __BioFVM_h__
#define __BioFVM_h__
#include <iostream>
#include <fstream>
namespace BioFVM{
extern std::string BioFVM_Version;
extern std::string BioFVM_URL;
};
#include "BioFVM_utilities.h"
#include "BioFVM_vector.h"
#include "BioFVM_vector.h"
#include "BioFVM_mesh.h"
#include "BioFVM_microenvironment.h"
#include "BioFVM_solvers.h"
#include "BioFVM_basic_agent.h"
#endif
/*
#############################################################################
# If you use BioFVM in your project, please cite BioFVM and the version #
# number, such as below: #
# #
# We solved the diffusion equations using BioFVM (Version 1.1.7) [1] #
# #
# [1] A. Ghaffarizadeh, S.H. Friedman, and P. Macklin, BioFVM: an efficient #
# parallelized diffusive transport solver for 3-D biological simulations,#
# Bioinformatics 32(8): 1256-8, 2016. DOI: 10.1093/bioinformatics/btv730 #
# #
#############################################################################
# #
# BSD 3-Clause License (see https://opensource.org/licenses/BSD-3-Clause) #
# #
# Copyright (c) 2015-2017, Paul Macklin and the BioFVM Project #
# All rights reserved. #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions are #
# met: #
# #
# 1. Redistributions of source code must retain the above copyright notice, #
# this list of conditions and the following disclaimer. #
# #
# 2. Redistributions in binary form must reproduce the above copyright #
# notice, this list of conditions and the following disclaimer in the #
# documentation and/or other materials provided with the distribution. #
# #
# 3. Neither the name of the copyright holder nor the names of its #
# contributors may be used to endorse or promote products derived from this #
# software without specific prior written permission. #
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS #
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED #
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A #
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER #
# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, #
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, #
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR #
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF #
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS #
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
# #
#############################################################################
*/
#include "BioFVM.h"
// #include "BioFVM_strings.h"
#include "BioFVM_MultiCellDS.h"
namespace BioFVM{
std::string BioFVM_Version = "1.1.7";
std::string BioFVM_URL = "http://BioFVM.MathCancer.org";
bool biofvm_dom_initialized = false;
pugi::xml_document biofvm_doc;
std::string MultiCellDS_version_string = "0.5";
std::string MultiCellDS_clinical_snapshot_type_string = "snapshot/clinical";
int MultiCellDS_clinical_snapshot_code = 4;
std::string MultiCellDS_experimental_snapshot_type_string = "snapshot/experimental";
int MultiCellDS_experimental_snapshot_code = 3;
std::string MultiCellDS_simulation_snapshot_type_string = "snapshot/simulation";
int MultiCellDS_simulation_snapshot_code = 2;
std::string MultiCellDS_digital_cell_line_type_string = "digital_cell_line";
int MultiCellDS_digital_cell_line_code = 1;
std::string MultiCellDS_generic_type_string = "generic";
int MultiCellDS_generic_code = 0;
bool biofvm_multicellds_BioFVM_metadata_initialized = false;
MultiCellDS_Metadata BioFVM_metadata;
/* options */
bool save_mesh_as_matlab = true;
bool save_density_data_as_matlab = true;
bool save_cells_as_custom_matlab = true;
bool save_cell_data = true;
Person_Metadata::Person_Metadata()
{
is_empty = true;
type = "user";
surname = "";
given_names = "";
email = "";
URL = "";
organization = "";
department = "";
ORCID = "";
}
void Person_Metadata::display_information( std::ostream& os )
{
os << this->type << " name: " << given_names << " " << surname << std::endl
<< "organization: " << organization << std::endl
<< "department: " << department << std::endl
<< "email: " << email << std::endl
<< "URL: " << URL << std::endl
<< "ORCID: " << ORCID << std::endl << std::endl ;
}
void Person_Metadata::insert_in_open_xml_pugi( pugi::xml_node& insert_here )
{
if( ORCID.size() )
{ is_empty = false; }
if( given_names.size() )
{ is_empty = false; }
if( surname.size() )
{ is_empty = false; }
if( email.size() )
{ is_empty = false; }
if( URL.size() )
{ is_empty = false; }
if( organization.size() )
{ is_empty = false; }
if( department.size() )
{ is_empty = false; }
// user information
pugi::xml_node node = insert_here.append_child( type.c_str() );
if( is_empty == true )
{ return; }
node = node.append_child( "orcid-identifier" );
if( ORCID.size() )
{
node = node.append_child( "path" );
node.append_child( pugi::node_pcdata ).set_value( ORCID.c_str() );
node = node.parent();
}
if( given_names.size() )
{
node = node.append_child( "given-names" );
node.append_child( pugi::node_pcdata ).set_value( given_names.c_str() );
node = node.parent();
}
if( surname.size() )
{
node = node.append_child( "family-name" );
node.append_child( pugi::node_pcdata ).set_value( surname.c_str() );
node = node.parent();
}
if( email.size() )
{
node = node.append_child( "email" );
node.append_child( pugi::node_pcdata ).set_value( email.c_str() );
node = node.parent();
}
if( URL.size() )
{
node = node.append_child( "url" );
node.append_child( pugi::node_pcdata ).set_value( URL.c_str() );
node = node.parent();
}
if( organization.size() )
{
node = node.append_child( "organization-name" );
node.append_child( pugi::node_pcdata ).set_value( organization.c_str() );
node = node.parent();
}
if( department.size() )
{
node = node.append_child( "department-name" );
node.append_child( pugi::node_pcdata ).set_value( department.c_str() );
node = node.parent();
}
return;
}
Citation_Metadata::Citation_Metadata()
{
DOI = "";
PMID = "";
PMCID = "";
text = "";
URL = "";
notes = "";
return;
}
void Citation_Metadata::display_information( std::ostream& os )
{
os << "citation: " << std::endl
<< "---------" << std::endl
<< "DOI: " << DOI << std::endl
<< "PMID: " << PMID << std::endl
<< "PMCID: " << PMCID << std::endl
<< "URL: " << URL << std::endl
<< "text: " << text << std::endl
<< "notes: " << notes << std::endl << std::endl;
return;
}
void Citation_Metadata::insert_in_open_xml_pugi( pugi::xml_node& insert_here )
{
// citation information
pugi::xml_node node = insert_here.append_child( "citation" );
if( text.size() )
{
node = node.append_child( "text" );
node.append_child( pugi::node_pcdata ).set_value( text.c_str() );
node = node.parent();
}
if( DOI.size() )
{
node = node.append_child( "DOI" );
node.append_child( pugi::node_pcdata ).set_value( DOI.c_str() );
node = node.parent();
}
if( URL.size() )
{
node = node.append_child( "URL" );
node.append_child( pugi::node_pcdata ).set_value( URL.c_str() );
node = node.parent();
}
if( PMID.size() )
{
node = node.append_child( "PMID" );
node.append_child( pugi::node_pcdata ).set_value( PMID.c_str() );
node = node.parent();
}
if( PMCID.size() )
{
node = node.append_child( "PMCID" );
node.append_child( pugi::node_pcdata ).set_value( PMCID.c_str() );
node = node.parent();
}
if( notes.size() )
{
node = node.append_child( "notes" );
node.append_child( pugi::node_pcdata ).set_value( notes.c_str() );
node = node.parent();
}
return;
}
Software_Metadata::Software_Metadata()
{
program_name = "BioFVM";
program_version = BioFVM_Version;
program_URL = BioFVM_URL;
creator.type = "creator";
return;
}
void Software_Metadata::display_information( std::ostream& os )
{
os << "Program: " << program_name << " (" << program_version << ")" << std::endl
<< "Project URL: " << program_URL << std::endl;
creator.display_information( os );
user.display_information( os );
citation.display_information( os );
return;
}
void Software_Metadata::insert_in_open_xml_pugi( pugi::xml_node& insert_here )
{
// user information
pugi::xml_node node = insert_here.append_child( "software" );
if( program_name.size() )
{
node = node.append_child( "name" );
node.append_child( pugi::node_pcdata ).set_value( program_name.c_str() );
node = node.parent();
node = node.append_child( "version" );
node.append_child( pugi::node_pcdata ).set_value( program_version.c_str() );
node = node.parent(); // software level
node = node.append_child( "URL" );
node.append_child( pugi::node_pcdata ).set_value( program_URL.c_str() );
node = node.parent();
}
creator.insert_in_open_xml_pugi( node );
citation.insert_in_open_xml_pugi( node );
user.insert_in_open_xml_pugi( node );
return;
}
MultiCellDS_Metadata::MultiCellDS_Metadata()
{
MultiCellDS_type = MultiCellDS_simulation_snapshot_type_string;
current_time = 0;
spatial_units = "micron";
time_units = "min";
runtime_units = "sec";
current_runtime = 0;
RUNTIME_TIC();
}
void MultiCellDS_Metadata::restart_runtime( void )
{
RUNTIME_TIC();
RUNTIME_TOC();
current_runtime = runtime_stopwatch_value();
return;
}
void MultiCellDS_Metadata::display_information( std::ostream& os)
{
RUNTIME_TOC();
current_runtime = runtime_stopwatch_value();
program.display_information( os );
data_citation.display_information( os );
os << "MultiCellDS type: " << MultiCellDS_type << " (Version " << MultiCellDS_version_string << ")" << std::endl
<< "Spatial units: " << spatial_units << std::endl
<< "Time units: " << time_units << std::endl
<< "Current simulation time: " << current_time << " " << time_units << std::endl
<< "Program run time: " << current_runtime << " " << runtime_units << std::endl;
}
void MultiCellDS_Metadata::sync_to_microenvironment( Microenvironment& M )
{
spatial_units = M.spatial_units;
time_units = M.time_units;
return;
}
void MultiCellDS_Metadata::add_to_open_xml_pugi( double current_simulation_time , pugi::xml_document& xml_dom )
{
static bool metadata_initialized_in_dom = false;
// update the current runtime
RUNTIME_TOC();
BioFVM_metadata.current_runtime = runtime_stopwatch_value();
// update the current simulation runtime
current_time = current_simulation_time;
// make sure the main structure is there.
add_MultiCellDS_main_structure_to_open_xml_pugi( xml_dom );
// Find the root.
pugi::xml_node root = xml_dom.child( "MultiCellDS");
// if the root is non-empty, just update the times.
if( metadata_initialized_in_dom )
{
// simulation time
pugi::xml_node node = root.child( "metadata");
node = node.child( "current_time" );
char buffer [1024];
sprintf( buffer , "%f" , BioFVM_metadata.current_time );
node.first_child().set_value( buffer ); // BioFVM_metadata.current_time );
// current wall time
RUNTIME_TOC();
BioFVM_metadata.current_runtime = runtime_stopwatch_value();
node = node.parent();
node = node.child( "current_runtime" );
sprintf( buffer , "%f" , BioFVM_metadata.current_runtime );
node.first_child( ).set_value( buffer );
node = node.parent();
node = node.child( "created" );
std::time_t t_now = std::time(NULL);
std::strftime(buffer , 1024 , "%Y-%m-%dT%H:%M:%SZ" , std::gmtime(&t_now));
// std::strftime(buffer , 1024 , "%Y-%m-%dT%H:%M:%S%z" , std::gmtime(&t_now));
node.first_child( ).set_value( buffer );
node = node.parent();
node = node.child( "last_modified" );
node.first_child( ).set_value( buffer );
return;
}
// The metadata haven't been properly initialized in the DOM.
pugi::xml_attribute attrib = root.attribute( "version" );
attrib.set_value( MultiCellDS_version_string.c_str() );
attrib = root.attribute( "type" );
attrib.set_value( MultiCellDS_type.c_str() );
// fill out metadata
pugi::xml_node node = root.child( "metadata" );
// program information
program.insert_in_open_xml_pugi( node );
// data citation
data_citation.insert_in_open_xml_pugi( node );
char* buffer;
buffer = new char [1024];
// simulation time
node = node.append_child( "current_time" );
attrib = node.append_attribute( "units" );
attrib.set_value( BioFVM_metadata.time_units.c_str() );
sprintf( buffer , "%f" , BioFVM_metadata.current_time );
node.append_child( pugi::node_pcdata ).set_value( buffer );
// current wall time
node = node.parent();
node = node.append_child( "current_runtime" );
attrib = node.append_attribute( "units" );
attrib.set_value( BioFVM_metadata.runtime_units.c_str() );
sprintf( buffer , "%f" , BioFVM_metadata.current_runtime );
node.append_child( pugi::node_pcdata ).set_value( buffer );
// created (timestamp)
node = node.parent();
node = node.append_child( "created" );
std::time_t t_now = std::time(NULL);
std::strftime(buffer , 1024 , "%Y-%m-%dT%H:%M:%SZ" , std::gmtime(&t_now));
// std::strftime(buffer , 1024 , "%Y-%m-%dT%H:%M:%S%z" , std::gmtime(&t_now));
node.append_child( pugi::node_pcdata ).set_value( buffer );
// last modified (timestamp)
node = node.parent();
node = node.append_child( "last_modified" );
node.append_child( pugi::node_pcdata ).set_value( buffer );
delete [] buffer;
metadata_initialized_in_dom = true;
}
/* setting up the main MultiCellDS tree structure */
void add_MultiCellDS_main_structure_to_open_xml_pugi( pugi::xml_document& xml_dom )
{
pugi::xml_node root = xml_dom.child( "MultiCellDS" );
if( !root )
{
root = xml_dom.append_child( "MultiCellDS" );
pugi::xml_attribute attrib = root.append_attribute( "version" );
attrib.set_value( MultiCellDS_version_string.c_str() );
attrib = root.append_attribute( "type" );
attrib.set_value( MultiCellDS_simulation_snapshot_type_string.c_str() );
}
pugi::xml_node node = root.child( "metadata" );
if( !node )
{ root.append_child( "metadata" ); }
node = root.child( "microenvironment" );
if( !node )
{ node = root.append_child( "microenvironment" ); }
node = root.child( "microenvironment" );
if( !node )
{ node = root.append_child( "microenvironment" ); }
node = root.child( "cellular_information" );
if( !node )
{ node = root.append_child( "cellular_information" ); }
return;
}
/* set options */
void set_save_biofvm_mesh_as_matlab( bool newvalue )
{ save_mesh_as_matlab = newvalue; }
void set_save_biofvm_data_as_matlab( bool newvalue )
{ save_density_data_as_matlab = newvalue; }
void set_save_biofvm_cell_data( bool newvalue )
{ save_cell_data = newvalue; }
void set_save_biofvm_cell_data_as_custom_matlab( bool newvalue )
{ save_cells_as_custom_matlab = newvalue; }
/* writing parts of BioFVM to a MultiCellDS file */
void add_BioFVM_substrates_to_open_xml_pugi( pugi::xml_document& xml_dom , std::string filename_base, Microenvironment& M )
{
add_MultiCellDS_main_structure_to_open_xml_pugi( xml_dom );
pugi::xml_node root = biofvm_doc.child( "MultiCellDS" );
pugi::xml_node node = root.child( "microenvironment" );
static bool BioFVM_substrates_initialized_in_dom = false;
// if the TME has not yet been initialized in the DOM, create all the
// right data elements, and populate the meshes.
if( !BioFVM_substrates_initialized_in_dom )
{
char* buffer;
buffer = new char [1024];