libSBML Python API  5.18.0
Additional complete example programs

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

Simple programs

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

More advanced programs

  • addCVTerms.py: Adds controlled vocabulary terms to a species in a model.
  • convertSBML.py: Example demonstrating how to convert SBML documents between SBML Levels.
  • createExampleSBML.py: Lengthy example of creating SBML models presented in the SBML specification.
  • getAllElementsWithNotes.py: Demonstrates how to use the element filter class to search the model for elements with specific attributes .
  • printMath.py: Prints the rule, reaction, and event formulas in a given SBML document.
  • printNotes.py: Prints the notes strings for each element in a given model.
  • printRegisteredPackages.py: A command-line program that prints the package plug-ins that are registered with this copy of libSBML.
  • printUnits.py: A command-line program that prints information about the units of measurement used in a given SBML file.
  • setIdFromNames.py: Program that renames all SIds that also have names specified. The new identifiers will be derived from the name, with all invalid characters removed.
  • stripPackage.py: Strips the given SBML Level 3 package from the given SBML file.
  • unsetNotes.py: 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.py: Simple example of writing a model that uses the SBML Level 3 Flux Balance Constraints package.
  • convertCobraToFbc.py: Example of converting a COBRA-style SBML Level 2 model to SBML Level 3 using the Flux Balance Constraints package.
  • convertFbcToCobra.py: 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.py: Simple example of writing a model that uses the SBML Level 3 Groups 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.

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.

  • convertLayout.py: Converts SBML Layout and Render data from SBML Level 2 to Level 3 and vice versa.

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.py: An example of creating a model using SBML Level 3 Qualitative Models.