COPASI API  4.16.103
test000043.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 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 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 #include "test000043.h"
12 
13 #include <sstream>
14 #include "utilities.hpp"
16 #include "copasi/model/CModel.h"
17 #include "copasi/model/CMetab.h"
20 #include "copasi/model/CReaction.h"
23 
25 
26 CCopasiDataModel* test000043::pCOPASIDATAMODEL = NULL;
27 
29 {
30  // Create the root container.
31  CCopasiRootContainer::init(0, NULL, false);
32  // Create the global data model.
34 }
35 
37 {
39 }
40 
42 {
43  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
44  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING));
45  CModel* pModel = pDataModel->getModel();
46  CPPUNIT_ASSERT(pModel != NULL);
47  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::number);
48  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
49  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
50  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
51  const CCompartment* pCompartment = pModel->getCompartments()[0];
52  CPPUNIT_ASSERT(pCompartment != NULL);
53  CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::FIXED);
54  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 2);
55  CMetab* pA = pModel->getMetabolites()[0];
56  CPPUNIT_ASSERT(pA != NULL);
57  CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::REACTIONS);
58  const CMetab* pB = pModel->getMetabolites()[1];
59  CPPUNIT_ASSERT(pB != NULL);
60  CPPUNIT_ASSERT(pB->getStatus() == CModelEntity::REACTIONS);
61  CPPUNIT_ASSERT(pModel->getModelValues().size() == 1);
62  const CModelValue* pModelValue = pModel->getModelValues()[0];
63  CPPUNIT_ASSERT(pModelValue != NULL);
64  CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::FIXED);
65  CPPUNIT_ASSERT(pModelValue->getInitialExpression() != "");
66  const CExpression* pExpr = pModelValue->getInitialExpressionPtr();
67  CPPUNIT_ASSERT(pExpr != NULL);
68  // check the expression
69  const CEvaluationNode* pNode = pExpr->getRoot();
70  CPPUNIT_ASSERT(pNode != NULL);
71  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
72  CPPUNIT_ASSERT(pObjectNode != NULL);
73  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
74  CPPUNIT_ASSERT(!objectCN.empty());
75  std::vector<CCopasiContainer*> listOfContainers;
76  listOfContainers.push_back(pModel);
77  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
78  CPPUNIT_ASSERT(pObject != NULL);
79  CPPUNIT_ASSERT(pObject->isReference() == true);
80  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("InitialParticleNumber"));
81  CPPUNIT_ASSERT(pObject->getObjectParent() == pA);
82  // check the reactions
83  CPPUNIT_ASSERT(pModel->getReactions().size() == 2);
84  const CReaction* pReaction1 = pModel->getReactions()[0];
85  CPPUNIT_ASSERT(pReaction1 != NULL);
86  CPPUNIT_ASSERT(pReaction1->isReversible() == false);
87  // check the kinetic law
88  const CFunction* pKineticFunction = pReaction1->getFunction();
89  CPPUNIT_ASSERT(pKineticFunction != NULL);
90  const CMassAction* pMassAction = dynamic_cast<const CMassAction*>(pKineticFunction);
91  //FTB: this no longer is recognized as mass action reaction because of the
92  // special case of a species with hOSU
93  CPPUNIT_ASSERT(pMassAction == NULL);
94  const CChemEq* pChemEq = &pReaction1->getChemEq();
95  CPPUNIT_ASSERT(pChemEq != NULL);
96  CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1);
97  CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1);
98  const CChemEqElement* pElement = pChemEq->getSubstrates()[0];
99  CPPUNIT_ASSERT(pElement != NULL);
100  CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3);
101  CPPUNIT_ASSERT(pElement->getMetabolite() == pA);
102  CPPUNIT_ASSERT(pChemEq->getProducts().size() == 0);
103  CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0);
104 
105  const CReaction* pReaction2 = pModel->getReactions()[1];
106  CPPUNIT_ASSERT(pReaction2 != NULL);
107  CPPUNIT_ASSERT(pReaction2->isReversible() == false);
108  // check the kinetic law
109  pKineticFunction = pReaction2->getFunction();
110  CPPUNIT_ASSERT(pKineticFunction != NULL);
111  CPPUNIT_ASSERT(pKineticFunction->getObjectName() == std::string("Function for reaction_1"));
112  const CFunctionParameters* pFunctionParameters = &pKineticFunction->getVariables();
113  CPPUNIT_ASSERT(pFunctionParameters->size() == 4);
114  const CFunctionParameter* pFunctionParameter = (*pFunctionParameters)[0];
115  CPPUNIT_ASSERT(pFunctionParameter != NULL);
116  CPPUNIT_ASSERT(pFunctionParameter->getType() == CFunctionParameter::FLOAT64);
117  CPPUNIT_ASSERT(pFunctionParameter->getUsage() == CFunctionParameter::PARAMETER);
118  pFunctionParameter = (*pFunctionParameters)[1];
119  CPPUNIT_ASSERT(pFunctionParameter != NULL);
120  CPPUNIT_ASSERT(pFunctionParameter->getType() == CFunctionParameter::FLOAT64);
121  CPPUNIT_ASSERT(pFunctionParameter->getUsage() == CFunctionParameter::PARAMETER);
122  pFunctionParameter = (*pFunctionParameters)[2];
123  CPPUNIT_ASSERT(pFunctionParameter != NULL);
124  CPPUNIT_ASSERT(pFunctionParameter->getType() == CFunctionParameter::FLOAT64);
125  CPPUNIT_ASSERT(pFunctionParameter->getUsage() == CFunctionParameter::VOLUME);
126  pFunctionParameter = (*pFunctionParameters)[3];
127  CPPUNIT_ASSERT(pFunctionParameter != NULL);
128  CPPUNIT_ASSERT(pFunctionParameter->getType() == CFunctionParameter::FLOAT64);
129  CPPUNIT_ASSERT(pFunctionParameter->getUsage() == CFunctionParameter::SUBSTRATE);
130  pNode = pKineticFunction->getRoot();
131  const CEvaluationNodeCall* pCallNode = dynamic_cast<const CEvaluationNodeCall*>(pNode);
132  CPPUNIT_ASSERT(pCallNode != NULL);
134  CPPUNIT_ASSERT(pCallNode->getData() == std::string("Henri-Michaelis-Menten (irreversible)_2"));
135  const CEvaluationNodeOperator* pOperatorNode = dynamic_cast<const CEvaluationNodeOperator*>(pCallNode->getChild());
136  CPPUNIT_ASSERT(pOperatorNode != NULL);
138  const CEvaluationNodeVariable* pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode->getChild());
139  CPPUNIT_ASSERT(pVariableNode != NULL);
140  CPPUNIT_ASSERT(pVariableNode->getIndex() == 3);
141  pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode->getChild()->getSibling());
142  CPPUNIT_ASSERT(pVariableNode != NULL);
143  CPPUNIT_ASSERT(pVariableNode->getIndex() == 2);
144  pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pCallNode->getChild()->getSibling());
145  CPPUNIT_ASSERT(pVariableNode != NULL);
146  CPPUNIT_ASSERT(pVariableNode->getIndex() == 0);
147  pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pCallNode->getChild()->getSibling()->getSibling());
148  CPPUNIT_ASSERT(pVariableNode != NULL);
149  CPPUNIT_ASSERT(pVariableNode->getIndex() == 1);
150 
151  pKineticFunction = dynamic_cast<const CFunction*>(pCallNode->getCalledTree());
152  CPPUNIT_ASSERT(pKineticFunction != NULL);
153  CPPUNIT_ASSERT(pKineticFunction->getObjectName() == std::string("Henri-Michaelis-Menten (irreversible)_2"));
154  pNode = pKineticFunction->getRoot();
155  CPPUNIT_ASSERT(pNode != NULL);
156  pOperatorNode = dynamic_cast<const CEvaluationNodeOperator*>(pNode);
157  CPPUNIT_ASSERT(pOperatorNode != NULL);
158  CPPUNIT_ASSERT(((CEvaluationNodeOperator::SubType)CEvaluationNode::subType(pOperatorNode->getType())) == CEvaluationNodeOperator::DIVIDE);
159  const CEvaluationNodeOperator* pOperatorNode2 = dynamic_cast<const CEvaluationNodeOperator*>(pOperatorNode->getChild());
160  CPPUNIT_ASSERT(pOperatorNode2 != NULL);
162  pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode2->getChild());
163  CPPUNIT_ASSERT(pVariableNode != NULL);
164  CPPUNIT_ASSERT(pVariableNode->getIndex() == 2);
165  pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode2->getChild()->getSibling());
166  CPPUNIT_ASSERT(pVariableNode != NULL);
167  CPPUNIT_ASSERT(pVariableNode->getIndex() == 0);
168  pOperatorNode2 = dynamic_cast<const CEvaluationNodeOperator*>(pOperatorNode->getChild()->getSibling());
169  CPPUNIT_ASSERT(pOperatorNode2 != NULL);
171  pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode2->getChild());
172  CPPUNIT_ASSERT(pVariableNode != NULL);
173  CPPUNIT_ASSERT(pVariableNode->getIndex() == 1);
174  pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode2->getChild()->getSibling());
175  CPPUNIT_ASSERT(pVariableNode != NULL);
176  CPPUNIT_ASSERT(pVariableNode->getIndex() == 0);
177 
178  // check the function parameters one should be the reference to the substrate
179  pChemEq = &pReaction2->getChemEq();
180  CPPUNIT_ASSERT(pChemEq != NULL);
181  CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1);
182  CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1);
183  pElement = pChemEq->getSubstrates()[0];
184  CPPUNIT_ASSERT(pElement != NULL);
185  CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3);
186  CPPUNIT_ASSERT(pElement->getMetabolite() == pA);
187  CPPUNIT_ASSERT(pChemEq->getProducts().size() == 1);
188  pElement = pChemEq->getProducts()[0];
189  CPPUNIT_ASSERT(pElement != NULL);
190  CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3);
191  CPPUNIT_ASSERT(pElement->getMetabolite() == pB);
192  CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0);
193  const std::vector<std::vector<std::string> > parameterMappings = pReaction2->getParameterMappings();
194  CPPUNIT_ASSERT(parameterMappings.size() == 4);
195  CPPUNIT_ASSERT(parameterMappings[2].size() == 1);
196  std::string parameterKey = parameterMappings[2][0];
197  CPPUNIT_ASSERT(parameterKey == pCompartment->getKey());
198  CPPUNIT_ASSERT(parameterMappings[3].size() == 1);
199  parameterKey = parameterMappings[3][0];
200  CPPUNIT_ASSERT(parameterKey == pA->getKey());
201 }
202 
203 const char* test000043::MODEL_STRING =
204  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
205  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version3\" level=\"2\" version=\"3\">\n"
206  " <model id=\"Model_1\" name=\"New Model\">\n"
207  " <notes>\n"
208  " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
209  " <p>Model with fixed compartment volume, two species with hasOnlySubstanceUnits flag set to true. The units are set to ml and item. There is an initial assignment for the global parameter that contains a reference to species A.</p>\n"
210  " <p>The imported model should contain an initial assignment for the global parameter that consists of the reference to the particle number of species A. The species references in the reactions should be imported multiplied by the volume.</p>\n"
211  " </body>\n"
212  " </notes>\n"
213  " <listOfFunctionDefinitions>\n"
214  " <functionDefinition id=\"function_1\" name=\"Henri-Michaelis-Menten (irreversible)\">\n"
215  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
216  " <lambda>\n"
217  " <bvar>\n"
218  " <ci> substrate </ci>\n"
219  " </bvar>\n"
220  " <bvar>\n"
221  " <ci> Km </ci>\n"
222  " </bvar>\n"
223  " <bvar>\n"
224  " <ci> V </ci>\n"
225  " </bvar>\n"
226  " <apply>\n"
227  " <divide/>\n"
228  " <apply>\n"
229  " <times/>\n"
230  " <ci> V </ci>\n"
231  " <ci> substrate </ci>\n"
232  " </apply>\n"
233  " <apply>\n"
234  " <plus/>\n"
235  " <ci> Km </ci>\n"
236  " <ci> substrate </ci>\n"
237  " </apply>\n"
238  " </apply>\n"
239  " </lambda>\n"
240  " </math>\n"
241  " </functionDefinition>\n"
242  " </listOfFunctionDefinitions>\n"
243  " <listOfUnitDefinitions>\n"
244  " <unitDefinition id=\"volume\">\n"
245  " <listOfUnits>\n"
246  " <unit kind=\"litre\" scale=\"-3\"/>\n"
247  " </listOfUnits>\n"
248  " </unitDefinition>\n"
249  " <unitDefinition id=\"substance\">\n"
250  " <listOfUnits>\n"
251  " <unit kind=\"item\"/>\n"
252  " </listOfUnits>\n"
253  " </unitDefinition>\n"
254  " </listOfUnitDefinitions>\n"
255  " <listOfCompartments>\n"
256  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>\n"
257  " </listOfCompartments>\n"
258  " <listOfSpecies>\n"
259  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialAmount=\"1\" hasOnlySubstanceUnits=\"true\"/>\n"
260  " <species id=\"species_2\" name=\"B\" compartment=\"compartment_1\" initialAmount=\"1\" hasOnlySubstanceUnits=\"true\"/>\n"
261  " </listOfSpecies>\n"
262  " <listOfParameters>\n"
263  " <parameter id=\"parameter_1\" name=\"K\" value=\"0\" constant=\"true\"/>\n"
264  " </listOfParameters>\n"
265  " <listOfInitialAssignments>\n"
266  " <initialAssignment symbol=\"parameter_1\">\n"
267  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
268  " <ci> species_1 </ci>\n"
269  " </math>\n"
270  " </initialAssignment>\n"
271  " </listOfInitialAssignments>\n"
272  " <listOfReactions>\n"
273  " <reaction id=\"reaction_1\" name=\"reaction_0\" reversible=\"false\">\n"
274  " <listOfReactants>\n"
275  " <speciesReference species=\"species_1\"/>\n"
276  " </listOfReactants>\n"
277  " <kineticLaw>\n"
278  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
279  " <apply>\n"
280  " <times/>\n"
281  " <ci> k1 </ci>\n"
282  " <ci> species_1 </ci>\n"
283  " </apply>\n"
284  " </math>\n"
285  " <listOfParameters>\n"
286  " <parameter id=\"k1\" value=\"0.1\"/>\n"
287  " </listOfParameters>\n"
288  " </kineticLaw>\n"
289  " </reaction>\n"
290  " <reaction id=\"reaction_2\" name=\"reaction_1\" reversible=\"false\">\n"
291  " <listOfReactants>\n"
292  " <speciesReference species=\"species_1\"/>\n"
293  " </listOfReactants>\n"
294  " <listOfProducts>\n"
295  " <speciesReference species=\"species_2\"/>\n"
296  " </listOfProducts>\n"
297  " <kineticLaw>\n"
298  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
299  " <apply>\n"
300  " <times/>\n"
301  " <ci> compartment_1 </ci>\n"
302  " <apply>\n"
303  " <ci> function_1 </ci>\n"
304  " <ci> species_1 </ci>\n"
305  " <ci> Km </ci>\n"
306  " <ci> V </ci>\n"
307  " </apply>\n"
308  " </apply>\n"
309  " </math>\n"
310  " <listOfParameters>\n"
311  " <parameter id=\"Km\" value=\"0.1\"/>\n"
312  " <parameter id=\"V\" value=\"0.1\"/>\n"
313  " </listOfParameters>\n"
314  " </kineticLaw>\n"
315  " </reaction>\n"
316  " </listOfReactions>\n"
317  " </model>\n"
318  "</sbml>\n"
319  ;
Header file of class CExpression.
size_t getCompartmentNumber() const
Definition: CChemEq.cpp:110
const CEvaluationTree * getCalledTree() const
Header file of class CModelEntity and CModelValue.
const std::string & getObjectName() const
virtual size_t size() const
const CRegisteredObjectName & getObjectCN() const
const Type & getType() const
void tearDown()
Definition: test000043.cpp:36
void setUp()
Definition: test000043.cpp:28
Definition: CMetab.h:178
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
virtual const Data & getData() const
bool isReference() const
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
static CCopasiDataModel * addDatamodel()
static Type subType(const Type &type)
const CCopasiVector< CChemEqElement > & getModifiers() const
Definition: CChemEq.cpp:66
bool importSBMLFromString(const std::string &sbmlDocumentText, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
void test_hasOnlySubstanceUnits()
Definition: test000043.cpp:41
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
static void init(int argc, char *argv[], const bool &withGui=false)
Definition: CModel.h:50
static const char * MODEL_STRING
Definition: test000043.h:31
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000043.h:32
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
CCopasiContainer * getObjectParent() const