END_TEST

START_TEST (test_comp_sbmldocument)
{
  SBMLNamespaces sbmlns(3,1,"comp",1);
  SBMLDocument doc(&sbmlns);
  CompSBMLDocumentPlugin* docplugin = static_cast<CompSBMLDocumentPlugin*>(doc.getPlugin("comp"));
  doc.setPackageRequired("comp", true);
  fail_unless(docplugin->getRequired() == true);

  fail_unless(docplugin->getNumModelDefinitions()==0);
  ModelDefinition* moddef = docplugin->createModelDefinition();
  moddef->setId("moddef1");
  fail_unless(docplugin->getNumModelDefinitions()==1);
  fail_unless(docplugin->addModelDefinition(NULL)==LIBSBML_INVALID_OBJECT);
  ModelDefinition moddef2(3, 1);
  moddef2.setId("moddef2");
  fail_unless(docplugin->addModelDefinition(&moddef2)==LIBSBML_OPERATION_SUCCESS);
  ModelDefinition* moddefref = docplugin->getModelDefinition("moddef2");
  fail_unless(moddefref->getId()=="moddef2");
  moddefref = docplugin->getModelDefinition(0);
  fail_unless(moddefref->getId()=="moddef1");
  moddef->setId("ID1");
  fail_unless(moddefref->getId()=="ID1");
  fail_unless(docplugin->removeModelDefinition(3)==NULL);
  fail_unless(docplugin->removeModelDefinition(0)==moddef);
  fail_unless(docplugin->getModelDefinition("moddef1")==NULL);

  fail_unless(docplugin->getNumExternalModelDefinitions()==0);
  ExternalModelDefinition* exmoddef = docplugin->createExternalModelDefinition();
  exmoddef->setId("exmoddef1");
  fail_unless(docplugin->getNumExternalModelDefinitions()==1);
  fail_unless(docplugin->addExternalModelDefinition(NULL)==LIBSBML_INVALID_OBJECT);
  ExternalModelDefinition exmoddef2(3, 1);
  exmoddef2.setId("exmoddef2");
  fail_unless(docplugin->addExternalModelDefinition(&exmoddef2)==LIBSBML_INVALID_OBJECT);
  exmoddef2.setSource("where/the/file/is.xml");
  fail_unless(docplugin->addExternalModelDefinition(&exmoddef2)==LIBSBML_OPERATION_SUCCESS);
  ExternalModelDefinition* exmoddefref = docplugin->getExternalModelDefinition("exmoddef2");
  fail_unless(exmoddefref->getId()=="exmoddef2");
  exmoddefref = docplugin->getExternalModelDefinition(0);
  fail_unless(exmoddefref->getId()=="exmoddef1");
  exmoddef->setModelRef("ID1");
  fail_unless(exmoddefref->getModelRef()=="ID1");
  fail_unless(docplugin->removeExternalModelDefinition(3)==NULL);
  fail_unless(docplugin->removeExternalModelDefinition(0)==exmoddef);
  fail_unless(docplugin->getExternalModelDefinition("exmoddef1")==NULL);

}
示例#2
0
    // Gater all Symbols and setup SymbolRefs and referencedSymbols
    void PharmML::setupSymbols() {
        SymbolGathering gathering;
        ModelDefinition *mdef = this->getModelDefinition();

        // Gather all symbols
        if (mdef->getParameterModel()) {
            mdef->getParameterModel()->gatherSymbols(gathering);
        }
        mdef->getStructuralModel()->gatherSymbols(gathering);
        for (VariabilityModel *vmod : mdef->getVariabilityModels()) {
            vmod->gatherSymbols(gathering);
        }
        if (mdef->getCovariateModel()) {
            mdef->getCovariateModel()->gatherSymbols(gathering);
        }
        for (auto const &om_model : mdef->getObservationModels()) {
            om_model->gatherSymbols(gathering);
        }
        gathering.globalBlock();
        if (this->independentVariable) {
            gathering.addSymbol(this->independentVariable);
        }
        for (FunctionDefinition *fdef : this->getFunctionDefinitions()) {
            gathering.addSymbol(fdef);
            for (FunctionArgumentDefinition *farg : fdef->getArguments()) {
                gathering.addSymbol(farg);
            }
        }
        if (this->getTrialDesign()) {       // Assume global namespace for DesignParameters
            this->getTrialDesign()->gatherSymbols(gathering);
        }

        this->allSymbols = gathering.getAllSymbols();

        gathering.setupAllSymbRefs();

        // Handle referrers that are not symbols
        this->setupRefererSymbRefs(gathering);

        // Setup TargetMapping's (refers to Symbol's via strings)
        this->setupTargetMappings(gathering);
    }
示例#3
0
void
CompIdBase::checkId (const ModelDefinition& x)
{
  if (x.isSetId()) doCheckId(x.getId(), x);
}
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;

}