libSBML Python API  5.18.0
libsbml.SBMLConverter Class Reference
Inheritance diagram for libsbml.SBMLConverter:
[legend]

Detailed Description

Base class for SBML converters.

This class of objects is defined by libSBML only and has no direct equivalent in terms of SBML components. It is a class used in the implementation of extra functionality provided by libSBML.

The SBMLConverter class is the base class for the various SBML converters: classes of objects that transform or convert SBML documents. These transformations can involve essentially anything that can be written algorithmically; examples include converting the units of measurement in a model, or converting from one Level+Version combination of SBML to another. Applications can also create their own converters by subclassing SBMLConverter and following the examples of the existing converters.

General information about the use of SBML converters

The use of all the converters follows a similar approach. First, one creates a ConversionProperties object and calls ConversionProperties.addOption() on this object with one argument: a text string that identifies the desired converter. (The text string is specific to each converter; consult the documentation for a given converter to find out how it should be enabled.)

Next, for some converters, the caller can optionally set some converter-specific properties using additional calls to ConversionProperties.addOption(). Many converters provide the ability to configure their behavior to some extent; this is realized through the use of properties that offer different options. The default property values for each converter can be interrogated using the method SBMLConverter.getDefaultProperties() on the converter class in question .

Finally, the caller should invoke the method SBMLDocument.convert() with the ConversionProperties object as an argument.

Example of invoking an SBML converter

The following code fragment illustrates an example using SBMLReactionConverter, which is invoked using the option string 'replaceReactions':

1 config = ConversionProperties()
2 if config != None:
3  config.addOption('replaceReactions')

In the case of SBMLReactionConverter, there are no options to affect its behavior, so the next step is simply to invoke the converter on an SBMLDocument object. Continuing the example code:

1 # Assume that the variable 'document' has been set to an SBMLDocument object.
2 status = document.convert(config)
3 if status != LIBSBML_OPERATION_SUCCESS:
4  # Handle error somehow.
5  print('Error: conversion failed due to the following:')
6  document.printErrors()

Here is an example of using a converter that offers an option. The following code invokes SBMLStripPackageConverter to remove the SBML Level 3 Layout package from a model. It sets the name of the package to be removed by adding a value for the option named 'package' defined by that converter:

1 def strip_layout_example(document):
2  config = ConversionProperties()
3  if config != None:
4  config.addOption('stripPackage')
5  config.addOption('package', 'layout')
6  status = document.convert(config)
7  if status != LIBSBML_OPERATION_SUCCESS:
8  # Handle error somehow.
9  print('Error: unable to strip the Layout package.')
10  print('LibSBML returned error: ' + OperationReturnValue_toString(status).strip())
11  else:
12  # Handle error somehow.
13  print('Error: unable to create ConversionProperties object')

Available SBML converters in libSBML

LibSBML provides a number of built-in converters; by convention, their names end in Converter. The following are the built-in converters provided by libSBML 5.18.0:

Public Member Functions

def __init__ (self, args)
 This method has multiple variants; they differ in the arguments they accept. More...
 
def clone (self)
 Creates and returns a deep copy of this SBMLConverter object. More...
 
def convert (self)
 Perform the conversion. More...
 
def getDefaultProperties (self)
 Returns the default properties of this converter. More...
 
def getDocument (self, args)
 Returns the SBML document that is the subject of the conversions. More...
 
def getName (self)
 Returns the name of this converter. More...
 
def getProperties (self)
 Returns the current properties in effect for this converter. More...
 
def getTargetNamespaces (self)
 Returns the target SBML namespaces of the currently set properties. More...
 
def matchesProperties (self, props)
 Returns True if this converter matches the given properties. More...
 
def setDocument (self, doc)
 This method has multiple variants; they differ in the arguments they accept. More...
 
def setProperties (self, props)
 Sets the configuration properties to be used by this converter. More...
 

Constructor & Destructor Documentation

def libsbml.SBMLConverter.__init__ (   self,
  args 
)

This method has multiple variants; they differ in the arguments they accept.

__init__()   SBMLConverter
__init__(string name)   SBMLConverter
__init__(SBMLConverter orig)   SBMLConverter

Each variant is described separately below.


Method variant with the following signature:
SBMLConverter()

Creates a new SBMLConverter object.


Method variant with the following signature:
SBMLConverter(SBMLConverter orig)

Copy constructor.

This creates a copy of an SBMLConverter object.

Parameters
origthe SBMLConverter object to copy.

Method variant with the following signature:
SBMLConverter(string name)

Creates a new SBMLConverter object with a given name.

Parameters
namethe name for the converter to create.

Member Function Documentation

def libsbml.SBMLConverter.clone (   self)

Creates and returns a deep copy of this SBMLConverter object.

clone()   SBMLConverter
Returns
the (deep) copy of this SBMLConverter object.
def libsbml.SBMLConverter.convert (   self)

Perform the conversion.

convert()   int

This method causes the converter to do the actual conversion work, that is, to convert the SBMLDocument object set by SBMLConverter.setDocument() and with the configuration options set by SBMLConverter.setProperties().

Returns
integer value indicating the success/failure of the operation. The set of possible values that may be returned depends on the converter subclass; please consult the documentation for the relevant class to find out what the possibilities are.
def libsbml.SBMLConverter.getDefaultProperties (   self)

Returns the default properties of this converter.

getDefaultProperties()   ConversionProperties

A given converter exposes one or more properties that can be adjusted in order to influence the behavior of the converter. This method returns the default property settings for this converter. It is meant to be called in order to discover all the settings for the converter object. The run-time properties of the converter object can be adjusted by using the method SBMLConverter.setProperties().

Returns
the default properties for the converter.
See also
setProperties()
matchesProperties()
def libsbml.SBMLConverter.getDocument (   self,
  args 
)

Returns the SBML document that is the subject of the conversions.

getDocument()   SBMLDocument
Returns
the current SBMLDocument object.
def libsbml.SBMLConverter.getName (   self)

Returns the name of this converter.

getName()   string
Returns
a string, the name of this converter.
def libsbml.SBMLConverter.getProperties (   self)

Returns the current properties in effect for this converter.

getProperties()   ConversionProperties

A given converter exposes one or more properties that can be adjusted in order to influence the behavior of the converter. This method returns the current properties for this converter; in other words, the settings in effect at this moment. To change the property values, you can use SBMLConverter.setProperties().

Returns
the currently set configuration properties.
See also
setProperties()
matchesProperties()
def libsbml.SBMLConverter.getTargetNamespaces (   self)

Returns the target SBML namespaces of the currently set properties.

getTargetNamespaces()   SBMLNamespaces

SBML namespaces are used by libSBML to express the Level+Version of the SBML document (and, possibly, any SBML Level 3 packages in use). Some converters' behavior is affected by the SBML namespace configured in the converter. For example, in SBMLLevelVersionConverter (the converter for converting SBML documents from one Level+Version combination to another), the actions are fundamentally dependent on the SBML namespaces targeted.

Returns
the SBMLNamespaces object that describes the SBML namespaces in effect, or None if none are set.
def libsbml.SBMLConverter.matchesProperties (   self,
  props 
)

Returns True if this converter matches the given properties.

matchesProperties(ConversionProperties props)   bool

Given a ConversionProperties object props, this method checks that props possesses an option value to enable this converter. If it does, this method returns True.

Parameters
propsthe properties to match.
Returns
True if the properties props would match the necessary properties for this type of converter, False otherwise.
def libsbml.SBMLConverter.setDocument (   self,
  doc 
)

This method has multiple variants; they differ in the arguments they accept.

setDocument(SBMLDocument doc)   int

Each variant is described separately below.


Method variant with the following signature:
setDocument(SBMLDocument doc)

Sets the SBML document to be converted.

Parameters
docthe document to use for this conversion.
Returns
integer value indicating the success/failure of the operation. The set of possible values that may be returned ultimately depends on the specific subclass of SBMLConverter being used, but the default method can return the following:

Method variant with the following signature:
setDocument(SBMLDocument doc)

Sets the SBML document to be converted.

Parameters
docthe document to use for this conversion.
Returns
integer value indicating the success/failure of the operation. The set of possible values that may be returned ultimately depends on the specific subclass of SBMLConverter being used, but the default method can return the following:
def libsbml.SBMLConverter.setProperties (   self,
  props 
)

Sets the configuration properties to be used by this converter.

setProperties(ConversionProperties props)   int
Parameters
propsthe ConversionProperties object defining the properties to set.
Returns
integer value indicating the success/failure of the operation. The set of possible values that may be returned ultimately depends on the specific subclass of SBMLConverter being used, but the default method can return the following values:
See also
getProperties()
matchesProperties()