コード例 #1
0
ファイル: CCopasiSpringLayout.cpp プロジェクト: copasi/COPASI
bool CCopasiSpringLayout::initFromLayout(CLayout* layout, Parameters* ppp)
{
  mpLayout = layout;
  mpPar = ppp;

  if (!mpLayout) return false;

  if (!ppp) return false;

  mCompartmentMap.clear();

  //store the compartment glyph for each species glyph (if it exists)
  unsigned int i;

  for (i = 0; i < mpLayout->getListOfMetaboliteGlyphs().size() ; ++i)
    {
      CMetab* metab = dynamic_cast<CMetab*>(mpLayout->getListOfMetaboliteGlyphs()[i].getModelObject());
      CLCompartmentGlyph*  tmp = NULL;

      if (metab)
        {
          unsigned int j;

          for (j = 0; j < mpLayout->getListOfCompartmentGlyphs().size(); ++j)
            if (mpLayout->getListOfCompartmentGlyphs()[j].getModelObjectKey() == metab->getCompartment()->getKey())
              {
                tmp = &mpLayout->getListOfCompartmentGlyphs()[j];
                break;
              }
        }

      mCompartmentMap[&mpLayout->getListOfMetaboliteGlyphs()[i]] = tmp;
    }

  //store the compartment glyph for each reaction glyph (if it exists)
  for (i = 0; i < mpLayout->getListOfReactionGlyphs().size() ; ++i)
    {
      mCompartmentMap[&mpLayout->getListOfReactionGlyphs()[i]] = findCompartmentForReactionNode(mpLayout->getListOfReactionGlyphs()[i]);
    }

  //create the list of constant positional relations
  //we assume that text glyphs are always moved with the glyph they refer to.
  //(i.e. the are not layed out independently)
  mFixedRelations.clear();

  for (i = 0; i < mpLayout->getListOfTextGlyphs().size(); ++i)
    {
      CoordinateRelation tmp;
      tmp.target = &mpLayout->getListOfTextGlyphs()[i];
      tmp.source = mpLayout->getListOfTextGlyphs()[i].getGraphicalObject();

      if (tmp.source)
        {
          tmp.diff = tmp.target->getPosition() - tmp.source->getPosition();
          mFixedRelations.push_back(tmp);
        }
    }

  return true;
}
コード例 #2
0
ファイル: CMetabNameInterface.cpp プロジェクト: copasi/COPASI
bool
CMetabNameInterface::doesExist(const CModel* model,
                               const std::string & metabolite,
                               const std::string & compartment)
{
  if (model == NULL)
    return false;

  CDataContainer::objectMap::range Range = model->getMetabolites().getObjects().equal_range(metabolite);
  CMetab * pSpecies = NULL;

  for (; Range.first != Range.second; ++Range.first)
    if ((pSpecies = dynamic_cast< CMetab * >(*Range.first)) != NULL)
      {
        if (compartment.empty() ||
            pSpecies->getCompartment()->getObjectName() == compartment) return true;
      }

  return false;
}
コード例 #3
0
ファイル: CMetabNameInterface.cpp プロジェクト: copasi/COPASI
std::string
CMetabNameInterface::createUniqueDisplayName(const CMetab & metab, const bool & quoted)
{
  return createUniqueDisplayName(metab.getObjectName(), metab.getCompartment()->getObjectName(), quoted);
}
コード例 #4
0
ファイル: CMetabNameInterface.cpp プロジェクト: copasi/COPASI
std::string
CMetabNameInterface::getDisplayName(const CModel* model, const CMetab & metab, const bool & quoted)
{
  return getDisplayName(model, metab.getObjectName(), metab.getCompartment()->getObjectName(), quoted);
}
コード例 #5
0
ファイル: CChemEqInterface.cpp プロジェクト: PriKalra/COPASI
void CChemEqInterface::completeCompartments()
{
  std::string DefaultCompartment;

  if (mpModel->getCompartments().size() == 0)
    DefaultCompartment = "compartment";
  else
    DefaultCompartment = mpModel->getCompartments()[0]->getObjectName();

  // We try to find a reaction compartment. Note, it is not possible to use
  // getCompartment as writeToChemEq may fail;
  std::string ReactionCompartment = "";
  bool first = true;
  bool HaveReactionCompartment = true;

  std::vector< std::string >::iterator itCompartment, endCompartment;

  itCompartment = mSubstrateCompartments.begin();
  endCompartment = mSubstrateCompartments.end();

  for (; itCompartment != endCompartment && HaveReactionCompartment; ++itCompartment)
    {
      if (*itCompartment == "") continue;

      if (first)
        {
          ReactionCompartment = *itCompartment;
          first = false;
        }
      else if (ReactionCompartment != *itCompartment)
        HaveReactionCompartment = false;
    }

  itCompartment = mProductCompartments.begin();
  endCompartment = mProductCompartments.end();

  for (; itCompartment != endCompartment && HaveReactionCompartment; ++itCompartment)
    {
      if (*itCompartment == "") continue;

      if (first)
        {
          ReactionCompartment = *itCompartment;
          first = false;
        }
      else if (ReactionCompartment != *itCompartment)
        HaveReactionCompartment = false;
    }

  itCompartment = mModifierCompartments.begin();
  endCompartment = mModifierCompartments.end();

  for (; itCompartment != endCompartment && HaveReactionCompartment; ++itCompartment)
    {
      if (*itCompartment == "") continue;

      if (first)
        {
          ReactionCompartment = *itCompartment;
          first = false;
        }
      else if (ReactionCompartment != *itCompartment)
        HaveReactionCompartment = false;
    }

  if (first)
    ReactionCompartment = DefaultCompartment;

  CMetab * pMetab;

  std::vector< std::string >::iterator itMetab;

  itMetab = mSubstrateNames.begin();
  itCompartment = mSubstrateCompartments.begin();
  endCompartment = mSubstrateCompartments.end();

  for (; itCompartment != endCompartment; ++itCompartment, ++itMetab)
    if (*itCompartment == "")
      {
        pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, "");

        if (pMetab == NULL)
          *itCompartment = ReactionCompartment;
        else if (CMetabNameInterface::isUnique(mpModel, *itMetab))
          *itCompartment = pMetab->getCompartment()->getObjectName();
        else // Multiple metabolites with the given name exist.
          {
            // 1. Metabolite in the reaction compartment
            pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, ReactionCompartment);

            // 2. Metabolite in the default compartment if different from reaction compartment
            if (pMetab == NULL && ReactionCompartment != DefaultCompartment)
              pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, DefaultCompartment);

            // 3. The first metabolite found
            if (pMetab == NULL)
              pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, "");

            *itCompartment = pMetab->getCompartment()->getObjectName();
          }
      }

  itMetab = mProductNames.begin();
  itCompartment = mProductCompartments.begin();
  endCompartment = mProductCompartments.end();

  for (; itCompartment != endCompartment; ++itCompartment, ++itMetab)
    if (*itCompartment == "")
      {
        pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, "");

        if (pMetab == NULL)
          *itCompartment = ReactionCompartment;
        else if (CMetabNameInterface::isUnique(mpModel, *itMetab))
          *itCompartment = pMetab->getCompartment()->getObjectName();
        else // Multiple metabolites with the given name exist.
          {
            // 1. Metabolite in the reaction compartment
            pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, ReactionCompartment);

            // 2. Metabolite in the default compartment if different from reaction compartment
            if (pMetab == NULL && ReactionCompartment != DefaultCompartment)
              pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, DefaultCompartment);

            // 3. The first metabolite found
            if (pMetab == NULL)
              pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, "");

            *itCompartment = pMetab->getCompartment()->getObjectName();
          }
      }

  itMetab = mModifierNames.begin();
  itCompartment = mModifierCompartments.begin();
  endCompartment = mModifierCompartments.end();

  for (; itCompartment != endCompartment; ++itCompartment, ++itMetab)
    if (*itCompartment == "")
      {
        pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, "");

        if (pMetab == NULL)
          *itCompartment = ReactionCompartment;
        else if (CMetabNameInterface::isUnique(mpModel, *itMetab))
          *itCompartment = pMetab->getCompartment()->getObjectName();
        else // Multiple metabolites with the given name exist.
          {
            // 1. Metabolite in the reaction compartment
            pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, ReactionCompartment);

            // 2. Metabolite in the default compartment if different from reaction compartment
            if (pMetab == NULL && ReactionCompartment != DefaultCompartment)
              pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, DefaultCompartment);

            // 3. The first metabolite found
            if (pMetab == NULL)
              pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, "");

            *itCompartment = pMetab->getCompartment()->getObjectName();
          }
      }
}