COPASI API  4.16.103
test000019.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000019.cpp,v $
3 // $Revision: 1.6 $
4 // $Name: $
5 // $Author: gauges $
6 // $Date: 2010/03/11 11:52:00 $
7 // End CVS Header
8 
9 // Copyright (C) 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 #include "test000019.hpp"
20 
21 #include <sstream>
22 #include "utilities.hpp"
24 
25 #include "sbml/SBMLDocument.h"
26 #include "sbml/Model.h"
27 #include "sbml/Rule.h"
28 #include "sbml/Species.h"
29 #include "sbml/Parameter.h"
30 #include "sbml/math/ASTNode.h"
31 
33 
34 CCopasiDataModel* test000019::pCOPASIDATAMODEL = NULL;
35 
36 void test000019::setUp()
37 {
38  // Create the root container.
39  CCopasiRootContainer::init(0, NULL, false);
40  // Create the global data model.
41  pCOPASIDATAMODEL = CCopasiRootContainer::addDatamodel();
42 }
43 
44 void test000019::tearDown()
45 {
47 }
48 
49 void test000019::test_references_to_species()
50 {
51  // load the CPS file
52  // export to SBML
53  // check the resulting SBML model
54  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
55  std::istringstream iss(test000019::MODEL_STRING);
56  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
57  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
58  CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, 2, 3).empty() == false);
59  SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
60  CPPUNIT_ASSERT(pDocument != NULL);
61  Model* pModel = pDocument->getModel();
62  CPPUNIT_ASSERT(pModel != NULL);
63  // assert that there is only one compartment and
64  // assert the compartment is constant
65  CPPUNIT_ASSERT(pModel->getNumCompartments() == 1);
66  Compartment* pCompartment = pModel->getCompartment(0);
67  CPPUNIT_ASSERT(pCompartment->getConstant() == false);
68  CPPUNIT_ASSERT(pModel->getNumSpecies() == 2);
69  Species* pSpecies = pModel->getSpecies(1);
70  CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() == true);
71  pSpecies = pModel->getSpecies(0);
72  std::string idSpeciesA = pSpecies->getId();
73  CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() == true);
74  CPPUNIT_ASSERT(pModel->getNumRules() == 1);
75  CPPUNIT_ASSERT(pModel->getNumInitialAssignments() == 1);
76  InitialAssignment* pAssignment = pModel->getInitialAssignment(0);
77  CPPUNIT_ASSERT(pAssignment != NULL);
78  CPPUNIT_ASSERT(pModel->getNumParameters() == 1);
79  Parameter* pParameter = pModel->getParameter(0);
80  CPPUNIT_ASSERT(pParameter != NULL);
81  CPPUNIT_ASSERT(pAssignment->getSymbol() == pParameter->getId());
82  const ASTNode* pMath = pAssignment->getMath();
83  CPPUNIT_ASSERT(pMath != NULL);
84  // the expression should be the species divided by the volume
85  CPPUNIT_ASSERT(pMath->getType() == AST_DIVIDE);
86  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
87  CPPUNIT_ASSERT(pMath->getChild(0) != NULL);
88  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
89  CPPUNIT_ASSERT(pMath->getChild(0)->getName() == idSpeciesA);
90  CPPUNIT_ASSERT(pMath->getChild(1) != NULL);
91  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
92  CPPUNIT_ASSERT(pMath->getChild(1)->getName() == pCompartment->getId());
93  Reaction* pReaction = pModel->getReaction(0);
94  // make sure this is reaction A ->
95  CPPUNIT_ASSERT(pReaction != NULL);
96  CPPUNIT_ASSERT(pReaction->getNumReactants() == 1);
97  CPPUNIT_ASSERT(pReaction->getNumProducts() == 0);
98  // check if all references in the kinetic law are unmodified
99  // math element must be a multiplication of the mass action term by
100  // the compartment volume
101  // the mass action term is a multiplication of the parameter node by
102  // the species node
103  CPPUNIT_ASSERT(pReaction->isSetKineticLaw() == true);
104  KineticLaw* pLaw = pReaction->getKineticLaw();
105  CPPUNIT_ASSERT(pLaw != NULL);
106  CPPUNIT_ASSERT(pLaw->isSetMath() == true);
107  pMath = pLaw->getMath();
108  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
109  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
110  CPPUNIT_ASSERT(pMath->getChild(0) != NULL);
111  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
112  CPPUNIT_ASSERT(pMath->getChild(0)->getName() == std::string("k1"));
113  CPPUNIT_ASSERT(pMath->getChild(1) != NULL);
114  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
115  CPPUNIT_ASSERT(pMath->getChild(1)->getName() == idSpeciesA);
116 
117  pReaction = pModel->getReaction(1);
118  // make sure this is reaction A -> S
119  CPPUNIT_ASSERT(pReaction != NULL);
120  CPPUNIT_ASSERT(pReaction->getNumReactants() == 1);
121  CPPUNIT_ASSERT(pReaction->getNumProducts() == 1);
122  // check if all references in the kinetic law are unmodified
123  // math element must be a multiplication of the compartments volume with
124  // a function call with three arguments
125  // the first argument is the reference to the species
126  CPPUNIT_ASSERT(pReaction->isSetKineticLaw() == true);
127  pLaw = pReaction->getKineticLaw();
128  CPPUNIT_ASSERT(pLaw != NULL);
129  CPPUNIT_ASSERT(pLaw->isSetMath() == true);
130  pMath = pLaw->getMath();
131  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
132  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
133  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
134  CPPUNIT_ASSERT(pMath->getChild(0)->getName() == pCompartment->getId());
135  pMath = pMath->getChild(1);
136  CPPUNIT_ASSERT(pMath != NULL);
137  CPPUNIT_ASSERT(pMath->getType() == AST_FUNCTION);
138  CPPUNIT_ASSERT(pMath->getNumChildren() == 3);
139  pMath = pMath->getChild(0);
140  CPPUNIT_ASSERT(pMath != NULL);
141  CPPUNIT_ASSERT(pMath->getType() == AST_DIVIDE);
142  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
143  CPPUNIT_ASSERT(pMath->getChild(0) != NULL);
144  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
145  CPPUNIT_ASSERT(pMath->getChild(0)->getName() == idSpeciesA);
146  CPPUNIT_ASSERT(pMath->getChild(1) != NULL);
147  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
148  CPPUNIT_ASSERT(pMath->getChild(1)->getName() == pCompartment->getId());
149 }
150 
151 const char* test000019::MODEL_STRING =
152  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
153  "<!-- generated with COPASI 4.3.25 (Debug) (http://www.copasi.org) at 2008-02-15 09:47:04 UTC -->\n"
154  "<COPASI xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.copasi.org/static/schema.xsd\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"25\">\n"
155  " <ListOfFunctions>\n"
156  " <Function key=\"Function_8\" name=\"Henri-Michaelis-Menten (irreversible)\" type=\"PreDefined\" reversible=\"false\">\n"
157  " <Expression>\n"
158  " V*substrate/(Km+substrate)\n"
159  " </Expression>\n"
160  " <ListOfParameterDescriptions>\n"
161  " <ParameterDescription key=\"FunctionParameter_41\" name=\"substrate\" order=\"0\" role=\"substrate\"/>\n"
162  " <ParameterDescription key=\"FunctionParameter_30\" name=\"Km\" order=\"1\" role=\"constant\"/>\n"
163  " <ParameterDescription key=\"FunctionParameter_45\" name=\"V\" order=\"2\" role=\"constant\"/>\n"
164  " </ListOfParameterDescriptions>\n"
165  " </Function>\n"
166  " <Function key=\"Function_13\" name=\"Mass action (irreversible)\" type=\"MassAction\" reversible=\"false\">\n"
167  " <Expression>\n"
168  " k1*PRODUCT&lt;substrate_i&gt;\n"
169  " </Expression>\n"
170  " <ListOfParameterDescriptions>\n"
171  " <ParameterDescription key=\"FunctionParameter_81\" name=\"k1\" order=\"0\" role=\"constant\"/>\n"
172  " <ParameterDescription key=\"FunctionParameter_79\" name=\"substrate\" order=\"1\" role=\"substrate\"/>\n"
173  " </ListOfParameterDescriptions>\n"
174  " </Function>\n"
175  " </ListOfFunctions>\n"
176  " <Model key=\"Model_1\" name=\"New Model\" timeUnit=\"s\" volumeUnit=\"ml\" quantityUnit=\"┬Ámol\" type=\"deterministic\">\n"
177  " <Comment>\n"
178  " <html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:13pt;font-family:Lucida Grande\">\n"
179  "<p>Model with variable volume compartment, micromol quantity units and a reference to the species initial concentration.</p>\n"
180  "<p>On export this should create an SBML file with the hasOnlySubstanceUnits flag on the species set.</p>\n"
181  "<p>The reference to the species in the initial assignment should be divided by the volume. The references in the reactions should be divided by the volume.</p>\n"
182  "</body></html>\n"
183  " </Comment>\n"
184  " <ListOfCompartments>\n"
185  " <Compartment key=\"Compartment_0\" name=\"compartment\" simulationType=\"assignment\">\n"
186  " <Expression>\n"
187  " 3+4\n"
188  " </Expression>\n"
189  " </Compartment>\n"
190  " </ListOfCompartments>\n"
191  " <ListOfMetabolites>\n"
192  " <Metabolite key=\"Metabolite_0\" name=\"A\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
193  " </Metabolite>\n"
194  " <Metabolite key=\"Metabolite_1\" name=\"S\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
195  " </Metabolite>\n"
196  " </ListOfMetabolites>\n"
197  " <ListOfModelValues>\n"
198  " <ModelValue key=\"ModelValue_0\" name=\"K\" simulationType=\"fixed\">\n"
199  " <InitialExpression>\n"
200  " &lt;CN=Root,Model=New Model,Vector=Compartments[compartment],Vector=Metabolites[A],Reference=InitialConcentration&gt;\n"
201  " </InitialExpression>\n"
202  " </ModelValue>\n"
203  " </ListOfModelValues>\n"
204  " <ListOfReactions>\n"
205  " <Reaction key=\"Reaction_0\" name=\"reaction\" reversible=\"false\">\n"
206  " <ListOfSubstrates>\n"
207  " <Substrate metabolite=\"Metabolite_0\" stoichiometry=\"1\"/>\n"
208  " </ListOfSubstrates>\n"
209  " <ListOfConstants>\n"
210  " <Constant key=\"Parameter_93\" name=\"k1\" value=\"0.1\"/>\n"
211  " </ListOfConstants>\n"
212  " <KineticLaw function=\"Function_13\">\n"
213  " <ListOfCallParameters>\n"
214  " <CallParameter functionParameter=\"FunctionParameter_81\">\n"
215  " <SourceParameter reference=\"Parameter_93\"/>\n"
216  " </CallParameter>\n"
217  " <CallParameter functionParameter=\"FunctionParameter_79\">\n"
218  " <SourceParameter reference=\"Metabolite_0\"/>\n"
219  " </CallParameter>\n"
220  " </ListOfCallParameters>\n"
221  " </KineticLaw>\n"
222  " </Reaction>\n"
223  " <Reaction key=\"Reaction_1\" name=\"reaction_1\" reversible=\"false\">\n"
224  " <ListOfSubstrates>\n"
225  " <Substrate metabolite=\"Metabolite_0\" stoichiometry=\"1\"/>\n"
226  " </ListOfSubstrates>\n"
227  " <ListOfProducts>\n"
228  " <Product metabolite=\"Metabolite_1\" stoichiometry=\"1\"/>\n"
229  " </ListOfProducts>\n"
230  " <ListOfConstants>\n"
231  " <Constant key=\"Parameter_92\" name=\"Km\" value=\"0.1\"/>\n"
232  " <Constant key=\"Parameter_91\" name=\"V\" value=\"0.1\"/>\n"
233  " </ListOfConstants>\n"
234  " <KineticLaw function=\"Function_8\">\n"
235  " <ListOfCallParameters>\n"
236  " <CallParameter functionParameter=\"FunctionParameter_41\">\n"
237  " <SourceParameter reference=\"Metabolite_0\"/>\n"
238  " </CallParameter>\n"
239  " <CallParameter functionParameter=\"FunctionParameter_30\">\n"
240  " <SourceParameter reference=\"Parameter_92\"/>\n"
241  " </CallParameter>\n"
242  " <CallParameter functionParameter=\"FunctionParameter_45\">\n"
243  " <SourceParameter reference=\"Parameter_91\"/>\n"
244  " </CallParameter>\n"
245  " </ListOfCallParameters>\n"
246  " </KineticLaw>\n"
247  " </Reaction>\n"
248  " </ListOfReactions>\n"
249  " <StateTemplate>\n"
250  " <StateTemplateVariable objectReference=\"Model_1\"/>\n"
251  " <StateTemplateVariable objectReference=\"Metabolite_0\"/>\n"
252  " <StateTemplateVariable objectReference=\"Metabolite_1\"/>\n"
253  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
254  " <StateTemplateVariable objectReference=\"ModelValue_0\"/>\n"
255  " </StateTemplate>\n"
256  " <InitialState type=\"initialState\">\n"
257  " 0 4.21549905e+18 4.215499050000001e+17 7 1\n"
258  " </InitialState>\n"
259  " </Model>\n"
260  "</COPASI>\n"
261  ;
SBMLDocument * getCurrentSBMLDocument()
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
static CCopasiDataModel * addDatamodel()
static void init(int argc, char *argv[], const bool &withGui=false)