sbmlutils.converters.xpp

XPP ode to SBML file converter.

XPP file format is described here http://www.math.pitt.edu/~bard/bardware/tut/newstyle.html

Every ODE file consists of a series of lines that start with a keyword followed by numbers, names, and formulas or declare a named formula such as a differential equation or auxiliary quantity. Only the first letter of the keyword is important; e.g. the parser treats “parameter” and “punxatawney” exactly the same. The parser can understand lines up to 256 characters. You can use line continuation by adding a backslash character. The first line of the file cannot be a number (as this tells XPP that the file is in the old-style) but can be any other charcter or declaration. It is standard form to make the first line a comment which has the name of the file, but this is optional.

! Variables have to be case sensitive !. These issues can easily be fixed based on validator output.

Only supports subset of features. Not supported: - table - sum, - shift - set - boundary - ran - arrays

shift(var,expr) This operator evaluates the expression expr converts it to an integer and then uses this to indirectly address a variable whose address is that of var plus the integer value of the expression. This is a way to imitate arrays in XPP. For example if you defined the sequence of 5 variables, u0,u1,u2,u3,u4 one right after another, then shift(u0,2) would return the value of u2.

sum(ex1,ex2)of(ex3) is a way of summing up things. The expressions ex1>, are evaluated and their integer parts are used as the lower and upper limits of the sum. The index of the sum is i’ so that you cannot have double sums since there is only one index. ex3 is the expression to be summed and will generally involve i’ For example sum(1,10)of(i’) will be evaluated to 55. Another example combines the sum with the shift operator. sum(0,4)of(shift(u0,i’)) will sum up u0 and the next four variables that were defined after it.

Module Contents

Functions

escape_string(info)

Escape string.

parse_keyword(xpp_id)

Parse the keyword and returns the xpp keyword type.

parts_from_expression(expression)

Return the parts of given expression.

sid_value_from_part(part)

Get sid, value tuple from given part of expression.

xpp2sbml(xpp_file, sbml_file[, force_lower, validate, ...])

Read given xpp_file and converts to SBML file.

Attributes

XPP_ODE

XPP_DE

XPP_IE

XPP_FUN

XPP_INIT

XPP_AUX

XPP_MAR

XPP_WIE

XPP_GLO

XPP_PAR

XPP_NUM

XPP_TAB

XPP_COMMENT_CHARS

XPP_CONTINUATION_CHAR

XPP_SETTING_CHAR

XPP_END_WORD

XPP_TYPE_CHARS

NOTES

sbmlutils.converters.xpp.XPP_ODE = 'ode'[source]
sbmlutils.converters.xpp.XPP_DE = 'difference equation'[source]
sbmlutils.converters.xpp.XPP_IE = 'integral equation'[source]
sbmlutils.converters.xpp.XPP_FUN = 'functions'[source]
sbmlutils.converters.xpp.XPP_INIT = 'initial data'[source]
sbmlutils.converters.xpp.XPP_AUX = 'auxiliary quantities'[source]
sbmlutils.converters.xpp.XPP_MAR = 'markov variables'[source]
sbmlutils.converters.xpp.XPP_WIE = 'wiener variables'[source]
sbmlutils.converters.xpp.XPP_GLO = 'global flags'[source]
sbmlutils.converters.xpp.XPP_PAR = 'parameter'[source]
sbmlutils.converters.xpp.XPP_NUM = 'number'[source]
sbmlutils.converters.xpp.XPP_TAB = 'table'[source]
sbmlutils.converters.xpp.XPP_COMMENT_CHARS = ['#', '%', '"'][source]
sbmlutils.converters.xpp.XPP_CONTINUATION_CHAR = '\\'[source]
sbmlutils.converters.xpp.XPP_SETTING_CHAR = '@'[source]
sbmlutils.converters.xpp.XPP_END_WORD = 'done'[source]
sbmlutils.converters.xpp.XPP_TYPE_CHARS[source]
sbmlutils.converters.xpp.NOTES = Multiline-String[source]
Show Value
"""
    <body xmlns='http://www.w3.org/1999/xhtml'>
    <h1>XPP model</h1>
    <p>This model was converted from XPP ode format to SBML using <code>sbmlutils</code>.</p>
    <pre>{}</pre>
    <div class="dc:publisher">This file has been produced by
      <a href="https://github.com/matthiaskoenig/sbmlutils/" title="sbmlutils" target="_blank">sbmlutils</a>.
    </div>

    <h2>Terms of use</h2>
      <div class="dc:rightsHolder">Copyright © 2017 Matthias Koenig</div>
      <div class="dc:license">
      <p>Redistribution and use of any part of this model, with or without modification, are permitted provided that
      the following conditions are met:
        <ol>
          <li>Redistributions of this SBML file must retain the above copyright notice, this list of conditions
              and the following disclaimer.</li>
          <li>Redistributions in a different form must reproduce the above copyright notice, this list of
              conditions and the following disclaimer in the documentation and/or other materials provided
          with the distribution.</li>
        </ol>
        This model is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
             the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</p>
      </div>
    </body>
"""
sbmlutils.converters.xpp.escape_string(info)[source]

Escape string.

Parameters:

info (str) –

Return type:

str

sbmlutils.converters.xpp.parse_keyword(xpp_id)[source]

Parse the keyword and returns the xpp keyword type.

Parameters:

xpp_id (str) –

Returns:

Return type:

Optional[str]

sbmlutils.converters.xpp.parts_from_expression(expression)[source]

Return the parts of given expression.

The parts can be whitespace or comma separated.

V1=-0.75 R1=0.26 CA1=0.1 H1=0.1 V1=-0.75, R1=0.26, CA1=0.1, H1=0.1

but there can also be commas in function definitions vex=vex(t,freq,vext)

Returns:

list of cleaned parts

Parameters:

expression (str) –

Return type:

List[str]

sbmlutils.converters.xpp.sid_value_from_part(part)[source]

Get sid, value tuple from given part of expression.

Parameters:

part (str) –

Returns:

Return type:

Tuple[str, str]

sbmlutils.converters.xpp.xpp2sbml(xpp_file, sbml_file, force_lower=False, validate=True, debug=False)[source]

Read given xpp_file and converts to SBML file.

Parameters:
  • debug (bool) –

  • xpp_file (pathlib.Path) – xpp input ode file

  • sbml_file (pathlib.Path) – sbml output file

  • force_lower (bool) – force lower case for all lines

  • validate (bool) – perform validation on the generated SBML file

Returns:

Return type:

libsbml.SBMLDocument