Latest Versions


Stable:
COPASI 4.6 (Build 32)
Development:
COPASI 4.5.31 (development)

VT Tribute

10. User Defined Functions

COPASI already defines a large set of commonly used kinetic functions to choose from. The list of defined functions is located at the last branch in the object tree.

Function table with predefined functions

Function table

Nevertheless sometimes you need to define your own kinetic function to solve a specific problem. COPASI enables you to add a new function either by double clicking on an empty table row or by clicking on the New button on the bottom of the screen. In the function definition dialog, you give your function a name in the Function Name field. This name has to be unique within the list of defined functions. Next, you have to specify a formula that defines the reaction rate of your kinetic function in the Formula field. The function string only covers the right side of the rate function.

Dialog for the definition of functions

Function definition dialog

So for Michaelis-Menten which is defined as you would enter into the Formula field. While you are typing the formula, COPASI already tries to parse the equation and extract the parameters. All parameters that COPASI finds are listed in the Parameters table.

Function definition dialog with committed function

Function definition dialog with graphical display of the function

In COPASI parameters can have arbitrary names, there are only a few rules that one has to be aware of. If a parameter starts with a letter or underscore character and contains only letters, digits and underscore characters all is well, if however the parameter name contains other characters, the whole parameter name has to be enclosed in double quotes. If the parameter name contains double quotes or backslashes those have to be escaped by a backslash.

As all variables found are defined, per default, as Parameters, you should specify their correct types by selecting one from the drop down list Description. However, the specific type of variables will affect to the type of reactions the function can be used for. E.g, if you define the function to contain two substrates and a modifier, you can later only use it for reactions that really do have two substrates.

Note

The restrictions on the number of modifiers is not strict since substrates and reactants could act as modifiers. So the above mentioned rate law could be used on reactions that do not explicitly specify a modifier.

You can also see this in the Application restrictions table below the Parameters table. Let's say you define the function and define A and B to be substrates, you will see that the Application restrictions say that there must be exactly two substrates in the reaction for that kinetics to be applicable. After defining this function, you will be able to use it for all chemical reaction that have exactly two substrates. Last but not least, you have to define whether this function can be applied to reversible, irreversible or both reaction types by selecting the reversible, irreversible or General radio button respectively. You can also call other functions from function definitions. There are four things you have to watch out for when you call a function within another function.

  1. Recursive function calls are not permitted. That is a function may not call itself, neither directly nor by calling another function that might call the first function again further along the line.

  2. You have to specify the correct number of arguments to the function called.

  3. You have to specify the correct argument types to the function call. I.e. if you call "Henry-Michaelis-Menten (irreversible)" from within another function, you have to make sure that the first call argument has a usage of Substrate and the other two have the usage Parameter.

  4. Which brings me to the last point. The built in function names in COPASI often use characters like "-" or even spaces, so if you want to call one of those functions, you have to quote this function name. So calling "Henry-Michaelis-Menten (irreversible)" from another function would look like this:

    Equation 1.1. 


After you commit the function, you can use it for the definition of reactions.

The operators and functions that COPASI knows and therefore can be used to create user defined functions are the following:

Table 1.4. Standard Operators

Operator/FunctionDescription
+plus operator
-minus operator
/division operator
*multiplication operator
%modulus operator
^power operator


Table 1.5. Miscellaneous Functions

Operator/FunctionDescription
abs / ABSabsolute value
floor / FLOORfloor value
ceil / CEILnext highest integer
factorial / FACTORIALfactorial function
log / LOGnatural logarithm
log10 / LOG10logarithm for base 10
exp / EXPexponent function


Table 1.6. Trigonometric Functions

Operator/FunctionDescription
sin / SINsine function
cos / COScosine function
tan / TANtangent function
sec / SECsecand function
csc / CSCcosecand function
cot / COTcotangent function
sinh / SINHhyperbolic sine function
cosh / COSHhyperbolic cosine function
tanh / TANHhyperbolic tangent function
sech / SECHhyperbolic secand function
csch / CSCHhyperbolic cosecand function
coth / COTHhyperbolic cotangent function
asin / ASINarcsine function
acos / ACOSarccosine function
atan / ATANarctangent function
arcsec / ARCSECarcsecand function
arccsc / ARCCSCarccosecand function
arccot / ARCCOTarccotangent function
arcsinh / ARCSINHhyperbolic arcsine function
arccosh / ARCCOSHhyperbolic arccosine function
arctanh / ARCTANHhyperbolic arctangent function
arcsech / ARCSECHhyperbolic arcsecand function
arccsch / ARCCSCHhyperbolic arccosecand function
arccoth / ARCCOTHhyperbolic arccotangent function


Table 1.7. Logical Functions

Operator/FunctionDescription
and / ANDlogical and (&)
or / ORlogical or (|)
xor / XORlogical xor
not / NOTlogical negation
le / LEsmaller or equal (<=)
lt / LTsmaller (<)
ge / GEgreater or equal (>=)
gt / GTgreater (>)
ne / NEnot equal (!=)
eq / EQequal (=)


Table 1.8. Miscellaneous

Operator/FunctionDescription
if / IFif statement for the construction of piecewise defined functions etc.
()parenthesis for grouping of elements


The functions name can be written with either all lowercase letters or all letters uppercase. Mixing of upper and lowercase letters is not allowed and will lead to errors.

Caution

Although COPASI allows the usage of discontinuous functions (ceil, floor, factorial, etc) all integration is done by LSODA which officially can not handle discontinuous functions. Nevertheless in most cases this will lead to correct results, however you should be aware of the fact that the usage of discontinuous functions in COPASI can lead to errors. Later versions of COPASI will use different integration methods that will be able to deal with discontinuous functions.

In addition to the function above, COPASI knows some predefined constant names:

Table 1.9. Built-in Constants

NameDescription
pi / PI quotient of a circles circumference and its diameter ( 3.14159...)
exponentiale / EXPONENTIALE Euler's number ( 2.7183... )
true / TRUEboolean true value for conditional expressions
false / FALSE boolean false value for conditional expressions
infinity / INFINITY positive infinity


Again, built-in constant names can be written with either all lowercase letters or all letters uppercase. Mixing of upper and lowercase letters is not allowed and will lead to errors.

In addition to defining "normal" functions, COPASI allows the definition of piecewise defined functions. Piecewise defined functions are constructed with the IF statement. The IF statement in COPASI is used like a function with three arguments. The first argument is a conditional expression that evaluates to either TRUE or FALSE, the second argument is an expression that is evaluated if the condition evaluates to TRUE otherwise the third argument, which can also be an expression, determines the value of the function. The second and third argument to the IF statement must evaluate to a double value, that means it can not be a conditional expression like the first argument. On the other hand, the second and third arguments themselves can be IF statements. So in order to make this a little more clear, we will look at how one would implement the Heaviside step function in COPASI:

Equation 1.2.