本文整理汇总了C++中Species::getId方法的典型用法代码示例。如果您正苦于以下问题:C++ Species::getId方法的具体用法?C++ Species::getId怎么用?C++ Species::getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Species
的用法示例。
在下文中一共展示了Species::getId方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkSpecies
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: editSpecies
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;
}
示例3: logFailure
/*
* 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: findIdByNameAndType
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 "";
}
示例5: prop
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];
//.........这里部分代码省略.........
示例6: notes
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: readSpatialSBML
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;
//.........这里部分代码省略.........
示例8: writeSBML
/**
* 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;
//.........这里部分代码省略.........
示例9: iss
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);
//.........这里部分代码省略.........
示例10: if
/* 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:
void
CompIdBase::checkId (const Species& x)
{
if (x.isSetId()) doCheckId(x.getId(), x);
}
示例12: readSpatialSBML
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())
{
//.........这里部分代码省略.........
示例13: if
/* 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 {
//.........这里部分代码省略.........