libSBML C++ API  libSBML 5.18.0 C++ API
groups_example1.cpp

Simple example of writing a model that uses the SBML Level 3 Groups package.

/**
* @file example1.cpp
* @brief SBML Groups example
* @author Akiya Jouraku
*
* $Id: example1.cpp 13540 2011-04-08 22:12:58Z fbergmann $
* $HeadURL: https://sbml.svn.sourceforge.net/svnroot/sbml/branches/libsbml-5/examples/groups/example1.cpp $
*
* This file is part of libSBML. Please visit http://sbml.org for more
* information about SBML, and the latest version of libSBML.
*/
#include "sbml/SBMLTypes.h"
int main(int argc,char** argv){
//
// Creates an SBMLNamespaces object with the given SBML level, version
// package name, package version.
//
// (NOTE) By defualt, the name of package (i.e. "groups") will be used
// if the arugment for the prefix is missing or empty. Thus the argument
// for the prefix can be added as follows:
//
// SBMLNamespaces sbmlns(3,1,"groups",1,"GROUP");
//
SBMLNamespaces sbmlns(3,1,"groups",1);
//
// (NOTES) The above code creating an SBMLNamespaces object can be replaced
// with one of the following other styles.
//
// (1) Creates an SBMLNamespace object with a SBML core namespace and then
// adds a groups package namespace to the object.
//
// SBMLNamespaces sbmlns(3,1);
// sbmlns.addPkgNamespace("groups",1);
//
// OR
//
// SBMLNamespaces sbmlns(3,1);
// sbmlns.addNamespace(GroupsExtension::XmlnsL3V1V1,"groups");
//
// (2) Creates a GroupsPkgNamespaces object (SBMLNamespace derived class for
// groups package. The class is basically used for createing an SBase derived
// objects defined in the groups package) with the given SBML level, version,
// and package version
//
// GroupsPkgNamespaces sbmlns(3,1,1);
//
// create the document
SBMLDocument *document = new SBMLDocument(&sbmlns);
document->setPackageRequired("groups", false);
// create the Model
Model* model=document->createModel();
// create the Compartment
Compartment* compartment = model->createCompartment();
compartment->setId("cytosol");
compartment->setConstant(true);
compartment=model->createCompartment();
compartment->setId("mitochon");
compartment->setConstant(true);
// create the Species
Species* species = model->createSpecies();
species->setId("ATPc");
species->setCompartment("cytosol");
species->setHasOnlySubstanceUnits(false);
species->setBoundaryCondition(false);
species->setConstant(false);
species = model->createSpecies();
species->setId("ATPm");
species->setCompartment("mitochon");
species->setHasOnlySubstanceUnits(false);
species->setBoundaryCondition(false);
species->setConstant(false);
// create the Groups
//
// Get a GroupsModelPlugin object plugged in the model object.
//
// The type of the returned value of SBase::getPlugin() function is SBasePlugin*, and
// thus the value needs to be casted for the corresponding derived class.
//
GroupsModelPlugin* mplugin = static_cast<GroupsModelPlugin*>(model->getPlugin("groups"));
//
// Creates a Group object via GroupsModelPlugin object.
//
Group* group = mplugin->createGroup();
group->setId("ATP");
group->setKind(GROUP_KIND_CLASSIFICATION);
group->setSBOTerm("SBO:0000252");
Member* member = group->createMember();
member->setIdRef("ATPc");
member = group->createMember();
member->setIdRef("ATPm");
writeSBML(document,"groups_example1.xml");
delete document;
}
GROUP_KIND_CLASSIFICATION
Definition: GroupsExtension.h:400
Compartment::setConstant
int setConstant(bool value)
Sets the value of the "constant" attribute of this Compartment object.
Definition: Compartment.cpp:681
Species::setInitialConcentration
int setInitialConcentration(double value)
Sets the "initialConcentration" attribute of this Species and marks the field as set.
Definition: Species.cpp:699
SBMLTypes.h
Include all SBML types in a single header file.
GroupsModelPlugin
Extension of Model.
Definition: GroupsModelPlugin.h:60
Member
The Member class defines what objects are parts of a Group.
Definition: Member.h:79
SBMLDocument::createModel
Model * createModel(const std::string sid="")
Creates a new Model inside this SBMLDocument, and returns a pointer to it.
Definition: SBMLDocument.cpp:643
Model::createSpecies
Species * createSpecies()
Creates a new Species inside this Model and returns it.
Definition: Model.cpp:1590
Group
Representation of a group of SBML components.
Definition: Group.h:171
GroupsExtensionTypes.h
Definition of GroupsExtensionTypes.
Compartment::setId
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this Compartment object.
Definition: Compartment.cpp:474
Species::setConstant
int setConstant(bool value)
Sets the "constant" attribute of this Species object.
Definition: Species.cpp:824
Compartment
An SBML compartment, where species are located.
Definition: Compartment.h:484
Group::setId
virtual int setId(const std::string &id)
Sets the value of the "id" attribute of this Group.
Definition: Group.cpp:208
Model
An SBML model.
Definition: Model.h:479
Species::setId
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this Species.
Definition: Species.cpp:586
GroupsModelPlugin::createGroup
Group * createGroup()
Creates a new Group object, adds it to this GroupsModelPlugin object and returns the Group object cre...
Definition: GroupsModelPlugin.cpp:227
SBMLDocument::setPackageRequired
int setPackageRequired(const std::string &package, bool flag)
Sets the required attribute value of the given package extension.
Definition: SBMLDocument.cpp:1439
SBMLNamespaces
Set of SBML Level + Version + namespace triples.
Definition: SBMLNamespaces.h:139
Species::setCompartment
int setCompartment(const std::string &sid)
Sets the "compartment" attribute of this Species object.
Definition: Species.cpp:665
Model::createCompartment
Compartment * createCompartment()
Creates a new Compartment inside this Model and returns it.
Definition: Model.cpp:1563
Member::setIdRef
int setIdRef(const std::string &idRef)
Sets the value of the "idRef" attribute of this Member.
Definition: Member.cpp:234
Species
An SBML species – a pool of entities.
Definition: Species.h:423
LIBSBML_CPP_NAMESPACE_USE
#define LIBSBML_CPP_NAMESPACE_USE
Definition: libsbml-namespace.h:67
SBMLDocument
Overall SBML container object.
Definition: SBMLDocument.h:342
SBase::getPlugin
SBasePlugin * getPlugin(const std::string &package)
Returns a plug-in object (extension interface) for an SBML Level&#160;3 package extension with the given p...
Definition: SBase.cpp:3460
Species::setBoundaryCondition
int setBoundaryCondition(bool value)
Sets the "boundaryCondition" attribute of this Species object.
Definition: Species.cpp:791
Species::setHasOnlySubstanceUnits
int setHasOnlySubstanceUnits(bool value)
Sets the "hasOnlySubstanceUnits" attribute of this Species object.
Definition: Species.cpp:771
writeSBML
int writeSBML(const SBMLDocument_t *d, const char *filename)
Writes the given SBML document d to the file named by filename.