Пример #1
0
void checkSpecies(Model* model, set<string>& components, set<string>& tests,  const map<string, vector<double> >& results, int type)
{
  //Must call this after 'checkCompartments' because we look in 'tests' for 'NonUnityCompartment'.
  if (model->getNumSpecies() > 0) {
    components.insert("Species");
    if (type==0) {
      tests.insert("Amount||Concentration");
    }
    else if (type==2) {
      tests.insert("Amount");
    }
	set<string> compartments;
    for (unsigned int s=0; s<model->getNumSpecies(); s++) {
      Species* species = model->getSpecies(s);
      if (species->isSetBoundaryCondition() && species->getBoundaryCondition()) {
        tests.insert("BoundaryCondition");
      }
      if (species->getConstant()) {
        tests.insert("ConstantSpecies");
      }
      if (species->isSetConversionFactor()) {
        tests.insert("ConversionFactors");
      }
      if (species->isSetHasOnlySubstanceUnits() && species->getHasOnlySubstanceUnits()) {
        tests.insert("HasOnlySubstanceUnits");
      }
      if (!species->isSetInitialAmount() && !species->isSetInitialConcentration()) {
        tests.insert("InitialValueReassigned");
      }
      else if (species->isSetId() && initialOverriddenIn(species->getId(), model, results, tests)) {
        tests.insert("InitialValueReassigned");
      }
      if (species->isSetCompartment()) {
        compartments.insert(species->getCompartment());
      }
    }
    if (tests.find("MultiCompartment") != tests.end() && compartments.size()==1 && model->getNumSpecies() > 1) {
      cerr << "Error:  multiple compartments discovered, but all species are in a single compartment." << endl;
      tests.insert("ERRORMultiCompartment");
    }
  }
}
Пример #2
0
int Database::editSpecies(Species s)
{
    QVariant name = s.getName().toString().toLower();
    if(this->specieExist(name) > 0){
        this->showError(QMessageBox::tr("Esta espécie já existe"));
        return 0;
    }
    if(this->specieExist(name) <= 0){
        this->query.prepare("UPDATE Species SET name=? WHERE Species.id=?;");
        this->query.addBindValue(name);
        this->query.addBindValue(s.getId());
        if(!this->query.exec()){
            this->showError(this->query.lastError());
            return -1;
        }
        return 1;
    }
    QMessageBox::information(0, QMessageBox::tr("Erro"),QMessageBox::tr("Espécie não encontrada!"));
    return 0;
}
/*
  * Logs a message about species with boundary condition false
  * being set by reaction and rules
  */
void
SpeciesReactionOrRule::logConflict (const Species& s, const Reaction& r)
{
  msg =
    //"A <species>'s quantity cannot be determined simultaneously by both "
    //"reactions and rules. More formally, if the identifier of a <species> "
    //"definition having 'boundaryCondition'='false' and 'constant'='false' is "
    //"referenced by a <speciesReference> anywhere in a model, then this "
    //"identifier cannot also appear as the value of a 'variable' in an "
    //"<assignmentRule> or a <rateRule>. (References: L2V1 Section 4.6.5; L2V2 "
    //"Section 4.8.6; L2V3 Section 4.8.6.) 
    "The species '";

  msg += s.getId();
  msg += "' occurs in both a rule and reaction '";
  msg += r.getId();
  msg += "'.";

  
  logFailure(s);
}
Пример #4
0
std::string SEDMLUtils::findIdByNameAndType(
  const std::map<CCopasiObject*, SBase*>& map,
  int typeCode,
  const std::string& name)
{
  std::map<CCopasiObject*, SBase*>::const_iterator it = map.begin();

  std::string::size_type compartmentStart = name.find("{");
  std::string nameOnly = name.substr(0, compartmentStart);

  while (it != map.end())
    {
      SBase* current = it->second;

      if (((current->getTypeCode() & typeCode) == typeCode) &&
          current->getName() == name)
        return current->getId();

      if (typeCode == SBML_SPECIES  && compartmentStart != std::string::npos)
        {
          if (((current->getTypeCode() & typeCode) == typeCode) &&
              current->getName() == nameOnly)
            {
              std::string compName = name.substr(compartmentStart + 1, name.size() - compartmentStart  - 2);
              std::string compId = findIdByNameAndType(map, SBML_COMPARTMENT, compName);
              Species* species = (Species*) current;

              if (species->getCompartment() == compId)
                return species->getId();
            }
        }

      ++it;
    }

  return "";
}
int 
  FbcToCobraConverter::convert()
{  
  int result = LIBSBML_OPERATION_FAILED;

  if (mDocument == NULL) 
  {
    return LIBSBML_INVALID_OBJECT;
  }

  Model* mModel = mDocument->getModel();
  if (mModel == NULL) 
  {
    return LIBSBML_INVALID_OBJECT;
  }

  FbcModelPlugin *plugin =
    static_cast<FbcModelPlugin*>(mDocument->getModel()->getPlugin("fbc"));

  // if we have don't have a fbc model we cannot do the conversion
  if (plugin == NULL || mDocument->getLevel() != 3)
  {
    return LIBSBML_OPERATION_FAILED;
  }

  // collect information

  Model* model = mDocument->getModel();
  map<const string, int> chargeMap;
  map<const string, string> formulaMap;

  for (unsigned int i = 0; i < model->getNumSpecies(); ++i)
  {
    Species* current = model->getSpecies(i);
    const string& currentId = current->getId();
    FbcSpeciesPlugin *splugin = static_cast<FbcSpeciesPlugin*>(current->getPlugin("fbc"));
    if (splugin == NULL)
      continue;
    if (splugin->isSetCharge())
    {
      chargeMap[currentId] = splugin->getCharge();
    }
    if (splugin->isSetChemicalFormula())
    {
      formulaMap[currentId] = splugin->getChemicalFormula();
    }
  }

  // create KineticLaw
  for (unsigned int i = 0; i < model->getNumReactions(); ++i)
  {
    Reaction* reaction = model->getReaction(i);
    if (reaction == NULL)
      continue;

    createKineticLawForReaction(reaction);

  }

  // update kinetic law from bounds
  for (unsigned int i = 0; i < plugin->getNumFluxBounds(); ++i)
  {
    FluxBound *current = plugin->getFluxBound(i);
    if (current == NULL)
      continue;
    Reaction* reaction = model->getReaction(current->getReaction());
    if (reaction == NULL)
      continue;

    updateKineticLawFromBound(reaction, current);

  }

  setObjectiveCoefficient(plugin, model);

  // disable package
  mDocument->enablePackage("http://www.sbml.org/sbml/level3/version1/fbc/version1", "fbc",false);

  // convert model to L2V1 (as L2V2 is the last model that had charge)
  mDocument->setConversionValidators(AllChecksON & UnitsCheckOFF);
  
  ConversionProperties prop(new SBMLNamespaces(2,1));
  prop.addOption("strict", false, "should validity be preserved");
  prop.addOption("ignorePackages", true, "convert even if packages are used");
  prop.addOption("setLevelAndVersion", true, "convert the document to the given level and version");
  int conversionResult = mDocument->convert(prop);
  if (conversionResult != LIBSBML_OPERATION_SUCCESS)
    return conversionResult;

  // set charge on species
  for (unsigned int i = 0; i < model->getNumSpecies(); ++i)  
  {
    Species* current = model->getSpecies(i);
    const string currentId = current->getId();
    int charge = chargeMap[currentId];

    if (charge != 0)
      current->setCharge(charge);

    const string formula = formulaMap[currentId];
    if (!formula.empty())
    {
      current->setNotes( getNotesForFormula(formula) );
    }
  }


  result = LIBSBML_OPERATION_SUCCESS;
  return result;
}
int 
  CobraToFbcConverter::convert()
{  
  int result = LIBSBML_OPERATION_FAILED;

  if (mDocument == NULL) 
  {
    return LIBSBML_INVALID_OBJECT;
  }

  Model* mModel = mDocument->getModel();
  if (mModel == NULL) 
  {
    return LIBSBML_INVALID_OBJECT;
  }

  FbcModelPlugin *plugin =
    (FbcModelPlugin*)(mDocument->getModel()->getPlugin("fbc"));

  // if we have a fbc model we are done already
  if (plugin != NULL || mDocument->getLevel() == 3)
  {
    return LIBSBML_OPERATION_SUCCESS;
  }
  
  std::map<const string, int> chargeMap;
  std::map<const string, string> formulaMap;
  Model* model = mDocument->getModel();

  for (unsigned int i = 0; i < model->getNumSpecies();++i)
  {
    Species* current = model->getSpecies(i);
    bool haveCharge = current->isSetCharge();
    if (haveCharge)
    {
      chargeMap[current->getId()] = current->getCharge();
      // need to unset the charge here, as it the call will 
      // not work once this is an L3 model
      current->unsetCharge();
    }
    if (current->isSetNotes())
    {
      string originalNotes = current->getNotesString();
	  string notes(originalNotes);
      std::transform(notes.begin(), notes.end(), notes.begin(), ::toupper);
      size_t pos = notes.find("FORMULA:");
      if (pos != string::npos)
      {
        size_t end = notes.find("</", pos+9);
        if (end != string::npos)
        {
          string formula = originalNotes.substr(pos + 9, end-(pos+9));
          if (formula[0] != '<' &&  formula[0] != '/' )
          {
            size_t pos = formula.find_first_not_of(" \n\t\r");
            if (pos != std::string::npos)
            formulaMap[current->getId()] = formula;
          }
        }
      } // added chemical formula if present 
	 
      pos = notes.find("CHARGE:");
      if (pos != string::npos && !haveCharge)
      {
        size_t end = notes.find("</", pos+8);
        if (end != string::npos)
        {
          string formula = originalNotes.substr(pos + 8, end-(pos+8));
          if (formula[0] != '<' &&  formula[0] != '/' )
          {
            size_t pos = formula.find_first_not_of(" \n\t\r");
            if (pos != std::string::npos)
		  {
			int charge; 
			stringstream str; 
			str << formula; 
			str >> charge;
			if (charge != 0)
			  chargeMap[current->getId()] = charge;
		  }
          }
Пример #7
0
void readSpatialSBML() {
	SBMLDocument *document2 = readSBML("spatial_example0.xml");
  
	Model *model2 = document2->getModel();
	Compartment *comp;
	SpatialCompartmentPlugin* cplugin;
	RequiredElementsSBasePlugin* reqplugin;
	for (unsigned int i = 0; i < model2->getNumCompartments(); i++) {
		comp = model2->getCompartment(i);
		cout << "Compartment" << i << ": "  << comp->getId() << endl;
		reqplugin = static_cast<RequiredElementsSBasePlugin*>(comp->getPlugin("req"));
		if (!reqplugin->getMathOverridden().empty()) {
			cout << "Comp" << i << "  req mathOverridden: "  << reqplugin->getMathOverridden() << endl;
		}
		cplugin = static_cast<SpatialCompartmentPlugin*>(comp->getPlugin("spatial"));
		if (cplugin->getCompartmentMapping()->isSetSpatialId()) {
			cout << "Comp" << i << "  CMSpId: "  << cplugin->getCompartmentMapping()->getSpatialId() << endl;
			cout << "Comp" << i << "  CM_Comp: "  << cplugin->getCompartmentMapping()->getCompartment() << endl;
			cout << "Comp" << i << "  CM_DType: "  << cplugin->getCompartmentMapping()->getDomainType() << endl;
			cout << "Comp" << i << "  CM_UnitSz: "  << cplugin->getCompartmentMapping()->getUnitSize() << endl;
		}
	}

	Species *sp;
	SpatialSpeciesRxnPlugin* srplugin;
	for (unsigned int i = 0; i < model2->getNumSpecies(); i++) {
		sp = model2->getSpecies(i);
		cout << "Species" << i << ": "      << sp->getId()      << endl;
		srplugin = static_cast<SpatialSpeciesRxnPlugin*>(sp->getPlugin("spatial"));
		if (srplugin->getIsSpatial()) {
			cout << "species" << i << "  isSpatial: "  << srplugin->getIsSpatial() << endl;
		}
	}

	Parameter *param;
	SpatialParameterPlugin* pplugin;
	for (unsigned int i = 0; i < model2->getNumParameters(); i++) {
		param = model2->getParameter(i);
		cout << "Parameter" << i << ": "  << param->getId() << endl;
		reqplugin = static_cast<RequiredElementsSBasePlugin*>(param->getPlugin("req"));
		if (!reqplugin->getMathOverridden().empty()) {
			cout << "Parameter" << i << "  req mathOverridden: "  << reqplugin->getMathOverridden() << endl;
		}
		pplugin = static_cast<SpatialParameterPlugin*>(param->getPlugin("spatial"));
		if (pplugin->getSpatialSymbolReference()->isSetSpatialId()) {
			cout << "Parameter" << i << "  SpRefId: "  << pplugin->getSpatialSymbolReference()->getSpatialId() << endl;
			cout << "Parameter" << i << "  SpRefType: "  << pplugin->getSpatialSymbolReference()->getType() << endl;
		}
		if (pplugin->getDiffusionCoefficient()->isSetVariable()) {
			cout << "Diff_" << i << "  SpeciesVarId: "  << pplugin->getDiffusionCoefficient()->getVariable() << endl;
			cout << "Diff_" << i << "  SpCoordIndex: "  << pplugin->getDiffusionCoefficient()->getCoordinateIndex() << endl;
		}
		if (pplugin->getAdvectionCoefficient()->isSetVariable()) {
			cout << "Adv_" << i << "  SpeciesVarId: "  << pplugin->getAdvectionCoefficient()->getVariable() << endl;
			cout << "Adv_" << i << "  SpCoordIndex: "  << pplugin->getAdvectionCoefficient()->getCoordinateIndex() << endl;
		}
		if (pplugin->getBoundaryCondition()->isSetVariable()) {
			cout << "BC_" << i << "  SpeciesVarId: "  << pplugin->getBoundaryCondition()->getVariable() << endl;
			cout << "BC_" << i << "  SpCoordBoundary: "  << pplugin->getBoundaryCondition()->getCoordinateBoundary() << endl;
			cout << "BC_" << i << "  SpBoundaryType: "  << pplugin->getBoundaryCondition()->getType() << endl;
		}
	}

	Reaction *rxn;
	for (unsigned int i = 0; i < model2->getNumReactions(); i++) {
		rxn = model2->getReaction(i);
		cout << "Reaction" << i << ": "      << rxn->getId()      << endl;
		srplugin = static_cast<SpatialSpeciesRxnPlugin*>(rxn->getPlugin("spatial"));
		if (srplugin->getIsLocal()) {
			cout << "rxn" << i << "  isLocal: "  << srplugin->getIsLocal() << endl;
		}
	}

	Rule *rule;
	for (unsigned int i = 0; i < model2->getNumRules(); i++) {
		rule = model2->getRule(i);
		cout << "Rule" << i << ": "      << rule->getVariable()      << endl;
	}

	//
	// Get a SpatialModelPlugin object plugged in the model object.
	//
	// The type of the returned value of SBase::getPlugin() function is 
	// SBasePlugin*, and thus the value needs to be cast for the 
	// corresponding derived class.
	//
	SpatialModelPlugin* mplugin2;
	mplugin2 = static_cast<SpatialModelPlugin*>(model2->getPlugin("spatial"));
	cout << "URI: "      << mplugin2->getURI()      << endl;
	cout << "prefix: "      << mplugin2->getPrefix()      << endl;

	// get a Geometry object via SpatialModelPlugin object.
	Geometry* geometry2 = mplugin2->getGeometry();
	cout << "Geometry coordSystem: "      << geometry2->getCoordinateSystem()      << endl;
    
	// get a CoordComponent object via the Geometry object.	
	CoordinateComponent* coordComp = geometry2->getCoordinateComponent(0);
	std::cout << "CoordComponent spatialId: " << coordComp->getSpatialId() << std::endl;
	std::cout << "CoordComponent compType: " << coordComp->getComponentType() << std::endl;
	std::cout << "CoordComponent sbmlUnit: " << coordComp->getSbmlUnit() << std::endl;
	std::cout << "CoordComponent index: " << coordComp->getIndex() << std::endl;
	BoundaryMin* minX = coordComp->getBoundaryMin();
	std::cout << "minX name: " << minX->getSpatialId() << std::endl;
	std::cout << "minX value: " << minX->getValue() << std::endl;
	BoundaryMax* maxX = coordComp->getBoundaryMax();
	std::cout << "maxX name: " << maxX->getSpatialId() << std::endl;
	std::cout << "maxX value: " << maxX->getValue() << std::endl;

	// get a DomainType object via the Geometry object.	
	DomainType* domainType2 = geometry2->getDomainType(0);
	std::cout << "DomainType spatialId: " << domainType2->getSpatialId() << std::endl;
	std::cout << "DomainType spatialDim: " << domainType2->getSpatialDimensions() << std::endl;

	// get a Domain object via the Geometry object.	
	Domain* domain = geometry2->getDomain(0);
	std::cout << "Domain1 spatialId: " << domain->getSpatialId() << std::endl;
	std::cout << "Domain1 implicit: " << domain->getImplicit() << std::endl;
	std::cout << "Domain1 domainType: " << domain->getDomainType() << std::endl;
	std::cout << "Domain1 Shape: " << domain->getShapeId() << std::endl;
	// get an internal point via the domain object
	InteriorPoint* internalPt = domain->getInteriorPoint(0);
	std::cout << "InternalPt_1 coord1: " << internalPt->getCoord1() << std::endl;

	// get a Domain object via the Geometry object.	
	domain = geometry2->getDomain(1);
	std::cout << "Domain2 spatialId: " << domain->getSpatialId() << std::endl;
	std::cout << "Domain2 implicit: " << domain->getImplicit() << std::endl;
	std::cout << "Domain2 domainType: " << domain->getDomainType() << std::endl;
	std::cout << "Domain2 Shape: " << domain->getShapeId() << std::endl;
	// get an internal point via the domain object
	internalPt = domain->getInteriorPoint(0);
	std::cout << "InternalPt_2 coord1: " << internalPt->getCoord1() << std::endl;

	// get an AdjacentDomains object via the Geometry object.	
	AdjacentDomains* adjDomain = geometry2->getAdjacentDomains(0);
	std::cout << "AdjDomain spatialId: " << adjDomain->getSpatialId() << std::endl;
	std::cout << "AdjDomain domain1: " << adjDomain->getDomain1() << std::endl;
	std::cout << "AdjDomain domain2: " << adjDomain->getDomain2() << std::endl;

	// get the different GeometryDefinition objects via the Geometry object.
	GeometryDefinition* gd;
	for (unsigned int i = 0; i < geometry2->getNumGeometryDefinitions(); i++) {
		gd = geometry2->getGeometryDefinition(i);
		if (gd->isAnalyticGeometry()) {
			AnalyticGeometry* analyticalGeom = static_cast<AnalyticGeometry*>(gd);
			std::cout << "AnalGeom spatialId: " << analyticalGeom->getSpatialId() << std::endl;

			// analVol from analGeom.
			AnalyticVolume* av = analyticalGeom->getAnalyticVolume(0);
			std::cout << "AnalVol spatialId: " << av->getSpatialId() << std::endl;
			std::cout << "AnalVol domainType: " << av->getDomainType() << std::endl;
			std::cout << "AnalVol funcType: " << av->getFunctionType() << std::endl;
			std::cout << "AnalVol ordinal: " << av->getOrdinal() << std::endl;
			const ASTNode* mathNode = av->getMath();
			char* mathStr = writeMathMLToString(mathNode);
			std::cout << "AnalVol math: " << mathStr << std::endl;
		}
		if (gd->isSampledFieldGeometry()) {
			SampledFieldGeometry* sfGeom = static_cast<SampledFieldGeometry*>(gd);
			std::cout << "SampledFieldGeom spatialId: " << sfGeom->getSpatialId() << std::endl;
			
			// sampledField from sfGeom
			SampledField* sf = sfGeom->getSampledField();
			std::cout << "SampledField spatialId: " << sf->getSpatialId() << std::endl;
			std::cout << "SampledField dataType: " << sf->getDataType() << std::endl;
			std::cout << "SampledField interpolation: " << sf->getInterpolationType() << std::endl;
			std::cout << "SampledField encoding: " << sf->getEncoding() << std::endl;
			std::cout << "SampledField numSamples1: " << sf->getNumSamples1() << std::endl;
			std::cout << "SampledField numSamples2: " << sf->getNumSamples2() << std::endl;
			std::cout << "SampledField numSamples3: " << sf->getNumSamples3() << std::endl;
			const ImageData* id = sf->getImageData();
			int* samples = new int[id->getSamplesLength()];
			id->getSamples(samples);
			std::cout << "ImageData samples[0]: " << samples[0] << std::endl;
			std::cout << "ImageData samplesLen: " << id->getSamplesLength() << std::endl;
			std::cout << "ImageData dataType: " << id->getDataType() << std::endl;

			// sampledVolVol from sfGeom.
			SampledVolume* sv = sfGeom->getSampledVolume(0);
			std::cout << "SampledVol spatialId: " << sv->getSpatialId() << std::endl;
			std::cout << "SampledVol domainType: " << sv->getDomainType() << std::endl;
			std::cout << "SampledVol sampledVal: " << sv->getSampledValue() << std::endl;
			std::cout << "SampledVol min: " << sv->getMinValue() << std::endl;
			std::cout << "SampledVol max: " << sv->getMaxValue() << std::endl;
		}
		if (gd->isParametricGeometry()) {
			ParametricGeometry* pGeom = static_cast<ParametricGeometry*>(gd);
			std::cout << "ParametricGeometry spatialId: " << pGeom->getSpatialId() << std::endl;
			
			// parametricObject from pGeom
			ParametricObject* pObj = pGeom->getParametricObject(0);
			std::cout << "ParametricObj spatialId: " << pObj->getSpatialId() << std::endl;
			std::cout << "ParametricObj domain: " << pObj->getDomain() << std::endl;
			std::cout << "ParametricObj polygonType: " << pObj->getPolygonType() << std::endl;
			const PolygonObject* po = pObj->getPolygonObject();
			int* ptInd = new int[po->getIndicesLength()];
			po->getPointIndices(ptInd);
			std::cout << "PolygonObj ptIndices[0]: " << ptInd[0] << std::endl;
			std::cout << "PolygonObj indLen: " << po->getIndicesLength() << std::endl;

			// SpatialPoint from pGeom.
			SpatialPoint* sp = pGeom->getSpatialPoint(0);
			std::cout << "SpatialPt spatialId: " << sp->getSpatialId() << std::endl;
			std::cout << "SpatialPt domain: " << sp->getDomain() << std::endl;
			std::cout << "SpatialPt coord1: " << sp->getCoord1() << std::endl;
			std::cout << "SpatialPt coord2: " << sp->getCoord2() << std::endl;
			std::cout << "SpatialPt coord3: " << sp->getCoord3() << std::endl;
		}
		if (gd->isCSGeometry()) {
			CSGeometry* csGeom = static_cast<CSGeometry*>(gd);
			std::cout << "CSGeometry spatialId: " << csGeom->getSpatialId() << std::endl;
			
			// CSGObject-CSGOperator from csGeom
			CSGObject* csgo;
			for (unsigned int i = 0; i < csGeom->getNumCSGObjects(); i++) {
				csgo = csGeom->getCSGObject(i);
				std::cout << "CSGObject spatialId: " << csgo->getSpatialId() << std::endl;
				std::cout << "CSGObject domainType: " << csgo->getDomainType() << std::endl;
				const CSGNode* csgnode = csgo->getCSGNodeRoot();
				if (csgnode->isCSGTransformation()) {
					CSGTransformation* transf = (CSGTransformation*)csgnode;
					if (transf->isCSGScale()) {
						CSGScale* scale = static_cast<CSGScale*>(transf);
						std::cout << "CSGScale scaleX: " << scale->getScaleX() << std::endl;
						std::cout << "CSGScale scaleY: " << scale->getScaleY() << std::endl;
						std::cout << "CSGScale scaleZ: " << scale->getScaleZ() << std::endl;
						const CSGNode* scaleChild = scale->getChild();
						if (scaleChild->isCSGPrimitive()) {
							CSGPrimitive* prim = (CSGPrimitive*)scaleChild;
							std::cout << "CSGPrimitive primitiveType: " << prim->getPrimitiveType() << std::endl;
						}
					}
				}
				if (csgnode->isCSGSetOperator()) {
					CSGSetOperator* setop = (CSGSetOperator*)(csgnode);
					std::cout << "CSGSetOperator opType: " << setop->getOperationType() << std::endl;
					for (unsigned int k = 0; k < setop->getNumCSGNodeChildren(); k++) {
						CSGNode* csgNode = setop->getCSGNodeChild(k);
						std::cout << "CSGNode type: " << csgNode->getTypeCode() << std::endl;
					}
				}
			}
		}
	}

	delete document2;
}
Пример #8
0
/**
 * Save the gene network to an SBML file. If the argument is null, use the network id.
 * @param filename URL to the file describing the network to load
 * @throws IOException
 */
void GeneNetwork::writeSBML(const char *filename) {
			
	ofstream data_file(filename); 
    if (!data_file.is_open()) {
        std::cerr << "Failed to open file " << filename << std::endl;
        exit(1);
    }
    data_file.close();
			
	::logging::log::emit<Info>() << "Writing file " << filename <<
		::logging::log::endl;
	
	SBMLDocument *sbmlDoc = new SBMLDocument(3, 1);

	Model *model = sbmlDoc->createModel();
	model->setId(id_);
	//model.getNotes ().add (comment_); // save network description
	
	int size = getSize();
	
	Compartment *comp = model->createCompartment();
  	comp->setId("cell");
	comp->setSize(1);

	std::vector<Species*> all_sp;
	Species *sp;

	for (int s=0; s < size; s++) { // save gene as species
//			species[s] = new Species(nodeIds_.get(s), nodeIds_.get(s));
		sp = model->createSpecies();
  		sp->setCompartment("cell");
  		sp->setId((nodes_.at(s)).getLabel());
  		all_sp.push_back(sp);
		//species[s].setInitialAmount(?); // maybe save the wild-type steady state?
		//model.addSpecies(species[s]);
	}
	
	// create the void species
	sp = model->createSpecies();
  	sp->setCompartment("cell");
  	sp->setId("_void_");
	sp->setInitialAmount(0);
	sp->setBoundaryCondition(true);
	sp->setConstant(true);
	all_sp.push_back(sp);
	//model.addSpecies(species[size]);


	// SET SYNTHESIS AND DEGRADATION REACTIONS FOR EVERY GENE
	for (int i=0; i<size; i++) {
		//::logging::log::emit<Info>() << ::logging::log::dec << i <<
		//::logging::log::endl;
		
		// the ID of gene i
//			String currentGeneID = nodeIds_.get(i);
		string currentGeneID = (nodes_.at(i)).getLabel();
		// The modifiers (regulators) of gene i
		std::vector<std::string> inputGenes = (nodes_.at(i)).getInputGenes();
		
		// SYNTHESIS REACTION
		std::string reactionId = currentGeneID + "_synthesis";
		Reaction *reaction = model->createReaction();
		KineticLaw *kineticLaw = reaction->createKineticLaw();
		SpeciesReference *spr;
		ModifierSpeciesReference *msr;
		reaction->setId(reactionId);
		reaction->setReversible (false);
		spr = reaction->createReactant();
  		spr->setSpecies(sp->getId());
  		spr = reaction->createProduct();
  		spr->setSpecies((all_sp.at(i))->getId());
		
		std::stringstream ss;
		ss << inputGenes.size();
		//::logging::log::emit<Debug>() << "node = " << nodes_.at(i).getLabel().c_str() << " #inputs = " << ss.str().c_str() << ::logging::log::endl;
		
		for (unsigned int r=0; r<inputGenes.size(); r++) {// set gene modifiers
//				reaction.addModifier(species[inputIndexes.get(r)]);
			//log.log(Level.INFO, "i = " + size);
			msr = reaction->createModifier();
			msr->setSpecies((all_sp.at(getIndexOfNode(inputGenes.at(r))))->getId());
		}

		//std::vector<RegulatoryModule> modules = (nodes_.at(i)).getRegulatoryModules();
		//log.log(Level.INFO, "size = " + modules.size());
		std::map<std::string, double> *params = new std::map<std::string, double>();
		(nodes_.at(i)).compileParameters(*params);
		
		//char buf[256];
		//sprintf(buf, "%f", nodes_.at(i).getDelta());
		//::logging::log::emit<Info>() << buf << ::logging::log::endl;
		//::logging::log::emit<Info>() << ::logging::log::dec << nodes_.at(i).getAlpha().size() <<
		//		::logging::log::endl;
		
		Parameter *para;
		// save gene parameters (note, the first param is the degradation rate)
		std::map<std::string, double>::iterator p = params->begin();
		//p++;
		for (; p!=params->end(); p++) {
			//if (p == params->begin()) {
			//	p++;
			//	continue;
			//}
			//::logging::log::emit<Info>() << p->first.c_str() <<
			//	::logging::log::endl;
			if (p->first != "delta") {
				para = kineticLaw->createParameter();
				para->setId(p->first);
				para->setValue(p->second);
			}
		}
		reaction->setKineticLaw(kineticLaw);
		model->addReaction(reaction);

		// DEGRADATION REACTION
		reaction = model->createReaction();
		kineticLaw = reaction->createKineticLaw();
		reactionId = currentGeneID + "_degradation";
		reaction->setId(reactionId);
		reaction->setReversible(false);
		spr = reaction->createReactant();
  		spr->setSpecies((all_sp.at(i))->getId());
  		spr = reaction->createProduct();
  		spr->setSpecies(sp->getId());

		para = kineticLaw->createParameter();
		std::map<std::string,double>::iterator it = params->find("delta");
		para->setId(it->first);
		para->setValue(it->second);
		
		reaction->setKineticLaw (kineticLaw);
		model->addReaction (reaction);
	}
	
	// PRINT FILE
	SBMLWriter sbmlWriter;
	sbmlWriter.writeSBML(sbmlDoc, filename);
	
	delete sbmlDoc;
}
Пример #9
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());
}
Пример #10
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;
}
Пример #11
0
void
CompIdBase::checkId (const Species& x)
{
  if (x.isSetId()) doCheckId(x.getId(), x);
}
Пример #12
0
void readSpatialSBML() {
	SBMLDocument *document2 = readSBML("spatial_example2.xml");
  
	Model *model2 = document2->getModel();
	Compartment *comp;
	SpatialCompartmentPlugin* cplugin;
	for (unsigned int i = 0; i < model2->getNumCompartments(); i++) {
		comp = model2->getCompartment(i);
		cout << "Compartment" << i << ": "  << comp->getId() << endl;
		cplugin = static_cast<SpatialCompartmentPlugin*>(comp->getPlugin("spatial"));
		if (cplugin->getCompartmentMapping()->isSetId()) {
			cout << "Comp" << i << "  CMSpId: "  << cplugin->getCompartmentMapping()->getId() << endl;
			cout << "Comp" << i << "  CM_DType: "  << cplugin->getCompartmentMapping()->getDomainType() << endl;
			cout << "Comp" << i << "  CM_UnitSz: "  << cplugin->getCompartmentMapping()->getUnitSize() << endl;
		}
	}

	Species *sp;
	SpatialSpeciesPlugin* srplugin;
	for (unsigned int i = 0; i < model2->getNumSpecies(); i++) {
		sp = model2->getSpecies(i);
		cout << "Species" << i << ": "      << sp->getId()      << endl;
		srplugin = static_cast<SpatialSpeciesPlugin*>(sp->getPlugin("spatial"));
		if (srplugin->getIsSpatial()) {
			cout << "species" << i << "  isSpatial: "  << srplugin->getIsSpatial() << endl;
		}
	}

	Parameter *param;
	SpatialParameterPlugin* pplugin;
	for (unsigned int i = 0; i < model2->getNumParameters(); i++) {
		param = model2->getParameter(i);
		cout << "Parameter" << i << ": "  << param->getId() << endl;
		pplugin = static_cast<SpatialParameterPlugin*>(param->getPlugin("spatial"));
		if (pplugin->isSetSpatialSymbolReference()) {
			cout << "Parameter" << i << "  SpRefId: "  << pplugin->getSpatialSymbolReference()->getSpatialRef() << endl;
		}
		if (pplugin->isSetDiffusionCoefficient()) {
			cout << "Diff_" << i << "  SpeciesVarId: "  << pplugin->getDiffusionCoefficient()->getVariable() << endl;
			cout << "Diff_" << i << "  Type: "  << DiffusionKind_toString(pplugin->getDiffusionCoefficient()->getType()) << endl;
      for (unsigned int j = 0; j < pplugin->getDiffusionCoefficient()->getNumCoordinateReferences(); ++j)
        cout << "Diff_" << i << "  SpCoordIndex  " << j << " : " << CoordinateKind_toString(pplugin->getDiffusionCoefficient()->getCoordinateReference(j) ->getCoordinate()) << endl;
		}
		if (pplugin->isSetAdvectionCoefficient()) {
			cout << "Adv_" << i << "  SpeciesVarId: "  << pplugin->getAdvectionCoefficient()->getVariable() << endl;
			cout << "Adv_" << i << "  SpCoordIndex: "  << CoordinateKind_toString(pplugin->getAdvectionCoefficient()->getCoordinate()) << endl;
		}
		if (pplugin->isSetBoundaryCondition()) {
			cout << "BC_" << i << "  SpeciesVarId: "  << pplugin->getBoundaryCondition()->getVariable() << endl;
			cout << "BC_" << i << "  SpCoordBoundary: "  << pplugin->getBoundaryCondition()->getCoordinateBoundary() << endl;
			cout << "BC_" << i << "  SpBoundaryType: "  << pplugin->getBoundaryCondition()->getType() << endl;
		}
	}

	Reaction *rxn;
	SpatialReactionPlugin* rplugin;
	for (unsigned int i = 0; i < model2->getNumReactions(); i++) {
		rxn = model2->getReaction(i);
		cout << "Reaction" << i << ": "      << rxn->getId()      << endl;
		rplugin = static_cast<SpatialReactionPlugin*>(rxn->getPlugin("spatial"));
		if (rplugin->getIsLocal()) {
			cout << "rxn" << i << "  isLocal: "  << rplugin->getIsLocal() << endl;
		}
	}

	Rule *rule;
	for (unsigned int i = 0; i < model2->getNumRules(); i++) {
		rule = model2->getRule(i);
		cout << "Rule" << i << ": "      << rule->getVariable()      << endl;
	}

	//
	// Get a SpatialModelPlugin object plugged in the model object.
	//
	// The type of the returned value of SBase::getPlugin() function is 
	// SBasePlugin*, and thus the value needs to be cast for the 
	// corresponding derived class.
	//
	SpatialModelPlugin* mplugin2;
	mplugin2 = static_cast<SpatialModelPlugin*>(model2->getPlugin("spatial"));
	cout << "URI: "      << mplugin2->getURI()      << endl;
	cout << "prefix: "      << mplugin2->getPrefix()      << endl;

	// get a Geometry object via SpatialModelPlugin object.
	Geometry* geometry2 = mplugin2->getGeometry();
	cout << "Geometry coordSystem: "      << geometry2->getCoordinateSystem()      << endl;
    
	// get a CoordComponent object via the Geometry object.	
	CoordinateComponent* coordComp = geometry2->getCoordinateComponent(0);
	std::cout << "CoordComponent Id: " << coordComp->getId() << std::endl;
  std::cout << "CoordComponent type: " << CoordinateKind_toString( coordComp->getType()) << std::endl;
	std::cout << "CoordComponent sbmlUnit: " << coordComp->getUnit() << std::endl;
  if (coordComp->isSetBoundaryMin())
  {
  Boundary* minX = coordComp->getBoundaryMin();
	std::cout << "minX name: " << minX->getId() << std::endl;
	std::cout << "minX value: " << minX->getValue() << std::endl;
  }
  if (coordComp->isSetBoundaryMax())
  {
	Boundary* maxX = coordComp->getBoundaryMax();
	std::cout << "maxX name: " << maxX->getId() << std::endl;
	std::cout << "maxX value: " << maxX->getValue() << std::endl;
  }

	// get a DomainType object via the Geometry object.	
	DomainType* domainType2 = geometry2->getDomainType(0);
	std::cout << "DomainType Id: " << domainType2->getId() << std::endl;
	std::cout << "DomainType spatialDim: " << domainType2->getSpatialDimension() << std::endl;

	// get a Domain object via the Geometry object.	
	Domain* domain = geometry2->getDomain(0);
	std::cout << "Domain1 Id: " << domain->getId() << std::endl;
	std::cout << "Domain1 domainType: " << domain->getDomainType() << std::endl;
	// get an internal point via the domain object
	InteriorPoint* internalPt = domain->getInteriorPoint(0);
	std::cout << "InternalPt_1 coord1: " << internalPt->getCoord1() << std::endl;

	// get a Domain object via the Geometry object.	
	domain = geometry2->getDomain(1);
	std::cout << "Domain2 Id: " << domain->getId() << std::endl;
	std::cout << "Domain2 domainType: " << domain->getDomainType() << std::endl;
	// get an internal point via the domain object
	internalPt = domain->getInteriorPoint(0);
	std::cout << "InternalPt_2 coord1: " << internalPt->getCoord1() << std::endl;

	// get an AdjacentDomains object via the Geometry object.	
	AdjacentDomains* adjDomain = geometry2->getAdjacentDomains(0);
	std::cout << "AdjDomain Id: " << adjDomain->getId() << std::endl;
	std::cout << "AdjDomain domain1: " << adjDomain->getDomain1() << std::endl;
	std::cout << "AdjDomain domain2: " << adjDomain->getDomain2() << std::endl;

	// get an AnalyticGeometry object via the Geometry object.
	GeometryDefinition* gd;
	for (unsigned int i = 0; i < geometry2->getNumGeometryDefinitions(); i++) {
		gd = geometry2->getGeometryDefinition(i);
		if (gd->isAnalyticGeometry()) {
			AnalyticGeometry* analyticalGeom = static_cast<AnalyticGeometry*>(gd);
			std::cout << "AnalGeom Id: " << analyticalGeom->getId() << std::endl;

			// analVol from analGeom.
			AnalyticVolume* av = analyticalGeom->getAnalyticVolume(0);
			std::cout << "AnalVol Id: " << av->getId() << std::endl;
			std::cout << "AnalVol domainType: " << av->getDomainType() << std::endl;
			std::cout << "AnalVol funcType: " << av->getFunctionType() << std::endl;
			std::cout << "AnalVol ordinal: " << av->getOrdinal() << std::endl;
			const ASTNode* mathNode = av->getMath();
			char* mathStr = writeMathMLToString(mathNode);
			std::cout << "AnalVol math: " << mathStr << std::endl;
		}
		if (gd->isSampledFieldGeometry()) {
			SampledFieldGeometry* sfGeom = static_cast<SampledFieldGeometry*>(gd);
			std::cout << "SampledFieldGeom Id: " << sfGeom->getId() << std::endl;
			
			// sampledField from sfGeom
			SampledField* sf = sfGeom->getSampledField();
			std::cout << "SampledField Id: " << sf->getId() << std::endl;
			std::cout << "SampledField dataType: " << sf->getDataType() << std::endl;
			std::cout << "SampledField interpolation: " << sf->getInterpolationType() << std::endl;
			std::cout << "SampledField encoding: " << sf->getEncoding() << std::endl;
			std::cout << "SampledField numSamples1: " << sf->getNumSamples1() << std::endl;
			std::cout << "SampledField numSamples2: " << sf->getNumSamples2() << std::endl;
			std::cout << "SampledField numSamples3: " << sf->getNumSamples3() << std::endl;
			const ImageData* id = sf->getImageData();
			int* samples = new int[id->getSamplesLength()];
			id->getSamples(samples);
			std::cout << "ImageData samples[0]: " << samples[0] << std::endl;
			std::cout << "ImageData dtype: " << id->getDataType() << std::endl;
			std::cout << "ImageData samplesLen: " << id->getSamplesLength() << std::endl;
      
			// sampledVolVol from sfGeom.
			SampledVolume* sv = sfGeom->getSampledVolume(0);
			std::cout << "SampledVol Id: " << sv->getId() << std::endl;
			std::cout << "SampledVol domainType: " << sv->getDomainType() << std::endl;
			std::cout << "SampledVol sampledVal: " << sv->getSampledValue() << std::endl;
			std::cout << "SampledVol min: " << sv->getMinValue() << std::endl;
			std::cout << "SampledVol max: " << sv->getMaxValue() << std::endl;
		}
	}

	delete document2;
}
Пример #13
0
/* 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;

}