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