COPASI API  4.16.103
test000044.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 "test000044.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* test000044::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() - 2.0) / 2.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() - 3.0) / 3.0) < 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* test000044::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  " <cn>2.0</cn>\n"
138  " </math>\n"
139  " </stoichiometryMath>\n"
140  " </speciesReference>\n"
141  " </listOfReactants>\n"
142  " <listOfProducts>\n"
143  " <speciesReference species=\"species_2\">\n"
144  " <stoichiometryMath>\n"
145  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
146  " <cn>3.0</cn>\n"
147  " </math>\n"
148  " </stoichiometryMath>\n"
149  " </speciesReference>\n"
150  " </listOfProducts>\n"
151  " <kineticLaw>\n"
152  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
153  " <apply>\n"
154  " <times/>\n"
155  " <ci> compartment_1 </ci>\n"
156  " <apply>\n"
157  " <minus/>\n"
158  " <apply>\n"
159  " <times/>\n"
160  " <ci> k1 </ci>\n"
161  " <ci> species_1 </ci>\n"
162  " </apply>\n"
163  " <apply>\n"
164  " <times/>\n"
165  " <ci> k2 </ci>\n"
166  " <ci> species_2 </ci>\n"
167  " </apply>\n"
168  " </apply>\n"
169  " </apply>\n"
170  " </math>\n"
171  " <listOfParameters>\n"
172  " <parameter id=\"k1\" value=\"0.1\"/>\n"
173  " <parameter id=\"k2\" value=\"0.1\"/>\n"
174  " </listOfParameters>\n"
175  " </kineticLaw>\n"
176  " </reaction>\n"
177  " </listOfReactions>\n"
178  " </model>\n"
179  "</sbml>\n"
180  ;
Header file of class CExpression.
size_t getCompartmentNumber() const
Definition: CChemEq.cpp:110
static const char * MODEL_STRING
Definition: test000044.h:31
void setUp()
Definition: test000044.cpp:28
Header file of class CModelEntity and CModelValue.
void tearDown()
Definition: test000044.cpp:36
virtual size_t size() const
Definition: CMetab.h:178
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)
void test_stoichiometricExpression()
Definition: test000044.cpp:41
Definition: CModel.h:50
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000044.h:32