本文整理汇总了C++中CompModelPlugin类的典型用法代码示例。如果您正苦于以下问题:C++ CompModelPlugin类的具体用法?C++ CompModelPlugin怎么用?C++ CompModelPlugin使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CompModelPlugin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hasActualErrors
bool hasActualErrors(SBMLDocument* document)
{
document->checkConsistency();
for (unsigned int e=0; e<document->getNumErrors(); e++) {
if (document->getError(e)->getSeverity() >= LIBSBML_SEV_ERROR) return true;
}
#ifdef USE_COMP
CompModelPlugin* compmod = static_cast<CompModelPlugin*>(document->getModel()->getPlugin("comp"));
if (compmod != NULL && compmod->getNumSubmodels() > 0) {
SBMLDocument flat(*document);
ConversionProperties* props = new ConversionProperties();
props->addOption("flatten comp");
SBMLConverter* converter =
SBMLConverterRegistry::getInstance().getConverterFor(*props);
converter->setDocument(&flat);
int result = converter->convert();
flat.checkConsistency();
bool flaterrors = false;
SBMLErrorLog* errlog = document->getErrorLog();
for (unsigned int e=0; e<flat.getNumErrors(); e++) {
if (flat.getError(e)->getSeverity() >= LIBSBML_SEV_ERROR) {
flaterrors = true;
errlog->add(*(flat.getError(e)));
}
}
if (flaterrors) return true;
}
#endif
return false;
}
示例2: getParentSBMLObject
//Deprecated function
int Replacing::performReplacement()
{
set<SBase*> toremove;
set<SBase*>* removed = NULL;
CompModelPlugin* cmp = NULL;
SBase* parent = getParentSBMLObject();
while (parent != NULL && parent->getTypeCode() != SBML_DOCUMENT) {
if (parent->getTypeCode() == SBML_COMP_MODELDEFINITION ||
parent->getTypeCode() == SBML_MODEL) {
cmp = static_cast<CompModelPlugin*>(parent->getPlugin("comp"));
if (cmp != NULL) {
removed = cmp->getRemovedSet();
}
}
parent = parent->getParentSBMLObject();
}
int ret = performReplacementAndCollect(removed, &toremove);
if (ret != LIBSBML_OPERATION_SUCCESS) {
return ret;
}
if (cmp == NULL) {
return LIBSBML_INVALID_OBJECT;
}
return cmp->removeCollectedElements(removed, &toremove);
}
示例3: getSBMLDocument
int CompModelPlugin::collectDeletionsAndDeleteSome(set<SBase*>* removed, set<SBase*>* toremove)
{
int ret = LIBSBML_OPERATION_SUCCESS;
SBMLDocument* doc = getSBMLDocument();
Model* model = static_cast<Model*>(getParentSBMLObject());
if (model==NULL) {
if (doc) {
string error = "Unable to attempt to perform deletions in CompModelPlugin::collectDeletionsAndDeleteSome: no parent model could be found for the given 'comp' model plugin element.";
doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
//Since deletions only exist in submodels, loop through the submodels.
for (unsigned int sub=0; sub<getNumSubmodels(); sub++) {
Submodel* submodel = getSubmodel(sub);
//First perform any deletions
for (unsigned int d=0; d<submodel->getNumDeletions(); d++) {
Deletion* deletion = submodel->getDeletion(d);
SBase* todel = deletion->getReferencedElement();
if (todel && (todel->getTypeCode() == SBML_COMP_DELETION ||
todel->getTypeCode() == SBML_COMP_REPLACEDBY ||
todel->getTypeCode() == SBML_COMP_REPLACEDELEMENT ||
todel->getTypeCode() == SBML_LOCAL_PARAMETER) )
{
//Go ahead and delete it!
set<SBase*> newToRemove;
newToRemove.insert(todel);
removeCollectedElements(removed, &newToRemove);
}
else {
//Otherwise, just collect it.
ret = deletion->collectDeletions(removed, toremove);
if (ret!=LIBSBML_OPERATION_SUCCESS) {
return ret;
}
}
}
//Next collect any deletions in that instantiated submodel (any that weren't just deleted)
Model* mod = submodel->getInstantiation();
if (mod==NULL) {
//getInstantiation sets its own error messages.
return LIBSBML_OPERATION_FAILED;
}
CompModelPlugin* modplug = static_cast<CompModelPlugin*>(mod->getPlugin(getPrefix()));
if (modplug==NULL) {
if (doc) {
//Shouldn't happen: 'getInstantiation' turns on the comp plugin.
string error = "Unable to rename elements in CompModelPlugin::collectDeletionsAndDeleteSome: no valid 'comp' plugin for the model instantiated from submodel " + submodel->getId();
doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
modplug->collectDeletionsAndDeleteSome(removed, toremove);
}
return ret;
}
示例4: getInstantiation
List*
Submodel::getAllInstantiatedElements()
{
Model* inst = getInstantiation();
if (inst==NULL) return NULL;
List* allElements = inst->getAllElements();
vector<List*> sublists;
CompModelPlugin* instp = static_cast<CompModelPlugin*>(inst->getPlugin(getPrefix()));
for (unsigned int sm=0; sm<instp->getNumSubmodels(); sm++) {
Submodel* subm=instp->getSubmodel(sm);
if (subm==NULL) return NULL;
List* sublist = subm->getAllInstantiatedElements();
sublists.push_back(sublist);
}
for (size_t l=0; l<sublists.size(); l++) {
allElements->transferFrom(sublists[l]);
delete sublists[l];
}
return allElements;
}
示例5: getSBMLDocument
SBase*
ReplacedElement::getReferencedElementFrom(Model* model)
{
SBMLDocument* doc = getSBMLDocument();
SBase* referent = Replacing::getReferencedElementFrom(model);
if (referent != NULL) return referent;
if (!isSetDeletion()) {
//In this case, something else went wrong in getReferencedElementFrom, which will have set its own error message.
return NULL;
}
model = getParentModel(this);
if (model==NULL) {
if (doc) {
string error = "In ReplacedElement::getReferencedElementFrom, unable to find referenced deletion '" + getDeletion() + "' for <replacedElement>: no parent model could be found.";
doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return NULL;
}
CompModelPlugin* mplugin = static_cast<CompModelPlugin*>(model->getPlugin(getPrefix()));
if (mplugin==NULL) {
if (doc) {
string error = "In ReplacedElement::getReferencedElementFrom, unable to find referenced deletion '" + getDeletion() + "' for <replacedElement>: no 'comp' plugin for the parent model could be found.";
doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return NULL;
}
Submodel* submod = mplugin->getSubmodel(getSubmodelRef());
if (submod==NULL) {
if (doc) {
string error = "In ReplacedElement::getReferencedElementFrom, unable to find referenced deletion '" + getDeletion() + "' for <replacedElement>: no such submodel '" + getSubmodelRef() + "'.";
doc->getErrorLog()->logPackageError("comp", CompReplacedElementSubModelRef, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return NULL;
}
SBase* ret = submod->getDeletion(getDeletion());
if (ret==NULL && doc) {
string error = "In ReplacedElement::getReferencedElementFrom, unable to find referenced deletion '" + getDeletion() + "' for <replacedElement>: no deletion with that ID exists in the model.";
doc->getErrorLog()->logPackageError("comp", CompDeletionMustReferenceObject, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return ret;
}
示例6: while
Model* CompModelPlugin::flattenModel() const
{
//First make a copy of our parent (the model to be flattened):
const Model* parent = static_cast<const Model*>(getParentSBMLObject());
if (parent==NULL) {
return NULL;
}
//doc needs to be non-const so that the error messages can be updated. Otherwise, nothing changes.
SBMLDocument* doc = const_cast<SBMLDocument*>(getSBMLDocument());
if (doc==NULL) {
return NULL;
}
//Set the original document so that it can find the model definitions
//and external model definitions while we flatten.
Model* flat = parent->clone();
flat->setSBMLDocument(doc);
CompModelPlugin* flatplug =
static_cast<CompModelPlugin*>(flat->getPlugin(getPrefix()));
// Now instantiate its submodels and
// follow all renaming/deletion/replacement rules.
vector<const Model*> submods;
int success = flatplug->instantiateSubmodels();
if (success != LIBSBML_OPERATION_SUCCESS) {
//instantiateSubmodels sets its own error messages.
delete flat;
return NULL;
}
//Now start the aggregation process.
//This goes from the bottom up, calling 'appendFrom' iteratively
//(from the plugin).
for (unsigned int sm=0; sm<flatplug->getNumSubmodels(); sm++)
{
Model* submodel = flatplug->getSubmodel(sm)->getInstantiation();
if (submodel==NULL) {
//getInstantiation should be calling a cached value by now, but if not, it will set its own error messages.
delete flat;
return NULL;
}
CompModelPlugin* submodplug =
static_cast<CompModelPlugin*>(submodel->getPlugin(getPrefix()));
if (submodplug != NULL) {
//Strip the ports from the submodel, as we no longer need them.
while (submodplug->getNumPorts() > 0)
{
delete submodplug->removePort(0);
}
}
success = flat->appendFrom(submodel);
if (success != LIBSBML_OPERATION_SUCCESS) {
string error = "Unable to flatten model in CompModelPlugin::flattenModel: appending elements from the submodel '" + submodel->getId() + "' to the elements of the parent model failed.";
doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
delete flat;
return NULL;
}
}
// Now we clear the saved referenced elements in the local Port objects,
// but point them to the new object if necessary.
flatplug->resetPorts();
// Next, strip the package info from 'flat'.
// We're going to remove everything but the Ports:
flatplug->mListOfSubmodels.clear();
flatplug->clearReplacedElements();
flatplug->unsetReplacedBy();
List* allelements = flat->getAllElements();
vector<SBase*> nonReplacedElements;
for (unsigned int el=0; el<allelements->getSize(); el++)
{
SBase* element = static_cast<SBase*>(allelements->get(el));
int type = element->getTypeCode();
if (!(type==SBML_COMP_REPLACEDBY ||
type==SBML_COMP_REPLACEDELEMENT ||
type==SBML_COMP_SBASEREF))
{
nonReplacedElements.push_back(element);
}
}
// delete the list
delete allelements;
for (unsigned int el=0; el<nonReplacedElements.size(); el++)
{
SBase* element = nonReplacedElements[el];
CompSBasePlugin* elplug =
static_cast<CompSBasePlugin*>(element->getPlugin(getPrefix()));
if (elplug != NULL)
{
elplug->clearReplacedElements();
elplug->unsetReplacedBy();
//.........这里部分代码省略.........
示例7: getSBMLDocument
int
Replacing::saveReferencedElement()
{
SBMLDocument* doc = getSBMLDocument();
if (!isSetSubmodelRef()) {
if (doc) {
string error = "Unable to find referenced element in Replacing::saveReferencedElement: the given <" + getElementName() + "> element";
if (isSetId()) {
error += " '" + getId() + "'";
}
error += " has no 'submodelRef' attribute.";
doc->getErrorLog()->logPackageError("comp", CompReplacedElementAllowedAttributes, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return LIBSBML_INVALID_OBJECT;
}
Model* model = getParentModel(this);
if (model==NULL) {
if (doc) {
string error = "Unable to find referenced element in Replacing::saveReferencedElement: no parent model could be found for the given <" + getElementName() + "> element";
if (isSetId()) {
error += " '" + getId() + "'.";
}
doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return LIBSBML_OPERATION_FAILED;
}
CompModelPlugin* cmp = static_cast<CompModelPlugin*>(model->getPlugin(getPrefix()));
if (cmp==NULL) {
if (doc) {
string error = "Unable to find referenced element in Replacing::saveReferencedElement: no 'comp' plugin for the parent model could be found for the given <" + getElementName() + "> element";
if (isSetId()) {
error += " '" + getId() + "'.";
}
doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return LIBSBML_OPERATION_FAILED;
}
Submodel* submod = cmp->getSubmodel(getSubmodelRef());
if (submod==NULL) {
if (doc) {
string error = "Unable to find referenced element for the given <" + getElementName() + "> element";
if (isSetId()) {
error += " '" + getId() + "'";
}
error += " in Replacing::saveReferencedElement: the submodelRef '" + getSubmodelRef() + "' could not be found in the model.";
int errnumber = CompReplacedElementSubModelRef;
if (getTypeCode() == SBML_COMP_REPLACEDBY) {
errnumber = CompReplacedBySubModelRef;
}
doc->getErrorLog()->logPackageError("comp", errnumber, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return LIBSBML_INVALID_ATTRIBUTE_VALUE;
}
Model* inst = submod->getInstantiation();
if (inst==NULL) {
//getInstantiation sets it own error messages.
return LIBSBML_OPERATION_FAILED;
}
mReferencedElement = getReferencedElementFrom(inst);
if (mDirectReference==NULL) {
mDirectReference = mReferencedElement;
}
//getReferencedElement* set their own error messages:
if (mReferencedElement==NULL) {
return LIBSBML_OPERATION_FAILED;
}
if (mReferencedElement->getTypeCode()==SBML_COMP_PORT) {
mReferencedElement = static_cast<Port*>(mReferencedElement)->getReferencedElement();
}
if (mReferencedElement==NULL) {
return LIBSBML_OPERATION_FAILED;
}
return LIBSBML_OPERATION_SUCCESS;
}
示例8: getSBMLDocument
//.........这里部分代码省略.........
{
//No error message: it should be impossible, if origmodel has the type code 'external model definition', for it to not be castable to an external model definition.
mInstantiatedModel = NULL;
mInstantiationOriginalURI = "";
return LIBSBML_OPERATION_FAILED;
}
mInstantiatedModel = extmod->getReferencedModel(rootdoc, parents);
if (mInstantiatedModel == NULL)
{
string error = "In Submodel::instantiate, unable to instantiate submodel '" + getId() + "' because the external model definition it referenced (model '" + getModelRef() +"') could not be resolved.";
rootdoc->getErrorLog()->logPackageError("comp", CompSubmodelMustReferenceModel, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
mInstantiationOriginalURI = "";
return LIBSBML_OPERATION_FAILED;
}
mInstantiationOriginalURI = extmod->getSource();
origdoc = mInstantiatedModel->getSBMLDocument();
newmodel = extmod->getSource() + "::" + getModelRef();
if (uniqueModels.insert(newmodel).second == false) {
//Can't instantiate this model, because we are already a child of it.
string error = "Error in Submodel::instantiate: cannot instantiate submodel '" + getId() + "' in model '" + parentmodelname + "' because it references the model '" + getModelRef() + "', which is already an ancestor of the submodel.";
rootdoc->getErrorLog()->logPackageError("comp", CompSubmodelCannotReferenceSelf, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
mInstantiatedModel = NULL;
mInstantiationOriginalURI = "";
return LIBSBML_OPERATION_FAILED;
}
mInstantiatedModel = mInstantiatedModel->clone();
mInstantiationOriginalURI = extmod->getSource();
break;
default:
//Should always be one of the above, unless someone extends one of the above and doesn't tell us.
string error = "Instantiation error in Submodel::instantiate: unable to parse the model '" + origmodel->getId() + "', as it was not of the type 'model' 'modelDefinition', or 'externalModelDefinition'. The most likely cause of this situation is if some other package extended one of those three types, but the submodel code was not updated.";
rootdoc->getErrorLog()->logPackageError("comp", CompUnresolvedReference, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
mInstantiatedModel = NULL;
mInstantiationOriginalURI = "";
return LIBSBML_OPERATION_FAILED;
}
if (mInstantiatedModel==NULL)
{
string error = "Instantiation error in Submodel::instantiate: unable to create a valid copy of model '" + getModelRef() + "'.";
rootdoc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
mInstantiationOriginalURI = "";
return LIBSBML_OPERATION_FAILED;
}
mInstantiatedModel->connectToParent(this);
mInstantiatedModel->setSBMLDocument(origdoc);
mInstantiatedModel->enablePackage(getPackageURI(), getPrefix(), true);
CompModelPlugin* instmodplug =
static_cast<CompModelPlugin*>(mInstantiatedModel->getPlugin(getPrefix()));
if (instmodplug == NULL)
{
mInstantiatedModel->enablePackageInternal(getPackageURI(), getPrefix(), true);
}
// call all registered callbacks
std::vector<ModelProcessingCallbackData*>::iterator it = mProcessingCBs.begin();
while(it != mProcessingCBs.end())
{
ModelProcessingCallbackData* current = *it;
int result = current->cb(mInstantiatedModel, rootdoc->getErrorLog(), current->data);
if (result != LIBSBML_OPERATION_SUCCESS)
return result;
++it;
}
CompModelPlugin* origmodplug =
static_cast<CompModelPlugin*>(rootdoc->getModel()->getPlugin(getPrefix()));
instmodplug =
static_cast<CompModelPlugin*>(mInstantiatedModel->getPlugin(getPrefix()));
if (instmodplug == NULL)
return LIBSBML_OPERATION_SUCCESS;
// if we have a transformer specified, then we need to propagate it, so it can
// be used
if (origmodplug->isSetTransformer())
{
if (instmodplug != NULL)
instmodplug->setTransformer(origmodplug->getTransformer());
}
for (unsigned int sub=0; sub<instmodplug->getNumSubmodels(); sub++)
{
Submodel* instsub = instmodplug->getSubmodel(sub);
int ret = instsub->instantiate();
if (ret != LIBSBML_OPERATION_SUCCESS) {
//'instantiate' already sets its own error messages.
delete mInstantiatedModel;
mInstantiatedModel = NULL;
mInstantiationOriginalURI = "";
return ret;
}
}
return LIBSBML_OPERATION_SUCCESS;
}
示例9: getSBMLDocument
SBase*
SBaseRef::getReferencedElementFrom(Model* model)
{
SBMLDocument* doc = getSBMLDocument();
if (!hasRequiredAttributes()) {
if (doc) {
string error = "In SBaseRef::getReferencedElementFrom, unable to find referenced element from <" + getElementName() + "> ";
if (isSetId()) {
error += "with ID '" + getId() + "' ";
}
error += "as it does not have the required attributes.";
int en = CompSBaseRefMustReferenceObject;
switch(getTypeCode()) {
case SBML_COMP_REPLACEDBY:
en = CompReplacedByAllowedAttributes;
break;
case SBML_COMP_REPLACEDELEMENT:
en = CompReplacedElementAllowedAttributes;
break;
case SBML_COMP_PORT:
en = CompPortAllowedAttributes;
break;
case SBML_COMP_DELETION:
en = CompDeletionAllowedAttributes;
}
doc->getErrorLog()->logPackageError("comp", en, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return NULL;
}
SBase* referent = NULL;
if (isSetPortRef()) {
CompModelPlugin* mplugin = static_cast<CompModelPlugin*>(model->getPlugin(getPrefix()));
Port* port = mplugin->getPort(getPortRef());
if (port==NULL) {
if (doc) {
string error = "In SBaseRef::getReferencedElementFrom, unable to find referenced element from SBase reference ";
if (isSetId()) {
error += "'" + getId() + "' ";
}
error += "as the port it references ('" + getPortRef() +"') could not be found.";
doc->getErrorLog()->logPackageError("comp", CompPortRefMustReferencePort, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return NULL;
}
mDirectReference = port;
referent = port->getReferencedElementFrom(model);
}
else if (isSetIdRef()) {
referent = model->getElementBySId(getIdRef());
if (referent == NULL && doc) {
string error = "In SBaseRef::getReferencedElementFrom, unable to find referenced element: no such SId in the model: '" + getIdRef() + "'.";
if (doc->getErrorLog()->contains(UnrequiredPackagePresent)
|| doc->getErrorLog()->contains(RequiredPackagePresent))
{
doc->getErrorLog()->logPackageError("comp",
CompIdRefMayReferenceUnknownPackage, getPackageVersion(),
getLevel(), getVersion(), error, getLine(), getColumn());
}
else
{
doc->getErrorLog()->logPackageError("comp",
CompIdRefMustReferenceObject, getPackageVersion(),
getLevel(), getVersion(), error, getLine(), getColumn());
}
}
}
else if (isSetUnitRef()) {
referent = model->getUnitDefinition(getUnitRef());
if (referent == NULL && doc) {
string error = "In SBaseRef::getReferencedElementFrom, unable to find referenced element: no such Unit in the model: '" + getUnitRef() + "'.";
doc->getErrorLog()->logPackageError("comp", CompUnitRefMustReferenceUnitDef, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
}
else if (isSetMetaIdRef()) {
referent = model->getElementByMetaId(getMetaIdRef());
if (referent == NULL && doc) {
string error = "In SBaseRef::getReferencedElementFrom, unable to find referenced element: no such metaid in the model: '" + getMetaIdRef() + "'.";
if (doc->getErrorLog()->contains(UnrequiredPackagePresent)
|| doc->getErrorLog()->contains(RequiredPackagePresent))
{
doc->getErrorLog()->logPackageError("comp",
CompIdRefMayReferenceUnknownPackage, getPackageVersion(),
getLevel(), getVersion(), error, getLine(), getColumn());
}
else
{
doc->getErrorLog()->logPackageError("comp",
CompMetaIdRefMustReferenceObject, getPackageVersion(),
getLevel(), getVersion(), error, getLine(), getColumn());
}
}
}
else {
//This is actually possible if the subclass overrides getNumReferents() (which some do). In that case, we just return NULL and let the overriding function find the referent instead.
return NULL;
}
if (referent == NULL) {
//No need to set an error message--one was already set above.
return NULL;
}
//.........这里部分代码省略.........
示例10: main
int main(int argc,char** argv)
{
int retval = 0;
SBMLNamespaces sbmlns(3,1,"comp",1);
// create the document
SBMLDocument *document = new SBMLDocument(&sbmlns);
//Create our submodel
CompSBMLDocumentPlugin* compdoc
= static_cast<CompSBMLDocumentPlugin*>(document->getPlugin("comp"));
compdoc->setRequired(true);
ModelDefinition* mod1 = compdoc->createModelDefinition();
mod1->setId("enzyme");
mod1->setName("enzyme");
Compartment* comp=mod1->createCompartment();
comp->setSpatialDimensions((unsigned int)3);
comp->setConstant(true);
comp->setId("comp");
comp->setSize(1L);
Species spec(&sbmlns);
spec.setCompartment("comp");
spec.setHasOnlySubstanceUnits(false);
spec.setConstant(false);
spec.setBoundaryCondition(false);
spec.setId("S");
mod1->addSpecies(&spec);
spec.setId("E");
mod1->addSpecies(&spec);
spec.setId("D");
mod1->addSpecies(&spec);
spec.setId("ES");
mod1->addSpecies(&spec);
Reaction rxn(&sbmlns);
rxn.setReversible(true);
rxn.setFast(false);
Reaction rxn2(rxn);
rxn.setId("J0");
rxn2.setId("J1");
SpeciesReference sr(&sbmlns);
sr.setConstant(true);
sr.setStoichiometry(1);
sr.setSpecies("S");
rxn.addReactant(&sr);
sr.setSpecies("E");
rxn.addReactant(&sr);
rxn2.addProduct(&sr);
sr.setSpecies("ES");
rxn.addProduct(&sr);
rxn2.addReactant(&sr);
sr.setSpecies("D");
rxn2.addProduct(&sr);
mod1->addReaction(&rxn);
mod1->addReaction(&rxn2);
// create the Model
Model* model=document->createModel();
model->setId("aggregate");
// Create a submodel
CompModelPlugin* mplugin = static_cast<CompModelPlugin*>(model->getPlugin("comp"));
Submodel* submod1 = mplugin->createSubmodel();
submod1->setId("submod1");
submod1->setModelRef("enzyme");
Submodel submod2;
submod2.setId("submod2");
submod2.setModelRef("enzyme");
mplugin->addSubmodel(&submod2);
writeSBMLToFile(document,"eg-simple-aggregate.xml");
writeSBMLToFile(document,"enzyme_model.xml");
delete document;
document = readSBMLFromFile("enzyme_model.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, "enzyme_model_rt.xml");
delete document;
}
#ifdef WIN32
if (retval != 0)
{
cout << "(Press any key to exit.)" << endl;
//.........这里部分代码省略.........
示例11: main
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 definition
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");
//Define the 'simple' model
ModelDefinition* mod1 = compdoc->createModelDefinition();
mod1->setId("simple");
Compartment* comp=mod1->createCompartment();
comp->setSpatialDimensions((unsigned int)3);
comp->setConstant(true);
comp->setId("comp");
comp->setSize(1L);
// We have to construct it this way because we get the comp
// plugin from it later.
Species spec(&sbmlns);
spec.setCompartment("comp");
spec.setHasOnlySubstanceUnits(false);
spec.setConstant(false);
spec.setBoundaryCondition(false);
spec.setId("S");
spec.setInitialConcentration(5);
mod1->addSpecies(&spec);
spec.setId("D");
spec.setInitialConcentration(10);
mod1->addSpecies(&spec);
Reaction rxn(&sbmlns);
rxn.setReversible(true);
rxn.setFast(false);
rxn.setId("J0");
SpeciesReference sr(&sbmlns);
sr.setConstant(true);
sr.setStoichiometry(1);
sr.setSpecies("S");
rxn.addReactant(&sr);
sr.setSpecies("D");
rxn.addProduct(&sr);
mod1->addReaction(&rxn);
CompModelPlugin* mod1plug
= static_cast<CompModelPlugin*>(mod1->getPlugin("comp"));
Port port;
port.setId("S_port");
port.setIdRef("S");
mod1plug->addPort(&port);
Port* port2 = mod1plug->createPort();
port2->setId("D_port");
port2->setIdRef("D");
port.setId("comp_port");
port.setIdRef("comp");
mod1plug->addPort(&port);
port.setId("J0_port");
port.setIdRef("J0");
mod1plug->addPort(&port);
// create the Model
Model* model=document->createModel();
model->setId("complexified");
// 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("simple");
Deletion* del = submod2->createDeletion();
del->setPortRef("J0_port");
// Synchronize the compartments
Compartment* mcomp=model->createCompartment();
mcomp->setSpatialDimensions((unsigned int)3);
mcomp->setConstant(true);
mcomp->setId("comp");
mcomp->setSize(1L);
CompSBasePlugin* compartplug
= static_cast<CompSBasePlugin*>(mcomp->getPlugin("comp"));
ReplacedElement re;
re.setIdRef("comp");
//.........这里部分代码省略.........
示例12: saveAllReferencedElements
/*
* Loop through all Submodels in this Model, instantiate all of them,
* perform all deletions, and synchronize all replacements.
* The resulting models are stored in the Submodel objects,
* and available from 'Submodel::getInstantiation()'
*/
int
CompModelPlugin::instantiateSubmodels()
{
Model* model = static_cast<Model*>(getParentSBMLObject());
if (model==NULL)
return LIBSBML_INVALID_OBJECT;
int ret;
// First we instantiate all the submodels.
// This acts recursively downward through the stack.
for (unsigned int sub=0; sub<mListOfSubmodels.size(); sub++)
{
Submodel* submodel = mListOfSubmodels.get(sub);
// Instead of 'instantiate', since we might have already
// been instantiated ourselves from above.
Model* submodinst = submodel->getInstantiation();
if (submodinst == NULL ) {
//'getInstantiation' already sets any errors that might have occurred.
return LIBSBML_OPERATION_FAILED;
}
// if we have a transformer specified, then we need to propagate it, so it can
// be used
if (isSetTransformer())
{
CompModelPlugin* other = dynamic_cast<CompModelPlugin*>(submodinst->getPlugin("comp"));
if (other != NULL)
other->setTransformer(getTransformer());
}
}
// Next, recursively find all the targets of SBaseRef elements
// and save them, since we're about to rename everything and
// we won't be able to find things by name any more.
ret = saveAllReferencedElements();
if (ret != LIBSBML_OPERATION_SUCCESS) {
//saveAllReferencedElements sets any errors.
return ret;
}
mRemoved.clear();
set<SBase*> toremove;
// Collect deletions (top-down):
// need to do this before renaming in case we delete a local parameter.
ret = collectDeletionsAndDeleteSome(&mRemoved, &toremove);
if (ret != LIBSBML_OPERATION_SUCCESS) {
return ret;
}
//Next, we rename *all* the elements so everything is unique.
ret = renameAllIDsAndPrepend("");
if (ret != LIBSBML_OPERATION_SUCCESS) {
return ret;
}
//Perform replacements and conversions (top-down) and collect them.
ret = collectRenameAndConvertReplacements(&mRemoved, &toremove);
if (ret != LIBSBML_OPERATION_SUCCESS) {
return ret;
}
//Finally, actually remove the collected elements from the model--they are
// all now redundant. Have to wait until now to do this, because of the
// possibility of nested constructs: replacing the child of a replaced
// element, for example, or even replacing the child of a deleted
// element.
removeCollectedElements(&mRemoved, &toremove);
mRemoved.clear();
return LIBSBML_OPERATION_SUCCESS;
}
示例13: main
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;
}
示例14: main
//.........这里部分代码省略.........
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);
示例15: stripPackages
/** @cond doxygenLibsbmlInternal */
int
CompFlatteningConverter::performConversion()
{
int result = LIBSBML_OPERATION_FAILED;
if (mDocument == NULL)
{
return LIBSBML_INVALID_OBJECT;
}
Model* mModel = mDocument->getModel();
if (mModel == NULL)
{
return LIBSBML_INVALID_OBJECT;
}
CompSBMLDocumentPlugin *plugin =
(CompSBMLDocumentPlugin*)(mDocument->getPlugin("comp"));
// if we don't have a comp model we are done already
if (plugin == NULL)
{
return LIBSBML_OPERATION_SUCCESS;
}
// strip packages as instructed by user
int success = stripPackages();
if (success != LIBSBML_OPERATION_SUCCESS)
{
return LIBSBML_OPERATION_FAILED;
}
// look at the document and work out the status of any remaining packages
mPackageValues.clear();
analyseDocument();
bool canFlatten = canBeFlattened();
if (canFlatten == false)
{
return LIBSBML_OPERATION_FAILED;
}
/* strip any unflattenable packages before we run validation */
if (getStripUnflattenablePackages() == true)
{
stripUnflattenablePackages();
}
/* run the comp validation rules as flattening will fail
* if there are bad or missing references between elements
*/
if (getPerformValidation() == true)
{
result = validateOriginalDocument();
if (result != LIBSBML_OPERATION_SUCCESS)
{
return result;
}
}
CompModelPlugin *modelPlugin = (CompModelPlugin*)(mModel->getPlugin("comp"));
if (modelPlugin==NULL)
{
restoreNamespaces();
return LIBSBML_OPERATION_FAILED;
}
mDocument->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed,
modelPlugin->getPackageVersion(), mDocument->getLevel(),
mDocument->getVersion(),
"The subsequent errors are from this attempt.");
// setup callback that will enable the packages on submodels
disable_info mainDoc;
mainDoc.doc = mDocument;
mainDoc.strippedPkgs = getPackagesToStrip();
mainDoc.disabledPkgs = mDisabledPackages;
mainDoc.stripUnflattenable = getStripUnflattenablePackages();
mainDoc.abortForRequiredOnly = getAbortForRequired();
Submodel::addProcessingCallback(&EnablePackageOnParentDocument, &(mainDoc));
Model* flatmodel = modelPlugin->flattenModel();
if (flatmodel == NULL)
{
//'flattenModel' sets its own error messages.
restoreNamespaces();
return LIBSBML_OPERATION_FAILED;
}
// we haven't failed flattening so remove that error message
mDocument->getErrorLog()->remove(CompModelFlatteningFailed);
//.........这里部分代码省略.........