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"); } } } } }
void Model::assignRequiredValues() { // when converting to L3 some attributes which have default values in L1/L2 // but are required in L3 are not present or set unsigned int i, n; if (getNumUnitDefinitions() > 0) { for (i = 0; i < getNumUnitDefinitions(); i++) { for (n = 0; n < getUnitDefinition(i)->getNumUnits(); n++) { Unit *u = getUnitDefinition(i)->getUnit(n); if (!u->isSetExponent()) u->setExponent(1.0); if (!u->isSetScale()) u->setScale(0); if (!u->isSetMultiplier()) u->setMultiplier(1.0); } } } if (getNumCompartments() > 0) { for (i = 0; i < getNumCompartments(); i++) { Compartment *c = getCompartment(i); c->setConstant(c->getConstant()); } } if (getNumSpecies() > 0) { for (i = 0; i < getNumSpecies(); i++) { Species * s = getSpecies(i); s->setBoundaryCondition(s->getBoundaryCondition()); s->setHasOnlySubstanceUnits(s->getHasOnlySubstanceUnits()); s->setConstant(s->getConstant()); } } if (getNumParameters() > 0) { for (i = 0; i < getNumParameters(); i++) { Parameter * p = getParameter(i); p->setConstant(p->getConstant()); } } if (getNumReactions() > 0) { for (i = 0; i < getNumReactions(); i++) { Reaction * r = getReaction(i); r->setFast(r->getFast()); r->setReversible(r->getReversible()); if (r->getNumReactants() > 0) { for (n = 0; n < r->getNumReactants(); n++) { SpeciesReference *sr = r->getReactant(n); if (sr->isSetStoichiometryMath()) { sr->setConstant(false); } else { sr->setConstant(true); } } } if (r->getNumProducts() > 0) { for (n = 0; n < r->getNumProducts(); n++) { SpeciesReference *sr = r->getProduct(n); if (sr->isSetStoichiometryMath()) { sr->setConstant(false); } else { sr->setConstant(true); } } } } } if (getNumEvents() > 0) { for (i = 0; i < getNumEvents(); i++) { Event * e = getEvent(i); e->setUseValuesFromTriggerTime(e->getUseValuesFromTriggerTime()); if (e->isSetTrigger()) { Trigger *t = e->getTrigger(); t->setPersistent(true); t->setInitialValue(true); } } } }
//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
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