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