COPASI API  4.16.103
test000011.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000011.cpp,v $
3 // $Revision: 1.6 $
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 "test000011.hpp"
20 
21 #include <sstream>
22 #include "utilities.hpp"
24 
25 #include "sbml/SBMLDocument.h"
26 #include "sbml/Model.h"
27 #include "sbml/Rule.h"
28 #include "sbml/Species.h"
29 #include "sbml/Parameter.h"
30 #include "sbml/math/ASTNode.h"
31 
33 
34 CCopasiDataModel* test000011::pCOPASIDATAMODEL = NULL;
35 
36 void test000011::setUp()
37 {
38  // Create the root container.
39  CCopasiRootContainer::init(0, NULL, false);
40  // Create the global data model.
41  pCOPASIDATAMODEL = CCopasiRootContainer::addDatamodel();
42 }
43 
44 void test000011::tearDown()
45 {
47 }
48 
49 void test000011::test_references_to_species()
50 {
51  // load the CPS file
52  // export to SBML
53  // check the resulting SBML model
54  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
55  std::istringstream iss(test000011::MODEL_STRING);
56  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
57  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
58  CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, 2, 3).empty() == false);
59  SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
60  CPPUNIT_ASSERT(pDocument != NULL);
61  Model* pModel = pDocument->getModel();
62  CPPUNIT_ASSERT(pModel != NULL);
63  // assert that there is only one compartment and
64  // assert the compartment is constant
65  CPPUNIT_ASSERT(pModel->getNumCompartments() == 1);
66  Compartment* pCompartment = pModel->getCompartment(0);
67  CPPUNIT_ASSERT(pCompartment->getConstant() == false);
68  CPPUNIT_ASSERT(pModel->getNumSpecies() == 2);
69  Species* pSpecies = pModel->getSpecies(1);
70  CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() == true);
71  pSpecies = pModel->getSpecies(0);
72  std::string idSpeciesA = pSpecies->getId();
73  CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() == true);
74  CPPUNIT_ASSERT(pModel->getNumParameters() == 2);
75  Parameter* pParameter = pModel->getParameter(0);
76  CPPUNIT_ASSERT(pParameter != NULL);
77  Parameter* pFactor = pModel->getParameter(1);
78  CPPUNIT_ASSERT(pFactor != NULL);
79  CPPUNIT_ASSERT(pFactor->getConstant() == true);
80  CPPUNIT_ASSERT(fabs((pFactor->getValue() - (AVOGADRO / 1000.0)) / (AVOGADRO / 1000.0)) < 1e-3);
81  // two rules, one rule is for the compartment
82  CPPUNIT_ASSERT(pModel->getNumRules() == 2);
83  AssignmentRule* pRule = dynamic_cast<AssignmentRule*>(pModel->getRule(0));
84  CPPUNIT_ASSERT(pRule != NULL);
85 
86  if (pRule->getVariable() != pParameter->getId())
87  {
88  CPPUNIT_ASSERT(pRule->getVariable() == pCompartment->getId());
89  pRule = dynamic_cast<AssignmentRule*>(pModel->getRule(1));
90  CPPUNIT_ASSERT(pRule != NULL);
91  CPPUNIT_ASSERT(pRule->getVariable() == pParameter->getId());
92  }
93 
94  const ASTNode* pMath = pRule->getMath();
95 
96  CPPUNIT_ASSERT(pMath != NULL);
97 
98  // the expression should be the species multiplied by a factor
99  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
100 
101  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
102 
103  CPPUNIT_ASSERT(pMath->getChild(0) != NULL);
104 
105  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
106 
107  CPPUNIT_ASSERT(pMath->getChild(0)->getName() == pSpecies->getId());
108 
109  CPPUNIT_ASSERT(pMath->getChild(1) != NULL);
110 
111  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
112 
113  CPPUNIT_ASSERT(pMath->getChild(1)->getName() == pFactor->getId());
114 
115  CPPUNIT_ASSERT(pModel->getNumReactions() == 2);
116 
117  Reaction* pReaction = pModel->getReaction(0);
118 
119  // make sure this is reaction A ->
120  CPPUNIT_ASSERT(pReaction != NULL);
121 
122  CPPUNIT_ASSERT(pReaction->getNumReactants() == 1);
123 
124  CPPUNIT_ASSERT(pReaction->getNumProducts() == 0);
125 
126  // check if all references in the kinetic law are unmodified
127  // math element must be a multiplication of the mass action term by
128  // the compartment volume
129  // the mass action term is a multiplication of the parameter node by
130  // the species node
131  CPPUNIT_ASSERT(pReaction->isSetKineticLaw() == true);
132 
133  KineticLaw* pLaw = pReaction->getKineticLaw();
134 
135  CPPUNIT_ASSERT(pLaw != NULL);
136 
137  CPPUNIT_ASSERT(pLaw->isSetMath() == true);
138 
139  pMath = pLaw->getMath();
140 
141  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
142 
143  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
144 
145  CPPUNIT_ASSERT(pMath->getChild(0) != NULL);
146 
147  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
148 
149  CPPUNIT_ASSERT(pMath->getChild(0)->getName() == std::string("k1"));
150 
151  CPPUNIT_ASSERT(pMath->getChild(1) != NULL);
152 
153  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
154 
155  CPPUNIT_ASSERT(pMath->getChild(1)->getName() == idSpeciesA);
156 
157  pReaction = pModel->getReaction(1);
158 
159  // make sure this is reaction A -> S
160  CPPUNIT_ASSERT(pReaction != NULL);
161 
162  CPPUNIT_ASSERT(pReaction->getNumReactants() == 1);
163 
164  CPPUNIT_ASSERT(pReaction->getNumProducts() == 1);
165 
166  // check if all references in the kinetic law are unmodified
167  // math element must be a multiplication of the compartments volume with
168  // a function call with three arguments
169  // the first argument is the reference to the species
170  CPPUNIT_ASSERT(pReaction->isSetKineticLaw() == true);
171 
172  pLaw = pReaction->getKineticLaw();
173 
174  CPPUNIT_ASSERT(pLaw != NULL);
175 
176  CPPUNIT_ASSERT(pLaw->isSetMath() == true);
177 
178  pMath = pLaw->getMath();
179 
180  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
181 
182  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
183 
184  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
185 
186  CPPUNIT_ASSERT(pMath->getChild(0)->getName() == pCompartment->getId());
187 
188  pMath = pMath->getChild(1);
189 
190  CPPUNIT_ASSERT(pMath != NULL);
191 
192  CPPUNIT_ASSERT(pMath->getType() == AST_FUNCTION);
193 
194  CPPUNIT_ASSERT(pMath->getNumChildren() == 3);
195 
196  pMath = pMath->getChild(0);
197 
198  CPPUNIT_ASSERT(pMath != NULL);
199 
200  CPPUNIT_ASSERT(pMath->getType() == AST_DIVIDE);
201 
202  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
203 
204  CPPUNIT_ASSERT(pMath->getChild(0) != NULL);
205 
206  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
207 
208  CPPUNIT_ASSERT(pMath->getChild(0)->getName() == idSpeciesA);
209 
210  CPPUNIT_ASSERT(pMath->getChild(1) != NULL);
211 
212  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
213 
214  CPPUNIT_ASSERT(pMath->getChild(1)->getName() == pCompartment->getId());
215 }
216 
217 const char* test000011::MODEL_STRING =
218  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
219  "<!-- generated with COPASI 4.3.25 (Debug) (http://www.copasi.org) at 2008-02-15 09:36:52 UTC -->\n"
220  "<COPASI xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.copasi.org/static/schema.xsd\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"25\">\n"
221  " <ListOfFunctions>\n"
222  " <Function key=\"Function_8\" name=\"Henri-Michaelis-Menten (irreversible)\" type=\"PreDefined\" reversible=\"false\">\n"
223  " <Expression>\n"
224  " V*substrate/(Km+substrate)\n"
225  " </Expression>\n"
226  " <ListOfParameterDescriptions>\n"
227  " <ParameterDescription key=\"FunctionParameter_41\" name=\"substrate\" order=\"0\" role=\"substrate\"/>\n"
228  " <ParameterDescription key=\"FunctionParameter_30\" name=\"Km\" order=\"1\" role=\"constant\"/>\n"
229  " <ParameterDescription key=\"FunctionParameter_45\" name=\"V\" order=\"2\" role=\"constant\"/>\n"
230  " </ListOfParameterDescriptions>\n"
231  " </Function>\n"
232  " <Function key=\"Function_13\" name=\"Mass action (irreversible)\" type=\"MassAction\" reversible=\"false\">\n"
233  " <Expression>\n"
234  " k1*PRODUCT&lt;substrate_i&gt;\n"
235  " </Expression>\n"
236  " <ListOfParameterDescriptions>\n"
237  " <ParameterDescription key=\"FunctionParameter_81\" name=\"k1\" order=\"0\" role=\"constant\"/>\n"
238  " <ParameterDescription key=\"FunctionParameter_79\" name=\"substrate\" order=\"1\" role=\"substrate\"/>\n"
239  " </ListOfParameterDescriptions>\n"
240  " </Function>\n"
241  " </ListOfFunctions>\n"
242  " <Model key=\"Model_1\" name=\"New Model\" timeUnit=\"s\" volumeUnit=\"ml\" quantityUnit=\"mmol\" type=\"deterministic\">\n"
243  " <Comment>\n"
244  " <html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:13pt;font-family:Lucida Grande\">\n"
245  "<p>Model with variable volume compartment,mmol quantity units and a reference to the species transient amount.</p>\n"
246  "<p>On export this should create an SBML file with the hasOnlySubstanceUnits flag on the species set.</p>\n"
247  "<p>The reference in the rule should by multiplied by a factor (6.023e20) and the references in the reaction should be divided by the volume.</p>\n"
248  "</body></html>\n"
249  " </Comment>\n"
250  " <ListOfCompartments>\n"
251  " <Compartment key=\"Compartment_0\" name=\"compartment\" simulationType=\"assignment\">\n"
252  " <Expression>\n"
253  " 3+4\n"
254  " </Expression>\n"
255  " </Compartment>\n"
256  " </ListOfCompartments>\n"
257  " <ListOfMetabolites>\n"
258  " <Metabolite key=\"Metabolite_0\" name=\"A\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
259  " </Metabolite>\n"
260  " <Metabolite key=\"Metabolite_1\" name=\"S\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
261  " </Metabolite>\n"
262  " </ListOfMetabolites>\n"
263  " <ListOfModelValues>\n"
264  " <ModelValue key=\"ModelValue_0\" name=\"K\" simulationType=\"assignment\">\n"
265  " <Expression>\n"
266  " &lt;CN=Root,Model=New Model,Vector=Compartments[compartment],Vector=Metabolites[A],Reference=ParticleNumber&gt;\n"
267  " </Expression>\n"
268  " </ModelValue>\n"
269  " </ListOfModelValues>\n"
270  " <ListOfReactions>\n"
271  " <Reaction key=\"Reaction_0\" name=\"reaction\" reversible=\"false\">\n"
272  " <ListOfSubstrates>\n"
273  " <Substrate metabolite=\"Metabolite_0\" stoichiometry=\"1\"/>\n"
274  " </ListOfSubstrates>\n"
275  " <ListOfConstants>\n"
276  " <Constant key=\"Parameter_93\" name=\"k1\" value=\"0.1\"/>\n"
277  " </ListOfConstants>\n"
278  " <KineticLaw function=\"Function_13\">\n"
279  " <ListOfCallParameters>\n"
280  " <CallParameter functionParameter=\"FunctionParameter_81\">\n"
281  " <SourceParameter reference=\"Parameter_93\"/>\n"
282  " </CallParameter>\n"
283  " <CallParameter functionParameter=\"FunctionParameter_79\">\n"
284  " <SourceParameter reference=\"Metabolite_0\"/>\n"
285  " </CallParameter>\n"
286  " </ListOfCallParameters>\n"
287  " </KineticLaw>\n"
288  " </Reaction>\n"
289  " <Reaction key=\"Reaction_1\" name=\"reaction_1\" reversible=\"false\">\n"
290  " <ListOfSubstrates>\n"
291  " <Substrate metabolite=\"Metabolite_0\" stoichiometry=\"1\"/>\n"
292  " </ListOfSubstrates>\n"
293  " <ListOfProducts>\n"
294  " <Product metabolite=\"Metabolite_1\" stoichiometry=\"1\"/>\n"
295  " </ListOfProducts>\n"
296  " <ListOfConstants>\n"
297  " <Constant key=\"Parameter_92\" name=\"Km\" value=\"0.1\"/>\n"
298  " <Constant key=\"Parameter_91\" name=\"V\" value=\"0.1\"/>\n"
299  " </ListOfConstants>\n"
300  " <KineticLaw function=\"Function_8\">\n"
301  " <ListOfCallParameters>\n"
302  " <CallParameter functionParameter=\"FunctionParameter_41\">\n"
303  " <SourceParameter reference=\"Metabolite_0\"/>\n"
304  " </CallParameter>\n"
305  " <CallParameter functionParameter=\"FunctionParameter_30\">\n"
306  " <SourceParameter reference=\"Parameter_92\"/>\n"
307  " </CallParameter>\n"
308  " <CallParameter functionParameter=\"FunctionParameter_45\">\n"
309  " <SourceParameter reference=\"Parameter_91\"/>\n"
310  " </CallParameter>\n"
311  " </ListOfCallParameters>\n"
312  " </KineticLaw>\n"
313  " </Reaction>\n"
314  " </ListOfReactions>\n"
315  " <StateTemplate>\n"
316  " <StateTemplateVariable objectReference=\"Model_1\"/>\n"
317  " <StateTemplateVariable objectReference=\"Metabolite_0\"/>\n"
318  " <StateTemplateVariable objectReference=\"Metabolite_1\"/>\n"
319  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
320  " <StateTemplateVariable objectReference=\"ModelValue_0\"/>\n"
321  " </StateTemplate>\n"
322  " <InitialState type=\"initialState\">\n"
323  " 0 4.215499050000001e+21 4.215499050000002e+20 7 4.215499050000001e+21\n"
324  " </InitialState>\n"
325  " </Model>\n"
326  "</COPASI>\n"
327  ;
SBMLDocument * getCurrentSBMLDocument()
#define AVOGADRO
Definition: copasi.h:25
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
static CCopasiDataModel * addDatamodel()
static void init(int argc, char *argv[], const bool &withGui=false)