Exemplo n.º 1
0
bool CEventAssignment::compile(CObjectInterface::ContainerList listOfContainer)
{
  clearDirectDependencies();

  bool success = true;

  mpTarget = NULL;

  CModelEntity * pEntity =
    dynamic_cast< CModelEntity * >(CCopasiRootContainer::getKeyFactory()->get(getObjectName()));

  // The entity type must not be an ASSIGNMENT
  if (pEntity != NULL &&
      pEntity->getStatus() != CModelEntity::ASSIGNMENT)
    {
      // We need use the virtual method getValueObject to retrieve the
      // target value from the model entity
      mpTarget = pEntity->getValueObject();
    }
  else if (pEntity != NULL &&
           pEntity->getStatus() == CModelEntity::ASSIGNMENT)
    {
      CCopasiMessage(CCopasiMessage::WARNING, "Invalid EventAssignment for '%s': an Assignment Rule already exists", pEntity->getObjectName().c_str());
    }
  else if (pEntity == NULL)
    {
      CCopasiMessage(CCopasiMessage::WARNING, "Invalid EventAssignment for '%s': object does not exist.", getObjectName().c_str());
    }

  if (mpTarget == NULL)
    {
      success = false;
    }

  if (mpExpression != NULL)
    {
      success &= mpExpression->compile(listOfContainer);
      setDirectDependencies(mpExpression->getDirectDependencies());
    }
  else
    {
      success = false;
    }

  return success;
}
Exemplo n.º 2
0
void CModelExpansion::duplicateGlobalQuantity(const CModelValue* 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
  CModelEntity* newObj;
  std::ostringstream infix;

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

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

  //status
  newObj->setStatus(source->getStatus());

  //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());
}
Exemplo n.º 3
0
void CQUpdatesWidget::loadObjectsTable(CModel* pModel)
{
  if (!pModel) return;

  mpTableObj->setColumnCount(5);
  mpTableObj->setRowCount(0);

  mpTableObj->setHorizontalHeaderItem(0, new QTableWidgetItem("User order"));
  mpTableObj->setHorizontalHeaderItem(1, new QTableWidgetItem("status"));
  mpTableObj->setHorizontalHeaderItem(2, new QTableWidgetItem(""));
  mpTableObj->setHorizontalHeaderItem(3, new QTableWidgetItem("Reduced system"));
  mpTableObj->setHorizontalHeaderItem(4, new QTableWidgetItem("status"));

  size_t i, imax;

  //metabolites
  imax = pModel->getMetabolites().size();

  if ((int) imax > mpTableObj->rowCount()) mpTableObj->setRowCount((int) imax);

  for (i = 0; i < imax; ++i)
    {
      mpTableObj->setVerticalHeaderItem((int) i, new QTableWidgetItem(QString::number(i)));

      CMetab* pM = pModel->getMetabolites()[i];

      QColor c(100, 100, 100);

      if (pM->getStatus() == CModelEntity::FIXED) c = QColor(150, 150, 150);

      if (pM->getStatus() == CModelEntity::ASSIGNMENT) c = QColor(250, 150, 250);

      if (pM->getStatus() == CModelEntity::REACTIONS) c = QColor(250, 250, 200);

      if (pM->getStatus() == CModelEntity::ODE) c = QColor(150, 250, 250);

      if (pM->getStatus() == CModelEntity::TIME) c = QColor(250, 150, 150);

      mpTableObj->setItem((int) i, 0, new QTableWidgetItem(FROM_UTF8(pM->getObjectName())));

      //mpTableObj->setText(i, 0, FROM_UTF8(pM->getObjectName()));
      std::string tmpString = CModelEntity::StatusName[pM->getStatus()];

      if (pM->isUsed())
        tmpString += " (Used = true, ";
      else
        tmpString += " (Used = false, ";

      mpTableObj->setItem((int) i, 1, new QTableWidgetItem(FROM_UTF8(tmpString)));
      //mpTableObj->setText(i, 1, FROM_UTF8(tmpString));
    }

  mpTableObj->resizeColumnToContents(0);
  mpTableObj->resizeColumnToContents(1);
  mpTableObj->setColumnWidth(2, 10);

  //metabolitesX
  imax = pModel->getMetabolitesX().size();

  if ((int) imax > mpTableObj->rowCount()) mpTableObj->setRowCount((int) imax);

  for (i = 0; i < imax; ++i)
    {
      CMetab* pM = pModel->getMetabolitesX()[i];

      QColor c(100, 100, 100);

      if (pM->getStatus() == CModelEntity::FIXED) c = QColor(150, 150, 150);

      if (pM->getStatus() == CModelEntity::ASSIGNMENT) c = QColor(250, 150, 250);

      if (pM->getStatus() == CModelEntity::REACTIONS) c = QColor(250, 250, 200);

      if (pM->getStatus() == CModelEntity::ODE) c = QColor(150, 250, 250);

      if (pM->getStatus() == CModelEntity::TIME) c = QColor(250, 150, 150);

      mpTableObj->setItem((int) i, 3, new QTableWidgetItem(FROM_UTF8(pM->getObjectName())));
      //mpTableObj->setText(i, 3, FROM_UTF8(pM->getObjectName()));

      std::string tmpString = CModelEntity::StatusName[pM->getStatus()];

      if (pM->isUsed())
        tmpString += " (Used = true, ";
      else
        tmpString += " (Used = false, ";

      mpTableObj->setItem((int) i, 4, new QTableWidgetItem(FROM_UTF8(tmpString)));
    }

  mpTableObj->resizeColumnToContents(3);
  mpTableObj->resizeColumnToContents(4);

  //state
  const CStateTemplate & st = pModel->getStateTemplate();
  imax = st.size();
  mpTableState->setRowCount(0);
  mpTableState->setRowCount((int)(imax + 1));
  mpTableState->setColumnCount(5);
  mpTableState->setHorizontalHeaderItem(0, new QTableWidgetItem("Name"));
  mpTableState->setHorizontalHeaderItem(1, new QTableWidgetItem("status"));
  mpTableState->setHorizontalHeaderItem(2, new QTableWidgetItem(""));
  mpTableState->setHorizontalHeaderItem(3, new QTableWidgetItem("ATol(1)"));
  mpTableState->setHorizontalHeaderItem(4, new QTableWidgetItem("SS criterion(1)"));

  for (i = 0; i < imax; ++i)
    {
      mpTableState->setVerticalHeaderItem((int) i, new QTableWidgetItem(QString::number(i)));

      CModelEntity* pME = *(st.getEntities() + i);

      //first column
      QColor c(100, 100, 100);

      if (dynamic_cast<CModel*>(pME)) c = QColor(250, 100, 100);

      if (dynamic_cast<CMetab*>(pME)) c = QColor(250, 250, 150);

      if (dynamic_cast<CCompartment*>(pME)) c = QColor(100, 250, 100);

      if (dynamic_cast<CModelValue*>(pME)) c = QColor(100, 100, 250);

      mpTableState->setItem((int) i, 0, new QTableWidgetItem(FROM_UTF8(pME->getObjectDisplayName())));
      //      mpTableState->setText(i, 0,FROM_UTF8(pME->getObjectDisplayName()));

      //second column
      std::string tmpString = CModelEntity::StatusName[pME->getStatus()];

      if (pME->isUsed())
        tmpString += " (Used = true, ";
      else
        tmpString += " (Used = false, ";

      c = QColor(100, 100, 100);

      if (pME->getStatus() == CModelEntity::FIXED) c = QColor(150, 150, 150);

      if (pME->getStatus() == CModelEntity::ASSIGNMENT) c = QColor(250, 150, 250);

      if (pME->getStatus() == CModelEntity::REACTIONS) c = QColor(250, 250, 200);

      if (pME->getStatus() == CModelEntity::ODE) c = QColor(150, 250, 250);

      if (pME->getStatus() == CModelEntity::TIME) c = QColor(250, 150, 150);

      mpTableState->setItem((int) i, 1, new QTableWidgetItem(FROM_UTF8(tmpString)));
      //mpTableState->setText(i, 1, FROM_UTF8(tmpString));
    }

  QColor c(200, 250, 250);

  for (i = st.beginIndependent() - st.getEntities(); i < (size_t)(st.endIndependent() - st.getEntities()); ++i)
    mpTableState->setItem((int) i, 2, new  QTableWidgetItem(""));

  c = QColor(250, 200, 250);

  for (i = st.beginDependent() - st.getEntities(); i < (size_t)(st.endDependent() - st.getEntities()); ++i)
    mpTableState->setItem((int) i, 2, new QTableWidgetItem(""));

  c = QColor(200, 200, 200);

  for (i = st.beginFixed() - st.getEntities(); i < (size_t)(st.endFixed() - st.getEntities()); ++i)
    mpTableState->setItem((int) i, 2, new QTableWidgetItem(""));

  int tmpint = st.beginIndependent() - st.getEntities();
  mpTableState->setItem(tmpint, 2, new QTableWidgetItem("beginIndependent "));
  tmpint = st.endIndependent() - st.getEntities();
  mpTableState->setItem(tmpint, 2, new QTableWidgetItem(mpTableState->item(tmpint, 2)->text() + "endIndependent "));

  tmpint = st.beginDependent() - st.getEntities();
  mpTableState->setItem(tmpint, 2, new QTableWidgetItem(mpTableState->item(tmpint, 2)->text() + "beginDependent "));
  tmpint = st.endDependent() - st.getEntities();
  mpTableState->setItem(tmpint, 2, new QTableWidgetItem(mpTableState->item(tmpint, 2)->text() + "endDependent "));

  tmpint = st.beginFixed() - st.getEntities();
  mpTableState->setItem(tmpint, 2, new QTableWidgetItem(mpTableState->item(tmpint, 2)->text() + "beginFixed "));
  tmpint = st.endFixed() - st.getEntities();
  mpTableState->setItem(tmpint, 2, new QTableWidgetItem("endFixed "));

  //add absolute Tolerances to table
  CVector< C_FLOAT64 > atolv = pModel->initializeAtolVector(1, false);
  tmpint = st.beginIndependent() - st.getEntities();

  for (i = 0; i < atolv.size(); ++i)
    {
      mpTableState->setItem((int) i + tmpint, 3, new QTableWidgetItem(QString::number(atolv[i])));

      CModelEntity* pME = *(st.getEntities() + i + 1);
      C_FLOAT64 tmp = std::min(atolv[i], std::max(100.0 * std::numeric_limits< C_FLOAT64 >::min(), fabs(pME->getInitialValue())));
      mpTableState->setItem((int) i + tmpint, 4, new QTableWidgetItem(QString::number(tmp)));
    }

  mpTableState->resizeColumnToContents(0);
  mpTableState->resizeColumnToContents(1);
  mpTableState->resizeColumnToContents(2);
  mpTableState->resizeColumnToContents(3);
  mpTableState->resizeColumnToContents(4);
}
Exemplo n.º 4
0
// virtual
bool CModelParameter::refreshFromModel(const bool & modifyExistence)
{
    bool success = true;

    if (modifyExistence)
    {
        if (mCompareResult == CModelParameter::Obsolete)
        {
            delete this;

            return true;
        }

        if (mCompareResult == CModelParameter::Missing)
        {
            mCompareResult = CModelParameter::Identical;
        }

        if (mType != ReactionParameter &&
                mpObject != NULL)
        {
            mSimulationType = static_cast< CModelEntity * >(mpObject)->getStatus();
        }
    }

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

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

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

            mValue = pEntity->getInitialValue();
        }
        break;

        case ReactionParameter:
        {
            CCopasiParameter * pParameter = static_cast< CCopasiParameter * >(mpObject);
            mValue = * pParameter->getValue().pDOUBLE;

            // We need to update the mapping
            // Check whether this refers to a global quantity.
            const CReaction * pReaction = static_cast< CModelParameterReactionParameter * >(this)->getReaction();

            if (pReaction != NULL)
            {
                if (pReaction->isLocalParameter(getName()))
                {
                    mSimulationType = CModelEntity::FIXED;
                    static_cast< CModelParameterReactionParameter * >(this)->setGlobalQuantityCN("");
                }
                else
                {
                    mSimulationType = CModelEntity::ASSIGNMENT;
                    const std::vector<std::string> ModelValue = pReaction->getParameterMapping(getName());

                    assert(ModelValue.size() == 1);

                    CModelValue * pModelValue = static_cast< CModelValue * >(CCopasiRootContainer::getKeyFactory()->get(ModelValue[0]));
                    static_cast< CModelParameterReactionParameter * >(this)->setGlobalQuantityCN(pModelValue->getInitialValueReference()->getCN());
                }
            }

            CCopasiObjectName GlobalQuantityCN = static_cast< CModelParameterReactionParameter * >(this)->getGlobalQuantityCN();

            if (GlobalQuantityCN != "")
            {
                CModelParameter * pGlobalQuantity = getSet()->getModelParameter(GlobalQuantityCN);

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

        default:
            success = false;
            break;
        }
    }

    return success;
}
Exemplo 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;
}
Exemplo n.º 6
0
bool CQRDFTreeView::enterProtected()
{
  clear();

  CCopasiObject *pObject = dynamic_cast< CCopasiObject * >(CCopasiRootContainer::getKeyFactory()->get(mKey));

  if (pObject != NULL)
    {
      CModelEntity * pEntity = NULL;
      CEvent * pEvent = NULL;
      CReaction * pReaction = NULL;
      CFunction * pFunction = NULL;
      const std::string * pMiriamAnnotation = NULL;

      if ((pEntity = dynamic_cast< CModelEntity * >(pObject)) != NULL)
        pMiriamAnnotation = &pEntity->getMiriamAnnotation();
      else if ((pEvent = dynamic_cast< CEvent * >(pObject)) != NULL)
        pMiriamAnnotation = &pEvent->getMiriamAnnotation();
      else if ((pReaction = dynamic_cast< CReaction * >(pObject)) != NULL)
        pMiriamAnnotation = &pReaction->getMiriamAnnotation();
      else if ((pFunction = dynamic_cast< CFunction * >(pObject)) != NULL)
        pMiriamAnnotation = &pFunction->getMiriamAnnotation();

      if (pMiriamAnnotation && *pMiriamAnnotation != "")
        mpGraph = CRDFParser::graphFromXml(*pMiriamAnnotation);
    }

  CCopasiMessage::clearDeque();

  if (CCopasiMessage::size() != 0)
    {
      QString Message = FROM_UTF8(CCopasiMessage::getAllMessageText());
      CQMessageBox::warning(this, QString("RDF Warning"), Message,
                            QMessageBox::Ok, QMessageBox::Ok);
    }

  if (mpGraph == NULL)
    mpGraph = new CRDFGraph;

  // We make sure that we always have an about node.
  mpGraph->createAboutNode(mKey);

  // We iterate of all triplets
  std::set< CRDFTriplet >::const_iterator it = mpGraph->getTriplets().begin();
  std::set< CRDFTriplet >::const_iterator end = mpGraph->getTriplets().end();

  for (; it != end; ++it)
    {
      CQRDFTreeViewItem * pSubjectItem = find(it->pSubject);

      if (pSubjectItem == NULL)
        {
          pSubjectItem = new CQRDFTreeViewItem(mpTreeWidget, NULL);
          insert(it->pSubject, pSubjectItem);
          // Display the subject information

          const CRDFSubject & Subject = it->pSubject->getSubject();

          switch (Subject.getType())
            {
              case CRDFSubject::RESOURCE:
                pSubjectItem->setText(COL_SUBJECT, FROM_UTF8(Subject.getResource()));
                break;

              case CRDFSubject::BLANK_NODE:
                pSubjectItem->setText(COL_SUBJECT, FROM_UTF8(Subject.getBlankNodeID()));
                break;
            }
        }

      CQRDFTreeViewItem * pObjectItem = NULL;

      if (it->Predicate.getURI() == "http://www.w3.org/1999/02/22-rdf-syntax-ns#subject")
        {
          pObjectItem = new CQRDFTreeViewItem(pSubjectItem, NULL);
          insert(it->pObject, pObjectItem);
        }
      else
        pObjectItem = find(it->pObject);

      if (pObjectItem == NULL)
        {
          pObjectItem = new CQRDFTreeViewItem(pSubjectItem, NULL);
          insert(it->pObject, pObjectItem);
        }
      else
        {
          QTreeWidgetItem * pParent = pObjectItem->parent();

          if (pParent == NULL)
            {
              mpTreeWidget->invisibleRootItem()->removeChild(pObjectItem);
              pSubjectItem->addChild(pObjectItem);
            }
          else
            {
              pParent->removeChild(pObjectItem);
              pSubjectItem->addChild(pObjectItem);
            }
        }

      pObjectItem->setTriplet(*it);
    }

  mpTreeWidget->setFocus();

  return true;
}