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