Пример #1
0
void test000047::test_delay()
{
  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING));
  CModel* pModel = pDataModel->getModel();
  CPPUNIT_ASSERT(pModel != NULL);
  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CUnit::mMol);
  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CUnit::ml);
  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CUnit::s);
  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
  const CCompartment* pCompartment = pModel->getCompartments()[0];
  CPPUNIT_ASSERT(pCompartment != NULL);
  CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::FIXED);
  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 2);
  const CMetab* pB = pModel->getMetabolites()[1];
  CPPUNIT_ASSERT(pB != NULL);
  CPPUNIT_ASSERT(pB->getStatus() == CModelEntity::FIXED);
  CMetab* pA = pModel->getMetabolites()[0];
  CPPUNIT_ASSERT(pA != NULL);
  CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::ASSIGNMENT);
  const CExpression* pExpr = pA->getExpressionPtr();
  CPPUNIT_ASSERT(pExpr != NULL);
  const CEvaluationNode* pNode = pExpr->getRoot();
  CPPUNIT_ASSERT(pNode != NULL);
  const CEvaluationNodeDelay* pDelayNode = dynamic_cast<const CEvaluationNodeDelay*>(pNode);
  CPPUNIT_ASSERT(pDelayNode != NULL);
  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pDelayNode->getChild());
  CPPUNIT_ASSERT(pObjectNode != NULL);
  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
  CPPUNIT_ASSERT(!objectCN.empty());
  std::vector<CCopasiContainer*> listOfContainers;
  listOfContainers.push_back(pModel);
  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
  CPPUNIT_ASSERT(pObject != NULL);
  CPPUNIT_ASSERT(pObject->isReference() == true);
  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Concentration"));
  CPPUNIT_ASSERT(pObject->getObjectParent() == pB);
  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pObjectNode->getSibling());
  CPPUNIT_ASSERT(pNumberNode != NULL);
  CPPUNIT_ASSERT(((CEvaluationNodeNumber::SubType)CEvaluationNode::subType(pNumberNode->getType())) == CEvaluationNodeNumber::DOUBLE);
  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 0.5) / 0.5) < 1e-3);

  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);

  CPPUNIT_ASSERT(pModel->getModelValues().size() == 1);
  const CModelValue* pModelValue = pModel->getModelValues()[0];
  CPPUNIT_ASSERT(pModelValue != NULL);
  CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::FIXED);
  CPPUNIT_ASSERT(pModel->getReactions().size() == 0);
  //CPPUNIT_ASSERT(CCopasiMessage::size() == 2);
  CCopasiMessage message = CCopasiMessage::getLastMessage();
  CPPUNIT_ASSERT(message.getType() == CCopasiMessage::WARNING);
  std::string s = message.getText();
  CPPUNIT_ASSERT(!s.empty());
  CPPUNIT_ASSERT(s.find(std::string("COPASI does not support time delays. Calculations on this model will most likely lead to unusable results.")) != std::string::npos);
  // right now, we don't care about the last message since it is a units
  // warning from libSBML
}
Пример #2
0
void test000052::test_bug988()
{
  CDataModel* pDataModel = pCOPASIDATAMODEL;
  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING));
  CModel* pModel = pDataModel->getModel();
  CPPUNIT_ASSERT(pModel != NULL);
  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CUnit::mMol);
  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CUnit::ml);
  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CUnit::s);
  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
  const CCompartment* pCompartment = pModel->getCompartments()[0];
  CPPUNIT_ASSERT(pCompartment != NULL);
  CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::Status::FIXED);
  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1);
  CMetab* pA = pModel->getMetabolites()[0];
  CPPUNIT_ASSERT(pA != NULL);
  CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::Status::ASSIGNMENT);
  const CExpression* pExpr = pA->getExpressionPtr();
  // check the expression
  const CEvaluationNode* pNode = pExpr->getRoot();
  CPPUNIT_ASSERT(pNode != NULL);
  const CEvaluationNodeChoice* pChoiceNode = dynamic_cast<const CEvaluationNodeChoice*>(pNode);
  CPPUNIT_ASSERT(pChoiceNode != NULL);
  pNode = dynamic_cast<const CEvaluationNode*>(pChoiceNode->getChild());
  CPPUNIT_ASSERT(pNode != NULL);
  const CEvaluationNodeLogical* pLogicalNode = dynamic_cast<const CEvaluationNodeLogical*>(pNode);
  CPPUNIT_ASSERT(pLogicalNode != NULL);
  CPPUNIT_ASSERT((pLogicalNode->subType()) == CEvaluationNode::SubType::LT);
  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pLogicalNode->getChild());
  CPPUNIT_ASSERT(pObjectNode != NULL);
  CCommonName objectCN = pObjectNode->getObjectCN();
  CPPUNIT_ASSERT(!objectCN.empty());
  CObjectInterface::ContainerList listOfContainers;
  listOfContainers.push_back(pModel);
  const CDataObject* pObject = CObjectInterface::DataModel(pCOPASIDATAMODEL->getObjectFromCN(listOfContainers, objectCN));
  CPPUNIT_ASSERT(pObject != NULL);
  CPPUNIT_ASSERT(pObject->hasFlag(CDataObject::Reference) == true);
  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Time"));
  CPPUNIT_ASSERT(pObject->getObjectParent() == pModel);
  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pObjectNode->getSibling());
  CPPUNIT_ASSERT(pNumberNode != NULL);
  CPPUNIT_ASSERT((pNumberNode->subType()) == CEvaluationNode::SubType::DOUBLE);
  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 5.0) / 5.0) < 1e-3);
  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pLogicalNode->getSibling());
  CPPUNIT_ASSERT(pNumberNode != NULL);
  CPPUNIT_ASSERT((pNumberNode->subType()) == CEvaluationNode::SubType::DOUBLE);
  CPPUNIT_ASSERT(pNumberNode->getValue() < 1e-3);
  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNumberNode->getSibling());
  CPPUNIT_ASSERT(pNumberNode != NULL);
  CPPUNIT_ASSERT((pNumberNode->subType()) == CEvaluationNode::SubType::DOUBLE);
  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 10.0) / 10.0) < 1e-3);

  CPPUNIT_ASSERT(pModel->getModelValues().size() == 0);
  CPPUNIT_ASSERT(pModel->getReactions().size() == 0);
}
Пример #3
0
void CModelExpansion::duplicateMetab(const CMetab* source, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap)
{
  //if the source object has already been duplicated: do nothing
  if (emap.exists(source))
    return;

  //is the containing compartment also duplicated?
  const CCompartment* sourceParent = source->getCompartment();
  const CCompartment * parent = NULL;
  bool nameflag;

  if (!sourceSet.contains(sourceParent))
    {
      parent = sourceParent; //use the original parent compartment
      nameflag = true; //metab needs renaming
    }
  else //use a copy of the parent compartment
    {
      nameflag = false; //no renaming necessary (since the copy is in a different compartment)

      //create copy if it does not exist
      if (!emap.exists(sourceParent))
        {
          duplicateCompartment(sourceParent, index, sourceSet, emap);
        }

      parent = dynamic_cast<CCompartment *>(emap.getDuplicatePtr(sourceParent));
    }

  //try creating the object until we find a name that is not yet used
  CMetab* newObj;
  std::ostringstream infix;

  do
    {
      std::ostringstream name;
      name << source->getObjectName() << infix.str();

      if (nameflag)
        name << index;

      newObj = mpModel->createMetabolite(name.str(), parent->getObjectName(), source->getInitialConcentration(), source->getStatus());

      infix << "_";
    }
  while (!newObj);

  //add duplicated object to the map
  emap.add(source, newObj);

  //expression (for assignment or ODE)
  newObj->setExpression(source->getExpression());
  updateExpression(newObj->getExpressionPtr(), index, sourceSet, emap);

  //initial expression
  newObj->setInitialExpression(source->getInitialExpression());
  updateExpression(newObj->getInitialExpressionPtr(), index, sourceSet, emap);

  newObj->setNotes(source->getNotes());
  newObj->setMiriamAnnotation(source->getMiriamAnnotation(), newObj->getKey(), source->getKey());
}
Пример #4
0
bool CModelMerging::mergeMetabolites(std::string toKey, std::string  key)
{

  bool info = false;

  //merge in  the relevant reactions

  size_t i, imax = mpModel->getReactions().size();
  size_t j, jmax;

  for (i = 0; i < imax; ++i)
    {
      CReaction * reac = &mpModel->getReactions()[i];

      jmax = reac->getChemEq().getSubstrates().size();

      for (j = 0; j < jmax; ++j)
        {
          CChemEqElement * subst = const_cast< CChemEqElement * >(&reac->getChemEq().getSubstrates()[j]);

          if (subst->getMetabolite()->getKey() == key)
            subst->setMetabolite(toKey);
        }

      jmax = reac->getChemEq().getProducts().size();

      for (j = 0; j < jmax; ++j)
        {
          CChemEqElement * prod = const_cast< CChemEqElement * >(&reac->getChemEq().getProducts()[j]);

          if (prod->getMetabolite()->getKey() == key)
            prod->setMetabolite(toKey);
        }

      jmax = reac->getChemEq().getModifiers().size();

      for (j = 0; j < jmax; ++j)
        {
          CChemEqElement * modif = const_cast< CChemEqElement * >(&reac->getChemEq().getModifiers()[j]);

          if (modif->getMetabolite()->getKey() == key)
            modif->setMetabolite(toKey);
        }

      //change parameters of  the kinetic function

      for (j = 0; j < reac->getFunctionParameters().size(); ++j)
        {
          switch (reac->getFunctionParameters()[j]->getUsage())
            {
              case CFunctionParameter::SUBSTRATE:
              case CFunctionParameter::PRODUCT:
              case CFunctionParameter::MODIFIER:
                //translate the metab keys
              {

                //we assume that only SUBSTRATE, PRODUCT, MODIFIER can be vectors

                size_t k, kmax = reac->getParameterMappings()[j].size();

                for (k = 0; k < kmax; ++k)
                  if (reac->getParameterMappings()[j][k] == key)
                    reac->getParameterMappings()[j][k] = toKey;
              }
              break;

              case CFunctionParameter::TIME:
                break;

              case CFunctionParameter::VOLUME:
                // ??? TODO : have to ask
                break;

              case CFunctionParameter::PARAMETER:
                break;

              default:
                return info;
                break;
            }
        }
    }

  imax = mpModel->getEvents().size();

  for (i = 0; i < imax; ++i)
    {
      CEvent * event = &mpModel->getEvents()[i];

      if (!event) return info;

      /* merge in  trigger expressions */
      CExpression* pExpression = event->getTriggerExpressionPtr();

      if (pExpression == NULL) return info;

      if (!mergeInExpression(toKey, key, pExpression))  return info;

      pExpression = event->getDelayExpressionPtr();

      if (pExpression)
        if (!mergeInExpression(toKey, key, pExpression))
          return info;

      jmax = event->getAssignments().size();

      for (j = 0; j < jmax; ++j)
        {
          CEventAssignment* assignment = &event->getAssignments()[j];

          if (!assignment) return info;

          std::string assignmentKey = assignment->getTargetKey();

          if (assignmentKey == key) assignment->setTargetKey(toKey);

          pExpression = assignment->getExpressionPtr();

          if (pExpression == NULL) return info;

          if (!mergeInExpression(toKey, key, pExpression))    return info;
        }
    }

  imax = mpModel->getMetabolites().size();

  for (i = 0; i < imax; ++i)
    {
      CMetab* metab = &mpModel->getMetabolites()[i];

      if (!metab) return info;

      switch (metab->getStatus())
        {
          case CModelEntity::FIXED:
          case CModelEntity::REACTIONS:

            break;

          case CModelEntity::ASSIGNMENT:

            if (!mergeInExpression(toKey, key, metab->getExpressionPtr())) return info;

            break;

          case CModelEntity::ODE:

            if (!mergeInExpression(toKey, key, metab->getExpressionPtr())) return info;

            if (metab->getInitialExpression() != "")
              if (!mergeInExpression(toKey, key, metab->getInitialExpressionPtr())) return info;

            break;

          default:
            return info;
            break;
        }
    }

  imax = mpModel->getCompartments().size();

  for (i = 0; i < imax; ++i)
    {
      CCompartment* comp = &mpModel->getCompartments()[i];

      if (!comp) return info;

      switch (comp ->getStatus())
        {
          case CModelEntity::FIXED:

            break;

          case CModelEntity::ASSIGNMENT:

            if (!mergeInExpression(toKey, key, comp->getExpressionPtr())) return info;

            break;

          case CModelEntity::ODE:

            if (!mergeInExpression(toKey, key, comp->getExpressionPtr())) return info;

            if (comp->getInitialExpression() != "")
              if (!mergeInExpression(toKey, key, comp->getInitialExpressionPtr())) return info;

            break;

          default:
            return info;
            break;
        }
    }

  imax = mpModel->getModelValues().size();

  for (i = 0; i < imax; ++i)
    {
      CModelValue* modval = &mpModel->getModelValues()[i];

      if (!modval) return info;

      switch (modval ->getStatus())
        {
          case CModelEntity::FIXED:

            break;

          case CModelEntity::ASSIGNMENT:

            if (!mergeInExpression(toKey, key, modval->getExpressionPtr())) return info;

            break;

          case CModelEntity::ODE:

            if (!mergeInExpression(toKey, key, modval->getExpressionPtr())) return info;

            if (modval->getInitialExpression() != "")
              if (!mergeInExpression(toKey, key, modval->getInitialExpressionPtr())) return info;

            break;

          default:
            return info;
            break;
        }
    }

  return true;
}