Beispiel #1
0
// virtual
CXMLHandler * ReactionGlyphHandler::processStart(const XML_Char * pszName,
    const XML_Char ** papszAttrs)
{
  CXMLHandler * pHandlerToCall = NULL;

  switch (mCurrentElement.first)
    {
      case ReactionGlyph:
      {
        //workload
        const char * key;
        const char * name;
        const char * reaction;
        key = mpParser->getAttributeValue("key", papszAttrs);
        name = mpParser->getAttributeValue("name", papszAttrs);
        reaction = mpParser->getAttributeValue("reaction", papszAttrs, false);

        mpData->pReactionGlyph = new CLReactionGlyph(name);
        const char * objectRole = mpParser->getAttributeValue("objectRole", papszAttrs, false);

        if (objectRole != NULL && objectRole[0] != 0)
          {
            mpData->pReactionGlyph->setObjectRole(objectRole);
          }

        if (reaction && reaction[0])
          {
            CReaction * pReaction = dynamic_cast< CReaction * >(mpData->mKeyMap.get(reaction));

            if (!pReaction)
              {
                CCopasiMessage(CCopasiMessage::WARNING, MCXML + 19, "ReactionGlyph" , key);
              }
            else
              {
                mpData->pReactionGlyph->setModelObjectKey(pReaction->getKey());
              }
          }

        mpData->pCurrentLayout->addReactionGlyph(mpData->pReactionGlyph);
        addFix(key, mpData->pReactionGlyph);
      }
      break;

      case BoundingBox:
      case Curve:
      case ListOfMetaboliteReferenceGlyphs:
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      default:
        CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 2,
                       mpParser->getCurrentLineNumber(), mpParser->getCurrentColumnNumber(), pszName);
        break;
    }

  return pHandlerToCall;
}
Beispiel #2
0
void UndoDependentData::restoreDependentObjects(CModel *pModel, QList<UndoReactionData *> *reactionData)
{
  if (pModel == NULL || reactionData == NULL || reactionData->empty())
    return;

  QList <UndoReactionData *>::const_iterator j;

  for (j = reactionData->begin(); j != reactionData->end(); ++j)
    {

      UndoReactionData * rData = *j;

      //need to make sure reaction doesn't exist in the model already
      if (pModel->getReactions().getIndex(rData->getName()) != C_INVALID_INDEX)
        continue;

      CReaction *pRea = rData->restoreObjectIn(pModel);

      rData->restoreDependentObjects(pModel);

      updateGUI(ListViews::REACTION, ListViews::ADD, pRea->getKey());
    }
}
Beispiel #3
0
void CModelExpansion::duplicateReaction(const CReaction* 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;

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

  do
    {
      std::ostringstream name;
      name << source->getObjectName() << infix.str() << index;
      newObj = mpModel->createReaction(name.str());
      infix << "_";
    }
  while (!newObj);

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

  //now copy the chemical equation
  size_t i;

  for (i = 0; i < source->getChemEq().getSubstrates().size(); ++i)
    {
      const CChemEqElement * sourceElement = source->getChemEq().getSubstrates()[i];
      const CMetab* pMetab = NULL;

      if (sourceSet.contains(sourceElement->getMetabolite()))
        {
          if (!emap.exists(sourceElement->getMetabolite()))
            duplicateMetab(sourceElement->getMetabolite(), index, sourceSet, emap);

          pMetab = dynamic_cast<const CMetab*>(emap.getDuplicatePtr(sourceElement->getMetabolite()));
        }
      else //add the original metab
        {
          pMetab = sourceElement->getMetabolite();
        }

      if (pMetab)
        newObj->addSubstrate(pMetab->getKey(), sourceElement->getMultiplicity());
    }

  for (i = 0; i < source->getChemEq().getProducts().size(); ++i)
    {
      const CChemEqElement * sourceElement = source->getChemEq().getProducts()[i];
      const CMetab* pMetab = NULL;

      if (sourceSet.contains(sourceElement->getMetabolite()))
        {
          if (!emap.exists(sourceElement->getMetabolite()))
            duplicateMetab(sourceElement->getMetabolite(), index, sourceSet, emap);

          pMetab = dynamic_cast<const CMetab*>(emap.getDuplicatePtr(sourceElement->getMetabolite()));
        }
      else //add the original metab
        {
          pMetab = sourceElement->getMetabolite();
        }

      if (pMetab)
        newObj->addProduct(pMetab->getKey(), sourceElement->getMultiplicity());
    }

  for (i = 0; i < source->getChemEq().getModifiers().size(); ++i)
    {
      const CChemEqElement * sourceElement = source->getChemEq().getModifiers()[i];
      const CMetab* pMetab = NULL;

      if (sourceSet.contains(sourceElement->getMetabolite()))
        {
          if (!emap.exists(sourceElement->getMetabolite()))
            duplicateMetab(sourceElement->getMetabolite(), index, sourceSet, emap);

          pMetab = dynamic_cast<const CMetab*>(emap.getDuplicatePtr(sourceElement->getMetabolite()));
        }
      else //add the original metab
        {
          pMetab = sourceElement->getMetabolite();
        }

      if (pMetab)
        newObj->addModifier(pMetab->getKey());
    }

  newObj->setReversible(source->isReversible());

  //set the kinetic function
  newObj->setFunction(const_cast<CFunction*>(source->getFunction()));

  //mapping and local parameters
  for (i = 0; i < newObj->getFunctionParameters().size(); ++i)
    {
      switch (newObj->getFunctionParameters()[i]->getUsage())
        {
          case CFunctionParameter::SUBSTRATE:
          case CFunctionParameter::PRODUCT:
          case CFunctionParameter::MODIFIER:
          {
            bool isVector = (newObj->getFunctionParameters()[i]->getType() == CFunctionParameter::VFLOAT64);

            if (isVector)
              newObj->clearParameterMapping(i);

            size_t k;

            for (k = 0; k < source->getParameterMappings()[i].size(); ++k)
              {
                //we assume that by now the metab was copied if necessary.
                //therefore we only need to check the map.
                std::string targetKey;

                if (emap.exists(source->getParameterMappings()[i][k]))
                  targetKey = emap.getDuplicateKey(source->getParameterMappings()[i][k]);
                else
                  targetKey = source->getParameterMappings()[i][k];

                if (isVector)
                  newObj->addParameterMapping(i, targetKey);
                else
                  newObj->setParameterMapping(i, targetKey);
              }
          }
          break;

          case CFunctionParameter::TIME:
            newObj->setParameterMapping(i, source->getParameterMappings()[i][0]);
            break;

          case CFunctionParameter::VOLUME:
            if (sourceSet.contains(source->getParameterMappings()[i][0]))
              {
                if (!emap.exists(source->getParameterMappings()[i][0]))
                  {
                    const CCompartment* pSource = dynamic_cast<const CCompartment*>(
                                                    (CCopasiRootContainer::getKeyFactory()->get(source->getParameterMappings()[i][0])));
                    duplicateCompartment(pSource, index, sourceSet, emap);
                  }

                newObj->setParameterMapping(i, emap.getDuplicateKey(source->getParameterMappings()[i][0]));
              }
            else //add the original metab
              {
                newObj->setParameterMapping(i, source->getParameterMappings()[i][0]);
              }

            break;

          case CFunctionParameter::PARAMETER:
            if (newObj->isLocalParameter(i))
              {
                //just copy the value
                newObj->setParameterValue(newObj->getFunctionParameters()[i]->getObjectName(),
                                          source->getParameterValue(newObj->getFunctionParameters()[i]->getObjectName()));
              }
            else
              {
                if (sourceSet.contains(source->getParameterMappings()[i][0]))
                  {
                    if (!emap.exists(source->getParameterMappings()[i][0]))
                      {
                        const CModelValue* pSource = dynamic_cast<const CModelValue*>(
                                                       (CCopasiRootContainer::getKeyFactory()->get(source->getParameterMappings()[i][0])));
                        duplicateGlobalQuantity(pSource, index, sourceSet, emap);
                      }

                    newObj->setParameterMapping(i, emap.getDuplicateKey(source->getParameterMappings()[i][0]));
                  }
                else //add the original global quantity
                  {
                    newObj->setParameterMapping(i, source->getParameterMappings()[i][0]);
                  }
              }

            break;

          default:
            break;
        }
    }

  newObj->setNotes(source->getNotes());
  newObj->setMiriamAnnotation(source->getMiriamAnnotation(), newObj->getKey(), source->getKey());
}
Beispiel #4
0
void CQCompartment::addCompartment(UndoCompartmentData *pSData)
{
  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);

  CModel * pModel = pDataModel->getModel();
  assert(pModel != NULL);

  //reinsert all the Compartments
  CCompartment *pCompartment =  pModel->createCompartment(pSData->getName());
  pCompartment->setInitialValue(pSData->getInitialValue());
  pCompartment->setStatus(pSData->getStatus());
  std::string key = pCompartment->getKey();
  protectedNotify(ListViews::COMPARTMENT, ListViews::ADD, key);

  //restore all the dependencies
  //reinsert all the species
  QList <UndoSpecieData *> *pSpecieData = pSData->getSpecieDependencyObjects();
  QList <UndoSpecieData *>::const_iterator i;

  for (i = pSpecieData->begin(); i != pSpecieData->end(); ++i)
    {
      UndoSpecieData * data = *i;
      //  beginInsertRows(QModelIndex(), 1, 1);
      CMetab *pSpecie =  pModel->createMetabolite(data->getName(), data->getCompartment(), data->getIConc(), data->getStatus());
      protectedNotify(ListViews::METABOLITE, ListViews::ADD, pSpecie->getKey());
      //endInsertRows();
    }

  //reinsert the dependency reaction
  QList <UndoReactionData *> *pReactionData = pSData->getReactionDependencyObjects();
  QList <UndoReactionData *>::const_iterator j;

  for (j = pReactionData->begin(); j != pReactionData->end(); ++j)
    {

      //UndoReactionData * rData = dynamic_cast<UndoReactionData*>(*j);
      UndoReactionData * rData = *j;

      //TODO check if reaction already exist in the model, better idea may be implemented in the future
      bool exist = false;

      for (int ii = 0; ii < (int)pModel->getReactions().size(); ++ii)
        {
          if (pModel->getReactions()[ii]->getObjectName() == rData->getName())
            {
              exist = true;
              ii = ii + pModel->getReactions().size() + 1; //jump out of the loop reaction exist already
            }
          else
            {
              exist = false;
            }
        }

      if (!exist)
        {
          protectedNotify(ListViews::METABOLITE, ListViews::ADD, ""); //Refresh all dependency species.
          CReaction *pRea =  pModel->createReaction(rData->getName());
          rData->getRi()->writeBackToReaction(pRea);
          protectedNotify(ListViews::REACTION, ListViews::ADD, pRea->getKey());
        }
    }

  mpListView->switchToOtherWidget(C_INVALID_INDEX, key);
}