Ejemplo n.º 1
0
//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);
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
/** @cond doxygenLibsbmlInternal */
void CompModelPlugin::renameIDs(List* allElements, const string& prefix)
{
  if (prefix=="") return; //Nothing to prepend.
  vector<pair<string, string> > renamedSIds;
  vector<pair<string, string> > renamedUnitSIds;
  vector<pair<string, string> > renamedMetaIds;
  //PrefixTransformer trans(prefix);
  for (unsigned long el=0; el < allElements->getSize(); ++el) 
  {
    SBase* element = static_cast<SBase*>(allElements->get(el));
    string id = element->getId();
    string metaid = element->getMetaId();
    //element->transformIdentifiers(&trans);
    element->prependStringToAllIdentifiers(prefix);
    if (element->getTypeCode() == SBML_LOCAL_PARAMETER) {
      element->setId(id); //Change it back.  This would perhaps be better served by overriding 'prependStringToAllIdentifiers' but hey.
    }
    string newid = element->getId();
    string newmetaid = element->getMetaId();
    if (id != newid) {
      int type = element->getTypeCode();
      if (type==SBML_UNIT_DEFINITION) {
        renamedUnitSIds.push_back(make_pair(id, newid));
      }
      else if (type==SBML_COMP_PORT) {
        //Do nothing--these can only be referenced from outside the Model, so they need to be handled specially.
        // (In the default case, we throw them away).
      }
      else {
        //This is a little dangerous, but hey!  What's a little danger between friends!
        //(What we are assuming is that any attribute you can get with 'getId' is of the type 'SId')
        renamedSIds.push_back(make_pair(id, newid));
      }
    }
    if (metaid != newmetaid) {
      renamedMetaIds.push_back(make_pair(metaid, newmetaid));
    }
  }

  for (unsigned long el=0; el<allElements->getSize(); el++) {
    SBase* element = static_cast<SBase*>(allElements->get(el));
    for (size_t id=0; id<renamedSIds.size(); id++) 
    {
      element->renameSIdRefs(renamedSIds[id].first, renamedSIds[id].second);
    }
    for (size_t uid=0; uid<renamedUnitSIds.size(); uid++) 
    {
      element->renameUnitSIdRefs(renamedUnitSIds[uid].first, renamedUnitSIds[uid].second);
    }
    for (size_t mid=0; mid<renamedMetaIds.size(); mid++) 
    {
      element->renameMetaIdRefs(renamedMetaIds[mid].first, renamedMetaIds[mid].second);
    }
  }
}
void 
ClassReplacements::checkReferencedElement(ReplacedElement& repE)
{
  // if the deletion attribute is set then we don't care what 
  // it points to
  if (repE.isSetDeletion() == true)
  {
    return;
  }

  unsigned int numErrsB4 = repE.getSBMLDocument()->getNumErrors();
  
  SBase* refElem = repE.getReferencedElement();
  
  // if there is an issue with references the getReferencedElement
  // will log errors and possibly fail
  // we dont want to try any further
  unsigned int numErrsAfter = repE.getSBMLDocument()->getNumErrors();

  if (numErrsB4 != numErrsAfter || refElem == NULL)
  {
    return;
  }

  SBase * parent = repE.getParentSBMLObject()->getParentSBMLObject();

  if (refElem->getTypeCode() != parent->getTypeCode())
  {
    int parentTC = parent->getTypeCode();
    // exception is anything with mathematical meaning
    // may replace a parameter
    if (refElem->getTypeCode() == SBML_PARAMETER)
    {
      if (parentTC == SBML_COMPARTMENT || parentTC == SBML_SPECIES ||
        parentTC == SBML_SPECIES_REFERENCE || parentTC == SBML_REACTION
        || parentTC == SBML_LOCAL_PARAMETER)
      {
        return;
      }
    }
    else if (refElem->getTypeCode() == SBML_LOCAL_PARAMETER)
    {
      if (parentTC == SBML_PARAMETER)
      {
        return;
      }
    }



    logBadClassReplacement(repE, refElem, parent);
  }


}
Ejemplo n.º 5
0
  virtual bool visit(const SBase &x)
  {
    if (&x == NULL || x.getPackageName() != "groups")
    {
      return SBMLVisitor::visit(x);
    }

    int code = x.getTypeCode();

    const ListOf* list = dynamic_cast<const ListOf*>(&x);

    if (list != NULL)
    {
      return SBMLVisitor::visit(x);
    }
    else
    {
      if (code == SBML_GROUPS_MEMBER)
      {
        return visit((const Member&)x);
      }
      else if (code == SBML_GROUPS_MEMBER_CONSTRAINT)
      {
        return visit((const MemberConstraint&)x);
      }
      else if (code == SBML_GROUPS_GROUP)
      {
        return visit((const Group&)x);
      }
      else 
      {
        return SBMLVisitor::visit(x);
      } 
    }
  }
Ejemplo n.º 6
0
bool getConstant(string id, Model* model,  const map<string, vector<double> >& results)
{
  if (variesIn(id, results)) return false;
  SBase* element = model->getElementBySId(id);
  Compartment* comp = static_cast<Compartment*>(element);
  Species* species = static_cast<Species*>(element);
  Parameter* param = static_cast<Parameter*>(element);
  Reaction* rxn = static_cast<Reaction*>(element);
  SpeciesReference* sr= static_cast<SpeciesReference*>(element);
  switch (element->getTypeCode()) {
  case SBML_COMPARTMENT:
    if (!comp->getConstant()) return false;
    break;
  case SBML_SPECIES:
    if (!species->getConstant()) return false;
    break;
  case SBML_PARAMETER:
    if (!param->getConstant()) return false;
    break;
  case SBML_REACTION:
    if (rxn->isSetKineticLaw()) {
      if (variesIn(rxn->getKineticLaw()->getMath(), model, results)) return false;
    }
    break;
  case SBML_SPECIES_REFERENCE:
    if (!sr->getConstant()) return false;
    break;
  default:
    assert(false); //Uncaught type!
    return true;
    break;
  }
  return true;
}
/*
 * @return the error message to use when logging constraint violations.
 * This method is called by logFailure.
 *
 * Returns a message that the given @p id and its corresponding object are
 * in  conflict with an object previously defined.
 */
const string
PieceBooleanMathCheck::getMessage (const ASTNode& node, const SBase& object)
{

  ostringstream oss_msg;

  //oss_msg << getPreamble();

  char * formula = SBML_formulaToString(&node);
  oss_msg << "The formula '" << formula;
  oss_msg << "' in the " << getFieldname() << " element of the <" << object.getElementName();
  oss_msg << "> ";
  switch(object.getTypeCode()) {
  case SBML_INITIAL_ASSIGNMENT:
  case SBML_EVENT_ASSIGNMENT:
  case SBML_ASSIGNMENT_RULE:
  case SBML_RATE_RULE:
    //LS DEBUG:  could use other attribute values, or 'isSetActualId'.
    break;
  default:
    if (object.isSetId()) {
      oss_msg << "with id '" << object.getId() << "' ";
    }
    break;
  }
  oss_msg << "uses a piecewise function that does not return a Boolean.";
  safe_free(formula);

  return oss_msg.str();
}
END_TEST


START_TEST (test_GetMultipleObjects_noUnits)
{
  SBMLReader        reader;
  SBMLDocument*     d;

  std::string filename(TestDataDirectory);
  filename += "multiple-ids.xml";


  d = reader.readSBML(filename);

 if (d == NULL)
  {
    fail("readSBML(\"multiple-ids.xml\") returned a NULL pointer.");
  }

  SBase* obj = d->getElementBySId("volume");
  fail_unless(obj == NULL);
  obj = d->getElementByMetaId("meta30");
  fail_unless(obj != NULL);
  fail_unless(obj->getTypeCode() == SBML_UNIT_DEFINITION);


  delete d;
}
Ejemplo n.º 9
0
/*
 * @return the error message to use when logging constraint violations.
 * This method is called by logFailure.
 *
 * Returns a message that the given @p id and its corresponding object are
 * in  conflict with an object previously defined.
 */
const string
CiElementMathCheck::getMessage (const ASTNode& node, const SBase& object)
{

  ostringstream msg;

  //msg << getPreamble();
  char * formula = SBML_formulaToString(&node);
  msg << "The formula '" << formula;
  msg << "' in the " << getFieldname() << " element of the <" << object.getElementName();
  msg << "> ";
  switch(object.getTypeCode()) {
  case SBML_INITIAL_ASSIGNMENT:
  case SBML_EVENT_ASSIGNMENT:
  case SBML_ASSIGNMENT_RULE:
  case SBML_RATE_RULE:
    //LS DEBUG:  could use other attribute values, or 'isSetActualId'.
    break;
  default:
    if (object.isSetId()) {
      msg << "with id '" << object.getId() << "' ";
    }
    break;
  }
  if (object.getLevel() == 2 && object.getVersion() == 1)
    msg << "uses '" << node.getName() << "' that is not the id of a species/compartment/parameter.";
  else if (object.getLevel() < 3)
    msg << "uses '" << node.getName() << "' that is not the id of a species/compartment/parameter/reaction.";
  else
    msg << "uses '" << node.getName() << "' that is not the id of a species/compartment/parameter/reaction/speciesReference.";
  safe_free(formula);

  return msg.str();
}
Ejemplo n.º 10
0
/*
* Logs a message about a function that should return same units
* as the arguments
*/
void 
ArgumentsUnitsCheck::logInconsistentSameUnits (const ASTNode & node, 
                                             const SBase & sb)
{
  char * formula = SBML_formulaToString(&node);
  msg = "The formula '" ;
  msg += formula;
  msg += "' in the math element of the <";
  msg += sb.getElementName();
  msg += "> ";
  switch(sb.getTypeCode()) {
  case SBML_INITIAL_ASSIGNMENT:
  case SBML_EVENT_ASSIGNMENT:
  case SBML_ASSIGNMENT_RULE:
  case SBML_RATE_RULE:
    //LS DEBUG:  could use other attribute values, or 'isSetActualId'.
    break;
  default:
    if (sb.isSetId()) {
      msg += "with id '";
      msg += sb.getId() + "' ";
    }
    break;
  }
  msg += "can only act on variables with the same units.";
  safe_free(formula);

  logFailure(sb, msg);

}
Ejemplo n.º 11
0
  virtual bool visit(const SBase &x)
  {
    if (&x == NULL || x.getPackageName() != "distrib")
    {
      return SBMLVisitor::visit(x);
    }

    int code = x.getTypeCode();

    const ListOf* list = dynamic_cast<const ListOf*>(&x);

    if (list != NULL)
    {
      return SBMLVisitor::visit(x);
    }
    else
    {
      if (code == SBML_DISTRIB_DRAW_FROM_DISTRIBUTION)
      {
        return visit((const DrawFromDistribution&)x);
      }
      else if (code == SBML_DISTRIB_INPUT)
      {
        return visit((const DistribInput&)x);
      }
      else if (code == SBML_DISTRIB_UNCERTAINTY)
      {
        return visit((const Uncertainty&)x);
      }
      else 
      {
        return SBMLVisitor::visit(x);
      } 
    }
  }
Ejemplo n.º 12
0
  virtual bool visit(const SBase &x)
  {
    if (&x == NULL || x.getPackageName() != "req")
    {
      return SBMLVisitor::visit(x);
    }

    int code = x.getTypeCode();

    const ListOf* list = dynamic_cast<const ListOf*>(&x);

    if (list != NULL)
    {
      return SBMLVisitor::visit(x);
    }
    else
    {
      if (code == SBML_REQ_CHANGED_MATH)
      {
        return visit((const ChangedMath&)x);
      }
      else 
      {
        return SBMLVisitor::visit(x);
      } 
    }
  }
/**
  * Checks any <ci> elements in the MathML of the ASTnode 
  * contain the id of an appropriate component of the model
  *
  * If an inconsistency is found, an error message is logged.
  */
void 
LocalParameterMathCheck::checkCiElement (const Model& m, 
                                        const ASTNode& node, 
                                        const SBase & sb)
{
  std::string name = node.getName();
  const KineticLaw * kl;

  if (m.getCompartment(name) == NULL &&
      m.getSpecies(name)     == NULL &&
      m.getParameter(name)   == NULL &&
      m.getReaction(name)    == NULL)
  {

    /* check whether we are in a kinetic law since there
     * may be local parameters to this law that are allowed
     */

    if (sb.getTypeCode() == SBML_KINETIC_LAW)
    {
      kl = m.getReaction(mKLCount)->getKineticLaw();

      if (kl->getParameter(name) == NULL && mLocalParameters.contains(name))
      {
        logMathConflict(node, sb);
      }
    }
    else if (mLocalParameters.contains(name))
    {
        logMathConflict(node, sb);
    }
  }
    
}
Ejemplo n.º 14
0
/*
 * @return the error message to use when logging constraint violations.
 * This method is called by logFailure.
 *
 * Returns a message that the given @p id and its corresponding object are
 * in  conflict with an object previously defined.
 */
const string
ArgumentsUnitsCheck::getMessage (const ASTNode& node, const SBase& object)
{

  ostringstream msg;

  //msg << getPreamble();
  char * formula = SBML_formulaToString(&node);
  msg << "The formula '" << formula;
  msg << "' in the " << getFieldname() << " element of the <" << object.getElementName();
  msg << "> ";
  switch(object.getTypeCode()) {
  case SBML_INITIAL_ASSIGNMENT:
  case SBML_EVENT_ASSIGNMENT:
  case SBML_ASSIGNMENT_RULE:
  case SBML_RATE_RULE:
    //LS DEBUG:  could use other attribute values, or 'isSetActualId'.
    break;
  default:
    if (object.isSetId()) {
      msg << "with id '" << object.getId() << "' ";
    }
    break;
  }
  msg << "produces an exponent that is not an integer and thus may produce ";
  msg << "invalid units.";
  safe_free(formula);

  return msg.str();
}
Ejemplo n.º 15
0
  virtual bool visit(const SBase &x)
  {
    if (&x == NULL || x.getPackageName() != "arrays")
    {
      return SBMLVisitor::visit(x);
    }

    int code = x.getTypeCode();

    const ListOf* list = dynamic_cast<const ListOf*>(&x);

    if (list != NULL)
    {
      return SBMLVisitor::visit(x);
    }
    else
    {
      if (code == SBML_ARRAYS_DIMENSION)
      {
        return visit((const Dimension&)x);
      }
      else if (code == SBML_ARRAYS_INDEX)
      {
        return visit((const Index&)x);
      }
      else 
      {
        return SBMLVisitor::visit(x);
      } 
    }
  }
END_TEST

START_TEST (test_GetMultipleObjects_noLocalParameters)
{
  SBMLReader        reader;
  SBMLDocument*     d;

  std::string filename(TestDataDirectory);
  filename += "multiple-ids.xml";


  d = reader.readSBML(filename);

 if (d == NULL)
  {
    fail("readSBML(\"multiple-ids.xml\") returned a NULL pointer.");
  }

  SBase* rxn = d->getElementBySId("J0");
  fail_unless(rxn != NULL);
  SBase* obj = rxn->getElementBySId("x");
  fail_unless(obj == NULL);
  obj = rxn->getElementByMetaId("meta28");
  fail_unless(obj != NULL);
  fail_unless(obj->getTypeCode() == SBML_LOCAL_PARAMETER);


  delete d;
}
/*
 * @return the error message to use when logging constraint violations.
 * This method is called by logFailure.
 *
 * Returns a message that the given @p id and its corresponding object are
 * in  conflict with an object previously defined.
 */
const string
NumericArgsMathCheck::getMessage (const ASTNode& node, const SBase& object)
{

  ostringstream msg;

  //msg << getPreamble();

  char * formula = SBML_formulaToString(&node);
  msg << "The formula '" << formula;
  msg << "' in the " << getFieldname() << " element of the <" << object.getElementName();
  msg << "> ";
  switch(object.getTypeCode()) {
  case SBML_INITIAL_ASSIGNMENT:
  case SBML_EVENT_ASSIGNMENT:
  case SBML_ASSIGNMENT_RULE:
  case SBML_RATE_RULE:
    //LS DEBUG:  could use other attribute values, or 'isSetActualId'.
    break;
  default:
    if (object.isSetId()) {
      msg << "with id '" << object.getId() << "' ";
    }
    break;
  }
  msg << "uses an argument to a operator that expects a numeric value.";
  safe_free(formula);

  return msg.str();
}
/*
 * @return the error message to use when logging constraint violations.
 * This method is called by logFailure.
 *
 * Returns a message that the given @p id and its corresponding object are
 * in  conflict with an object previously defined.
 */
const string
FunctionApplyMathCheck::getMessage (const ASTNode& node, const SBase& object)
{

  ostringstream msg;

  //msg << getPreamble();
  char * formula = SBML_formulaToString(&node);
  msg << "The formula '" << formula;
  msg << "' in the " << getFieldname() << " element of the <" << object.getElementName();
  msg << "> ";
  switch(object.getTypeCode()) {
  case SBML_INITIAL_ASSIGNMENT:
  case SBML_EVENT_ASSIGNMENT:
  case SBML_ASSIGNMENT_RULE:
  case SBML_RATE_RULE:
    //LS DEBUG:  could use other attribute values, or 'isSetActualId'.
    break;
  default:
    if (object.isSetId()) {
      msg << "with id '" << object.getId() << "' ";
    }
    break;
  }
  msg << "uses '" << node.getName() << "' which is not a function definition id.";
  safe_free(formula);

  return msg.str();
}
Ejemplo n.º 19
0
/*
* Logs a message about the conditional part of a piecewise function 
* that should have dimensionless units
*/
void 
ArgumentsUnitsCheck::logInconsistentPiecewiseCondition (const ASTNode & node, 
                                          const SBase & sb)
{
  char * formula = SBML_formulaToString(&node);
  msg = "The formula '";
  msg += formula;
  msg += "' in the math element of the <";
  msg += sb.getElementName();
  msg += "> ";
  switch(sb.getTypeCode()) {
  case SBML_INITIAL_ASSIGNMENT:
  case SBML_EVENT_ASSIGNMENT:
  case SBML_ASSIGNMENT_RULE:
  case SBML_RATE_RULE:
    //LS DEBUG:  could use other attribute values, or 'isSetActualId'.
    break;
  default:
    if (sb.isSetId()) {
      msg += "with id '";
      msg += sb.getId() + "' ";
    }
    break;
  }
  msg += "uses a piecewise function";
  msg += " where the conditional statement is not dimensionless.";
  safe_free(formula);

  logFailure(sb, msg);

}
Ejemplo n.º 20
0
bool getSetValue(string id, Model* model, const set<string>& tests, double& setValue) 
{
  SBase* element = model->getElementBySId(id);
  if (element==NULL) return false;
  Compartment* comp = static_cast<Compartment*>(element);
  Species* species = static_cast<Species*>(element);
  Parameter* param = static_cast<Parameter*>(element);
  Reaction* rxn = static_cast<Reaction*>(element);
  SpeciesReference* sr= static_cast<SpeciesReference*>(element);
  switch(element->getTypeCode()) {
  case SBML_COMPARTMENT:
    if (comp->isSetSize()) {
      setValue = comp->getSize();
      return true;
    }
    break;
  case SBML_SPECIES:
    if (species->isSetInitialAmount()) {
      setValue = species->getInitialAmount();
      if (tests.find("Concentration") != tests.end()) {
        comp = model->getCompartment(species->getCompartment());
        if (comp->isSetSize()) {
          setValue = setValue/comp->getSize();
        }
      }
      return true;
    }
    if (species->isSetInitialConcentration()) {
      setValue = species->getInitialConcentration();
      if (tests.find("Amount") != tests.end()) {
        comp = model->getCompartment(species->getCompartment());
        if (comp->isSetSize()) {
          setValue = setValue*comp->getSize();
        }
      }
      return true;
    }
    break;
  case SBML_PARAMETER:
    if (param->isSetValue()) {
      setValue = param->getValue();
      return true;
    }
    break;
  case SBML_REACTION:
    return false; //We'd have to calculate the math here, which I'm not going to do.
  case SBML_SPECIES_REFERENCE:
    if (sr->isSetStoichiometry()) {
      setValue = sr->getStoichiometry();
      return true;
    }
    break;
  default:
    assert(false); //Uncaught type!
    return false;
    break;
  }
  return false;
}
END_TEST


START_TEST (test_GetMultipleObjects_noAssignments)
{
  SBMLReader        reader;
  SBMLDocument*     d;

  std::string filename(TestDataDirectory);
  filename += "assignments-invalid.xml";


  d = reader.readSBML(filename);

 if (d->getModel() == NULL)
  {
    fail("readSBML(\"assignments-invalid.xml\") returned an empty model.");
  }

  SBase* obj = d->getElementBySId("ia");
  fail_unless(obj == NULL);
  obj = d->getElementByMetaId("ia_meta");
  fail_unless(obj != NULL);
  fail_unless(obj->getTypeCode() == SBML_INITIAL_ASSIGNMENT);

  obj = d->getElementBySId("ar");
  fail_unless(obj == NULL);
  obj = d->getElementByMetaId("ar_meta");
  fail_unless(obj != NULL);
  fail_unless(obj->getTypeCode() == SBML_ASSIGNMENT_RULE);

  obj = d->getElementBySId("rr");
  fail_unless(obj == NULL);
  obj = d->getElementByMetaId("rr_meta");
  fail_unless(obj != NULL);
  fail_unless(obj->getTypeCode() == SBML_RATE_RULE);

  obj = d->getElementBySId("ea");
  fail_unless(obj == NULL);
  obj = d->getElementByMetaId("ea_meta");
  fail_unless(obj != NULL);
  fail_unless(obj->getTypeCode() == SBML_EVENT_ASSIGNMENT);


  delete d;
}
Ejemplo n.º 22
0
void checkComp(CompSBMLDocumentPlugin* compdoc, set<string>& components, set<string>& tests,  const map<string, vector<double> >& results)
{
  SBMLDocument* doc = compdoc->getSBMLDocument();
  List* allElements = doc->getAllElements();
  for (unsigned int e=0; e<allElements->getSize(); e++) {
    SBase* element = static_cast<SBase*>(allElements->get(e));
    ReplacedElement* re;
    Submodel* submod;
    switch(element->getTypeCode()) {
    case SBML_COMP_SUBMODEL:
      components.insert("comp:Submodel");
      submod = static_cast<Submodel*>(element);
      if (submod->isSetExtentConversionFactor()) {
        tests.insert("comp:ExtentConversionFactor");
      }
      if (submod->isSetTimeConversionFactor()) {
        tests.insert("comp:TimeConversionFactor");
      }
      break;
    case SBML_COMP_MODELDEFINITION:
      components.insert("comp:ModelDefinition");
      break;
    case SBML_COMP_EXTERNALMODELDEFINITION:
      components.insert("comp:ExternalModelDefinition");
      break;
    case SBML_COMP_SBASEREF:
      components.insert("comp:SBaseRef");
      break;
    case SBML_COMP_DELETION:
      components.insert("comp:Deletion");
      break;
    case SBML_COMP_REPLACEDELEMENT:
      components.insert("comp:ReplacedElement");
      re = static_cast<ReplacedElement*>(element);
      if (re->isSetConversionFactor()) {
        tests.insert("comp:ConversionFactor");
      }
      break;
    case SBML_COMP_REPLACEDBY:
      components.insert("comp:ReplacedBy");
      break;
    case SBML_COMP_PORT:
      components.insert("comp:Port");
      break;
    default:
      break;
    }
  }
  for (map<string, vector<double> >::const_iterator result=results.begin(); 
    result != results.end(); result++) {
      string id = result->first;
      if (id.find("__") != string::npos) {
        //It is probably a submodel element, renamed
        tests.insert("comp:SubmodelOutput");
      }
  }
}
Ejemplo n.º 23
0
  virtual bool visit (const SBase &x)
  {
    if(&x == NULL || x.getPackageName() != "qual")
    {
      return SBMLVisitor::visit(x);
    }

    int code = x.getTypeCode();

    const ListOf* list = dynamic_cast<const ListOf*>(&x);

    if (list != NULL)
    {
      code = list->getItemTypeCode();

      if (code == SBML_QUAL_FUNCTION_TERM)
      {
        return visit((const ListOfFunctionTerms&)x);
      }
      else
      {
        return SBMLVisitor::visit(x);
      }
    }
    else
    {
      if (code == SBML_QUAL_QUALITATIVE_SPECIES)
      {
        return visit((const QualitativeSpecies&)x);
      }
      else if (code == SBML_QUAL_TRANSITION)
      {
        return visit((const Transition&)x);
      }
      else if (code == SBML_QUAL_INPUT)
      {
        return visit((const Input&)x);
      }
      else if (code == SBML_QUAL_OUTPUT)
      {
        return visit((const Output&)x);
      }
      else if (code == SBML_QUAL_FUNCTION_TERM)
      {
        return visit((const FunctionTerm&)x);
      }
      else if (code == SBML_QUAL_DEFAULT_TERM)
      {
        return visit((const DefaultTerm&)x);
      }
      else 
      {
        return SBMLVisitor::visit(x);
      } 
    }
  }
Ejemplo n.º 24
0
std::string SEDMLUtils::findIdByNameAndType(
  const std::map<CCopasiObject*, SBase*>& map,
  int typeCode,
  const std::string& name)
{
  std::map<CCopasiObject*, SBase*>::const_iterator it = map.begin();

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

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

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

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

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

      ++it;
    }

  return "";
}
Ejemplo n.º 25
0
/*
  * Checks any &lt;ci&gt; elements in the MathML of the ASTnode 
  * contain the id of an appropriate component of the model
  *
  * If an inconsistency is found, an error message is logged.
  */
void 
CiElementMathCheck::checkCiElement (const Model& m, 
                                        const ASTNode& node, 
                                        const SBase & sb)
{
  std::string name = node.getName();
  const KineticLaw * kl;

  /* leave out this check if the ci element is a local parameter in a kineticLaw
   * caught by LocalParameterMathCheck instead
   */
  if (!mLocalParameters.contains(name))
  {
    bool allowReactionId = true;
    bool allowSpeciesRef = false;

    if ( (m.getLevel() == 2) && (m.getVersion() == 1) )
      allowReactionId = false;

    if (m.getLevel() > 2)
      allowSpeciesRef = true;

    if (m.getCompartment(name) == NULL &&
        m.getSpecies(name)     == NULL &&
        m.getParameter(name)   == NULL &&
        (!allowReactionId || m.getReaction(name) == NULL ) &&
        (!allowSpeciesRef || m.getSpeciesReference(name) == NULL ) )
    {
      /* check whether we are in a kinetic law since there
      * may be local parameters
      */

      if (sb.getTypeCode() == SBML_KINETIC_LAW)
      {
        kl = m.getReaction(mKLCount)->getKineticLaw();

        if (kl->getParameter(name) == NULL)
        {
          logMathConflict(node, sb);
        }
      }
      else
      {
          logMathConflict(node, sb);
      }
    }
  }
    
}
/*
  * Logs a message about dupliacte top level annotations.
  */
void
DuplicateTopLevelAnnotation::logDuplicate (std::string name, const SBase& object )
{

  msg = "The namespaces '";
  msg += name;
  msg += "' is duplicated within the annotation of the ";
  msg += SBMLTypeCode_toString( object.getTypeCode(), object.getPackageName().c_str() );
  msg += " with id '";
  msg += object.getId();
  msg += "'.";

  
  logFailure(object);
}
Ejemplo n.º 27
0
int SBaseRef::saveReferencedElement()
{
  //The only thing that knows what Model we should point to is the parent of this object.  Since it will also be of the class SBaseRef, just call this recursively.
  SBMLDocument* doc = getSBMLDocument();
  SBase* parent = getParentSBMLObject();
  if (parent==NULL) {
    if (doc) {
      string error = "In SBaseRef::saveReferencedElement, unable to find referenced element: no parent could be found for the given <sBaseRef> element.";
      doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
    }
    return LIBSBML_OPERATION_FAILED;
  }
  SBaseRef* parentref = static_cast<SBaseRef*>(parent);
  if (parentref==NULL || (parent->getTypeCode() != SBML_COMP_SBASEREF &&
                          parent->getTypeCode() != SBML_COMP_PORT &&
                          parent->getTypeCode() != SBML_COMP_DELETION &&
                          parent->getTypeCode() != SBML_COMP_REPLACEDBY &&
                          parent->getTypeCode() != SBML_COMP_REPLACEDELEMENT)) {
    if (doc) {
      string error = "In SBaseRef::saveReferencedElement, unable to find referenced element: the parent of the given <sBaseRef> element was not the correct type.";
      doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
    }
    return LIBSBML_OPERATION_FAILED;
  }
  if (parentref->saveReferencedElement() != LIBSBML_OPERATION_SUCCESS) {
    //saveReferencedElement will set its own error messages.
    return LIBSBML_OPERATION_FAILED;
  }
  mReferencedElement = parentref->getReferencedElement();
  mDirectReference = parentref->getDirectReference();
  if (mReferencedElement==NULL) {
    //getReferencedElement will set its own error messages.
    return LIBSBML_OPERATION_FAILED;
  }
  return LIBSBML_OPERATION_SUCCESS;
}
void 
ReportEmptyListOf::logEmptyList(const ListOf* list, const SBase& parent)
{
  msg = "The ListOf";
  msg += SBMLTypeCode_toString( list->getItemTypeCode(), list->getPackageName().c_str());
  msg += "s in the ";
  msg += SBMLTypeCode_toString(parent.getTypeCode(), parent.getPackageName().c_str());
  msg += " with id '";
  msg += parent.getId();
  msg += "' has no child ";
  msg += SBMLTypeCode_toString( list->getItemTypeCode(), list->getPackageName().c_str());
  msg += " elements.";
  
  logFailure(*list);
}
Ejemplo n.º 29
0
/**
 * @return the most specific Swig type for the given SBasePlugin object.
 */
struct swig_type_info*
GetDowncastSwigType (SBasePlugin* sbp)
{
  if (sbp == 0) return SWIGTYPE_p_SBasePlugin;

  const std::string pkgName = sbp->getPackageName();
  SBase* sb = sbp->getParentSBMLObject();
  if (!sb) return SWIGTYPE_p_SBasePlugin;

#include "local-downcast-plugins.cpp"

  if (sb->getTypeCode() == SBML_DOCUMENT)
    return SWIGTYPE_p_SBMLDocumentPlugin;

  return SWIGTYPE_p_SBasePlugin;
}
/**
  * Checks the MathML of the ASTnode 
  * is appropriate for the function being performed
  *
  * If an inconsistency is found, an error message is logged.
  */
void
NumericReturnMathCheck::checkMath (const Model& m, const ASTNode& node, const SBase & sb)
{
  //SBMLTypeCode_t type = sb.getTypeCode();
  int type = sb.getTypeCode();
  
  /* HACK: if the math is a lambda - this is invalid
   * and will be caught by constraint 2006
   * dont want to check it here as it will also fire this
   */
  if (!(node.getType() == AST_LAMBDA))
  {
    switch (type) 
    {
      case SBML_KINETIC_LAW:
      case SBML_INITIAL_ASSIGNMENT:
      case SBML_ASSIGNMENT_RULE:
      case SBML_RATE_RULE:
      case SBML_ALGEBRAIC_RULE:
      case SBML_SPECIES_CONCENTRATION_RULE:
      case SBML_COMPARTMENT_VOLUME_RULE:
      case SBML_PARAMETER_RULE:
      case SBML_EVENT_ASSIGNMENT:
      case SBML_SPECIES_REFERENCE:

        if (!returnsNumeric(m, &node))
        {
          logMathConflict(node, sb);
        }
        break;

      case SBML_EVENT:

        /* only want to check delay since trigger should return boolean */
        if (!mIsTrigger && !returnsNumeric(m , &node))
        {
          logMathConflict(node, sb);
        }
        break;

      default:

        break;

    }
  }
}