END_TEST START_TEST (test_WriteL3SBML_Species_conversionFactor) { const char* expected = "<species id=\"Ca2\" compartment=\"cell\"" " hasOnlySubstanceUnits=\"false\"" " boundaryCondition=\"true\" constant=\"true\"" " conversionFactor=\"p\"/>"; const char* expected1 = "<species id=\"Ca2\" compartment=\"cell\"" " hasOnlySubstanceUnits=\"false\"" " boundaryCondition=\"true\" constant=\"true\"/>"; Species *s = D->createModel()->createSpecies(); s->setId("Ca2"); s->setCompartment("cell"); s->setBoundaryCondition(true); s->setHasOnlySubstanceUnits(false); s->setConstant(true); s->setConversionFactor("p"); char* sbml = s->toSBML(); fail_unless( equals(expected, sbml) ); safe_free(sbml); s->unsetConversionFactor(); sbml = s->toSBML(); fail_unless( equals(expected1, sbml) ); safe_free(sbml); }
END_TEST START_TEST (test_WriteL3SBML_Species) { const char* expected = "<species id=\"Ca2\" compartment=\"cell\" initialAmount=\"0.7\"" " substanceUnits=\"mole\" hasOnlySubstanceUnits=\"false\"" " boundaryCondition=\"true\" constant=\"true\"/>"; Species *s = D->createModel()->createSpecies(); s->setId("Ca2"); s->setCompartment("cell"); s->setInitialAmount(0.7); s->setUnits("mole"); s->setBoundaryCondition(true); s->setHasOnlySubstanceUnits(false); s->setConstant(true); char* sbml = s->toSBML(); fail_unless( equals(expected, sbml) ); safe_free(sbml); }
LIBSBML_CPP_NAMESPACE_USE int main(int argc,char** argv) { SBMLNamespaces sbmlns(3,1,"fbc",1); // create the document SBMLDocument *document = new SBMLDocument(&sbmlns); document->setPackageRequired("fbc", false); // create the Model Model* model=document->createModel(); // create the Compartment Compartment* compartment = model->createCompartment(); compartment->setId("compartment"); compartment->setConstant(true); compartment->setSize(1); // create the Species Species* species = model->createSpecies(); species->setId("Node1"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node2"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node3"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node4"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node5"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node6"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node7"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node8"); species->setCompartment("compartment"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node0"); species->setCompartment("compartment"); species->setBoundaryCondition(true); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("Node9"); species->setCompartment("compartment"); species->setBoundaryCondition(true); species->setConstant(false); species->setHasOnlySubstanceUnits(false); Reaction* reaction = model->createReaction(); reaction->setId("J0"); reaction->setReversible(false); reaction->setFast(false); SpeciesReference* reactant = reaction->createReactant(); reactant->setSpecies("Node0"); reactant->setStoichiometry(1); reactant->setConstant(true); SpeciesReference* product = reaction->createProduct(); product->setSpecies("Node1"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J1"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node1"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node2"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J2"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node2"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node3"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J3"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node1"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node4"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J4"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node4"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node3"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J5"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node3"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node5"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J6"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node5"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node6"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J7"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node6"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node7"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J8"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node5"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node8"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J9"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node8"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node7"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("J10"); reaction->setReversible(false); reaction->setFast(false); reactant = reaction->createReactant(); reactant->setSpecies("Node7"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("Node9"); product->setStoichiometry(1); product->setConstant(true); // // Get a FbcModelPlugin 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 casted for the // corresponding derived class. // FbcModelPlugin* mplugin = static_cast<FbcModelPlugin*>(model->getPlugin("fbc")); FluxBound* bound= mplugin->createFluxBound(); bound->setId("bound1"); bound->setReaction("J0"); bound->setOperation("equal"); bound->setValue(10); Objective* objective = mplugin->createObjective(); objective->setId("obj1"); objective->setType("maximize"); // mark obj1 as active objective mplugin->setActiveObjectiveId("obj1"); FluxObjective* fluxObjective = objective->createFluxObjective(); fluxObjective->setReaction("J8"); fluxObjective->setCoefficient(1); writeSBML(document,"fbc_example1.xml"); delete document; }
void Model::assignRequiredValues() { // when converting to L3 some attributes which have default values in L1/L2 // but are required in L3 are not present or set unsigned int i, n; if (getNumUnitDefinitions() > 0) { for (i = 0; i < getNumUnitDefinitions(); i++) { for (n = 0; n < getUnitDefinition(i)->getNumUnits(); n++) { Unit *u = getUnitDefinition(i)->getUnit(n); if (!u->isSetExponent()) u->setExponent(1.0); if (!u->isSetScale()) u->setScale(0); if (!u->isSetMultiplier()) u->setMultiplier(1.0); } } } if (getNumCompartments() > 0) { for (i = 0; i < getNumCompartments(); i++) { Compartment *c = getCompartment(i); c->setConstant(c->getConstant()); } } if (getNumSpecies() > 0) { for (i = 0; i < getNumSpecies(); i++) { Species * s = getSpecies(i); s->setBoundaryCondition(s->getBoundaryCondition()); s->setHasOnlySubstanceUnits(s->getHasOnlySubstanceUnits()); s->setConstant(s->getConstant()); } } if (getNumParameters() > 0) { for (i = 0; i < getNumParameters(); i++) { Parameter * p = getParameter(i); p->setConstant(p->getConstant()); } } if (getNumReactions() > 0) { for (i = 0; i < getNumReactions(); i++) { Reaction * r = getReaction(i); r->setFast(r->getFast()); r->setReversible(r->getReversible()); if (r->getNumReactants() > 0) { for (n = 0; n < r->getNumReactants(); n++) { SpeciesReference *sr = r->getReactant(n); if (sr->isSetStoichiometryMath()) { sr->setConstant(false); } else { sr->setConstant(true); } } } if (r->getNumProducts() > 0) { for (n = 0; n < r->getNumProducts(); n++) { SpeciesReference *sr = r->getProduct(n); if (sr->isSetStoichiometryMath()) { sr->setConstant(false); } else { sr->setConstant(true); } } } } } if (getNumEvents() > 0) { for (i = 0; i < getNumEvents(); i++) { Event * e = getEvent(i); e->setUseValuesFromTriggerTime(e->getUseValuesFromTriggerTime()); if (e->isSetTrigger()) { Trigger *t = e->getTrigger(); t->setPersistent(true); t->setInitialValue(true); } } } }
LIBSBML_CPP_NAMESPACE_USE int main(int argc,char** argv) { DynPkgNamespaces sbmlns; // create the document SBMLDocument *document = new SBMLDocument(&sbmlns); document->setPackageRequired("dyn", true); // create the Model Model* model=document->createModel(); model->setId("singleCell"); // create the Compartment Compartment* compartment = model->createCompartment(); compartment->setId("Extracellular"); compartment->setConstant(true); compartment->setSize(8000000); compartment->setSpatialDimensions(3.0); compartment = model->createCompartment(); compartment->setId("PlasmaMembrane"); compartment->setConstant(true); compartment->setSize(314); compartment->setSpatialDimensions(2.0); compartment = model->createCompartment(); compartment->setId("Cytosol"); compartment->setConstant(true); compartment->setSize(523); compartment->setSpatialDimensions(3.0); // create the Species Species* species = model->createSpecies(); species->setId("C_EC"); species->setCompartment("Extracellular"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("RTR_M"); species->setCompartment("PlasmaMembrane"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("RCC_M"); species->setCompartment("PlasmaMembrane"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("A_C"); species->setCompartment("Cytosol"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("AA_C"); species->setCompartment("Cytosol"); species->setBoundaryCondition(false); species->setConstant(false); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("T"); species->setCompartment("Cytosol"); species->setBoundaryCondition(false); species->setConstant(false); species->setInitialConcentration(10); species->setHasOnlySubstanceUnits(false); species = model->createSpecies(); species->setId("S"); species->setCompartment("Cytosol"); species->setBoundaryCondition(false); species->setConstant(false); species->setInitialConcentration(5); species->setHasOnlySubstanceUnits(false); // create the Reactions Reaction* reaction = model->createReaction(); reaction->setId("r1"); reaction->setReversible(true); reaction->setFast(false); reaction->setCompartment("Extracellular"); SpeciesReference* reactant = reaction->createReactant(); reactant->setSpecies("RTR_M"); reactant->setStoichiometry(1); reactant->setConstant(true); reactant = reaction->createReactant(); reactant->setSpecies("C_EC"); reactant->setStoichiometry(1); reactant->setConstant(true); SpeciesReference* product = reaction->createProduct(); product->setSpecies("RCC_M"); product->setStoichiometry(1); product->setConstant(true); reaction = model->createReaction(); reaction->setId("r2"); reaction->setReversible(true); reaction->setFast(false); reaction->setCompartment("Cytosol"); reactant = reaction->createReactant(); reactant->setSpecies("A_C"); reactant->setStoichiometry(1); reactant->setConstant(true); product = reaction->createProduct(); product->setSpecies("AA_C"); product->setStoichiometry(1); product->setConstant(true); SimpleSpeciesReference* modifier = reaction->createModifier(); modifier->setSpecies("RCC_M"); // Create Event Event* event = model->createEvent(); event->setUseValuesFromTriggerTime(true); Trigger* trigger = event->createTrigger(); trigger->setInitialValue(false); trigger->setPersistent(true); trigger->setMath(SBML_parseFormula("lt(AA_C, T)")); // // Get a DynEventPlugin object plugged in the event object. // // The type of the returned value of SBase::getPlugin() function is // SBasePlugin*, and thus the value needs to be casted for the // corresponding derived class. // DynEventPlugin* eplugin = static_cast<DynEventPlugin*>(event->getPlugin("dyn")); eplugin->setApplyToAll(true); eplugin->setCboTerm("http://cbo.biocomplexity.indiana.edu/svn/cbo/trunk/CBO_1_0.owl#CellDeath"); event = model->createEvent(); event->setUseValuesFromTriggerTime(true); trigger = event->createTrigger(); trigger->setInitialValue(false); trigger->setPersistent(true); trigger->setMath(SBML_parseFormula("lt(AA_C, S)")); eplugin = static_cast<DynEventPlugin*>(event->getPlugin("dyn")); eplugin->setApplyToAll(true); eplugin->setCboTerm("http://cbo.biocomplexity.indiana.edu/svn/cbo/trunk/CBO_1_0.owl#CellDevision"); document->checkConsistency(); if (document->getNumErrors(LIBSBML_SEV_ERROR) > 0) document->printErrors(); writeSBML(document,"dyn_example1.xml"); delete document; }
int main(int argc,char** argv) { int retval = 0; SBMLNamespaces sbmlns(3,1,"comp",1); // create the document SBMLDocument *document = new SBMLDocument(&sbmlns); //Define the external model definitions CompSBMLDocumentPlugin* compdoc = static_cast<CompSBMLDocumentPlugin*>(document->getPlugin("comp")); compdoc->setRequired(true); ExternalModelDefinition* extmod = compdoc->createExternalModelDefinition(); extmod->setId("ExtMod1"); extmod->setSource("enzyme_model.xml"); extmod->setModelRef("enzyme"); // create the main Model Model* model=document->createModel(); // Set the submodels CompModelPlugin* mplugin = static_cast<CompModelPlugin*>(model->getPlugin("comp")); Submodel* submod1 = mplugin->createSubmodel(); submod1->setId("A"); submod1->setModelRef("ExtMod1"); Submodel* submod2 = mplugin->createSubmodel(); submod2->setId("B"); submod2->setModelRef("ExtMod1"); // create a replacement compartment Compartment* comp=model->createCompartment(); comp->setSpatialDimensions((unsigned int)3); comp->setConstant(true); comp->setId("comp"); comp->setSize(1L); //Tell the model that this compartment replaces both of the inside ones. CompSBasePlugin* compartplug = static_cast<CompSBasePlugin*>(comp->getPlugin("comp")); ReplacedElement re; re.setIdRef("comp"); re.setSubmodelRef("A"); compartplug->addReplacedElement(&re); re.setSubmodelRef("B"); compartplug->addReplacedElement(&re); // create a replacement species Species* spec = model->createSpecies(); spec->setCompartment("comp"); spec->setHasOnlySubstanceUnits(false); spec->setConstant(false); spec->setBoundaryCondition(false); spec->setId("S"); //Tell the model that this species replaces both of the inside ones. CompSBasePlugin* spp = static_cast<CompSBasePlugin*>(spec->getPlugin("comp")); re.setIdRef("S"); re.setSubmodelRef("A"); spp->addReplacedElement(&re); re.setSubmodelRef("B"); spp->addReplacedElement(&re); writeSBMLToFile(document,"eg-import-external.xml"); writeSBMLToFile(document,"spec_example2.xml"); delete document; document = readSBMLFromFile("spec_example2.xml"); if (document == NULL) { cout << "Error reading back in file." << endl; retval = -1; } else { document->setConsistencyChecks(LIBSBML_CAT_UNITS_CONSISTENCY, false); document->checkConsistency(); if (document->getErrorLog()->getNumFailsWithSeverity(2) > 0 || document->getErrorLog()->getNumFailsWithSeverity(3) > 0) { stringstream errorstream; document->printErrors(errorstream); cout << "Errors encoutered when round-tripping SBML file: \n" << errorstream.str() << endl; retval = -1; } writeSBMLToFile(document, "spec_example2_rt.xml"); delete document; } #ifdef WIN32 if (retval != 0) { cout << "(Press any key to exit.)" << endl; _getch(); } #endif return retval; }
LIBSBML_CPP_NAMESPACE_USE int main (int argc, char* argv[]) { SBMLNamespaces sbmlns(3,1,"multi",1); // create the document SBMLDocument *document = new SBMLDocument(&sbmlns); // set the required attribute to true MultiSBMLDocumentPlugin * docPlug = static_cast<MultiSBMLDocumentPlugin*>(document->getPlugin("multi")); docPlug->setRequired(true); // create the Model Model* model=document->createModel(); // create the compartments Compartment * c = model->createCompartment(); c->setId("membrane"); c->setConstant(true); // set the multi attribute isType via the compartmentPlugin MultiCompartmentPlugin * compPlug = static_cast<MultiCompartmentPlugin*>(c->getPlugin("multi")); compPlug->setIsType(true); // create the speciesTypes MultiModelPlugin * modelPlug = static_cast<MultiModelPlugin*>(model->getPlugin("multi")); MultiSpeciesType * st = modelPlug->createMultiSpeciesType(); st->setId("stX"); st->setCompartment("membrane"); // create species Species *s = model->createSpecies(); s->setId("s1"); s->setCompartment("membrane"); s->setBoundaryCondition(false); s->setHasOnlySubstanceUnits(false); s->setConstant(false); // set the multi attribute speciesType via the compartmentPlugin MultiSpeciesPlugin * spPlug = static_cast<MultiSpeciesPlugin*>(s->getPlugin("multi")); spPlug->setSpeciesType("stX"); // create species feature SpeciesFeature *sf = spPlug->createSpeciesFeature(); sf->setSpeciesFeatureType("a"); sf->setOccur(1); sf->setComponent("b"); SpeciesFeatureValue *sfv = sf->createSpeciesFeatureValue(); sfv->setValue("c"); // create a subListOfSpeciesFeatures SubListOfSpeciesFeatures* subloSF = spPlug->createSubListOfSpeciesFeatures(); subloSF->setRelation(Relation_fromString("and")); // add speciesFeatures to the subList SpeciesFeature *sf1 = new SpeciesFeature(3, 1, 1); sf1->setSpeciesFeatureType("a1"); sf1->setOccur(1); sf1->setComponent("b1"); SpeciesFeatureValue *sfv1 = sf1->createSpeciesFeatureValue(); sfv1->setValue("c1"); subloSF->appendAndOwn(sf1); sf1 = new SpeciesFeature(3, 1, 1); sf1->setSpeciesFeatureType("a2"); sf1->setOccur(1); sf1->setComponent("b2"); sfv1 = sf1->createSpeciesFeatureValue(); sfv1->setValue("c2"); subloSF->appendAndOwn(sf1); // create a second subListOfSpeciesfeatures subloSF = spPlug->createSubListOfSpeciesFeatures(); subloSF->setRelation(Relation_fromString("or")); sf1 = new SpeciesFeature(3, 1, 1); sf1->setSpeciesFeatureType("a3"); sf1->setOccur(1); sf1->setComponent("b3"); sfv1 = sf1->createSpeciesFeatureValue(); sfv1->setValue("c3"); subloSF->appendAndOwn(sf1); sf1 = new SpeciesFeature(3, 1, 1); sf1->setSpeciesFeatureType("a4"); sf1->setOccur(1); sf1->setComponent("b4"); sfv1 = sf1->createSpeciesFeatureValue(); sfv1->setValue("c4"); subloSF->appendAndOwn(sf1); writeSBML(document,"multi_example3.xml"); delete document; return 0; }
LIBSBML_CPP_NAMESPACE_USE int main(int argc,char** argv) { DynPkgNamespaces sbmlns; sbmlns.addPackageNamespace("comp", 1, "comp"); // create the document SBMLDocument *document = new SBMLDocument(&sbmlns); document->setPackageRequired("dyn", true); document->setPackageRequired("comp", true); // create the Model Model* model=document->createModel(); model->setId("grid2x2"); // create the Compartment Compartment* compartment = model->createCompartment(); compartment->setId("Loc1"); compartment->setConstant(false); compartment->setSize(1); compartment->setSpatialDimensions(2.0); DynCompartmentPlugin* cplugin = static_cast<DynCompartmentPlugin*>(compartment->getPlugin("dyn")); SpatialComponent* component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANX); component->setVariable("q1_X"); component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANY); component->setVariable("q1_Y"); CompSBasePlugin* compPlugin = static_cast<CompSBasePlugin*>(compartment->getPlugin("comp")); ReplacedElement* relement = compPlugin->createReplacedElement(); relement->setIdRef("C"); relement->setSubmodelRef("GRID_1_1_cell"); compartment = model->createCompartment(); compartment->setId("Loc2"); compartment->setConstant(false); compartment->setSize(1); compartment->setSpatialDimensions(2.0); cplugin = static_cast<DynCompartmentPlugin*>(compartment->getPlugin("dyn")); component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANX); component->setVariable("q2_X"); component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANY); component->setVariable("q2_Y"); compPlugin = static_cast<CompSBasePlugin*>(compartment->getPlugin("comp")); relement = compPlugin->createReplacedElement(); relement->setIdRef("C"); relement->setSubmodelRef("GRID_1_2_cell"); compartment = model->createCompartment(); compartment->setId("Loc3"); compartment->setConstant(false); compartment->setSize(1); compartment->setSpatialDimensions(2.0); cplugin = static_cast<DynCompartmentPlugin*>(compartment->getPlugin("dyn")); component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANX); component->setVariable("q3_X"); component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANY); component->setVariable("q3_Y"); compPlugin = static_cast<CompSBasePlugin*>(compartment->getPlugin("comp")); relement = compPlugin->createReplacedElement(); relement->setIdRef("C"); relement->setSubmodelRef("GRID_2_1_cell"); compartment = model->createCompartment(); compartment->setId("Loc4"); compartment->setConstant(false); compartment->setSize(1); compartment->setSpatialDimensions(2.0); cplugin = static_cast<DynCompartmentPlugin*>(compartment->getPlugin("dyn")); component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANX); component->setVariable("q4_X"); component = cplugin->createSpatialComponent(); component->setSpatialIndex(DYN_SPATIALKIND_CARTESIANY); component->setVariable("q4_Y"); compPlugin = static_cast<CompSBasePlugin*>(compartment->getPlugin("comp")); relement = compPlugin->createReplacedElement(); relement->setIdRef("C"); relement->setSubmodelRef("GRID_2_2_cell"); // create Parameters Parameter* param = model->createParameter(); param->initDefaults(); param->setId("q1_X"); param->setValue(1); param = model->createParameter(); param->initDefaults(); param->setId("q1_Y"); param->setValue(1); param = model->createParameter(); param->initDefaults(); param->setId("q2_X"); param->setValue(2); param = model->createParameter(); param->initDefaults(); param->setId("q2_Y"); param->setValue(1); param = model->createParameter(); param->initDefaults(); param->setId("q3_X"); param->setValue(1); param = model->createParameter(); param->initDefaults(); param->setId("q3_Y"); param->setValue(2); param = model->createParameter(); param->initDefaults(); param->setId("q4_X"); param->setValue(2); param = model->createParameter(); param->initDefaults(); param->setId("q4_Y"); param->setValue(2); // create SubModels CompModelPlugin* mplugin = static_cast<CompModelPlugin*>(model->getPlugin("comp")); Submodel* submodel = mplugin->createSubmodel(); submodel->setId("GRID_1_1_cell"); submodel->setModelRef("Cell"); submodel = mplugin->createSubmodel(); submodel->setId("GRID_1_2_cell"); submodel->setModelRef("Cell"); submodel = mplugin->createSubmodel(); submodel->setId("GRID_2_1_cell"); submodel->setModelRef("Cell"); submodel = mplugin->createSubmodel(); submodel->setId("GRID_2_2_cell"); submodel->setModelRef("Cell"); // create the ModelDefinition CompSBMLDocumentPlugin* dplugin = static_cast<CompSBMLDocumentPlugin*>(document->getPlugin("comp")); ModelDefinition* mdef = dplugin->createModelDefinition(); mdef->setId("Cell"); compartment = mdef->createCompartment(); compartment->initDefaults(); compartment->setId("C"); compartment->setSpatialDimensions(2.0); compartment->setSize(1.0); Species* species = mdef->createSpecies(); species->setId("R"); species->setCompartment("C"); species->setHasOnlySubstanceUnits(false); species->setBoundaryCondition(false); species->setConstant(false); species = mdef->createSpecies(); species->setId("S"); species->setCompartment("C"); species->setHasOnlySubstanceUnits(false); species->setBoundaryCondition(false); species->setConstant(false); Reaction* reaction = mdef->createReaction(); reaction->setId("Degradation_R"); reaction->setReversible(false); reaction->setFast(false); reaction->setCompartment("C"); SpeciesReference* reactant = reaction->createReactant(); reactant->setSpecies("R"); reactant->setStoichiometry(1); reactant->setConstant(true); reaction = mdef->createReaction(); reaction->setId("Degradation_S"); reaction->setReversible(false); reaction->setFast(false); reaction->setCompartment("C"); reactant = reaction->createReactant(); reactant->setSpecies("S"); reactant->setStoichiometry(1); reactant->setConstant(true); document->checkConsistency(); Event* event = mdef->createEvent(); event->setId("event0"); event->setUseValuesFromTriggerTime(false); DynEventPlugin* eplugin = static_cast<DynEventPlugin*>(event->getPlugin("dyn")); eplugin->setApplyToAll(true); eplugin->setCboTerm("http://cbo.biocomplexity.indiana.edu/svn/cbo/trunk/CBO_1_0.owl#CellDivision"); Trigger* trigger = event->createTrigger(); trigger->setInitialValue(false); trigger->setPersistent(false); trigger->setMath(SBML_parseFormula("true")); if (document->getNumErrors(LIBSBML_SEV_ERROR) > 0) document->printErrors(); writeSBML(document,"dyn_example2.xml"); delete document; }
LIBSBML_CPP_NAMESPACE_USE int main(int argc,char** argv){ // // Creates an SBMLNamespaces object with the given SBML level, version // package name, package version. // // (NOTE) By defualt, the name of package (i.e. "groups") will be used // if the arugment for the prefix is missing or empty. Thus the argument // for the prefix can be added as follows: // // SBMLNamespaces sbmlns(3,1,"groups",1,"GROUP"); // SBMLNamespaces sbmlns(3,1,"groups",1); // // (NOTES) The above code creating an SBMLNamespaces object can be replaced // with one of the following other styles. // // (1) Creates an SBMLNamespace object with a SBML core namespace and then // adds a groups package namespace to the object. // // SBMLNamespaces sbmlns(3,1); // sbmlns.addPkgNamespace("groups",1); // // OR // // SBMLNamespaces sbmlns(3,1); // sbmlns.addNamespace(GroupsExtension::XmlnsL3V1V1,"groups"); // // (2) Creates a GroupsPkgNamespaces object (SBMLNamespace derived class for // groups package. The class is basically used for createing an SBase derived // objects defined in the groups package) with the given SBML level, version, // and package version // // GroupsPkgNamespaces sbmlns(3,1,1); // // create the document SBMLDocument *document = new SBMLDocument(&sbmlns); // create the Model Model* model=document->createModel(); // create the Compartment Compartment* compartment = model->createCompartment(); compartment->setId("cytosol"); compartment->setConstant(true); compartment=model->createCompartment(); compartment->setId("mitochon"); compartment->setConstant(true); // create the Species Species* species = model->createSpecies(); species->setId("ATPc"); species->setCompartment("cytosol"); species->setInitialConcentration(1); species->setHasOnlySubstanceUnits(false); species->setBoundaryCondition(false); species->setConstant(false); species = model->createSpecies(); species->setId("ATPm"); species->setCompartment("mitochon"); species->setInitialConcentration(2); species->setHasOnlySubstanceUnits(false); species->setBoundaryCondition(false); species->setConstant(false); // create the Groups // // Get a GroupsModelPlugin 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 casted for the corresponding derived class. // GroupsModelPlugin* mplugin = static_cast<GroupsModelPlugin*>(model->getPlugin("groups")); // // Creates a Group object via GroupsModelPlugin object. // Group* group = mplugin->createGroup(); group->setId("ATP"); group->setKind(GROUP_KIND_CLASSIFICATION); group->setSBOTerm("SBO:0000252"); Member* member = group->createMember(); member->setIdRef("ATPc"); member = group->createMember(); member->setIdRef("ATPm"); writeSBML(document,"groups_example1.xml"); delete document; }