示例#1
0
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");
        }
      }
    }
  }
}
示例#2
0
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;
}
示例#3
0
/* 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 
AssignmentCycles::addReactionDependencies(const Model& m, const Reaction& object)
{
  unsigned int ns;
  std::string thisId = object.getId();

  /* 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.getKineticLaw()->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;
}
END_TEST


START_TEST ( test_KineticLaw_parent_create_model )
{
    Model *m = new Model(2, 4);
    Reaction * r = m->createReaction();
    KineticLaw* kl = r->createKineticLaw();

    fail_unless(r == kl->getParentSBMLObject());
    fail_unless(r == r->getKineticLaw()->getParentSBMLObject());

    delete r;
}
/*
 * 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();
}
void 
convertPow(SBMLDocument* doc, 
           bool shouldChangePow, 
           bool inlineCompartmentSizes)
{

  Model* model = SBMLDocument_getModel(doc);
  if (model == NULL)
  {
    return;
  }

  std::map<string, double> compartmentValueMap;
  if (inlineCompartmentSizes)
  {
    for(unsigned int i = 0; i < model->getNumCompartments(); ++i)
    {
      Compartment* c = model->getCompartment(i);
      compartmentValueMap[c->getId()] = c->getSize();
    }
  }

  for(unsigned int i = 0; i < model->getNumReactions(); ++i)
  {
    Reaction* r  = model->getReaction(i);
    KineticLaw* kl = r->getKineticLaw();
    const char* strKineticFormula;
    if (kl == NULL)
    {
      strKineticFormula = "";
    }
    else
    {
      strKineticFormula = KineticLaw_getFormula(kl);
      if (strKineticFormula == NULL)
      {
        continue;
      }
    }

    ASTNode* ast_Node	= SBML_parseFormula (strKineticFormula);
    if (ast_Node != NULL)
    {
      changePow(ast_Node, compartmentValueMap, shouldChangePow);
      kl->setMath (ast_Node);
    }
    delete ast_Node;
  }
}
END_TEST


START_TEST ( test_KineticLaw_parent_add )
{
    KineticLaw* kl=new KineticLaw(2, 4);

    Reaction * r = new Reaction(2, 4);

    r->setKineticLaw(kl);

    fail_unless(r == r->getKineticLaw()->getParentSBMLObject());

    delete r;
}
示例#9
0
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);
      }
    }
  }
}
示例#10
0
/* 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);
      }
    }
  }
}
void setObjectiveCoefficient(FbcModelPlugin* plugin, Model* model)
{
  if (plugin == NULL || model == NULL)
    return;

  Objective* obj = plugin->getActiveObjective();
  if (obj == NULL)
    return;

  for (unsigned int i = 0; i < obj->getNumFluxObjectives(); ++i)
  {
    FluxObjective* fluxObj = obj->getFluxObjective(i);
    if (fluxObj == NULL)
      continue;
    Reaction* reaction = model->getReaction(fluxObj->getReaction());
    if (reaction == NULL)
      continue;
    KineticLaw* law = reaction->getKineticLaw();
    if (law == NULL)
      continue;
    LocalParameter* param = law->getLocalParameter("OBJECTIVE_COEFFICIENT");
    param->setValue(fluxObj->getCoefficient());
  }
}
示例#12
0
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();
        }
      }
    }
  }
}
示例#13
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
示例#14
0
文件: GeneNetwork.cpp 项目: jbao/GNW
/** 
 * Load a gene network from an SBML file. Overrides Structure.load(). Format must
 * be equal GeneNetwork.SBML. Note, the SBML file must be in the exact same format
 * as the SBML files produced by writeSBML(). In particular, we assume that reactions are listed
 * *ordered* as we do in writeSBML().
 * @param filename URL to the file describing the network to load
 * @param format File format (GML, DOT, etc.)
 * @throws IOException 
 */
void GeneNetwork::load_sbml(const char *filename) {
	SBMLDocument* document;
  	SBMLReader reader;

  	document = reader.readSBML(filename);

  	unsigned int errors = document->getNumErrors();
	if (errors > 0) {
        std::cerr << "Failed to open file " << filename << std::endl;
        exit(1);
    }

	Model *m = document->getModel();

	// -----------------------------------------
	// Set the network size and create the genes
	// do not count the species _void_
	int size = m->getNumSpecies() - 1;
	ListOfSpecies *species = m->getListOfSpecies();
	
	for (int g=0; g < size; g++) {
		if (species->get(g)->getId() != "_void_") {
			//HillGene hg = new HillGene(this);
			//hg.setLabel(species.get(g).getId());
			HillGene *n = new HillGene(species->get(g)->getId());
			//n.setLabel(species->get(g)->getId());
			nodes_.push_back(*n);
			delete n;
		}
	}
	
	x_ = Vec_DP(nodes_.size());
	x_ = 0;
	y_ = Vec_DP(nodes_.size());
	y_ = 0;
	
	//vector<string> parameterNames; // the names of the parameters
	//vector<double> parameterValues; // the values of the parameters
	std::map<std::string, double> params;
	std::vector<std::string> inputNodes; // the indexes of the inputs
	HillGene src, tgt;
	Parameter *param;
	
	// 2 loops for one gene: both synthesis and degradation reactions
	// (we assume that reactions are listed *ordered* as we do in writeSBML())
	//int counter = 0;
	for (unsigned int i=0; i < m->getNumReactions(); i++) {
		Reaction *re = m->getReaction(i);
		std::string id = re->getId();
		
		std::stringstream ss;
		ss << i;
		//::logging::log::emit<Debug>() << id.c_str() <<
		//		::logging::log::endl;
	
		tgt = nodes_.at(getIndexOfNode(getGeneReactantId(id)));
		//tgt->setLabel(getGeneReactantId(*re));
      	//SpeciesReference *rt = re->getReactant(0);
      	//Node *tgt = new HillGene();
      	//tgt->setLabel(rt->getSpecies());
      	//ListOfSpeciesReferences *modifiers = re->getListOfModifiers();

    	for (unsigned int j=0; j < re->getNumModifiers(); j++) {
      		ModifierSpeciesReference *md = re->getModifier(j);
      		src = nodes_.at(getIndexOfNode(md->getSpecies()));      		
      		inputNodes.push_back(src.getLabel());
      		
            // set output genes
            std::vector<std::string> outputs = src.getOutputGenes();
            outputs.push_back(tgt.getLabel());
            src.setOutputGenes(outputs);
      		
            // The edge type is unknown for now, it is initialized later
      		Edge *e = new Edge(&src, &tgt, "+-");
			edges_.push_back(*e);
			//delete src;
			delete e;
		}

      	KineticLaw *kl = re->getKineticLaw();
      		
      	for(unsigned int j=0; j < kl->getNumParameters(); j++) {
        	param = kl->getParameter(j);
			params[param->getId()] = param->getValue();
			//char buf[256];
      		//sprintf(buf, "%s\t%f", param->getId().c_str(), param->getValue());
			//::logging::log::emit<Info>() << buf <<	::logging::log::endl;
		}
		
		//::logging::log::emit<Info>() << ::logging::log::dec << params.size() <<
		//		::logging::log::endl;
		
		// in the second iteration for this gene
		if (i%2 == 1) {
			// set parameters in gene
			//tgt.initialization(params, inputNodes);
			nodes_.at(getIndexOfNode(getGeneReactantId(id))).initialization(params, inputNodes);;
			//char buf[256];
			//sprintf(buf, "%f", params["k_1"]);
			//::logging::log::emit<Info>() << buf << ::logging::log::endl;
			
			inputNodes.clear(); // don't clear because the reference was copied to the gene
			//parameterNames.clear(); // reset (they were not copied)
			//parameterValues.clear();
			params.clear();
		}
		//counter++;
	}
	//setEdgeTypesAccordingToDynamicalModel();
	//signed_ = true;
	
	//delete document;
	//delete n;
	//delete e;
}
示例#15
0
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],&parameterValues[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],&parameterValues[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],&parameterValues[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;
	}
}
示例#16
0
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());
}
示例#17
0
//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());
                            }
                        }
                    }
                }
            }
        }
    }
}
示例#18
0
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;
}
示例#19
0
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;
}
示例#20
0
//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