COPASI API  4.16.103
test000093.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 #include "test000093.h"
7 
8 #include <sstream>
9 #include "utilities.hpp"
13 #include "copasi/model/CModel.h"
15 #include "copasi/model/CMetab.h"
17 #include "copasi/model/CEvent.h"
18 
19 #include "sbml/SBMLDocument.h"
20 #include "sbml/Model.h"
21 #include "sbml/Rule.h"
22 #include "sbml/Species.h"
23 #include "sbml/Parameter.h"
24 #include "sbml/math/ASTNode.h"
25 
27 
28 CCopasiDataModel* test000093::pCOPASIDATAMODEL = NULL;
29 
31 {
32  // Create the root container.
33  CCopasiRootContainer::init(0, NULL, false);
34  // Create the global data model.
36 }
37 
39 {
41 }
42 
44 {
45  // load the CPS file
46  // export to SBML
47  // check the resulting SBML model
48  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
49  std::istringstream iss(test000093::MODEL_STRING_1);
50  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
51  std::string content = pDataModel->exportSBMLToString(NULL, 2, 3);
52  CPPUNIT_ASSERT(content.empty() == false);
53  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
54  SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
55  CPPUNIT_ASSERT(pDocument != NULL);
56  Model* pModel = pDocument->getModel();
57  CPPUNIT_ASSERT(pModel != NULL);
58  // assert that there is only one compartment and
59  // assert the compartment is not constant
60  CPPUNIT_ASSERT(pModel->getNumCompartments() == 1);
61  Compartment* pCompartment = pModel->getCompartment(0);
62  CPPUNIT_ASSERT(pCompartment->getConstant() == false);
63  CPPUNIT_ASSERT(pModel->getNumSpecies() == 2);
64  Species* pSpecies = pModel->getSpecies(1);
65  std::string idSpeciesS, idSpeciesA;
66 
67  if (pSpecies->getName() == "S")
68  {
69  idSpeciesS = pSpecies->getId();
70  }
71  else
72  {
73  idSpeciesA = pSpecies->getId();
74  }
75 
76  CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() == true);
77  pSpecies = pModel->getSpecies(0);
78 
79  if (pSpecies->getName() == "S")
80  {
81  idSpeciesS = pSpecies->getId();
82  }
83  else
84  {
85  idSpeciesA = pSpecies->getId();
86  }
87 
88  CPPUNIT_ASSERT(!idSpeciesS.empty());
89  CPPUNIT_ASSERT(!idSpeciesA.empty());
90  CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() == true);
91  CPPUNIT_ASSERT(pModel->getNumRules() == 2);
92  CPPUNIT_ASSERT(pModel->getNumInitialAssignments() == 2);
93  const InitialAssignment* pAssignment1 = pModel->getInitialAssignment(0);
94  CPPUNIT_ASSERT(pAssignment1 != NULL);
95  CPPUNIT_ASSERT(pModel->getNumParameters() == 1);
96  Parameter* pParameter = pModel->getParameter(0);
97  CPPUNIT_ASSERT(pParameter != NULL);
98 
99  // the initial expression for the species needs to be multiplied
100  // by the compartment volume
101  // and the reference to the species in the initial expression for the model
102  // value has to be divided by the compartment volume
103  const InitialAssignment* pAssignment2 = NULL;
104 
105  if (pAssignment1->getSymbol() == pParameter->getId())
106  {
107  pAssignment2 = pModel->getInitialAssignment(1);
108  }
109  else
110  {
111  pAssignment2 = pAssignment1;
112  pAssignment1 = pModel->getInitialAssignment(1);
113  }
114 
115  assert(pAssignment2 != NULL);
116 
117  // check the reference in the initial assignment to the parameter
118  const ASTNode* pMath = pAssignment1->getMath();
119  CPPUNIT_ASSERT(pMath != NULL);
120  CPPUNIT_ASSERT(pMath->getType() == AST_DIVIDE);
121  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
122  const ASTNode* pChild1 = pMath->getChild(0);
123  CPPUNIT_ASSERT(pChild1 != NULL);
124  const ASTNode* pChild2 = NULL;
125 
126  // one child needs to be the number 2, the other needs to be a division operator
127  if (pChild1->getType() == AST_DIVIDE)
128  {
129  pChild2 = pMath->getChild(1);
130  }
131  else
132  {
133  pChild2 = pChild1;
134  pChild1 = pMath->getChild(1);
135  }
136 
137  CPPUNIT_ASSERT(pChild2 != NULL);
138  CPPUNIT_ASSERT(pChild1->getType() == AST_DIVIDE);
139  CPPUNIT_ASSERT(pChild2->getType() == AST_REAL);
140  CPPUNIT_ASSERT((fabs(pChild2->getReal() - 2.0) / 2.0) < 1e-9);
141  CPPUNIT_ASSERT(pChild1->getNumChildren() == 2);
142  pChild2 = pChild1->getChild(1);
143  CPPUNIT_ASSERT(pChild2 != NULL);
144  pChild1 = pChild1->getChild(0);
145  CPPUNIT_ASSERT(pChild1 != NULL);
146  CPPUNIT_ASSERT(pChild1->getType() == AST_NAME);
147  CPPUNIT_ASSERT(pChild2->getType() == AST_NAME);
148  CPPUNIT_ASSERT(pChild1->getName() == idSpeciesS);
149  CPPUNIT_ASSERT(pChild2->getName() == pCompartment->getId());
150  // test the initial expression for the species.
151  // This must be an addition multiplied by the volume
152  pMath = pAssignment2->getMath();
153  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
154  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
155  pChild1 = pMath->getChild(0);
156  CPPUNIT_ASSERT(pChild1 != NULL);
157 
158  if (pChild1->getType() == AST_PLUS)
159  {
160  pChild2 = pMath->getChild(1);
161  }
162  else
163  {
164  pChild2 = pChild1;
165  pChild1 = pMath->getChild(1);
166  }
167 
168  CPPUNIT_ASSERT(pChild2 != NULL);
169  CPPUNIT_ASSERT(pChild1->getType() == AST_PLUS);
170  CPPUNIT_ASSERT(pChild2->getType() == AST_NAME);
171  CPPUNIT_ASSERT(pChild2->getName() == pCompartment->getId());
172  CPPUNIT_ASSERT(pChild1->getNumChildren() == 2);
173  pChild2 = pChild1->getChild(0);
174  pChild1 = pChild1->getChild(1);
175  CPPUNIT_ASSERT(pChild2->getType() == AST_REAL);
176 
177  if ((fabs(pChild2->getReal() - 12.0) / 12.0) < 1e-9)
178  {
179  CPPUNIT_ASSERT((fabs(pChild1->getReal() - 6.0) / 6.0) < 1e-9);
180  }
181  else
182  {
183  CPPUNIT_ASSERT((fabs(pChild2->getReal() - 6.0) / 6.0) < 1e-9);
184  CPPUNIT_ASSERT((fabs(pChild1->getReal() - 12.0) / 12.0) < 1e-9);
185  }
186 
187  // the reference to the species in the rule for species S needs to be divided by the volume
188  const Rule* pRule1 = pModel->getRule(0);
189  CPPUNIT_ASSERT(pRule1 != NULL);
190  const AssignmentRule* pARule1 = dynamic_cast<const AssignmentRule*>(pRule1);
191  CPPUNIT_ASSERT(pARule1 != NULL);
192  const Rule* pRule2 = NULL;
193  const AssignmentRule* pARule2 = NULL;
194 
195  if (pARule1->getVariable() == pCompartment->getId())
196  {
197  pRule2 = pModel->getRule(1);
198  pARule2 = dynamic_cast<const AssignmentRule*>(pRule2);
199  }
200  else
201  {
202  pRule2 = pRule1;
203  pARule2 = pARule1;
204  pRule1 = pModel->getRule(1);
205  pARule1 = dynamic_cast<const AssignmentRule*>(pRule1);
206  }
207 
208  CPPUNIT_ASSERT(pRule1 != NULL);
209  CPPUNIT_ASSERT(pARule1 != NULL);
210  CPPUNIT_ASSERT(pRule2 != NULL);
211  CPPUNIT_ASSERT(pARule2 != NULL);
212  // the first rule is the rule for the compartment which is
213  // an addition of two numbers
214  pMath = pARule1->getMath();
215  CPPUNIT_ASSERT(pMath != 0);
216  CPPUNIT_ASSERT(pMath->getType() == AST_PLUS);
217  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
218  pChild2 = pMath->getChild(0);
219  pChild1 = pMath->getChild(1);
220  CPPUNIT_ASSERT(pChild2->getType() == AST_REAL);
221 
222  if ((fabs(pChild2->getReal() - 3.0) / 3.0) < 1e-9)
223  {
224  CPPUNIT_ASSERT((fabs(pChild1->getReal() - 4.0) / 4.0) < 1e-9);
225  }
226  else
227  {
228  CPPUNIT_ASSERT((fabs(pChild2->getReal() - 4.0) / 4.0) < 1e-9);
229  CPPUNIT_ASSERT((fabs(pChild1->getReal() - 3.0) / 3.0) < 1e-9);
230  }
231 
232  // the second rule id the one for species S
233  // this expression contains a reference to species A which must be divided by the volume
234  // and the complete expression must be multiplied by the volume
235  pMath = pARule2->getMath();
236  CPPUNIT_ASSERT(pMath != NULL);
237  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
238  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
239  pChild1 = pMath->getChild(0);
240  CPPUNIT_ASSERT(pChild1 != NULL);
241 
242  if (pChild1->getType() == AST_NAME)
243  {
244  pChild2 = pMath->getChild(1);
245  }
246  else
247  {
248  pChild2 = pChild1;
249  pChild1 = pMath->getChild(1);
250  }
251 
252  CPPUNIT_ASSERT(pChild1 != NULL);
253  CPPUNIT_ASSERT(pChild2 != NULL);
254  CPPUNIT_ASSERT(pChild1->getType() == AST_NAME);
255  CPPUNIT_ASSERT(pChild1->getName() == pCompartment->getId());
256  CPPUNIT_ASSERT(pChild2->getType() == AST_TIMES);
257  CPPUNIT_ASSERT(pChild2->getNumChildren() == 2);
258  pChild1 = pChild2->getChild(0);
259 
260  if (pChild1->getType() == AST_REAL)
261  {
262  pChild2 = pChild2->getChild(1);
263  }
264  else
265  {
266 
267  pMath = pChild2;
268  pChild2 = pChild1;
269  pChild1 = pMath->getChild(1);
270  }
271 
272  CPPUNIT_ASSERT(pChild1 != NULL);
273  CPPUNIT_ASSERT(pChild2 != NULL);
274  CPPUNIT_ASSERT(pChild1->getType() == AST_REAL);
275  CPPUNIT_ASSERT((fabs(pChild1->getReal() - 3.0) / 3.0) < 1e-9);
276  CPPUNIT_ASSERT(pChild2->getType() == AST_DIVIDE);
277  CPPUNIT_ASSERT(pChild2->getNumChildren() == 2);
278  pChild1 = pChild2->getChild(0);
279  pChild2 = pChild2->getChild(1);
280  CPPUNIT_ASSERT(pChild1 != NULL);
281  CPPUNIT_ASSERT(pChild1->getType() == AST_NAME);
282  CPPUNIT_ASSERT(pChild1->getName() == idSpeciesA);
283  CPPUNIT_ASSERT(pChild2 != NULL);
284  CPPUNIT_ASSERT(pChild2->getType() == AST_NAME);
285  CPPUNIT_ASSERT(pChild2->getName() == pCompartment->getId());
286 
287  // now we reimport the model and check if the divisions and mutliplications by the compartment have been reverted
288  pDataModel->newModel(NULL, true);
289  CPPUNIT_ASSERT(pDataModel->getModel()->getCompartments().size() == 0);
290  bool result = pDataModel->importSBMLFromString(content);
291  CPPUNIT_ASSERT(result == true);
292  const CModel* pCModel = pDataModel->getModel();
293  CPPUNIT_ASSERT(pCModel->getCompartments().size() == 1);
294  // there is one factor for the conversion from particles to amount
295  CPPUNIT_ASSERT(pCModel->getModelValues().size() == 2);
296  CPPUNIT_ASSERT(pCModel->getMetabolites().size() == 2);
297  CPPUNIT_ASSERT(pCModel->getReactions().size() == 0);
298  CPPUNIT_ASSERT(pCModel->getEvents().size() == 0);
299  const CCompartment* pCCompartment = pCModel->getCompartments()[0];
300  CPPUNIT_ASSERT(pCCompartment != NULL);
301  CPPUNIT_ASSERT(pCCompartment->getStatus() == CModelEntity::ASSIGNMENT);
302  const CExpression* pExpr = pCCompartment->getExpressionPtr();
303  CPPUNIT_ASSERT(pExpr != NULL);
304  const CEvaluationNode* pEvalNode = pExpr->getRoot();
305  CPPUNIT_ASSERT(pEvalNode != NULL);
306  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OPERATOR);
307  const CEvaluationNodeOperator* pOperator = dynamic_cast<const CEvaluationNodeOperator*>(pEvalNode);
309  CPPUNIT_ASSERT(pOperator != NULL);
310  CPPUNIT_ASSERT(pOperator->getChild() != NULL);
311  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild());
312  CPPUNIT_ASSERT(pEvalNode != NULL);
313  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::NUMBER);
314  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pEvalNode);
315 
316  if (fabs((pNumberNode->getValue() - 3.0) / 3.0) < 1e-6)
317  {
318  CPPUNIT_ASSERT(pNumberNode->getSibling() != NULL);
319  pEvalNode = dynamic_cast<const CEvaluationNode*>(pNumberNode->getSibling());
320  CPPUNIT_ASSERT(pEvalNode != NULL);
321  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::NUMBER);
322  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pEvalNode);
323  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 4.0) / 4.0) < 1e-6);
324  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
325  }
326  else
327  {
328  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 4.0) / 4.0) < 1e-6);
329  CPPUNIT_ASSERT(pNumberNode->getSibling() != NULL);
330  pEvalNode = dynamic_cast<const CEvaluationNode*>(pNumberNode->getSibling());
331  CPPUNIT_ASSERT(pEvalNode != NULL);
332  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::NUMBER);
333  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pEvalNode);
334  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 3.0) / 3.0) < 1e-6);
335  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
336  }
337 
338  const CMetab* pMetabA = pCModel->getMetabolites()[0];
339 
340  CPPUNIT_ASSERT(pMetabA != NULL);
341 
342  const CMetab* pMetabS = NULL;
343 
344  if (pMetabA->getObjectName() == "A")
345  {
346  pMetabS = pCModel->getMetabolites()[1];
347  }
348  else
349  {
350  pMetabS = pMetabA;
351  pMetabA = pCModel->getMetabolites()[1];
352  CPPUNIT_ASSERT(pMetabA != NULL);
353  }
354 
355  CPPUNIT_ASSERT(pMetabS != NULL);
356  CPPUNIT_ASSERT(pMetabA->getObjectName() == "A");
357  CPPUNIT_ASSERT(pMetabS->getObjectName() == "S");
358 
359  // next we test the initial expression for the model value
360  const CModelValue* pModelValue = NULL;
361  unsigned int iMax = pCModel->getModelValues().size();
362 
363  for (unsigned int i = 0; i < iMax; ++i)
364  {
365  if (pCModel->getModelValues()[i]->getObjectName() == "K")
366  {
367  pModelValue = pCModel->getModelValues()[i];
368  break;
369  }
370  }
371 
372  CPPUNIT_ASSERT(pModelValue != NULL);
373  CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::FIXED);
374  pExpr = pModelValue->getInitialExpressionPtr();
375  CPPUNIT_ASSERT(pExpr != NULL);
376  pEvalNode = pExpr->getRoot();
377  CPPUNIT_ASSERT(pEvalNode != NULL);
378  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OPERATOR);
379  pOperator = dynamic_cast<const CEvaluationNodeOperator*>(pEvalNode);
380  CPPUNIT_ASSERT(pOperator != NULL);
382  CPPUNIT_ASSERT(pOperator->getChild() != NULL);
383  CPPUNIT_ASSERT(pOperator->getChild()->getSibling() != NULL);
384  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild()->getSibling());
385  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::NUMBER);
386  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pEvalNode);
387  CPPUNIT_ASSERT(pNumberNode != NULL);
388  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 2.0) / 2.0) < 1e-6);
389  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
390  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild());
391  CPPUNIT_ASSERT(pEvalNode != NULL);
392  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OPERATOR);
393  pOperator = dynamic_cast<const CEvaluationNodeOperator*>(pEvalNode);
394  CPPUNIT_ASSERT(pOperator != NULL);
396  CPPUNIT_ASSERT(pOperator->getChild() != NULL);
397  CPPUNIT_ASSERT(pOperator->getChild()->getSibling() != NULL);
398  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild()->getSibling());
399  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OBJECT);
400  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pEvalNode);
401  CPPUNIT_ASSERT(pObjectNode != NULL);
402  CPPUNIT_ASSERT(pObjectNode->getSibling() == NULL);
404  // check the data of the object node
405  std::string objectCN = pObjectNode->getObjectCN();
406  CPPUNIT_ASSERT(!objectCN.empty());
407  std::vector<CCopasiContainer*> listOfContainers;
408  listOfContainers.push_back(const_cast<CModel*>(pCModel));
409  const CCopasiObject* pObject = pDataModel->ObjectFromName(listOfContainers, objectCN);
410  CPPUNIT_ASSERT(pObject != NULL);
411  CPPUNIT_ASSERT(pObject->isReference() == true);
412  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("InitialVolume"));
413  CPPUNIT_ASSERT(pObject->getObjectParent() == pCCompartment);
414 
415  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild());
416  CPPUNIT_ASSERT(pEvalNode != NULL);
417  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OPERATOR);
418  pOperator = dynamic_cast<const CEvaluationNodeOperator*>(pEvalNode);
420  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild());
421  CPPUNIT_ASSERT(pEvalNode != NULL);
422  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OBJECT);
423  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pEvalNode);
424  CPPUNIT_ASSERT(pObjectNode != NULL);
426  // check the data of the object node
427  objectCN = pObjectNode->getObjectCN();
428  CPPUNIT_ASSERT(!objectCN.empty());
429  pObject = pDataModel->ObjectFromName(listOfContainers, objectCN);
430  CPPUNIT_ASSERT(pObject != NULL);
431  CPPUNIT_ASSERT(pObject->isReference() == true);
432  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("InitialParticleNumber"));
433  CPPUNIT_ASSERT(pObject->getObjectParent() == pMetabS);
434  pEvalNode = dynamic_cast<const CEvaluationNode*>(pObjectNode->getSibling());
435  CPPUNIT_ASSERT(pEvalNode != NULL);
436  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OBJECT);
437  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pEvalNode);
438  CPPUNIT_ASSERT(pObjectNode != NULL);
440  // check the data of the object node
441  objectCN = pObjectNode->getObjectCN();
442  CPPUNIT_ASSERT(!objectCN.empty());
443  pObject = pDataModel->ObjectFromName(listOfContainers, objectCN);
444  CPPUNIT_ASSERT(pObject != NULL);
445  CPPUNIT_ASSERT(pObject->isReference() == true);
446  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("InitialValue"));
447 
448  //
449  // then we test the expression and the initial expression for the two metabolites
450  CPPUNIT_ASSERT(pMetabA->getStatus() == CModelEntity::REACTIONS);
451  pExpr = pMetabA->getInitialExpressionPtr();
452  CPPUNIT_ASSERT(pExpr != NULL);
453  pEvalNode = pExpr->getRoot();
454  CPPUNIT_ASSERT(pEvalNode != NULL);
455  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OPERATOR);
456  pOperator = dynamic_cast<const CEvaluationNodeOperator*>(pEvalNode);
458  CPPUNIT_ASSERT(pOperator != NULL);
459  CPPUNIT_ASSERT(pOperator->getChild() != NULL);
460  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild());
461  CPPUNIT_ASSERT(pEvalNode != NULL);
462  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::NUMBER);
463  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pEvalNode);
464 
465  if (fabs((pNumberNode->getValue() - 12.0) / 12.0) < 1e-6)
466  {
467  CPPUNIT_ASSERT(pNumberNode->getSibling() != NULL);
468  pEvalNode = dynamic_cast<const CEvaluationNode*>(pNumberNode->getSibling());
469  CPPUNIT_ASSERT(pEvalNode != NULL);
470  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::NUMBER);
471  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pEvalNode);
472  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 6.0) / 6.0) < 1e-6);
473  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
474  }
475  else
476  {
477  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 6.0) / 6.0) < 1e-6);
478  CPPUNIT_ASSERT(pNumberNode->getSibling() != NULL);
479  pEvalNode = dynamic_cast<const CEvaluationNode*>(pNumberNode->getSibling());
480  CPPUNIT_ASSERT(pEvalNode != NULL);
481  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::NUMBER);
482  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pEvalNode);
483  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 12.0) / 12.0) < 1e-6);
484  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
485  }
486 
487  CPPUNIT_ASSERT(pMetabS->getStatus() == CModelEntity::ASSIGNMENT);
488  pExpr = pMetabS->getExpressionPtr();
489  CPPUNIT_ASSERT(pExpr != NULL);
490  pEvalNode = pExpr->getRoot();
491  CPPUNIT_ASSERT(pEvalNode != NULL);
492  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OPERATOR);
493  pOperator = dynamic_cast<const CEvaluationNodeOperator*>(pEvalNode);
494  CPPUNIT_ASSERT(pOperator != NULL);
496  CPPUNIT_ASSERT(pOperator->getChild() != NULL);
497  CPPUNIT_ASSERT(pOperator->getChild()->getSibling() != NULL);
498  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild()->getSibling());
499  CPPUNIT_ASSERT(pEvalNode != NULL);
500  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::NUMBER);
501  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pEvalNode);
502  CPPUNIT_ASSERT(pNumberNode != NULL);
503  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 3.0) / 3.0) < 1e-6);
504  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
505 
506  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild());
507  CPPUNIT_ASSERT(pEvalNode != NULL);
508  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OPERATOR);
509  pOperator = dynamic_cast<const CEvaluationNodeOperator*>(pEvalNode);
510  CPPUNIT_ASSERT(pOperator != NULL);
512  CPPUNIT_ASSERT(pOperator->getChild() != NULL);
513  CPPUNIT_ASSERT(pOperator->getChild()->getSibling() != NULL);
514  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild()->getSibling());
515  CPPUNIT_ASSERT(pEvalNode != NULL);
516  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OBJECT);
517  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pEvalNode);
518  CPPUNIT_ASSERT(pObjectNode != NULL);
520  // check the data of the object node
521  objectCN = pObjectNode->getObjectCN();
522  CPPUNIT_ASSERT(!objectCN.empty());
523  pObject = pDataModel->ObjectFromName(listOfContainers, objectCN);
524  CPPUNIT_ASSERT(pObject != NULL);
525  CPPUNIT_ASSERT(pObject->isReference() == true);
526  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Volume"));
527  CPPUNIT_ASSERT(pObject->getObjectParent() == pCCompartment);
528  CPPUNIT_ASSERT(pObjectNode->getSibling() == NULL);
529 
530  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild());
531  CPPUNIT_ASSERT(pEvalNode != NULL);
532  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OPERATOR);
533  pOperator = dynamic_cast<const CEvaluationNodeOperator*>(pEvalNode);
534  CPPUNIT_ASSERT(pOperator != NULL);
536  CPPUNIT_ASSERT(pOperator->getChild() != NULL);
537  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild());
538  CPPUNIT_ASSERT(pEvalNode != NULL);
539  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OBJECT);
540  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pEvalNode);
541  CPPUNIT_ASSERT(pObjectNode != NULL);
543  // check the data of the object node
544  objectCN = pObjectNode->getObjectCN();
545  CPPUNIT_ASSERT(!objectCN.empty());
546  pObject = pDataModel->ObjectFromName(listOfContainers, objectCN);
547  CPPUNIT_ASSERT(pObject != NULL);
548  CPPUNIT_ASSERT(pObject->isReference() == true);
549  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("ParticleNumber"));
550  CPPUNIT_ASSERT(pObject->getObjectParent() == pMetabA);
551  pEvalNode = dynamic_cast<const CEvaluationNode*>(pObjectNode->getSibling());
552  CPPUNIT_ASSERT(pEvalNode != NULL);
553  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OBJECT);
554  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pEvalNode);
555  CPPUNIT_ASSERT(pObjectNode != NULL);
557  // check the data of the object node
558  objectCN = pObjectNode->getObjectCN();
559  CPPUNIT_ASSERT(!objectCN.empty());
560  pObject = pDataModel->ObjectFromName(listOfContainers, objectCN);
561  CPPUNIT_ASSERT(pObject != NULL);
562  CPPUNIT_ASSERT(pObject->isReference() == true);
563  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
564  CPPUNIT_ASSERT(pObjectNode->getSibling() == NULL);
565 }
566 
568 {
569  // load the CPS file
570  // export to SBML
571  // check the resulting SBML model
572  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
573  std::istringstream iss(test000093::MODEL_STRING_2);
574  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
575  std::string content = pDataModel->exportSBMLToString(NULL, 2, 3);
576  CPPUNIT_ASSERT(content.empty() == false);
577  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
578  SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
579  CPPUNIT_ASSERT(pDocument != NULL);
580  Model* pModel = pDocument->getModel();
581  CPPUNIT_ASSERT(pModel != NULL);
582  // assert that there is only one compartment and
583  // assert the compartment is not constant
584  CPPUNIT_ASSERT(pModel->getNumCompartments() == 1);
585  Compartment* pCompartment = pModel->getCompartment(0);
586  CPPUNIT_ASSERT(pCompartment->getConstant() == false);
587  CPPUNIT_ASSERT(pModel->getNumSpecies() == 2);
588  Species* pSpecies = pModel->getSpecies(1);
589  std::string idSpeciesS, idSpeciesA;
590 
591  if (pSpecies->getName() == "S")
592  {
593  idSpeciesS = pSpecies->getId();
594  }
595  else
596  {
597  idSpeciesA = pSpecies->getId();
598  }
599 
600  CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() == true);
601  pSpecies = pModel->getSpecies(0);
602 
603  if (pSpecies->getName() == "S")
604  {
605  idSpeciesS = pSpecies->getId();
606  }
607  else
608  {
609  idSpeciesA = pSpecies->getId();
610  }
611 
612  CPPUNIT_ASSERT(!idSpeciesS.empty());
613  CPPUNIT_ASSERT(!idSpeciesA.empty());
614  CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() == true);
615  CPPUNIT_ASSERT(pModel->getNumRules() == 1);
616  CPPUNIT_ASSERT(pModel->getNumInitialAssignments() == 2);
617  const InitialAssignment* pAssignment1 = pModel->getInitialAssignment(0);
618  CPPUNIT_ASSERT(pAssignment1 != NULL);
619  CPPUNIT_ASSERT(pModel->getNumParameters() == 1);
620  CPPUNIT_ASSERT(pModel->getNumEvents() == 1);
621  Parameter* pParameter = pModel->getParameter(0);
622  CPPUNIT_ASSERT(pParameter != NULL);
623 
624  // the initial expression for the species needs to be multiplied
625  // by the compartment volume
626  // and the reference to the species in the initial expression for the model
627  // value has to be divided by the compartment volume
628  const InitialAssignment* pAssignment2 = NULL;
629 
630  if (pAssignment1->getSymbol() == pParameter->getId())
631  {
632  pAssignment2 = pModel->getInitialAssignment(1);
633  }
634  else
635  {
636  pAssignment2 = pAssignment1;
637  pAssignment1 = pModel->getInitialAssignment(1);
638  }
639 
640  assert(pAssignment2 != NULL);
641 
642  // check the reference in the initial assignment to the parameter
643  const ASTNode* pMath = pAssignment1->getMath();
644  CPPUNIT_ASSERT(pMath != NULL);
645  CPPUNIT_ASSERT(pMath->getType() == AST_DIVIDE);
646  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
647  const ASTNode* pChild1 = pMath->getChild(0);
648  CPPUNIT_ASSERT(pChild1 != NULL);
649  const ASTNode* pChild2 = NULL;
650 
651  // one child needs to be the number 2, the other needs to be a division operator
652  if (pChild1->getType() == AST_DIVIDE)
653  {
654  pChild2 = pMath->getChild(1);
655  }
656  else
657  {
658  pChild2 = pChild1;
659  pChild1 = pMath->getChild(1);
660  }
661 
662  CPPUNIT_ASSERT(pChild2 != NULL);
663  CPPUNIT_ASSERT(pChild1->getType() == AST_DIVIDE);
664  CPPUNIT_ASSERT(pChild2->getType() == AST_REAL);
665  CPPUNIT_ASSERT((fabs(pChild2->getReal() - 2.0) / 2.0) < 1e-9);
666  CPPUNIT_ASSERT(pChild1->getNumChildren() == 2);
667  pChild2 = pChild1->getChild(1);
668  CPPUNIT_ASSERT(pChild2 != NULL);
669  pChild1 = pChild1->getChild(0);
670  CPPUNIT_ASSERT(pChild1 != NULL);
671  CPPUNIT_ASSERT(pChild1->getType() == AST_NAME);
672  CPPUNIT_ASSERT(pChild2->getType() == AST_NAME);
673  CPPUNIT_ASSERT(pChild1->getName() == idSpeciesS);
674  CPPUNIT_ASSERT(pChild2->getName() == pCompartment->getId());
675  // test the initial expression for the species.
676  // This must be an addition multiplied by the volume
677  pMath = pAssignment2->getMath();
678  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
679  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
680  pChild1 = pMath->getChild(0);
681  CPPUNIT_ASSERT(pChild1 != NULL);
682 
683  if (pChild1->getType() == AST_PLUS)
684  {
685  pChild2 = pMath->getChild(1);
686  }
687  else
688  {
689  pChild2 = pChild1;
690  pChild1 = pMath->getChild(1);
691  }
692 
693  CPPUNIT_ASSERT(pChild2 != NULL);
694  CPPUNIT_ASSERT(pChild1->getType() == AST_PLUS);
695  CPPUNIT_ASSERT(pChild2->getType() == AST_NAME);
696  CPPUNIT_ASSERT(pChild2->getName() == pCompartment->getId());
697  CPPUNIT_ASSERT(pChild1->getNumChildren() == 2);
698  pChild2 = pChild1->getChild(0);
699  pChild1 = pChild1->getChild(1);
700  CPPUNIT_ASSERT(pChild2->getType() == AST_REAL);
701 
702  if ((fabs(pChild2->getReal() - 12.0) / 12.0) < 1e-9)
703  {
704  CPPUNIT_ASSERT((fabs(pChild1->getReal() - 6.0) / 6.0) < 1e-9);
705  }
706  else
707  {
708  CPPUNIT_ASSERT((fabs(pChild2->getReal() - 6.0) / 6.0) < 1e-9);
709  CPPUNIT_ASSERT((fabs(pChild1->getReal() - 12.0) / 12.0) < 1e-9);
710  }
711 
712  // the reference to the species in the rule for species S needs to be divided by the volume
713  const Rule* pRule1 = pModel->getRule(0);
714  CPPUNIT_ASSERT(pRule1 != NULL);
715  const AssignmentRule* pARule1 = dynamic_cast<const AssignmentRule*>(pRule1);
716  CPPUNIT_ASSERT(pARule1 != NULL);
717 
718  // the second rule id the one for species S
719  // this expression contains a reference to species A which must be divided by the volume
720  // and the complete expression must be multiplied by the volume
721  pMath = pARule1->getMath();
722  CPPUNIT_ASSERT(pMath != NULL);
723  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
724  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
725  pChild1 = pMath->getChild(0);
726  CPPUNIT_ASSERT(pChild1 != NULL);
727 
728  if (pChild1->getType() == AST_NAME)
729  {
730  pChild2 = pMath->getChild(1);
731  }
732  else
733  {
734  pChild2 = pChild1;
735  pChild1 = pMath->getChild(1);
736  }
737 
738  CPPUNIT_ASSERT(pChild1 != NULL);
739  CPPUNIT_ASSERT(pChild2 != NULL);
740  CPPUNIT_ASSERT(pChild1->getType() == AST_NAME);
741  CPPUNIT_ASSERT(pChild1->getName() == pCompartment->getId());
742  CPPUNIT_ASSERT(pChild2->getType() == AST_TIMES);
743  CPPUNIT_ASSERT(pChild2->getNumChildren() == 2);
744  pChild1 = pChild2->getChild(0);
745 
746  if (pChild1->getType() == AST_REAL)
747  {
748  pChild2 = pChild2->getChild(1);
749  }
750  else
751  {
752 
753  pMath = pChild2;
754  pChild2 = pChild1;
755  pChild1 = pMath->getChild(1);
756  }
757 
758  CPPUNIT_ASSERT(pChild1 != NULL);
759  CPPUNIT_ASSERT(pChild2 != NULL);
760  CPPUNIT_ASSERT(pChild1->getType() == AST_REAL);
761  CPPUNIT_ASSERT((fabs(pChild1->getReal() - 3.0) / 3.0) < 1e-9);
762  CPPUNIT_ASSERT(pChild2->getType() == AST_DIVIDE);
763  CPPUNIT_ASSERT(pChild2->getNumChildren() == 2);
764  pChild1 = pChild2->getChild(0);
765  pChild2 = pChild2->getChild(1);
766  CPPUNIT_ASSERT(pChild1 != NULL);
767  CPPUNIT_ASSERT(pChild1->getType() == AST_NAME);
768  CPPUNIT_ASSERT(pChild1->getName() == idSpeciesA);
769  CPPUNIT_ASSERT(pChild2 != NULL);
770  CPPUNIT_ASSERT(pChild2->getType() == AST_NAME);
771  CPPUNIT_ASSERT(pChild2->getName() == pCompartment->getId());
772 
773  // now we reimport the model and check if the divisions and mutliplications by the compartment have been reverted
774  pDataModel->newModel(NULL, true);
775  CPPUNIT_ASSERT(pDataModel->getModel()->getCompartments().size() == 0);
776  bool result = pDataModel->importSBMLFromString(content);
777  CPPUNIT_ASSERT(result == true);
778  const CModel* pCModel = pDataModel->getModel();
779  CPPUNIT_ASSERT(pCModel->getCompartments().size() == 1);
780  // there is one factor for the conversion from particles to amount
781  CPPUNIT_ASSERT(pCModel->getModelValues().size() == 2);
782  CPPUNIT_ASSERT(pCModel->getMetabolites().size() == 2);
783  CPPUNIT_ASSERT(pCModel->getReactions().size() == 0);
784  CPPUNIT_ASSERT(pCModel->getEvents().size() == 1);
785  const CCompartment* pCCompartment = pCModel->getCompartments()[0];
786  CPPUNIT_ASSERT(pCCompartment != NULL);
787  CPPUNIT_ASSERT(pCCompartment->getStatus() == CModelEntity::FIXED);
788  const CMetab* pMetabA = pCModel->getMetabolites()[0];
789 
790  CPPUNIT_ASSERT(pMetabA != NULL);
791 
792  const CMetab* pMetabS = NULL;
793 
794  if (pMetabA->getObjectName() == "A")
795  {
796  pMetabS = pCModel->getMetabolites()[1];
797  }
798  else
799  {
800  pMetabS = pMetabA;
801  pMetabA = pCModel->getMetabolites()[1];
802  CPPUNIT_ASSERT(pMetabA != NULL);
803  }
804 
805  CPPUNIT_ASSERT(pMetabS != NULL);
806  CPPUNIT_ASSERT(pMetabA->getObjectName() == "A");
807  CPPUNIT_ASSERT(pMetabS->getObjectName() == "S");
808 
809  // next we test the initial expression for the model value
810  const CModelValue* pModelValue = NULL;
811  unsigned int iMax = pCModel->getModelValues().size();
812 
813  for (unsigned int i = 0; i < iMax; ++i)
814  {
815  if (pCModel->getModelValues()[i]->getObjectName() == "K")
816  {
817  pModelValue = pCModel->getModelValues()[i];
818  break;
819  }
820  }
821 
822  CPPUNIT_ASSERT(pModelValue != NULL);
823  CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::FIXED);
824  const CExpression* pExpr = pModelValue->getInitialExpressionPtr();
825  CPPUNIT_ASSERT(pExpr != NULL);
826  const CEvaluationNode* pEvalNode = pExpr->getRoot();
827  CPPUNIT_ASSERT(pEvalNode != NULL);
828  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OPERATOR);
829  const CEvaluationNodeOperator* pOperator = dynamic_cast<const CEvaluationNodeOperator*>(pEvalNode);
830  CPPUNIT_ASSERT(pOperator != NULL);
832  CPPUNIT_ASSERT(pOperator->getChild() != NULL);
833  CPPUNIT_ASSERT(pOperator->getChild()->getSibling() != NULL);
834  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild()->getSibling());
835  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::NUMBER);
836  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pEvalNode);
837  CPPUNIT_ASSERT(pNumberNode != NULL);
838  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 2.0) / 2.0) < 1e-6);
839  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
840  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild());
841  CPPUNIT_ASSERT(pEvalNode != NULL);
842  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OPERATOR);
843  pOperator = dynamic_cast<const CEvaluationNodeOperator*>(pEvalNode);
844  CPPUNIT_ASSERT(pOperator != NULL);
846  CPPUNIT_ASSERT(pOperator->getChild() != NULL);
847  CPPUNIT_ASSERT(pOperator->getChild()->getSibling() != NULL);
848  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild()->getSibling());
849  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OBJECT);
850  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pEvalNode);
851  CPPUNIT_ASSERT(pObjectNode != NULL);
852  CPPUNIT_ASSERT(pObjectNode->getSibling() == NULL);
854  // check the data of the object node
855  std::string objectCN = pObjectNode->getObjectCN();
856  CPPUNIT_ASSERT(!objectCN.empty());
857  std::vector<CCopasiContainer*> listOfContainers;
858  listOfContainers.push_back(const_cast<CModel*>(pCModel));
859  const CCopasiObject* pObject = pDataModel->ObjectFromName(listOfContainers, objectCN);
860  CPPUNIT_ASSERT(pObject != NULL);
861  CPPUNIT_ASSERT(pObject->isReference() == true);
862  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("InitialVolume"));
863  CPPUNIT_ASSERT(pObject->getObjectParent() == pCCompartment);
864 
865  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild());
866  CPPUNIT_ASSERT(pEvalNode != NULL);
867  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OPERATOR);
868  pOperator = dynamic_cast<const CEvaluationNodeOperator*>(pEvalNode);
870  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild());
871  CPPUNIT_ASSERT(pEvalNode != NULL);
872  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OBJECT);
873  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pEvalNode);
874  CPPUNIT_ASSERT(pObjectNode != NULL);
876  // check the data of the object node
877  objectCN = pObjectNode->getObjectCN();
878  CPPUNIT_ASSERT(!objectCN.empty());
879  pObject = pDataModel->ObjectFromName(listOfContainers, objectCN);
880  CPPUNIT_ASSERT(pObject != NULL);
881  CPPUNIT_ASSERT(pObject->isReference() == true);
882  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("InitialParticleNumber"));
883  CPPUNIT_ASSERT(pObject->getObjectParent() == pMetabS);
884  pEvalNode = dynamic_cast<const CEvaluationNode*>(pObjectNode->getSibling());
885  CPPUNIT_ASSERT(pEvalNode != NULL);
886  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OBJECT);
887  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pEvalNode);
888  CPPUNIT_ASSERT(pObjectNode != NULL);
890  // check the data of the object node
891  objectCN = pObjectNode->getObjectCN();
892  CPPUNIT_ASSERT(!objectCN.empty());
893  pObject = pDataModel->ObjectFromName(listOfContainers, objectCN);
894  CPPUNIT_ASSERT(pObject != NULL);
895  CPPUNIT_ASSERT(pObject->isReference() == true);
896  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("InitialValue"));
897 
898  //
899  // then we test the expression and the initial expression for the two metabolites
900  CPPUNIT_ASSERT(pMetabA->getStatus() == CModelEntity::REACTIONS);
901  pExpr = pMetabA->getInitialExpressionPtr();
902  CPPUNIT_ASSERT(pExpr != NULL);
903  pEvalNode = pExpr->getRoot();
904  CPPUNIT_ASSERT(pEvalNode != NULL);
905  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OPERATOR);
906  pOperator = dynamic_cast<const CEvaluationNodeOperator*>(pEvalNode);
908  CPPUNIT_ASSERT(pOperator != NULL);
909  CPPUNIT_ASSERT(pOperator->getChild() != NULL);
910  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild());
911  CPPUNIT_ASSERT(pEvalNode != NULL);
912  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::NUMBER);
913  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pEvalNode);
914 
915  if (fabs((pNumberNode->getValue() - 12.0) / 12.0) < 1e-6)
916  {
917  CPPUNIT_ASSERT(pNumberNode->getSibling() != NULL);
918  pEvalNode = dynamic_cast<const CEvaluationNode*>(pNumberNode->getSibling());
919  CPPUNIT_ASSERT(pEvalNode != NULL);
920  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::NUMBER);
921  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pEvalNode);
922  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 6.0) / 6.0) < 1e-6);
923  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
924  }
925  else
926  {
927  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 6.0) / 6.0) < 1e-6);
928  CPPUNIT_ASSERT(pNumberNode->getSibling() != NULL);
929  pEvalNode = dynamic_cast<const CEvaluationNode*>(pNumberNode->getSibling());
930  CPPUNIT_ASSERT(pEvalNode != NULL);
931  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::NUMBER);
932  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pEvalNode);
933  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 12.0) / 12.0) < 1e-6);
934  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
935  }
936 
937  CPPUNIT_ASSERT(pMetabS->getStatus() == CModelEntity::ASSIGNMENT);
938  pExpr = pMetabS->getExpressionPtr();
939  CPPUNIT_ASSERT(pExpr != NULL);
940  pEvalNode = pExpr->getRoot();
941  CPPUNIT_ASSERT(pEvalNode != NULL);
942  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OPERATOR);
943  pOperator = dynamic_cast<const CEvaluationNodeOperator*>(pEvalNode);
944  CPPUNIT_ASSERT(pOperator != NULL);
946  CPPUNIT_ASSERT(pOperator->getChild() != NULL);
947  CPPUNIT_ASSERT(pOperator->getChild()->getSibling() != NULL);
948  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild()->getSibling());
949  CPPUNIT_ASSERT(pEvalNode != NULL);
950  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::NUMBER);
951  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pEvalNode);
952  CPPUNIT_ASSERT(pNumberNode != NULL);
953  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 3.0) / 3.0) < 1e-6);
954  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
955 
956  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild());
957  CPPUNIT_ASSERT(pEvalNode != NULL);
958  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OPERATOR);
959  pOperator = dynamic_cast<const CEvaluationNodeOperator*>(pEvalNode);
960  CPPUNIT_ASSERT(pOperator != NULL);
962  CPPUNIT_ASSERT(pOperator->getChild() != NULL);
963  CPPUNIT_ASSERT(pOperator->getChild()->getSibling() != NULL);
964  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild()->getSibling());
965  CPPUNIT_ASSERT(pEvalNode != NULL);
966  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OBJECT);
967  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pEvalNode);
968  CPPUNIT_ASSERT(pObjectNode != NULL);
970  // check the data of the object node
971  objectCN = pObjectNode->getObjectCN();
972  CPPUNIT_ASSERT(!objectCN.empty());
973  pObject = pDataModel->ObjectFromName(listOfContainers, objectCN);
974  CPPUNIT_ASSERT(pObject != NULL);
975  CPPUNIT_ASSERT(pObject->isReference() == true);
976  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Volume"));
977  CPPUNIT_ASSERT(pObject->getObjectParent() == pCCompartment);
978  CPPUNIT_ASSERT(pObjectNode->getSibling() == NULL);
979 
980  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild());
981  CPPUNIT_ASSERT(pEvalNode != NULL);
982  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OPERATOR);
983  pOperator = dynamic_cast<const CEvaluationNodeOperator*>(pEvalNode);
984  CPPUNIT_ASSERT(pOperator != NULL);
986  CPPUNIT_ASSERT(pOperator->getChild() != NULL);
987  pEvalNode = dynamic_cast<const CEvaluationNode*>(pOperator->getChild());
988  CPPUNIT_ASSERT(pEvalNode != NULL);
989  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OBJECT);
990  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pEvalNode);
991  CPPUNIT_ASSERT(pObjectNode != NULL);
993  // check the data of the object node
994  objectCN = pObjectNode->getObjectCN();
995  CPPUNIT_ASSERT(!objectCN.empty());
996  pObject = pDataModel->ObjectFromName(listOfContainers, objectCN);
997  CPPUNIT_ASSERT(pObject != NULL);
998  CPPUNIT_ASSERT(pObject->isReference() == true);
999  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("ParticleNumber"));
1000  CPPUNIT_ASSERT(pObject->getObjectParent() == pMetabA);
1001  pEvalNode = dynamic_cast<const CEvaluationNode*>(pObjectNode->getSibling());
1002  CPPUNIT_ASSERT(pEvalNode != NULL);
1003  CPPUNIT_ASSERT(CEvaluationNode::type(pEvalNode->getType()) == CEvaluationNode::OBJECT);
1004  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pEvalNode);
1005  CPPUNIT_ASSERT(pObjectNode != NULL);
1007  // check the data of the object node
1008  objectCN = pObjectNode->getObjectCN();
1009  CPPUNIT_ASSERT(!objectCN.empty());
1010  pObject = pDataModel->ObjectFromName(listOfContainers, objectCN);
1011  CPPUNIT_ASSERT(pObject != NULL);
1012  CPPUNIT_ASSERT(pObject->isReference() == true);
1013  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
1014  CPPUNIT_ASSERT(pObjectNode->getSibling() == NULL);
1015 }
1016 
1017 const char* test000093::MODEL_STRING_1 =
1018  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1019  "<!-- generated with COPASI 4.6.34 (Debug) (http://www.copasi.org) at 2010-11-02 12:24:37 UTC -->\n"
1020  "<?oxygen RNGSchema=\"http://www.copasi.org/static/schema/CopasiML.rng\" type=\"xml\"?>\n"
1021  "<COPASI xmlns=\"http://www.copasi.org/static/schema\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"34\">\n"
1022  " <Model key=\"Model_1\" name=\"New Model\" simulationType=\"time\" timeUnit=\"s\" volumeUnit=\"ml\" areaUnit=\"m²\" lengthUnit=\"m\" quantityUnit=\"µmol\" type=\"deterministic\" avogadroConstant=\"6.02214e+23\">\n"
1023  " <MiriamAnnotation>\n"
1024  "<rdf:RDF\n"
1025  " xmlns:dcterms=\"http://purl.org/dc/terms/\"\n"
1026  " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n"
1027  " <rdf:Description rdf:about=\"#Model_1\">\n"
1028  " <dcterms:created>\n"
1029  " <rdf:Description>\n"
1030  " <dcterms:W3CDTF>2010-11-02T13:22:15Z</dcterms:W3CDTF>\n"
1031  " </rdf:Description>\n"
1032  " </dcterms:created>\n"
1033  " </rdf:Description>\n"
1034  "</rdf:RDF>\n"
1035  "\n"
1036  " </MiriamAnnotation>\n"
1037  " <Comment>\n"
1038  " <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"
1039  "<p>Model with variable volume compartment, micromol quantity units and a reference to the species initial amount.</p>\n"
1040  "<p>On export this should create an SBML file with the hasOnlySubstanceUnits flag on the species set.</p>\n"
1041  "<p>Assignments and initial assignment expressions to species should be multiplied by the compartment volume on export and references to species in expressions should be divided by the volume.</p>\n"
1042  "<p>On reimport these modifications should be reversed.</p>\n"
1043  "</body></html>\n"
1044  " </Comment>\n"
1045  " <ListOfCompartments>\n"
1046  " <Compartment key=\"Compartment_0\" name=\"compartment\" simulationType=\"assignment\" dimensionality=\"3\">\n"
1047  " <Expression>\n"
1048  " 3+4\n"
1049  " </Expression>\n"
1050  " </Compartment>\n"
1051  " </ListOfCompartments>\n"
1052  " <ListOfMetabolites>\n"
1053  " <Metabolite key=\"Metabolite_0\" name=\"A\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
1054  " <InitialExpression>\n"
1055  " 12+6\n"
1056  " </InitialExpression>\n"
1057  " </Metabolite>\n"
1058  " <Metabolite key=\"Metabolite_1\" name=\"S\" simulationType=\"assignment\" compartment=\"Compartment_0\">\n"
1059  " <Expression>\n"
1060  " &lt;CN=Root,Model=New Model,Vector=Compartments[compartment],Vector=Metabolites[A],Reference=Concentration&gt;*3\n"
1061  " </Expression>\n"
1062  " </Metabolite>\n"
1063  " </ListOfMetabolites>\n"
1064  " <ListOfModelValues>\n"
1065  " <ModelValue key=\"ModelValue_0\" name=\"K\" simulationType=\"fixed\">\n"
1066  " <InitialExpression>\n"
1067  " &lt;CN=Root,Model=New Model,Vector=Compartments[compartment],Vector=Metabolites[S],Reference=InitialConcentration&gt;/2.0\n"
1068  " </InitialExpression>\n"
1069  " </ModelValue>\n"
1070  " </ListOfModelValues>\n"
1071  " <StateTemplate>\n"
1072  " <StateTemplateVariable objectReference=\"Model_1\"/>\n"
1073  " <StateTemplateVariable objectReference=\"Metabolite_1\"/>\n"
1074  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
1075  " <StateTemplateVariable objectReference=\"Metabolite_0\"/>\n"
1076  " <StateTemplateVariable objectReference=\"ModelValue_0\"/>\n"
1077  " </StateTemplate>\n"
1078  " <InitialState type=\"initialState\">\n"
1079  " 0 4.215499050000001e+17 7 0 0 \n"
1080  " </InitialState>\n"
1081  " </Model>\n"
1082  "</COPASI> \n"
1083  ;
1084 
1085 const char* test000093::MODEL_STRING_2 =
1086  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1087  "<!-- generated with COPASI 4.6.34 (Debug) (http://www.copasi.org) at 2010-11-02 12:29:26 UTC -->\n"
1088  "<?oxygen RNGSchema=\"http://www.copasi.org/static/schema/CopasiML.rng\" type=\"xml\"?>\n"
1089  "<COPASI xmlns=\"http://www.copasi.org/static/schema\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"34\">\n"
1090  " <Model key=\"Model_1\" name=\"New Model\" simulationType=\"time\" timeUnit=\"s\" volumeUnit=\"ml\" areaUnit=\"m²\" lengthUnit=\"m\" quantityUnit=\"µmol\" type=\"deterministic\" avogadroConstant=\"6.02214e+23\">\n"
1091  " <Comment>\n"
1092  " <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"
1093  "<p>Model with variable volume compartment, micromol quantity units and a reference to the species initial amount.</p>\n"
1094  "<p>This time the volume is variable because there is an event assignment to it.</p>\n"
1095  "<p>On export this should create an SBML file with the hasOnlySubstanceUnits flag on the species set.</p>\n"
1096  "<p>Assignments and initial assignment expressions to species should be multiplied by the compartment volume on export and references to species in expressions should be divided by the volume.</p>\n"
1097  "<p>On reimport these modifications should be reversed.</p>\n"
1098  "</body></html>\n"
1099  " </Comment>\n"
1100  " <ListOfCompartments>\n"
1101  " <Compartment key=\"Compartment_0\" name=\"compartment\" simulationType=\"fixed\" dimensionality=\"3\">\n"
1102  " </Compartment>\n"
1103  " </ListOfCompartments>\n"
1104  " <ListOfMetabolites>\n"
1105  " <Metabolite key=\"Metabolite_0\" name=\"A\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
1106  " <InitialExpression>\n"
1107  " 12+6\n"
1108  " </InitialExpression>\n"
1109  " </Metabolite>\n"
1110  " <Metabolite key=\"Metabolite_1\" name=\"S\" simulationType=\"assignment\" compartment=\"Compartment_0\">\n"
1111  " <Expression>\n"
1112  " &lt;CN=Root,Model=New Model,Vector=Compartments[compartment],Vector=Metabolites[A],Reference=Concentration&gt;*3\n"
1113  " </Expression>\n"
1114  " </Metabolite>\n"
1115  " </ListOfMetabolites>\n"
1116  " <ListOfModelValues>\n"
1117  " <ModelValue key=\"ModelValue_0\" name=\"K\" simulationType=\"fixed\">\n"
1118  " <InitialExpression>\n"
1119  " &lt;CN=Root,Model=New Model,Vector=Compartments[compartment],Vector=Metabolites[S],Reference=InitialConcentration&gt;/2.0\n"
1120  " </InitialExpression>\n"
1121  " </ModelValue>\n"
1122  " </ListOfModelValues>\n"
1123  " <ListOfEvents>\n"
1124  " <Event key=\"Event_0\" name=\"event_1\" order=\"1\">\n"
1125  " <TriggerExpression>\n"
1126  " &lt;CN=Root,Model=New Model,Reference=Time&gt; gt 3.0\n"
1127  " </TriggerExpression>\n"
1128  " <ListOfAssignments>\n"
1129  " <Assignment targetKey=\"Metabolite_0\">\n"
1130  " <Expression>\n"
1131  " 3.0\n"
1132  " </Expression>\n"
1133  " </Assignment>\n"
1134  " <Assignment targetKey=\"Compartment_0\">\n"
1135  " <Expression>\n"
1136  " 4.0\n"
1137  " </Expression>\n"
1138  " </Assignment>\n"
1139  " </ListOfAssignments>\n"
1140  " </Event>\n"
1141  " </ListOfEvents>\n"
1142  " <StateTemplate>\n"
1143  " <StateTemplateVariable objectReference=\"Model_1\"/>\n"
1144  " <StateTemplateVariable objectReference=\"Metabolite_1\"/>\n"
1145  " <StateTemplateVariable objectReference=\"Metabolite_0\"/>\n"
1146  " <StateTemplateVariable objectReference=\"ModelValue_0\"/>\n"
1147  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
1148  " </StateTemplate>\n"
1149  " <InitialState type=\"initialState\">\n"
1150  " 0 4.215499050000001e+17 7.5878986554e+19 0 7 \n"
1151  " </InitialState>\n"
1152  " </Model>\n"
1153  "</COPASI>\n"
1154  ;
const CExpression * getExpressionPtr() const
Header file of class CExpression.
SBMLDocument * getCurrentSBMLDocument()
Header file of class CModelEntity and CModelValue.
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
CCopasiVectorN< CEvent > & getEvents()
Definition: CModel.cpp:1110
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
const std::string & getObjectName() const
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
virtual size_t size() const
const CRegisteredObjectName & getObjectCN() const
const C_FLOAT64 & getValue() const
bool newModel(CProcessReport *pProcessReport, const bool &deleteOldData)
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000093.h:34
const Type & getType() const
static const char * MODEL_STRING_1
Definition: test000093.h:32
Definition: CMetab.h:178
static const char * MODEL_STRING_2
Definition: test000093.h:33
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
static Type type(const Type &type)
bool isReference() const
void setUp()
Definition: test000093.cpp:30
void test_bug1503_2()
Definition: test000093.cpp:567
static CCopasiDataModel * addDatamodel()
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
static Type subType(const Type &type)
void test_bug1503_1()
Definition: test000093.cpp:43
bool importSBMLFromString(const std::string &sbmlDocumentText, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
static void init(int argc, char *argv[], const bool &withGui=false)
Definition: CModel.h:50
Header file of class CEvent.
void tearDown()
Definition: test000093.cpp:38
const CModelEntity::Status & getStatus() const
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
CCopasiContainer * getObjectParent() const
const CExpression * getInitialExpressionPtr() const