COPASI API  4.16.103
test000065.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000065.cpp,v $
3 // $Revision: 1.5 $
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 "test000065.h"
20 
21 #include <sstream>
22 #include "utilities.hpp"
24 #include "copasi/model/CModel.h"
25 #include "copasi/model/CMetab.h"
27 #include "copasi/model/CReaction.h"
30 
31 #include "sbml/SBMLDocument.h"
32 #include "sbml/Model.h"
33 #include "sbml/Reaction.h"
34 
36 
37 /**
38  * These tests are supposed to make sure that assignments on a species with the
39  * hasOnlySubstanceUnits flag set are exported correctly.
40  * It tests rules and event assignments with and without the flag set.
41  */
42 CCopasiDataModel* test000065::pCOPASIDATAMODEL = NULL;
43 
45 {
46  // Create the root container.
47  CCopasiRootContainer::init(0, NULL, false);
48  // Create the global data model.
50 }
51 
53 {
55 }
56 
58 {
59  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
60  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING1));
61  CModel* pModel = pDataModel->getModel();
62  CPPUNIT_ASSERT(pModel != NULL);
63  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
64  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
65  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
66  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
67  const CCompartment* pCompartment = pModel->getCompartments()[0];
68  CPPUNIT_ASSERT(pCompartment != NULL);
69  CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::FIXED);
70  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 4);
71  CPPUNIT_ASSERT(pModel->getReactions().size() == 1);
72  const CReaction* pReaction = pModel->getReactions()[0];
73  CPPUNIT_ASSERT(pReaction != NULL);
74  CPPUNIT_ASSERT(pReaction->getChemEq().getSubstrates().size() == 2);
75  CPPUNIT_ASSERT(pReaction->getChemEq().getProducts().size() == 2);
76  CPPUNIT_ASSERT(pReaction->getChemEq().getModifiers().size() == 0);
77  CPPUNIT_ASSERT(pReaction->isReversible() == false);
78  const CFunction* pFunction = pReaction->getFunction();
79  CPPUNIT_ASSERT(pFunction != NULL);
80  CPPUNIT_ASSERT(pFunction->getType() == CEvaluationTree::UserDefined);
81  CPPUNIT_ASSERT(pFunction->isReversible() == TriUnspecified);
82  // just to be sure also check the tree
83  const CEvaluationNode* pRoot = pFunction->getRoot();
84  CPPUNIT_ASSERT(pRoot != NULL);
85  CPPUNIT_ASSERT(CEvaluationNode::type(pRoot->getType()) == CEvaluationNode::OPERATOR);
87  const CEvaluationNode* pChild = dynamic_cast<const CEvaluationNode*>(pRoot->getChild());
88  CPPUNIT_ASSERT(pChild != NULL);
89  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::OPERATOR);
91  pChild = dynamic_cast<const CEvaluationNode*>(pChild->getChild());
92  CPPUNIT_ASSERT(pChild != NULL);
93  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
94  const CEvaluationNodeVariable* pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pChild);
95  CPPUNIT_ASSERT(pVariableNode != NULL);
96  CPPUNIT_ASSERT(pVariableNode->getData() == "Vmax");
97  pChild = dynamic_cast<const CEvaluationNode*>(pChild->getSibling());
98  CPPUNIT_ASSERT(pChild != NULL);
99  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
100  pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pChild);
101  CPPUNIT_ASSERT(pVariableNode != NULL);
102  // can't check the variable name here since I don't know what name has been
103  // created for it
104  pChild = dynamic_cast<const CEvaluationNode*>(pRoot->getChild()->getSibling());
105  CPPUNIT_ASSERT(pChild != NULL);
106  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::OPERATOR);
108  pChild = dynamic_cast<const CEvaluationNode*>(pChild->getChild());
109  CPPUNIT_ASSERT(pChild != NULL);
110  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
111  pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pChild);
112  CPPUNIT_ASSERT(pVariableNode != NULL);
113  CPPUNIT_ASSERT(pVariableNode->getData() == "Km");
114  pChild = dynamic_cast<const CEvaluationNode*>(pChild->getSibling());
115  CPPUNIT_ASSERT(pChild != NULL);
116  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
117  pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pChild);
118  CPPUNIT_ASSERT(pVariableNode != NULL);
119  // can't check the variable name here since I don't know what name has been
120  // created for it
121 }
122 
124 {
125  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
126  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING2));
127  CModel* pModel = pDataModel->getModel();
128  CPPUNIT_ASSERT(pModel != NULL);
129  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
130  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
131  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
132  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
133  const CCompartment* pCompartment = pModel->getCompartments()[0];
134  CPPUNIT_ASSERT(pCompartment != NULL);
135  CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::FIXED);
136  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 4);
137  CPPUNIT_ASSERT(pModel->getReactions().size() == 1);
138  const CReaction* pReaction = pModel->getReactions()[0];
139  CPPUNIT_ASSERT(pReaction != NULL);
140  CPPUNIT_ASSERT(pReaction->getChemEq().getSubstrates().size() == 2);
141  CPPUNIT_ASSERT(pReaction->getChemEq().getProducts().size() == 2);
142  CPPUNIT_ASSERT(pReaction->getChemEq().getModifiers().size() == 0);
143  CPPUNIT_ASSERT(pReaction->isReversible() == false);
144  const CFunction* pFunction = pReaction->getFunction();
145  CPPUNIT_ASSERT(pFunction != NULL);
146  CPPUNIT_ASSERT(pFunction->getType() == CEvaluationTree::UserDefined);
147  CPPUNIT_ASSERT(pFunction->isReversible() == TriUnspecified);
148  // just to be sure also check the tree
149  const CEvaluationNode* pRoot = pFunction->getRoot();
150  CPPUNIT_ASSERT(pRoot != NULL);
151  CPPUNIT_ASSERT(CEvaluationNode::type(pRoot->getType()) == CEvaluationNode::OPERATOR);
153  const CEvaluationNode* pChild = dynamic_cast<const CEvaluationNode*>(pRoot->getChild());
154  CPPUNIT_ASSERT(pChild != NULL);
155  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::OPERATOR);
157  pChild = dynamic_cast<const CEvaluationNode*>(pChild->getChild());
158  CPPUNIT_ASSERT(pChild != NULL);
159  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
160  const CEvaluationNodeVariable* pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pChild);
161  CPPUNIT_ASSERT(pVariableNode != NULL);
162  CPPUNIT_ASSERT(pVariableNode->getData() == "Vmax");
163  pChild = dynamic_cast<const CEvaluationNode*>(pChild->getSibling());
164  CPPUNIT_ASSERT(pChild != NULL);
165  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
166  pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pChild);
167  CPPUNIT_ASSERT(pVariableNode != NULL);
168  // can't check the variable name here since I don't know what name has been
169  // created for it
170  pChild = dynamic_cast<const CEvaluationNode*>(pRoot->getChild()->getSibling());
171  CPPUNIT_ASSERT(pChild != NULL);
172  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::OPERATOR);
174  pChild = dynamic_cast<const CEvaluationNode*>(pChild->getChild());
175  CPPUNIT_ASSERT(pChild != NULL);
176  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
177  pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pChild);
178  CPPUNIT_ASSERT(pVariableNode != NULL);
179  CPPUNIT_ASSERT(pVariableNode->getData() == "Km");
180  pChild = dynamic_cast<const CEvaluationNode*>(pChild->getSibling());
181  CPPUNIT_ASSERT(pChild != NULL);
182  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
183  pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pChild);
184  CPPUNIT_ASSERT(pVariableNode != NULL);
185  // can't check the variable name here since I don't know what name has been
186  // created for it
187 }
188 
189 const char* test000065::MODEL_STRING1 =
190  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
191  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version3\" level=\"2\" version=\"3\">"
192  " <model id=\"Model_1\" name=\"New Model\">"
193  " <notes>"
194  " <body xmlns=\"http://www.w3.org/1999/xhtml\">"
195  " <p>Model with one reaction that uses a kinetic law that is not"
196  " suitable for the reaction.</p>"
197  " <p>The function created for this reaction should therefore be set"
198  " to TriUnspecified</p>"
199  " </body>"
200  " </notes>"
201  " <listOfUnitDefinitions>"
202  " <unitDefinition id=\"volume\">"
203  " <listOfUnits>"
204  " <unit kind=\"litre\" scale=\"-3\"/>"
205  " </listOfUnits>"
206  " </unitDefinition>"
207  " <unitDefinition id=\"substance\">"
208  " <listOfUnits>"
209  " <unit kind=\"mole\" scale=\"-3\"/>"
210  " </listOfUnits>"
211  " </unitDefinition>"
212  " </listOfUnitDefinitions>"
213  " <listOfCompartments>"
214  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>"
215  " </listOfCompartments>"
216  " <listOfSpecies>"
217  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialConcentration=\"1\"/>"
218  " <species id=\"species_2\" name=\"B\" compartment=\"compartment_1\" initialConcentration=\"1\"/>"
219  " <species id=\"species_3\" name=\"C\" compartment=\"compartment_1\" initialConcentration=\"1\"/>"
220  " <species id=\"species_4\" name=\"D\" compartment=\"compartment_1\" initialConcentration=\"1\"/>"
221  " </listOfSpecies>"
222  " <listOfReactions>"
223  " <reaction id=\"reaction1\" reversible=\"false\">"
224  " <listOfReactants>"
225  " <speciesReference species=\"species_1\"/>"
226  " <speciesReference species=\"species_2\"/>"
227  " </listOfReactants>"
228  " <listOfProducts>"
229  " <speciesReference species=\"species_3\"/>"
230  " <speciesReference species=\"species_4\"/>"
231  " </listOfProducts>"
232  " <kineticLaw>"
233  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
234  " <apply>"
235  " <times/>"
236  " <ci> compartment_1 </ci>"
237  " <apply>"
238  " <divide/>"
239  " <apply>"
240  " <times/>"
241  " <ci> Vmax </ci>"
242  " <ci> species_1 </ci>"
243  " </apply>"
244  " <apply>"
245  " <plus/>"
246  " <ci> Km </ci>"
247  " <ci> species_1 </ci>"
248  " </apply>"
249  " </apply>"
250  " </apply>"
251  " </math>"
252  " <listOfParameters>"
253  " <parameter id=\"Vmax\" value=\"0.015\"/>"
254  " <parameter id=\"Km\" value=\"0.015\"/>"
255  " </listOfParameters>"
256  " </kineticLaw>"
257  " </reaction>"
258  " </listOfReactions>"
259  " </model>"
260  "</sbml>"
261  ;
262 
263 const char* test000065::MODEL_STRING2 =
264  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
265  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version3\" level=\"2\" version=\"3\">"
266  " <model id=\"Model_1\" name=\"New Model\">"
267  " <notes>"
268  " <body xmlns=\"http://www.w3.org/1999/xhtml\">"
269  " <p>Model with one reaction that uses a kinetic law that is not"
270  " suitable for the reaction.</p>"
271  " <p>The function created for this reaction should therefore be set"
272  " to TriUnspecified</p>"
273  " </body>"
274  " </notes>"
275  " <listOfFunctionDefinitions>"
276  " <functionDefinition id=\"function_1\" name=\"MM\">"
277  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
278  " <lambda>"
279  " <bvar>"
280  " <ci> Vmax </ci>"
281  " </bvar>"
282  " <bvar>"
283  " <ci> Km </ci>"
284  " </bvar>"
285  " <bvar>"
286  " <ci> S </ci>"
287  " </bvar>"
288  " <apply>"
289  " <divide/>"
290  " <apply>"
291  " <times/>"
292  " <ci> Vmax </ci>"
293  " <ci> S </ci>"
294  " </apply>"
295  " <apply>"
296  " <plus/>"
297  " <ci> Km </ci>"
298  " <ci> S </ci>"
299  " </apply>"
300  " </apply>"
301  " </lambda>"
302  " </math>"
303  " </functionDefinition>"
304  " </listOfFunctionDefinitions>"
305  " <listOfUnitDefinitions>"
306  " <unitDefinition id=\"volume\">"
307  " <listOfUnits>"
308  " <unit kind=\"litre\" scale=\"-3\"/>"
309  " </listOfUnits>"
310  " </unitDefinition>"
311  " <unitDefinition id=\"substance\">"
312  " <listOfUnits>"
313  " <unit kind=\"mole\" scale=\"-3\"/>"
314  " </listOfUnits>"
315  " </unitDefinition>"
316  " </listOfUnitDefinitions>"
317  " <listOfCompartments>"
318  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>"
319  " </listOfCompartments>"
320  " <listOfSpecies>"
321  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialConcentration=\"1\"/>"
322  " <species id=\"species_2\" name=\"B\" compartment=\"compartment_1\" initialConcentration=\"1\"/>"
323  " <species id=\"species_3\" name=\"C\" compartment=\"compartment_1\" initialConcentration=\"1\"/>"
324  " <species id=\"species_4\" name=\"D\" compartment=\"compartment_1\" initialConcentration=\"1\"/>"
325  " </listOfSpecies>"
326  " <listOfReactions>"
327  " <reaction id=\"reaction1\" reversible=\"false\">"
328  " <listOfReactants>"
329  " <speciesReference species=\"species_1\"/>"
330  " <speciesReference species=\"species_2\"/>"
331  " </listOfReactants>"
332  " <listOfProducts>"
333  " <speciesReference species=\"species_3\"/>"
334  " <speciesReference species=\"species_4\"/>"
335  " </listOfProducts>"
336  " <kineticLaw>"
337  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
338  " <apply>"
339  " <times/>"
340  " <ci> compartment_1 </ci>"
341  " <apply>"
342  " <ci> function_1 </ci>"
343  " <ci> Vmax </ci>"
344  " <ci> Km </ci>"
345  " <ci> species_1 </ci>"
346  " </apply>"
347  " </apply>"
348  " </math>"
349  " <listOfParameters>"
350  " <parameter id=\"Vmax\" value=\"0.015\"/>"
351  " <parameter id=\"Km\" value=\"0.015\"/>"
352  " </listOfParameters>"
353  " </kineticLaw>"
354  " </reaction>"
355  " </listOfReactions>"
356  " </model>"
357  "</sbml>"
358  ;
void tearDown()
Definition: test000065.cpp:52
const Type & getType() const
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000065.h:36
void test_import_reaction_with_unsuitable_kinetic_1()
Definition: test000065.cpp:57
void test_import_reaction_with_unsuitable_kinetic_2()
Definition: test000065.cpp:123
static Type type(const Type &type)
static const char * MODEL_STRING1
Definition: test000065.h:34
void setUp()
Definition: test000065.cpp:44
static CCopasiDataModel * addDatamodel()
static Type subType(const Type &type)
bool importSBMLFromString(const std::string &sbmlDocumentText, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
static void init(int argc, char *argv[], const bool &withGui=false)
Definition: CModel.h:50
static const char * MODEL_STRING2
Definition: test000065.h:35
virtual const Data & getData() const
Definition: CCopasiNode.h:118
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210