Previous Page Parent Page Next Page TOC
User Manual | Importing and Exporting | Exporting C Source Files

Exporting C Source Files

Sometimes it is of advantage to have the differential equations that make up your model in the form of source code for some programming language. This allows you to integrate your model into some experimental analysis software that you might have written, or some analysis software that expect the input as C source code like AUTO.

So far COPASI only supports the export of C source code, source code for other programming languages might follow if there is need for it.

The C source file COPASI exports is split into several smaller parts which are encapsulated in #ifdef structures for the C preprocessor. The file consists of ten such sections which can be included in other files by defining the corresponding preprocessor constants at the place of inclusion. Example:

#define SIZE_DEFINITIONS
#include "SOURCE FILE"
#undef SIZE_DEFINITIONS


The file contains the following sections:

C Code Export Sections
Name Description
SIZE_DEFINITIONS Contains size definitions for the individual model elements, e.g. N_COMPARTMENTS for the number of compartments or N_REACTIONS for the number of reactions. All definitions are declared with preprocessor #define statements.
SPECIES Contains assignments for the species initial concentrations. The assignments are of the form y[INDEX]=VALUE where INDEX is the index of the species and VALUE is the initial concentration. This assumes that the including code has generated an array of double values of size N_METABS called y. N_METABS is part of the SIZE_DEFINITIONS section (see SIZE_DEFINITIONS above).
INDEP_SPECIES Contains assignments for the independent species initial concentrations. The assignments are of the form x[INDEX]=VALUE where INDEX is the index of the independent species and VALUE is the initial concentration. This assumes that the including code has generated an array of double values of size N_INDEP_METABS called x. N_INDEP_METABS is part of the SIZE_DEFINITIONS section (see SIZE_DEFINITIONS above).
MOIETY Contains assignments for the moieties. The assignments are of the form y[INDEX]=RSIDE where INDEX is the index of the species and RSIDE is the calculated value for the moiety, e.g. 0.2 - y[INDEX2]. y is the vector of species (see SPECIES above).
COMPARTMENTS Contains assignments for the compartments initial volumes. The assignments are of the form c[INDEX]=VALUE where INDEX is the index of the compartment and VALUE is the initial volume. This assumes that the including code has generated an array of double values of size N_COMPARTMENTS called c. N_COMPARTMENTS is part of the SIZE_DEFINITIONS section (see SIZE_DEFINITIONS above).
GLOBAL_PARAMETERS Contains assignments for the values of global kinetic parameters. The assignments are of the form gk[INDEX]=VALUE where INDEX is the index of the global parameter and VALUE is the value. This assumes that the including code has generated an array of double values of size N_GLOBAL_PARAMS called k. N_GLOBALPARAMS is part of the SIZE_DEFINITIONS section (see SIZE_DEFINITIONS above).
KINETIC_PARAMETERS Contains assignments for the values of local kinetic parameters. The assignments are of the form k[INDEX]=VALUE where INDEX is the index of the local parameter and VALUE is the value. This assumes that the including code has generated an array of double values of size N_KIN_PARAMS called k. N_KIN_PARAMS is part of the SIZE_DEFINITIONS section (see SIZE_DEFINITIONS above).
KINETIC_FUNCTIONS_HEADER This section contains the declarations of function definitions. The section has to be included before the function definitions section itself and before the differential equations section is included.
KINETIC_FUNCTIONS This section contains the implementation of the function definitions.
DIFFERENTIAL_EQUATIONS This section contains the set of differential equations. The result of the right hand side of each differential equation is stored in a variable dxdt[INDEX]. This assumes that the including program has created an array of double values called dxdt of size N_INDEP_METABS. N_INDEP_METABS is part of the SIZE_DEFINITIONS section (see SIZE_DEFINITIONS above).




In order to export the set of differential equations to a C source code file, you select the Export ODEs menu entry from COPASI's File menu. In the save dialog that shows up, you select C Files (*.c) from the File type drop down and specify the name of the file you want to write the ODEs to. After clicking on the Save the ODEs will be saved to the specified file.