void AssignmentCycles::addInitialAssignmentDependencies(const Model& m, const InitialAssignment& object) { unsigned int ns; std::string thisId = object.getSymbol(); /* loop thru the list of names in the Math * if they refer to a Reaction, an Assignment Rule * or an Initial Assignment add to the map * with the variable as key */ List* variables = object.getMath()->getListOfNodes( ASTNode_isName ); for (ns = 0; ns < variables->getSize(); ns++) { ASTNode* node = static_cast<ASTNode*>( variables->get(ns) ); string name = node->getName() ? node->getName() : ""; if (m.getReaction(name)) { mIdMap.insert(pair<const std::string, std::string>(thisId, name)); } else if (m.getRule(name) && m.getRule(name)->isAssignment()) { mIdMap.insert(pair<const std::string, std::string>(thisId, name)); } else if (m.getInitialAssignment(name)) { mIdMap.insert(pair<const std::string, std::string>(thisId, name)); } } delete variables; }
void CompIdBase::checkId (const InitialAssignment& x) { if (x.isSetSymbol()) doCheckId(x.getSymbol(), x); }
void test000014::test_references_to_species() { // load the CPS file // export to SBML // check the resulting SBML model CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; std::istringstream iss(test000014::MODEL_STRING); CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true); CPPUNIT_ASSERT(pDataModel->getModel() != NULL); CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, 2, 3).empty() == false); SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument(); CPPUNIT_ASSERT(pDocument != NULL); Model* pModel = pDocument->getModel(); CPPUNIT_ASSERT(pModel != NULL); // assert that there is only one compartment and // assert the compartment is constant CPPUNIT_ASSERT(pModel->getNumCompartments() == 1); Compartment* pCompartment = pModel->getCompartment(0); CPPUNIT_ASSERT(pCompartment->getConstant() == false); CPPUNIT_ASSERT(pModel->getNumSpecies() == 2); Species* pSpecies = pModel->getSpecies(1); CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() == true); pSpecies = pModel->getSpecies(0); std::string idSpeciesA = pSpecies->getId(); CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() == true); CPPUNIT_ASSERT(pModel->getNumRules() == 1); CPPUNIT_ASSERT(pModel->getNumInitialAssignments() == 1); InitialAssignment* pAssignment = pModel->getInitialAssignment(0); CPPUNIT_ASSERT(pAssignment != NULL); CPPUNIT_ASSERT(pModel->getNumParameters() == 1); Parameter* pParameter = pModel->getParameter(0); CPPUNIT_ASSERT(pParameter != NULL); CPPUNIT_ASSERT(pAssignment->getSymbol() == pParameter->getId()); const ASTNode* pMath = pAssignment->getMath(); CPPUNIT_ASSERT(pMath != NULL); // the expression should be the species divided by the initial volume CPPUNIT_ASSERT(pMath->getType() == AST_DIVIDE); CPPUNIT_ASSERT(pMath->getNumChildren() == 2); CPPUNIT_ASSERT(pMath->getChild(0) != NULL); CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getChild(0)->getName() == pSpecies->getId()); CPPUNIT_ASSERT(pMath->getChild(1) != NULL); CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getChild(1)->getName() == pCompartment->getId()); CPPUNIT_ASSERT(pModel->getNumReactions() == 2); Reaction* pReaction = pModel->getReaction(0); // make sure this is reaction A -> CPPUNIT_ASSERT(pReaction != NULL); CPPUNIT_ASSERT(pReaction->getNumReactants() == 1); CPPUNIT_ASSERT(pReaction->getNumProducts() == 0); // check if all references in the kinetic law are unmodified // math element must be a multiplication of the mass action term by // the compartment volume // the mass action term is a multiplication of the parameter node by // the species node CPPUNIT_ASSERT(pReaction->isSetKineticLaw() == true); KineticLaw* pLaw = pReaction->getKineticLaw(); CPPUNIT_ASSERT(pLaw != NULL); CPPUNIT_ASSERT(pLaw->isSetMath() == true); pMath = pLaw->getMath(); CPPUNIT_ASSERT(pMath->getType() == AST_TIMES); CPPUNIT_ASSERT(pMath->getNumChildren() == 2); CPPUNIT_ASSERT(pMath->getChild(0) != NULL); CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getChild(0)->getName() == std::string("k1")); CPPUNIT_ASSERT(pMath->getChild(1) != NULL); CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getChild(1)->getName() == idSpeciesA); pReaction = pModel->getReaction(1); // make sure this is reaction A -> S CPPUNIT_ASSERT(pReaction != NULL); CPPUNIT_ASSERT(pReaction->getNumReactants() == 1); CPPUNIT_ASSERT(pReaction->getNumProducts() == 1); // check if all references in the kinetic law are unmodified // math element must be a multiplication of the compartments volume with // a function call with three arguments // the first argument is the reference to the species CPPUNIT_ASSERT(pReaction->isSetKineticLaw() == true); pLaw = pReaction->getKineticLaw(); CPPUNIT_ASSERT(pLaw != NULL); CPPUNIT_ASSERT(pLaw->isSetMath() == true); pMath = pLaw->getMath(); CPPUNIT_ASSERT(pMath->getType() == AST_TIMES); CPPUNIT_ASSERT(pMath->getNumChildren() == 2); CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getChild(0)->getName() == pCompartment->getId()); pMath = pMath->getChild(1); CPPUNIT_ASSERT(pMath != NULL); CPPUNIT_ASSERT(pMath->getType() == AST_FUNCTION); CPPUNIT_ASSERT(pMath->getNumChildren() == 3); pMath = pMath->getChild(0); CPPUNIT_ASSERT(pMath != NULL); CPPUNIT_ASSERT(pMath->getType() == AST_DIVIDE); CPPUNIT_ASSERT(pMath->getNumChildren() == 2); CPPUNIT_ASSERT(pMath->getChild(0) != NULL); CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getChild(0)->getName() == idSpeciesA); CPPUNIT_ASSERT(pMath->getChild(1) != NULL); CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getChild(1)->getName() == pCompartment->getId()); }