libSBML C API  5.18.0
spec_example1.c

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>
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;
}