libSBML C API  libSBML 5.20.2 C API
Loading...
Searching...
No Matches
spec_example1.c

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

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

/**
* @file spec_example1.c
* @brief SBML hierarchical composition example
* @author Lucian Smith
* @author Sarah Keating
*
* <!--------------------------------------------------------------------------
* 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>
#include <sbml/packages/comp/common/compfwd.h>
LIBSBML_CPP_NAMESPACE_USE
int main(int argc,char** argv)
{
int retval = 0;
SBMLNamespaces_t * sbmlns;
Species_t * s1;
Species_t * s2;
Species_t * s3;
Species_t * s4;
Reaction_t * r1;
Reaction_t * r2;
Model_t * model;
CompModelPlugin_t *modelPlug;
Submodel_t * sub1;
Submodel_t * sub2;
/* get comp registry entry */
/* create the sbml namespaces object with comp */
XMLNamespaces_add(comp, SBMLExtension_getURI(sbmlext, 3, 1, 1), "comp");
sbmlns = SBMLNamespaces_create(3, 1);
/* create the document */
/* set the comp reqd attribute to true */
docPlug = (CompSBMLDocumentPlugin_t * )(SBase_getPlugin((SBase_t*)(doc), "comp"));
/* create the submodel */
Model_setId((Model_t*)(modDef), "enzyme");
Model_setName((Model_t*)(modDef), "enzyme");
Compartment_setId(c, "comp");
s1 = Model_createSpecies((Model_t*)(modDef));
Species_setId(s1, "S");
s2 = Model_createSpecies((Model_t*)(modDef));
Species_setId(s2, "E");
s3 = Model_createSpecies((Model_t*)(modDef));
Species_setId(s3, "D");
s4 = Model_createSpecies((Model_t*)(modDef));
Species_setId(s4, "ES");
r1 = Model_createReaction((Model_t*)(modDef));
Reaction_setId(r1, "J0");
r2 = Model_createReaction((Model_t*)(modDef));
Reaction_setId(r2, "J1");
/* create the model */
Model_setId(model, "aggregate");
/* add the submodels*/
modelPlug = (CompModelPlugin_t*)(SBase_getPlugin((SBase_t *)(model), "comp"));
sub1 = CompModelPlugin_createSubmodel(modelPlug);
Submodel_setId(sub1, "submod1");
Submodel_setModelRef(sub1, "enzyme");
sub2 = CompModelPlugin_createSubmodel(modelPlug);
Submodel_setId(sub2, "submod2");
Submodel_setModelRef(sub2, "enzyme");
/* write the file */
writeSBMLToFile(doc, "enzyme_model.xml");
return retval;
}
Submodel_t * CompModelPlugin_createSubmodel(CompModelPlugin_t *cmp)
_tCreates_t _ta_t _tnew_t _tSubmodel_t_t, _tadds_t _tit_t _tto_t _tthis_t _tCompModelPlugin_t_t _tand...
Definition CompModelPlugin.cpp:1461
Definition of CompModelPlugin_t, the plugin class of comp package for the Model_t element.
ModelDefinition_t * CompSBMLDocumentPlugin_createModelDefinition(CompSBMLDocumentPlugin_t *csbmldp)
_tCreates_t _ta_t _tnew_t _tModelDefinition_t_t _tobject_t, _tadds_t _tit_t _tto_t _tthis_t _tCompSBM...
Definition CompSBMLDocumentPlugin.cpp:1287
Definition of CompSBMLDocumentPlugin_t, the plugin class of comp package for the Model_t element.
int Compartment_setSize(Compartment_t *c, double value)
_tSets_t _tthe_t "_tsize_t" _tattribute_t (_tor_t "_tvolume_t" _tin_t _tSBML_t _tLevel_t _t1_t) _tof_...
Definition Compartment.cpp:2314
int Compartment_setSpatialDimensions(Compartment_t *c, unsigned int value)
_tSets_t _tthe_t "_tspatialDimensions_t" _tattribute_t _tof_t _tthe_t _tgiven_t _tCompartment_t_t _ts...
Definition Compartment.cpp:2292
int Compartment_setConstant(Compartment_t *c, int value)
_tSets_t _tthe_t _tvalue_t _tof_t _tthe_t "_tconstant_t" _tattribute_t _tof_t _tthe_t _tgiven_t _tCom...
Definition Compartment.cpp:2358
int Compartment_setId(Compartment_t *c, const char *sid)
_tSets_t _tthe_t _tvalue_t _tof_t _tthe_t "_tid_t" _tattribute_t _tof_t _tthe_t _tgiven_t _tCompartme...
Definition Compartment.cpp:2258
Reaction_t * Model_createReaction(Model_t *m)
_tCreates_t _ta_t _tnew_t _tReaction_t_t _tstructure_t _tinside_t _tthe_t _tgiven_t _tModel_t_t _tstr...
Definition Model.cpp:7741
Species_t * Model_createSpecies(Model_t *m)
_tCreates_t _ta_t _tnew_t _tSpecies_t_t _tstructure_t _tinside_t _tthe_t _tgiven_t _tModel_t_t _tand_...
Definition Model.cpp:7686
int Model_setId(Model_t *m, const char *sid)
_tSet_t _tthe_t _tidentifier_t _tof_t _ta_t _tgiven_t _tModel_t_t _tstructure_t.
Definition Model.cpp:7306
int Model_setName(Model_t *m, const char *name)
_tSet_t _tthe_t _tidentifier_t _tof_t _tthe_t _tgiven_t _tModel_t_t _tstructure_t.
Definition Model.cpp:7317
Compartment_t * Model_createCompartment(Model_t *m)
_tCreates_t _ta_t _tnew_t _tCompartment_t_t _tstructure_t _tinside_t _tthe_t _tgiven_t _tModel_t_t _t...
Definition Model.cpp:7678
int Reaction_setFast(Reaction_t *r, int value)
_tSets_t _tthe_t _tfast_t _tstatus_t _tof_t _tthis_t _tReaction_t_t _tto_t _tvalue_t (_tboolean_t).
Definition Reaction.cpp:2830
SpeciesReference_t * Reaction_createProduct(Reaction_t *r)
_tCreates_t _ta_t _tnew_t _tSpeciesReference_t, _tadds_t _tit_t _tto_t _tthis_t _tReaction_t_t'_ts_t ...
Definition Reaction.cpp:3006
int Reaction_setId(Reaction_t *r, const char *sid)
_tSets_t _tthe_t _tid_t _tof_t _tthis_t _tReaction_t_t _tto_t _ta_t _tcopy_t _tof_t @_tp_t _tsid_t.
Definition Reaction.cpp:2786
int Reaction_setReversible(Reaction_t *r, int value)
_tSets_t _tthe_t _treversible_t _tstatus_t _tof_t _tthis_t _tReaction_t_t _tto_t _tvalue_t (_tboolean...
Definition Reaction.cpp:2819
SpeciesReference_t * Reaction_createReactant(Reaction_t *r)
_tCreates_t _ta_t _tnew_t _tSpeciesReference_t, _tadds_t _tit_t _tto_t _tthis_t _tReaction_t_t'_ts_t ...
Definition Reaction.cpp:2998
SBMLDocument_t * SBMLDocument_createWithSBMLNamespaces(SBMLNamespaces_t *sbmlns)
_tCreates_t _ta_t _tnew_t _tSBMLDocument_t _tusing_t _tthe_t _tgiven_t _tSBMLNamespaces_t_t _tstructu...
Definition SBMLDocument.cpp:2232
Model_t * SBMLDocument_createModel(SBMLDocument_t *d)
_tCreates_t _ta_t _tnew_t _tModel_t_t _tstructure_t _tinside_t _tthe_t _tgiven_t _tSBMLDocument_t_t _...
Definition SBMLDocument.cpp:2357
int SBMLDocumentPlugin_setRequired(SBMLDocumentPlugin_t *plugin, int required)
_tSets_t _tthe_t _tvalue_t _tof_t "_trequired_t" _tattribute_t _tof_t _tcorresponding_t _tpackage_t _...
Definition SBMLDocumentPlugin.cpp:332
Definition of SBMLDocumentPlugin_t, the derived class of SBasePlugin_t.
const char * SBMLExtension_getURI(SBMLExtension_t *ext, unsigned int sbmlLevel, unsigned int sbmlVersion, unsigned int pkgVersion)
_tReturns_t _tthe_t _turi_t _tcorresponding_t _tto_t _tthe_t _tgiven_t _tSBML_t _tlevel_t,...
Definition SBMLExtension.cpp:564
Template class for registering extension packages.
SBMLExtension_t * SBMLExtensionRegistry_getExtension(const char *package)
_tReturns_t _tan_t _tSBMLExtension_t_t _tstructure_t _twith_t _tthe_t _tgiven_t _tpackage_t _tURI_t _...
int SBMLNamespaces_addNamespaces(SBMLNamespaces_t *sbmlns, const XMLNamespaces_t *xmlns)
_tAdd_t _tthe_t _tXML_t _tnamespaces_t _tlist_t _tto_t _tthe_t _tset_t _tof_t _tnamespaces_t _twithin...
Definition SBMLNamespaces.cpp:867
SBMLNamespaces_t * SBMLNamespaces_create(unsigned int level, unsigned int version)
@_tendcond_t
Definition SBMLNamespaces.cpp:818
Include all SBML types in a single header file.
int writeSBMLToFile(const SBMLDocument_t *d, const char *filename)
_tWrites_t _tthe_t _tgiven_t _tSBML_t _tdocument_t @_tp_t _td_t _tto_t _tthe_t _tfile_t @_tp_t _tfile...
Definition SBMLWriter.cpp:452
SBasePlugin_t * SBase_getPlugin(SBase_t *sb, const char *package)
_tReturns_t _ta_t _tplug_t-_tin_t _tstructure_t (_textension_t _tinterface_t) _tfor_t _tan_t _tSBML_t...
Definition SBase.cpp:8043
int Species_setId(Species_t *s, const char *sid)
_tSets_t _tthe_t "_tid_t" _tattribute_t _tof_t _tthe_t _tgiven_t _tSpecies_t_t _tstructure_t.
Definition Species.cpp:2867
int Species_setHasOnlySubstanceUnits(Species_t *s, int value)
_tSets_t _tthe_t "_thasOnlySubstanceUnits_t" _tattribute_t _tof_t _tthe_t _tgiven_t _tSpecies_t_t _ts...
Definition Species.cpp:2967
int Species_setBoundaryCondition(Species_t *s, int value)
_tSets_t _tthe_t "_tboundaryCondition_t" _tattribute_t _tof_t _tthe_t _tgiven_t _tSpecies_t_t _tstruc...
Definition Species.cpp:2978
int Species_setConstant(Species_t *s, int value)
_tSets_t _tthe_t "_tconstant_t" _tattribute_t _tof_t _tthe_t _tgiven_t _tSpecies_t_t _tstructure_t.
Definition Species.cpp:3000
int Species_setCompartment(Species_t *s, const char *sid)
_tSets_t _tthe_t "_tcompartment_t" _tattribute_t _tof_t _tthe_t _tgiven_t _tSpecies_t_t _tstructure_t...
Definition Species.cpp:2900
int SpeciesReference_setSpecies(SpeciesReference_t *sr, const char *sid)
_tSets_t _tthe_t _tvalue_t _tof_t _tthe_t "_tspecies_t" _tattribute_t _tof_t _tthe_t _tgiven_t _tSpec...
Definition SpeciesReference.cpp:2098
int SpeciesReference_setStoichiometry(SpeciesReference_t *sr, double value)
_tSets_t _tthe_t _tvalue_t _tof_t _tthe_t "_tstoichiometry_t" _tattribute_t _tof_t _tthe_t _tgiven_t ...
Definition SpeciesReference.cpp:2109
int SpeciesReference_setConstant(SpeciesReference_t *sr, int value)
_tAssign_t _tthe_t "_tconstant_t" _tattribute_t _tof_t _ta_t _tSpeciesReference_t_t _tstructure_t.
Definition SpeciesReference.cpp:2160
int Submodel_setModelRef(Submodel_t *s, const char *modelRef)
_tSets_t _tthe_t _tmodelRef_t _tof_t _tthe_t _tgiven_t _tSubmodel_t_t _tto_t _ta_t _tcopy_t _tof_t @_...
Definition Submodel.cpp:1580
int Submodel_setId(Submodel_t *s, const char *id)
_tAssigns_t _tthe_t _tidentifier_t _tof_t _tan_t _tSubmodel_t_t _tstructure_t.
Definition Submodel.cpp:1564
Definition of Submodel_t, the SBase_t derived class of the comp package.
LIBLAX_EXTERN int XMLNamespaces_add(XMLNamespaces_t *ns, const char *uri, const char *prefix)
_tAppends_t _tan_t _tXML_t _tnamespace_t _tprefix_t/_tURI_t _tpair_t _tto_t _tthis_t _tXMLNamespaces_...
Definition XMLNamespaces.cpp:493
LIBLAX_EXTERN XMLNamespaces_t * XMLNamespaces_create(void)
@_tendcond_t
Definition XMLNamespaces.cpp:467