COPASI API  4.16.103
test000047.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 "test000047.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* test000047::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  const CMetab* pB = pModel->getMetabolites()[1];
56  CPPUNIT_ASSERT(pB != NULL);
57  CPPUNIT_ASSERT(pB->getStatus() == CModelEntity::FIXED);
58  CMetab* pA = pModel->getMetabolites()[0];
59  CPPUNIT_ASSERT(pA != NULL);
60  CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::ASSIGNMENT);
61  const CExpression* pExpr = pA->getExpressionPtr();
62  CPPUNIT_ASSERT(pExpr != NULL);
63  const CEvaluationNode* pNode = pExpr->getRoot();
64  CPPUNIT_ASSERT(pNode != NULL);
65  const CEvaluationNodeDelay* pDelayNode = dynamic_cast<const CEvaluationNodeDelay*>(pNode);
66  CPPUNIT_ASSERT(pDelayNode != NULL);
67  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pDelayNode->getChild());
68  CPPUNIT_ASSERT(pObjectNode != NULL);
69  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
70  CPPUNIT_ASSERT(!objectCN.empty());
71  std::vector<CCopasiContainer*> listOfContainers;
72  listOfContainers.push_back(pModel);
73  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
74  CPPUNIT_ASSERT(pObject != NULL);
75  CPPUNIT_ASSERT(pObject->isReference() == true);
76  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Concentration"));
77  CPPUNIT_ASSERT(pObject->getObjectParent() == pB);
78  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pObjectNode->getSibling());
79  CPPUNIT_ASSERT(pNumberNode != NULL);
81  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 0.5) / 0.5) < 1e-3);
82 
83  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);
84 
85  CPPUNIT_ASSERT(pModel->getModelValues().size() == 1);
86  const CModelValue* pModelValue = pModel->getModelValues()[0];
87  CPPUNIT_ASSERT(pModelValue != NULL);
88  CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::FIXED);
89  CPPUNIT_ASSERT(pModel->getReactions().size() == 0);
90  //CPPUNIT_ASSERT(CCopasiMessage::size() == 2);
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("COPASI does not support time delays. Calculations on this model will most likely lead to unusable results.")) != std::string::npos);
96  // right now, we don't care about the last message since it is a units
97  // warning from libSBML
98 }
99 
100 const char* test000047::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 mMol.</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\" constant=\"false\" />\n"
126  " <species id=\"species_2\" name=\"B\" compartment=\"compartment_1\" initialConcentration=\"1\" constant=\"true\" />\n"
127  " </listOfSpecies>\n"
128  " <listOfParameters>\n"
129  " <parameter id=\"parameter_1\" name=\"K\" value=\"0\"/>\n"
130  " </listOfParameters>\n"
131  " <listOfRules>\n"
132  " <assignmentRule variable=\"species_1\">\n"
133  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
134  " <apply>\n"
135  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/delay\">\n"
136  " delay\n"
137  " </csymbol>\n"
138  " <ci> species_2 </ci>\n"
139  " <cn> 0.5 </cn>\n"
140  " </apply>\n"
141  " </math>\n"
142  " </assignmentRule>\n"
143  " </listOfRules>\n"
144  " </model>\n"
145  "</sbml>\n"
146  ;
Header file of class CExpression.
Header file of class CModelEntity and CModelValue.
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
const std::string & getObjectName() const
const CRegisteredObjectName & getObjectCN() const
Definition: CMetab.h:178
bool isReference() const
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000047.h:32
static const char * MODEL_STRING
Definition: test000047.h:31
static CCopasiDataModel * addDatamodel()
static Type subType(const Type &type)
static CCopasiMessage getLastMessage()
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
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
void test_delay()
Definition: test000047.cpp:41
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
void tearDown()
Definition: test000047.cpp:36
CCopasiContainer * getObjectParent() const
void setUp()
Definition: test000047.cpp:28