Lengthy example of creating SBML models presented in the SBML specification.
Lengthy example of creating SBML models presented in the SBML specification.
#include <stdio.h>
const char* ProgramName = "createExampleModels";
const char* ProgramVersion = "1.0.0";
const unsigned int Level = 2;
const unsigned int Version = 4;
int
main (int argc, char *argv[])
{
int SBMLok = 0;
sbmlDoc = createExampleEnzymaticReaction();
SBMLok = validateExampleSBML(sbmlDoc);
if (SBMLok == 1) writeExampleSBML(sbmlDoc, "enzymaticreaction.xml");
if (SBMLok == 0) return 1;
sbmlDoc = createExampleInvolvingUnits();
SBMLok = validateExampleSBML(sbmlDoc);
if (SBMLok == 1) writeExampleSBML(sbmlDoc, "units.xml");
if (SBMLok == 0) return 1;
sbmlDoc = createExampleInvolvingFunctionDefinitions();
SBMLok = validateExampleSBML(sbmlDoc);
if (SBMLok == 1) writeExampleSBML(sbmlDoc, "functiondef.xml");
if (SBMLok == 0) return 1;
return 0;
}
{
const unsigned int level = Level;
const unsigned int version = Version;
const char* compName = "cytosol";
char* mathXMLString;
mathXMLString = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
" <apply>"
" <times/>"
" <ci> cytosol </ci>"
" <ci> kcat </ci>"
" <ci> ES </ci>"
" </apply>"
"</math>";
return sbmlDoc;
}
{
const unsigned int level = Level;
const unsigned int version = Version;
char* notesString, * mathXMLString ;
ASTNode_t* astMath, * astDivide, * astTimes, * astPlus ;
const char* compName = "cell";
notesString = "<xhtml:p> ((vm * s1)/(km + s1)) * cell </xhtml:p>";
mathXMLString = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
" <apply>"
" <times/>"
" <apply>"
" <divide/>"
" <apply>"
" <times/>"
" <ci> vm </ci>"
" <ci> s2 </ci>"
" </apply>"
" <apply>"
" <plus/>"
" <ci> km </ci>"
" <ci> s2 </ci>"
" </apply>"
" </apply>"
" <ci> cell </ci>"
" </apply>"
"</math>";
notesString = "<xhtml:p> ((vm * x1)/(km + x1)) * cell </xhtml:p>";
mathXMLString = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
" <apply>"
" <times/>"
" <apply>"
" <divide/>"
" <apply>"
" <times/>"
" <ci> vm </ci>"
" <ci> x1 </ci>"
" </apply>"
" <apply>"
" <plus/>"
" <ci> km </ci>"
" <ci> x1 </ci>"
" </apply>"
" </apply>"
" <ci> cell </ci>"
" </apply>"
"</math>";
return sbmlDoc;
}
{
const unsigned int level = Level;
const unsigned int version = Version;
char* mathXMLString;
const char* compName = "compartmentOne";
mathXMLString = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
" <lambda>"
" <bvar>"
" <ci> x </ci>"
" </bvar>"
" <apply>"
" <times/>"
" <ci> x </ci>"
" <cn> 2 </cn>"
" </apply>"
" </lambda>"
"</math>";
mathXMLString = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
" <apply>"
" <divide/>"
" <apply>"
" <times/>"
" <apply>"
" <ci> f </ci>"
" <ci> S1 </ci>"
" </apply>"
" <ci> compartmentOne </ci>"
" </apply>"
" <ci> t </ci>"
" </apply>"
"</math>";
return sbmlDoc;
}
{
int noProblems = 1;
unsigned int numCheckFailures = 0;
unsigned int numConsistencyErrors = 0;
unsigned int numConsistencyWarnings = 0;
unsigned int numValidationErrors = 0;
unsigned int numValidationWarnings = 0;
if (!sbmlDoc)
{
fprintf(stderr, "validateExampleSBML: given a null SBML Document\n");
return 0;
}
if ( numCheckFailures > 0 )
{
unsigned int i;
noProblems = 0;
for (i = 0; i < numCheckFailures; i++)
{
{
++numConsistencyErrors;
}
else
{
++numConsistencyWarnings;
}
}
}
if (numConsistencyErrors > 0)
{
printf("Further validation aborted.\n");
}
else
{
if ( numCheckFailures > 0 )
{
unsigned int i;
noProblems = 0;
for (i = 0; i < numCheckFailures; i++)
{
{
++numValidationErrors;
}
else
{
++numValidationWarnings;
}
}
}
}
if (noProblems)
return 1;
else
{
if (numConsistencyErrors > 0)
{
printf("ERROR: encountered %d consistency error%s in model '%s'.\n",
numConsistencyErrors,
(numConsistencyErrors == 1 ? "" : "s"),
}
if (numConsistencyWarnings > 0)
{
printf( "Notice: encountered %d consistency warning%s in model '%s'.\n",
numConsistencyWarnings,
(numConsistencyWarnings == 1 ? "" : "s"),
);
}
if (numValidationErrors > 0)
{
printf("ERROR: encountered %d validation error%s in model '%s'.\n",
numValidationErrors,
(numValidationErrors == 1 ? "" : "s"),
}
if (numValidationWarnings > 0)
{
printf( "Notice: encountered %d validation warning%s in model '%s'.\n",
numValidationWarnings,
(numValidationWarnings == 1 ? "" : "s"),
);
}
return (numConsistencyErrors == 0 && numValidationErrors == 0);
}
}
{
if (result)
{
printf("Wrote file \"%s\"\n", filename);
return 1;
}
else
{
fprintf(stderr, "Failed to write \"%s\"\n", filename );
return 0;
}
}
int ASTNode_addChild(ASTNode_t *node, ASTNode_t *child)
_tAdds_t _ta_t _tnode_t _tas_t _ta_t _tchild_t _tof_t _tanother_t _tnode_t.
Definition ASTNode.cpp:4672
ASTNode_t * ASTNode_getRightChild(const ASTNode_t *node)
_tReturns_t _tthe_t _tright_t-_tmost_t _tchild_t _tof_t _ta_t _tgiven_t _tnode_t.
Definition ASTNode.cpp:4720
ASTNode_t * ASTNode_createWithType(ASTNodeType_t type)
_tCreates_t _ta_t _tnew_t _tASTNode_t_t _tstructure_t _tand_t _tsets_t _tits_t _ttype_t.
Definition ASTNode.cpp:4627
int ASTNode_setName(ASTNode_t *node, const char *name)
_tSets_t _tthe_t _tnode_t _tto_t _trepresent_t _ta_t _tnamed_t _tentity_t.
Definition ASTNode.cpp:5182
ASTNode_t * ASTNode_getLeftChild(const ASTNode_t *node)
_tReturns_t _tthe_t _tleft_t-_tmost_t _tchild_t _tof_t _ta_t _tgiven_t _tnode_t.
Definition ASTNode.cpp:4711
void ASTNode_free(ASTNode_t *node)
_tFrees_t _tthe_t _tgiven_t _tASTNode_t_t _tstructure_t, _tincluding_t _tany_t _tchild_t _tnodes_t.
Definition ASTNode.cpp:4644
@ AST_MINUS
Definition ASTNodeType.h:85
@ AST_DIVIDE
Definition ASTNodeType.h:87
@ AST_TIMES
Definition ASTNodeType.h:86
@ AST_NAME
Definition ASTNodeType.h:95
@ AST_PLUS
Definition ASTNodeType.h:84
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_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
int FunctionDefinition_setMath(FunctionDefinition_t *fd, const ASTNode_t *math)
_tSets_t _tthe_t "_tmath_t" _tsubelement_t _tof_t _ta_t _tgiven_t _tFunctionDefinition_t_t _tstructur...
Definition FunctionDefinition.cpp:1445
int FunctionDefinition_setId(FunctionDefinition_t *fd, const char *sid)
_tSets_t _tthe_t _tvalue_t _tof_t _tthe_t "_tid_t" _tattribute_t _tof_t _ta_t _tFunctionDefinition_t_...
Definition FunctionDefinition.cpp:1423
Parameter_t * KineticLaw_createParameter(KineticLaw_t *kl)
_tCreates_t _ta_t _tnew_t _tParameter_t_t _tstructure_t, _tadds_t _tit_t _tto_t _tthe_t _tgiven_t _tK...
Definition KineticLaw.cpp:2214
int KineticLaw_setMath(KineticLaw_t *kl, const ASTNode_t *math)
_tSets_t _tthe_t _tformula_t _tof_t _tthe_t _tgiven_t _tKineticLaw_t_t _tstructure_t.
Definition KineticLaw.cpp:2136
ASTNode_t * readMathMLFromString(const char *xml)
@_tendcond_t
Definition MathML.cpp:2273
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
const char * Model_getId(const Model_t *m)
_tGet_t _tthe_t _tidentifier_t _tof_t _tthe_t _tgiven_t _tModel_t_t _tstructure_t.
Definition Model.cpp:7157
UnitDefinition_t * Model_createUnitDefinition(Model_t *m)
_tCreates_t _ta_t _tnew_t _tUnitDefinition_t_t _tstructure_t _tinside_t _tthe_t _tgiven_t _tModel_t_t...
Definition Model.cpp:7646
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
Parameter_t * Model_createParameter(Model_t *m)
_tCreates_t _ta_t _tnew_t _tParameter_t_t _tstructure_t _tinside_t _tthe_t _tgiven_t _tModel_t_t _tan...
Definition Model.cpp:7694
FunctionDefinition_t * Model_createFunctionDefinition(Model_t *m)
_tCreates_t _ta_t _tnew_t _tFunctionDefinition_t_t _tstructure_t _tinside_t _tthe_t _tgiven_t _tModel...
Definition Model.cpp:7638
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 Parameter_setId(Parameter_t *p, const char *sid)
_tAssigns_t _tthe_t _tidentifier_t _tof_t _ta_t _tParameter_t_t _tstructure_t.
Definition Parameter.cpp:2088
int Parameter_setUnits(Parameter_t *p, const char *units)
_tAssign_t _tthe_t _tunits_t _tof_t _ta_t _tParameter_t_t _tstructure_t.
Definition Parameter.cpp:2121
int Parameter_setValue(Parameter_t *p, double value)
_tAssign_t _tthe_t _tvalue_t _tof_t _ta_t _tParameter_t_t _tstructure_t.
Definition Parameter.cpp:2110
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
KineticLaw_t * Reaction_createKineticLaw(Reaction_t *r)
_tCreates_t _ta_t _tnew_t _tKineticLaw_t_t _tfor_t _tthis_t _tReaction_t_t _tand_t _treturns_t _tit_t...
Definition Reaction.cpp:3022
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
const XMLNamespaces_t * SBMLDocument_getNamespaces(SBMLDocument_t *d)
_tReturns_t _ta_t _tlist_t _tof_t _tXMLNamespaces_t_t _tassociated_t _twith_t _tthe_t _tXML_t _tconte...
Definition SBMLDocument.cpp:2555
void SBMLDocument_printErrors(SBMLDocument_t *d, FILE *stream)
_tPrints_t _tto_t _tthe_t _tgiven_t _toutput_t _tstream_t _tall_t _tthe_t _terrors_t _tor_t _twarning...
Definition SBMLDocument.cpp:2525
unsigned int SBMLDocument_checkInternalConsistency(SBMLDocument_t *d)
_tPerforms_t _tconsistency_t _tchecking_t _ton_t _tlibSBML_t'_ts_t _tinternal_t _trepresentation_t _t...
Definition SBMLDocument.cpp:2414
const SBMLError_t * SBMLDocument_getError(SBMLDocument_t *d, unsigned int n)
_tReturns_t _tthe_t _tnth_t _terror_t _tor_t _twarning_t _tencountered_t _tduring_t _tparsing_t,...
Definition SBMLDocument.cpp:2488
void SBMLDocument_free(SBMLDocument_t *d)
_tFrees_t _tthe_t _tgiven_t _tSBMLDocument_t_t _tstructure_t.
Definition SBMLDocument.cpp:2248
Model_t * SBMLDocument_getModel(SBMLDocument_t *d)
_tReturns_t _tthe_t _tModel_t_t _tstructure_t _tstored_t _tin_t _tthis_t _tSBMLDocument_t_t _tstructu...
Definition SBMLDocument.cpp:2290
unsigned int SBMLDocument_checkConsistency(SBMLDocument_t *d)
_tPerforms_t _ta_t _tset_t _tof_t _tconsistency_t _tand_t _tvalidation_t _tchecks_t _ton_t _tthe_t _t...
Definition SBMLDocument.cpp:2401
SBMLDocument_t * SBMLDocument_createWithLevelAndVersion(unsigned int level, unsigned int version)
_tCreates_t _ta_t _tnew_t, _tempty_t _tSBMLDocument_t_t _tstructure_t _twith_t _tgiven_t _tvalues_t _...
Definition SBMLDocument.cpp:2216
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
Include all SBML types in a single header file.
int writeSBML(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 _tnamed_t _tb...
Definition SBMLWriter.cpp:440
int SBase_setNotesString(SBase_t *sb, const char *notes)
_tSets_t _tthe_t _tnotes_t _tfor_t _tthe_t _tgiven_t _tSBML_t _tstructure_t.
Definition SBase.cpp:7722
int SBase_setNotes(SBase_t *sb, const XMLNode_t *notes)
_tSets_t _tthe_t _tnotes_t _tfor_t _tthe_t _tgiven_t _tSBML_t _tstructure_t.
Definition SBase.cpp:7711
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_setInitialAmount(Species_t *s, double value)
_tSets_t _tthe_t "_tinitialAmount_t" _tattribute_t _tvalue_t _tof_t _tthe_t _tgiven_t _tSpecies_t_t _...
Definition Species.cpp:2911
int Species_setName(Species_t *s, const char *name)
_tSets_t _tthe_t "_tname_t" _tattribute_t _tof_t _tthe_t _tgiven_t _tSpecies_t_t _tstructure_t.
Definition Species.cpp:2878
int Species_setInitialConcentration(Species_t *s, double value)
_tSets_t _tthe_t "_tinitialConcentration_t" _tattribute_t _tvalue_t _tof_t _tthe_t _tgiven_t _tSpecie...
Definition Species.cpp:2922
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 Unit_setScale(Unit_t *u, int value)
_tSets_t _tthe_t "_tscale_t" _tattribute_t _tvalue_t _tof_t _tthe_t _tgiven_t _tUnit_t_t _tstructure_...
Definition Unit.cpp:3038
int Unit_setExponent(Unit_t *u, int value)
_tSets_t _tthe_t "_texponent_t" _tattribute_t _tvalue_t _tof_t _tthe_t _tgiven_t _tUnit_t_t _tstructu...
Definition Unit.cpp:3022
int Unit_setKind(Unit_t *u, UnitKind_t kind)
_tSets_t _tthe_t _tkind_t _tof_t _tthe_t _tgiven_t _tUnit_t_t _tstructure_t @_tp_t _tu_t _tto_t _tthe...
Definition Unit.cpp:3014
Unit_t * UnitDefinition_createUnit(UnitDefinition_t *ud)
_tCreates_t _ta_t _tnew_t _tand_t _tempty_t _tUnit_t_t _tstructure_t, _tadds_t _tit_t _tto_t _tthe_t ...
Definition UnitDefinition.cpp:2521
int UnitDefinition_setId(UnitDefinition_t *ud, const char *id)
_tSets_t _tthe_t _tattribute_t "_tid_t" _tof_t _tthe_t _tgiven_t _tUnitDefinition_t_t _tstructure_t _...
Definition UnitDefinition.cpp:2483
@ UNIT_KIND_LITRE
Definition UnitKind.h:80
@ UNIT_KIND_MOLE
Definition UnitKind.h:85
@ UNIT_KIND_SECOND
Definition UnitKind.h:90
LIBLAX_EXTERN void XMLAttributes_free(XMLAttributes_t *xa)
_tFrees_t _tthe_t _tgiven_t _tXMLAttributes_t_t _tstructure_t.
Definition XMLAttributes.cpp:1284
LIBLAX_EXTERN XMLAttributes_t * XMLAttributes_create(void)
@_tendcond_t
Definition XMLAttributes.cpp:1276
LIBLAX_EXTERN int XMLError_isError(const XMLError_t *error)
_tPredicate_t _treturning_t @_tc_t _t1_t (_ttrue_t) _tor_t @_tc_t _t0_t (_tfalse_t) _tdepending_t _to...
Definition XMLError.cpp:1028
LIBLAX_EXTERN int XMLError_isFatal(const XMLError_t *error)
_tPredicate_t _treturning_t @_tc_t _t1_t (_ttrue_t) _tor_t @_tc_t _t0_t (_tfalse_t) _tdepending_t _to...
Definition XMLError.cpp:1037
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 XMLNode_t * XMLNode_createTextNode(const char *text)
_tCreates_t _ta_t _ttext_t _tXMLNode_t_t.
Definition XMLNode.cpp:756
LIBLAX_EXTERN void XMLNode_free(XMLNode_t *node)
_tDestroys_t _tthis_t _tXMLNode_t_t _tstructure_t.
Definition XMLNode.cpp:795
LIBLAX_EXTERN int XMLNode_addChild(XMLNode_t *node, const XMLNode_t *child)
_tAdds_t _ta_t _tcopy_t _tof_t _tchild_t _tnode_t _tto_t _tthis_t _tXMLNode_t_t _tstructure_t.
Definition XMLNode.cpp:804
LIBLAX_EXTERN XMLNode_t * XMLNode_createStartElement(const XMLTriple_t *triple, const XMLAttributes_t *attr)
_tCreates_t _ta_t _tnew_t _tstart_t _telement_t _tXMLNode_t_t _tstructure_t _twith_t _tXMLTriple_t_t ...
Definition XMLNode.cpp:726
LIBLAX_EXTERN void XMLTriple_free(XMLTriple_t *triple)
_tDestroys_t _tthis_t _tXMLTriple_t_t _tstructure_t.
Definition XMLTriple.cpp:258
LIBLAX_EXTERN XMLTriple_t * XMLTriple_createWith(const char *name, const char *uri, const char *prefix)
_tCreates_t _ta_t _tnew_t _tXMLTriple_t_t _tstructure_t _twith_t _tname_t, _tprefix_t _tand_t _turi_t...
Definition XMLTriple.cpp:249
Stores an XML namespace triple.