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