/* convert from L1 to L3 */ void Model::convertL3ToL1 () { // // Level 3 allows a model to be specified without a Compartment. However // this is not valid in Level 1. Thus if a L3 model has no Compartment // one must be included // if (getNumCompartments() == 0) { createCompartment()->setId(ASSIGNED_COMPARTMENT); } dealWithModelUnits(); dealWithAssigningL1Stoichiometry(*this, false); for (unsigned int i = 0; i < getNumReactions(); i++) { Reaction *r = getReaction(i); if (r->isSetKineticLaw()) { KineticLaw *kl = r->getKineticLaw(); for (unsigned int j = 0; j < kl->getNumLocalParameters(); j++) { Parameter *lp = new Parameter(getLevel(), getVersion()); (*lp) = *(kl->getLocalParameter(j)); kl->addParameter(lp); } } } }
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 getConstant(string id, Model* model, const map<string, vector<double> >& results) { if (variesIn(id, results)) return false; SBase* element = model->getElementBySId(id); Compartment* comp = static_cast<Compartment*>(element); Species* species = static_cast<Species*>(element); Parameter* param = static_cast<Parameter*>(element); Reaction* rxn = static_cast<Reaction*>(element); SpeciesReference* sr= static_cast<SpeciesReference*>(element); switch (element->getTypeCode()) { case SBML_COMPARTMENT: if (!comp->getConstant()) return false; break; case SBML_SPECIES: if (!species->getConstant()) return false; break; case SBML_PARAMETER: if (!param->getConstant()) return false; break; case SBML_REACTION: if (rxn->isSetKineticLaw()) { if (variesIn(rxn->getKineticLaw()->getMath(), model, results)) return false; } break; case SBML_SPECIES_REFERENCE: if (!sr->getConstant()) return false; break; default: assert(false); //Uncaught type! return true; break; } return true; }
void Model::convertParametersToLocals(unsigned int level, unsigned int version) { for (unsigned int i = 0; i < getNumReactions(); i++) { Reaction *r = getReaction(i); if (r->isSetKineticLaw()) { KineticLaw *kl = r->getKineticLaw(); for (unsigned int j = 0; j < kl->getNumParameters(); j++) { LocalParameter *lp = new LocalParameter(level, version); (*lp) = *(kl->getParameter(j)); kl->addLocalParameter(lp); } } } }
/* * Checks that all variables referenced in FunctionDefinition bodies are * bound variables (function arguments). */ void KineticLawVars::check_ (const Model& m, const Reaction& r) { unsigned int n; /* create list of all species in the reaction */ for (n = 0; n < r.getNumReactants(); n++) { mSpecies.append(r.getReactant(n)->getSpecies()); } for (n = 0; n < r.getNumProducts(); n++) { mSpecies.append(r.getProduct(n)->getSpecies()); } for (n = 0; n < r.getNumModifiers(); n++) { mSpecies.append(r.getModifier(n)->getSpecies()); } if ( r.isSetKineticLaw() && r.getKineticLaw()->isSetMath() ) { const ASTNode* math = r.getKineticLaw()->getMath(); List* names = math->getListOfNodes( ASTNode_isName ); for (n = 0; n < names->getSize(); ++n) { ASTNode* node = static_cast<ASTNode*>( names->get(n) ); string name = node->getName() ? node->getName() : ""; if (m.getSpecies(name) != NULL && !mSpecies.contains(name) ) logUndefined(r, name); } delete names; } mSpecies.clear(); }
/* convert from L1 to L3 */ void Model::convertL3ToL2 (bool strict) { dealWithModelUnits(); dealWithStoichiometry(); dealWithEvents(strict); for (unsigned int i = 0; i < getNumReactions(); i++) { Reaction *r = getReaction(i); if (r->isSetKineticLaw()) { KineticLaw *kl = r->getKineticLaw(); for (unsigned int j = 0; j < kl->getNumLocalParameters(); j++) { Parameter *lp = new Parameter(getLevel(), getVersion()); (*lp) = *(kl->getLocalParameter(j)); kl->addParameter(lp); } } } }
int main (int argc, char* argv[]) { if (argc != 2) { cout << endl << "Usage: printNotes filename" << endl << endl; return 1; } unsigned int i,j; const char* filename = argv[1]; SBMLDocument* document; SBMLReader reader; document = reader.readSBML(filename); unsigned int errors = document->getNumErrors(); cout << endl; cout << "filename: " << filename << endl; cout << endl; if(errors > 0) { document->printErrors(cerr); delete document; return errors; } /* Model */ Model* m = document->getModel(); printNotes(m); for(i=0; i < m->getNumReactions(); i++) { Reaction* re = m->getReaction(i); printNotes(re); /* SpeciesReference (Reacatant) */ for(j=0; j < re->getNumReactants(); j++) { SpeciesReference* rt = re->getReactant(j); if (rt->isSetNotes()) cout << " "; printNotes(rt, (rt->isSetSpecies() ? rt->getSpecies() : std::string("")) ); } /* SpeciesReference (Product) */ for(j=0; j < re->getNumProducts(); j++) { SpeciesReference* rt = re->getProduct(j); if (rt->isSetNotes()) cout << " "; printNotes(rt, (rt->isSetSpecies() ? rt->getSpecies() : std::string("")) ); } /* ModifierSpeciesReference (Modifier) */ for(j=0; j < re->getNumModifiers(); j++) { ModifierSpeciesReference* md = re->getModifier(j); if (md->isSetNotes()) cout << " "; printNotes(md, (md->isSetSpecies() ? md->getSpecies() : std::string("")) ); } /* Kineticlaw */ if(re->isSetKineticLaw()) { KineticLaw* kl = re->getKineticLaw(); if (kl->isSetNotes()) cout << " "; printNotes(kl); /* Parameter */ for(j=0; j < kl->getNumParameters(); j++) { Parameter* pa = kl->getParameter(j); if (pa->isSetNotes()) cout << " "; printNotes(pa); } } } /* Species */ for(i=0; i < m->getNumSpecies(); i++) { Species* sp = m->getSpecies(i); printNotes(sp); } /* Compartment */ for(i=0; i < m->getNumCompartments(); i++) { Compartment* sp = m->getCompartment(i); printNotes(sp); } /* FunctionDefinition */ for(i=0; i < m->getNumFunctionDefinitions(); i++) { FunctionDefinition* sp = m->getFunctionDefinition(i); printNotes(sp); } /* UnitDefinition */ for(i=0; i < m->getNumUnitDefinitions(); i++) { UnitDefinition* sp = m->getUnitDefinition(i); printNotes(sp); } /* Parameter */ for(i=0; i < m->getNumParameters(); i++) { Parameter* sp = m->getParameter(i); printNotes(sp); } /* Rule */ for(i=0; i < m->getNumRules(); i++) { Rule* sp = m->getRule(i); printNotes(sp); } /* InitialAssignment */ for(i=0; i < m->getNumInitialAssignments(); i++) { InitialAssignment* sp = m->getInitialAssignment(i); printNotes(sp); } /* Event */ for(i=0; i < m->getNumEvents(); i++) { Event* sp = m->getEvent(i); printNotes(sp); /* Trigger */ if(sp->isSetTrigger()) { const Trigger* tg = sp->getTrigger(); if (tg->isSetNotes()) cout << " "; printNotes(const_cast<Trigger*>(tg)); } /* Delay */ if(sp->isSetDelay()) { const Delay* dl = sp->getDelay(); if (dl->isSetNotes()) cout << " "; printNotes(const_cast<Delay*>(dl)); } /* EventAssignment */ for(j=0; j < sp->getNumEventAssignments(); j++) { EventAssignment* ea = sp->getEventAssignment(j); if (ea->isSetNotes()) cout << " "; printNotes(ea); } } /* SpeciesType */ for(i=0; i < m->getNumSpeciesTypes(); i++) { SpeciesType* sp = m->getSpeciesType(i); printNotes(sp); } /* Constraint */ for(i=0; i < m->getNumConstraints(); i++) { Constraint* sp = m->getConstraint(i); printNotes(sp); } delete document; return errors; }
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 test000009::test_references_to_species() { // load the CPS file // export to SBML // check the resulting SBML model CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; std::istringstream iss(test000009::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() == 2); // there are two rules, one is the rule for the compartment AssignmentRule* pRule = dynamic_cast<AssignmentRule*>(pModel->getRule(0)); CPPUNIT_ASSERT(pRule != NULL); CPPUNIT_ASSERT(pModel->getNumParameters() == 1); Parameter* pParameter = pModel->getParameter(0); CPPUNIT_ASSERT(pParameter != NULL); if (pRule->getVariable() != pParameter->getId()) { pRule = dynamic_cast<AssignmentRule*>(pModel->getRule(1)); } CPPUNIT_ASSERT(pRule->getVariable() == pParameter->getId()); const ASTNode* pMath = pRule->getMath(); CPPUNIT_ASSERT(pMath != NULL); // the expression should be the species divided by the volume CPPUNIT_ASSERT(pMath->getType() == AST_DIVIDE); 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 // the code that multiplies the reaction by the compartments volume // recognizes the division of the species by the compartment and cancels // those two 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)->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()); }
//create REACTION void SbmlReader::createReaction( map< string,Id > &molMap ) { map< string,double > rctMap; map< string,double >::iterator rctMap_iter; map< string,double >pdtMap; map< string,double >::iterator pdtMap_iter; map< string,Eref >::iterator elemt_iter; map< string,EnzymeInfo >enzInfoMap; double rctorder,pdtorder; static const Cinfo* moleculeCinfo = initMoleculeCinfo(); static const Finfo* reacFinfo =moleculeCinfo->findFinfo( "reac" ); static const Cinfo* reactionCinfo = initReactionCinfo(); static const Finfo* subFinfo = reactionCinfo->findFinfo( "sub" ); static const Finfo* prdFinfo = reactionCinfo->findFinfo( "prd" ); static const Finfo* kfFinfo = reactionCinfo->findFinfo( "kf" ); static const Finfo* kbFinfo = reactionCinfo->findFinfo( "kb" ); Reaction* reac; for ( unsigned int r = 0; r < model_->getNumReactions(); r++ ) { reac = model_->getReaction( r ); const string id=reac->getId(); //cout<<"reaction is "<<id<<endl; std::string name; if ( reac->isSetName() ){ name = reac->getName(); } string grpname = getAnnotation( reac,enzInfoMap ); if ( (grpname != "") && (enzInfoMap[grpname].stage == 3) ) setupEnzymaticReaction( enzInfoMap[grpname],grpname ); else if ( grpname == "" ) { if ( reac->getNumModifiers()> 0 ) setupMMEnzymeReaction( reac,id ); else{ bool rev=reac->getReversible(); bool fast=reac->getFast(); if ( fast ){ cout<<"warning: for now fast attribute is not handled"<<endl; errorFlag_ = true; } int numRcts = reac->getNumReactants(); int numPdts = reac->getNumProducts(); if ( numRcts == 0 && numPdts != 0 ){ const SpeciesReference* pdt = reac->getProduct( 0 ); std::string spName = pdt->getSpecies(); Id parent = molMap.find( spName )->second; //gives compartment of spName string parentCompt = parent()->name(); //cout<<"parent of reactant :"<<parentCompt<<endl; ostringstream spId; spId <<id<<"_Src"; molecule_ = Neutral::create( "Molecule",spId.str(),parent,Id::scratchId() );//create Molecule molMap[spId.str()] = parent; elmtMap_[spId.str()] = Eref( molecule_ ); ::set< double >( molecule_,"conc", 1 ); ::set< int >( molecule_,"mode",4 ); reaction_ = Neutral::create( "Reaction",id,parent,Id::scratchId() ); //create Reaction Eref( reaction_ ).add( subFinfo->msg(),elmtMap_[spId.str()],reacFinfo->msg(),ConnTainer::Default ); } else{ const SpeciesReference* rect=reac->getReactant(0); std::string sp=rect->getSpecies(); Id m = molMap.find(sp)->second; //gives compartment of sp reaction_ = Neutral::create( "Reaction",id,m,Id::scratchId() ); //create Reaction double rctcount=0.0; rctMap.clear(); for ( unsigned int rt=0;rt<reac->getNumReactants();rt++ ) { const SpeciesReference* rct=reac->getReactant(rt); sp=rct->getSpecies(); rctMap_iter = rctMap.find(sp); if ( rctMap_iter != rctMap.end() ){ rctcount = rctMap_iter->second; } else { rctcount = 0.0; } rctcount += rct->getStoichiometry(); rctMap[sp] = rctcount; for ( int i=0;(int)i<rct->getStoichiometry();i++ ) { Eref(reaction_).add( subFinfo->msg(),elmtMap_[sp],reacFinfo->msg(),ConnTainer::Default ); } } } double pdtcount = 0.0; pdtMap.clear(); for ( unsigned int pt=0;pt<reac->getNumProducts();pt++ ) { const SpeciesReference* pdt=reac->getProduct(pt); std::string sp=pdt->getSpecies(); pdtMap_iter = pdtMap.find(sp); if ( pdtMap_iter != pdtMap.end() ){ pdtcount = pdtMap_iter->second; } else { pdtcount = 0.0; } pdtcount += pdt->getStoichiometry(); pdtMap[sp] = pdtcount; for ( int i=0;i<pdt->getStoichiometry();i++ ) { Eref(reaction_).add( prdFinfo->msg(),elmtMap_[sp],reacFinfo->msg(),ConnTainer::Default ); } } //order of reactants rctorder = 0.0; string rsp = "",psp = ""; for ( rctMap_iter=rctMap.begin();rctMap_iter!=rctMap.end();rctMap_iter++ ) { rctorder += rctMap_iter->second; rsp=rctMap_iter->first; //species of the reactant } //cout<<"rct order = "<<rctorder<<endl; //order of products pdtorder = 0.0; for ( pdtMap_iter=pdtMap.begin();pdtMap_iter!=pdtMap.end();pdtMap_iter++ ) { pdtorder += pdtMap_iter->second; psp=pdtMap_iter->first; //species of the product } //cout<<"pdt order = "<<pdtorder<<endl; if ( reac->isSetKineticLaw() ) { KineticLaw * klaw=reac->getKineticLaw(); //vector< double > rate = getKLaw( klaw,rev ); vector< double > rate; rate.clear(); getKLaw( klaw,rev,rate ); if ( errorFlag_ ) return; else if ( !errorFlag_ ){ ::set< double >( reaction_, kfFinfo, rate[0] ); ::set< double >( reaction_, kbFinfo, rate[1] ); } } }//else modifier }//else }//reaction }//create reaction
LIBSBML_CPP_NAMESPACE_USE int main (int argc, char *argv[]) { if (argc != 2) { cout << endl << "Usage: printUnits filename" << endl << endl; return 1; } const char* filename = argv[1]; SBMLDocument* document = readSBML(filename); if (document->getNumErrors() > 0) { cerr << "Encountered the following SBML errors:" << endl; document->printErrors(cerr); return 1; } Model* model = document->getModel(); if (model == 0) { cout << "No model present." << endl; return 1; } unsigned int i,j; for (i = 0; i < model->getNumSpecies(); i++) { Species* s = model->getSpecies(i); cout << "Species " << i << ": " << UnitDefinition::printUnits(s->getDerivedUnitDefinition()) << endl; } for (i = 0; i < model->getNumCompartments(); i++) { Compartment *c = model->getCompartment(i); cout << "Compartment " << i << ": " << UnitDefinition::printUnits(c->getDerivedUnitDefinition()) << endl; } for (i = 0; i < model->getNumParameters(); i++) { Parameter *p = model->getParameter(i); cout << "Parameter " << i << ": " << UnitDefinition::printUnits(p->getDerivedUnitDefinition()) << endl; } for (i = 0; i < model->getNumInitialAssignments(); i++) { InitialAssignment *ia = model->getInitialAssignment(i); cout << "InitialAssignment " << i << ": " << UnitDefinition::printUnits(ia->getDerivedUnitDefinition()) << endl; cout << " undeclared units: "; cout << (ia->containsUndeclaredUnits() ? "yes\n" : "no\n"); } for (i = 0; i < model->getNumEvents(); i++) { Event *e = model->getEvent(i); cout << "Event " << i << ": " << endl; if (e->isSetDelay()) { cout << "Delay: " << UnitDefinition::printUnits(e->getDelay()->getDerivedUnitDefinition()) << endl; cout << " undeclared units: "; cout << (e->getDelay()->containsUndeclaredUnits() ? "yes\n" : "no\n"); } for (j = 0; j < e->getNumEventAssignments(); j++) { EventAssignment *ea = e->getEventAssignment(j); cout << "EventAssignment " << j << ": " << UnitDefinition::printUnits(ea->getDerivedUnitDefinition()) << endl; cout << " undeclared units: "; cout << (ea->containsUndeclaredUnits() ? "yes\n" : "no\n"); } } for (i = 0; i < model->getNumReactions(); i++) { Reaction *r = model->getReaction(i); cout << "Reaction " << i << ": " << endl; if (r->isSetKineticLaw()) { cout << "Kinetic Law: " << UnitDefinition::printUnits(r->getKineticLaw()->getDerivedUnitDefinition()) << endl; cout << " undeclared units: "; cout << (r->getKineticLaw()->containsUndeclaredUnits() ? "yes\n" : "no\n"); } for (j = 0; j < r->getNumReactants(); j++) { SpeciesReference *sr = r->getReactant(j); if (sr->isSetStoichiometryMath()) { cout << "Reactant stoichiometryMath" << j << ": " << UnitDefinition::printUnits(sr->getStoichiometryMath()->getDerivedUnitDefinition()) << endl; cout << " undeclared units: "; cout << (sr->getStoichiometryMath()->containsUndeclaredUnits() ? "yes\n" : "no\n"); } } for (j = 0; j < r->getNumProducts(); j++) { SpeciesReference *sr = r->getProduct(j); if (sr->isSetStoichiometryMath()) { cout << "Product stoichiometryMath" << j << ": " << UnitDefinition::printUnits(sr->getStoichiometryMath()->getDerivedUnitDefinition()) << endl; cout << " undeclared units: "; cout << (sr->getStoichiometryMath()->containsUndeclaredUnits() ? "yes\n" : "no\n"); } } } for (i = 0; i < model->getNumRules(); i++) { Rule *r = model->getRule(i); cout << "Rule " << i << ": " << UnitDefinition::printUnits(r->getDerivedUnitDefinition()) << endl; cout << " undeclared units: "; cout << (r->containsUndeclaredUnits() ? "yes\n" : "no\n"); } delete document; return 0; }
void SbmlReader::createReaction(const map< string, Id > &molSidcmptMIdMap ) { Reaction* reac; map< string,double > rctMap; map< string,double >::iterator rctMap_iter; map< string,double >prdMap; map< string,double >::iterator prdMap_iter; map< string,EnzymeInfo >enzInfoMap; for ( unsigned int r = 0; r < model_->getNumReactions(); r++ ) { Id reaction_; reac = model_->getReaction( r ); noOfsub_ = 0; noOfprd_ = 0; std:: string id; //=reac->getId(); if ( reac->isSetId() ) id = reac->getId(); std::string name; if ( reac->isSetName() ) { name = reac->getName(); name = nameString(name); } if (name.empty()) { if (id.empty()) assert("Reaction id and name is empty"); else name = id; } string grpname = getAnnotation( reac,enzInfoMap ); if ( (grpname != "") && (enzInfoMap[grpname].stage == 3) ) { setupEnzymaticReaction( enzInfoMap[grpname],grpname ,molSidcmptMIdMap,name); } //if (grpname != "") // { //cout << "\n enz matic reaction " << enzInfoMap[grpname].stage; //setupEnzymaticReaction( enzInfoMap[grpname],grpname ,molSidcmptMIdMap); //} else if ( grpname == "" ) { if (reac->getNumModifiers() > 0) setupMMEnzymeReaction( reac,id,name ,molSidcmptMIdMap); else { bool rev=reac->getReversible(); bool fast=reac->getFast(); if ( fast ) { cout<<"warning: for now fast attribute is not handled"<<endl; errorFlag_ = true; } int numRcts = reac->getNumReactants(); int numPdts = reac->getNumProducts(); if ( numRcts == 0 && numPdts != 0 ) { cout << "Reaction with zero Substrate is not possible but exist in this model"; const SpeciesReference* pdt = reac->getProduct( 0 ); std::string spName = pdt->getSpecies(); Id parent = molSidcmptMIdMap.find( spName )->second; //gives compartment of spName cout << " \n \t ################################# Sub = 0 and prd != 0 need to the reac ############### "; const SpeciesReference* rect=reac->getReactant(0); std::string sp=rect->getSpecies(); Id comptRef = molSidcmptMIdMap.find(sp)->second; //gives compartment of sp Id meshEntry = Neutral::child( comptRef.eref(), "mesh" ); Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() ); reaction_ = shell->doCreate("Reac", meshEntry, name, 1); //shell->doAddMsg( "Single", meshEntry, "remeshReacs", reaction_, "remesh"); //Get Substrate addSubPrd(reac,reaction_,"prd"); } //if numRcts == 0 else { const SpeciesReference* rect=reac->getReactant(0); std::string sp=rect->getSpecies(); Id comptRef = molSidcmptMIdMap.find(sp)->second; //gives compartment of sp Id meshEntry = Neutral::child( comptRef.eref(), "mesh" ); Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() ); reaction_ = shell->doCreate("Reac", comptRef, name, 1); //shell->doAddMsg( "Single", meshEntry, "remeshReacs", reaction_, "remesh"); //Get Substrate addSubPrd(reac,reaction_,"sub"); //Get Product addSubPrd(reac,reaction_,"prd"); } if ( reac->isSetKineticLaw() ) { KineticLaw * klaw=reac->getKineticLaw(); //vector< double > rate = getKLaw( klaw,rev ); vector< double > rate; rate.clear(); getKLaw( klaw,rev,rate ); if ( errorFlag_ ) return; else if ( !errorFlag_ ) { //cout << " Reaction name " << name << " kf " << rate[0] << " kb " << rate[1]<<endl; Field < double > :: set( reaction_, "Kf", rate[0] ); Field < double > :: set( reaction_, "Kb", rate[1] ); /*if (numRcts > 1) rate[0] = rate[0]*pow(1e3,1.0); cout << "Reaction " << id << " " << name << " " << rate[0] << " " << rate[1]<<endl; Field < double > :: set( reaction_, "Kf", rate[0] ); Field < double > :: set( reaction_, "Kb", rate[1] ); */ } } //issetKineticLaw } //else } // else grpname == "" }//for unsigned } //reaction