COPASI API  4.16.103
test000098.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000098.cpp,v $
3 // $Revision: 1.2 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/05/24 16:32:32 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 #include "test000098.h"
15 
16 #include <sstream>
17 #include <fstream>
18 #include "utilities.hpp"
19 
20 #include "sbml/SBMLDocument.h"
21 #include "sbml/Model.h"
22 #include "sbml/xml/XMLNode.h"
23 
26 #include "copasi/model/CModel.h"
28 #include "copasi/model/CMetab.h"
30 #include "copasi/model/CReaction.h"
31 #include "copasi/model/CEvent.h"
32 
34 {
35  // Create the root container.
36  CCopasiRootContainer::init(0, NULL, false);
38 }
39 
41 {
43 }
44 
45 
46 // tests whether we are importing notes on all elemnts
48 {
49  CPPUNIT_ASSERT(pDataModel != NULL);
50  // import the file and check if we find all the notes
52  // check if all the elements have notes
53  const CModel* pModel = pDataModel->getModel();
54  CPPUNIT_ASSERT(pModel != NULL);
55  std::string notes = pModel->getNotes();
56  CPPUNIT_ASSERT(!notes.empty());
57  CPPUNIT_ASSERT(notes.find("Simple note on model") != std::string::npos);
58  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
59  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1);
60  CPPUNIT_ASSERT(pModel->getReactions().size() == 1);
61  CPPUNIT_ASSERT(pModel->getModelValues().size() == 1);
62  CPPUNIT_ASSERT(pModel->getEvents().size() == 1);
63  // compartment
64  const CCompartment* pCompartment = pModel->getCompartments()[0];
65  CPPUNIT_ASSERT(pCompartment != NULL);
66  notes = pCompartment->getNotes();
67  CPPUNIT_ASSERT(!notes.empty());
68  CPPUNIT_ASSERT(notes.find("Simple note on compartment") != std::string::npos);
69  // species
70  const CMetab* pMetab = pModel->getMetabolites()[0];
71  CPPUNIT_ASSERT(pMetab != NULL);
72  notes = pMetab->getNotes();
73  CPPUNIT_ASSERT(!notes.empty());
74  CPPUNIT_ASSERT(notes.find("Simple note on species") != std::string::npos);
75  // reaction
76  const CReaction* pReaction = pModel->getReactions()[0];
77  CPPUNIT_ASSERT(pReaction != NULL);
78  notes = pReaction->getNotes();
79  CPPUNIT_ASSERT(!notes.empty());
80  CPPUNIT_ASSERT(notes.find("Simple note on reaction") != std::string::npos);
81  // parameter
82  const CModelValue* pModelValue = pModel->getModelValues()[0];
83  CPPUNIT_ASSERT(pModelValue != NULL);
84  notes = pModelValue->getNotes();
85  CPPUNIT_ASSERT(!notes.empty());
86  CPPUNIT_ASSERT(notes.find("Simple note on parameter") != std::string::npos);
87  // event
88  const CEvent* pEvent = pModel->getEvents()[0];
89  CPPUNIT_ASSERT(pEvent != NULL);
90  notes = pEvent->getNotes();
91  CPPUNIT_ASSERT(!notes.empty());
92  CPPUNIT_ASSERT(notes.find("Simple note on event") != std::string::npos);
93 }
94 
95 // tests whether we are importing global render information
97 {
98  CPPUNIT_ASSERT(pDataModel != NULL);
99  std::istringstream iss(test000098::CPS_MODEL_1);
100  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
101  std::string s;
102 
103  try
104  {
105  s = pDataModel->exportSBMLToString(NULL, 2, 1);
106  }
107  catch (...)
108  {
109  CPPUNIT_ASSERT(false);
110  }
111 
112  CPPUNIT_ASSERT(!s.empty());
113  SBMLReader reader;
114  SBMLDocument* pSBMLDocument = NULL;
115 
116  try
117  {
118  pSBMLDocument = reader.readSBMLFromString(s);
119  }
120  catch (...)
121  {
122  CPPUNIT_ASSERT(false);
123  }
124 
125  CPPUNIT_ASSERT(pSBMLDocument != NULL);
126  Model* pModel = pSBMLDocument->getModel();
127  CPPUNIT_ASSERT(pModel != NULL);
128  CPPUNIT_ASSERT(pModel->isSetNotes() == true);
129  std::string notes = pModel->getNotesString();
130  CPPUNIT_ASSERT(!notes.empty());
131  CPPUNIT_ASSERT(notes.find("Simple note on model") != std::string::npos);
132 
133  CPPUNIT_ASSERT(pModel->getNumCompartments() == 1);
134  CPPUNIT_ASSERT(pModel->getNumSpecies() == 1);
135  CPPUNIT_ASSERT(pModel->getNumParameters() == 1);
136  CPPUNIT_ASSERT(pModel->getNumReactions() == 1);
137  CPPUNIT_ASSERT(pModel->getNumEvents() == 1);
138  // compartment
139  SBase* pObject = pModel->getCompartment(0);
140  CPPUNIT_ASSERT(pObject != NULL);
141  CPPUNIT_ASSERT(pObject->isSetNotes() == true);
142  notes = pObject->getNotesString();
143  CPPUNIT_ASSERT(!notes.empty());
144  CPPUNIT_ASSERT(notes.find("Simple note on compartment") != std::string::npos);
145  // species
146  pObject = pModel->getSpecies(0);
147  CPPUNIT_ASSERT(pObject != NULL);
148  CPPUNIT_ASSERT(pObject->isSetNotes() == true);
149  notes = pObject->getNotesString();
150  CPPUNIT_ASSERT(!notes.empty());
151  CPPUNIT_ASSERT(notes.find("Simple note on species") != std::string::npos);
152  // parameter
153  pObject = pModel->getParameter(0);
154  CPPUNIT_ASSERT(pObject != NULL);
155  CPPUNIT_ASSERT(pObject->isSetNotes() == true);
156  notes = pObject->getNotesString();
157  CPPUNIT_ASSERT(!notes.empty());
158  CPPUNIT_ASSERT(notes.find("Simple note on parameter") != std::string::npos);
159  // reaction
160  pObject = pModel->getReaction(0);
161  CPPUNIT_ASSERT(pObject != NULL);
162  CPPUNIT_ASSERT(pObject->isSetNotes() == true);
163  notes = pObject->getNotesString();
164  CPPUNIT_ASSERT(!notes.empty());
165  CPPUNIT_ASSERT(notes.find("Simple note on reaction") != std::string::npos);
166  // event
167  pObject = pModel->getEvent(0);
168  CPPUNIT_ASSERT(pObject != NULL);
169  CPPUNIT_ASSERT(pObject->isSetNotes() == true);
170  notes = pObject->getNotesString();
171  CPPUNIT_ASSERT(!notes.empty());
172  CPPUNIT_ASSERT(notes.find("Simple note on event") != std::string::npos);
173 
174 
175 }
176 
177 
178 
179 
180 
181 // SBML model with local render information
182 const char* test000098::SBML_MODEL_1 =
183  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
184  "<!-- Created by COPASI version 4.6.34 (Debug) on 2011-05-12 15:45 with libSBML version 4.2.0. -->\n"
185  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version4\" level=\"2\" version=\"4\">\n"
186  " <model metaid=\"COPASI1\" id=\"Model_1\" name=\"New Model\">\n"
187  " <notes>\n"
188  " <body xmlns=\"http://www.w3.org/1999/xhtml\">Simple note on model</body>\n"
189  " </notes>\n"
190  " <listOfFunctionDefinitions>\n"
191  " <functionDefinition id=\"function_1\" name=\"Constant flux (irreversible)\">\n"
192  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
193  " <lambda>\n"
194  " <bvar>\n"
195  " <ci> v </ci>\n"
196  " </bvar>\n"
197  " <ci> v </ci>\n"
198  " </lambda>\n"
199  " </math>\n"
200  " </functionDefinition>\n"
201  " </listOfFunctionDefinitions>\n"
202  " <listOfUnitDefinitions>\n"
203  " <unitDefinition id=\"volume\" name=\"volume\">\n"
204  " <listOfUnits>\n"
205  " <unit kind=\"litre\" scale=\"-3\"/>\n"
206  " </listOfUnits>\n"
207  " </unitDefinition>\n"
208  " <unitDefinition id=\"substance\" name=\"substance\">\n"
209  " <listOfUnits>\n"
210  " <unit kind=\"mole\" scale=\"-3\"/>\n"
211  " </listOfUnits>\n"
212  " </unitDefinition>\n"
213  " </listOfUnitDefinitions>\n"
214  " <listOfCompartments>\n"
215  " <compartment metaid=\"COPASI2\" id=\"compartment_1\" name=\"compartment_1\" size=\"1\">\n"
216  " <notes>\n"
217  " <body xmlns=\"http://www.w3.org/1999/xhtml\">Simple note on compartment</body>\n"
218  " </notes>\n"
219  " </compartment>\n"
220  " </listOfCompartments>\n"
221  " <listOfSpecies>\n"
222  " <species metaid=\"COPASI3\" id=\"species_1\" name=\"species_1\" compartment=\"compartment_1\" initialConcentration=\"1\">\n"
223  " <notes>\n"
224  " <body xmlns=\"http://www.w3.org/1999/xhtml\">Simple note on species</body>\n"
225  " </notes>\n"
226  " </species>\n"
227  " </listOfSpecies>\n"
228  " <listOfParameters>\n"
229  " <parameter metaid=\"COPASI4\" id=\"parameter_1\" name=\"quantity_1\" value=\"0\" constant=\"false\">\n"
230  " <notes>\n"
231  " <body xmlns=\"http://www.w3.org/1999/xhtml\">Simple note on parameter</body>\n"
232  " </notes>\n"
233  " </parameter>\n"
234  " </listOfParameters>\n"
235  " <listOfReactions>\n"
236  " <reaction metaid=\"COPASI6\" id=\"reaction_1\" name=\"reaction_1\" reversible=\"false\">\n"
237  " <notes>\n"
238  " <body xmlns=\"http://www.w3.org/1999/xhtml\">Simple note on reaction</body>\n"
239  " </notes>\n"
240  " <listOfProducts>\n"
241  " <speciesReference species=\"species_1\"/>\n"
242  " </listOfProducts>\n"
243  " <kineticLaw>\n"
244  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
245  " <apply>\n"
246  " <times/>\n"
247  " <ci> compartment_1 </ci>\n"
248  " <apply>\n"
249  " <ci> function_1 </ci>\n"
250  " <ci> v </ci>\n"
251  " </apply>\n"
252  " </apply>\n"
253  " </math>\n"
254  " <listOfParameters>\n"
255  " <parameter id=\"v\" name=\"v\" value=\"0.1\"/>\n"
256  " </listOfParameters>\n"
257  " </kineticLaw>\n"
258  " </reaction>\n"
259  " </listOfReactions>\n"
260  " <listOfEvents>\n"
261  " <event metaid=\"COPASI5\" id=\"event_1\" name=\"event_1\">\n"
262  " <notes>\n"
263  " <body xmlns=\"http://www.w3.org/1999/xhtml\">Simple note on event</body>\n"
264  " </notes>\n"
265  " <trigger>\n"
266  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
267  " <apply>\n"
268  " <gt/>\n"
269  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/time\"> time </csymbol>\n"
270  " <cn> 3 </cn>\n"
271  " </apply>\n"
272  " </math>\n"
273  " </trigger>\n"
274  " <listOfEventAssignments>\n"
275  " <eventAssignment variable=\"parameter_1\">\n"
276  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
277  " <cn> 3 </cn>\n"
278  " </math>\n"
279  " </eventAssignment>\n"
280  " </listOfEventAssignments>\n"
281  " </event>\n"
282  " </listOfEvents>\n"
283  " </model>\n"
284  "</sbml>\n"
285  ;
286 
287 // COPASI model with local render information
288 const char* test000098::CPS_MODEL_1 =
289  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
290  "<!-- generated with COPASI 4.6.34 (Debug) (http://www.copasi.org) at 2011-05-12 13:45:33 UTC -->\n"
291  "<?oxygen RNGSchema=\"http://www.copasi.org/static/schema/CopasiML.rng\" type=\"xml\"?>\n"
292  "<COPASI xmlns=\"http://www.copasi.org/static/schema\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"34\">\n"
293  " <ListOfFunctions>\n"
294  " <Function key=\"Function_6\" name=\"Constant flux (irreversible)\" type=\"PreDefined\" reversible=\"false\">\n"
295  " <Expression>\n"
296  " v\n"
297  " </Expression>\n"
298  " <ListOfParameterDescriptions>\n"
299  " <ParameterDescription key=\"FunctionParameter_49\" name=\"v\" order=\"0\" role=\"constant\"/>\n"
300  " </ListOfParameterDescriptions>\n"
301  " </Function>\n"
302  " </ListOfFunctions>\n"
303  " <Model key=\"Model_0\" name=\"New Model\" simulationType=\"time\" timeUnit=\"s\" volumeUnit=\"ml\" areaUnit=\"m²\" lengthUnit=\"m\" quantityUnit=\"mmol\" type=\"deterministic\" avogadroConstant=\"6.02214179e+23\">\n"
304  " <Comment>\n"
305  " Simple note on model\n"
306  " </Comment>\n"
307  " <ListOfCompartments>\n"
308  " <Compartment key=\"Compartment_0\" name=\"compartment_1\" simulationType=\"fixed\" dimensionality=\"3\">\n"
309  " <Comment>\n"
310  " Simple note on compartment\n"
311  " </Comment>\n"
312  " </Compartment>\n"
313  " </ListOfCompartments>\n"
314  " <ListOfMetabolites>\n"
315  " <Metabolite key=\"Metabolite_0\" name=\"species_1\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
316  " <Comment>\n"
317  " Simple note on species\n"
318  " </Comment>\n"
319  " </Metabolite>\n"
320  " </ListOfMetabolites>\n"
321  " <ListOfModelValues>\n"
322  " <ModelValue key=\"ModelValue_0\" name=\"quantity_1\" simulationType=\"fixed\">\n"
323  " <Comment>\n"
324  " Simple note on parameter\n"
325  " </Comment>\n"
326  " </ModelValue>\n"
327  " </ListOfModelValues>\n"
328  " <ListOfReactions>\n"
329  " <Reaction key=\"Reaction_0\" name=\"reaction_1\" reversible=\"false\">\n"
330  " <Comment>\n"
331  " Simple note on reaction\n"
332  " </Comment>\n"
333  " <ListOfProducts>\n"
334  " <Product metabolite=\"Metabolite_0\" stoichiometry=\"1\"/>\n"
335  " </ListOfProducts>\n"
336  " <ListOfConstants>\n"
337  " <Constant key=\"Parameter_74\" name=\"v\" value=\"0.1\"/>\n"
338  " </ListOfConstants>\n"
339  " <KineticLaw function=\"Function_6\">\n"
340  " <ListOfCallParameters>\n"
341  " <CallParameter functionParameter=\"FunctionParameter_49\">\n"
342  " <SourceParameter reference=\"Parameter_74\"/>\n"
343  " </CallParameter>\n"
344  " </ListOfCallParameters>\n"
345  " </KineticLaw>\n"
346  " </Reaction>\n"
347  " </ListOfReactions>\n"
348  " <ListOfEvents>\n"
349  " <Event key=\"Event_0\" name=\"event_1\" order=\"1\">\n"
350  " <Comment>\n"
351  " Simple note on event\n"
352  " </Comment>\n"
353  " <TriggerExpression>\n"
354  " &lt;CN=Root,Model=New Model,Reference=Time&gt; gt 3.0\n"
355  " </TriggerExpression>\n"
356  " <ListOfAssignments>\n"
357  " <Assignment targetKey=\"ModelValue_0\">\n"
358  " <Expression>\n"
359  " 3.0\n"
360  " </Expression>\n"
361  " </Assignment>\n"
362  " </ListOfAssignments>\n"
363  " </Event>\n"
364  " </ListOfEvents>\n"
365  " <StateTemplate>\n"
366  " <StateTemplateVariable objectReference=\"Model_0\"/>\n"
367  " <StateTemplateVariable objectReference=\"Metabolite_0\"/>\n"
368  " <StateTemplateVariable objectReference=\"ModelValue_0\"/>\n"
369  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
370  " </StateTemplate>\n"
371  " <InitialState type=\"initialState\">\n"
372  " 0 6.022141790000001e+20 0 1 \n"
373  " </InitialState>\n"
374  " </Model>\n"
375  "</COPASI>\n"
376  ;
Definition: CEvent.h:152
Header file of class CModelEntity and CModelValue.
void test_export_notes()
Definition: test000098.cpp:96
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
static const char * CPS_MODEL_1
Definition: test000098.h:39
Definition: CMetab.h:178
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
void tearDown()
Definition: test000098.cpp:40
void setUp()
Definition: test000098.cpp:33
static CCopasiDataModel * addDatamodel()
void test_import_notes()
Definition: test000098.cpp:47
bool importSBMLFromString(const std::string &sbmlDocumentText, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
static void init(int argc, char *argv[], const bool &withGui=false)
Definition: CModel.h:50
Header file of class CEvent.
static const char * SBML_MODEL_1
Definition: test000098.h:37
CCopasiDataModel * pDataModel
Definition: test000098.h:41