copasi/sedml/CSEDMLExporter.cpp
/**
 * Creates the simulations for SEDML.
 */
Creates the simulations for SEDML.
Creates the simulations for SEDML .
std::string
CSEDMLExporter::createScanTask(CDataModel& dataModel, const std::string & modelId)
{
  if (mpSEDMLDocument->getVersion() != 2)
    return "";
  CScanTask* pTask =  dynamic_cast<CScanTask*>(&dataModel.getTaskList()->operator[]("Scan"));
  if (pTask == NULL)
    return "";
  CScanProblem* pProblem = dynamic_cast<CScanProblem*>(pTask->getProblem());
  size_t numItems = pProblem->getNumberOfScanItems();
  if (numItems == 0)
    return "";
  if (pProblem->getSubtask() != CTaskEnum::Task::steadyState &&
      pProblem->getSubtask() != CTaskEnum::Task::timeCourse)
    {
      CCopasiMessage(CCopasiMessage::WARNING, "SED-ML: This version of COPASI only allows the export of time course or steady state scans.");
      return "";
    }
  std::string subTaskId;
  if (pProblem->getSubtask() == CTaskEnum::Task::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());
  for (size_t i = 0; i < numItems; ++i)
    {
      CCopasiParameterGroup* current = pProblem->getScanItem(i);
      CScanProblem::Type type = (CScanProblem::Type)(current->getParameter("Type")->getValue< unsigned C_INT32 >());
      if (type == CScanProblem::SCAN_RANDOM)
        {
          CCopasiMessage(CCopasiMessage::WARNING, "SED-ML: This version of COPASI cannot export random scan items, they will be ignored.");
          continue;
        }
      int numSteps = (current->getParameter("Number of steps")->getValue< unsigned C_INT32 >());
      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;
        }
      if (type == CScanProblem::SCAN_LINEAR)
        {
          double min = (current->getParameter("Minimum")->getValue< C_FLOAT64 >());
          double max = (current->getParameter("Maximum")->getValue< C_FLOAT64 >());
          bool log = (current->getParameter("log")->getValue< bool >());
          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 CRegisteredCommonName& cn = (current->getParameter("Object")->getValue< CCommonName >());
          const CDataObject* pObject = static_cast<const CDataObject*>(dataModel.getObject(cn));
          if (pObject == NULL)
            {
              CCopasiMessage(CCopasiMessage::WARNING, "SED-ML: This version of COPASI cannot export the selected scan object, it will be ignored.");
              continue;
            }
          std::string xpath = SEDMLUtils::getXPathForObject(*pObject);
          if (xpath.empty())
            {
              CCopasiMessage(CCopasiMessage::WARNING, "SED-ML: 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());
  SedSubTask* subTask = task->createSubTask();
  subTask->setOrder(1);
  subTask->setTask(subTaskId);
  return taskId;
}
std :: string CSEDMLExporter :: createScanTask ( CDataModel & dataModel , const std :: string & modelId ) { if ( mpSEDMLDocument -> getVersion ( ) != 2 ) return " " ; CScanTask * pTask = dynamic_cast < CScanTask * > ( & dataModel . getTaskList ( ) -> operator [ ] ( " " ) ) ; if ( pTask == NULL ) return " " ; CScanProblem * pProblem = dynamic_cast < CScanProblem * > ( pTask -> getProblem ( ) ) ; size_t numItems = pProblem -> getNumberOfScanItems ( ) ; if ( numItems == 0 ) return " " ; if ( pProblem -> getSubtask ( ) != CTaskEnum :: Task :: steadyState && pProblem -> getSubtask ( ) != CTaskEnum :: Task :: timeCourse ) { CCopasiMessage ( CCopasiMessage :: WARNING , " " ) ; return " " ; } std :: string subTaskId ; if ( pProblem -> getSubtask ( ) == CTaskEnum :: Task :: steadyState ) { subTaskId = createSteadyStateTask ( dataModel , modelId ) ; } else { subTaskId = mpTimecourseTask -> getId ( ) ; } SedRepeatedTask * task = mpSEDMLDocument -> createRepeatedTask ( ) ; std :: string taskId = SEDMLUtils :: getNextId ( " " , mpSEDMLDocument -> getNumTasks ( ) ) ; task -> setId ( taskId ) ; task -> setResetModel ( ! pProblem -> getContinueFromCurrentState ( ) ) ; for ( size_t i = 0 ; i < numItems ; ++ i ) { CCopasiParameterGroup * current = pProblem -> getScanItem ( i ) ; CScanProblem :: Type type = ( CScanProblem :: Type ) ( current -> getParameter ( " " ) -> getValue < unsigned C_INT32 > ( ) ) ; if ( type == CScanProblem :: SCAN_RANDOM ) { CCopasiMessage ( CCopasiMessage :: WARNING , " " ) ; continue ; } int numSteps = ( current -> getParameter ( " " ) -> getValue < unsigned C_INT32 > ( ) ) ; if ( type == CScanProblem :: SCAN_REPEAT ) { SedUniformRange * range = task -> createUniformRange ( ) ; range -> setId ( SEDMLUtils :: getNextId ( " " , task -> getNumRanges ( ) ) ) ; range -> setStart ( 0 ) ; range -> setEnd ( numSteps ) ; range -> setNumberOfPoints ( numSteps ) ; range -> setType ( " " ) ; if ( task -> isSetRangeId ( ) ) task -> setRangeId ( range -> getId ( ) ) ; continue ; } if ( type == CScanProblem :: SCAN_LINEAR ) { double min = ( current -> getParameter ( " " ) -> getValue < C_FLOAT64 > ( ) ) ; double max = ( current -> getParameter ( " " ) -> getValue < C_FLOAT64 > ( ) ) ; bool log = ( current -> getParameter ( " " ) -> getValue < bool > ( ) ) ; SedUniformRange * range = task -> createUniformRange ( ) ; range -> setId ( SEDMLUtils :: getNextId ( " " , task -> getNumRanges ( ) ) ) ; range -> setStart ( min ) ; range -> setEnd ( max ) ; range -> setNumberOfPoints ( numSteps ) ; range -> setType ( log ? " " : " " ) ; const CRegisteredCommonName & cn = ( current -> getParameter ( " " ) -> getValue < CCommonName > ( ) ) ; const CDataObject * pObject = static_cast < const CDataObject * > ( dataModel . getObject ( cn ) ) ; if ( pObject == NULL ) { CCopasiMessage ( CCopasiMessage :: WARNING , " " ) ; continue ; } std :: string xpath = SEDMLUtils :: getXPathForObject ( * pObject ) ; if ( xpath . empty ( ) ) { CCopasiMessage ( CCopasiMessage :: WARNING , " " ) ; 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 ( ) ) ; SedSubTask * subTask = task -> createSubTask ( ) ; subTask -> setOrder ( 1 ) ; subTask -> setTask ( subTaskId ) ; return taskId ; }
Creates the simulations for SEDML.
Creates the simulations for SEDML .
// need L1V2 to export repeated tasks // create ranges / changes // ignore random items // handle repeats // handle scans // create subtask