From fa21e73f812b8b54f0812fe61715eefa879fd00f Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Tue, 14 Nov 2023 04:57:17 +0000 Subject: [PATCH 01/15] Fix generator args --- chaste_codegen_sbml/generator.py | 34 +++++++++++--------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/chaste_codegen_sbml/generator.py b/chaste_codegen_sbml/generator.py index 298c427..7ffb76d 100644 --- a/chaste_codegen_sbml/generator.py +++ b/chaste_codegen_sbml/generator.py @@ -1,7 +1,7 @@ import sys import os from os.path import basename -from libsbml import * +from libsbml import SBMLReader from . import translator from . import filewriters @@ -46,42 +46,30 @@ def MoveFilesToDirectory(files, new_path): for i in range(len(files)): os.rename(current_path + "/" + files[i], new_path + "/" + files[i]) -def Generate(path_to_file): +def Generate(sbml_file, output_filename=None, output_directory=None): """ Main function. Arguments are: Input, Output Filename, Output Directory. """ - # path_to_file = args[1] - #Get the model from the file reader = SBMLReader() - document = reader.readSBMLFromFile(path_to_file) + document = reader.readSBMLFromFile(sbml_file) model = document.getModel() #Get Name of file - # if(len(args) > 2): - # model_name = args[2] - # else: - # filename = basename(path_to_file) - # split_fname = filename.split('.') - # model_name = split_fname[0] - - filename = basename(path_to_file) - model_name = filename.split('.')[0] + if not output_filename: + output_filename = basename(sbml_file).split('.')[0] # If there are events in the model, we define the class as a cell cycle model. # Otherwise, the model is assumed to be a subcellular reaction network model. - if( translator.IsSrnModel(model) ): - filewriters.WriteSrnModelToFile(model_name, model) + if translator.IsSrnModel(model): + filewriters.WriteSrnModelToFile(output_filename, model) else: - filewriters.WriteCcmModelToFile(model_name, model) + filewriters.WriteCcmModelToFile(output_filename, model) - # if(len(args) > 3): - # output_directory = args[3] - # else: - # output_directory = "." - output_directory = "." + if not output_directory: + output_directory = "." - output_files = GetOutputFilenames(path_to_file, model_name) + output_files = GetOutputFilenames(sbml_file, output_filename) #Move created files if output directory has been specified. MoveFilesToDirectory(output_files, output_directory) From 4350bf752206cea3399342920235372069f9edee Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Tue, 14 Nov 2023 08:08:58 +0000 Subject: [PATCH 02/15] #3 Use ids in reactions --- chaste_codegen_sbml/translator.py | 38 ------------------------------- 1 file changed, 38 deletions(-) diff --git a/chaste_codegen_sbml/translator.py b/chaste_codegen_sbml/translator.py index e4c5c48..24cb914 100644 --- a/chaste_codegen_sbml/translator.py +++ b/chaste_codegen_sbml/translator.py @@ -409,7 +409,6 @@ def GetRulesString(model): rule_id = GetRule(i, model) rule_def = AddTabs(1) + rule_id + " = " + rules_dict[rule_id] + ";\n" rules_string += rule_def - rules_string = GetReactionStringWithSpeciesNamesAndParameterNames(model,rules_string) rules_string = rules_string.replace("max","fmax") rules_string = rules_string.replace("min","fmin") @@ -435,36 +434,6 @@ def GetReactionFormula(n, model): ################################## NEW ###################################################### -def GetReactionStringWithSpeciesNamesAndParameterNames(model,string): - - num_species = model.getNumSpecies() - num_parameters = model.getNumParameters() - num_compartments = model.getNumCompartments() - - for i in range(num_species): - species = model.getSpecies(i) - species_id= species.getId() - species_name = species.getName() - # if (species_name != ''): - # string = string.replace(species_id,species_name) - - for i in range(num_parameters): - parameter = model.getParameter(i) - parameter_id= parameter.getId() - parameter_name = parameter.getName() - # if (parameter_name != ''): - # string = string.replace(parameter_id,parameter_name) - - for i in range(num_compartments): - compartment = model.getCompartment(i) - compartment_id= compartment.getId() - compartment_name = compartment.getName() - # if (compartment_name != ''): - # string = string.replace(compartment_id,compartment_name) - - return string - - def GetSpeciesNames(model,string): num_species = model.getNumSpecies() @@ -555,8 +524,6 @@ def GetReactionString(model): reaction_id = GetReaction(i, model) reaction_formula = GetReactionFormula(i, model) - reaction_formula = GetReactionStringWithSpeciesNamesAndParameterNames(model,reaction_formula) - #Get the relevant strings reaction_params_string = GetReactionParameterString(reaction) reaction_def = GetDoubleDefinition(1, reaction_id, reaction_formula, True) @@ -638,9 +605,6 @@ def GetOdesDictionary(model): #Add reaction products and reactants to the dictionary AddReactionToDictionary(odes_dict, reaction) - for key,value in odes_dict.items(): - odes_dict[key] = GetReactionStringWithSpeciesNamesAndParameterNames(model,odes_dict[key]) - return odes_dict def IsSpeciesDefinedAsOde(species_id, model): @@ -777,8 +741,6 @@ def GetOdesString(model): elif ((species_id_new == k) & (not (species_ode == ''))): species_ode = species_ode + "+ rDY[" + str(j) + "]" - species_ode = GetReactionStringWithSpeciesNamesAndParameterNames(model,species_ode) - compartment_id = species.getCompartment() #Get the corresponding compartment compartment_name = GetCompartmentNameCorrespondingToId(model,compartment_id) From 4942e8418b8cbdf4c96f029df78cca8ac542fc50 Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Tue, 14 Nov 2023 08:17:48 +0000 Subject: [PATCH 03/15] #3 Use species ids --- chaste_codegen_sbml/translator.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/chaste_codegen_sbml/translator.py b/chaste_codegen_sbml/translator.py index 24cb914..b87a48c 100644 --- a/chaste_codegen_sbml/translator.py +++ b/chaste_codegen_sbml/translator.py @@ -434,19 +434,6 @@ def GetReactionFormula(n, model): ################################## NEW ###################################################### -def GetSpeciesNames(model,string): - - num_species = model.getNumSpecies() - - for i in range(num_species): - species = model.getSpecies(i) - species_id= species.getId() - species_name = species.getName().strip().replace(" ","_") - # if (species_name != ''): - # string = string.replace(species_id,species_name) - - return string - def GetParameterNames(model,string): num_parameters = model.getNumParameters() @@ -818,8 +805,6 @@ def GetStateVariableString(model): else: state_variables_string += "\n" - state_variables_string = GetSpeciesNames(model,state_variables_string) - return state_variables_string ##State parameter functions From 449826bef7e6c5c5bfbd96fe1e1de887b8196b42 Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Tue, 14 Nov 2023 08:19:34 +0000 Subject: [PATCH 04/15] #3 Use parameter ids --- chaste_codegen_sbml/translator.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/chaste_codegen_sbml/translator.py b/chaste_codegen_sbml/translator.py index b87a48c..5182fdd 100644 --- a/chaste_codegen_sbml/translator.py +++ b/chaste_codegen_sbml/translator.py @@ -434,19 +434,6 @@ def GetReactionFormula(n, model): ################################## NEW ###################################################### -def GetParameterNames(model,string): - - num_parameters = model.getNumParameters() - - for i in range(num_parameters): - parameter = model.getParameter(i) - parameter_id= parameter.getId() - parameter_name = parameter.getName() - # if (parameter_name != ''): - # string = string.replace(parameter_id,parameter_name) - - return string - def GetReactionNames(model,string): num_reactions = model.getNumReactions() From e51c9b4ff3e204dbe8da8a008d98058774b2637d Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Tue, 14 Nov 2023 08:23:26 +0000 Subject: [PATCH 05/15] #3 Use reaction ids --- chaste_codegen_sbml/translator.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/chaste_codegen_sbml/translator.py b/chaste_codegen_sbml/translator.py index 5182fdd..7a4a734 100644 --- a/chaste_codegen_sbml/translator.py +++ b/chaste_codegen_sbml/translator.py @@ -434,20 +434,6 @@ def GetReactionFormula(n, model): ################################## NEW ###################################################### -def GetReactionNames(model,string): - - num_reactions = model.getNumReactions() - - for i in range(num_reactions): - reaction = model.getReaction(i) - reaction_id= reaction.getId() - reaction_name = reaction.getName() - # if (reaction_name != ''): - # string = string.replace(reaction_id,reaction_name) - - return string - - def GetCompartmentNameCorrespondingToId(model,string): compartment_id = string @@ -511,8 +497,6 @@ def GetReactionString(model): reactions_string += "\n" - reactions_string = GetReactionNames(model,reactions_string) - return reactions_string @@ -668,9 +652,6 @@ def GetOdesString(model): if( (species_id in odes_dict)&(not species.getBoundaryCondition()) ): #species defined by algebraic rules are not in odes_dict species_ode = odes_dict[species_id] #Get the corresponding ode - ######### EDITED ############# - species_ode = GetReactionNames(model,species_ode) - # species = model.getSpecies(key) compartment_id = species.getCompartment() #Get the corresponding compartment From 51aac104fc7fd7cd5bfd2c84f6759f31e3bdcb04 Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Tue, 14 Nov 2023 08:31:03 +0000 Subject: [PATCH 06/15] #3 Using more reaction ids --- chaste_codegen_sbml/translator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/chaste_codegen_sbml/translator.py b/chaste_codegen_sbml/translator.py index 7a4a734..a74d747 100644 --- a/chaste_codegen_sbml/translator.py +++ b/chaste_codegen_sbml/translator.py @@ -420,7 +420,6 @@ def GetReaction(n, model): """ Get the ID of a reaction to use as a variable name. """ reaction = model.getReaction(n) reaction_id = reaction.getId() - reaction_name = reaction.getName() return reaction_id def GetReactionFormula(n, model): From 85841dd616bc8336b9f1aa973209930f87793fc1 Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Tue, 14 Nov 2023 08:36:01 +0000 Subject: [PATCH 07/15] #3 Simplify imports --- chaste_codegen_sbml/filewriters.py | 3 --- chaste_codegen_sbml/generator.py | 4 +--- chaste_codegen_sbml/translator.py | 4 ---- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/chaste_codegen_sbml/filewriters.py b/chaste_codegen_sbml/filewriters.py index 337f212..13acc79 100644 --- a/chaste_codegen_sbml/filewriters.py +++ b/chaste_codegen_sbml/filewriters.py @@ -1,6 +1,3 @@ -import sys -import os.path -from libsbml import * from . import translator # Script with functions that will write all the necessary SBML info into Chaste .cpp diff --git a/chaste_codegen_sbml/generator.py b/chaste_codegen_sbml/generator.py index 7ffb76d..c9d6fb2 100644 --- a/chaste_codegen_sbml/generator.py +++ b/chaste_codegen_sbml/generator.py @@ -1,6 +1,4 @@ -import sys import os -from os.path import basename from libsbml import SBMLReader from . import translator from . import filewriters @@ -57,7 +55,7 @@ def Generate(sbml_file, output_filename=None, output_directory=None): #Get Name of file if not output_filename: - output_filename = basename(sbml_file).split('.')[0] + output_filename = os.path.basename(sbml_file).split('.')[0] # If there are events in the model, we define the class as a cell cycle model. # Otherwise, the model is assumed to be a subcellular reaction network model. diff --git a/chaste_codegen_sbml/translator.py b/chaste_codegen_sbml/translator.py index a74d747..3b503ad 100644 --- a/chaste_codegen_sbml/translator.py +++ b/chaste_codegen_sbml/translator.py @@ -1,7 +1,3 @@ -import sys -import os.path -from libsbml import * - # Script with useful functions to extract the relevant information from an # SBML file needed to define an ODE Model in Chaste From a0b44b56eb343ef686bf5eb7d6bd319ef62b461f Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Tue, 14 Nov 2023 08:53:47 +0000 Subject: [PATCH 08/15] #3 Fix num state vars --- chaste_codegen_sbml/filewriters.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/chaste_codegen_sbml/filewriters.py b/chaste_codegen_sbml/filewriters.py index 13acc79..9c08480 100644 --- a/chaste_codegen_sbml/filewriters.py +++ b/chaste_codegen_sbml/filewriters.py @@ -256,13 +256,11 @@ def GetClassDefinition(filename, model): ode_name = GetOdeSystemName(filename) ##### EDITED ###################### - in this case, the rules are also variables (as totals of other variables) - odes_dict = translator.GetOdesDictionary(model) - rules_dict = translator.GetRulesDictionary(model) - num_species = len(odes_dict) + len(rules_dict) + num_state_vars = len(translator.GetOdesDictionary(model)) class_defn_str = (translator.GetBlockCommentDefinition(0, "SBML ODE System", True) + ode_name + "::" + ode_name + " (std::vector stateVariables)\n" + - translator.AddTabs(1) + ": AbstractOdeSystem(" + str(num_species) + ")\n" + translator.AddTabs(1) + ": AbstractOdeSystem(" + str(num_state_vars) + ")\n" "{\n" + translator.AddTabs(1) + "mpSystemInfo.reset(new CellwiseOdeSystemInformation<" + ode_name + ">);\n" "\n" + From 4f3c83769cc1c4da50128855f3158f31e9759c37 Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Tue, 28 Nov 2023 01:27:05 +0000 Subject: [PATCH 09/15] Add srn wrapper templates --- .../templates/SbmlSrnWrapperModel.cpp | 183 ++++++++++++++++++ .../templates/SbmlSrnWrapperModel.hpp | 125 ++++++++++++ 2 files changed, 308 insertions(+) create mode 100644 chaste_codegen_sbml/templates/SbmlSrnWrapperModel.cpp create mode 100644 chaste_codegen_sbml/templates/SbmlSrnWrapperModel.hpp diff --git a/chaste_codegen_sbml/templates/SbmlSrnWrapperModel.cpp b/chaste_codegen_sbml/templates/SbmlSrnWrapperModel.cpp new file mode 100644 index 0000000..e4bd3ab --- /dev/null +++ b/chaste_codegen_sbml/templates/SbmlSrnWrapperModel.cpp @@ -0,0 +1,183 @@ +/* + +Copyright (c) 2005-2013, University of Oxford. +All rights reserved. + +University of Oxford means the Chancellor, Masters and Scholars of the +University of Oxford, having an administrative office at Wellington +Square, Oxford OX1 2JD, UK. + +This file is part of Chaste. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * 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. + * Neither the name of the University of Oxford 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 SBMLSRNWRAPPERMODEL_CPP_ +#define SBMLSRNWRAPPERMODEL_CPP_ + +//#include "UblasIncludes.hpp" +#include "SbmlSrnWrapperModel.hpp" +#include "CellCycleModelOdeSolver.hpp" +#include "RungeKutta4IvpOdeSolver.hpp" +#include "AbstractOdeSrnModel.hpp" +#include "CvodeAdaptor.hpp" +//#include "Exception.hpp" +#include "Debug.hpp" + + +template +SbmlSrnWrapperModel::SbmlSrnWrapperModel(boost::shared_ptr pOdeSolver) + : AbstractOdeSrnModel(SIZE, pOdeSolver) +{ + + // TODO add CVODE solver. See VanLeeuwen CCM in trunk + + if (mpOdeSolver == boost::shared_ptr()) + { + + #ifdef CHASTE_CVODE + mpOdeSolver = CellCycleModelOdeSolver, CvodeAdaptor>::Instance(); + mpOdeSolver->Initialise(); + // Chaste solvers always check for stopping events, CVODE needs to be instructed to do so + mpOdeSolver->CheckForStoppingEvents(); + mpOdeSolver->SetMaxSteps(10000); + #else + mpOdeSolver = CellCycleModelOdeSolver, RungeKutta4IvpOdeSolver>::Instance(); + mpOdeSolver->Initialise(); + SetDt(0.0001); // This is small enough for both examples to converge + #endif //CHASTE_CVODE + } + + assert(mpOdeSolver->IsSetUp()); +} + +//New method for copy constructor +template +SbmlSrnWrapperModel::SbmlSrnWrapperModel(const SbmlSrnWrapperModel& rModel) + : AbstractOdeSrnModel(rModel) +{ + /* + * Set each member variable of the new SRN model that inherits + * its value from the parent. + * + * Note 1: some of the new SRN model's member variables + * will already have been correctly initialized in its constructor. + * + * Note 2: one or more of the new SRN model's member variables + * may be set/overwritten as soon as InitialiseDaughterCell() is called on + * the new SRN model. + * + * Note 3: Only set the variables defined in this class. Variables defined + * in parent classes will be defined there. + */ + + assert(rModel.GetOdeSystem()); + SetOdeSystem(new SBMLODE(rModel.GetOdeSystem()->rGetStateVariables())); +} + +template +AbstractSrnModel* SbmlSrnWrapperModel::CreateSrnModel() +{ + return new SbmlSrnWrapperModel(*this); +} + + +template +void SbmlSrnWrapperModel::SimulateToCurrentTime() +{ + + assert(mpOdeSystem != NULL); + assert(mpCell != NULL); + + /* Custom behaviour: store the state variables as cell data and set any parameters + * using cell data, so that we can visualise different concentrations in Paraview. + */ + + std::vector parameterNames = mpOdeSystem->rGetParameterNames(); + //Set parameters that need to be set + for (unsigned i = 0; i < parameterNames.size(); i++) + { + std::string parameterName = parameterNames[i]; + + //Get the value from cell data + double parameterValue = mpCell->GetCellData()->GetItem(parameterName); + + mpOdeSystem->SetParameter(parameterName, parameterValue); + } + + std::vector stateVariableNames = mpOdeSystem->rGetStateVariableNames(); + + for (unsigned i = 0; i < stateVariableNames.size(); i++) + { + std::string stateName = stateVariableNames[i]; + double stateValue = mpOdeSystem->rGetStateVariables()[i]; + + //Set current state variable value as cell data + mpCell->GetCellData()->SetItem(stateName, stateValue); + } + + + // run the ODE simulation as needed + AbstractOdeSrnModel::SimulateToCurrentTime(); + + +} + +template +void SbmlSrnWrapperModel::Initialise() +{ + AbstractOdeSrnModel::Initialise(new SBMLODE); + + //Initialise cell data + assert(mpOdeSystem != NULL); + assert(mpCell != NULL); + + /* Custom behaviour: store the state variables as cell data and set any parameters + * using cell data, so that we can visualise different concentrations in Paraview. + */ + + std::vector stateVariableNames = mpOdeSystem->rGetStateVariableNames(); + + for (unsigned i = 0; i < stateVariableNames.size(); i++) + { + std::string stateName = stateVariableNames[i]; + double stateValue = mpOdeSystem->rGetStateVariables()[i]; + + //Set current state variable value as cell data + mpCell->GetCellData()->SetItem(stateName, stateValue); + } + +} + + +template +void SbmlSrnWrapperModel::OutputSrnModelParameters(out_stream& rParamsFile) +{ + // No new parameters to output. + + // Call direct parent class + AbstractOdeSrnModel::OutputSrnModelParameters(rParamsFile); +} + +#endif /* SBMLSRNWRAPPERMODEL_CPP_ */ diff --git a/chaste_codegen_sbml/templates/SbmlSrnWrapperModel.hpp b/chaste_codegen_sbml/templates/SbmlSrnWrapperModel.hpp new file mode 100644 index 0000000..97a749d --- /dev/null +++ b/chaste_codegen_sbml/templates/SbmlSrnWrapperModel.hpp @@ -0,0 +1,125 @@ +/* + +Copyright (c) 2005-2013, University of Oxford. +All rights reserved. + +University of Oxford means the Chancellor, Masters and Scholars of the +University of Oxford, having an administrative office at Wellington +Square, Oxford OX1 2JD, UK. + +This file is part of Chaste. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * 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. + * Neither the name of the University of Oxford 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 SBMLSRNWRAPPERMODEL_HPP_ +#define SBMLSRNWRAPPERMODEL_HPP_ + +#include "ChasteSerialization.hpp" +#include + +//#include "Goldbeter1991OdeSystem.hpp" +#include "AbstractOdeSrnModel.hpp" + + +/** + * A wrapper around AbstractOdeSrnModel that can be templated on the ODE system for + * use with SBML generated models + */ +template +class SbmlSrnWrapperModel : public AbstractOdeSrnModel +{ +private: + + /** Needed for serialization. */ + friend class boost::serialization::access; + /** + * Archive the cell-cycle model and member variables. + * + * @param archive the archive + * @param version the current version of this class + */ + template + void serialize(Archive & archive, const unsigned int version) + { + archive & boost::serialization::base_object(*this); + } + +protected: + /** + * Protected copy-constructor for use by CreateSrnModel. The only way for external code to create a copy of a SRN model + * is by calling that method, to ensure that a model of the correct subclass is created. + * This copy-constructor helps subclasses to ensure that all member variables are correctly copied when this happens. + * + * This method is called by child classes to set member variables for a daughter cell upon cell division. + * Note that the parent SRN model will have had ResetForDivision() called just before CreateSrnModel() is called, + * so performing an exact copy of the parent is suitable behaviour. Any daughter-cell-specific initialisation + * can be done in InitialiseDaughterCell(). + * + * @param rModel the SRN model to copy. + */ + SbmlSrnWrapperModel(const SbmlSrnWrapperModel& rModel); + + +public: + + /** + * Default constructor calls base class. + * + * @param pOdeSolver An optional pointer to a cell-cycle model ODE solver object (allows the use of different ODE solvers) + */ + SbmlSrnWrapperModel(boost::shared_ptr pOdeSolver = boost::shared_ptr()); + + + /** + * Overridden builder method to create new copies of + * this srn model. + * + * @return Returns a copy of the current srn model. + */ + AbstractSrnModel* CreateSrnModel(); + + /** + * Initialise the cell-cycle model at the start of a simulation. + * + * This overridden method sets up a new Ode system. + */ + void Initialise(); // override + + /** + * Overridden SimulateToTime() method for custom behaviour + */ + void SimulateToCurrentTime(); + + /** + * Outputs cell-cycle model parameters to file. + * + * @param rParamsFile the file stream to which the parameters are output + */ + void OutputSrnModelParameters(out_stream& rParamsFile); + + +}; + +#endif /* SBMLSRNWRAPPERMODEL_HPP_ */ From 3330ac58a80e18da668b899354df47d0ea54e142 Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Tue, 28 Nov 2023 01:40:44 +0000 Subject: [PATCH 10/15] Add GetStateVariable to srn template --- chaste_codegen_sbml/templates/SbmlSrnWrapperModel.cpp | 7 +++++++ chaste_codegen_sbml/templates/SbmlSrnWrapperModel.hpp | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/chaste_codegen_sbml/templates/SbmlSrnWrapperModel.cpp b/chaste_codegen_sbml/templates/SbmlSrnWrapperModel.cpp index e4bd3ab..2811363 100644 --- a/chaste_codegen_sbml/templates/SbmlSrnWrapperModel.cpp +++ b/chaste_codegen_sbml/templates/SbmlSrnWrapperModel.cpp @@ -180,4 +180,11 @@ void SbmlSrnWrapperModel::OutputSrnModelParameters(out_stream& rP AbstractOdeSrnModel::OutputSrnModelParameters(rParamsFile); } +template +double SbmlSrnWrapperModel::GetStateVariable(const std::string& rName) +{ + assert(mpOdeSystem != nullptr); + return mpOdeSystem->GetStateVariable(rName); +} + #endif /* SBMLSRNWRAPPERMODEL_CPP_ */ diff --git a/chaste_codegen_sbml/templates/SbmlSrnWrapperModel.hpp b/chaste_codegen_sbml/templates/SbmlSrnWrapperModel.hpp index 97a749d..712722a 100644 --- a/chaste_codegen_sbml/templates/SbmlSrnWrapperModel.hpp +++ b/chaste_codegen_sbml/templates/SbmlSrnWrapperModel.hpp @@ -119,6 +119,12 @@ class SbmlSrnWrapperModel : public AbstractOdeSrnModel */ void OutputSrnModelParameters(out_stream& rParamsFile); + /** + * @return the value of a given state variable. + * + * @param rName the name of the state variable + */ + double GetStateVariable(const std::string& rName); }; From bb2a89bd489d54c9b3e846a6baf7f5e31f6861d1 Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Tue, 5 Dec 2023 08:40:03 +0000 Subject: [PATCH 11/15] Add hpp jinja templates --- .../templates/common/hpp/base.j2 | 12 +++++ .../templates/common/hpp/class_declaration.j2 | 29 ++++++++++++ .../templates/common/hpp/comments.j2 | 11 +++++ .../templates/common/hpp/includes.j2 | 8 ++++ .../templates/common/hpp/serialization.j2 | 44 +++++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 chaste_codegen_sbml/templates/common/hpp/base.j2 create mode 100644 chaste_codegen_sbml/templates/common/hpp/class_declaration.j2 create mode 100644 chaste_codegen_sbml/templates/common/hpp/comments.j2 create mode 100644 chaste_codegen_sbml/templates/common/hpp/includes.j2 create mode 100644 chaste_codegen_sbml/templates/common/hpp/serialization.j2 diff --git a/chaste_codegen_sbml/templates/common/hpp/base.j2 b/chaste_codegen_sbml/templates/common/hpp/base.j2 new file mode 100644 index 0000000..9138a15 --- /dev/null +++ b/chaste_codegen_sbml/templates/common/hpp/base.j2 @@ -0,0 +1,12 @@ +#ifndef {% filter upper %}{{class_name}}_HPP_{% endfilter %} +#define {% filter upper %}{{class_name}}_HPP_{% endfilter %} + +{% include "common/hpp/comments.j2" %} + +{% include "common/hpp/includes.j2" %} + +{% include "common/hpp/class_declaration.j2" %} + +{% include "common/hpp/serialization.j2" %} + +#endif // {% filter upper %}{{class_name}}_HPP_{% endfilter %} diff --git a/chaste_codegen_sbml/templates/common/hpp/class_declaration.j2 b/chaste_codegen_sbml/templates/common/hpp/class_declaration.j2 new file mode 100644 index 0000000..381e9e4 --- /dev/null +++ b/chaste_codegen_sbml/templates/common/hpp/class_declaration.j2 @@ -0,0 +1,29 @@ +class {{class_name}} : public AbstractOdeSystem +{ +private: + /* Initialise compartments and values. */ + double cell; + + /* Initialise model parameters. */ + {%for state_var in state_vars -%} + double {{state_var}}; + {%endfor -%}; + + friend class boost::serialization::access; + template + void serialize(Archive &archive, const unsigned int version) + { + archive &boost::serialization::base_object(*this); + } + +public: + /* Default constructor. */ + {{class_name}}(std::vector stateVariables = std::vector()); + + /* Destructor. */ + ~{{class_name}}(); + + void Init(); + + void EvaluateYDerivatives(double time, const std::vector &rY, std::vector &rDY); +}; diff --git a/chaste_codegen_sbml/templates/common/hpp/comments.j2 b/chaste_codegen_sbml/templates/common/hpp/comments.j2 new file mode 100644 index 0000000..9f9aecf --- /dev/null +++ b/chaste_codegen_sbml/templates/common/hpp/comments.j2 @@ -0,0 +1,11 @@ +//! @file +//! +//! This source file was generated from SBML by chaste_codegen_sbml version {{converter_version}} +//! +//! Model: {{model_name}} +//! +//! Processed by chaste_codegen_sbml: https://github.com/Chaste/chaste-codegen-sbml +//! (translator: chaste_codegen_sbml, model type: {{model_type}}) +//! on {{generation_date}} +//! +//! \ No newline at end of file diff --git a/chaste_codegen_sbml/templates/common/hpp/includes.j2 b/chaste_codegen_sbml/templates/common/hpp/includes.j2 new file mode 100644 index 0000000..4a71cbd --- /dev/null +++ b/chaste_codegen_sbml/templates/common/hpp/includes.j2 @@ -0,0 +1,8 @@ +#include "AbstractOdeSystem.hpp" +#include "ChasteSerialization.hpp" + +#include +#include + +#include +#include \ No newline at end of file diff --git a/chaste_codegen_sbml/templates/common/hpp/serialization.j2 b/chaste_codegen_sbml/templates/common/hpp/serialization.j2 new file mode 100644 index 0000000..7b5e5fe --- /dev/null +++ b/chaste_codegen_sbml/templates/common/hpp/serialization.j2 @@ -0,0 +1,44 @@ +namespace +{ + namespace serialization + { + /* Serialize information required to construct a {{class_name}}. */ + template + inline void save_construct_data( + Archive &ar, + const {{class_name}} *t, + const unsigned int file_version) + { + const std::vector state_variables = t->rGetConstStateVariables(); + ar & state_variables; + } + + /* De-serialize constructor parameters and intiialise a {{class_name}}. */ + template + inline void load_construct_data( + Archive &ar, + {{class_name}} *t, + const unsigned int file_version) + { + std::vector state_variables; + ar & state_variables; + + // Invoke inplace constructor to initialise instance + ::new (t) {{class_name}}(state_variables); + } + } +} + +/* Define SRN model using Wrappers. */ +#include "SbmlSrnWrapperModel.hpp" +#include "SbmlSrnWrapperModel.cpp" + +typedef SbmlSrnWrapperModel<{{class_name}}, {{num_state_vars}}> Goldbeter1991SrnModel; + +// Declare identifiers for the serializer +#include "SerializationExportWrapper.hpp" +CHASTE_CLASS_EXPORT({{class_name}}) +EXPORT_TEMPLATE_CLASS2(SbmlSrnWrapperModel, {{class_name}}, {{num_state_vars}}) + +#include "CellCycleModelOdeSolverExportWrapper.hpp" +EXPORT_CELL_CYCLE_MODEL_ODE_SOLVER({{class_name}}) \ No newline at end of file From 3a4e2f1c8192e1fd50463eeccca5e7df5a39f85f Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Mon, 20 Jan 2025 13:16:58 +0000 Subject: [PATCH 12/15] #3 Rename jinja templates --- .../templates/common/hpp/{base.j2 => base.hpp} | 8 ++++---- .../common/hpp/{comments.j2 => blurb.hpp} | 0 ...class_declaration.j2 => class_declaration.hpp} | 0 .../common/hpp/{includes.j2 => includes.hpp} | 0 .../hpp/{serialization.j2 => serialization.hpp} | 0 chaste_codegen_sbml/templates/normal_model.cpp | 15 +++++++++++++++ chaste_codegen_sbml/templates/normal_model.hpp | 10 ++++++++++ 7 files changed, 29 insertions(+), 4 deletions(-) rename chaste_codegen_sbml/templates/common/hpp/{base.j2 => base.hpp} (52%) rename chaste_codegen_sbml/templates/common/hpp/{comments.j2 => blurb.hpp} (100%) rename chaste_codegen_sbml/templates/common/hpp/{class_declaration.j2 => class_declaration.hpp} (100%) rename chaste_codegen_sbml/templates/common/hpp/{includes.j2 => includes.hpp} (100%) rename chaste_codegen_sbml/templates/common/hpp/{serialization.j2 => serialization.hpp} (100%) create mode 100644 chaste_codegen_sbml/templates/normal_model.cpp create mode 100644 chaste_codegen_sbml/templates/normal_model.hpp diff --git a/chaste_codegen_sbml/templates/common/hpp/base.j2 b/chaste_codegen_sbml/templates/common/hpp/base.hpp similarity index 52% rename from chaste_codegen_sbml/templates/common/hpp/base.j2 rename to chaste_codegen_sbml/templates/common/hpp/base.hpp index 9138a15..c96b48b 100644 --- a/chaste_codegen_sbml/templates/common/hpp/base.j2 +++ b/chaste_codegen_sbml/templates/common/hpp/base.hpp @@ -1,12 +1,12 @@ #ifndef {% filter upper %}{{class_name}}_HPP_{% endfilter %} #define {% filter upper %}{{class_name}}_HPP_{% endfilter %} -{% include "common/hpp/comments.j2" %} +{% include "common/hpp/blurb.hpp" %} -{% include "common/hpp/includes.j2" %} +{% include "common/hpp/includes.hpp" %} -{% include "common/hpp/class_declaration.j2" %} +{% include "common/hpp/class_declaration.hpp" %} -{% include "common/hpp/serialization.j2" %} +{% include "common/hpp/serialization.hpp" %} #endif // {% filter upper %}{{class_name}}_HPP_{% endfilter %} diff --git a/chaste_codegen_sbml/templates/common/hpp/comments.j2 b/chaste_codegen_sbml/templates/common/hpp/blurb.hpp similarity index 100% rename from chaste_codegen_sbml/templates/common/hpp/comments.j2 rename to chaste_codegen_sbml/templates/common/hpp/blurb.hpp diff --git a/chaste_codegen_sbml/templates/common/hpp/class_declaration.j2 b/chaste_codegen_sbml/templates/common/hpp/class_declaration.hpp similarity index 100% rename from chaste_codegen_sbml/templates/common/hpp/class_declaration.j2 rename to chaste_codegen_sbml/templates/common/hpp/class_declaration.hpp diff --git a/chaste_codegen_sbml/templates/common/hpp/includes.j2 b/chaste_codegen_sbml/templates/common/hpp/includes.hpp similarity index 100% rename from chaste_codegen_sbml/templates/common/hpp/includes.j2 rename to chaste_codegen_sbml/templates/common/hpp/includes.hpp diff --git a/chaste_codegen_sbml/templates/common/hpp/serialization.j2 b/chaste_codegen_sbml/templates/common/hpp/serialization.hpp similarity index 100% rename from chaste_codegen_sbml/templates/common/hpp/serialization.j2 rename to chaste_codegen_sbml/templates/common/hpp/serialization.hpp diff --git a/chaste_codegen_sbml/templates/normal_model.cpp b/chaste_codegen_sbml/templates/normal_model.cpp new file mode 100644 index 0000000..095d98b --- /dev/null +++ b/chaste_codegen_sbml/templates/normal_model.cpp @@ -0,0 +1,15 @@ +{% include "Shared/cpp/header_comments" %} +{% include "Shared/cpp/includes" %} +{% include "Shared/cpp/lookup_tables" %} +{% include "Shared/cpp/UseCellMLDefaultStimulus" %} +{% include "Shared/cpp/GetIntracellularCalciumConcentration" %} +{%- include "Shared/cpp/constructor_declaration" %} +{% include "Shared/cpp/constructor_body" %} +{% include "Shared/cpp/destructor" %} +{% include "Shared/cpp/GetLookupTableCollection" %} +{% include "Shared/cpp/VerifyStateVariables" %} +{% include "Shared/cpp/GetIIonic" %} +{% include "Shared/cpp/EvaluateYDerivatives" %} +{%- include "Shared/cpp/ComputeDerivedQuantities" %} +{% include "Shared/cpp/OdeSystemInformation" %} +{% include "Shared/cpp/CHASTE_CLASS_EXPORT" %} \ No newline at end of file diff --git a/chaste_codegen_sbml/templates/normal_model.hpp b/chaste_codegen_sbml/templates/normal_model.hpp new file mode 100644 index 0000000..1b0c1b4 --- /dev/null +++ b/chaste_codegen_sbml/templates/normal_model.hpp @@ -0,0 +1,10 @@ +{% include "Shared/hpp/header_comments" %} +{% include "Shared/hpp/includes" %} +#include "{{base_class}}.hpp" +{% include "Shared/hpp/class_declaration" %} +{% include "Shared/hpp/DefaultStimulus_IntracellularCalciumConcentration" %} + {{class_name}}(boost::shared_ptr pSolver, boost::shared_ptr pIntracellularStimulus); +{% include "Shared/hpp/destructor_verify_state_variables_GetIIonic" %} + void EvaluateYDerivatives(double {{free_variable.var_name}}, const {{vector_decl}} rY, {{vector_decl}} rDY); +{% include "Shared/hpp/ComputeDerivedQuantities" %} +{% include "Shared/hpp/CHASTE_CLASS_EXPORT" %} \ No newline at end of file From 04bfaea96a0da2a14f5f98997b367b770de790f3 Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Mon, 20 Jan 2025 14:35:53 +0000 Subject: [PATCH 13/15] #3 Update license and readme --- LICENSE | 2 +- README.md | 34 ++++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/LICENSE b/LICENSE index 7903d62..614a8cb 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2023, Chaste - Cancer Heart and Soft Tissue Environment +Copyright (c) 2025, Chaste - Cancer Heart and Soft Tissue Environment Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.md b/README.md index 7988791..d24c10b 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,44 @@ -# Chaste code generation from SBML +# SBML → Chaste -The `chaste_codegen_sbml` module takes [SBML](https://synonym.caltech.edu/) models as input and uses [libSBML](https://synonym.caltech.edu/software/libsbml/) to parse the models and output C++ code for Chaste. +`chaste_codegen_sbml` converts [SBML](https://synonym.caltech.edu/) models to C++ Chaste code. It relies on [libSBML](https://synonym.caltech.edu/software/libsbml/) for parsing SBML. ## Installation -### User install Installation via [`pipx`](https://pipx.pypa.io/) is recommended ``` pipx install git+https://github.com/Chaste/chaste-codegen-sbml@develop ``` -Alternatively, install via `pip` (optionally in a virtual environment) +Alternatively, install via `pip` ``` -# Create and activate a virtual environment +# Create and activate a virtual environment (optional) python -m venv sbml-venv +source sbml-venv/bin/activate # Install pip install git+https://github.com/Chaste/chaste-codegen-sbml@develop ``` -### Developer install -Clone the repository and install the package in editable mode along with the `dev` dependencies: +## Usage +``` +chaste_codegen_sbml [-h] +``` + +## Development +### Getting the code ``` +# Clone the repository git clone https://github.com/Chaste/chaste-codegen-sbml cd chaste-codegen-sbml -pip install -e .[dev] + +# Create and activate a virtual environment +python -m venv venv +source venv/bin/activate + +# Install in editable mode along with dev dependencies +pip install -e ."[dev]" ``` -## Usage +### Running tests ``` -chaste_codegen_sbml [-h] +python -m pytest ``` - -## Testing From 2d414e79dcb0a915e3f60eb96cf9a5360836151e Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Mon, 20 Jan 2025 15:00:38 +0000 Subject: [PATCH 14/15] #3 Update dependency versions --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 76f46f9..2667cc2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,13 +11,13 @@ authors = [{ name = "Kwabena Amponsah" }, { name = "James Osborne" }] requires-python = ">=3.8" -dependencies = ["Jinja2 >=2.11,<3", "python-libsbml >=5.20,<6"] +dependencies = ["Jinja2 >=3.0,<4", "python-libsbml >=5.20,<6"] [project.optional-dependencies] dev = [ "flake8==3.9", "isort==5.8", - "Jinja2==2.11", + "Jinja2==3.1", "pytest==6.2", "python-libsbml==5.20", ] From a95332e821e8f942deb08935d9a793beae283e24 Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Mon, 20 Jan 2025 15:01:23 +0000 Subject: [PATCH 15/15] #3 Add test data for Goldbeter1991 model --- .../data/Goldbeter1991/Goldbeter1991.xml | 464 ++++++++++++++++++ .../Goldbeter1991/Goldbeter1991SrnModel.cpp | 125 +++++ .../Goldbeter1991/Goldbeter1991SrnModel.hpp | 89 ++++ 3 files changed, 678 insertions(+) create mode 100644 chaste_codegen_sbml/tests/data/Goldbeter1991/Goldbeter1991.xml create mode 100644 chaste_codegen_sbml/tests/data/Goldbeter1991/Goldbeter1991SrnModel.cpp create mode 100644 chaste_codegen_sbml/tests/data/Goldbeter1991/Goldbeter1991SrnModel.hpp diff --git a/chaste_codegen_sbml/tests/data/Goldbeter1991/Goldbeter1991.xml b/chaste_codegen_sbml/tests/data/Goldbeter1991/Goldbeter1991.xml new file mode 100644 index 0000000..74d9201 --- /dev/null +++ b/chaste_codegen_sbml/tests/data/Goldbeter1991/Goldbeter1991.xml @@ -0,0 +1,464 @@ + + + + + +
Goldbeter - Min Mit Oscil
+

Minimal cascade model for the mitotic oscillator involving cyclin and cdc2 kinase.

+
+

This model has been generated by MathSBML 2.4.6 (14-January-2005) 14-January-2005 18:33:39.806932.

+
+

This model is described in the article:

+ +
Goldbeter A.
+
Proc. Natl. Acad. Sci. U.S.A. 1991; 88(20):9107-11
+

Abstract:

+

A minimal model for the mitotic oscillator is presented. The model, built on recent experimental advances, is based on the cascade of post-translational modification that modulates the activity of cdc2 kinase during the cell cycle. The model pertains to the situation encountered in early amphibian embryos, where the accumulation of cyclin suffices to trigger the onset of mitosis. In the first cycle of the bicyclic cascade model, cyclin promotes the activation of cdc2 kinase through reversible dephosphorylation, and in the second cycle, cdc2 kinase activates a cyclin protease by reversible phosphorylation. That cyclin activates cdc2 kinase while the kinase triggers the degradation of cyclin has suggested that oscillations may originate from such a negative feedback loop [Félix, M. A., Labbé, J. C., Dorée, M., Hunt, T. & Karsenti, E. (1990) Nature (London) 346, 379-382]. This conjecture is corroborated by the model, which indicates that sustained oscillations of the limit cycle type can arise in the cascade, provided that a threshold exists in the activation of cdc2 kinase by cyclin and in the activation of cyclin proteolysis by cdc2 kinase. The analysis shows how miototic oscillations may readily arise from time lags associated with these thresholds and from the delayed negative feedback provided by cdc2-induced cyclin degradation. A mechanism for the origin of the thresholds is proposed in terms of the phenomenon of zero-order ultrasensitivity previously described for biochemical systems regulated by covalent modification.

+
+
+

This model is hosted on BioModels Database + and identified by: BIOMD0000000003 + .

+

To cite BioModels Database, please use: BioModels Database: An enhanced, curated and annotated resource for published quantitative kinetic models + .

+
+

To the extent possible under law, all copyright and related or neighbouring rights to this encoded model have been dedicated to the public domain worldwide. Please refer to CC0 Public Domain Dedication + for more information.

+
+ + +
+ + + + + + + + Shapiro + Bruce + + bshapiro@jpl.nasa.gov + + NASA Jet Propulsion Laboratory + + + + + Chelliah + Vijayalakshmi + + viji@ebi.ac.uk + + EMBL-EBI + + + + + + 2005-02-06T23:39:40Z + + + 2013-05-16T14:38:01Z + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + C + VM1 + + + + + C + Kc + + -1 + + + + + + + + + M + VM3 + + + + + + + + + + + + + + + + + + + + + + + + + cell + vi + + + + + + + + + + + + + + + + + + + + + + + + + + + C + cell + kd + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + C + cell + vd + X + + + + + C + Kd + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + cell + + + 1 + + + -1 + M + + + V1 + + + + + K1 + + + -1 + M + + 1 + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + cell + M + V2 + + + + + K2 + M + + -1 + + + + + + + + + + + + + + + + + + cell + V3 + + + 1 + + + -1 + X + + + + + + + K3 + + + -1 + X + + 1 + + -1 + + + + + + + + + + + + + + + + + cell + V4 + X + + + + + K4 + X + + -1 + + + + + + + + + + +
+
\ No newline at end of file diff --git a/chaste_codegen_sbml/tests/data/Goldbeter1991/Goldbeter1991SrnModel.cpp b/chaste_codegen_sbml/tests/data/Goldbeter1991/Goldbeter1991SrnModel.cpp new file mode 100644 index 0000000..7f3f731 --- /dev/null +++ b/chaste_codegen_sbml/tests/data/Goldbeter1991/Goldbeter1991SrnModel.cpp @@ -0,0 +1,125 @@ +#include "Goldbeter1991SrnModel.hpp" +#include "CellwiseOdeSystemInformation.hpp" +/* SBML ODE System */ +Goldbeter1991OdeSystem::Goldbeter1991OdeSystem (std::vector stateVariables) + : AbstractOdeSystem(3) +{ + mpSystemInfo.reset(new CellwiseOdeSystemInformation); + + Init(); + + SetDefaultInitialCondition(0, 0.01); + SetDefaultInitialCondition(1, 0.01); + SetDefaultInitialCondition(2, 0.01); + + + if (stateVariables != std::vector()) { + SetStateVariables(stateVariables); + } +} + +Goldbeter1991OdeSystem::~Goldbeter1991OdeSystem() +{ +} + +void Goldbeter1991OdeSystem::Init() + { + /* Initialise the parameters. */ + cell = 1.0; + V1 = 0.0; + V3 = 0.0; + VM1 = 3.0; + VM3 = 1.0; + Kc = 0.5; +} + +void Goldbeter1991OdeSystem::EvaluateYDerivatives(double time, const std::vector& rY, std::vector& rDY) +{ + /* Define state variables */ + double C = rY[0]; // Cyclin + double M = rY[1]; // cdc_2_kinase + double X = rY[2]; // Cyclin_Protease + + /* Define state parameters */ + + /* Define algebraic rules. */ + V1 = C * VM1 * pow(C + Kc, -1); + V3 = M * VM3; + + /* Define the reactions in this model. */ + // creation of cyclin + double vi = 0.025; + double reaction1 = cell * vi; + + // default degradation of cyclin + double kd = 0.01; + double reaction2 = C * cell * kd; + + // cdc2 kinase triggered degration of cyclin + double vd = 0.25; + double Kd = 0.02; + double reaction3 = C * cell * vd * X * pow(C + Kd, -1); + + // activation of cdc2 kinase + double K1 = 0.005; + double reaction4 = cell * (1 + -1 * M) * V1 * pow(K1 + -1 * M + 1, -1); + + // deactivation of cdc2 kinase + double V2 = 1.5; + double K2 = 0.005; + double reaction5 = cell * M * V2 * pow(K2 + M, -1); + + // activation of cyclin protease + double K3 = 0.005; + double reaction6 = cell * V3 * (1 + -1 * X) * pow(K3 + -1 * X + 1, -1); + + // deactivation of cyclin protease + double K4 = 0.005; + double V4 = 0.5; + double reaction7 = cell * V4 * X * pow(K4 + X, -1); + + + rDY[0] = (reaction1 - reaction2 - reaction3) / cell; // dCyclin/dt + rDY[1] = (reaction4 - reaction5) / cell; // dcdc_2_kinase/dt + rDY[2] = (reaction6 - reaction7) / cell; // dCyclin Protease/dt + + /* Account for the differences in timescales. */ + rDY[0] *= 3600.0; + rDY[1] *= 3600.0; + rDY[2] *= 3600.0; + +} + +template<> +void CellwiseOdeSystemInformation::Initialise() +{ + this->mVariableNames.push_back("Cyclin"); + this->mVariableUnits.push_back("non-dim"); + this->mInitialConditions.push_back(0.01); + + this->mVariableNames.push_back("cdc_2_kinase"); + this->mVariableUnits.push_back("non-dim"); + this->mInitialConditions.push_back(0.01); + + this->mVariableNames.push_back("Cyclin Protease"); + this->mVariableUnits.push_back("non-dim"); + this->mInitialConditions.push_back(0.01); + + + this->mInitialised = true; +} + +/* Define SRN model using Wrappers. */ +#include "SbmlSrnWrapperModel.hpp" +#include "SbmlSrnWrapperModel.cpp" + +typedef SbmlSrnWrapperModel Goldbeter1991SrnModel; + +// Declare identifiers for the serializer +#include "SerializationExportWrapperForCpp.hpp" +CHASTE_CLASS_EXPORT(Goldbeter1991OdeSystem) +EXPORT_TEMPLATE_CLASS2(SbmlSrnWrapperModel, Goldbeter1991OdeSystem, 5) + +#include "CellCycleModelOdeSolverExportWrapper.hpp" +EXPORT_CELL_CYCLE_MODEL_ODE_SOLVER(Goldbeter1991SrnModel) + diff --git a/chaste_codegen_sbml/tests/data/Goldbeter1991/Goldbeter1991SrnModel.hpp b/chaste_codegen_sbml/tests/data/Goldbeter1991/Goldbeter1991SrnModel.hpp new file mode 100644 index 0000000..dc1d256 --- /dev/null +++ b/chaste_codegen_sbml/tests/data/Goldbeter1991/Goldbeter1991SrnModel.hpp @@ -0,0 +1,89 @@ +#ifndef GOLDBETER1991ODESYSTEMANDSRNMODEL_HPP_ +#define GOLDBETER1991ODESYSTEMANDSRNMODEL_HPP_ + +#include "ChasteSerialization.hpp" +#include +#include + +#include +#include +#include "AbstractOdeSystem.hpp" + +class Goldbeter1991OdeSystem : public AbstractOdeSystem +{ +private: + + /* Initialise compartments and values. */ + double cell; + + /* Initialise model parameters. */ + double V1; + double V3; + double VM1; + double VM3; + double Kc; + + + friend class boost::serialization::access; + template + void serialize(Archive & archive, const unsigned int version) + { + archive & boost::serialization::base_object(*this); + } + +public: + + /* Default constructor. */ + Goldbeter1991OdeSystem(std::vector stateVariables=std::vector()); + + /* Destructor. */ + ~Goldbeter1991OdeSystem(); + + + void Init(); + + void EvaluateYDerivatives(double time, const std::vector& rY, std::vector& rDY); + +}; + +namespace +{ +namespace serialization +{ +/* Serialize information required to construct a Goldbeter1991OdeSystem. */ +template +inline void save_construct_data( + Archive & ar, const Goldbeter1991OdeSystem * t, const unsigned int file_version) +{ + const std::vector state_variables = t->rGetConstStateVariables(); + ar & state_variables; +} +/* De-serialize constructor parameters and intiialise a Goldbeter1991OdeSystem. */ +template +inline void load_construct_data( + Archive & ar, Goldbeter1991OdeSystem * t, const unsigned int file_version) +{ + std::vector state_variables; + ar & state_variables; + + // Invoke inplace constructor to initialise instance + ::new(t)Goldbeter1991OdeSystem(state_variables); +} +} +} // namespace ... + +/* Define SRN model using Wrappers. */ +#include "SbmlSrnWrapperModel.hpp" +#include "SbmlSrnWrapperModel.cpp" + +typedef SbmlSrnWrapperModel Goldbeter1991SrnModel; + +// Declare identifiers for the serializer +#include "SerializationExportWrapper.hpp" +CHASTE_CLASS_EXPORT(Goldbeter1991OdeSystem) +EXPORT_TEMPLATE_CLASS2(SbmlSrnWrapperModel, Goldbeter1991OdeSystem, 5) + +#include "CellCycleModelOdeSolverExportWrapper.hpp" +EXPORT_CELL_CYCLE_MODEL_ODE_SOLVER(Goldbeter1991SrnModel) + +#endif /* GOLDBETER1991ODESYSTEMANDSRNMODEL_HPP_ */ \ No newline at end of file