void checkReactions(Model* model, set<string>& components, set<string>& tests, const map<string, vector<double> >& results, int type) { if (model->getNumReactions() > 0) { components.insert("Reaction"); for (unsigned int r=0; r<model->getNumReactions(); r++) { Reaction* rxn = model->getReaction(r); if (rxn->isSetFast() && rxn->getFast()) { tests.insert("FastReaction"); } if (rxn->isSetReversible() && rxn->getReversible()) { if (type!=1) { tests.insert("ReversibleReaction [?]"); } } ListOfSpeciesReferences* reactants = rxn->getListOfReactants(); checkSpeciesRefs(model, reactants, components, tests, results); ListOfSpeciesReferences* products = rxn->getListOfProducts(); checkSpeciesRefs(model, products, components, tests, results); if (rxn->isSetKineticLaw()) { KineticLaw* kl = rxn->getKineticLaw(); if (kl->getNumParameters() > 0) { tests.insert("LocalParameters"); } if (kl->isSetMath() == false) { tests.insert("NoMathML"); } } } } }
bool variesIn(string id, Model* model, const map<string, vector<double> >& results) { if (variesIn(id, results)) return true; Rule* rule = model->getRule(id); if (rule != NULL) { if (rule->getTypeCode() == SBML_RATE_RULE) return true; return variesIn(rule->getMath(), model, results); } if (!getConstant(id, model, results)) { //The variable might be set by an algebraic rule for (unsigned long r=0; r<model->getNumRules(); r++) { if (model->getRule(r)->getTypeCode() == SBML_ALGEBRAIC_RULE) { if (appearsIn(id, model->getRule(r)->getMath()) && variesBesides(id, model->getRule(r)->getMath(), model, results)) return true; } } } for (unsigned long e=0; e<model->getNumEvents(); e++) { Event* event = model->getEvent(e); for (unsigned long ea=0; ea<event->getNumEventAssignments(); ea++) { if (event->getEventAssignment(ea)->getVariable() == id) return true; } } Species* species = model->getSpecies(id); if (species==NULL) return false; if (species->isSetBoundaryCondition() && species->getBoundaryCondition()==true) return false; for (unsigned long r=0; r<model->getNumReactions(); r++) { Reaction* rxn = model->getReaction(r); if (variesIn(id, rxn->getListOfReactants(), results)) return true; if (variesIn(id, rxn->getListOfProducts(), results)) return true; } return false; }
END_TEST START_TEST ( test_SpeciesReference_Product_parent_create ) { Reaction *r = new Reaction(2, 4); SpeciesReference *sr = r->createProduct(); ListOf *lo = r->getListOfProducts(); fail_unless(lo == r->getProduct(0)->getParentSBMLObject()); fail_unless(lo == sr->getParentSBMLObject()); fail_unless(r == lo->getParentSBMLObject()); }
END_TEST START_TEST ( test_SpeciesReference_Product_parent_add ) { SpeciesReference *sr = new SpeciesReference(2, 4); Reaction *r = new Reaction(2, 4); sr->setSpecies("p"); r->addProduct(sr); delete sr; ListOf *lo = r->getListOfProducts(); fail_unless(lo == r->getProduct(0)->getParentSBMLObject()); fail_unless(r == lo->getParentSBMLObject()); }
void Model::removeDuplicateTopLevelAnnotations() { unsigned int i, n; this->removeDuplicateAnnotations(); if (getNumFunctionDefinitions() > 0) { getListOfFunctionDefinitions()->removeDuplicateAnnotations(); for (i = 0; i < getNumFunctionDefinitions(); i++) { getFunctionDefinition(i)->removeDuplicateAnnotations(); } } if (getNumUnitDefinitions() > 0) { getListOfUnitDefinitions()->removeDuplicateAnnotations(); for (i = 0; i < getNumUnitDefinitions(); i++) { getUnitDefinition(i)->removeDuplicateAnnotations(); getUnitDefinition(i)->getListOfUnits()->removeDuplicateAnnotations(); for (n = 0; n < getUnitDefinition(i)->getNumUnits(); n++) { getUnitDefinition(i)->getUnit(n)->removeDuplicateAnnotations(); } } } if (getNumCompartmentTypes() > 0) { getListOfCompartmentTypes()->removeDuplicateAnnotations(); for (i = 0; i < getNumCompartmentTypes(); i++) { getCompartmentType(i)->removeDuplicateAnnotations(); } } if (getNumSpeciesTypes() > 0) { getListOfSpeciesTypes()->removeDuplicateAnnotations(); for (i = 0; i < getNumSpeciesTypes(); i++) { getSpeciesType(i)->removeDuplicateAnnotations(); } } if (getNumCompartments() > 0) { getListOfCompartments()->removeDuplicateAnnotations(); for (i = 0; i < getNumCompartments(); i++) { getCompartment(i)->removeDuplicateAnnotations(); } } if (getNumSpecies() > 0) { getListOfSpecies()->removeDuplicateAnnotations(); for (i = 0; i < getNumSpecies(); i++) { getSpecies(i)->removeDuplicateAnnotations(); } } if (getNumParameters() > 0) { getListOfParameters()->removeDuplicateAnnotations(); for (i = 0; i < getNumParameters(); i++) { getParameter(i)->removeDuplicateAnnotations(); } } if (getNumInitialAssignments() > 0) { getListOfInitialAssignments()->removeDuplicateAnnotations(); for (i = 0; i < getNumInitialAssignments(); i++) { getInitialAssignment(i)->removeDuplicateAnnotations(); } } if (getNumConstraints() > 0) { getListOfConstraints()->removeDuplicateAnnotations(); for (i = 0; i < getNumConstraints(); i++) { getConstraint(i)->removeDuplicateAnnotations(); } } if (getNumRules() > 0) { getListOfRules()->removeDuplicateAnnotations(); for (i = 0; i < getNumRules(); i++) { getRule(i)->removeDuplicateAnnotations(); } } if (getNumReactions() > 0) { getListOfReactions()->removeDuplicateAnnotations(); for (i = 0; i < getNumReactions(); i++) { Reaction * r = getReaction(i); r->removeDuplicateAnnotations(); if (r->getNumReactants() > 0) { r->getListOfReactants()->removeDuplicateAnnotations(); for (n = 0; n < r->getNumReactants(); n++) { r->getReactant(n)->removeDuplicateAnnotations(); } } if (r->getNumProducts() > 0) { r->getListOfProducts()->removeDuplicateAnnotations(); for (n = 0; n < r->getNumProducts(); n++) { r->getProduct(n)->removeDuplicateAnnotations(); } } if (r->getNumModifiers() > 0) { r->getListOfModifiers()->removeDuplicateAnnotations(); for (n = 0; n < r->getNumModifiers(); n++) { r->getModifier(n)->removeDuplicateAnnotations(); } } if (r->isSetKineticLaw()) { r->getKineticLaw()->removeDuplicateAnnotations(); if (r->getKineticLaw()->getNumParameters() > 0) { r->getKineticLaw()->getListOfParameters() ->removeDuplicateAnnotations(); for (n = 0; n < r->getKineticLaw()->getNumParameters(); n++) { r->getKineticLaw()->getParameter(n)->removeDuplicateAnnotations(); } } } } } if (getNumEvents() > 0) { getListOfEvents()->removeDuplicateAnnotations(); for (i = 0; i < getNumEvents(); i++) { getEvent(i)->removeDuplicateAnnotations(); if (getEvent(i)->getNumEventAssignments() > 0) { getEvent(i)->getListOfEventAssignments()->removeDuplicateAnnotations(); for (n = 0; n < getEvent(i)->getNumEventAssignments(); n++) { getEvent(i)->getEventAssignment(n)->removeDuplicateAnnotations(); } } } } }
void SBML_sim::loadSBML(SBMLDocument * doc) { if (!doc || doc->getNumErrors() > 0) { } else { Model * model = doc->getModel(); ListOfParameters * params = model->getListOfParameters(); ListOfReactions * reacs = model->getListOfReactions(); ListOfSpecies * species = model->getListOfSpecies(); ListOfSpeciesTypes * types = model->getListOfSpeciesTypes(); ListOfEvents * events = model->getListOfEvents(); ListOfRules * rules = model->getListOfRules(); vector<string> assignmentEquations, rateEquations, eventTriggers; vector< vector<string> > eventResponses; if (events) for (int i=0; i < events->size(); ++i) { Event * e = events->get(i); eventTriggers.push_back( SBML_formulaToString( e->getTrigger()->getMath() ) ); ListOfEventAssignments * eventAssn = e->getListOfEventAssignments(); vector<string> responses; string s; for (int j=0; j < eventAssn->size(); ++j) { s = eventAssn->get(j)->getVariable(); s.append("="); s.append( SBML_formulaToString( eventAssn->get(j)->getMath() ) ); responses.push_back(s); } eventResponses.push_back( responses ); } if (rules) for (int i=0; i < rules->size(); ++i) { Rule * r = rules->get(i); if (r->isAssignment()) { AssignmentRule * ar = (AssignmentRule*)r; assignmentVariables.push_back(ar->getVariable()); assignmentValues.push_back(1.0); assignmentEquations.push_back(ar->getFormula()); } } if (species) for (int i=0; i < species->size(); ++i) if (!species->get(i)->getConstant() && !species->get(i)->getBoundaryCondition()) { variableNames.push_back(species->get(i)->getId()); if (species->get(i)->isSetInitialAmount()) variableValues.push_back(species->get(i)->getInitialAmount()); else if (species->get(i)->isSetInitialConcentration()) variableValues.push_back(species->get(i)->getInitialConcentration()); else variableValues.push_back(0.0); } else { parameterNames.push_back(species->get(i)->getId()); if (species->get(i)->isSetInitialAmount()) parameterValues.push_back(species->get(i)->getInitialAmount()); else if (species->get(i)->isSetInitialConcentration()) parameterValues.push_back(species->get(i)->getInitialConcentration()); else parameterValues.push_back(0.0); } if (params) for (int i=0; i < params->size(); ++i) { parameterNames.push_back(params->get(i)->getId()); parameterValues.push_back(params->get(i)->getValue()); } int numReacs = 0; if (reacs) numReacs = reacs->size(); stoichiometryMatrix = new double[ numReacs * variableNames.size() ]; for (int i=0; i < numReacs; ++i) { Reaction * r = reacs->get(i); reactionNames.push_back(r->getId()); rateEquations.push_back(r->getKineticLaw()->getFormula()); ListOfSpeciesReferences * reactants = r->getListOfReactants(), * products = r->getListOfProducts(); for (int j=0; j < variableNames.size(); ++j) { stoichiometryMatrix[ j*numReacs + i ] = 0.0; for (int k=0; k < reactants->size(); ++k) if (reactants->get(k) && reactants->get(k)->getSpecies() == variableNames[j]) stoichiometryMatrix[ j*numReacs + i ] -= 1.0; //stoichiometryMatrix[ j*numReacs + i ] -= SpeciesReference_getStoichiometry(reactants->get(k)); for (int k=0; k < products->size(); ++k) if (products->get(k) && products->get(k)->getSpecies() == variableNames[j]) stoichiometryMatrix[ j*numReacs + i ] += 1.0; //stoichiometryMatrix[ j*numReacs + i ] += SpeciesReference_getStoichiometry(reactants->get(k)); } } for (int i=0; i < rateEquations.size(); ++i) { mu::Parser p; addSBMLFunctions(p); p.SetExpr(rateEquations[i]); for (int j=0; j < variableNames.size(); ++j) p.DefineVar("time",&(this->time)); for (int j=0; j < variableNames.size(); ++j) p.DefineVar("Time",&(this->time)); for (int j=0; j < variableNames.size(); ++j) p.DefineVar(variableNames[j],&variableValues[j]); for (int j=0; j < parameterNames.size(); ++j) p.DefineVar(parameterNames[j],¶meterValues[j]); for (int j=0; j < assignmentVariables.size(); ++j) p.DefineVar(assignmentVariables[j],&assignmentValues[j]); p.SetVarFactory(muparser_add_variable, (void*)this); try { p.Eval(); rateEqns.push_back(p); } catch(...) { //reactionNames.clear(); //rateEqns.clear(); break; } } for (int i=0; i < assignmentEquations.size(); ++i) { mu::Parser p; addSBMLFunctions(p); p.SetExpr(assignmentEquations[i]); for (int j=0; j < variableNames.size(); ++j) p.DefineVar(variableNames[j],&variableValues[j]); for (int j=0; j < parameterNames.size(); ++j) p.DefineVar(parameterNames[j],¶meterValues[j]); for (int j=0; j < assignmentVariables.size(); ++j) p.DefineVar(assignmentVariables[j],&assignmentValues[j]); //p.SetVarFactory(muparser_add_variable, (void*)this); try { p.Eval(); assignmentEqns.push_back(p); } catch(...) { std::cout << assignmentEquations[i] << std::endl; //assignmentVariables.clear(); //assignmentEqns.clear(); break; } } for (int i=0; i < eventTriggers.size(); ++i) { mu::Parser p; addSBMLFunctions(p); p.SetExpr(eventTriggers[i]); for (int j=0; j < variableNames.size(); ++j) p.DefineVar("time",&(this->time)); for (int j=0; j < variableNames.size(); ++j) p.DefineVar("Time",&(this->time)); for (int j=0; j < variableNames.size(); ++j) p.DefineVar(variableNames[j],&variableValues[j]); for (int j=0; j < parameterNames.size(); ++j) p.DefineVar(parameterNames[j],¶meterValues[j]); for (int j=0; j < assignmentVariables.size(); ++j) p.DefineVar(assignmentVariables[j],&assignmentValues[j]); try { p.Eval(); //resposes for the trigger vector<mu::Parser> responses; for (int j=0; j < eventResponses[i].size(); ++j) { mu::Parser p; addSBMLFunctions(p); p.SetExpr(eventResponses[i][j]); try { p.Eval(); responses.push_back(p); } catch(...) {} } if (responses.size() > 0) { triggerEqns.push_back(p); responseEqns.push_back(responses); } } catch(...) { //assignmentVariables.clear(); //assignmentEqns.clear(); break; } } //delete params; //delete reacs; } }
//static void SBMLUtils::collectIds(Model* pModel, std::map<std::string, const SBase*>& ids, std::map<std::string, const SBase*>& metaIds) { if (pModel != NULL) { // the model itself SBase* pSBase = NULL; std::string id; if (pModel->isSetId()) { id = pModel->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pModel->isSetMetaId()) { id = pModel->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } // ListOfFunctionDefinitions pSBase = pModel->getListOfFunctionDefinitions(); if (pSBase != NULL) { if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } // all FunctionDefinitions unsigned int i, iMax = pModel->getListOfFunctionDefinitions()->size(); for (i = 0; i < iMax; ++i) { pSBase = pModel->getListOfFunctionDefinitions()->get(i); if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } } // ListOfUnitDefinition pSBase = pModel->getListOfUnitDefinitions(); if (pSBase != NULL) { if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } // all UnitDefinitions // for each UnitDefinition: ListOfUnits, each Unit in ListOfUnits unsigned int i, iMax = pModel->getListOfUnitDefinitions()->size(); for (i = 0; i < iMax; ++i) { /* UnitDefinitions have their ids in a different namespace so we only consider meta ids. */ UnitDefinition* pUDef = pModel->getUnitDefinition(i); assert(pUDef != NULL); if (pUDef->isSetMetaId()) { id = pUDef->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pUDef)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } ListOf* pList = pUDef->getListOfUnits(); if (pList != NULL) { if (pList->isSetMetaId()) { id = pList->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pList)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } unsigned j, jMax = pList->size(); for (j = 0; j < jMax; ++j) { pSBase = pList->get(j); assert(pSBase != NULL); if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } } } } // ListOfCompartmentTypes pSBase = pModel->getListOfCompartmentTypes(); if (pSBase != NULL) { if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } // each compartment type unsigned int i, iMax = pModel->getListOfCompartmentTypes()->size(); for (i = 0; i < iMax; ++i) { pSBase = pModel->getCompartmentType(i); assert(pSBase != NULL); if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } } // ListOfSpeciesTypes pSBase = pModel->getListOfSpeciesTypes(); if (pSBase != NULL) { if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } // each species type unsigned int i, iMax = pModel->getListOfSpeciesTypes()->size(); for (i = 0; i < iMax; ++i) { pSBase = pModel->getSpeciesType(i); assert(pSBase != NULL); if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } } // ListOfCompartments pSBase = pModel->getListOfCompartments(); if (pSBase != NULL) { if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } // all compartments unsigned int i, iMax = pModel->getListOfCompartments()->size(); for (i = 0; i < iMax; ++i) { pSBase = pModel->getCompartment(i); assert(pSBase != NULL); if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } } // ListOfSpecies pSBase = pModel->getListOfSpecies(); if (pSBase != NULL) { if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } // all species unsigned int i, iMax = pModel->getListOfSpecies()->size(); for (i = 0; i < iMax; ++i) { pSBase = pModel->getSpecies(i); assert(pSBase != NULL); if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } } // ListOfParameters pSBase = pModel->getListOfParameters(); if (pSBase != NULL) { if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } // each parameter unsigned int i, iMax = pModel->getListOfParameters()->size(); for (i = 0; i < iMax; ++i) { pSBase = pModel->getParameter(i); assert(pSBase != NULL); if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } } // ListOfInitialAssignments pSBase = pModel->getListOfInitialAssignments(); if (pSBase != NULL) { if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } // each initial assignment unsigned int i, iMax = pModel->getListOfInitialAssignments()->size(); for (i = 0; i < iMax; ++i) { pSBase = pModel->getInitialAssignment(i); assert(pSBase != NULL); // initial assignments have no ids if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } } // ListOfRules pSBase = pModel->getListOfRules(); if (pSBase != NULL) { if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } // each rule unsigned int i, iMax = pModel->getListOfRules()->size(); for (i = 0; i < iMax; ++i) { pSBase = pModel->getRule(i); assert(pSBase != NULL); // rules don't have ids if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } } // ListOfConstraints pSBase = pModel->getListOfConstraints(); if (pSBase != NULL) { if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } // each constraint unsigned int i, iMax = pModel->getListOfConstraints()->size(); for (i = 0; i < iMax; ++i) { pSBase = pModel->getConstraint(i); assert(pSBase != NULL); // constraints don't have ids if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } } // ListOfReactions pSBase = pModel->getListOfReactions(); if (pSBase != NULL) { if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } // all reactions unsigned int i, iMax = pModel->getListOfReactions()->size(); for (i = 0; i < iMax; ++i) { Reaction* pReaction = pModel->getReaction(i); assert(pReaction != NULL); if (pReaction->isSetId()) { id = pReaction->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pReaction)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pReaction->isSetMetaId()) { id = pReaction->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pReaction)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } // for each reaction: ListOfSubstrates, each substrate, ListOfProducts, each // Product, ListOfModifieres, each modifier, KineticLaw, ListOfparameters, // each parameter if (pReaction->getListOfReactants() != NULL) { pSBase = pReaction->getListOfReactants(); if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } unsigned int j, jMax = pReaction->getListOfReactants()->size(); for (j = 0; j < jMax; ++j) { pSBase = pReaction->getReactant(j); assert(pSBase != NULL); // since L2V2 species references can have ids if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } } if (pReaction->getListOfProducts() != NULL) { pSBase = pReaction->getListOfProducts(); if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } unsigned int j, jMax = pReaction->getListOfProducts()->size(); for (j = 0; j < jMax; ++j) { pSBase = pReaction->getProduct(j); assert(pSBase != NULL); // since L2V2 species references can have ids if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } } if (pReaction->getListOfModifiers() != NULL) { pSBase = pReaction->getListOfModifiers(); if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } unsigned int j, jMax = pReaction->getListOfModifiers()->size(); for (j = 0; j < jMax; ++j) { pSBase = pReaction->getModifier(j); assert(pSBase != NULL); // since L2V2 species references can have ids if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } } KineticLaw* pKLaw = pReaction->getKineticLaw(); if (pKLaw != NULL) { if (pKLaw->isSetMetaId()) { id = pKLaw->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pKLaw)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } pSBase = pKLaw->getListOfParameters(); if (pSBase != NULL) { if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } unsigned int j, jMax = pKLaw->getListOfParameters()->size(); for (j = 0; j < jMax; ++j) { pSBase = pKLaw->getParameter(j); assert(pSBase != NULL); // local parameters have their ids in a // different namespace if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } } } } } // ListOfEvents pSBase = pModel->getListOfEvents(); if (pSBase != NULL) { if (pSBase->isSetId()) { id = pSBase->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } // each event unsigned int i, iMax = pModel->getListOfEvents()->size(); for (i = 0; i < iMax; ++i) { Event* pEvent = pModel->getEvent(i); assert(pEvent != NULL); if (pEvent->isSetId()) { id = pEvent->getId(); if (ids.find(id) == ids.end()) { ids.insert(std::pair<const std::string, const SBase*>(id, pEvent)); } else { CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str()); } } if (pEvent->isSetMetaId()) { id = pEvent->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pEvent)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } // in each event Trigger,Delay,ListOfEventAssignments, each event assignment if (pEvent->isSetTrigger()) { pSBase = pEvent->getTrigger(); assert(pSBase != NULL); if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } if (pEvent->isSetDelay()) { pSBase = pEvent->getDelay(); assert(pSBase != NULL); if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } if (pEvent->getListOfEventAssignments() != NULL) { pSBase = pEvent->getListOfEventAssignments(); if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } unsigned int j, jMax = pEvent->getListOfEventAssignments()->size(); for (j = 0; j < jMax; ++j) { pSBase = pEvent->getEventAssignment(j); assert(pSBase != NULL); if (pSBase->isSetMetaId()) { id = pSBase->getMetaId(); if (metaIds.find(id) == metaIds.end()) { metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase)); } else { CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str()); } } } } } } } }