COPASI API  4.16.103
test000045.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 #include "test000045.h"
12 
13 #include <sstream>
14 #include "utilities.hpp"
16 #include "copasi/model/CModel.h"
17 #include "copasi/model/CMetab.h"
20 #include "copasi/model/CReaction.h"
23 
25 
26 CCopasiDataModel* test000045::pCOPASIDATAMODEL = NULL;
27 
29 {
30  // Create the root container.
31  CCopasiRootContainer::init(0, NULL, false);
32  // Create the global data model.
34 }
35 
37 {
39 }
40 
42 {
43  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
44  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING));
45  CModel* pModel = pDataModel->getModel();
46  CPPUNIT_ASSERT(pModel != NULL);
47  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
48  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
49  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
50  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
51  const CCompartment* pCompartment = pModel->getCompartments()[0];
52  CPPUNIT_ASSERT(pCompartment != NULL);
53  CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::FIXED);
54  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 2);
55  CMetab* pA = pModel->getMetabolites()[0];
56  CPPUNIT_ASSERT(pA != NULL);
57  CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::REACTIONS);
58  const CMetab* pB = pModel->getMetabolites()[1];
59  CPPUNIT_ASSERT(pB != NULL);
60  CPPUNIT_ASSERT(pB->getStatus() == CModelEntity::REACTIONS);
61  CPPUNIT_ASSERT(pModel->getModelValues().size() == 1);
62  const CModelValue* pModelValue = pModel->getModelValues()[0];
63  CPPUNIT_ASSERT(pModelValue != NULL);
64  CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::FIXED);
65 
66  CPPUNIT_ASSERT(pModel->getReactions().size() == 1);
67  const CReaction* pReaction1 = pModel->getReactions()[0];
68  CPPUNIT_ASSERT(pReaction1 != NULL);
69  CPPUNIT_ASSERT(pReaction1->isReversible() == true);
70  // check the kinetic law
71  const CFunction* pKineticFunction = pReaction1->getFunction();
72  CPPUNIT_ASSERT(pKineticFunction != NULL);
73  const CMassAction* pMassAction = dynamic_cast<const CMassAction*>(pKineticFunction);
74  CPPUNIT_ASSERT(pMassAction != NULL);
75  const CChemEq* pChemEq = &pReaction1->getChemEq();
76  CPPUNIT_ASSERT(pChemEq != NULL);
77  CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1);
78  CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1);
79  const CChemEqElement* pElement = pChemEq->getSubstrates()[0];
80  CPPUNIT_ASSERT(pElement != NULL);
81  CPPUNIT_ASSERT(fabs((pElement->getMultiplicity() - 3.0) / 3.0) < 1e-3);
82  CPPUNIT_ASSERT(pElement->getMetabolite() == pA);
83  CPPUNIT_ASSERT(pChemEq->getProducts().size() == 1);
84  pElement = pChemEq->getProducts()[0];
85  CPPUNIT_ASSERT(pElement != NULL);
86  CPPUNIT_ASSERT(fabs((pElement->getMultiplicity() - 1.3) / 1.3) < 1e-3);
87  CPPUNIT_ASSERT(pElement->getMetabolite() == pB);
88  CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0);
89  //CPPUNIT_ASSERT(CCopasiMessage::size() == 5);
91  CPPUNIT_ASSERT(message.getType() == CCopasiMessage::WARNING);
92  std::string s = message.getText();
93  CPPUNIT_ASSERT(!s.empty());
94  CPPUNIT_ASSERT(s.find(std::string("One or more stoichiometric expressions were evaluated and converted to constants values.")) != std::string::npos);
95  // the other four messages are libSBML unit warnings I don't care about right
96  // now.
97 }
98 
99 const char* test000045::MODEL_STRING =
100  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
101  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version3\" level=\"2\" version=\"3\">\n"
102  " <model id=\"Model_1\" name=\"New Model\">\n"
103  " <notes>\n"
104  " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
105  " <p>Model with fixed compartment volume, two species with hasOnlySubstanceUnits flag set to false. The units are set to ml and item. There is a stoichiometric expression for the only species in the only reaction. The expression consists of the number 2.0</p>\n"
106  " <p>The substrate of the reaction in the imported model should have a multiplicity of 2.</p>\n"
107  " </body>\n"
108  " </notes>\n"
109  " <listOfUnitDefinitions>\n"
110  " <unitDefinition id=\"volume\">\n"
111  " <listOfUnits>\n"
112  " <unit kind=\"litre\" scale=\"-3\"/>\n"
113  " </listOfUnits>\n"
114  " </unitDefinition>\n"
115  " <unitDefinition id=\"substance\">\n"
116  " <listOfUnits>\n"
117  " <unit kind=\"mole\" scale=\"-3\"/>\n"
118  " </listOfUnits>\n"
119  " </unitDefinition>\n"
120  " </listOfUnitDefinitions>\n"
121  " <listOfCompartments>\n"
122  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>\n"
123  " </listOfCompartments>\n"
124  " <listOfSpecies>\n"
125  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialConcentration=\"1\"/>\n"
126  " <species id=\"species_2\" name=\"B\" compartment=\"compartment_1\" initialConcentration=\"1\"/>\n"
127  " </listOfSpecies>\n"
128  " <listOfParameters>\n"
129  " <parameter id=\"parameter_1\" name=\"K\" value=\"0\"/>\n"
130  " </listOfParameters>\n"
131  " <listOfReactions>\n"
132  " <reaction id=\"reaction_1\" name=\"reaction_0\" reversible=\"true\">\n"
133  " <listOfReactants>\n"
134  " <speciesReference species=\"species_1\">\n"
135  " <stoichiometryMath>\n"
136  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
137  " <apply>\n"
138  " <times/>\n"
139  " <cn>2.0</cn>\n"
140  " <cn>1.5</cn>\n"
141  " </apply>\n"
142  " </math>\n"
143  " </stoichiometryMath>\n"
144  " </speciesReference>\n"
145  " </listOfReactants>\n"
146  " <listOfProducts>\n"
147  " <speciesReference species=\"species_2\">\n"
148  " <stoichiometryMath>\n"
149  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
150  " <apply>\n"
151  " <minus/>\n"
152  " <apply>\n"
153  " <divide/>\n"
154  " <cn>3.0</cn>\n"
155  " <cn>2.0</cn>\n"
156  " </apply>\n"
157  " <cn>0.2</cn>\n"
158  " </apply>\n"
159  " </math>\n"
160  " </stoichiometryMath>\n"
161  " </speciesReference>\n"
162  " </listOfProducts>\n"
163  " <kineticLaw>\n"
164  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
165  " <apply>\n"
166  " <times/>\n"
167  " <ci> compartment_1 </ci>\n"
168  " <apply>\n"
169  " <minus/>\n"
170  " <apply>\n"
171  " <times/>\n"
172  " <ci> k1 </ci>\n"
173  " <ci> species_1 </ci>\n"
174  " </apply>\n"
175  " <apply>\n"
176  " <times/>\n"
177  " <ci> k2 </ci>\n"
178  " <ci> species_2 </ci>\n"
179  " </apply>\n"
180  " </apply>\n"
181  " </apply>\n"
182  " </math>\n"
183  " <listOfParameters>\n"
184  " <parameter id=\"k1\" value=\"0.1\"/>\n"
185  " <parameter id=\"k2\" value=\"0.1\"/>\n"
186  " </listOfParameters>\n"
187  " </kineticLaw>\n"
188  " </reaction>\n"
189  " </listOfReactions>\n"
190  " </model>\n"
191  "</sbml>\n"
192  ;
Header file of class CExpression.
size_t getCompartmentNumber() const
Definition: CChemEq.cpp:110
Header file of class CModelEntity and CModelValue.
virtual size_t size() const
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000045.h:32
void tearDown()
Definition: test000045.cpp:36
Definition: CMetab.h:178
void setUp()
Definition: test000045.cpp:28
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
static CCopasiDataModel * addDatamodel()
const CCopasiVector< CChemEqElement > & getModifiers() const
Definition: CChemEq.cpp:66
static CCopasiMessage getLastMessage()
bool importSBMLFromString(const std::string &sbmlDocumentText, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
static void init(int argc, char *argv[], const bool &withGui=false)
Definition: CModel.h:50
void test_stoichiometricExpression()
Definition: test000045.cpp:41
static const char * MODEL_STRING
Definition: test000045.h:31