COPASI API  4.16.103
test000091.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000091.cpp,v $
3 // $Revision: 1.4 $
4 // $Name: $
5 // $Author: bergmann $
6 // $Date: 2012/05/16 06:24:49 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 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 #include "test000091.h"
15 
16 #include <sstream>
17 #include "utilities.hpp"
19 #include "copasi/model/CModel.h"
20 #include "copasi/model/CMetab.h"
23 #include "copasi/model/CReaction.h"
26 
27 #include <sbml/SBMLDocument.h>
28 #include <sbml/Model.h>
29 #include <sbml/Compartment.h>
30 #include <sbml/Species.h>
31 #include <sbml/Parameter.h>
32 #include <sbml/Reaction.h>
33 #include <sbml/math/ASTNode.h>
34 
36 
37 CCopasiDataModel* test000091::pCOPASIDATAMODEL = NULL;
38 
40 {
41  // Create the root container.
42  CCopasiRootContainer::init(0, NULL, false);
43  // Create the global data model.
45 }
46 
48 {
50 }
51 
53 {
54  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
55  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING1));
56  CModel* pModel = pDataModel->getModel();
57  CPPUNIT_ASSERT(pModel != NULL);
58  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
59  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
60  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
61  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
62  const CCompartment* pCompartment = pModel->getCompartments()[0];
63  CPPUNIT_ASSERT(pCompartment != NULL);
64  CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::FIXED);
65  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 2);
66  const CMetab* pB = pModel->getMetabolites()[1];
67  CPPUNIT_ASSERT(pB != NULL);
68  CPPUNIT_ASSERT(pB->getStatus() == CModelEntity::REACTIONS);
69  CMetab* pA = pModel->getMetabolites()[0];
70  CPPUNIT_ASSERT(pA != NULL);
71  CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::REACTIONS);
72  // there should now be three model values because we created two dummy model
73  // values that represent the two different delay expression
74  CPPUNIT_ASSERT(pModel->getModelValues().size() == 3);
75  const CModelValue* pK1 = NULL;
76  const CModelValue* pDummy1 = NULL;
77  const CModelValue* pDummy2 = NULL;
78  unsigned int i;
79 
80  for (i = 0; i < 3; ++i)
81  {
82  if (pModel->getModelValues()[i]->getObjectName() == "K1")
83  {
84  pK1 = pModel->getModelValues()[i];
85  }
86  else
87  {
88  if (pDummy1 == NULL)
89  {
90  pDummy1 = pModel->getModelValues()[i];
91  }
92  else
93  {
94  pDummy2 = pModel->getModelValues()[i];
95  }
96  }
97  }
98 
99  CPPUNIT_ASSERT(pK1 != NULL);
100  CPPUNIT_ASSERT(pK1->getStatus() == CModelEntity::FIXED);
101  CPPUNIT_ASSERT(fabs((pK1->getInitialValue() - 4.0) / 4.0) < 1e-9);
102  CPPUNIT_ASSERT(pDummy1 != NULL);
103  CPPUNIT_ASSERT(pDummy1->getStatus() == CModelEntity::ASSIGNMENT);
104  const CExpression* pExpr = pDummy1->getExpressionPtr();
105  CPPUNIT_ASSERT(pExpr != NULL);
106  const CEvaluationNode* pNode = pExpr->getRoot();
107  CPPUNIT_ASSERT(pNode != NULL);
108  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::DELAY);
110  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
111  CPPUNIT_ASSERT(pNode != NULL);
112  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
114  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
115  CPPUNIT_ASSERT(pObjectNode != NULL);
116  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
117  CPPUNIT_ASSERT(!objectCN.empty());
118  std::vector<CCopasiContainer*> listOfContainers;
119  listOfContainers.push_back(pModel);
120  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
121  CPPUNIT_ASSERT(pObject != NULL);
122  CPPUNIT_ASSERT(pObject->isReference() == true);
123  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
124  CPPUNIT_ASSERT(pObject->getObjectParent() == pK1);
125  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pObjectNode->getSibling());
126  CPPUNIT_ASSERT(pNumberNode != NULL);
127  CPPUNIT_ASSERT(((CEvaluationNodeNumber::SubType)CEvaluationNode::subType(pNumberNode->getType())) == CEvaluationNodeNumber::DOUBLE);
128  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 0.5) / 0.5) < 1e-3);
129  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
130 
131  CPPUNIT_ASSERT(pDummy2 != NULL);
132  CPPUNIT_ASSERT(pDummy2->getStatus() == CModelEntity::ASSIGNMENT);
133  pExpr = pDummy2->getExpressionPtr();
134  CPPUNIT_ASSERT(pExpr != NULL);
135  pNode = pExpr->getRoot();
136  CPPUNIT_ASSERT(pNode != NULL);
137  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::DELAY);
139  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
140  CPPUNIT_ASSERT(pNode != NULL);
141  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
143  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
144  CPPUNIT_ASSERT(pObjectNode != NULL);
145  objectCN = pObjectNode->getObjectCN();
146  CPPUNIT_ASSERT(!objectCN.empty());
147  pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
148  CPPUNIT_ASSERT(pObject != NULL);
149  CPPUNIT_ASSERT(pObject->isReference() == true);
150  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
151  CPPUNIT_ASSERT(pObject->getObjectParent() == pK1);
152  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pObjectNode->getSibling());
153  CPPUNIT_ASSERT(pNumberNode != NULL);
154  CPPUNIT_ASSERT(((CEvaluationNodeNumber::SubType)CEvaluationNode::subType(pNumberNode->getType())) == CEvaluationNodeNumber::DOUBLE);
155  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 0.2) / 0.2) < 1e-3);
156  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
157 
158  CPPUNIT_ASSERT(pModel->getReactions().size() == 1);
159  const CReaction* pReaction = pModel->getReactions()[0];
160  CPPUNIT_ASSERT(pReaction != NULL);
161 
162  CPPUNIT_ASSERT(pReaction->isReversible() == false);
163  // check the kinetic law
164  const CFunction* pKineticFunction = pReaction->getFunction();
165  CPPUNIT_ASSERT(pKineticFunction != NULL);
166 
167  const CChemEq* pChemEq = &pReaction->getChemEq();
168  CPPUNIT_ASSERT(pChemEq != NULL);
169  CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1);
170  CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1);
171  const CChemEqElement* pElement = pChemEq->getSubstrates()[0];
172  CPPUNIT_ASSERT(pElement != NULL);
173  CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3);
174  CPPUNIT_ASSERT(pElement->getMetabolite() == pA);
175  CPPUNIT_ASSERT(pChemEq->getProducts().size() == 1);
176  pElement = pChemEq->getProducts()[0];
177  CPPUNIT_ASSERT(pElement != NULL);
178  CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3);
179  CPPUNIT_ASSERT(pElement->getMetabolite() == pB);
180  CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0);
181 
182  const std::vector<std::vector<std::string> > parameterMappings = pReaction->getParameterMappings();
183  CPPUNIT_ASSERT(parameterMappings.size() == 3);
184  CPPUNIT_ASSERT(parameterMappings[0].size() == 1);
185  CPPUNIT_ASSERT(parameterMappings[0][0] == pDummy1->getKey());
186  CPPUNIT_ASSERT(parameterMappings[1].size() == 1);
187  CPPUNIT_ASSERT(parameterMappings[1][0] == pDummy2->getKey());
188  CPPUNIT_ASSERT(parameterMappings[2].size() == 1);
189  CPPUNIT_ASSERT(parameterMappings[2][0] == pA->getKey());
190 
191  const CFunctionParameters& funPars = pKineticFunction->getVariables();
192  CPPUNIT_ASSERT(funPars.size() == 3);
193  // check the expression of the kinetic law
194  // dummy1 * dummy2 * dummy1 * species1
195  pNode = pKineticFunction->getRoot();
196  CPPUNIT_ASSERT(pNode != NULL);
197  const CEvaluationNodeOperator* pOpNode = dynamic_cast<const CEvaluationNodeOperator*>(pNode);
198  CPPUNIT_ASSERT(pOpNode != NULL);
200  const CEvaluationNode* pNode2 = dynamic_cast<const CEvaluationNode*>(pOpNode->getChild()->getSibling());
201  CPPUNIT_ASSERT(pNode2 != NULL);
202  const CEvaluationNodeVariable* pVarNode = dynamic_cast<const CEvaluationNodeVariable*>(pNode2);
203  CPPUNIT_ASSERT(pVarNode != NULL);
204  CPPUNIT_ASSERT(pVarNode->getData() == funPars[2]->getObjectName());
205  CPPUNIT_ASSERT(pVarNode->getSibling() == NULL);
206  pOpNode = dynamic_cast<const CEvaluationNodeOperator*>(pNode->getChild());
207  CPPUNIT_ASSERT(pOpNode != NULL);
209  pNode2 = dynamic_cast<const CEvaluationNode*>(pOpNode->getChild()->getSibling());
210  CPPUNIT_ASSERT(pNode2 != NULL);
211  pVarNode = dynamic_cast<const CEvaluationNodeVariable*>(pNode2);
212  CPPUNIT_ASSERT(pVarNode != NULL);
213  CPPUNIT_ASSERT(pVarNode->getData() == funPars[0]->getObjectName());
214  pOpNode = dynamic_cast<const CEvaluationNodeOperator*>(pOpNode->getChild());
215  CPPUNIT_ASSERT(pOpNode != NULL);
217  pNode2 = dynamic_cast<const CEvaluationNode*>(pOpNode->getChild()->getSibling());
218  CPPUNIT_ASSERT(pNode2 != NULL);
219  pVarNode = dynamic_cast<const CEvaluationNodeVariable*>(pNode2);
220  CPPUNIT_ASSERT(pVarNode != NULL);
221  CPPUNIT_ASSERT(pVarNode->getData() == funPars[1]->getObjectName());
222  pNode2 = dynamic_cast<const CEvaluationNode*>(pOpNode->getChild());
223  CPPUNIT_ASSERT(pNode2 != NULL);
224  pVarNode = dynamic_cast<const CEvaluationNodeVariable*>(pNode2);
225  CPPUNIT_ASSERT(pVarNode != NULL);
226  CPPUNIT_ASSERT(pVarNode->getData() == funPars[0]->getObjectName());
227 
228  // check for the two messages
229  // we should have a message that delay is not supported and we should have a
230  // message about replaced delay nodes
231  CPPUNIT_ASSERT(CCopasiMessage::checkForMessage(MCSBML + 36));
232  CPPUNIT_ASSERT(CCopasiMessage::checkForMessage(MCSBML + 86));
233 
234  // now we reexport the model and check if the changes we made during import
235  // are exported correctly
236  CPPUNIT_ASSERT(pCOPASIDATAMODEL->getCurrentSBMLDocument() != NULL);
237  // export to the same level and version we imported
238  CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, pCOPASIDATAMODEL->getCurrentSBMLDocument()->getLevel(), pCOPASIDATAMODEL->getCurrentSBMLDocument()->getVersion()).empty() == false);
239  SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
240  CPPUNIT_ASSERT(pDocument != NULL);
241  const Model* pCModel = pDocument->getModel();
242  CPPUNIT_ASSERT(pCModel != NULL);
243  // assert that there is only one compartment and
244  // assert the compartment is constant
245  CPPUNIT_ASSERT(pCModel->getNumCompartments() == 1);
246  const Compartment* pCCompartment = pCModel->getCompartment(0);
247  CPPUNIT_ASSERT(pCCompartment->getConstant() == true);
248  CPPUNIT_ASSERT(pCModel->getNumSpecies() == 2);
249  const Species* pSpeciesA = pCModel->getSpecies(0);
250  CPPUNIT_ASSERT(pCModel->getNumParameters() == 3);
251  const Parameter* pParameterK1 = pCModel->getParameter(0);
252  CPPUNIT_ASSERT(pParameterK1 != NULL);
253  CPPUNIT_ASSERT(pParameterK1->getConstant() == true);
254  const Parameter* pParameterDummy1 = pCModel->getParameter(1);
255  CPPUNIT_ASSERT(pParameterDummy1 != NULL);
256  CPPUNIT_ASSERT(pParameterDummy1->getConstant() == false);
257  const Parameter* pParameterDummy2 = pCModel->getParameter(2);
258  CPPUNIT_ASSERT(pParameterDummy2 != NULL);
259  CPPUNIT_ASSERT(pParameterDummy2->getConstant() == false);
260  // there must be two rules
261  const AssignmentRule* pARule = dynamic_cast<const AssignmentRule*>(pCModel->getRule(pParameterDummy1->getId()));
262  CPPUNIT_ASSERT(pARule != NULL);
263  const ASTNode* pANode = pARule->getMath();
264  CPPUNIT_ASSERT(pANode != NULL);
265  CPPUNIT_ASSERT(pANode->getType() == AST_FUNCTION_DELAY);
266  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
267  const ASTNode* pChild = pANode->getChild(0);
268  CPPUNIT_ASSERT(pChild != NULL);
269  CPPUNIT_ASSERT(pChild->getType() == AST_NAME);
270  CPPUNIT_ASSERT(pChild->getName() == pParameterK1->getId());
271  pChild = pANode->getChild(1);
272  CPPUNIT_ASSERT(pChild != NULL);
273  CPPUNIT_ASSERT(pChild->getType() == AST_REAL);
274  CPPUNIT_ASSERT(fabs((pChild->getReal() - 0.5) / 0.5) < 1e-9);
275 
276  pARule = dynamic_cast<const AssignmentRule*>(pCModel->getRule(pParameterDummy2->getId()));
277  CPPUNIT_ASSERT(pARule != NULL);
278  pANode = pARule->getMath();
279  CPPUNIT_ASSERT(pANode != NULL);
280  CPPUNIT_ASSERT(pANode->getType() == AST_FUNCTION_DELAY);
281  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
282  pChild = pANode->getChild(0);
283  CPPUNIT_ASSERT(pChild != NULL);
284  CPPUNIT_ASSERT(pChild->getType() == AST_NAME);
285  CPPUNIT_ASSERT(pChild->getName() == pParameterK1->getId());
286  pChild = pANode->getChild(1);
287  CPPUNIT_ASSERT(pChild != NULL);
288  CPPUNIT_ASSERT(pChild->getType() == AST_REAL);
289  CPPUNIT_ASSERT(fabs((pChild->getReal() - 0.2) / 0.2) < 1e-9);
290 
291  const Reaction* pCReaction = pCModel->getReaction(0);
292  // make sure this is reaction A ->
293  CPPUNIT_ASSERT(pCReaction != NULL);
294  CPPUNIT_ASSERT(pCReaction->getNumReactants() == 1);
295  CPPUNIT_ASSERT(pCReaction->getNumProducts() == 1);
296 
297  CPPUNIT_ASSERT(pCReaction->isSetKineticLaw() == true);
298  const KineticLaw* pLaw = pCReaction->getKineticLaw();
299  CPPUNIT_ASSERT(pLaw != NULL);
300  CPPUNIT_ASSERT(pLaw->isSetMath() == true);
301  pANode = pLaw->getMath();
302  CPPUNIT_ASSERT(pANode->getType() == AST_TIMES);
303  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
304  CPPUNIT_ASSERT(pANode->getChild(0)->getType() == AST_NAME);
305  CPPUNIT_ASSERT(pANode->getChild(0)->getName() == pCCompartment->getId());
306  pANode = pANode->getChild(1);
307  CPPUNIT_ASSERT(pANode != NULL);
308  // times a function call
309  CPPUNIT_ASSERT(pANode->getType() == AST_FUNCTION);
310  CPPUNIT_ASSERT(pANode->getNumChildren() == 3);
311  CPPUNIT_ASSERT(pANode->getChild(0) != NULL);
312  CPPUNIT_ASSERT(pANode->getChild(0)->getType() == AST_NAME);
313  CPPUNIT_ASSERT(pANode->getChild(0)->getName() == pParameterDummy1->getId());
314  CPPUNIT_ASSERT(pANode->getChild(1) != NULL);
315  CPPUNIT_ASSERT(pANode->getChild(1)->getType() == AST_NAME);
316  CPPUNIT_ASSERT(pANode->getChild(1)->getName() == pParameterDummy2->getId());
317  CPPUNIT_ASSERT(pANode->getChild(2) != NULL);
318  CPPUNIT_ASSERT(pANode->getChild(2)->getType() == AST_NAME);
319  CPPUNIT_ASSERT(pANode->getChild(2)->getName() == pSpeciesA->getId());
320 
321  CPPUNIT_ASSERT(pCModel->getListOfFunctionDefinitions()->size() == 1);
322  const FunctionDefinition* pFunDef = pCModel->getFunctionDefinition(0);
323  CPPUNIT_ASSERT(pFunDef != NULL);
324  CPPUNIT_ASSERT(pFunDef->getId() == pANode->getName());
325  pANode = pFunDef->getMath();
326  CPPUNIT_ASSERT(pANode != NULL);
327  CPPUNIT_ASSERT(pANode->getType() == AST_LAMBDA);
328  CPPUNIT_ASSERT(pANode->getNumChildren() == 4);
329  CPPUNIT_ASSERT(pANode->getChild(0)->getType() == AST_NAME);
330  std::string paramName1 = pANode->getChild(0)->getName();
331  CPPUNIT_ASSERT(!paramName1.empty());
332  CPPUNIT_ASSERT(pANode->getChild(1)->getType() == AST_NAME);
333  std::string paramName2 = pANode->getChild(1)->getName();
334  CPPUNIT_ASSERT(!paramName2.empty());
335  CPPUNIT_ASSERT(pANode->getChild(2)->getType() == AST_NAME);
336  std::string paramName3 = pANode->getChild(2)->getName();
337  CPPUNIT_ASSERT(!paramName3.empty());
338 
339  // this is the tree of the function
340  pANode = pANode->getChild(3);
341  CPPUNIT_ASSERT(pANode != NULL);
342  CPPUNIT_ASSERT(pANode->getType() == AST_TIMES);
343  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
344  CPPUNIT_ASSERT(pANode->getChild(1)->getType() == AST_NAME);
345  CPPUNIT_ASSERT(pANode->getChild(1)->getName() == paramName3);
346  pANode = pANode->getChild(0);
347  CPPUNIT_ASSERT(pANode != NULL);
348  CPPUNIT_ASSERT(pANode->getType() == AST_TIMES);
349  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
350  CPPUNIT_ASSERT(pANode->getChild(1)->getType() == AST_NAME);
351  CPPUNIT_ASSERT(pANode->getChild(1)->getName() == paramName1);
352  pANode = pANode->getChild(0);
353  CPPUNIT_ASSERT(pANode != NULL);
354  CPPUNIT_ASSERT(pANode->getType() == AST_TIMES);
355  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
356  CPPUNIT_ASSERT(pANode->getChild(0)->getType() == AST_NAME);
357  CPPUNIT_ASSERT(pANode->getChild(0)->getName() == paramName1);
358  CPPUNIT_ASSERT(pANode->getChild(1)->getType() == AST_NAME);
359  CPPUNIT_ASSERT(pANode->getChild(1)->getName() == paramName2);
360 }
361 
363 {
364  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
365  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING2));
366  CModel* pModel = pDataModel->getModel();
367  CPPUNIT_ASSERT(pModel != NULL);
368  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
369  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
370  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
371  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
372  const CCompartment* pCompartment = pModel->getCompartments()[0];
373  CPPUNIT_ASSERT(pCompartment != NULL);
374  CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::FIXED);
375  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 2);
376  const CMetab* pB = pModel->getMetabolites()[1];
377  CPPUNIT_ASSERT(pB != NULL);
378  CPPUNIT_ASSERT(pB->getStatus() == CModelEntity::REACTIONS);
379  CMetab* pA = pModel->getMetabolites()[0];
380  CPPUNIT_ASSERT(pA != NULL);
381  CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::REACTIONS);
382  // there should now be three model values because we created two dummy model
383  // values that represent the two different delay expression
384  CPPUNIT_ASSERT(pModel->getModelValues().size() == 7);
385  const CModelValue* pK1 = NULL;
386  // four delay replacements
387  const CModelValue* pDummy1 = NULL;
388  const CModelValue* pDummy2 = NULL;
389  const CModelValue* pDummy3 = NULL;
390  const CModelValue* pDummy4 = NULL;
391  // two local parameters that had to be converted to global parameters
392  const CModelValue* pGlobalized1 = NULL;
393  const CModelValue* pGlobalized2 = NULL;
394  // assign all the global parameters
395  pK1 = pModel->getModelValues()["K1"];
396  CPPUNIT_ASSERT(pK1 != NULL);
397  pDummy1 = pModel->getModelValues()["delay_replacement_parameter_0"];
398  CPPUNIT_ASSERT(pDummy1 != NULL);
399  pDummy2 = pModel->getModelValues()["delay_replacement_parameter_1"];
400  CPPUNIT_ASSERT(pDummy2 != NULL);
401  pDummy3 = pModel->getModelValues()["delay_replacement_parameter_2"];
402  CPPUNIT_ASSERT(pDummy3 != NULL);
403  pDummy4 = pModel->getModelValues()["delay_replacement_parameter_3"];
404  CPPUNIT_ASSERT(pDummy4 != NULL);
405 
406  CPPUNIT_ASSERT(pModel->getReactions().size() == 1);
407  const CReaction* pReaction = pModel->getReactions()[0];
408  CPPUNIT_ASSERT(pReaction != NULL);
409 
410  std::string reactionId = pReaction->getSBMLId();
411  pGlobalized1 = pModel->getModelValues()[reactionId+"_local_0"];
412  CPPUNIT_ASSERT(pGlobalized1 != NULL);
413  pGlobalized2 = pModel->getModelValues()[reactionId+"_local_1"];
414  CPPUNIT_ASSERT(pGlobalized2 != NULL);
415 
416  // check if K1 has the correct value
417  CPPUNIT_ASSERT(pK1 != NULL);
418  CPPUNIT_ASSERT(pK1->getStatus() == CModelEntity::FIXED);
419  CPPUNIT_ASSERT(fabs((pK1->getInitialValue() - 4.0) / 4.0) < 1e-9);
420  // check if pGlobalized1 (former k3) has the correct value
421  CPPUNIT_ASSERT(pGlobalized1 != NULL);
422  CPPUNIT_ASSERT(pGlobalized1->getStatus() == CModelEntity::FIXED);
423  CPPUNIT_ASSERT(fabs((pGlobalized1->getInitialValue() - 0.3) / 0.3) < 1e-9);
424  // check if pGlobalized2 (former k2) has the correct value
425  CPPUNIT_ASSERT(pGlobalized2 != NULL);
426  CPPUNIT_ASSERT(pGlobalized2->getStatus() == CModelEntity::FIXED);
427  CPPUNIT_ASSERT(fabs((pGlobalized2->getInitialValue() - 0.2) / 0.2) < 1e-9);
428 
429  // check if pDummy1 has the correct expression
430  CPPUNIT_ASSERT(pDummy1->getStatus() == CModelEntity::ASSIGNMENT);
431  const CExpression* pExpr = pDummy1->getExpressionPtr();
432  CPPUNIT_ASSERT(pExpr != NULL);
433  const CEvaluationNode* pNode = pExpr->getRoot();
434  CPPUNIT_ASSERT(pNode != NULL);
435  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::DELAY);
437  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
438  CPPUNIT_ASSERT(pNode != NULL);
439  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
441  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
442  CPPUNIT_ASSERT(pObjectNode != NULL);
443  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
444  CPPUNIT_ASSERT(!objectCN.empty());
445  std::vector<CCopasiContainer*> listOfContainers;
446  listOfContainers.push_back(pModel);
447  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
448  CPPUNIT_ASSERT(pObject != NULL);
449  CPPUNIT_ASSERT(pObject->isReference() == true);
450  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
451  CPPUNIT_ASSERT(pObject->getObjectParent() == pK1);
452  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pObjectNode->getSibling());
453  CPPUNIT_ASSERT(pNumberNode != NULL);
454  CPPUNIT_ASSERT(((CEvaluationNodeNumber::SubType)CEvaluationNode::subType(pNumberNode->getType())) == CEvaluationNodeNumber::DOUBLE);
455  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 0.5) / 0.5) < 1e-3);
456  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
457 
458  // check if pDummy2 has the correct expression
459  CPPUNIT_ASSERT(pDummy2->getStatus() == CModelEntity::ASSIGNMENT);
460  pExpr = pDummy2->getExpressionPtr();
461  CPPUNIT_ASSERT(pExpr != NULL);
462  pNode = pExpr->getRoot();
463  CPPUNIT_ASSERT(pNode != NULL);
464  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::DELAY);
466  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
467  CPPUNIT_ASSERT(pNode != NULL);
468  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
470  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
471  CPPUNIT_ASSERT(pObjectNode != NULL);
472  objectCN = pObjectNode->getObjectCN();
473  CPPUNIT_ASSERT(!objectCN.empty());
474  pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
475  CPPUNIT_ASSERT(pObject != NULL);
476  CPPUNIT_ASSERT(pObject->isReference() == true);
477  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
478  CPPUNIT_ASSERT(pObject->getObjectParent() == pK1);
479  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pObjectNode->getSibling());
480  CPPUNIT_ASSERT(pNumberNode != NULL);
481  CPPUNIT_ASSERT(((CEvaluationNodeNumber::SubType)CEvaluationNode::subType(pNumberNode->getType())) == CEvaluationNodeNumber::DOUBLE);
482  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 0.2) / 0.2) < 1e-3);
483  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
484 
485  // check if pDummy3 has the correct expression
486  CPPUNIT_ASSERT(pDummy3->getStatus() == CModelEntity::ASSIGNMENT);
487  pExpr = pDummy3->getExpressionPtr();
488  CPPUNIT_ASSERT(pExpr != NULL);
489  pNode = pExpr->getRoot();
490  CPPUNIT_ASSERT(pNode != NULL);
491  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::DELAY);
493  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
494  CPPUNIT_ASSERT(pNode != NULL);
495  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
497  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
498  CPPUNIT_ASSERT(pObjectNode != NULL);
499  objectCN = pObjectNode->getObjectCN();
500  CPPUNIT_ASSERT(!objectCN.empty());
501  pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
502  CPPUNIT_ASSERT(pObject != NULL);
503  CPPUNIT_ASSERT(pObject->isReference() == true);
504  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
505  CPPUNIT_ASSERT(pObject->getObjectParent() == pGlobalized1);
506  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pObjectNode->getSibling());
507  CPPUNIT_ASSERT(pNumberNode != NULL);
508  CPPUNIT_ASSERT(((CEvaluationNodeNumber::SubType)CEvaluationNode::subType(pNumberNode->getType())) == CEvaluationNodeNumber::DOUBLE);
509  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 0.5) / 0.5) < 1e-3);
510  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
511 
512  // check if pDummy4 has the correct expression
513  CPPUNIT_ASSERT(pDummy4->getStatus() == CModelEntity::ASSIGNMENT);
514  pExpr = pDummy4->getExpressionPtr();
515  CPPUNIT_ASSERT(pExpr != NULL);
516  pNode = pExpr->getRoot();
517  CPPUNIT_ASSERT(pNode != NULL);
518  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::DELAY);
520  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
521  CPPUNIT_ASSERT(pNode != NULL);
522  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
524  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
525  CPPUNIT_ASSERT(pObjectNode != NULL);
526  objectCN = pObjectNode->getObjectCN();
527  CPPUNIT_ASSERT(!objectCN.empty());
528  pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
529  CPPUNIT_ASSERT(pObject != NULL);
530  CPPUNIT_ASSERT(pObject->isReference() == true);
531  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
532  CPPUNIT_ASSERT(pObject->getObjectParent() == pGlobalized2);
533  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pObjectNode->getSibling());
534  CPPUNIT_ASSERT(pNumberNode != NULL);
535  CPPUNIT_ASSERT(((CEvaluationNodeNumber::SubType)CEvaluationNode::subType(pNumberNode->getType())) == CEvaluationNodeNumber::DOUBLE);
536  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 0.5) / 0.5) < 1e-3);
537  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
538 
539  CPPUNIT_ASSERT(pReaction->isReversible() == false);
540  // check the kinetic law
541  const CFunction* pKineticFunction = pReaction->getFunction();
542  CPPUNIT_ASSERT(pKineticFunction != NULL);
543 
544  const CChemEq* pChemEq = &pReaction->getChemEq();
545  CPPUNIT_ASSERT(pChemEq != NULL);
546  CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1);
547  CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1);
548  const CChemEqElement* pElement = pChemEq->getSubstrates()[0];
549  CPPUNIT_ASSERT(pElement != NULL);
550  CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3);
551  CPPUNIT_ASSERT(pElement->getMetabolite() == pA);
552  CPPUNIT_ASSERT(pChemEq->getProducts().size() == 1);
553  pElement = pChemEq->getProducts()[0];
554  CPPUNIT_ASSERT(pElement != NULL);
555  CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3);
556  CPPUNIT_ASSERT(pElement->getMetabolite() == pB);
557  CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0);
558 
559  const std::vector<std::vector<std::string> > parameterMappings = pReaction->getParameterMappings();
560  CPPUNIT_ASSERT(parameterMappings.size() == 7);
561  CPPUNIT_ASSERT(parameterMappings[0].size() == 1);
562  CPPUNIT_ASSERT(pReaction->isLocalParameter(0) == false);
563  CPPUNIT_ASSERT(parameterMappings[0][0] == pDummy1->getKey());
564  CPPUNIT_ASSERT(parameterMappings[1].size() == 1);
565  CPPUNIT_ASSERT(pReaction->isLocalParameter(1) == false);
566  CPPUNIT_ASSERT(parameterMappings[1][0] == pDummy2->getKey());
567  CPPUNIT_ASSERT(parameterMappings[2].size() == 1);
568  CPPUNIT_ASSERT(pReaction->isLocalParameter(2) == false);
569  CPPUNIT_ASSERT(parameterMappings[2][0] == pDummy3->getKey());
570  CPPUNIT_ASSERT(parameterMappings[3].size() == 1);
571  CPPUNIT_ASSERT(pReaction->isLocalParameter(3) == false);
572  CPPUNIT_ASSERT(parameterMappings[3][0] == pDummy4->getKey());
573  CPPUNIT_ASSERT(parameterMappings[4].size() == 1);
574  CPPUNIT_ASSERT(pReaction->isLocalParameter(4) == true);
575  const CCopasiParameter* pLocalParam = pReaction->getParameters().getParameter("k1");
576  CPPUNIT_ASSERT(pLocalParam != NULL);
577  CPPUNIT_ASSERT(parameterMappings[5].size() == 1);
578  CPPUNIT_ASSERT(pReaction->isLocalParameter(5) == false);
579  CPPUNIT_ASSERT(parameterMappings[5][0] == pGlobalized1->getKey());
580  CPPUNIT_ASSERT(parameterMappings[6].size() == 1);
581  CPPUNIT_ASSERT(parameterMappings[6][0] == pA->getKey());
582 
583  const CFunctionParameters& funPars = pKineticFunction->getVariables();
584  CPPUNIT_ASSERT(funPars.size() == 7);
585  // check the expression of the kinetic law
586  // dummy1 * dummy2 * dummy1 * species1 * k1 * dummy3 * dummy4 * dummy3 * globalized1
587  pNode = pKineticFunction->getRoot();
588  CPPUNIT_ASSERT(pNode != NULL);
589  const CEvaluationNodeOperator* pOpNode = dynamic_cast<const CEvaluationNodeOperator*>(pNode);
590  CPPUNIT_ASSERT(pOpNode != NULL);
592  const CEvaluationNode* pNode2 = dynamic_cast<const CEvaluationNode*>(pOpNode->getChild()->getSibling());
593  CPPUNIT_ASSERT(pNode2 != NULL);
594  const CEvaluationNodeVariable* pVarNode = dynamic_cast<const CEvaluationNodeVariable*>(pNode2);
595  CPPUNIT_ASSERT(pVarNode != NULL);
596  CPPUNIT_ASSERT(pVarNode->getData() == funPars[5]->getObjectName());
597  CPPUNIT_ASSERT(pVarNode->getSibling() == NULL);
598  pOpNode = dynamic_cast<const CEvaluationNodeOperator*>(pNode->getChild());
599  CPPUNIT_ASSERT(pOpNode != NULL);
601  pNode2 = dynamic_cast<const CEvaluationNode*>(pOpNode->getChild()->getSibling());
602  CPPUNIT_ASSERT(pNode2 != NULL);
603  pVarNode = dynamic_cast<const CEvaluationNodeVariable*>(pNode2);
604  CPPUNIT_ASSERT(pVarNode != NULL);
605  CPPUNIT_ASSERT(pVarNode->getData() == funPars[2]->getObjectName());
606  pOpNode = dynamic_cast<const CEvaluationNodeOperator*>(pOpNode->getChild());
607  CPPUNIT_ASSERT(pOpNode != NULL);
609  pNode2 = dynamic_cast<const CEvaluationNode*>(pOpNode->getChild()->getSibling());
610  CPPUNIT_ASSERT(pNode2 != NULL);
611  pVarNode = dynamic_cast<const CEvaluationNodeVariable*>(pNode2);
612  CPPUNIT_ASSERT(pVarNode != NULL);
613  CPPUNIT_ASSERT(pVarNode->getData() == funPars[3]->getObjectName());
614  pOpNode = dynamic_cast<const CEvaluationNodeOperator*>(pOpNode->getChild());
615  CPPUNIT_ASSERT(pOpNode != NULL);
617  pNode2 = dynamic_cast<const CEvaluationNode*>(pOpNode->getChild()->getSibling());
618  CPPUNIT_ASSERT(pNode2 != NULL);
619  pVarNode = dynamic_cast<const CEvaluationNodeVariable*>(pNode2);
620  CPPUNIT_ASSERT(pVarNode != NULL);
621  CPPUNIT_ASSERT(pVarNode->getData() == funPars[2]->getObjectName());
622  pOpNode = dynamic_cast<const CEvaluationNodeOperator*>(pOpNode->getChild());
623  CPPUNIT_ASSERT(pOpNode != NULL);
625  pNode2 = dynamic_cast<const CEvaluationNode*>(pOpNode->getChild()->getSibling());
626  CPPUNIT_ASSERT(pNode2 != NULL);
627  pVarNode = dynamic_cast<const CEvaluationNodeVariable*>(pNode2);
628  CPPUNIT_ASSERT(pVarNode != NULL);
629  CPPUNIT_ASSERT(pVarNode->getData() == funPars[4]->getObjectName());
630  pOpNode = dynamic_cast<const CEvaluationNodeOperator*>(pOpNode->getChild());
631  CPPUNIT_ASSERT(pOpNode != NULL);
633  pNode2 = dynamic_cast<const CEvaluationNode*>(pOpNode->getChild()->getSibling());
634  CPPUNIT_ASSERT(pNode2 != NULL);
635  pVarNode = dynamic_cast<const CEvaluationNodeVariable*>(pNode2);
636  CPPUNIT_ASSERT(pVarNode != NULL);
637  CPPUNIT_ASSERT(pVarNode->getData() == funPars[6]->getObjectName());
638  pOpNode = dynamic_cast<const CEvaluationNodeOperator*>(pOpNode->getChild());
639  CPPUNIT_ASSERT(pOpNode != NULL);
641  pNode2 = dynamic_cast<const CEvaluationNode*>(pOpNode->getChild()->getSibling());
642  CPPUNIT_ASSERT(pNode2 != NULL);
643  pVarNode = dynamic_cast<const CEvaluationNodeVariable*>(pNode2);
644  CPPUNIT_ASSERT(pVarNode != NULL);
645  CPPUNIT_ASSERT(pVarNode->getData() == funPars[0]->getObjectName());
646  pOpNode = dynamic_cast<const CEvaluationNodeOperator*>(pOpNode->getChild());
647  CPPUNIT_ASSERT(pOpNode != NULL);
649  pNode2 = dynamic_cast<const CEvaluationNode*>(pOpNode->getChild()->getSibling());
650  CPPUNIT_ASSERT(pNode2 != NULL);
651  pVarNode = dynamic_cast<const CEvaluationNodeVariable*>(pNode2);
652  CPPUNIT_ASSERT(pVarNode != NULL);
653  CPPUNIT_ASSERT(pVarNode->getData() == funPars[1]->getObjectName());
654 
655  pNode2 = dynamic_cast<const CEvaluationNode*>(pOpNode->getChild());
656  CPPUNIT_ASSERT(pNode2 != NULL);
657  pVarNode = dynamic_cast<const CEvaluationNodeVariable*>(pNode2);
658  CPPUNIT_ASSERT(pVarNode != NULL);
659  CPPUNIT_ASSERT(pVarNode->getData() == funPars[0]->getObjectName());
660 
661  // check for the two messages
662  // we should have a message that delay is not supported and we should have a
663  // message about replaced delay nodes
664  CPPUNIT_ASSERT(CCopasiMessage::checkForMessage(MCSBML + 36));
665  CPPUNIT_ASSERT(CCopasiMessage::checkForMessage(MCSBML + 86));
666  CPPUNIT_ASSERT(CCopasiMessage::checkForMessage(MCSBML + 87));
667 
668  // now we reexport the model and check if the changes we made during import
669  // are exported correctly
670  CPPUNIT_ASSERT(pCOPASIDATAMODEL->getCurrentSBMLDocument() != NULL);
671  // export to the same level and version we imported
672  CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, pCOPASIDATAMODEL->getCurrentSBMLDocument()->getLevel(), pCOPASIDATAMODEL->getCurrentSBMLDocument()->getVersion()).empty() == false);
673  SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
674  CPPUNIT_ASSERT(pDocument != NULL);
675  const Model* pCModel = pDocument->getModel();
676  CPPUNIT_ASSERT(pCModel != NULL);
677  // assert that there is only one compartment and
678  // assert the compartment is constant
679  CPPUNIT_ASSERT(pCModel->getNumCompartments() == 1);
680  const Compartment* pCCompartment = pCModel->getCompartment(0);
681  CPPUNIT_ASSERT(pCCompartment->getConstant() == true);
682  CPPUNIT_ASSERT(pCModel->getNumSpecies() == 2);
683  const Species* pSpeciesA = pCModel->getSpecies(0);
684  CPPUNIT_ASSERT(pCModel->getNumParameters() == 7);
685  const Parameter* pParameterK1 = pCModel->getParameter(0);
686  CPPUNIT_ASSERT(pParameterK1 != NULL);
687  CPPUNIT_ASSERT(pParameterK1->getConstant() == true);
688  CPPUNIT_ASSERT(fabs((pParameterK1->getValue() - 4.0) / 4.0) < 1e-9);
689  const Parameter* pParameterDummy1 = pCModel->getParameter(1);
690  CPPUNIT_ASSERT(pParameterDummy1 != NULL);
691  CPPUNIT_ASSERT(pParameterDummy1->getConstant() == false);
692  const Parameter* pParameterDummy2 = pCModel->getParameter(2);
693  CPPUNIT_ASSERT(pParameterDummy2 != NULL);
694  CPPUNIT_ASSERT(pParameterDummy2->getConstant() == false);
695  const Parameter* pParameterDummy3 = pCModel->getParameter(3);
696  CPPUNIT_ASSERT(pParameterDummy3 != NULL);
697  CPPUNIT_ASSERT(pParameterDummy3->getConstant() == false);
698  const Parameter* pGlobalizedParam1 = pCModel->getParameter(4);
699  CPPUNIT_ASSERT(pGlobalizedParam1 != NULL);
700  CPPUNIT_ASSERT(pGlobalizedParam1->getConstant() == true);
701  CPPUNIT_ASSERT(fabs((pGlobalizedParam1->getValue() - 0.3) / 0.3) < 1e-9);
702  const Parameter* pParameterDummy4 = pCModel->getParameter(5);
703  CPPUNIT_ASSERT(pParameterDummy4 != NULL);
704  CPPUNIT_ASSERT(pParameterDummy4->getConstant() == false);
705  const Parameter* pGlobalizedParam2 = pCModel->getParameter(6);
706  CPPUNIT_ASSERT(pGlobalizedParam2 != NULL);
707  CPPUNIT_ASSERT(pGlobalizedParam2->getConstant() == true);
708  CPPUNIT_ASSERT(fabs((pGlobalizedParam2->getValue() - 0.2) / 0.2) < 1e-9);
709  //
710  // there must be four rules
711  const AssignmentRule* pARule = dynamic_cast<const AssignmentRule*>(pCModel->getRule(pParameterDummy1->getId()));
712  CPPUNIT_ASSERT(pARule != NULL);
713  const ASTNode* pANode = pARule->getMath();
714  CPPUNIT_ASSERT(pANode != NULL);
715  CPPUNIT_ASSERT(pANode->getType() == AST_FUNCTION_DELAY);
716  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
717  const ASTNode* pChild = pANode->getChild(0);
718  CPPUNIT_ASSERT(pChild != NULL);
719  CPPUNIT_ASSERT(pChild->getType() == AST_NAME);
720  CPPUNIT_ASSERT(pChild->getName() == pParameterK1->getId());
721  pChild = pANode->getChild(1);
722  CPPUNIT_ASSERT(pChild != NULL);
723  CPPUNIT_ASSERT(pChild->getType() == AST_REAL);
724  CPPUNIT_ASSERT(fabs((pChild->getReal() - 0.5) / 0.5) < 1e-9);
725 
726  pARule = dynamic_cast<const AssignmentRule*>(pCModel->getRule(pParameterDummy2->getId()));
727  CPPUNIT_ASSERT(pARule != NULL);
728  pANode = pARule->getMath();
729  CPPUNIT_ASSERT(pANode != NULL);
730  CPPUNIT_ASSERT(pANode->getType() == AST_FUNCTION_DELAY);
731  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
732  pChild = pANode->getChild(0);
733  CPPUNIT_ASSERT(pChild != NULL);
734  CPPUNIT_ASSERT(pChild->getType() == AST_NAME);
735  CPPUNIT_ASSERT(pChild->getName() == pParameterK1->getId());
736  pChild = pANode->getChild(1);
737  CPPUNIT_ASSERT(pChild != NULL);
738  CPPUNIT_ASSERT(pChild->getType() == AST_REAL);
739  CPPUNIT_ASSERT(fabs((pChild->getReal() - 0.2) / 0.2) < 1e-9);
740 
741  // rule for dummy3
742  pARule = dynamic_cast<const AssignmentRule*>(pCModel->getRule(pParameterDummy3->getId()));
743  CPPUNIT_ASSERT(pARule != NULL);
744  pANode = pARule->getMath();
745  CPPUNIT_ASSERT(pANode != NULL);
746  CPPUNIT_ASSERT(pANode->getType() == AST_FUNCTION_DELAY);
747  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
748  pChild = pANode->getChild(0);
749  CPPUNIT_ASSERT(pChild != NULL);
750  CPPUNIT_ASSERT(pChild->getType() == AST_NAME);
751  CPPUNIT_ASSERT(pChild->getName() == pGlobalizedParam1->getId());
752  pChild = pANode->getChild(1);
753  CPPUNIT_ASSERT(pChild != NULL);
754  CPPUNIT_ASSERT(pChild->getType() == AST_REAL);
755  CPPUNIT_ASSERT(fabs((pChild->getReal() - 0.5) / 0.5) < 1e-9);
756 
757  // rule for dummy4
758  pARule = dynamic_cast<const AssignmentRule*>(pCModel->getRule(pParameterDummy4->getId()));
759  CPPUNIT_ASSERT(pARule != NULL);
760  pANode = pARule->getMath();
761  CPPUNIT_ASSERT(pANode != NULL);
762  CPPUNIT_ASSERT(pANode->getType() == AST_FUNCTION_DELAY);
763  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
764  pChild = pANode->getChild(0);
765  CPPUNIT_ASSERT(pChild != NULL);
766  CPPUNIT_ASSERT(pChild->getType() == AST_NAME);
767  CPPUNIT_ASSERT(pChild->getName() == pGlobalizedParam2->getId());
768  pChild = pANode->getChild(1);
769  CPPUNIT_ASSERT(pChild != NULL);
770  CPPUNIT_ASSERT(pChild->getType() == AST_REAL);
771  CPPUNIT_ASSERT(fabs((pChild->getReal() - 0.5) / 0.5) < 1e-9);
772 
773  const Reaction* pCReaction = pCModel->getReaction(0);
774  // make sure this is reaction A ->
775  CPPUNIT_ASSERT(pCReaction != NULL);
776  CPPUNIT_ASSERT(pCReaction->getNumReactants() == 1);
777  CPPUNIT_ASSERT(pCReaction->getNumProducts() == 1);
778 
779  CPPUNIT_ASSERT(pCReaction->isSetKineticLaw() == true);
780  const KineticLaw* pLaw = pCReaction->getKineticLaw();
781  CPPUNIT_ASSERT(pLaw != NULL);
782  CPPUNIT_ASSERT(pLaw->getNumParameters() == 1);
783  const Parameter* pLocalP = pLaw->getParameter(0);
784  CPPUNIT_ASSERT(pLocalP != NULL);
785  CPPUNIT_ASSERT(fabs((pLocalP->getValue() - 0.1) / 0.1) < 1e-9);
786  CPPUNIT_ASSERT(pLaw->isSetMath() == true);
787  pANode = pLaw->getMath();
788  CPPUNIT_ASSERT(pANode->getType() == AST_TIMES);
789  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
790  CPPUNIT_ASSERT(pANode->getChild(0)->getType() == AST_NAME);
791  CPPUNIT_ASSERT(pANode->getChild(0)->getName() == pCCompartment->getId());
792  pANode = pANode->getChild(1);
793  CPPUNIT_ASSERT(pANode != NULL);
794  // times a function call
795  CPPUNIT_ASSERT(pANode->getType() == AST_FUNCTION);
796  CPPUNIT_ASSERT(pANode->getNumChildren() == 7);
797  CPPUNIT_ASSERT(pANode->getChild(0) != NULL);
798  CPPUNIT_ASSERT(pANode->getChild(0)->getType() == AST_NAME);
799  CPPUNIT_ASSERT(pANode->getChild(0)->getName() == pParameterDummy1->getId());
800  CPPUNIT_ASSERT(pANode->getChild(1) != NULL);
801  CPPUNIT_ASSERT(pANode->getChild(1)->getType() == AST_NAME);
802  CPPUNIT_ASSERT(pANode->getChild(1)->getName() == pParameterDummy2->getId());
803  CPPUNIT_ASSERT(pANode->getChild(2) != NULL);
804  CPPUNIT_ASSERT(pANode->getChild(2)->getType() == AST_NAME);
805  CPPUNIT_ASSERT(pANode->getChild(2)->getName() == pParameterDummy3->getId());
806  CPPUNIT_ASSERT(pANode->getChild(3) != NULL);
807  CPPUNIT_ASSERT(pANode->getChild(3)->getType() == AST_NAME);
808  CPPUNIT_ASSERT(pANode->getChild(3)->getName() == pParameterDummy4->getId());
809  CPPUNIT_ASSERT(pANode->getChild(4) != NULL);
810  CPPUNIT_ASSERT(pANode->getChild(4)->getType() == AST_NAME);
811  CPPUNIT_ASSERT(pANode->getChild(4)->getName() == pLocalP->getId());
812  CPPUNIT_ASSERT(pANode->getChild(5) != NULL);
813  CPPUNIT_ASSERT(pANode->getChild(5)->getType() == AST_NAME);
814  CPPUNIT_ASSERT(pANode->getChild(5)->getName() == pGlobalizedParam1->getId());
815  CPPUNIT_ASSERT(pANode->getChild(6) != NULL);
816  CPPUNIT_ASSERT(pANode->getChild(6)->getType() == AST_NAME);
817  CPPUNIT_ASSERT(pANode->getChild(6)->getName() == pSpeciesA->getId());
818 
819  CPPUNIT_ASSERT(pCModel->getListOfFunctionDefinitions()->size() == 1);
820  const FunctionDefinition* pFunDef = pCModel->getFunctionDefinition(0);
821  CPPUNIT_ASSERT(pFunDef != NULL);
822  CPPUNIT_ASSERT(pFunDef->getId() == pANode->getName());
823  pANode = pFunDef->getMath();
824  CPPUNIT_ASSERT(pANode != NULL);
825  CPPUNIT_ASSERT(pANode->getType() == AST_LAMBDA);
826  CPPUNIT_ASSERT(pANode->getNumChildren() == 8);
827  CPPUNIT_ASSERT(pANode->getChild(0)->getType() == AST_NAME);
828  std::string paramName1 = pANode->getChild(0)->getName();
829  CPPUNIT_ASSERT(!paramName1.empty());
830  CPPUNIT_ASSERT(pANode->getChild(1)->getType() == AST_NAME);
831  std::string paramName2 = pANode->getChild(1)->getName();
832  CPPUNIT_ASSERT(!paramName2.empty());
833  CPPUNIT_ASSERT(pANode->getChild(2)->getType() == AST_NAME);
834  std::string paramName3 = pANode->getChild(2)->getName();
835  CPPUNIT_ASSERT(!paramName3.empty());
836  CPPUNIT_ASSERT(pANode->getChild(3)->getType() == AST_NAME);
837  std::string paramName4 = pANode->getChild(3)->getName();
838  CPPUNIT_ASSERT(!paramName4.empty());
839  CPPUNIT_ASSERT(pANode->getChild(4)->getType() == AST_NAME);
840  std::string paramName5 = pANode->getChild(4)->getName();
841  CPPUNIT_ASSERT(!paramName5.empty());
842  CPPUNIT_ASSERT(pANode->getChild(5)->getType() == AST_NAME);
843  std::string paramName6 = pANode->getChild(5)->getName();
844  CPPUNIT_ASSERT(!paramName6.empty());
845  CPPUNIT_ASSERT(pANode->getChild(6)->getType() == AST_NAME);
846  std::string paramName7 = pANode->getChild(6)->getName();
847  CPPUNIT_ASSERT(!paramName7.empty());
848  //
849  // this is the tree of the function
850  pANode = pANode->getChild(7);
851  CPPUNIT_ASSERT(pANode != NULL);
852  CPPUNIT_ASSERT(pANode->getType() == AST_TIMES);
853  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
854  CPPUNIT_ASSERT(pANode->getChild(1)->getType() == AST_NAME);
855  CPPUNIT_ASSERT(pANode->getChild(1)->getName() == paramName6);
856  pANode = pANode->getChild(0);
857  CPPUNIT_ASSERT(pANode != NULL);
858  CPPUNIT_ASSERT(pANode->getType() == AST_TIMES);
859  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
860  CPPUNIT_ASSERT(pANode->getChild(1)->getType() == AST_NAME);
861  CPPUNIT_ASSERT(pANode->getChild(1)->getName() == paramName3);
862  pANode = pANode->getChild(0);
863  CPPUNIT_ASSERT(pANode != NULL);
864  CPPUNIT_ASSERT(pANode->getType() == AST_TIMES);
865  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
866  CPPUNIT_ASSERT(pANode->getChild(1)->getType() == AST_NAME);
867  CPPUNIT_ASSERT(pANode->getChild(1)->getName() == paramName4);
868  pANode = pANode->getChild(0);
869  CPPUNIT_ASSERT(pANode != NULL);
870  CPPUNIT_ASSERT(pANode->getType() == AST_TIMES);
871  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
872  CPPUNIT_ASSERT(pANode->getChild(1)->getType() == AST_NAME);
873  CPPUNIT_ASSERT(pANode->getChild(1)->getName() == paramName3);
874  pANode = pANode->getChild(0);
875  CPPUNIT_ASSERT(pANode != NULL);
876  CPPUNIT_ASSERT(pANode->getType() == AST_TIMES);
877  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
878  CPPUNIT_ASSERT(pANode->getChild(1)->getType() == AST_NAME);
879  CPPUNIT_ASSERT(pANode->getChild(1)->getName() == paramName5);
880  pANode = pANode->getChild(0);
881  CPPUNIT_ASSERT(pANode != NULL);
882  CPPUNIT_ASSERT(pANode->getType() == AST_TIMES);
883  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
884  CPPUNIT_ASSERT(pANode->getChild(1)->getType() == AST_NAME);
885  CPPUNIT_ASSERT(pANode->getChild(1)->getName() == paramName7);
886  pANode = pANode->getChild(0);
887  CPPUNIT_ASSERT(pANode != NULL);
888  CPPUNIT_ASSERT(pANode->getType() == AST_TIMES);
889  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
890  CPPUNIT_ASSERT(pANode->getChild(1)->getType() == AST_NAME);
891  CPPUNIT_ASSERT(pANode->getChild(1)->getName() == paramName1);
892  pANode = pANode->getChild(0);
893  CPPUNIT_ASSERT(pANode != NULL);
894  CPPUNIT_ASSERT(pANode->getType() == AST_TIMES);
895  CPPUNIT_ASSERT(pANode->getNumChildren() == 2);
896  CPPUNIT_ASSERT(pANode->getChild(0)->getType() == AST_NAME);
897  CPPUNIT_ASSERT(pANode->getChild(0)->getName() == paramName1);
898  CPPUNIT_ASSERT(pANode->getChild(1)->getType() == AST_NAME);
899  CPPUNIT_ASSERT(pANode->getChild(1)->getName() == paramName2);
900 }
901 
902 const char* test000091::MODEL_STRING1 =
903  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
904  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version3\" level=\"2\" version=\"3\">\n"
905  " <model id=\"Model_1\" name=\"New Model\">\n"
906  " <notes>\n"
907  " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
908  " <p>Model with delay in kinetic law</p>\n"
909  " </body>\n"
910  " </notes>\n"
911  " <listOfUnitDefinitions>\n"
912  " <unitDefinition id=\"volume\">\n"
913  " <listOfUnits>\n"
914  " <unit kind=\"litre\" scale=\"-3\"/>\n"
915  " </listOfUnits>\n"
916  " </unitDefinition>\n"
917  " <unitDefinition id=\"substance\">\n"
918  " <listOfUnits>\n"
919  " <unit kind=\"mole\" scale=\"-3\"/>\n"
920  " </listOfUnits>\n"
921  " </unitDefinition>\n"
922  " </listOfUnitDefinitions>\n"
923  " <listOfCompartments>\n"
924  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>\n"
925  " </listOfCompartments>\n"
926  " <listOfSpecies>\n"
927  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialConcentration=\"1\"/>\n"
928  " <species id=\"species_2\" name=\"B\" compartment=\"compartment_1\" initialConcentration=\"1\"/>\n"
929  " </listOfSpecies>\n"
930  " <listOfParameters>\n"
931  " <parameter id=\"parameter_1\" name=\"K1\" value=\"4\"/>\n"
932  " </listOfParameters>\n"
933  " <listOfReactions>\n"
934  " <reaction id=\"reaction_1\" name=\"reaction_0\" reversible=\"false\">\n"
935  " <listOfReactants>\n"
936  " <speciesReference species=\"species_1\"/>\n"
937  " </listOfReactants>\n"
938  " <listOfProducts>\n"
939  " <speciesReference species=\"species_2\"/>\n"
940  " </listOfProducts>\n"
941  " <kineticLaw>\n"
942  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
943  " <apply>\n"
944  " <times/>\n"
945  " <ci> compartment_1 </ci>i\n"
946  " <apply>\n"
947  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/delay\">\n"
948  " delay\n"
949  " </csymbol>\n"
950  " <ci> parameter_1 </ci>\n"
951  " <cn> 0.5 </cn>\n"
952  " </apply>\n"
953  " <apply>\n"
954  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/delay\">\n"
955  " delay\n"
956  " </csymbol>\n"
957  " <ci> parameter_1 </ci>\n"
958  " <cn> 0.2 </cn>\n"
959  " </apply>\n"
960  " <apply>\n"
961  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/delay\">\n"
962  " delay\n"
963  " </csymbol>\n"
964  " <ci> parameter_1 </ci>\n"
965  " <cn> 0.5 </cn>\n"
966  " </apply>\n"
967  " <ci> species_1 </ci>\n"
968  " </apply>\n"
969  " </math>\n"
970  " </kineticLaw>\n"
971  " </reaction>\n"
972  " </listOfReactions>\n"
973  " </model>\n"
974  "</sbml>\n"
975  ;
976 
977 const char* test000091::MODEL_STRING2 =
978  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
979  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version3\" level=\"2\" version=\"3\">\n"
980  " <model id=\"Model_1\" name=\"New Model\">\n"
981  " <notes>\n"
982  " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
983  " <p>Model with delay in kinetic law as well as local parameters in delay expression</p>\n"
984  " </body>\n"
985  " </notes>\n"
986  " <listOfUnitDefinitions>\n"
987  " <unitDefinition id=\"volume\">\n"
988  " <listOfUnits>\n"
989  " <unit kind=\"litre\" scale=\"-3\"/>\n"
990  " </listOfUnits>\n"
991  " </unitDefinition>\n"
992  " <unitDefinition id=\"substance\">\n"
993  " <listOfUnits>\n"
994  " <unit kind=\"mole\" scale=\"-3\"/>\n"
995  " </listOfUnits>\n"
996  " </unitDefinition>\n"
997  " </listOfUnitDefinitions>\n"
998  " <listOfCompartments>\n"
999  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>\n"
1000  " </listOfCompartments>\n"
1001  " <listOfSpecies>\n"
1002  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialConcentration=\"1\"/>\n"
1003  " <species id=\"species_2\" name=\"B\" compartment=\"compartment_1\" initialConcentration=\"1\"/>\n"
1004  " </listOfSpecies>\n"
1005  " <listOfParameters>\n"
1006  " <parameter id=\"parameter_1\" name=\"K1\" value=\"4\"/>\n"
1007  " </listOfParameters>\n"
1008  " <listOfReactions>\n"
1009  " <reaction id=\"reaction_1\" name=\"reaction_0\" reversible=\"false\">\n"
1010  " <listOfReactants>\n"
1011  " <speciesReference species=\"species_1\"/>\n"
1012  " </listOfReactants>\n"
1013  " <listOfProducts>\n"
1014  " <speciesReference species=\"species_2\"/>\n"
1015  " </listOfProducts>\n"
1016  " <kineticLaw>\n"
1017  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
1018  " <apply>\n"
1019  " <times/>\n"
1020  " <ci> compartment_1 </ci>i\n"
1021  " <apply>\n"
1022  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/delay\">\n"
1023  " delay\n"
1024  " </csymbol>\n"
1025  " <ci> parameter_1 </ci>\n"
1026  " <cn> 0.5 </cn>\n"
1027  " </apply>\n"
1028  " <apply>\n"
1029  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/delay\">\n"
1030  " delay\n"
1031  " </csymbol>\n"
1032  " <ci> parameter_1 </ci>\n"
1033  " <cn> 0.2 </cn>\n"
1034  " </apply>\n"
1035  " <apply>\n"
1036  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/delay\">\n"
1037  " delay\n"
1038  " </csymbol>\n"
1039  " <ci> parameter_1 </ci>\n"
1040  " <cn> 0.5 </cn>\n"
1041  " </apply>\n"
1042  " <ci> species_1 </ci>\n"
1043  " <ci> k1 </ci>\n"
1044  " <apply>\n"
1045  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/delay\">\n"
1046  " delay\n"
1047  " </csymbol>\n"
1048  " <ci> k3 </ci>\n"
1049  " <cn> 0.5 </cn>\n"
1050  " </apply>\n"
1051  " <apply>\n"
1052  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/delay\">\n"
1053  " delay\n"
1054  " </csymbol>\n"
1055  " <ci> k2 </ci>\n"
1056  " <cn> 0.5 </cn>\n"
1057  " </apply>\n"
1058  " <apply>\n"
1059  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/delay\">\n"
1060  " delay\n"
1061  " </csymbol>\n"
1062  " <ci> k3 </ci>\n"
1063  " <cn> 0.5 </cn>\n"
1064  " </apply>\n"
1065  " <ci> k3 </ci>\n"
1066  " </apply>\n"
1067  " </math>\n"
1068  " <listOfParameters>"
1069  " <parameter id=\"k1\" value=\"0.1\"/>"
1070  " <parameter id=\"k2\" value=\"0.2\"/>"
1071  " <parameter id=\"k3\" value=\"0.3\"/>"
1072  " </listOfParameters>"
1073  " </kineticLaw>\n"
1074  " </reaction>\n"
1075  " </listOfReactions>\n"
1076  " </model>\n"
1077  "</sbml>\n"
1078  ;
void tearDown()
Definition: test000091.cpp:47
const CExpression * getExpressionPtr() const
Header file of class CExpression.
size_t getCompartmentNumber() const
Definition: CChemEq.cpp:110
SBMLDocument * getCurrentSBMLDocument()
Header file of class CModelEntity and CModelValue.
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
const std::string & getObjectName() const
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
virtual size_t size() const
const Type & getType() const
Definition: CMetab.h:178
static const char * MODEL_STRING2
Definition: test000091.h:33
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000091.h:34
const C_FLOAT64 & getInitialValue() const
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
static Type type(const Type &type)
#define MCSBML
bool isReference() const
virtual const std::string & getKey() const
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
static CCopasiDataModel * addDatamodel()
static Type subType(const Type &type)
static const char * MODEL_STRING1
Definition: test000091.h:32
const CCopasiVector< CChemEqElement > & getModifiers() const
Definition: CChemEq.cpp:66
static bool checkForMessage(const size_t &number)
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
virtual const Data & getData() const
Definition: CCopasiNode.h:118
const CModelEntity::Status & getStatus() const
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
void test_delay_in_kinetic_law()
Definition: test000091.cpp:52
CCopasiContainer * getObjectParent() const
void test_delay_in_kinetic_law_local_parameter()
Definition: test000091.cpp:362
void setUp()
Definition: test000091.cpp:39