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; }
/* create MOLECULE */ map< string,Id > SbmlReader::createMolecule( map< string,Id > &idMap ) { map<string,Id>molMap; static const Cinfo* moleculeCinfo = initMoleculeCinfo(); static const Finfo* modeFinfo = moleculeCinfo->findFinfo( "mode" ); static const Finfo* nInitFinfo = moleculeCinfo->findFinfo( "nInit" ); static const Cinfo* kincomptCinfo = initKinComptCinfo(); static const Finfo* dimensionFinfo = kincomptCinfo->findFinfo( "numDimensions" ); static const Finfo* sizeFinfo = kincomptCinfo->findFinfo( "size" ); int num_species = model_->getNumSpecies(); //cout << "num species: " << num_species << endl; for ( int sindex = 0; sindex < num_species; sindex++ ) { Species* s = model_->getSpecies(sindex); if (!s){ //cout << "species " << sindex << " is nul" << endl; continue; } std::string compt = ""; if ( s->isSetCompartment() ) compt = s->getCompartment(); if (compt.length()< 1){ cout << "compt is empty for species "<< sindex << endl; continue; } string id = s->getId(); //cout<<"species is :"<<id<<endl; if (id.length() < 1){ continue; } /*std::string name = ""; if ( s->isSetName() ){ name = s->getName(); }*/ Id comptEl = idMap[compt]; molecule_ = Neutral::create( "Molecule",id,comptEl,Id::scratchId() );//create Molecule molMap[id] = comptEl; elmtMap_[id] = Eref( molecule_ ); //printNotes(s); UnitDefinition * ud = s->getDerivedUnitDefinition(); assert(ud != NULL); /*string udef = UnitDefinition::printUnits(ud); //cout << "species unit :" << udef << endl;*/ double initvalue =0.0; if ( s->isSetInitialConcentration() ) initvalue = s->getInitialConcentration(); else if ( s->isSetInitialAmount() ) initvalue = s->getInitialAmount() ; else { cout << "Invalid SBML: Either initialConcentration or initialAmount must be set." << endl; return molMap; } double transvalue = transformUnits(1,ud); //cout << "initAmount: " << initvalue << endl; transvalue *= initvalue; //cout << "transvalue: " << transvalue << endl; unsigned int dimension; get< unsigned int >( comptEl.eref(), dimensionFinfo,dimension ); bool initconc = s->isSetInitialConcentration(); if ( dimension > 0 && initconc) { double size; get< double > (comptEl.eref(),sizeFinfo,size); transvalue *= size; } ::set< double >( molecule_, nInitFinfo, transvalue ); //initialAmount bool cons=s->getConstant(); bool bcondition = s->getBoundaryCondition(); if (cons){ ::set< int >( molecule_,modeFinfo,4 ); //cout << "set constant 4" << endl; }else if (bcondition) { ::set< int >( molecule_,modeFinfo,1 ); //cout << "set constant 1" << endl; }else { ::set< int >( molecule_,modeFinfo,0 ); //cout << "set constant 0" << endl; } } return molMap; }
/* create MOLECULE */ const SbmlReader::sbmlStr_mooseId SbmlReader::createMolecule( map< string,Id > &comptSidMIdMap) { Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() ); map< string, Id >molSidcmptMIdMap; double transvalue = 0.0; int num_species = model_->getNumSpecies(); if (num_species == 0) { baseId = Id(); errorFlag_ = true; return molSidcmptMIdMap; } for ( int sindex = 0; sindex < num_species; sindex++ ) { Species* spe = model_->getSpecies(sindex); if (!spe) { continue; } std::string compt = ""; if ( spe->isSetCompartment() ) { compt = spe->getCompartment(); } if (compt.length()< 1) { //cout << "compt is empty for species "<< sindex << endl; continue; } string id = spe->getId(); if (id.length() < 1) { continue; } std::string name = ""; if ( spe->isSetName() ) { name = spe->getName(); name = nameString(name); } if (name.empty()) name = id; double initvalue =0.0; if ( spe->isSetInitialConcentration() ) initvalue = spe->getInitialConcentration(); else if ( spe->isSetInitialAmount() ) initvalue = spe->getInitialAmount() ; else { unsigned int nr = model_->getNumRules(); bool found = false; for ( unsigned int r = 0; r < nr; r++ ) { Rule * rule = model_->getRule(r); bool assignRule = rule->isAssignment(); if ( assignRule ) { string rule_variable = rule->getVariable(); if (rule_variable.compare(id) == 0) { found = true; break; } } } if (found == false) { cout << "Invalid SBML: Either initialConcentration or initialAmount must be set or it should be found in assignmentRule but non happening for " << spe->getName() <<endl; return molSidcmptMIdMap; } } Id comptEl = comptSidMIdMap[compt]; Id meshEntry = Neutral::child( comptEl.eref(), "mesh" ); bool constant = spe->getConstant(); bool boundaryCondition = spe->getBoundaryCondition(); if (boundaryCondition == true) cout << "Pools having BoundaryCondition true " << name <<endl; Id pool; //If constant is true then its equivalent to BuffPool in moose if (constant == true) //if( (boundaryCondition == true) && (constant==false)) pool = shell->doCreate("BufPool",comptEl,name,1); else pool = shell->doCreate("Pool", comptEl, name ,1); molSidcmptMIdMap[id] = comptEl; //Map to Molecule SBML id to Moose Id molSidMIdMap_[id] = pool; //shell->doAddMsg( "OneToOne",pool, "mesh", meshEntry, "mesh" ); bool bcondition = spe->getBoundaryCondition(); if ( constant == true && bcondition == false) cout <<"The species "<< name << " should not appear in reactant or product as per sbml Rules"<< endl; unsigned int spatialDimen =Field< unsigned int >::get( comptEl, "numDimensions"); UnitDefinition * ud = spe->getDerivedUnitDefinition(); assert(ud != NULL); bool hasonlySubUnit = spe->getHasOnlySubstanceUnits(); //double v = Field< double >::get( comptEl.path(), "volume" ); transvalue = transformUnits(1,ud,"substance",hasonlySubUnit); if (hasonlySubUnit) { // In Moose, no. of molecules (nInit) and unit is "item" if (spatialDimen > 0 && spe->isSetInitialAmount() ) { //transvalue *= initvalue; initvalue *=transvalue; Field < double> :: set( pool, "nInit", initvalue); } } else { //transvalue *=initvalue; initvalue *=transvalue; Field <double> :: set(pool, "concInit",initvalue); } //cout << " poolMap_ "<< name << " " <<transvalue << " "<< hasonlySubUnit; //poolMap_.insert(make_pair(id,make_tuple(name,transvalue,hasonlySubUnit))); } return molSidcmptMIdMap; }