Пример #1
0
bool CExperimentObjectMap::elevateChildren()
{
  bool success = true;

  elements::iterator itColumn = beginIndex();
  elements::iterator endColumn = endIndex();

  if (itColumn != endColumn &&
      dynamic_cast< CCopasiParameterGroup * >(*itColumn) == NULL) // We have an old data format.
    {
      CCopasiParameterGroup New(getObjectName());

      for (; itColumn != endColumn; ++itColumn)
        {
          CCopasiParameterGroup * pGroup = New.assertGroup((*itColumn)->getObjectName());
          pGroup->assertParameter("Object CN", CCopasiParameter::CN, (*itColumn)->getValue< CRegisteredObjectName >());
        }

      clear();
      operator=(New);
    }

  for (itColumn = beginIndex(); itColumn != endColumn; ++itColumn)
    if (((*itColumn) = elevate<CDataColumn, CCopasiParameterGroup>(*itColumn)) == NULL)
      success = false;

  return success;
}
Пример #2
0
// virtual
QModelIndex CQTaskMethodParametersDM::index(int row, int column, const QModelIndex & parent) const
{
  CCopasiParameterGroup * pParent = static_cast< CCopasiParameterGroup * >(nodeFromIndex(parent));

  if (pParent == NULL &&
      mMethods.size() > 0)
    {
      QVector< CCopasiMethod * >::const_iterator it = mMethods.constBegin();
      QVector< CCopasiMethod * >::const_iterator end = mMethods.constEnd();

      int Row = row;

      for (; it != end; ++it)
        if (Row < (int)(*it)->size())
          {
            return createIndex(row, column, *((*it)->beginIndex() + Row));
          }
        else
          {
            Row -= (int)(*it)->size();
          }

      return QModelIndex();
    }

  if (pParent != NULL && row < (int) pParent->size())
    return createIndex(row, column, *(pParent->beginIndex() + row));
  else
    return QModelIndex();
}
Пример #3
0
bool CExperimentObjectMap::elevateChildren()
{
  bool success = true;

  std::vector<CCopasiParameter *>::iterator itColumn = mValue.pGROUP->begin();
  std::vector<CCopasiParameter *>::iterator endColumn = mValue.pGROUP->end();

  if (itColumn != endColumn &&
      dynamic_cast< CCopasiParameterGroup * >(*itColumn) == NULL) // We have an old data format.
    {
      CCopasiParameterGroup New(getObjectName());

      for (; itColumn != endColumn; ++itColumn)
        {
          CCopasiParameterGroup * pGroup = New.assertGroup((*itColumn)->getObjectName());
          pGroup->assertParameter("Object CN", CCopasiParameter::CN, *(*itColumn)->getValue().pCN);
        }

      clear();
      *this = New;
    }

  for (itColumn = mValue.pGROUP->begin(); itColumn != endColumn; ++itColumn)
    if (((*itColumn) = elevate<CDataColumn, CCopasiParameterGroup>(*itColumn)) == NULL)
      success = false;

  return success;
}
Пример #4
0
C_FLOAT64 CExperimentObjectMap::CDataColumn::getDefaultScale() const
{
  if (mpObjectCN == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  CCopasiParameterGroup *pGroup =
    dynamic_cast< CCopasiParameterGroup * >(getObjectParent());

  if (pGroup == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  const CExperiment *pExperiment =
    dynamic_cast<const CExperiment * >(pGroup->getObjectParent());

  if (pExperiment == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  CObjectInterface::ContainerList ListOfContainer;
  ListOfContainer.push_back(getObjectDataModel());

  const CCopasiObject * pObject = CObjectInterface::DataObject(CObjectInterface::GetObjectFromCN(ListOfContainer, *mpObjectCN));

  if (pObject == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  return pExperiment->getDefaultScale(pObject);
}
Пример #5
0
void CQParameterGroupView::slotPushButtonClicked(const QModelIndex & index)
{
  QModelIndex Source = index;

  while (Source.model()->inherits("QSortFilterProxyModel"))
    {
      Source = static_cast< const QSortFilterProxyModel *>(Source.model())->mapToSource(index);
    }

  if (this->itemDelegateForRow(Source.row()) != mpPushButtonDelegate) return;

  CCopasiParameter * pParameter = CQParameterGroupDM::nodeFromIndex(Source);

  if (pParameter->getType() != CCopasiParameter::Type::GROUP) return;

  CCopasiParameterGroup * pGroup = static_cast< CCopasiParameterGroup * >(pParameter);

  CCopasiParameterGroup::elements::const_iterator it = pGroup->getElementTemplates().beginIndex();
  CCopasiParameterGroup::elements::const_iterator end = pGroup->getElementTemplates().endIndex();

  for (; it != end; ++it)
    {
      switch ((*it)->getType())
        {
          case CCopasiParameter::Type::CN:
            modifySelectCNs(*pGroup, **it);
            break;

          default:
            break;
        }
    }
}
Пример #6
0
C_FLOAT64 CExperimentObjectMap::CDataColumn::getDefaultScale() const
{
  if (mpObjectCN == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  CCopasiParameterGroup *pGroup =
    dynamic_cast< CCopasiParameterGroup * >(getObjectParent());

  if (pGroup == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  const CExperiment *pExperiment =
    dynamic_cast<const CExperiment * >(pGroup->getObjectParent());

  if (pExperiment == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  const CCopasiDataModel* pDataModel = getObjectDataModel();
  assert(pDataModel != NULL);
  const CCopasiObject * pObject = pDataModel->getDataObject(*mpObjectCN);

  if (pObject == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  return pExperiment->getDefaultScale(pObject);
}
Пример #7
0
int CQTaskMethodParametersDM::getRow(const CCopasiParameter * pNode) const
{
  if (pNode == NULL)
    {
      return -1;
    }

  CCopasiParameterGroup * pParent = static_cast< CCopasiParameterGroup * >(pNode->getObjectParent());

  if (pParent == NULL)
    {
      return 0;
    }

  if (isMethod(pParent))
    {
      QVector< CCopasiMethod * >::const_iterator itMethod = mMethods.constBegin();
      QVector< CCopasiMethod * >::const_iterator endMethod = mMethods.constEnd();

      int i = 0;

      for (; itMethod != endMethod; ++itMethod)
        {
          CCopasiParameterGroup::index_iterator it = pParent->beginIndex();
          CCopasiParameterGroup::index_iterator end = pParent->endIndex();

          for (; it != end; ++it, ++i)
            if (*it == pNode)
              {
                return i;
              }
        }
    }
  else
    {
      int i = 0;

      CCopasiParameterGroup::index_iterator it = pParent->beginIndex();
      CCopasiParameterGroup::index_iterator end = pParent->endIndex();

      for (; it != end; ++it, ++i)
        if (*it == pNode)
          {
            return i;
          }
    }

  return -1;
}
Пример #8
0
bool CScanWidgetRandom::saveToScanItem(CScanProblem * pg) const
{
  CScanProblem::Type type = CScanProblem::SCAN_RANDOM;

  unsigned C_INT32 steps = 1;

  CCopasiParameterGroup* tmp = pg->createScanItem(type, steps, mpObject);
  assert(tmp);

  tmp->setValue("Distribution type", (unsigned C_INT32)comboBoxType->currentItem());
  tmp->setValue("Minimum", lineEditMin->text().toDouble());
  tmp->setValue("Maximum", lineEditMax->text().toDouble());
  tmp->setValue("log", checkBoxLog->isChecked());

  return true;
}
Пример #9
0
void CQParameterGroupView::modifySelectCNs(CCopasiParameterGroup & group, const CCopasiParameter & cnTemplate)
{
  // OpenSelectionDialog
  std::vector< const CDataObject * > Selection;
  CObjectInterface::ContainerList ContainerList;
  ContainerList.push_back(group.getObjectDataModel());

  // Create the current selection
  CCopasiParameterGroup::elements::iterator it = group.beginIndex();
  CCopasiParameterGroup::elements::iterator end = group.endIndex();

  for (; it != end; ++it)
    {
      const CDataObject * pObject = CObjectInterface::DataObject(CObjectInterface::GetObjectFromCN(ContainerList, (*it)->getValue< CCommonName >()));

      if (pObject != NULL)
        {
          Selection.push_back(pObject);
        }
    }

  CModel * pModel = group.getObjectDataModel()->getModel();

  std::vector<const CDataObject * > ValidObjects;

  const std::vector< std::pair < CCommonName, CCommonName > > & ValidValues = cnTemplate.getValidValues< CCommonName >();
  std::vector< std::pair < CCommonName, CCommonName > >::const_iterator itValidValues = ValidValues.begin();
  std::vector< std::pair < CCommonName, CCommonName > >::const_iterator endValidValues = ValidValues.end();

  for (; itValidValues != endValidValues; ++itValidValues)
    {
      CObjectLists::ListType ListType = toEnum(itValidValues->first, CObjectLists::ListTypeName, CObjectLists::EMPTY_LIST);
      std::vector<const CDataObject * > Tmp = CObjectLists::getListOfConstObjects(ListType, pModel);
      ValidObjects.insert(ValidObjects.end(), Tmp.begin(), Tmp.end());
    }

  std::vector< const CDataObject * > NewSelection = CCopasiSelectionDialog::getObjectVector(this, ValidObjects, &Selection);

  // Modify group parameters;
  mpParameterGroupDM->beginResetModel();
  group.clear();

  std::vector< const CDataObject * >::const_iterator itNew = NewSelection.begin();
  std::vector< const CDataObject * >::const_iterator endNew = NewSelection.end();

  for (; itNew != endNew; ++itNew)
    {
      group.addParameter("Reaction", CCopasiParameter::Type::CN, (*itNew)->getCN());
    }

  mpParameterGroupDM->endResetModel();
}
Пример #10
0
bool CFitProblem::elevateChildren()
{
  // This call is necessary since CFitProblem is derived from COptProblem.
  if (!COptProblem::elevateChildren()) return false;

  // Due to a naming conflict the following parameters may have been overwritten during
  // the load of a CopasiML file we replace them with default values if that was the case.
  mpParmSteadyStateCN =
    assertParameter("Steady-State", CCopasiParameter::CN, CCopasiObjectName(""))->getValue().pCN;
  mpParmTimeCourseCN =
    assertParameter("Time-Course", CCopasiParameter::CN, CCopasiObjectName(""))->getValue().pCN;

  CCopasiVectorN< CCopasiTask > * pTasks = NULL;
  CCopasiDataModel* pDataModel = getObjectDataModel();

  if (pDataModel)
    pTasks = pDataModel->getTaskList();

  if (pTasks == NULL)
    pTasks = dynamic_cast<CCopasiVectorN< CCopasiTask > *>(getObjectAncestor("Vector"));

  if (pTasks)
    {
      unsigned C_INT32 i, imax = pTasks->size();

      if (!mpParmSteadyStateCN->compare(0, 5 , "Task_") ||
          *mpParmSteadyStateCN == "")
        for (i = 0; i < imax; i++)
          if ((*pTasks)[i]->getType() == CCopasiTask::steadyState)
            {
              *mpParmSteadyStateCN = (*pTasks)[i]->getCN();
              break;
            }

      if (!mpParmTimeCourseCN->compare(0, 5 , "Task_") ||
          *mpParmTimeCourseCN == "")
        for (i = 0; i < imax; i++)
          if ((*pTasks)[i]->getType() == CCopasiTask::timeCourse)
            {
              *mpParmTimeCourseCN = (*pTasks)[i]->getCN();
              break;
            }
    }

  std::map<std::string, std::string> ExperimentMap;
  CCopasiParameterGroup * pGroup;
  CExperiment * pExperiment;

  std::vector<CCopasiParameter *> * pExperiments =
    getGroup("Experiment Set")->CCopasiParameter::getValue().pGROUP;
  std::vector<CCopasiParameter *>::iterator itExp;
  std::vector<CCopasiParameter *>::iterator endExp;

  for (itExp = pExperiments->begin(), endExp = pExperiments->end(); itExp != endExp; ++itExp)
    if ((pGroup = dynamic_cast< CCopasiParameterGroup * >(*itExp)) != NULL &&
        pGroup->getParameter("Key") != NULL)
      ExperimentMap[*pGroup->getValue("Key").pKEY] = (*itExp)->getObjectName();

  mpExperimentSet =
    elevate<CExperimentSet, CCopasiParameterGroup>(getGroup("Experiment Set"));

  if (!mpExperimentSet) return false;

  std::map<std::string, std::string>::iterator itMap;
  std::map<std::string, std::string>::iterator endMap;

  for (itMap = ExperimentMap.begin(), endMap = ExperimentMap.end(); itMap != endMap; ++itMap)
    {
      pExperiment = mpExperimentSet->getExperiment(itMap->second);
      itMap->second = pExperiment->CCopasiParameter::getKey();
      pExperiment->setValue("Key", itMap->second);
    }


  std::vector<COptItem * >::iterator it = mpOptItems->begin();
  std::vector<COptItem * >::iterator end = mpOptItems->end();

  for (; it != end; ++it)
    {
      if (!((*it) = elevate<CFitItem, COptItem>(*it)))
        return false;

      pExperiments =
        (*it)->getParameter("Affected Experiments")->getValue().pGROUP;

      for (itExp = pExperiments->begin(), endExp = pExperiments->end(); itExp != endExp; ++itExp)
        (*itExp)->setValue(ExperimentMap[*(*itExp)->getValue().pKEY]);

    }

  it = mpConstraintItems->begin();
  end = mpConstraintItems->end();

  for (; it != end; ++it)
    {
      if (!((*it) = elevate<CFitConstraint, COptItem>(*it)))
        return false;

      pExperiments =
        (*it)->getParameter("Affected Experiments")->getValue().pGROUP;

      for (itExp = pExperiments->begin(), endExp = pExperiments->end(); itExp != endExp; ++itExp)
        (*itExp)->setValue(ExperimentMap[*(*itExp)->getValue().pKEY]);

    }

  return true;
}
Пример #11
0
/**
 * Creates the simulations for SEDML.
 */
std::string CSEDMLExporter::createScanTask(CCopasiDataModel& dataModel, const std::string & modelId)
{
  // need L1V2 to export repeated tasks
  if (mpSEDMLDocument->getVersion() != 2) return "";

  CScanTask* pTask =  dynamic_cast<CScanTask*>((*dataModel.getTaskList())["Scan"]);

  if (pTask == NULL) return "";

  CScanProblem* pProblem = dynamic_cast<CScanProblem*>(pTask->getProblem());
  size_t numItems = pProblem->getNumberOfScanItems();

  if (numItems == 0)
    return "";

  if (pProblem->getSubtask() != CCopasiTask::steadyState &&
      pProblem->getSubtask() != CCopasiTask::timeCourse)
    {
      CCopasiMessage(CCopasiMessage::WARNING, "This version of COPASI only allows the export of time course or steady state scans.");
      return "";
    }

  std::string subTaskId;

  if (pProblem->getSubtask() == CCopasiTask::steadyState)
    {
      subTaskId = createSteadyStateTask(dataModel, modelId);
    }
  else
    {
      subTaskId = mpTimecourseTask->getId();
    }

  SedRepeatedTask* task = mpSEDMLDocument->createRepeatedTask();
  std::string taskId = SEDMLUtils::getNextId("task", mpSEDMLDocument->getNumTasks());
  task->setId(taskId);
  task->setResetModel(!pProblem->getContinueFromCurrentState());

  // craete ranges / changes
  for (size_t i = 0; i < numItems; ++i)
    {
      CCopasiParameterGroup* current = pProblem->getScanItem(i);
      CScanProblem::Type type = (CScanProblem::Type)(*current->getParameter("Type")->getValue().pUINT);

      // ignore random items
      if (type == CScanProblem::SCAN_RANDOM)
        {
          CCopasiMessage(CCopasiMessage::WARNING, "This version of COPASI cannot export random scan items, they will be ignored.");
          continue;
        }

      int numSteps = (*current->getParameter("Number of steps")->getValue().pUINT);

      // handle repeats
      if (type == CScanProblem::SCAN_REPEAT)
        {
          SedUniformRange *range = task->createUniformRange();
          range->setId(SEDMLUtils::getNextId("range", task->getNumRanges()));
          range->setStart(0);
          range->setEnd(numSteps);
          range->setNumberOfPoints(numSteps);
          range->setType("linear");

          if (task->isSetRangeId())
            task->setRangeId(range->getId());

          continue;
        }

      // handle scans
      if (type == CScanProblem::SCAN_LINEAR)
        {
          double min = (*current->getParameter("Minimum")->getValue().pDOUBLE);
          double max = (*current->getParameter("Maximum")->getValue().pDOUBLE);
          bool log = (*current->getParameter("log")->getValue().pBOOL);

          SedUniformRange *range = task->createUniformRange();
          range->setId(SEDMLUtils::getNextId("range", task->getNumRanges()));
          range->setStart(min);
          range->setEnd(max);
          range->setNumberOfPoints(numSteps);
          range->setType(log ? "log" : "linear");

          const CRegisteredObjectName& cn = (*current->getParameter("Object")->getValue().pCN);
          std::string xpath = SEDMLUtils::getXPathForObject(*static_cast<const CCopasiObject*>(dataModel.getObject(cn)));

          if (xpath.empty())
            {
              CCopasiMessage(CCopasiMessage::WARNING, "This version of COPASI cannot export the selected scan object, it will be ignored.");
              continue;
            }

          SedSetValue *change = task->createTaskChange();
          change->setModelReference(modelId);

          if (xpath == SEDML_TIME_URN)
            {
              change->setSymbol(xpath);
            }
          else
            {
              change->setTarget(xpath);
            }

          change->setRange(range->getId());
          change->setMath(SBML_parseFormula(range->getId().c_str()));

          continue;
        }
    }

  if (!task->isSetRangeId() && task->getNumRanges() > 0)
    task->setRangeId(task->getRange(0)->getId());

  // create subtask
  SedSubTask* subTask = task->createSubTask();
  subTask->setOrder(1);
  subTask->setTask(subTaskId);

  return taskId;
}
Пример #12
0
CExperimentSet::CExperimentSet(const CCopasiParameterGroup & group,
                               const CDataContainer * pParent):
  CCopasiParameterGroup(group, static_cast< const CDataContainer * >((pParent != NULL) ? pParent : group.getObjectDataModel())),
  mpExperiments(NULL),
  mNonExperiments(0),
  mDependentObjects(0),
  mDependentObjectiveValues(0),
  mDependentRMS(0),
  mDependentErrorMean(0),
  mDependentErrorMeanSD(0),
  mDependentDataCount(0),
  mValidValueCount(0)
{initializeParameter();}