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