Пример #1
0
bool ScanWidget::saveTaskProtected()
{
  if (mIsLoading)
    return true; // currently loading the widget list cannot be trusted

  saveCommon();

  CScanTask* scanTask =
    dynamic_cast< CScanTask * >(mpObject);

  if (!scanTask) return false;

  CScanProblem *scanProblem = dynamic_cast<CScanProblem *>(scanTask->getProblem());

  if (!scanProblem) return false;

  const std::vector< QWidget * > & widgetList = scrollview->getWidgetList();

  size_t newSize = widgetList.size() - 1; // The last widget is reserved for the subtask.
  size_t oldSize = scanProblem->getNumberOfScanItems();

  size_t i, imax = std::min(newSize, oldSize);

  mChanged = false;

  for (i = 0; i < imax; ++i)
    {
      QWidget * pWidget = widgetList[i];

      if (pWidget->objectName() == "CScanWidgetScan")
        {
          mChanged |= static_cast< CScanWidgetScan * >(pWidget)->save(scanProblem->getScanItem(i));
        }
      else if (pWidget->objectName() == "CScanWidgetRandom")
        {
          mChanged |= static_cast< CScanWidgetRandom * >(pWidget)->save(scanProblem->getScanItem(i));
        }
      else if (pWidget->objectName() == "CScanWidgetRepeat")
        {
          mChanged |= static_cast< CScanWidgetRepeat * >(pWidget)->save(scanProblem->getScanItem(i));
        }
    }

  for (; i < newSize; ++i)
    {
      mChanged = true;
      QWidget * pWidget = widgetList[i];
      CCopasiParameterGroup * pItem = scanProblem->addScanItem(CScanProblem::SCAN_LINEAR);

      if (pWidget->objectName() == "CScanWidgetScan")
        {
          static_cast< CScanWidgetScan * >(pWidget)->save(pItem);
        }
      else if (pWidget->objectName() == "CScanWidgetRandom")
        {
          static_cast< CScanWidgetRandom * >(pWidget)->save(pItem);
        }
      else if (pWidget->objectName() == "CScanWidgetRepeat")
        {
          static_cast< CScanWidgetRepeat * >(pWidget)->save(pItem);
        }
    }

  for (; i < oldSize; ++i)
    {
      mChanged = true;
      scanProblem->removeScanItem(newSize);
    }

  // the subtask
  const CScanWidgetTask * tmpT = dynamic_cast<CScanWidgetTask*>(widgetList[newSize]);

  if (tmpT != NULL)
    {
      mChanged |= tmpT->save(scanProblem);
    }

  // :TODO Bug 322: This should only be called when actual changes have been saved.
  // However we do not check whether the scan item are mChanged we delete all
  // and create them new.
  if (mChanged)
    {
      if (mpDataModel != NULL)
        {
          mpDataModel->changed();
        }

      mChanged = false;
    }

  return true;
}
Пример #2
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;
}
Пример #3
0
bool ScanWidget::loadTaskProtected()
{
  if (mIsLoading)
    return true; // currently loading

  mIsLoading = true;

  loadCommon();

  CScanTask* scanTask =
    dynamic_cast< CScanTask * >(mpObject);

  if (!scanTask) return false;

  CScanProblem *scanProblem = dynamic_cast<CScanProblem *>(scanTask->getProblem());

  if (!scanProblem) return false;

  scrollview->clearWidgetList();

  //std::vector<QWidget*> & widgetList = scrollview->getWidgetList();

  //+++
  CScanWidgetScan* tmp1;
  CScanWidgetRepeat* tmp2;
  CScanWidgetRandom* tmp3;
  //CScanWidgetBreak* tmp4;

  // the scan items
  assert(CRootContainer::getDatamodelList()->size() > 0);

  size_t i, imax = scanProblem->getNumberOfScanItems();

  for (i = 0; i < imax; ++i)
    {
      CScanProblem::Type type = scanProblem->getScanItem(i)->getValue< CScanProblem::Type >("Type");

      switch (type)
        {
          //+++
          case CScanProblem::SCAN_LINEAR:
            tmp1 = new CScanWidgetScan(scrollview);
            tmp1->load(scanProblem->getScanItem(i));
            scrollview->addWidget(tmp1);
            break;

          case CScanProblem::SCAN_REPEAT:
            tmp2 = new CScanWidgetRepeat(scrollview);
            tmp2->load(scanProblem->getScanItem(i));
            scrollview->addWidget(tmp2);
            break;

          case CScanProblem::SCAN_RANDOM:
            tmp3 = new CScanWidgetRandom(scrollview);
            tmp3->load(scanProblem->getScanItem(i));
            scrollview->addWidget(tmp3);
            break;

          default:
            break;
        }
    }

  // the widget for the subtask
  CScanWidgetTask* tmpT = new CScanWidgetTask(scrollview);
  tmpT->load(scanProblem);
  scrollview->addWidget(tmpT, false); //false: no control buttons (up/down/del)

  mChanged = false;

  mIsLoading = false;

  return true;
}
Пример #4
0
int main(int argc, char *argv[])
{
  // Parse the commandline options
  // first argument is the SBML filename
  // second argument is the endtime
  // third argument is the step number
  // fourth argument is the filename where the results are to be written
  // fifth argument is the tmp directory (this is not needed)
  // the rest of the arguments are species names for the result
  try
    {
      // Create the root container.
      CCopasiRootContainer::init(0, NULL, false);
    }

  catch (copasi::autoexcept &e)
    {}

  catch (copasi::option_error &e)
    {}

  if (argc < 5)
    {
      std::cout << "Usage: stochastic-testsuite METHOD SBMLFILENAME ENDTIME STEPNUMBER REPEATS OUTFILENAME SPECIESID1 SPECIESID2 ..." << std::endl;
      exit(1);
    }

  const char* pMethodType = argv[1];

  const char* pSBMLFilename = argv[2];

  const char* pEndTime = argv[3];

  const char* pStepNumber = argv[4];

  const char* pRepeats = argv[5];

  const char* pOutputFilename = argv[6];

  unsigned int NUMARGS = 7;

  /*
  std::cout << "Input : " << pSBMLFilename << std::endl;
  std::cout << "Endtime : " << pEndTime << std::endl;
  std::cout << "Stepnumber: " << pStepNumber << std::endl;
  std::cout << "Repeats : " << pRepeats << std::endl;
  std::cout << "Output file: " << pOutputFilename << std::endl;
  */
  char** pSBMLSpeciesIds = new char * [argc - NUMARGS];

  unsigned int i, iMax = argc;

  CTrajectoryTask* pTrajectoryTask = NULL;

  CScanTask* pScanTask = NULL;

  std::string CWD = COptions::getPWD();

  double endTime = strToDouble(pEndTime, &pEndTime);

  double stepNumber = strToDouble(pStepNumber, &pStepNumber);

  char** pTmpP = (char**)(&pRepeats);

  long int repeats = strtol(pRepeats, pTmpP , 10);

  CCopasiMethod::SubType MethodType;

  if (!strcmp(pMethodType, "stochastic"))
    {
      MethodType = CCopasiMethod::stochastic;
    }
  else if (!strcmp(pMethodType, "directMethod"))
    {
      MethodType = CCopasiMethod::directMethod;
    }
  else if (!strcmp(pMethodType, "tauLeap"))
    {
      MethodType = CCopasiMethod::tauLeap;
    }
  else if (!strcmp(pMethodType, "adaptiveSA"))
    {
      MethodType = CCopasiMethod::adaptiveSA;
    }
  else if (!strcmp(pMethodType, "LSODA"))
    {
      MethodType = CCopasiMethod::deterministic;
    }
  else
    {
      std::cerr << "Invalid method type. Valid options are:" << std::endl;
      std::cerr << "    stochastic" << std::endl;
      std::cerr << "    directMethod" << std::endl;
      std::cerr << "    tauLeap" << std::endl;
    }

  if (endTime == 0.0)
    {
      std::cerr << "Invalid endtime " << pEndTime << std::endl;
      exit(1);
    }

  if (stepNumber == 0.0)
    {
      std::cerr << "Invalid step number " << pStepNumber << std::endl;
      exit(1);
    }

  for (i = NUMARGS; i < iMax; ++i)
    {
      pSBMLSpeciesIds[i - NUMARGS] = argv[i];
      //std::cout << "Copying pointer to " <<  argv[i]  << "." << std::endl;
    }

  try
    {
      // Create the global data model.
      CCopasiDataModel* pDataModel = CCopasiRootContainer::addDatamodel();

      // Import the SBML File
      pDataModel->importSBML(pSBMLFilename);

      //pDataModel->getModel()->forceCompile();

      // create a report with the correct filename and all the species against
      // time.
      CReportDefinitionVector* pReports = pDataModel->getReportDefinitionList();
      CReportDefinition* pReport = pReports->createReportDefinition("Report", "Output for stochastic testsuite run");
      pReport->setTaskType(CCopasiTask::timeCourse);
      pReport->setIsTable(false);

      CCopasiReportSeparator Separator(std::string(","));
      pReport->setSeparator(Separator);

      std::vector<CRegisteredObjectName> * pHeader = pReport->getHeaderAddr();
      std::vector<CRegisteredObjectName> * pBody = pReport->getBodyAddr();

      // Add time column
      pHeader->push_back(CCopasiStaticString("time").getCN());
      pBody->push_back(CCopasiObjectName(pDataModel->getModel()->getCN() + ",Reference=Time"));

      iMax = iMax - NUMARGS;
      const CCopasiVector<CMetab>& metabolites = pDataModel->getModel()->getMetabolites();

      for (i = 0; i < iMax; ++i)
        {
          pHeader->push_back(Separator.getCN());
          pBody->push_back(Separator.getCN());

          unsigned int j, jMax = metabolites.size();

          std::string SBMLId = unQuote(pSBMLSpeciesIds[i]);

          for (j = 0; j < jMax; ++j)
            {
              if (metabolites[j]->getSBMLId() == SBMLId)
                {
                  break;
                }
            }

          if (j == jMax)
            {
              std::cerr << "Could not find a metabolite for the SBML id \"" << pSBMLSpeciesIds[i] << "\"" << std::endl;
              exit(1);
            }

          pHeader->push_back(CCopasiStaticString(SBMLId).getCN());
          pBody->push_back(metabolites[j]->getObject(CCopasiObjectName("Reference=ParticleNumber"))->getCN());
        }

      // create a trajectory task
      pTrajectoryTask = new CTrajectoryTask();
      pTrajectoryTask->setMethodType(MethodType);
      pTrajectoryTask->getProblem()->setModel(pDataModel->getModel());
      pTrajectoryTask->setScheduled(false);

      //pTrajectoryTask->getReport().setReportDefinition(pReport);
      //pTrajectoryTask->getReport().setTarget(CWD + "/" + pOutputFilename);
      //pTrajectoryTask->getReport().setAppend(false);

      CTrajectoryProblem* pProblem = dynamic_cast<CTrajectoryProblem*>(pTrajectoryTask->getProblem());

      pProblem->setStepNumber((const unsigned C_INT32)stepNumber);
      pProblem->setDuration((const C_FLOAT64)endTime);
      pProblem->setTimeSeriesRequested(true);
      pProblem->setTimeSeriesRequested(false);

      //pProblem->setInitialState(pDataModel->getModel()->getInitialState());

      CCopasiVectorN< CCopasiTask > & TaskList = * pDataModel->getTaskList();

      TaskList.remove("Time-Course");
      TaskList.add(pTrajectoryTask, true);

      // create a scan task

      pScanTask = new CScanTask(pDataModel);
      CScanProblem* pScanProblem = dynamic_cast<CScanProblem*>(pScanTask->getProblem());
      pScanProblem->setModel(pDataModel->getModel());

      pScanTask->setScheduled(true);

      pScanTask->getReport().setReportDefinition(pReport);
      pScanTask->getReport().setTarget(CWD + "/" + pOutputFilename);
      pScanTask->getReport().setAppend(false);

      pScanProblem->setSubtask(CCopasiTask::timeCourse);
      pScanProblem->createScanItem(CScanProblem::SCAN_REPEAT, repeats);
      pScanProblem->setOutputInSubtask(true);
      pScanProblem->setContinueFromCurrentState(false);

      TaskList.remove("Scan");
      TaskList.add(pScanTask, true);

      // save the file for control purposes
      std::string saveFilename = pSBMLFilename;
      saveFilename = saveFilename.substr(0, saveFilename.length() - 4) + ".cps";
      pDataModel->saveModel(saveFilename, NULL, true);

      // Run the trajectory task

      pScanTask->initialize(CCopasiTask::OUTPUT_SE, pDataModel, NULL);
      pScanTask->process(true);
      pScanTask->restore();

      // create another report that will write to the directory where the input file came from
      // this can be used for debugging
      // create a trajectory task
      // pScanTask->getReport().setTarget(pOutputFilename);

      // pScanTask->initialize(CCopasiTask::OUTPUT_SE, pDataModel, NULL);
      // pScanTask->process(true);
      // pScanTask->restore();
    }
  catch (CCopasiException Exception)
    {
      std::cerr << Exception.getMessage().getText() << std::endl;
    }

  CCopasiRootContainer::destroy();

  return 0;
}