COPASI API  4.16.103
test000046.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 "test000046.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* test000046::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  CPPUNIT_ASSERT(fabs((pModelValue->getInitialValue() - 3.7) / 3.7) < 1e-3);
66 
67  CPPUNIT_ASSERT(pModel->getReactions().size() == 1);
68  const CReaction* pReaction1 = pModel->getReactions()[0];
69  CPPUNIT_ASSERT(pReaction1 != NULL);
70  CPPUNIT_ASSERT(pReaction1->isReversible() == true);
71  // check the kinetic law
72  const CFunction* pKineticFunction = pReaction1->getFunction();
73  CPPUNIT_ASSERT(pKineticFunction != NULL);
74  const CMassAction* pMassAction = dynamic_cast<const CMassAction*>(pKineticFunction);
75  CPPUNIT_ASSERT(pMassAction != NULL);
76  const CChemEq* pChemEq = &pReaction1->getChemEq();
77  CPPUNIT_ASSERT(pChemEq != NULL);
78  CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1);
79  CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1);
80  const CChemEqElement* pElement = pChemEq->getSubstrates()[0];
81  CPPUNIT_ASSERT(pElement != NULL);
82  CPPUNIT_ASSERT(fabs((pElement->getMultiplicity() - 1.85) / 1.85) < 1e-3);
83  CPPUNIT_ASSERT(pElement->getMetabolite() == pA);
84  CPPUNIT_ASSERT(pChemEq->getProducts().size() == 1);
85  pElement = pChemEq->getProducts()[0];
86  CPPUNIT_ASSERT(pElement != NULL);
87  CPPUNIT_ASSERT(fabs((pElement->getMultiplicity() - 3.35) / 3.35) / 3.35 < 1e-3);
88  CPPUNIT_ASSERT(pElement->getMetabolite() == pB);
89  CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0);
90  //CPPUNIT_ASSERT(CCopasiMessage::size() == 5);
92  CPPUNIT_ASSERT(message.getType() == CCopasiMessage::WARNING);
93  std::string s = message.getText();
94  CPPUNIT_ASSERT(!s.empty());
95  CPPUNIT_ASSERT(s.find(std::string("One or more stoichiometric expressions were evaluated and converted to constants values.")) != std::string::npos);
96  // the other four messages are libSBML unit warnings I don't care about right
97  // now.
98 }
99 
100 const char* test000046::MODEL_STRING =
101  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
102  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version3\" level=\"2\" version=\"3\">\n"
103  " <model id=\"Model_1\" name=\"New Model\">\n"
104  " <notes>\n"
105  " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
106  " <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"
107  " <p>The substrate of the reaction in the imported model should have a multiplicity of 2.</p>\n"
108  " </body>\n"
109  " </notes>\n"
110  " <listOfUnitDefinitions>\n"
111  " <unitDefinition id=\"volume\">\n"
112  " <listOfUnits>\n"
113  " <unit kind=\"litre\" scale=\"-3\"/>\n"
114  " </listOfUnits>\n"
115  " </unitDefinition>\n"
116  " <unitDefinition id=\"substance\">\n"
117  " <listOfUnits>\n"
118  " <unit kind=\"mole\" scale=\"-3\"/>\n"
119  " </listOfUnits>\n"
120  " </unitDefinition>\n"
121  " </listOfUnitDefinitions>\n"
122  " <listOfCompartments>\n"
123  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>\n"
124  " </listOfCompartments>\n"
125  " <listOfSpecies>\n"
126  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialConcentration=\"1\"/>\n"
127  " <species id=\"species_2\" name=\"B\" compartment=\"compartment_1\" initialConcentration=\"1\"/>\n"
128  " </listOfSpecies>\n"
129  " <listOfParameters>\n"
130  " <parameter id=\"parameter_1\" name=\"K\" value=\"3.7\"/>\n"
131  " </listOfParameters>\n"
132  " <listOfReactions>\n"
133  " <reaction id=\"reaction_1\" name=\"reaction_0\" reversible=\"true\">\n"
134  " <listOfReactants>\n"
135  " <speciesReference species=\"species_1\">\n"
136  " <stoichiometryMath>\n"
137  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
138  " <apply>\n"
139  " <divide/>\n"
140  " <ci> parameter_1 </ci>\n"
141  " <cn> 2.0 </cn>\n"
142  " </apply>\n"
143  " </math>\n"
144  " </stoichiometryMath>\n"
145  " </speciesReference>\n"
146  " </listOfReactants>\n"
147  " <listOfProducts>\n"
148  " <speciesReference species=\"species_2\">\n"
149  " <stoichiometryMath>\n"
150  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
151  " <apply>\n"
152  " <times/>\n"
153  " <apply>\n"
154  " <plus/>\n"
155  " <ci> parameter_1 </ci>\n"
156  " <cn> 3.0 </cn>\n"
157  " </apply>\n"
158  " <cn> 0.5 </cn>\n"
159  " </apply>\n"
160  " </math>\n"
161  " </stoichiometryMath>\n"
162  " </speciesReference>\n"
163  " </listOfProducts>\n"
164  " <kineticLaw>\n"
165  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
166  " <apply>\n"
167  " <times/>\n"
168  " <ci> compartment_1 </ci>\n"
169  " <apply>\n"
170  " <minus/>\n"
171  " <apply>\n"
172  " <times/>\n"
173  " <ci> k1 </ci>\n"
174  " <ci> species_1 </ci>\n"
175  " </apply>\n"
176  " <apply>\n"
177  " <times/>\n"
178  " <ci> k2 </ci>\n"
179  " <ci> species_2 </ci>\n"
180  " </apply>\n"
181  " </apply>\n"
182  " </apply>\n"
183  " </math>\n"
184  " <listOfParameters>\n"
185  " <parameter id=\"k1\" value=\"0.1\"/>\n"
186  " <parameter id=\"k2\" value=\"0.1\"/>\n"
187  " </listOfParameters>\n"
188  " </kineticLaw>\n"
189  " </reaction>\n"
190  " </listOfReactions>\n"
191  " </model>\n"
192  "</sbml>\n"
193  ;
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 const char * MODEL_STRING
Definition: test000046.h:31
Definition: CMetab.h:178
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
void test_stoichiometricExpression()
Definition: test000046.cpp:41
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
static CCopasiDataModel * addDatamodel()
void tearDown()
Definition: test000046.cpp:36
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 CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000046.h:32
static void init(int argc, char *argv[], const bool &withGui=false)
Definition: CModel.h:50
void setUp()
Definition: test000046.cpp:28