COPASI API  4.16.103
test000009.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000009.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 "test000009.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* test000009::pCOPASIDATAMODEL = NULL;
35 
36 void test000009::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 test000009::tearDown()
45 {
47 }
48 
49 void test000009::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(test000009::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->getNumRules() == 2);
75  // there are two rules, one is the rule for the compartment
76  AssignmentRule* pRule = dynamic_cast<AssignmentRule*>(pModel->getRule(0));
77  CPPUNIT_ASSERT(pRule != NULL);
78  CPPUNIT_ASSERT(pModel->getNumParameters() == 1);
79  Parameter* pParameter = pModel->getParameter(0);
80  CPPUNIT_ASSERT(pParameter != NULL);
81 
82  if (pRule->getVariable() != pParameter->getId())
83  {
84  pRule = dynamic_cast<AssignmentRule*>(pModel->getRule(1));
85  }
86 
87  CPPUNIT_ASSERT(pRule->getVariable() == pParameter->getId());
88  const ASTNode* pMath = pRule->getMath();
89  CPPUNIT_ASSERT(pMath != NULL);
90  // the expression should be the species divided by the volume
91  CPPUNIT_ASSERT(pMath->getType() == AST_DIVIDE);
92  CPPUNIT_ASSERT(pMath->getChild(0) != NULL);
93  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
94  CPPUNIT_ASSERT(pMath->getChild(0)->getName() == pSpecies->getId());
95  CPPUNIT_ASSERT(pMath->getChild(1) != NULL);
96  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
97  CPPUNIT_ASSERT(pMath->getChild(1)->getName() == pCompartment->getId());
98  CPPUNIT_ASSERT(pModel->getNumReactions() == 2);
99  Reaction* pReaction = pModel->getReaction(0);
100  // make sure this is reaction A ->
101  CPPUNIT_ASSERT(pReaction != NULL);
102  CPPUNIT_ASSERT(pReaction->getNumReactants() == 1);
103  CPPUNIT_ASSERT(pReaction->getNumProducts() == 0);
104  // check if all references in the kinetic law are unmodified
105  // math element must be a multiplication of the mass action term by
106  // the compartment volume
107  // the mass action term is a multiplication of the parameter node by
108  // the species node
109  // the code that multiplies the reaction by the compartments volume
110  // recognizes the division of the species by the compartment and cancels
111  // those two
112  CPPUNIT_ASSERT(pReaction->isSetKineticLaw() == true);
113  KineticLaw* pLaw = pReaction->getKineticLaw();
114  CPPUNIT_ASSERT(pLaw != NULL);
115  CPPUNIT_ASSERT(pLaw->isSetMath() == true);
116  pMath = pLaw->getMath();
117  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
118  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
119  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
120  CPPUNIT_ASSERT(pMath->getChild(0)->getName() == std::string("k1"));
121  CPPUNIT_ASSERT(pMath->getChild(1) != NULL);
122  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
123  CPPUNIT_ASSERT(pMath->getChild(1)->getName() == idSpeciesA);
124 
125  pReaction = pModel->getReaction(1);
126  // make sure this is reaction A -> S
127  CPPUNIT_ASSERT(pReaction != NULL);
128  CPPUNIT_ASSERT(pReaction->getNumReactants() == 1);
129  CPPUNIT_ASSERT(pReaction->getNumProducts() == 1);
130  // check if all references in the kinetic law are unmodified
131  // math element must be a multiplication of the compartments volume with
132  // a function call with three arguments
133  // the first argument is the reference to the species
134  CPPUNIT_ASSERT(pReaction->isSetKineticLaw() == true);
135  pLaw = pReaction->getKineticLaw();
136  CPPUNIT_ASSERT(pLaw != NULL);
137  CPPUNIT_ASSERT(pLaw->isSetMath() == true);
138  pMath = pLaw->getMath();
139  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
140  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
141  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
142  CPPUNIT_ASSERT(pMath->getChild(0)->getName() == pCompartment->getId());
143  pMath = pMath->getChild(1);
144  CPPUNIT_ASSERT(pMath != NULL);
145  CPPUNIT_ASSERT(pMath->getType() == AST_FUNCTION);
146  CPPUNIT_ASSERT(pMath->getNumChildren() == 3);
147  pMath = pMath->getChild(0);
148  CPPUNIT_ASSERT(pMath != NULL);
149  CPPUNIT_ASSERT(pMath->getType() == AST_DIVIDE);
150  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
151  CPPUNIT_ASSERT(pMath->getChild(0) != NULL);
152  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
153  CPPUNIT_ASSERT(pMath->getChild(0)->getName() == idSpeciesA);
154  CPPUNIT_ASSERT(pMath->getChild(1) != NULL);
155  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
156  CPPUNIT_ASSERT(pMath->getChild(1)->getName() == pCompartment->getId());
157 }
158 
159 const char* test000009::MODEL_STRING =
160  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
161  "<!-- generated with COPASI 4.3.25 (Debug) (http://www.copasi.org) at 2008-02-15 09:34:28 UTC -->\n"
162  "<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"
163  " <ListOfFunctions>\n"
164  " <Function key=\"Function_8\" name=\"Henri-Michaelis-Menten (irreversible)\" type=\"PreDefined\" reversible=\"false\">\n"
165  " <Expression>\n"
166  " V*substrate/(Km+substrate)\n"
167  " </Expression>\n"
168  " <ListOfParameterDescriptions>\n"
169  " <ParameterDescription key=\"FunctionParameter_41\" name=\"substrate\" order=\"0\" role=\"substrate\"/>\n"
170  " <ParameterDescription key=\"FunctionParameter_30\" name=\"Km\" order=\"1\" role=\"constant\"/>\n"
171  " <ParameterDescription key=\"FunctionParameter_45\" name=\"V\" order=\"2\" role=\"constant\"/>\n"
172  " </ListOfParameterDescriptions>\n"
173  " </Function>\n"
174  " <Function key=\"Function_13\" name=\"Mass action (irreversible)\" type=\"MassAction\" reversible=\"false\">\n"
175  " <Expression>\n"
176  " k1*PRODUCT&lt;substrate_i&gt;\n"
177  " </Expression>\n"
178  " <ListOfParameterDescriptions>\n"
179  " <ParameterDescription key=\"FunctionParameter_81\" name=\"k1\" order=\"0\" role=\"constant\"/>\n"
180  " <ParameterDescription key=\"FunctionParameter_79\" name=\"substrate\" order=\"1\" role=\"substrate\"/>\n"
181  " </ListOfParameterDescriptions>\n"
182  " </Function>\n"
183  " </ListOfFunctions>\n"
184  " <Model key=\"Model_1\" name=\"New Model\" timeUnit=\"s\" volumeUnit=\"ml\" quantityUnit=\"mmol\" type=\"deterministic\">\n"
185  " <Comment>\n"
186  " <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"
187  "<p>Model with variable volume compartment, mmol quantity units and a reference to the species transient concentration.</p>\n"
188  "<p>On export this should create an SBML file with the hasOnlySubstanceUnits flag on the species set. </p>\n"
189  "<p>The reference in the rule should be divided by the volume. The references in the reactions should also be divided by the volume.</p>\n"
190  "</body></html>\n"
191  " </Comment>\n"
192  " <ListOfCompartments>\n"
193  " <Compartment key=\"Compartment_0\" name=\"compartment\" simulationType=\"assignment\">\n"
194  " <Expression>\n"
195  " 3+4\n"
196  " </Expression>\n"
197  " </Compartment>\n"
198  " </ListOfCompartments>\n"
199  " <ListOfMetabolites>\n"
200  " <Metabolite key=\"Metabolite_0\" name=\"A\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
201  " </Metabolite>\n"
202  " <Metabolite key=\"Metabolite_1\" name=\"S\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
203  " </Metabolite>\n"
204  " </ListOfMetabolites>\n"
205  " <ListOfModelValues>\n"
206  " <ModelValue key=\"ModelValue_0\" name=\"K\" simulationType=\"assignment\">\n"
207  " <Expression>\n"
208  " &lt;CN=Root,Model=New Model,Vector=Compartments[compartment],Vector=Metabolites[A],Reference=Concentration&gt;\n"
209  " </Expression>\n"
210  " </ModelValue>\n"
211  " </ListOfModelValues>\n"
212  " <ListOfReactions>\n"
213  " <Reaction key=\"Reaction_0\" name=\"reaction\" reversible=\"false\">\n"
214  " <ListOfSubstrates>\n"
215  " <Substrate metabolite=\"Metabolite_0\" stoichiometry=\"1\"/>\n"
216  " </ListOfSubstrates>\n"
217  " <ListOfConstants>\n"
218  " <Constant key=\"Parameter_93\" name=\"k1\" value=\"0.1\"/>\n"
219  " </ListOfConstants>\n"
220  " <KineticLaw function=\"Function_13\">\n"
221  " <ListOfCallParameters>\n"
222  " <CallParameter functionParameter=\"FunctionParameter_81\">\n"
223  " <SourceParameter reference=\"Parameter_93\"/>\n"
224  " </CallParameter>\n"
225  " <CallParameter functionParameter=\"FunctionParameter_79\">\n"
226  " <SourceParameter reference=\"Metabolite_0\"/>\n"
227  " </CallParameter>\n"
228  " </ListOfCallParameters>\n"
229  " </KineticLaw>\n"
230  " </Reaction>\n"
231  " <Reaction key=\"Reaction_1\" name=\"reaction_1\" reversible=\"false\">\n"
232  " <ListOfSubstrates>\n"
233  " <Substrate metabolite=\"Metabolite_0\" stoichiometry=\"1\"/>\n"
234  " </ListOfSubstrates>\n"
235  " <ListOfProducts>\n"
236  " <Product metabolite=\"Metabolite_1\" stoichiometry=\"1\"/>\n"
237  " </ListOfProducts>\n"
238  " <ListOfConstants>\n"
239  " <Constant key=\"Parameter_92\" name=\"Km\" value=\"0.1\"/>\n"
240  " <Constant key=\"Parameter_91\" name=\"V\" value=\"0.1\"/>\n"
241  " </ListOfConstants>\n"
242  " <KineticLaw function=\"Function_8\">\n"
243  " <ListOfCallParameters>\n"
244  " <CallParameter functionParameter=\"FunctionParameter_41\">\n"
245  " <SourceParameter reference=\"Metabolite_0\"/>\n"
246  " </CallParameter>\n"
247  " <CallParameter functionParameter=\"FunctionParameter_30\">\n"
248  " <SourceParameter reference=\"Parameter_92\"/>\n"
249  " </CallParameter>\n"
250  " <CallParameter functionParameter=\"FunctionParameter_45\">\n"
251  " <SourceParameter reference=\"Parameter_91\"/>\n"
252  " </CallParameter>\n"
253  " </ListOfCallParameters>\n"
254  " </KineticLaw>\n"
255  " </Reaction>\n"
256  " </ListOfReactions>\n"
257  " <StateTemplate>\n"
258  " <StateTemplateVariable objectReference=\"Model_1\"/>\n"
259  " <StateTemplateVariable objectReference=\"Metabolite_0\"/>\n"
260  " <StateTemplateVariable objectReference=\"Metabolite_1\"/>\n"
261  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
262  " <StateTemplateVariable objectReference=\"ModelValue_0\"/>\n"
263  " </StateTemplate>\n"
264  " <InitialState type=\"initialState\">\n"
265  " 0 4.215499050000001e+21 4.215499050000002e+20 7 1\n"
266  " </InitialState>\n"
267  " </Model>\n"
268  "</COPASI>\n"
269  ;
SBMLDocument * getCurrentSBMLDocument()
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)