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