COPASI API  4.16.103
test000008.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000008.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 "test000008.hpp"
20 
21 #include <sstream>
22 #include "utilities.hpp"
24 #include "copasi/model/CModel.h"
25 
26 #include "sbml/SBMLDocument.h"
27 #include "sbml/Model.h"
28 #include "sbml/Rule.h"
29 #include "sbml/Species.h"
30 #include "sbml/Parameter.h"
31 #include "sbml/math/ASTNode.h"
32 
34 
35 CCopasiDataModel* test000008::pCOPASIDATAMODEL = NULL;
36 
37 void test000008::setUp()
38 {
39  // Create the root container.
40  CCopasiRootContainer::init(0, NULL, false);
41  // Create the global data model.
42  pCOPASIDATAMODEL = CCopasiRootContainer::addDatamodel();
43 }
44 
45 void test000008::tearDown()
46 {
48 }
49 
50 void test000008::test_references_to_species()
51 {
52  // load the CPS file
53  // export to SBML
54  // check the resulting SBML model
55  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
56  std::istringstream iss(test000008::MODEL_STRING);
57  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
58  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
59  CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, 2, 3).empty() == false);
60  SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
61  CPPUNIT_ASSERT(pDocument != NULL);
62  Model* pModel = pDocument->getModel();
63  CPPUNIT_ASSERT(pModel != NULL);
64  // assert that there is only one compartment and
65  // assert the compartment is constant
66  CPPUNIT_ASSERT(pModel->getNumCompartments() == 1);
67  Compartment* pCompartment = pModel->getCompartment(0);
68  CPPUNIT_ASSERT(pCompartment->getConstant() == true);
69  CPPUNIT_ASSERT(pModel->getNumSpecies() == 2);
70  Species* pSpecies = pModel->getSpecies(1);
71  CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() == false);
72  pSpecies = pModel->getSpecies(0);
73  std::string idSpeciesA = pSpecies->getId();
74  CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() == false);
75  CPPUNIT_ASSERT(pModel->getNumInitialAssignments() == 1);
76  InitialAssignment* pAssignment = pModel->getInitialAssignment(0);
77  CPPUNIT_ASSERT(pAssignment != NULL);
78  CPPUNIT_ASSERT(pModel->getNumParameters() == 1);
79  Parameter* pParameter = pModel->getParameter(0);
80  CPPUNIT_ASSERT(pParameter != NULL);
81  CPPUNIT_ASSERT(pAssignment->getSymbol() == pParameter->getId());
82  const ASTNode* pMath = pAssignment->getMath();
83  CPPUNIT_ASSERT(pMath != NULL);
84  // the mathematical expression should be a multiplication of the species
85  // and the compartment
86  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
87  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
88  CPPUNIT_ASSERT(pMath->getChild(0) != NULL);
89  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
90  CPPUNIT_ASSERT(pMath->getChild(0)->getName() == pSpecies->getId());
91  CPPUNIT_ASSERT(pMath->getChild(1) != NULL);
92  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
93  CPPUNIT_ASSERT(pMath->getChild(1)->getName() == pCompartment->getId());
94  CPPUNIT_ASSERT(pModel->getNumReactions() == 2);
95  Reaction* pReaction = pModel->getReaction(0);
96  // make sure this is reaction A ->
97  CPPUNIT_ASSERT(pReaction != NULL);
98  CPPUNIT_ASSERT(pReaction->getNumReactants() == 1);
99  CPPUNIT_ASSERT(pReaction->getNumProducts() == 0);
100  // check if all references in the kinetic law are unmodified
101  // math element must be a multiplication of the mass action term by
102  // the compartment volume
103  // the mass action term is a multiplication of the parameter node by
104  // the species node
105  CPPUNIT_ASSERT(pReaction->isSetKineticLaw() == true);
106  KineticLaw* pLaw = pReaction->getKineticLaw();
107  CPPUNIT_ASSERT(pLaw != NULL);
108  CPPUNIT_ASSERT(pLaw->isSetMath() == true);
109  pMath = pLaw->getMath();
110  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
111  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
112  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
113  CPPUNIT_ASSERT(pMath->getChild(0)->getName() == pCompartment->getId());
114  pMath = pMath->getChild(1);
115  CPPUNIT_ASSERT(pMath != NULL);
116  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
117  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
118  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
119  CPPUNIT_ASSERT(pMath->getChild(0)->getName() == std::string("k1"));
120  pMath = pMath->getChild(1);
121  CPPUNIT_ASSERT(pMath != NULL);
122  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
123  CPPUNIT_ASSERT(pMath->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_NAME);
150  CPPUNIT_ASSERT(pMath->getName() == idSpeciesA);
151 }
152 
153 const char* test000008::MODEL_STRING =
154  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
155  "<!-- generated with COPASI 4.3.25 (Debug) (http://www.copasi.org) at 2008-02-15 09:32:34 UTC -->\n"
156  "<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"
157  " <ListOfFunctions>\n"
158  " <Function key=\"Function_8\" name=\"Henri-Michaelis-Menten (irreversible)\" type=\"PreDefined\" reversible=\"false\">\n"
159  " <Expression>\n"
160  " V*substrate/(Km+substrate)\n"
161  " </Expression>\n"
162  " <ListOfParameterDescriptions>\n"
163  " <ParameterDescription key=\"FunctionParameter_41\" name=\"substrate\" order=\"0\" role=\"substrate\"/>\n"
164  " <ParameterDescription key=\"FunctionParameter_30\" name=\"Km\" order=\"1\" role=\"constant\"/>\n"
165  " <ParameterDescription key=\"FunctionParameter_45\" name=\"V\" order=\"2\" role=\"constant\"/>\n"
166  " </ListOfParameterDescriptions>\n"
167  " </Function>\n"
168  " <Function key=\"Function_13\" name=\"Mass action (irreversible)\" type=\"MassAction\" reversible=\"false\">\n"
169  " <Expression>\n"
170  " k1*PRODUCT&lt;substrate_i&gt;\n"
171  " </Expression>\n"
172  " <ListOfParameterDescriptions>\n"
173  " <ParameterDescription key=\"FunctionParameter_81\" name=\"k1\" order=\"0\" role=\"constant\"/>\n"
174  " <ParameterDescription key=\"FunctionParameter_79\" name=\"substrate\" order=\"1\" role=\"substrate\"/>\n"
175  " </ListOfParameterDescriptions>\n"
176  " </Function>\n"
177  " </ListOfFunctions>\n"
178  " <Model key=\"Model_1\" name=\"New Model\" timeUnit=\"s\" volumeUnit=\"ml\" quantityUnit=\"#\" type=\"deterministic\">\n"
179  " <Comment>\n"
180  " <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"
181  "<p>Model with constant volume compartment,# quantity units and a reference to the species initial amount.</p>\n"
182  "<p>On export this should create an SBML file with the hasOnlySubstanceUnits flag on the species unset.</p>\n"
183  "<p>The reference to the species in the initial assignment should be multiplied by the volume of the compartment.</p>\n"
184  "</body></html>\n"
185  " </Comment>\n"
186  " <ListOfCompartments>\n"
187  " <Compartment key=\"Compartment_0\" name=\"compartment\" simulationType=\"fixed\">\n"
188  " </Compartment>\n"
189  " </ListOfCompartments>\n"
190  " <ListOfMetabolites>\n"
191  " <Metabolite key=\"Metabolite_0\" name=\"A\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
192  " </Metabolite>\n"
193  " <Metabolite key=\"Metabolite_1\" name=\"S\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
194  " </Metabolite>\n"
195  " </ListOfMetabolites>\n"
196  " <ListOfModelValues>\n"
197  " <ModelValue key=\"ModelValue_0\" name=\"K\" simulationType=\"fixed\">\n"
198  " <InitialExpression>\n"
199  " &lt;CN=Root,Model=New Model,Vector=Compartments[compartment],Vector=Metabolites[A],Reference=InitialParticleNumber&gt;\n"
200  " </InitialExpression>\n"
201  " </ModelValue>\n"
202  " </ListOfModelValues>\n"
203  " <ListOfReactions>\n"
204  " <Reaction key=\"Reaction_0\" name=\"reaction\" reversible=\"false\">\n"
205  " <ListOfSubstrates>\n"
206  " <Substrate metabolite=\"Metabolite_0\" stoichiometry=\"1\"/>\n"
207  " </ListOfSubstrates>\n"
208  " <ListOfConstants>\n"
209  " <Constant key=\"Parameter_93\" name=\"k1\" value=\"0.1\"/>\n"
210  " </ListOfConstants>\n"
211  " <KineticLaw function=\"Function_13\">\n"
212  " <ListOfCallParameters>\n"
213  " <CallParameter functionParameter=\"FunctionParameter_81\">\n"
214  " <SourceParameter reference=\"Parameter_93\"/>\n"
215  " </CallParameter>\n"
216  " <CallParameter functionParameter=\"FunctionParameter_79\">\n"
217  " <SourceParameter reference=\"Metabolite_0\"/>\n"
218  " </CallParameter>\n"
219  " </ListOfCallParameters>\n"
220  " </KineticLaw>\n"
221  " </Reaction>\n"
222  " <Reaction key=\"Reaction_1\" name=\"reaction_1\" reversible=\"false\">\n"
223  " <ListOfSubstrates>\n"
224  " <Substrate metabolite=\"Metabolite_0\" stoichiometry=\"1\"/>\n"
225  " </ListOfSubstrates>\n"
226  " <ListOfProducts>\n"
227  " <Product metabolite=\"Metabolite_1\" stoichiometry=\"1\"/>\n"
228  " </ListOfProducts>\n"
229  " <ListOfConstants>\n"
230  " <Constant key=\"Parameter_92\" name=\"Km\" value=\"0.1\"/>\n"
231  " <Constant key=\"Parameter_91\" name=\"V\" value=\"0.1\"/>\n"
232  " </ListOfConstants>\n"
233  " <KineticLaw function=\"Function_8\">\n"
234  " <ListOfCallParameters>\n"
235  " <CallParameter functionParameter=\"FunctionParameter_41\">\n"
236  " <SourceParameter reference=\"Metabolite_0\"/>\n"
237  " </CallParameter>\n"
238  " <CallParameter functionParameter=\"FunctionParameter_30\">\n"
239  " <SourceParameter reference=\"Parameter_92\"/>\n"
240  " </CallParameter>\n"
241  " <CallParameter functionParameter=\"FunctionParameter_45\">\n"
242  " <SourceParameter reference=\"Parameter_91\"/>\n"
243  " </CallParameter>\n"
244  " </ListOfCallParameters>\n"
245  " </KineticLaw>\n"
246  " </Reaction>\n"
247  " </ListOfReactions>\n"
248  " <StateTemplate>\n"
249  " <StateTemplateVariable objectReference=\"Model_1\"/>\n"
250  " <StateTemplateVariable objectReference=\"Metabolite_0\"/>\n"
251  " <StateTemplateVariable objectReference=\"Metabolite_1\"/>\n"
252  " <StateTemplateVariable objectReference=\"ModelValue_0\"/>\n"
253  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
254  " </StateTemplate>\n"
255  " <InitialState type=\"initialState\">\n"
256  " 0 1 0.1 1 1\n"
257  " </InitialState>\n"
258  " </Model>\n"
259  "</COPASI>\n"
260  ;
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)