Loading [MathJax]/extensions/tex2jax.js
libSBML C++ API  5.20.4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
spec_example1.cpp

Example #1 from the SBML Level 3 Hierarchical Model Composition specification.

Example #1 from the SBML Level 3 Hierarchical Model Composition specification.

/**
* @file spec_example1.cpp
* @brief SBML hierarchical composition example
* @author Lucian Smith
*
* <!--------------------------------------------------------------------------
* This sample program is distributed under a different license than the rest
* of libSBML. This program uses the open-source MIT license, as follows:
*
* Copyright (c) 2013-2018 by the California Institute of Technology
* (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
* and the University of Heidelberg (Germany), with support from the National
* Institutes of Health (USA) under grant R01GM070923. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Neither the name of the California Institute of Technology (Caltech), nor
* of the European Bioinformatics Institute (EMBL-EBI), nor of the University
* of Heidelberg, nor the names of any contributors, may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* ------------------------------------------------------------------------ -->
*/
#include <iostream>
#include <sstream>
#include <sbml/SBMLTypes.h>
#ifdef WIN32
#include <conio.h>
#endif
LIBSBML_CPP_NAMESPACE_USE
using namespace std;
int main(int argc,char** argv)
{
int retval = 0;
SBMLNamespaces sbmlns(3,1,"comp",1);
// create the document
SBMLDocument *document = new SBMLDocument(&sbmlns);
//Create our submodel
= static_cast<CompSBMLDocumentPlugin*>(document->getPlugin("comp"));
compdoc->setRequired(true);
mod1->setId("enzyme");
mod1->setName("enzyme");
Compartment* comp=mod1->createCompartment();
comp->setSpatialDimensions((unsigned int)3);
comp->setConstant(true);
comp->setId("comp");
comp->setSize(1L);
Species spec(&sbmlns);
spec.setCompartment("comp");
spec.setConstant(false);
spec.setBoundaryCondition(false);
spec.setId("S");
mod1->addSpecies(&spec);
spec.setId("E");
mod1->addSpecies(&spec);
spec.setId("D");
mod1->addSpecies(&spec);
spec.setId("ES");
mod1->addSpecies(&spec);
Reaction rxn(&sbmlns);
rxn.setReversible(true);
rxn.setFast(false);
Reaction rxn2(rxn);
rxn.setId("J0");
rxn2.setId("J1");
SpeciesReference sr(&sbmlns);
sr.setConstant(true);
sr.setSpecies("S");
rxn.addReactant(&sr);
sr.setSpecies("E");
rxn.addReactant(&sr);
rxn2.addProduct(&sr);
sr.setSpecies("ES");
rxn.addProduct(&sr);
rxn2.addReactant(&sr);
sr.setSpecies("D");
rxn2.addProduct(&sr);
mod1->addReaction(&rxn);
mod1->addReaction(&rxn2);
// create the Model
Model* model=document->createModel();
model->setId("aggregate");
// Create a submodel
CompModelPlugin* mplugin = static_cast<CompModelPlugin*>(model->getPlugin("comp"));
Submodel* submod1 = mplugin->createSubmodel();
submod1->setId("submod1");
submod1->setModelRef("enzyme");
Submodel submod2;
submod2.setId("submod2");
submod2.setModelRef("enzyme");
mplugin->addSubmodel(&submod2);
writeSBMLToFile(document,"eg-simple-aggregate.xml");
writeSBMLToFile(document,"enzyme_model.xml");
delete document;
document = readSBMLFromFile("enzyme_model.xml");
if (document == NULL)
{
cout << "Error reading back in file." << endl;
retval = -1;
}
else
{
document->checkConsistency();
if (document->getErrorLog()->getNumFailsWithSeverity(2) > 0
|| document->getErrorLog()->getNumFailsWithSeverity(3) > 0)
{
stringstream errorstream;
document->printErrors(errorstream);
cout << "Errors encoutered when round-tripping SBML file: \n"
<< errorstream.str() << endl;
retval = -1;
}
writeSBMLToFile(document, "enzyme_model_rt.xml");
delete document;
}
#ifdef WIN32
if (retval != 0)
{
cout << "(Press any key to exit.)" << endl;
_getch();
}
#endif
return retval;
}
static SBMLExtensionRegister< CompExtension > compExtensionRegistry
Definition CompExtension.cpp:109
Definition of CompExtension, the core module of comp package.
Definition of CompModelPlugin, the plugin class of comp package for the Model element.
Definition of CompSBMLDocumentPlugin, the plugin class of comp package for the Model element.
Definition of CompSBasePlugin, the plugin class of comp package for the Model element.
@ LIBSBML_CAT_UNITS_CONSISTENCY
Definition SBMLError.h:975
Template class for registering extension packages.
The registry class for tracking package extensions.
SBMLDocument_t * readSBMLFromFile(const char *filename)
Reads an SBML document from the given file.
Include all SBML types in a single header file.
int writeSBMLToFile(const SBMLDocument_t *d, const char *filename)
Writes the given SBML document d to the file filename.
Definition CompModelPlugin.h:87
Submodel * createSubmodel()
Creates a Submodel object, adds it to the end of the submodel objects list and returns a pointer to t...
Definition CompModelPlugin.cpp:312
int addSubmodel(const Submodel *submodel)
Adds a copy of the given Submodel object to the list of submodels.
Definition CompModelPlugin.cpp:275
Definition CompSBMLDocumentPlugin.h:94
virtual int setRequired(bool value)
Sets the bool value of "required" attribute of corresponding package in SBMLDocument element.
Definition CompSBMLDocumentPlugin.cpp:600
ModelDefinition * createModelDefinition()
Creates a ModelDefinition object, adds it to the end of the ModelDefinition objects list and returns ...
Definition CompSBMLDocumentPlugin.cpp:399
Definition Compartment.h:490
int setConstant(bool value)
Sets the value of the "constant" attribute of this Compartment object.
Definition Compartment.cpp:661
int setSpatialDimensions(unsigned int value)
Sets the "spatialDimensions" attribute of this Compartment object.
Definition Compartment.cpp:552
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this Compartment object.
Definition Compartment.cpp:479
int setSize(double value)
Sets the "size" attribute (or "volume" in SBML Level&#160;1) of this Compartment object.
Definition Compartment.cpp:603
Definition ModelDefinition.h:71
Definition Reaction.h:224
int setReversible(bool value)
Sets the value of the "reversible" attribute of this Reaction.
Definition Reaction.cpp:599
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this Reaction.
Definition Reaction.cpp:517
int addReactant(const SpeciesReference *sr)
Adds a given SpeciesReference object as a reactant in this Reaction.
Definition Reaction.cpp:784
int setFast(bool value)
Sets the value of the "fast" attribute of this Reaction.
Definition Reaction.cpp:612
int addProduct(const SpeciesReference *sr)
Adds a given SpeciesReference object as a product in this Reaction.
Definition Reaction.cpp:840
Definition SBMLDocument.h:351
Model * createModel(const std::string sid="")
Creates a new Model inside this SBMLDocument, and returns a pointer to it.
Definition SBMLDocument.cpp:627
unsigned int checkConsistency()
Performs consistency checking and validation on this SBML document.
Definition SBMLDocument.cpp:699
SBMLErrorLog * getErrorLog()
Returns the list of errors or warnings logged during parsing, consistency checking,...
Definition SBMLDocument.cpp:1345
void printErrors(std::ostream &stream=std::cerr) const
Prints all the errors or warnings encountered trying to parse, check, or translate this SBML document...
Definition SBMLDocument.cpp:1192
void setConsistencyChecks(SBMLErrorCategory_t category, bool apply)
Controls the consistency checks that are performed when SBMLDocument::checkConsistency() is called.
Definition SBMLDocument.cpp:677
unsigned int getNumFailsWithSeverity(unsigned int severity)
Returns the number of errors that have been logged with the given severity code.
Definition SBMLErrorLog.cpp:363
Definition SBMLExtensionRegister.h:74
Definition SBMLNamespaces.h:145
SBasePlugin * getPlugin(const std::string &package)
Returns a plug-in object (extension interface) for an SBML Level&#160;3 package extension with the given ...
Definition SBase.cpp:3551
int setSpecies(const std::string &sid)
Sets the "species" attribute of this SimpleSpeciesReference.
Definition SimpleSpeciesReference.cpp:196
Definition Species.h:429
int setCompartment(const std::string &sid)
Sets the "compartment" attribute of this Species object.
Definition Species.cpp:661
int setConstant(bool value)
Sets the "constant" attribute of this Species object.
Definition Species.cpp:820
int setBoundaryCondition(bool value)
Sets the "boundaryCondition" attribute of this Species object.
Definition Species.cpp:787
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this Species.
Definition Species.cpp:591
int setHasOnlySubstanceUnits(bool value)
Sets the "hasOnlySubstanceUnits" attribute of this Species object.
Definition Species.cpp:767
Definition SpeciesReference.h:281
int setStoichiometry(double value)
Sets the value of the "stoichiometry" attribute of this SpeciesReference.
Definition SpeciesReference.cpp:312
int setConstant(bool flag)
Sets the "constant" attribute of this SpeciesReference to the given boolean flag.
Definition SpeciesReference.cpp:400
Definition Submodel.h:156
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this Submodel.
Definition Submodel.cpp:178
virtual int setModelRef(const std::string &modelRef)
Sets the value of the "modelRef" attribute of this Submodel.
Definition Submodel.cpp:254