COPASI API  4.16.103
test000048.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000048.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 "test000048.h"
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* test000048::pCOPASIDATAMODEL = NULL;
35 
37 {
38  // Create the root container.
39  CCopasiRootContainer::init(0, NULL, false);
40  // Create the global data model.
42 }
43 
45 {
47 }
48 
50 {
51  // load the CPS file
52  // export to SBML
53  // check the resulting SBML model
54  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
55  std::istringstream iss(test000048::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  // since the compartment is no constant all species should be
69  // exported with the hasOnlySubstanceUnits flag set to true
70  CPPUNIT_ASSERT(pModel->getNumSpecies() == 2);
71  const Species* pA = pModel->getSpecies(0);
72  CPPUNIT_ASSERT(pA != NULL);
73  CPPUNIT_ASSERT(pA->getHasOnlySubstanceUnits() == true);
74  const Species* pB = pModel->getSpecies(0);
75  CPPUNIT_ASSERT(pB != NULL);
76  CPPUNIT_ASSERT(pB->getHasOnlySubstanceUnits() == true);
77 
78  CPPUNIT_ASSERT(pModel->getNumInitialAssignments() == 1);
79  // check the initial assignment
80  const InitialAssignment* pIA = pModel->getInitialAssignment(0);
81  CPPUNIT_ASSERT(pIA != NULL);
82  CPPUNIT_ASSERT(pIA->getSymbol() == pCompartment->getId());
83  CPPUNIT_ASSERT(pIA->isSetMath() == true);
84  const ASTNode* pNode = pIA->getMath();
85  CPPUNIT_ASSERT(pNode != NULL);
86  // since the quantity unit is set to particle numbers, the expression should
87  // consists of only one node which is a reference to species A
88  CPPUNIT_ASSERT(pNode->getType() == AST_NAME);
89  CPPUNIT_ASSERT(pNode->getName() == pA->getId());
90  CPPUNIT_ASSERT(pModel->getNumRules() == 1);
91  // check the rule
92  const Rule* pRule = pModel->getRule(0);
93  CPPUNIT_ASSERT(pRule != NULL);
94  const RateRule* pRateRule = dynamic_cast<const RateRule*>(pRule);
95  CPPUNIT_ASSERT(pRateRule != NULL);
96  CPPUNIT_ASSERT(pRateRule->getVariable() == pCompartment->getId());
97  CPPUNIT_ASSERT(pRule->isSetMath() == true);
98  pNode = pRateRule->getMath();
99  CPPUNIT_ASSERT(pNode != NULL);
100  CPPUNIT_ASSERT(pNode->getType() == AST_NAME);
101  CPPUNIT_ASSERT(pNode->getName() == pA->getId());
102 }
103 
104 const char* test000048::MODEL_STRING =
105  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
106  "<!-- generated with COPASI 4.2.23++ (Debug) (http://www.copasi.org) at 2007-12-05 21:20:21 UTC -->\n"
107  "<COPASI xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.copasi.org/static/schema.xsd\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"23\">\n"
108  " <ListOfFunctions>\n"
109  " <Function key=\"Function_13\" name=\"Mass action (irreversible)\" type=\"MassAction\" reversible=\"false\">\n"
110  " <Expression>\n"
111  " k1*PRODUCT&lt;substrate_i&gt;\n"
112  " </Expression>\n"
113  " <ListOfParameterDescriptions>\n"
114  " <ParameterDescription key=\"FunctionParameter_81\" name=\"k1\" order=\"0\" role=\"constant\"/>\n"
115  " <ParameterDescription key=\"FunctionParameter_79\" name=\"substrate\" order=\"1\" role=\"substrate\"/>\n"
116  " </ListOfParameterDescriptions>\n"
117  " </Function>\n"
118  " <Function key=\"Function_44\" name=\"Objective Function\" type=\"Expression\">\n"
119  " <Expression>\n"
120  " \n"
121  " </Expression>\n"
122  " </Function>\n"
123  " </ListOfFunctions>\n"
124  " <Model key=\"Model_1\" name=\"New Model\" timeUnit=\"s\" volumeUnit=\"ml\" quantityUnit=\"#\" type=\"deterministic\">\n"
125  " <Comment>\n"
126  " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
127  " \n"
128  " </body>\n"
129  " </Comment>\n"
130  " <ListOfCompartments>\n"
131  " <Compartment key=\"Compartment_0\" name=\"compartment\" simulationType=\"ode\">\n"
132  " <Expression>\n"
133  " &lt;CN=Root,Model=New Model,Vector=Compartments[compartment],Vector=Metabolites[A],Reference=ParticleNumber&gt;\n"
134  " </Expression>\n"
135  " <InitialExpression>\n"
136  " &lt;CN=Root,Model=New Model,Vector=Compartments[compartment],Vector=Metabolites[A],Reference=InitialParticleNumber&gt;\n"
137  " </InitialExpression>\n"
138  " </Compartment>\n"
139  " </ListOfCompartments>\n"
140  " <ListOfMetabolites>\n"
141  " <Metabolite key=\"Metabolite_0\" name=\"A\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
142  " </Metabolite>\n"
143  " <Metabolite key=\"Metabolite_1\" name=\"B\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
144  " </Metabolite>\n"
145  " </ListOfMetabolites>\n"
146  " <ListOfReactions>\n"
147  " <Reaction key=\"Reaction_0\" name=\"reaction\" reversible=\"false\">\n"
148  " <ListOfSubstrates>\n"
149  " <Substrate metabolite=\"Metabolite_0\" stoichiometry=\"1\"/>\n"
150  " </ListOfSubstrates>\n"
151  " <ListOfProducts>\n"
152  " <Product metabolite=\"Metabolite_1\" stoichiometry=\"1\"/>\n"
153  " </ListOfProducts>\n"
154  " <ListOfConstants>\n"
155  " <Constant key=\"Parameter_103\" name=\"k1\" value=\"0.1\"/>\n"
156  " </ListOfConstants>\n"
157  " <KineticLaw function=\"Function_13\">\n"
158  " <ListOfCallParameters>\n"
159  " <CallParameter functionParameter=\"FunctionParameter_81\">\n"
160  " <SourceParameter reference=\"Parameter_103\"/>\n"
161  " </CallParameter>\n"
162  " <CallParameter functionParameter=\"FunctionParameter_79\">\n"
163  " <SourceParameter reference=\"Metabolite_0\"/>\n"
164  " </CallParameter>\n"
165  " </ListOfCallParameters>\n"
166  " </KineticLaw>\n"
167  " </Reaction>\n"
168  " </ListOfReactions>\n"
169  " <StateTemplate>\n"
170  " <StateTemplateVariable objectReference=\"Model_1\"/>\n"
171  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
172  " <StateTemplateVariable objectReference=\"Metabolite_0\"/>\n"
173  " <StateTemplateVariable objectReference=\"Metabolite_1\"/>\n"
174  " </StateTemplate>\n"
175  " <InitialState type=\"initialState\">\n"
176  " 0 1000 1000 100\n"
177  " </InitialState>\n"
178  " </Model>\n"
179  "</COPASI>\n"
180  ;
SBMLDocument * getCurrentSBMLDocument()
void setUp()
Definition: test000048.cpp:36
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
void test_bug919()
Definition: test000048.cpp:49
void tearDown()
Definition: test000048.cpp:44
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000048.h:32
static CCopasiDataModel * addDatamodel()
static void init(int argc, char *argv[], const bool &withGui=false)
static const char * MODEL_STRING
Definition: test000048.h:31