libSBML C++ API  5.20.4
Additional complete examples

The libSBML distribution comes with the following selection of complete example programs in the top-level file directory named examples/c++.

Simple programs

  • echoSBML.cpp: Echos (and in the process, pretty prints) an SBML model.
  • readSBML.cpp: A simple command-line program that reads an SBML file and prints some statistics about it.
  • printSBML.cpp: Prints information about the top-level model in the given SBML file.
  • printSupported.cpp: Prints the supported SBML Levels and Versions for this copy of libSBML.

More advanced programs

  • addCVTerms.cpp: Adds controlled vocabulary terms to a species in a model.
  • convertSBML.cpp: Example demonstrating how to convert SBML documents between SBML Levels.
  • getAllElementsWithNotes.cpp: Demonstrates how to use the element filter class to search the model for elements with specific attributes .
  • printMath.cpp: Prints the rule, reaction, and event formulas in a given SBML document.
  • printNotes.cpp: Prints the notes strings for each element in a given model.
  • printUnits.cpp: A command-line program that prints information about the units of measurement used in a given SBML file.
  • renameSId.cpp: Program that renames a specific SId and updates all references to it in a given model.
  • rngvalidator.cpp: Example of creating a RELAX NG (RNG) validator to be called during validation.
  • setIdFromNames.cpp: Program that renames all SIds that also have names specified. The new identifiers will be derived from the name, with all invalid characters removed.
  • setNamesFromIds.cpp: Program that changes all objects' "name" attribute values to match their "id" attribute values.
  • stripPackage.cpp: Strips the given SBML Level 3 package from the given SBML file.
  • translateL3Math.cpp: Translates infix formulas into MathML and vice-versa, using the SBML Level 3 parser instead of the old Level 1 parser.
  • unsetNotes.cpp: Unsets the notes for each element in the given SBML file.

Programs using SBML Level 3 packages

The following examples use specific libSBML plug-ins to support SBML Level 3 packages. The use of these packages requires your copy of libSBML to have been configured to enable the appropriate plug-in. The default installation of libSBML comes with the packages below already enabled, but beware that if you built libSBML from source code and disabled one or more of these packages, then their features will not be available.

Package: Flux Balance Constraints

The Flux Balance Constraints package has the nickname “fbc”. The libSBML classes that implement this package are marked with the symbol fbc in the libSBML documentation.

  • fbc_example1.cpp: Simple example of writing a model that uses the SBML Level 3 Flux Balance Constraints package.
  • convertCobraToFbc.cpp: Example of converting a COBRA-style SBML Level 2 model to SBML Level 3 using the Flux Balance Constraints package.
  • convertFbcToCobra.cpp: Example of converting an SBML Level 3 model using the Flux Balance Constraints package to a COBRA-style SBML Level 2 model.

Package: Groups

The Groups package has the nickname “groups”. The libSBML classes that implement this package are marked with the symbol groups in the libSBML documentation.

  • groups_example1.cpp: Simple example of writing a model that uses the SBML Level 3 Groups package.
  • groups_example2.cpp: Simple example of writing a model that uses the SBML Level 3 Groups package and also the SBML Level 3 Layout package.

Package: Hierarchical Model Composition

The Hierarchical Model Composition package has the nickname “comp”. The libSBML classes that implement this package are marked with the symbol comp in the libSBML documentation.

  • spec_example1.cpp: Example #1 from the SBML Level 3 Hierarchical Model Composition specification.
  • spec_example2.cpp: Example #2 from the SBML Level 3 Hierarchical Model Composition specification.
  • spec_example3.cpp: Example #3 from the SBML Level 3 Hierarchical Model Composition specification.
  • spec_example4.cpp: Example #4 from the SBML Level 3 Hierarchical Model Composition specification.

Package: Layout

The Layout package has the nickname “layout”. The libSBML classes that implement this package are marked with the symbol layout in the libSBML documentation.

  • addLayout.cpp: Simple example of using the SBML graphical layout specification, in both Level 2 and Level 3.

Package: Qualitative Models

The Qualitative Models package has the nickname “qual”. The libSBML classes that implement this package are marked with the symbol qual in the libSBML documentation.

  • qual_example1.cpp: An example of creating a model using SBML Level 3 Qualitative Models.