LibSBML

Software library for the SBML format


title: "LibSBML" type: doc version: 1 created: 2026-02-28 author: "Wikipedia contributors" status: active scope: public tags: ["c++-libraries", "free-software-programmed-in-c++", "software-using-the-gnu-lesser-general-public-license", "cross-platform-free-software", "free-computer-libraries", "free-science-software", "articles-with-example-python-(programming-language)-code"] description: "Software library for the SBML format" topic_path: "general/c-libraries" source: "https://en.wikipedia.org/wiki/LibSBML" license: "CC BY-SA 4.0" wikipedia_page_id: 0 wikipedia_revision_id: 0

::summary Software library for the SBML format ::

::data[format=table title="Infobox software"]

FieldValue
namelibSBML
logo size150px
developerThe SBML Team
released
genreXML parser library
latest release version5.20.4
latest release date
programming languageC++, C
operating systemWindows, Mac OS, Unix-like
licenseLGPL License v2.1
websitesbml.org
::

| name = libSBML | logo = | logo size = 150px | caption = | developer = The SBML Team | released = | genre = XML parser library | latest release version = 5.20.4 | latest release date = | programming language = C++, C | operating system = Windows, Mac OS, Unix-like | license = LGPL License v2.1 | website = sbml.org

LibSBML is an open-source software library that provides an application programming interface (API) for the SBML (Systems Biology Markup Language {{Cite journal | last1 = Hucka | first1 = M. | last2 = Finney | first2 = A. | last3 = Sauro | first3 = H. M. | last4 = Bolouri | first4 = H. | last5 = Doyle | first5 = J. C. | last6 = Kitano | first6 = H. |author-link6= Hiroaki Kitano | last7 = Arkin | first7 = A. P. | last8 = Bornstein | first8 = A. P. | last9 = Bray | first9 = B. J. | last10 = Cornish-Bowden | doi = 10.1093/bioinformatics/btg015 | first10 = D. | last11 = Cuellar | first11 = A. | last12 = Dronov | first12 = A. A. | last13 = Gilles | first13 = S. | last14 = Ginkel | first14 = E. D. | last15 = Gor | first15 = M. | last16 = Goryanin | first16 = V. | last17 = Hedley | first17 = I. I. | last18 = Hodgman | first18 = W. J. | last19 = Hofmeyr | first19 = T. C. | last20 = Hunter | first20 = J. -H. | last21 = Juty | first21 = P. J. | last22 = Kasberger | first22 = N. S. | last23 = Kremling | first23 = J. L. | last24 = Kummer | first24 = A. | last25 = Le Novère | first25 = U. | last26 = Loew | first26 = N. | last27 = Lucio | first27 = L. M. | last28 = Mendes | first28 = P. |author-link28= Pedro Pedrosa Mendes | last29 = Minch | first29 = P. | last30 = Mjolsness | first30 = E. | title = The systems biology markup language (SBML): A medium for representation and exchange of biochemical network models | journal = Bioinformatics | volume = 19 | issue = 4 | pages = 524–531 | year = 2003 | pmid = 12611808 | pmc = | doi-access = free |last1 = Finney |first1 = A. |last2 = Hucka |first2 = M. |title = Systems biology markup language: Level 2 and beyond |journal = Biochemical Society Transactions |volume = 31 |issue = Pt 6 |pages = 1472–1473 |year = 2003 |doi = 10.1042/bst0311472 |pmid = 14641091 |pmc = |citeseerx = 10.1.1.466.8001 | doi = 10.1049/sb:20045008 | last1 = Hucka | first1 = M. | last2 = Finney | first2 = A. | last3 = Bornstein | first3 = B. J. | last4 = Keating | first4 = S. M. | last5 = Shapiro | first5 = B. E. | last6 = Matthews | first6 = J. | last7 = Kovitz | first7 = B. L. | last8 = Schilstra | first8 = M. J. | last9 = Funahashi | first9 = A. | last10 = Doyle | first10 = S. M. | last11 = Kitano | first11 = M. J. | title = Evolving a lingua franca and associated software infrastructure for computational systems biology: The Systems Biology Markup Language (SBML) project | journal = Systems Biology | volume = 1 | issue = 1 | pages = 41–53 | year = 2004 | doi-broken-date = 12 July 2025 | pmid = 17052114 | url = https://authors.library.caltech.edu/2099/1/HUCieesb04.pdf

The libSBML library is free software released under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation; either version 2.1 of the License, or any later version. LibSBML was developed thanks to funding from many agencies, particularly the National Institute of General Medical Sciences (NIGMS, USA) as well as the Defense Advanced Research Projects Agency (DARPA, USA) under the Bio-SPICE program.

Description

The Systems Biology Markup Language (SBML) is an XML-based format for encoding computational models of a sort common in systems biology. Although SBML is based upon XML, and thus software developers could support SBML using off-the-shelf XML parser libraries, libSBML offers numerous advantages that make it easier for developers to implement support for SBML in their software. The premise behind the development of libSBML is that it is more convenient and efficient for developers to start with a higher-level API tailored specifically to SBML and its distinctive features than it is to start with a plain XML parser library.

Significant features of libSBML

The following is a partial list of libSBML's features:

  • Supports all Levels and Versions of SBML with common API classes and methods, thus smoothing the differences between different flavors of SBML from the perspective of the application software.
  • Provides facilities for manipulating mathematical formulas in both text-string format and MathML 2.0 format, as well as the ability to interconvert mathematical expressions between these forms. Internally, libSBML uses familiar Abstract Syntax Trees (ASTs) to represent formulas, and provides AST-oriented methods for calling applications.
  • Performs validation of XML and SBML at the time of parsing files and data streams. This helps verify the correctness of models in a way that goes beyond simple syntactic validation.
  • Offers support for dimensional analysis and unit checking. LibSBML implements a thorough system for dimensional analysis and checking units of quantities in a model.
  • Provides facilities for the creation and manipulation of SBML annotations and notes. These have a specific format dictated by the SBML specifications. The formats and standards supported by libSBML include MIRIAM (Minimal Information Requested in the Annotation of a Model) and SBO (the Systems Biology Ontology).
  • Supports transparently reading and writing compressed files in the ZIP, GZIP and BZIP formats.
  • Provides interfaces for the C, C++, C#, Java, Python, Perl, MATLAB, Octave, and Ruby programming languages. The C and C++ interfaces are implemented natively; the C#, Java, Perl, Python, and Ruby interfaces are implemented using SWIG, the Simplified Wrapper Interface Generator; and the MATLAB and Octave interfaces are implemented through custom hand-written code.
  • Provides many convenience methods, such as for obtaining a count of the number of boundary condition species, determining the modifier species of a reaction (assuming the reaction provides kinetics), constructing the stoichiometric matrix for all reactions in a model, and more.

Manipulation of mathematical formulas

Some further explanations may be warranted concerning libSBML's support for working with mathematical formulas. In SBML Level 1, mathematical formulas are represented as text strings using a C-like syntax. This representation was chosen because of its simplicity, widespread familiarity and use in applications such as GEPASI{{Cite journal | last1 = Mendes | first1 = P. |author-link1= Pedro Pedrosa Mendes | title = GEPASI: A software package for modelling the dynamics, steady states and control of biochemical and other systems | journal = Computer Applications in the Biosciences | volume = 9 | issue = 5 | pages = 563–571 | year = 1993 | doi = 10.1093/bioinformatics/9.5.563 | pmid = 8293329 | title-link = COPASI | doi-access = free

As mentioned above, LibSBML provides an abstraction for working with mathematical expressions in both text-string and MathML form: Abstract Syntax Trees (ASTs). Abstract Syntax Trees are well known in the computer science community; they are simple recursive data structures useful for representing the syntactic structure of sentences in certain kinds of languages (mathematical or otherwise). Much as libSBML allows programmers to manipulate SBML at the level of domain-specific objects, regardless of SBML Level or version, it also allows programmers to work with mathematical formula at the level of ASTs regardless of whether the original format was C-like infix or MathML. LibSBML goes one step further by allowing programmers to work exclusively with infix formula strings and instantly convert them to the appropriate MathML whenever needed.

Dependencies

LibSBML requires a separate library to do low-level read/write operations on XML. It can use any one of three XML parser libraries: Xerces, expat or libxml2. Users can specify which library they wish to use at libSBML compilation time. LibSBML hides the differences between these parser libraries behind an abstraction layer; it seamlessly uses whichever library against which a given instance of libSBML has been compiled. (However, released binary distributions of libSBML all make use of the libxml2 library.)

Usage

LibSBML uses software objects (i.e., instances of classes) that correspond to SBML components, with member variables representing the attributes of the corresponding SBML objects. The libSBML API is constructed to provide an intuitive way of relating SBML and the code needed to create or manipulate it with a class hierarchy that mimics the SBML structure. More information about the libSBML objects is available in the libSBML API documentation.

Reading and writing SBML

LibSBML enables reading from and writing to either files or strings. Once an SBML document is read, libSBML stores the SBML content in an SBMLDocument object. This object can be written out again later. The following is an example written in Python:

::code[lang=pycon]

import libsbml

read a document

doc = libsbml.readSBMLFromFile(filename) doc = libsbml.readSBMLFromString(string)

helper function that takes either a string

or filename as argument

doc = libsbml.readSBML(filename) doc = libsbml.readSBML(string)

write a document

libsbml.writeSBMLToFile(doc, filename) True

libsbml.writeSBMLToString(doc) '\n \n
\n \n' ::

Creating and manipulating SBML

The libSBML API allows easy creation of objects and subobjects representing SBML elements and the subelements contained within them. The following is an example written in C++:

::code[lang=cpp] void createSBML() { // create an SBML Level 3 Version 1 document SBMLDocument* doc = new SBMLDocument(3, 1);

// create the model as a sub element of the document Model * model = doc->createModel();

// create a compartment as a sub element of the model Compartment * compartment1 = model->createCompartment();

// create an independent compartment and then add it to the model Compartment * compartment2 = new Compartment(3, 1); model->addCompartment(compartment2); } ::

Accessing attributes

Each component in SBML has a number of attributes associated with it. These are stored as member variables of a given class, and libSBML provides functions to retrieve and query these values. The syntax of these functions is consistent throughout libSBML. The following is an example written in Python:

::code[lang=pycon]

import libsbml

create an SBML Level 3 Version 1 document

sbmlns = libsbml.SBMLNamespaces(3, 1) doc = libsbml.SBMLDocument(sbmlns)

#create the model as a sub element of the document model = doc.createModel()

#create a compartment as a sub element of the model compartment = model.createCompartment()

set the attributes on the compartment

note a return value of 0 indicates success

compartment.setId("cell") 0 compartment.setSize(2.3) 0 compartment.setSpatialDimensions(3) 0 compartment.setUnits("litre") 0 compartment.setConstant(True) 0

get the attribute values

compartment.getId() 'cell' compartment.getSpatialDimensions() 3

examine the status of the attribute

compartment.isSetSize() True compartment.getSize() 2.3

#unset an attribute value compartment.unsetSize() 0 compartment.isSetSize() False compartment.getSize() nan ::

References

References

  1. Jarnac, Sauro H. "A system for interactive metabolic analysis". In: Hofmeyr, J-HS, et al., eds. ''Animating the Cellular Map: Proceedings of the 9th International Meeting on BioThermoKinetics''. Stellenbosch, South Africa: Stellenbosch University Press; 2000. pp. 221–228.

::callout[type=info title="Wikipedia Source"] This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page. ::

c++-librariesfree-software-programmed-in-c++software-using-the-gnu-lesser-general-public-licensecross-platform-free-softwarefree-computer-librariesfree-science-softwarearticles-with-example-python-(programming-language)-code