COPASI API  4.16.103
test000033.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000033.cpp,v $
3 // $Revision: 1.10 $
4 // $Name: $
5 // $Author: bergmann $
6 // $Date: 2012/04/20 09:23:41 $
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 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 #include "test000033.h"
20 
21 #include <sstream>
22 #include "utilities.hpp"
24 #include "copasi/model/CModel.h"
25 #include "copasi/model/CMetab.h"
28 #include "copasi/model/CReaction.h"
31 
33 
34 CCopasiDataModel* test000033::pCOPASIDATAMODEL = NULL;
35 
37 {
38  // Create the root container.
39  CCopasiRootContainer::init(0, NULL, false);
40  // Create the global data model.
42 }
43 
45 {
47 }
48 
50 {
51  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
52  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING));
53  CModel* pModel = pDataModel->getModel();
54  CPPUNIT_ASSERT(pModel != NULL);
55  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
56  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
57  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
58  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
59  const CCompartment* pCompartment = pModel->getCompartments()[0];
60  CPPUNIT_ASSERT(pCompartment != NULL);
61  CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::FIXED);
62  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 2);
63  CMetab* pA = pModel->getMetabolites()[0];
64  CPPUNIT_ASSERT(pA != NULL);
65  CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::REACTIONS);
66  const CMetab* pB = pModel->getMetabolites()[1];
67  CPPUNIT_ASSERT(pB != NULL);
68  CPPUNIT_ASSERT(pB->getStatus() == CModelEntity::REACTIONS);
69  CPPUNIT_ASSERT(pModel->getModelValues().size() == 2);
70  // check the second model value
71  const CModelValue* pFactor = pModel->getModelValues()[1];
72  CPPUNIT_ASSERT(pFactor != NULL);
73  CPPUNIT_ASSERT(pFactor->getStatus() == CModelEntity::FIXED);
74  CPPUNIT_ASSERT(fabs((pFactor->getInitialValue() - pModel->getQuantity2NumberFactor()) / pModel->getQuantity2NumberFactor()) < 1e-3);
75  const CModelValue* pModelValue = pModel->getModelValues()[0];
76  CPPUNIT_ASSERT(pModelValue != NULL);
77  CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::ODE);
78  const CExpression* pExpr = pModelValue->getExpressionPtr();
79  // check the expression
80  const CEvaluationNode* pNode = pExpr->getRoot();
81  CPPUNIT_ASSERT(pNode != NULL);
82  const CEvaluationNodeOperator* pOperatorNode = dynamic_cast<const CEvaluationNodeOperator*>(pNode);
83  CPPUNIT_ASSERT(pOperatorNode != NULL);
85  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNode->getChild()->getSibling());
86  CPPUNIT_ASSERT(pNumberNode != NULL);
88  pOperatorNode = dynamic_cast<const CEvaluationNodeOperator*>(pOperatorNode->getChild());
89  CPPUNIT_ASSERT(pOperatorNode != NULL);
91  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pOperatorNode->getChild());
92  CPPUNIT_ASSERT(pObjectNode != NULL);
93  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
94  CPPUNIT_ASSERT(!objectCN.empty());
95  std::vector<CCopasiContainer*> listOfContainers;
96  listOfContainers.push_back(pModel);
97  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
98  CPPUNIT_ASSERT(pObject != NULL);
99  CPPUNIT_ASSERT(pObject->isReference() == true);
100  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("ParticleNumber"));
101  CPPUNIT_ASSERT(pObject->getObjectParent() == pA);
102  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pOperatorNode->getChild()->getSibling());
103  CPPUNIT_ASSERT(pObjectNode != NULL);
104  objectCN = pObjectNode->getObjectCN();
105  CPPUNIT_ASSERT(!objectCN.empty());
106  pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
107  CPPUNIT_ASSERT(pObject != NULL);
108  CPPUNIT_ASSERT(pObject->isReference() == true);
109  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
110  CPPUNIT_ASSERT(pObject->getObjectParent() == pFactor);
111 
112  CPPUNIT_ASSERT(pModel->getReactions().size() == 2);
113  const CReaction* pReaction1 = pModel->getReactions()[0];
114  CPPUNIT_ASSERT(pReaction1 != NULL);
115  CPPUNIT_ASSERT(pReaction1->isReversible() == false);
116  // check the kinetic law
117  const CFunction* pKineticFunction = pReaction1->getFunction();
118  CPPUNIT_ASSERT(pKineticFunction != NULL);
119  const CMassAction* pMassAction = dynamic_cast<const CMassAction*>(pKineticFunction);
120  //FTB: this no longer is recognized as mass action reaction because of the
121  // special case of a species with hOSU
122  CPPUNIT_ASSERT(pMassAction == NULL);
123  const CChemEq* pChemEq = &pReaction1->getChemEq();
124  CPPUNIT_ASSERT(pChemEq != NULL);
125  CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1);
126  CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1);
127  const CChemEqElement* pElement = pChemEq->getSubstrates()[0];
128  CPPUNIT_ASSERT(pElement != NULL);
129  CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3);
130  CPPUNIT_ASSERT(pElement->getMetabolite() == pA);
131  CPPUNIT_ASSERT(pChemEq->getProducts().size() == 0);
132  CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0);
133 
134  const CReaction* pReaction2 = pModel->getReactions()[1];
135  CPPUNIT_ASSERT(pReaction2 != NULL);
136  CPPUNIT_ASSERT(pReaction2->isReversible() == false);
137  // check the kinetic law
138  pKineticFunction = pReaction2->getFunction();
139  CPPUNIT_ASSERT(pKineticFunction != NULL);
140  CPPUNIT_ASSERT(pKineticFunction->getObjectName() == std::string("Henri-Michaelis-Menten (irreversible)"));
141  // check the function parameters one should be the reference to the substrate
142  pChemEq = &pReaction2->getChemEq();
143  CPPUNIT_ASSERT(pChemEq != NULL);
144  CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1);
145  CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1);
146  pElement = pChemEq->getSubstrates()[0];
147  CPPUNIT_ASSERT(pElement != NULL);
148  CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3);
149  CPPUNIT_ASSERT(pElement->getMetabolite() == pA);
150  CPPUNIT_ASSERT(pChemEq->getProducts().size() == 1);
151  pElement = pChemEq->getProducts()[0];
152  CPPUNIT_ASSERT(pElement != NULL);
153  CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3);
154  CPPUNIT_ASSERT(pElement->getMetabolite() == pB);
155  CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0);
156  const std::vector<std::vector<std::string> > parameterMappings = pReaction2->getParameterMappings();
157  CPPUNIT_ASSERT(parameterMappings.size() == 3);
158  CPPUNIT_ASSERT(parameterMappings[0].size() == 1);
159  const std::string parameterKey = parameterMappings[0][0];
160  CPPUNIT_ASSERT(parameterKey == pA->getKey());
161 }
162 
163 const char* test000033::MODEL_STRING =
164  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
165  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version3\" level=\"2\" version=\"3\">\n"
166  " <notes>\n"
167  " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
168  " <p>Model with fixed compartment volume, two species with hasOnlySubstanceUnits flag set to true. The units are set to ml and mMol. There is an assignment rule for the global parameter that contains a reference to species A multiplied by an arbitrary value.</p>\n"
169  " <p>The imported model should contain an assignment for the global parameter that consists of the reference to the particle number of species A divided by a constant and multiplied by the arbitrary value. The species references in the reactions should be imported multiplied by the volume.</p>\n"
170  " </body>\n"
171  " </notes>\n"
172  " <model id=\"Model_1\" name=\"New Model\">\n"
173  " <listOfFunctionDefinitions>\n"
174  " <functionDefinition id=\"function_1\" name=\"Henri-Michaelis-Menten (irreversible)\">\n"
175  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
176  " <lambda>\n"
177  " <bvar>\n"
178  " <ci> substrate </ci>\n"
179  " </bvar>\n"
180  " <bvar>\n"
181  " <ci> Km </ci>\n"
182  " </bvar>\n"
183  " <bvar>\n"
184  " <ci> V </ci>\n"
185  " </bvar>\n"
186  " <apply>\n"
187  " <divide/>\n"
188  " <apply>\n"
189  " <times/>\n"
190  " <ci> V </ci>\n"
191  " <ci> substrate </ci>\n"
192  " </apply>\n"
193  " <apply>\n"
194  " <plus/>\n"
195  " <ci> Km </ci>\n"
196  " <ci> substrate </ci>\n"
197  " </apply>\n"
198  " </apply>\n"
199  " </lambda>\n"
200  " </math>\n"
201  " </functionDefinition>\n"
202  " </listOfFunctionDefinitions>\n"
203  " <listOfUnitDefinitions>\n"
204  " <unitDefinition id=\"volume\">\n"
205  " <listOfUnits>\n"
206  " <unit kind=\"litre\" scale=\"-3\"/>\n"
207  " </listOfUnits>\n"
208  " </unitDefinition>\n"
209  " <unitDefinition id=\"substance\">\n"
210  " <listOfUnits>\n"
211  " <unit kind=\"mole\" scale=\"-3\"/>\n"
212  " </listOfUnits>\n"
213  " </unitDefinition>\n"
214  " </listOfUnitDefinitions>\n"
215  " <listOfCompartments>\n"
216  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>\n"
217  " </listOfCompartments>\n"
218  " <listOfSpecies>\n"
219  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialAmount=\"1\" hasOnlySubstanceUnits=\"true\"/>\n"
220  " <species id=\"species_2\" name=\"B\" compartment=\"compartment_1\" initialAmount=\"1\" hasOnlySubstanceUnits=\"true\"/>\n"
221  " </listOfSpecies>\n"
222  " <listOfParameters>\n"
223  " <parameter id=\"parameter_1\" name=\"K\" value=\"0\" constant=\"false\"/>\n"
224  " </listOfParameters>\n"
225  " <listOfRules>\n"
226  " <rateRule variable=\"parameter_1\">\n"
227  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
228  " <apply>\n"
229  " <times/>\n"
230  " <ci> species_1 </ci>\n"
231  " <cn> 3.0221415e20 </cn>\n"
232  " </apply>\n"
233  " </math>\n"
234  " </rateRule>\n"
235  " </listOfRules>\n"
236  " <listOfReactions>\n"
237  " <reaction id=\"reaction_1\" name=\"reaction_0\" reversible=\"false\">\n"
238  " <listOfReactants>\n"
239  " <speciesReference species=\"species_1\"/>\n"
240  " </listOfReactants>\n"
241  " <kineticLaw>\n"
242  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
243  " <apply>\n"
244  " <times/>\n"
245  " <ci> k1 </ci>\n"
246  " <ci> species_1 </ci>\n"
247  " </apply>\n"
248  " </math>\n"
249  " <listOfParameters>\n"
250  " <parameter id=\"k1\" value=\"0.1\"/>\n"
251  " </listOfParameters>\n"
252  " </kineticLaw>\n"
253  " </reaction>\n"
254  " <reaction id=\"reaction_2\" name=\"reaction_1\" reversible=\"false\">\n"
255  " <listOfReactants>\n"
256  " <speciesReference species=\"species_1\"/>\n"
257  " </listOfReactants>\n"
258  " <listOfProducts>\n"
259  " <speciesReference species=\"species_2\"/>\n"
260  " </listOfProducts>\n"
261  " <kineticLaw>\n"
262  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
263  " <apply>\n"
264  " <times/>\n"
265  " <ci> compartment_1 </ci>\n"
266  " <apply>\n"
267  " <ci> function_1 </ci>\n"
268  " <apply>\n"
269  " <divide/>\n"
270  " <ci> species_1 </ci>\n"
271  " <ci> compartment_1 </ci>\n"
272  " </apply> \n"
273  " <ci> Km </ci>\n"
274  " <ci> V </ci>\n"
275  " </apply>\n"
276  " </apply>\n"
277  " </math>\n"
278  " <listOfParameters>\n"
279  " <parameter id=\"Km\" value=\"0.1\"/>\n"
280  " <parameter id=\"V\" value=\"0.1\"/>\n"
281  " </listOfParameters>\n"
282  " </kineticLaw>\n"
283  " </reaction>\n"
284  " </listOfReactions>\n"
285  " </model>\n"
286  "</sbml>\n"
287  ;
const CExpression * getExpressionPtr() const
Header file of class CExpression.
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000033.h:32
size_t getCompartmentNumber() const
Definition: CChemEq.cpp:110
Header file of class CModelEntity and CModelValue.
void setUp()
Definition: test000033.cpp:36
const std::string & getObjectName() const
virtual size_t size() const
static const char * MODEL_STRING
Definition: test000033.h:31
const Type & getType() const
void tearDown()
Definition: test000033.cpp:44
Definition: CMetab.h:178
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
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)
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
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
void test_hasOnlySubstanceUnits()
Definition: test000033.cpp:49