示例#1
0
// static
std::string CModelParameter::nameFromCN(const CCopasiObjectName & cn)
{
    CCopasiObjectName Primary = cn.getPrimary();
    CCopasiObjectName Remainder = cn.getRemainder();

    while (Remainder != "")
    {
        Primary = Remainder.getPrimary();
        Remainder = Remainder.getRemainder();
    }

    std::string Name = Primary.getElementName(0);

    if (Name != "")
    {
        return Name;
    }

    return Primary.getObjectName();
}
示例#2
0
// virtual
void CModelParameterReactionParameter::compile()
{
    CModelParameter::compile();

    mGlobalQuantityCN = std::string();

    std::string Infix = getInitialExpression();

    if (Infix.length() > 2)
    {
        // Infix: <CN,Reference=InitialValue> or <CN,Reference=Value>
        CCopasiObjectName Tmp = Infix.substr(1, Infix.length() - 2);
        std::string Separator = "";

        for (; Tmp != ""; Tmp = Tmp.getRemainder())
        {
            CCopasiObjectName Primary = Tmp.getPrimary();

            if (Primary.getObjectType() == "Reference")
            {
                break;
            }

            mGlobalQuantityCN += Separator + Primary;
            Separator = ",";
        }

        setSimulationType(CModelEntity::ASSIGNMENT);
    }
    else
    {
        setSimulationType(CModelEntity::FIXED);
    }

    mpGlobalQuantity = this->getSet()->getModelParameter(mGlobalQuantityCN);

    if (mpGlobalQuantity != NULL)
    {
        mValue = mpGlobalQuantity->getValue(ParticleNumbers);
    }

    std::vector< CCopasiContainer * > ListOfContainer;

    CModel * pModel = getModel();
    ListOfContainer.push_back(pModel);

    mpReaction = static_cast< CReaction * >(pModel->getObjectDataModel()->ObjectFromName(ListOfContainer, mpParent->getCN()));
}
示例#3
0
// virtual
void CModelParameterSpecies::setCN(const CCopasiObjectName & cn)
{
    CModelParameter::setCN(cn);

    // Determine the CN for the compartment.
    // "CN=Root,Model=New Model,Vector=Compartments[compartment],Vector=Metabolites[A]"
    CCopasiObjectName Tmp = mCN;
    std::string Separator = "";

    for (; Tmp != ""; Tmp = Tmp.getRemainder())
    {
        CCopasiObjectName Primary = Tmp.getPrimary();
        mCompartmentCN += Separator + Primary;
        Separator = ",";

        if (Primary.getObjectType() == "Vector" &&
                Primary.getObjectName() == "Compartments")
        {
            break;
        }
    }
}
示例#4
0
void CModelExpansion::updateExpression(CExpression* exp, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap)
{
  if (!exp)
    return;

  //we loop through the complete expression
  std::vector< CEvaluationNode * >::const_iterator it = exp->getNodeList().begin();
  std::vector< CEvaluationNode * >::const_iterator end = exp->getNodeList().end();

  for (; it != end; ++it)
    {
      CEvaluationNodeObject * node = dynamic_cast<CEvaluationNodeObject*>(*it);

      if (!node)
        continue;

      //std::cout << node->getData() << std::endl;
      const CCopasiObject * pObj = dynamic_cast<const CCopasiObject*>(node->getObjectInterfacePtr());
      std::string refname = "";
      std::string reftype = "";

      //when copying between models, pObj=NULL. This is because the expression could not be compiled
      //if it points to an object in a different model.
      //We try to fix this now:
      if (!pObj && mpSourceModel)
        {
          CCopasiObjectName cn = node->getObjectCN();

          while (cn.getPrimary().getObjectType() != "Model" && !cn.empty())
            {
              cn = cn.getRemainder();
            }

          pObj = dynamic_cast<const CCopasiObject*>(mpSourceModel->getObject(cn));
        }

      if (pObj)
        {
          refname = pObj->getObjectName();
          reftype = pObj->getObjectType();
          pObj = pObj->getObjectParent();
        }

      //is the object one that is/should be copied?
      if (sourceSet.contains(pObj))
        {
          if (!emap.exists(pObj))
            {
              //we have to create the duplicate
              std::cout << "!!!" << std::endl;

              if (dynamic_cast<const CCompartment*>(pObj))
                duplicateCompartment(dynamic_cast<const CCompartment*>(pObj), index, sourceSet, emap);

              if (dynamic_cast<const CMetab*>(pObj))
                duplicateMetab(dynamic_cast<const CMetab*>(pObj), index, sourceSet, emap);

              if (dynamic_cast<const CModelValue*>(pObj))
                duplicateGlobalQuantity(dynamic_cast<const CModelValue*>(pObj), index, sourceSet, emap);

              if (dynamic_cast<const CReaction*>(pObj))
                duplicateReaction(dynamic_cast<const CReaction*>(pObj), index, sourceSet, emap);
            }

          //find the duplicate
          const CCopasiObject* duplicate = emap.getDuplicatePtr(pObj);

          if (duplicate)
            {
              //get the reference object
              const CCopasiObject* pRef = dynamic_cast<const CCopasiObject*>(duplicate->getObject(reftype + "=" + refname));

              //update the node
              if (pRef)
                node->setData("<" + pRef->getCN() + ">");

              //std::cout << node->getData() << std::endl;
            }
        }
    }
}