— the global portal for all things SBML

Current layout implementation

Details here are given to outline a suggested approach for the preliminary development of libSBML code to support SBML extensions, until we have a working implementation of the a more robust API. In a nutshell, we suggest that people wishing to start coding mimic the way the current layout extension is implemented in libSBML.

SBML file

The main layout information appears within the annotation element on the model component of an SBML file, as shown:

<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="" level="2" version="1">
  <model id="TestModel">
      <listOfLayouts xmlns=""  
        <layout id="Layout_1">
          <dimensions width="400" height="220"/>
            <compartmentGlyph id="CompartmentGlyph_1"
              <boundingBox id="bb1">
                <position x="5" y="5"/>
                <dimensions width="390" height="210"/>
            <reactionGlyph id="ReactionGlyph_1" reaction="Reaction_1">
                  <curveSegment xsi:type="LineSegment">
                    <start x="165" y="105"/>
                    <end x="165" y="115"/>
            <textGlyph id="TextGlyph_01" graphicalObject="SpeciesGlyph_1"
              <boundingBox id="bbA">
                <position x="92" y="26"/>
                <dimensions width="228" height="24"/>

Additionally the layout extension adds information within the annotation element of a speciesReference component.

      <reaction id="Reaction_1" reversible="false">
          <speciesReference species="Species_1">
              <layoutId xmlns=""

Storing extension information as annotations means that reading and writing of the information is easily achieved within libSBML, without too much code that will eventually become redundant as the modularization API is established. (Honestly it's minimal Image:icon_smile.gif.)

Source code

Core libSBML is written in C++ and thus code for any extensions will have to be written in C++.


Any classes introduced by layout are added to the SBMLTypeCode_t enumeration in the SBMLTypeCodes.h file. The class/structure variants of each are included in sbmlfwd.h via a separate layoutfwd.h file. The extension adds a ListOfLayouts to the model which is used to store the attributes and values of the layout specific classes after they have been either read or created.


The class definition and functions for the layout extension are contained within the layout directory of the libSBML source tree. For historical reasons this directory is a subdirectory of the src/sbml directory. It is not strictly speaking necessary that any other extensions are located as subdirectories of sbml, however doing so makes adding extensions to the build process much easier so it is recommended. There are additional files, LayoutAnnotation.cpp and LayoutAnnotation.h in the src/annotation directory, that contain the functions that parse the annotation into the appropriate classes or the ListOfLayouts into an annotation.

Preprocessor definitions

The layout extension uses the preprocessor definition USE_LAYOUT which is defined when --enable-layout is specified using the configure script. The source code files use #ifdef USE_LAYOUT to introduce layout specific code within the core libSBML code and the 'Makefile's use the flag to add the appropriate files to the build process.

Specific layout code

Since only the model and speciesReference components contain layout information, the use of #ifdef USE_LAYOUT occurs only within the Model and SpeciesReference files. The code included within the core libSBML relates only to reading and writing layout information and general housekeeping functions such as copy, clone etc.

Language bindings

The src/bindings directory contains subdirectories for each of the language bindings. In the case of those bindings generated by SWIG, the local.i file in the relevant language directory uses the USE_LAYOUT flag to add appropriate information for the layout extension to the file.

Retrieved from ""

This page was last modified 09:51, 17 August 2008.

Please use our issue tracking system for any questions or suggestions about this website. This page was last modified 09:51, 17 August 2008.