19 #include "test000018.hpp"
22 #include "utilities.hpp"
25 #include "sbml/SBMLDocument.h"
26 #include "sbml/Model.h"
27 #include "sbml/Rule.h"
28 #include "sbml/Species.h"
29 #include "sbml/Parameter.h"
30 #include "sbml/math/ASTNode.h"
36 void test000018::setUp()
44 void test000018::tearDown()
49 void test000018::test_references_to_species()
55 std::istringstream iss(test000018::MODEL_STRING);
57 CPPUNIT_ASSERT(pDataModel->
getModel() != NULL);
60 CPPUNIT_ASSERT(pDocument != NULL);
61 Model* pModel = pDocument->getModel();
62 CPPUNIT_ASSERT(pModel != NULL);
65 CPPUNIT_ASSERT(pModel->getNumCompartments() == 1);
66 Compartment* pCompartment = pModel->getCompartment(0);
67 CPPUNIT_ASSERT(pCompartment->getConstant() ==
false);
68 CPPUNIT_ASSERT(pModel->getNumSpecies() == 2);
69 Species* pSpecies = pModel->getSpecies(1);
70 CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() ==
true);
71 pSpecies = pModel->getSpecies(0);
72 std::string idSpeciesA = pSpecies->getId();
73 CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() ==
true);
75 CPPUNIT_ASSERT(pModel->getNumRules() == 2);
76 AssignmentRule* pRule =
dynamic_cast<AssignmentRule*
>(pModel->getRule(0));
77 CPPUNIT_ASSERT(pRule != NULL);
78 CPPUNIT_ASSERT(pModel->getNumParameters() == 2);
79 Parameter* pParameter = pModel->getParameter(0);
80 CPPUNIT_ASSERT(pParameter != NULL);
81 Parameter* pFactor = pModel->getParameter(1);
82 CPPUNIT_ASSERT(pFactor != NULL);
83 CPPUNIT_ASSERT(pFactor->getConstant() ==
true);
84 CPPUNIT_ASSERT(fabs((pFactor->getValue() - (
AVOGADRO / 1e6)) / (
AVOGADRO / 1e6)) < 1e-3);
86 if (pRule->getVariable() != pParameter->getId())
88 CPPUNIT_ASSERT(pRule->getVariable() == pCompartment->getId());
89 pRule =
dynamic_cast<AssignmentRule*
>(pModel->getRule(1));
90 CPPUNIT_ASSERT(pRule != NULL);
91 CPPUNIT_ASSERT(pRule->getVariable() == pParameter->getId());
94 const ASTNode* pMath = pRule->getMath();
96 CPPUNIT_ASSERT(pMath != NULL);
99 CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
101 CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
103 CPPUNIT_ASSERT(pMath->getChild(0) != NULL);
105 CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
107 CPPUNIT_ASSERT(pMath->getChild(0)->getName() == idSpeciesA);
109 CPPUNIT_ASSERT(pMath->getChild(1) != NULL);
111 CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
113 CPPUNIT_ASSERT(pMath->getChild(1)->getName() == pFactor->getId());
115 CPPUNIT_ASSERT(pModel->getNumReactions() == 2);
117 Reaction* pReaction = pModel->getReaction(0);
120 CPPUNIT_ASSERT(pReaction != NULL);
122 CPPUNIT_ASSERT(pReaction->getNumReactants() == 1);
124 CPPUNIT_ASSERT(pReaction->getNumProducts() == 0);
131 CPPUNIT_ASSERT(pReaction->isSetKineticLaw() ==
true);
133 KineticLaw* pLaw = pReaction->getKineticLaw();
135 CPPUNIT_ASSERT(pLaw != NULL);
137 CPPUNIT_ASSERT(pLaw->isSetMath() ==
true);
139 pMath = pLaw->getMath();
141 CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
143 CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
145 CPPUNIT_ASSERT(pMath->getChild(0) != NULL);
147 CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
149 CPPUNIT_ASSERT(pMath->getChild(0)->getName() == std::string(
"k1"));
151 CPPUNIT_ASSERT(pMath->getChild(1) != NULL);
153 CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
155 CPPUNIT_ASSERT(pMath->getChild(1)->getName() == idSpeciesA);
157 pReaction = pModel->getReaction(1);
160 CPPUNIT_ASSERT(pReaction != NULL);
162 CPPUNIT_ASSERT(pReaction->getNumReactants() == 1);
164 CPPUNIT_ASSERT(pReaction->getNumProducts() == 1);
170 CPPUNIT_ASSERT(pReaction->isSetKineticLaw() ==
true);
172 pLaw = pReaction->getKineticLaw();
174 CPPUNIT_ASSERT(pLaw != NULL);
176 CPPUNIT_ASSERT(pLaw->isSetMath() ==
true);
178 pMath = pLaw->getMath();
180 CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
182 CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
184 CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
186 CPPUNIT_ASSERT(pMath->getChild(0)->getName() == pCompartment->getId());
188 pMath = pMath->getChild(1);
190 CPPUNIT_ASSERT(pMath != NULL);
192 CPPUNIT_ASSERT(pMath->getType() == AST_FUNCTION);
194 CPPUNIT_ASSERT(pMath->getNumChildren() == 3);
196 pMath = pMath->getChild(0);
198 CPPUNIT_ASSERT(pMath != NULL);
200 CPPUNIT_ASSERT(pMath->getType() == AST_DIVIDE);
202 CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
204 CPPUNIT_ASSERT(pMath->getChild(0) != NULL);
206 CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
208 CPPUNIT_ASSERT(pMath->getChild(0)->getName() == idSpeciesA);
210 CPPUNIT_ASSERT(pMath->getChild(1) != NULL);
212 CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
214 CPPUNIT_ASSERT(pMath->getChild(1)->getName() == pCompartment->getId());
217 const char* test000018::MODEL_STRING =
218 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
219 "<!-- generated with COPASI 4.3.25 (Debug) (http://www.copasi.org) at 2008-02-15 09:45:35 UTC -->\n"
220 "<COPASI xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.copasi.org/static/schema.xsd\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"25\">\n"
221 " <ListOfFunctions>\n"
222 " <Function key=\"Function_8\" name=\"Henri-Michaelis-Menten (irreversible)\" type=\"PreDefined\" reversible=\"false\">\n"
224 " V*substrate/(Km+substrate)\n"
226 " <ListOfParameterDescriptions>\n"
227 " <ParameterDescription key=\"FunctionParameter_41\" name=\"substrate\" order=\"0\" role=\"substrate\"/>\n"
228 " <ParameterDescription key=\"FunctionParameter_30\" name=\"Km\" order=\"1\" role=\"constant\"/>\n"
229 " <ParameterDescription key=\"FunctionParameter_45\" name=\"V\" order=\"2\" role=\"constant\"/>\n"
230 " </ListOfParameterDescriptions>\n"
232 " <Function key=\"Function_13\" name=\"Mass action (irreversible)\" type=\"MassAction\" reversible=\"false\">\n"
234 " k1*PRODUCT<substrate_i>\n"
236 " <ListOfParameterDescriptions>\n"
237 " <ParameterDescription key=\"FunctionParameter_81\" name=\"k1\" order=\"0\" role=\"constant\"/>\n"
238 " <ParameterDescription key=\"FunctionParameter_79\" name=\"substrate\" order=\"1\" role=\"substrate\"/>\n"
239 " </ListOfParameterDescriptions>\n"
241 " </ListOfFunctions>\n"
242 " <Model key=\"Model_1\" name=\"New Model\" timeUnit=\"s\" volumeUnit=\"ml\" quantityUnit=\"µmol\" type=\"deterministic\">\n"
244 " <html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:13pt;font-family:Lucida Grande\">\n"
245 "<p>Model with variable volume compartment, micromol quantity units and a reference to the species transient amount.</p>\n"
246 "<p>On export this should create an SBML file with the hasOnlySubstanceUnits flag on the species set.</p>\n"
247 "<p>The reference in the rule should be multiplied by a factor (6.023e17) and the references in the reactions should be divided by the volume.</p>\n"
250 " <ListOfCompartments>\n"
251 " <Compartment key=\"Compartment_0\" name=\"compartment\" simulationType=\"assignment\">\n"
256 " </ListOfCompartments>\n"
257 " <ListOfMetabolites>\n"
258 " <Metabolite key=\"Metabolite_0\" name=\"A\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
260 " <Metabolite key=\"Metabolite_1\" name=\"S\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
262 " </ListOfMetabolites>\n"
263 " <ListOfModelValues>\n"
264 " <ModelValue key=\"ModelValue_0\" name=\"K\" simulationType=\"assignment\">\n"
266 " <CN=Root,Model=New Model,Vector=Compartments[compartment],Vector=Metabolites[A],Reference=ParticleNumber>\n"
269 " </ListOfModelValues>\n"
270 " <ListOfReactions>\n"
271 " <Reaction key=\"Reaction_0\" name=\"reaction\" reversible=\"false\">\n"
272 " <ListOfSubstrates>\n"
273 " <Substrate metabolite=\"Metabolite_0\" stoichiometry=\"1\"/>\n"
274 " </ListOfSubstrates>\n"
275 " <ListOfConstants>\n"
276 " <Constant key=\"Parameter_93\" name=\"k1\" value=\"0.1\"/>\n"
277 " </ListOfConstants>\n"
278 " <KineticLaw function=\"Function_13\">\n"
279 " <ListOfCallParameters>\n"
280 " <CallParameter functionParameter=\"FunctionParameter_81\">\n"
281 " <SourceParameter reference=\"Parameter_93\"/>\n"
282 " </CallParameter>\n"
283 " <CallParameter functionParameter=\"FunctionParameter_79\">\n"
284 " <SourceParameter reference=\"Metabolite_0\"/>\n"
285 " </CallParameter>\n"
286 " </ListOfCallParameters>\n"
289 " <Reaction key=\"Reaction_1\" name=\"reaction_1\" reversible=\"false\">\n"
290 " <ListOfSubstrates>\n"
291 " <Substrate metabolite=\"Metabolite_0\" stoichiometry=\"1\"/>\n"
292 " </ListOfSubstrates>\n"
293 " <ListOfProducts>\n"
294 " <Product metabolite=\"Metabolite_1\" stoichiometry=\"1\"/>\n"
295 " </ListOfProducts>\n"
296 " <ListOfConstants>\n"
297 " <Constant key=\"Parameter_92\" name=\"Km\" value=\"0.1\"/>\n"
298 " <Constant key=\"Parameter_91\" name=\"V\" value=\"0.1\"/>\n"
299 " </ListOfConstants>\n"
300 " <KineticLaw function=\"Function_8\">\n"
301 " <ListOfCallParameters>\n"
302 " <CallParameter functionParameter=\"FunctionParameter_41\">\n"
303 " <SourceParameter reference=\"Metabolite_0\"/>\n"
304 " </CallParameter>\n"
305 " <CallParameter functionParameter=\"FunctionParameter_30\">\n"
306 " <SourceParameter reference=\"Parameter_92\"/>\n"
307 " </CallParameter>\n"
308 " <CallParameter functionParameter=\"FunctionParameter_45\">\n"
309 " <SourceParameter reference=\"Parameter_91\"/>\n"
310 " </CallParameter>\n"
311 " </ListOfCallParameters>\n"
314 " </ListOfReactions>\n"
316 " <StateTemplateVariable objectReference=\"Model_1\"/>\n"
317 " <StateTemplateVariable objectReference=\"Metabolite_0\"/>\n"
318 " <StateTemplateVariable objectReference=\"Metabolite_1\"/>\n"
319 " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
320 " <StateTemplateVariable objectReference=\"ModelValue_0\"/>\n"
321 " </StateTemplate>\n"
322 " <InitialState type=\"initialState\">\n"
323 " 0 4.21549905e+18 4.215499050000001e+17 7 4.21549905e+18\n"
SBMLDocument * getCurrentSBMLDocument()
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
static CCopasiDataModel * addDatamodel()
static void init(int argc, char *argv[], const bool &withGui=false)