Ejemplo n.º 1
0
void
UndoSpeciesData::fillObject(CModel *)
{
  CMetab * pSpecies =
    dynamic_cast<CMetab*>(CCopasiRootContainer::getKeyFactory()->get(mKey));

  if (pSpecies == NULL) return;

  if (getStatus() != CModelEntity::ASSIGNMENT)
    {
      pSpecies->setInitialConcentration(getIConc());
      pSpecies->setInitialValue(getINumber());
    }

  if (getStatus() == CModelEntity::ODE || getStatus() == CModelEntity::ASSIGNMENT)
    {
      pSpecies->setExpression(getExpression());
    }

  // set initial expression
  if (getStatus() != CModelEntity::ASSIGNMENT)
    {
      pSpecies->setInitialExpression(getInitialExpression());
    }
}
Ejemplo n.º 2
0
const CModelParameter::CompareResult & CModelParameter::diff(const CModelParameter & other,
        const CModelParameter::Framework & framework,
        const bool & /* createMissing */)
{
    if (mCompareResult == Missing ||
            mCompareResult == Obsolete)
    {
        return mCompareResult;
    }

    switch (mType)
    {
    case Compartment:
    case Species:
    case ModelValue:

        if (other.getObject() != NULL &&
                mpObject != NULL &&
                static_cast< CModelEntity *>(mpObject)->getStatus() == CModelEntity::ASSIGNMENT &&
                (fabs(getValue(ParticleNumbers) - other.getValue(ParticleNumbers)) > 50 * (fabs(getValue(ParticleNumbers)) + fabs(other.getValue(ParticleNumbers))) * std::numeric_limits< C_FLOAT64 >::epsilon() ||
                 getInitialExpression() != ""))
        {
            mCompareResult = Conflict;
            return mCompareResult;
        }

        break;

    default:
        break;
    }

    if (getInitialExpression() != other.getInitialExpression() ||
            fabs(getValue(framework) - other.getValue(framework)) > 50 * (fabs(getValue(framework)) + fabs(other.getValue(framework))) * std::numeric_limits< C_FLOAT64 >::epsilon())
    {
        mCompareResult = Modified;
    }
    else
    {
        mCompareResult = Identical;
    }

    return mCompareResult;
}
Ejemplo n.º 3
0
bool CModelParameter::isReadOnly() const
{
    if (mType == Reaction ||
            mType == Group ||
            mType == Set ||
            (mType == Model && getModel()->isAutonomous()) ||
            (mIsInitialExpressionValid && getInitialExpression() != ""))
    {
        return true;
    }

    return false;
}
Ejemplo n.º 4
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()));
}
Ejemplo n.º 5
0
// virtual
bool CModelParameter::updateModel()
{
    bool success = true;

    if (mpObject != NULL)
    {
        switch (mType)
        {
        case Model:
        {
            CModel * pModel = static_cast< CModel * >(mpObject);

            if (!pModel->isAutonomous())
            {
                pModel->setInitialValue(mValue);
            }
            else
            {
                pModel->setInitialValue(0.0);
            }
        }
        break;

        case Compartment:
        case Species:
        case ModelValue:
        {
            CModelEntity * pEntity = static_cast< CModelEntity * >(mpObject);

            if (pEntity->getStatus() != CModelEntity::ASSIGNMENT)
            {
                pEntity->setInitialValue(mValue);

                if (mIsInitialExpressionValid)
                {
                    pEntity->setInitialExpression(getInitialExpression());
                }
            }
        }
        break;

        case ReactionParameter:
        {
            CCopasiParameter * pParameter = static_cast< CCopasiParameter * >(mpObject);
            CReaction * pReaction = static_cast< CReaction * >(mpObject->getObjectAncestor("Reaction"));

            if (mIsInitialExpressionValid &&
                    getInitialExpression() != "")
            {
                CModel * pModel = mpParent->getModel();

                assert(pModel != NULL);

                std::vector< CCopasiContainer * > ListOfContainer;
                ListOfContainer.push_back(pModel);

                CCopasiObjectName CN = static_cast< CEvaluationNodeObject * >(mpInitialExpression->getRoot())->getObjectCN();
                CCopasiObject * pObject = pModel->getObjectDataModel()->ObjectFromName(ListOfContainer, CN);

                assert(pObject != NULL);

                // We assign the object value
                pParameter->setValue(* (C_FLOAT64 *) pObject->getValuePointer());

                // We map the parameter to the global quantity
                pReaction->setParameterMapping(pParameter->getObjectName(), pObject->getObjectParent()->getKey());
            }
            else
            {
                pParameter->setValue(mValue);

                // We need to remove the existing mapping to a global quantity1.
                pReaction->setParameterMapping(pParameter->getObjectName(), pParameter->getKey());
            }
        }
        break;

        default:
            success = false;
            break;
        }
    }

    return success;
}