Verification of required attributes and elements
All SBML components have a number of attributes, and in some cases subelements too. An attribute has a name and a value. An element refers to another type of component within SBML (e.g., a
math element or a
listOfXYZ element). Many attributes and elements are optional, but some are required. However, in libSBML up through version 3, object constructors do not check for required attributes; callers must know which attributes and elements are required or else rely on a full validation pass to check for mistakes. This arrangement is error-prone at best.
Example of the issue
Consider the following code;
Model *m = new Model(2, 4); Compartment *c = new Compartment(2, 4); Event *e = new Event(2, 4); m->addCompartment(c); m->addEvent(e);
The code above creates a model with a compartment and an event. No errors will be generated at any point. However, the model is invalid for three reasons:
- The compartment has no id.
- The event has no trigger.
- The event has no eventAssignments.
Other than performing a full validation of an SBMLDocument, libSBML version 3 does not provide any means of checking whether an object has all its required attributes and/or elements.
In order to facilitate the creation of valid SBML, libSBML version 4 includes two new methods on each
virtual bool hasRequiredAttributes();
virtual bool hasRequiredElements();
These methods return
true if the object has all the required attributes/elements, and they return
false otherwise. The new addXXX functions use these methods to determine whether the object being added is valid, but they may also be useful to call directly.
Required attributes and elements
The table lists the required attributes and elements for each component.
|Component||Required Attributes||Required Elements|
|Model||-||listOfCompartment (L1 only)|
listOfSpecies (L1V1 only)
listOfReactions (L1V1 only)
|UnitDefinition||id||listOfUnits (L2 only)|
initialAmount (L1 only)
value (L1V1 only)
|AlgebraicRule||formula (L1 only)||math (L2 only)|
|KineticLaw||formula (L1 only)||math (L2 only)|