COPASI API  4.16.103
test000038.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000038.cpp,v $
3 // $Revision: 1.9 $
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 "test000038.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* test000038::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::number);
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() == 1);
70  const CModelValue* pModelValue = pModel->getModelValues()[0];
71  CPPUNIT_ASSERT(pModelValue != NULL);
72  CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::FIXED);
73  CPPUNIT_ASSERT(pModelValue->getInitialExpression() != "");
74  const CExpression* pExpr = pModelValue->getInitialExpressionPtr();
75  CPPUNIT_ASSERT(pExpr != NULL);
76  // check the expression
77  const CEvaluationNode* pNode = pExpr->getRoot();
78  CPPUNIT_ASSERT(pNode != NULL);
79  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
80  CPPUNIT_ASSERT(pObjectNode != NULL);
81  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
82  CPPUNIT_ASSERT(!objectCN.empty());
83  std::vector<CCopasiContainer*> listOfContainers;
84  listOfContainers.push_back(pModel);
85  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
86  CPPUNIT_ASSERT(pObject != NULL);
87  CPPUNIT_ASSERT(pObject->isReference() == true);
88  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("InitialParticleNumber"));
89  CPPUNIT_ASSERT(pObject->getObjectParent() == pA);
90  // check the reactions
91  CPPUNIT_ASSERT(pModel->getReactions().size() == 2);
92  const CReaction* pReaction1 = pModel->getReactions()[0];
93  CPPUNIT_ASSERT(pReaction1 != NULL);
94  CPPUNIT_ASSERT(pReaction1->isReversible() == false);
95  // check the kinetic law
96  const CFunction* pKineticFunction = pReaction1->getFunction();
97  CPPUNIT_ASSERT(pKineticFunction != NULL);
98  const CMassAction* pMassAction = dynamic_cast<const CMassAction*>(pKineticFunction);
99  //FTB: this no longer is recognized as mass action reaction because of the
100  // special case of a species with hOSU
101  CPPUNIT_ASSERT(pMassAction == NULL);
102  const CChemEq* pChemEq = &pReaction1->getChemEq();
103  CPPUNIT_ASSERT(pChemEq != NULL);
104  CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1);
105  CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1);
106  const CChemEqElement* pElement = pChemEq->getSubstrates()[0];
107  CPPUNIT_ASSERT(pElement != NULL);
108  CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3);
109  CPPUNIT_ASSERT(pElement->getMetabolite() == pA);
110  CPPUNIT_ASSERT(pChemEq->getProducts().size() == 0);
111  CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0);
112 
113  const CReaction* pReaction2 = pModel->getReactions()[1];
114  CPPUNIT_ASSERT(pReaction2 != NULL);
115  CPPUNIT_ASSERT(pReaction2->isReversible() == false);
116  // check the kinetic law
117  pKineticFunction = pReaction2->getFunction();
118  CPPUNIT_ASSERT(pKineticFunction != NULL);
119  CPPUNIT_ASSERT(pKineticFunction->getObjectName() == std::string("Henri-Michaelis-Menten (irreversible)"));
120  // check the function parameters one should be the reference to the substrate
121  pChemEq = &pReaction2->getChemEq();
122  CPPUNIT_ASSERT(pChemEq != NULL);
123  CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1);
124  CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1);
125  pElement = pChemEq->getSubstrates()[0];
126  CPPUNIT_ASSERT(pElement != NULL);
127  CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3);
128  CPPUNIT_ASSERT(pElement->getMetabolite() == pA);
129  CPPUNIT_ASSERT(pChemEq->getProducts().size() == 1);
130  pElement = pChemEq->getProducts()[0];
131  CPPUNIT_ASSERT(pElement != NULL);
132  CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3);
133  CPPUNIT_ASSERT(pElement->getMetabolite() == pB);
134  CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0);
135  const std::vector<std::vector<std::string> > parameterMappings = pReaction2->getParameterMappings();
136  CPPUNIT_ASSERT(parameterMappings.size() == 3);
137  CPPUNIT_ASSERT(parameterMappings[0].size() == 1);
138  const std::string parameterKey = parameterMappings[0][0];
139  CPPUNIT_ASSERT(parameterKey == pA->getKey());
140 }
141 
142 const char* test000038::MODEL_STRING =
143  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
144  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version3\" level=\"2\" version=\"3\">\n"
145  " <model id=\"Model_1\" name=\"New Model\">\n"
146  " <notes>\n"
147  " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
148  " <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"
149  " <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"
150  " </body>\n"
151  " </notes>\n"
152  " <listOfFunctionDefinitions>\n"
153  " <functionDefinition id=\"function_1\" name=\"Henri-Michaelis-Menten (irreversible)\">\n"
154  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
155  " <lambda>\n"
156  " <bvar>\n"
157  " <ci> substrate </ci>\n"
158  " </bvar>\n"
159  " <bvar>\n"
160  " <ci> Km </ci>\n"
161  " </bvar>\n"
162  " <bvar>\n"
163  " <ci> V </ci>\n"
164  " </bvar>\n"
165  " <apply>\n"
166  " <divide/>\n"
167  " <apply>\n"
168  " <times/>\n"
169  " <ci> V </ci>\n"
170  " <ci> substrate </ci>\n"
171  " </apply>\n"
172  " <apply>\n"
173  " <plus/>\n"
174  " <ci> Km </ci>\n"
175  " <ci> substrate </ci>\n"
176  " </apply>\n"
177  " </apply>\n"
178  " </lambda>\n"
179  " </math>\n"
180  " </functionDefinition>\n"
181  " </listOfFunctionDefinitions>\n"
182  " <listOfUnitDefinitions>\n"
183  " <unitDefinition id=\"volume\">\n"
184  " <listOfUnits>\n"
185  " <unit kind=\"litre\" scale=\"-3\"/>\n"
186  " </listOfUnits>\n"
187  " </unitDefinition>\n"
188  " <unitDefinition id=\"substance\">\n"
189  " <listOfUnits>\n"
190  " <unit kind=\"item\"/>\n"
191  " </listOfUnits>\n"
192  " </unitDefinition>\n"
193  " </listOfUnitDefinitions>\n"
194  " <listOfCompartments>\n"
195  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>\n"
196  " </listOfCompartments>\n"
197  " <listOfSpecies>\n"
198  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialAmount=\"1\" hasOnlySubstanceUnits=\"true\"/>\n"
199  " <species id=\"species_2\" name=\"B\" compartment=\"compartment_1\" initialAmount=\"1\" hasOnlySubstanceUnits=\"true\"/>\n"
200  " </listOfSpecies>\n"
201  " <listOfParameters>\n"
202  " <parameter id=\"parameter_1\" name=\"K\" value=\"0\" constant=\"true\"/>\n"
203  " </listOfParameters>\n"
204  " <listOfInitialAssignments>\n"
205  " <initialAssignment symbol=\"parameter_1\">\n"
206  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
207  " <ci> species_1 </ci>\n"
208  " </math>\n"
209  " </initialAssignment>\n"
210  " </listOfInitialAssignments>\n"
211  " <listOfReactions>\n"
212  " <reaction id=\"reaction_1\" name=\"reaction_0\" reversible=\"false\">\n"
213  " <listOfReactants>\n"
214  " <speciesReference species=\"species_1\"/>\n"
215  " </listOfReactants>\n"
216  " <kineticLaw>\n"
217  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
218  " <apply>\n"
219  " <times/>\n"
220  " <ci> k1 </ci>\n"
221  " <ci> species_1 </ci>\n"
222  " </apply>\n"
223  " </math>\n"
224  " <listOfParameters>\n"
225  " <parameter id=\"k1\" value=\"0.1\"/>\n"
226  " </listOfParameters>\n"
227  " </kineticLaw>\n"
228  " </reaction>\n"
229  " <reaction id=\"reaction_2\" name=\"reaction_1\" reversible=\"false\">\n"
230  " <listOfReactants>\n"
231  " <speciesReference species=\"species_1\"/>\n"
232  " </listOfReactants>\n"
233  " <listOfProducts>\n"
234  " <speciesReference species=\"species_2\"/>\n"
235  " </listOfProducts>\n"
236  " <kineticLaw>\n"
237  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
238  " <apply>\n"
239  " <times/>\n"
240  " <ci> compartment_1 </ci>\n"
241  " <apply>\n"
242  " <ci> function_1 </ci>\n"
243  " <apply>\n"
244  " <divide/>\n"
245  " <ci> species_1 </ci>\n"
246  " <ci> compartment_1 </ci>\n"
247  " </apply> \n"
248  " <ci> Km </ci>\n"
249  " <ci> V </ci>\n"
250  " </apply>\n"
251  " </apply>\n"
252  " </math>\n"
253  " <listOfParameters>\n"
254  " <parameter id=\"Km\" value=\"0.1\"/>\n"
255  " <parameter id=\"V\" value=\"0.1\"/>\n"
256  " </listOfParameters>\n"
257  " </kineticLaw>\n"
258  " </reaction>\n"
259  " </listOfReactions>\n"
260  " </model>\n"
261  "</sbml>\n"
262  ;
Header file of class CExpression.
size_t getCompartmentNumber() const
Definition: CChemEq.cpp:110
Header file of class CModelEntity and CModelValue.
const std::string & getObjectName() const
virtual size_t size() const
const CRegisteredObjectName & getObjectCN() const
void test_hasOnlySubstanceUnits()
Definition: test000038.cpp:49
static const char * MODEL_STRING
Definition: test000038.h:31
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
void setUp()
Definition: test000038.cpp:36
static CCopasiDataModel * addDatamodel()
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
void tearDown()
Definition: test000038.cpp:44
static void init(int argc, char *argv[], const bool &withGui=false)
Definition: CModel.h:50
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
CCopasiContainer * getObjectParent() const
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000038.h:32