예제 #1
0
// virtual
int CQTaskMethodParametersDM::rowCount(const QModelIndex & parent) const
{
  if (!parent.isValid())
    {
      QVector< CCopasiMethod * >::const_iterator it = mMethods.constBegin();
      QVector< CCopasiMethod * >::const_iterator end = mMethods.constEnd();

      int size = 0;

      for (; it != end; ++it)
        size += (int)(*it)->size();

      return size;
    }

  CCopasiParameter * pParent = nodeFromIndex(parent);

  switch (pParent->getType())
    {
      case CCopasiParameter::GROUP:
        return (int) static_cast< CCopasiParameterGroup * >(pParent)->size();
        break;

      default:
        break;
    }

  return 0;
}
예제 #2
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;
        }
    }
}
예제 #3
0
CTSSATask::CTSSATask(const CTSSATask & src,
                     const CCopasiContainer * pParent):
  CCopasiTask(src, pParent),
  mTimeSeriesRequested(src.mTimeSeriesRequested),
  mTimeSeries(),
  mpTSSAProblem(NULL),
  mpTSSAMethod(NULL),
  mpCurrentState(NULL),
  mpCurrentTime(NULL)
{
  mpProblem =
    new CTSSAProblem(*static_cast< CTSSAProblem * >(src.mpProblem), this);

  mpMethod = createMethod(src.mpMethod->getSubType());
  * mpMethod = * src.mpMethod;
  mpMethod->elevateChildren();

  this->add(mpMethod, true);

  CCopasiParameter * pParameter = mpMethod->getParameter("Integrate Reduced Model");

  if (pParameter != NULL)
    mUpdateMoieties = *pParameter->getValue().pBOOL;
  else
    mUpdateMoieties = false;
}
예제 #4
0
void CTauLeapMethod::initializeParameter()
{
  CCopasiParameter *pParm;

  assertParameter("Epsilon", CCopasiParameter::DOUBLE, (C_FLOAT64) 0.001);
  assertParameter("Max Internal Steps", CCopasiParameter::UINT, (unsigned C_INT32) 10000);
  assertParameter("Use Random Seed", CCopasiParameter::BOOL, false);
  assertParameter("Random Seed", CCopasiParameter::UINT, (unsigned C_INT32) 1);

  // Check whether we have a method with the old parameter names
  if ((pParm = getParameter("TAULEAP.Tau")) != NULL)
    {
      removeParameter("TAULEAP.Tau");

      if ((pParm = getParameter("TAULEAP.UseRandomSeed")) != NULL)
        {
          setValue("Use Random Seed", *pParm->getValue().pBOOL);
          removeParameter("TAULEAP.UseRandomSeed");
        }

      if ((pParm = getParameter("TAULEAP.RandomSeed")) != NULL)
        {
          setValue("Random Seed", *pParm->getValue().pUINT);
          removeParameter("TAULEAP.RandomSeed");
        }
    }
}
예제 #5
0
CTrajectoryTask::CTrajectoryTask(const CCopasiContainer * pParent):
  CCopasiTask(CCopasiTask::timeCourse, pParent),
  mTimeSeriesRequested(true),
  mTimeSeries(),
  mpTrajectoryProblem(NULL),
  mpSteadyState(NULL),
  mpTrajectoryMethod(NULL),
  mUpdateMoieties(false),
  mpCurrentState(NULL),
  mpCurrentTime(NULL),
  mOutputStartTime(0.0),
  mpLessOrEqual(&fle),
  mpLess(&fl)
{
  mpProblem = new CTrajectoryProblem(this);
  mpMethod = createMethod(CCopasiMethod::deterministic);
  this->add(mpMethod, true);

  CCopasiParameter * pParameter = mpMethod->getParameter("Integrate Reduced Model");

  if (pParameter != NULL)
    mUpdateMoieties = *pParameter->getValue().pBOOL;
  else
    mUpdateMoieties = false;
}
예제 #6
0
void CLyapWolfMethod::initializeParameter()
{
  assertParameter("Orthonormalization Interval", CCopasiParameter::UDOUBLE, (C_FLOAT64) 1.0);
  assertParameter("Overall time", CCopasiParameter::UDOUBLE, (C_FLOAT64) 1000.0);
  assertParameter("Relative Tolerance", CCopasiParameter::UDOUBLE, (C_FLOAT64) 1.0e-6);
  assertParameter("Absolute Tolerance", CCopasiParameter::UDOUBLE, (C_FLOAT64) 1.0e-12);
  assertParameter("Max Internal Steps", CCopasiParameter::UINT, (unsigned C_INT32) 10000);

  // Check whether we have an (obsolete) parameter "Use Default Absolute Tolerance"
  CCopasiParameter *pParm;

  if ((pParm = getParameter("Use Default Absolute Tolerance")) != NULL)
    {
      C_FLOAT64 NewValue;

      if (*pParm->getValue().pBOOL)
        {
          // The default
          NewValue = 1.e-12;
        }
      else
        {
          NewValue = *getValue("Absolute Tolerance").pUDOUBLE;
        }

      setValue("Absolute Tolerance", NewValue);
      removeParameter("Use Default Absolute Tolerance");
    }

  // These parameters are no longer supported.
  removeParameter("Adams Max Order");
  removeParameter("BDF Max Order");
}
예제 #7
0
파일: CFitItem.cpp 프로젝트: bmoreau/COPASI
bool CFitItem::elevateChildren()
{
  // The functionality of SavedValue is no handled more transparently
  // through the StartValue. Therefore, in case we encounter an old file
  // we need to copy its value.
  CCopasiParameter *pSavedValue = getParameter("SavedValue");

  if (pSavedValue)
    {
      setStartValue(*pSavedValue->getValue().pDOUBLE);
      removeParameter("SavedValue");
    }

  mpGrpAffectedExperiments =
    elevate<CCopasiParameterGroup, CCopasiParameterGroup>(mpGrpAffectedExperiments);

  if (!mpGrpAffectedExperiments) return false;

  mpGrpAffectedCrossValidations =
    elevate<CCopasiParameterGroup, CCopasiParameterGroup>(mpGrpAffectedCrossValidations);

  if (!mpGrpAffectedCrossValidations) return false;

  return true;
}
예제 #8
0
bool CTSSATask::initialize(const OutputFlag & of,
                           COutputHandler * pOutputHandler,
                           std::ostream * pOstream)
{
  assert(mpProblem && mpMethod);

  mpTSSAProblem = dynamic_cast<CTSSAProblem *>(mpProblem);
  assert(mpTSSAProblem);

  mpTSSAMethod = dynamic_cast<CTSSAMethod *>(mpMethod);
  assert(mpTSSAMethod);

  mpTSSAMethod->setProblem(mpTSSAProblem);

  bool success = mpMethod->isValidProblem(mpProblem);

  CCopasiParameter * pParameter = mpMethod->getParameter("Integrate Reduced Model");

  if (pParameter != NULL)
    mUpdateMoieties = *pParameter->getValue().pBOOL;
  else
    mUpdateMoieties = false;

  pdelete(mpCurrentState);
  mpCurrentState = new CState(mpTSSAProblem->getModel()->getState());
  mpCurrentTime = &mpCurrentState->getTime();

  // Handle the time series as a regular output.
  mTimeSeriesRequested = mpTSSAProblem->timeSeriesRequested();

  if (pOutputHandler != NULL)
    {
      if (mTimeSeriesRequested)
        {
          mTimeSeries.allocate(mpTSSAProblem->getStepNumber());
          pOutputHandler->addInterface(&mTimeSeries);
        }
      else
        {
          mTimeSeries.clear();
        }
    }

//NEW

  mpTSSAMethod->setModel(mpTSSAProblem->getModel());

  mpTSSAMethod->predifineAnnotation();

//

  if (!CCopasiTask::initialize(of, pOutputHandler, pOstream)) success = false;

  return success;
}
예제 #9
0
bool CCrossSectionTask::initialize(const OutputFlag & of,
                                   COutputHandler * pOutputHandler,
                                   std::ostream * pOstream)
{
  assert(mpProblem && mpMethod);

  mpCrossSectionProblem = dynamic_cast<CCrossSectionProblem *>(mpProblem);
  assert(mpCrossSectionProblem);

  mpTrajectoryMethod = dynamic_cast<CTrajectoryMethod *>(mpMethod);
  assert(mpTrajectoryMethod);

  mpTrajectoryMethod->setProblem(mpCrossSectionProblem);

  bool success = mpMethod->isValidProblem(mpProblem);

  CCopasiParameter * pParameter = mpMethod->getParameter("Integrate Reduced Model");

  if (pParameter != NULL)
    mUpdateMoieties = *pParameter->getValue().pBOOL;
  else
    mUpdateMoieties = false;

  pdelete(mpCurrentState);
  mpCurrentState = new CState(mpCrossSectionProblem->getModel()->getState());
  mpCurrentTime = &mpCurrentState->getTime();

  //init the ring buffer for the states
  mStatesRing.resize(RING_SIZE);
  mStatesRingCounter = 0;

  // Handle the time series as a regular output.
  mTimeSeriesRequested = true;//mpCrossSectionProblem->timeSeriesRequested();

  if ((pOutputHandler != NULL) &&
      mTimeSeriesRequested &&
      (of & CCopasiTask::TIME_SERIES))
    {
      mTimeSeries.allocate(20);
      pOutputHandler->addInterface(&mTimeSeries);
    }
  else
    {
      mTimeSeries.clear();
    }

  createEvent();

  if (!CCopasiTask::initialize(of, pOutputHandler, pOstream)) success = false;

  return success;
}
예제 #10
0
void CExperimentObjectMap::CDataColumn::initializeParameter()
{
  mpRole = (CExperiment::Type *)
           assertParameter("Role", CCopasiParameter::UINT, (unsigned C_INT32) CExperiment::ignore)->getValue().pUINT;

  CCopasiParameter * pParm = getParameter("Object CN");

  if (pParm != NULL)
    mpObjectCN = pParm->getValue().pCN;

  pParm = getParameter("Weight");

  if (pParm != NULL)
    mpScale = pParm->getValue().pUDOUBLE;

  elevateChildren();
}
예제 #11
0
// virtual
QModelIndex CQTaskMethodParametersDM::parent(const QModelIndex & index) const
{
  CCopasiParameter * pNode = nodeFromIndex(index);

  if (pNode == NULL || isMethod(pNode))
    {
      return QModelIndex();
    }

  if (isMethod(dynamic_cast<CCopasiParameter *>(pNode->getObjectParent())))
    {
      return QModelIndex();
    }

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

  return createIndex(getRow(pParent), 0, pParent);
}
예제 #12
0
CTSSATask::CTSSATask(const CCopasiContainer * pParent):
  CCopasiTask(CCopasiTask::tssAnalysis, pParent),
  mTimeSeriesRequested(true),
  mTimeSeries(),
  mpTSSAProblem(NULL),
  mpTSSAMethod(NULL),
  mpCurrentState(NULL),
  mpCurrentTime(NULL)
{
  mpProblem = new CTSSAProblem(this);
  mpMethod = createMethod(CCopasiMethod::tssILDM);
  this->add(mpMethod, true);

  CCopasiParameter * pParameter = mpMethod->getParameter("Integrate Reduced Model");

  if (pParameter != NULL)
    mUpdateMoieties = *pParameter->getValue().pBOOL;
  else
    mUpdateMoieties = false;
}
예제 #13
0
void CTrajectoryTask::load(CReadConfig & configBuffer)
{
  configBuffer.getVariable("Dynamics", "bool", &mScheduled,
                           CReadConfig::LOOP);

  pdelete(mpProblem);
  mpProblem = new CTrajectoryProblem(this);
  ((CTrajectoryProblem *) mpProblem)->load(configBuffer);

  pdelete(mpMethod);
  mpMethod = CTrajectoryMethod::createMethod();
  this->add(mpMethod, true);

  CCopasiParameter * pParameter = mpMethod->getParameter("Integrate Reduced Model");

  if (pParameter != NULL)
    mUpdateMoieties = *pParameter->getValue().pBOOL;

  ((CTrajectoryMethod *)mpMethod)->setProblem((CTrajectoryProblem *) mpProblem);
}
예제 #14
0
bool CCrossSectionTask::setMethodType(const int & type)
{
  CCopasiMethod::SubType Type = (CCopasiMethod::SubType) type;

  if (!isValidMethod(Type, ValidMethods)) return false;

  if (mpMethod->getSubType() == Type) return true;

  pdelete(mpMethod);
  mpMethod = createMethod(Type);
  this->add(mpMethod, true);

  CCopasiParameter * pParameter = mpMethod->getParameter("Integrate Reduced Model");

  if (pParameter != NULL)
    mUpdateMoieties = *pParameter->getValue().pBOOL;
  else
    mUpdateMoieties = false;

  return true;
}
예제 #15
0
// virtual
Qt::ItemFlags CQTaskMethodParametersDM::flags(const QModelIndex &index) const
{
  CCopasiParameter * pNode = nodeFromIndex(index);

  if (pNode == NULL)
    {
      return Qt::ItemIsEnabled;
    }

  if (index.column() == COL_VALUE)
    {
      if (pNode->getType() == CCopasiParameter::BOOL)
        return QAbstractItemModel::flags(index) | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;;

      if (pNode->hasValidValues())
        {
          emit signalCreateComboBox(index);
        }
      else if (pNode->getType() == CCopasiParameter::GROUP &&
               static_cast< CCopasiParameterGroup * >(pNode)->getElementTemplates().size() > 0)
        {
          emit signalCreatePushButton(index);
        }
      else
        {
          emit signalCloseEditor(index);
        }

      if (pNode->getType() == CCopasiParameter::CN)
        {
          return (QAbstractItemModel::flags(index) | Qt::ItemIsEnabled) & ~Qt::ItemIsEditable;
        }

      return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsEnabled;
    }

  return QAbstractItemModel::flags(index) & ~Qt::ItemIsEditable;
}
예제 #16
0
void CSteadyStateMethod::initializeParameter()
{
  CCopasiParameter *pParm;

  assertParameter("Resolution", CCopasiParameter::UDOUBLE, (C_FLOAT64) 1.0e-009);
  mpSSResolution = (C_FLOAT64*)getValue("Resolution").pUDOUBLE;
  mpDerivationResolution = (C_FLOAT64*)getValue("Resolution").pUDOUBLE;

  assertParameter("Derivation Factor", CCopasiParameter::UDOUBLE, (C_FLOAT64) 1.0e-003);
  mpDerivationFactor = (C_FLOAT64*)getValue("Derivation Factor").pUDOUBLE;

  // Check whether we have a method with the old parameter names
  if ((pParm = getParameter("Newton.DerivationFactor")) != NULL)
    {
      setValue("Derivation Factor", *pParm->getValue().pUDOUBLE);
      removeParameter("Newton.DerivationFactor");
    }

  if ((pParm = getParameter("Newton.Resolution")) != NULL)
    {
      setValue("Resolution", *pParm->getValue().pUDOUBLE);
      removeParameter("Newton.Resolution");
    }
}
void CFixLocalReactionParameters::changeModel()
{
  CCopasiParameter * pParameter = NULL;
  CModelValue * pModelValue = NULL;
  CReaction * pReaction = NULL;

  std::stringstream NameStream;
  std::stringstream Message;

  std::string OldCN;
  std::string NewCNBase;
  std::string NewCN;
  std::string Infix;

  std::string::size_type Start;

  // Loop through all changes.
  std::multimap< CCopasiParameter *, const CExpression * >::const_iterator itChanges = mChanges.begin();
  std::multimap< CCopasiParameter *, const CExpression * >::const_iterator endChanges = mChanges.end();

  for (; itChanges != endChanges; ++itChanges)
    {
      if (pParameter != itChanges->first)
        {
          // We have a new parameter
          pParameter = itChanges->first;
          OldCN = "<" + pParameter->getCN() + ",Reference=";

          // Create a global quantity of type FIXED.
          std::string Name = pParameter->getObjectName();
          pReaction = static_cast< CReaction * >(pParameter->getObjectAncestor("Reaction"));
          Name += "{" + pReaction->getObjectName() + "}";

          pModelValue = mpModel->createModelValue(Name, pParameter->getValue< C_FLOAT64 >());

          // In case the created name is not unique we append _n with increasing n
          // until we succeed;
          C_INT32 index = 0;

          while (pModelValue == NULL)
            {
              NameStream.str("");
              NameStream << Name << "_" << index++;
              pModelValue = mpModel->createModelValue(NameStream.str(), pParameter->getValue< C_FLOAT64 >());
            }

          NewCNBase = "<" + pModelValue->getCN() + ",Reference=";

          // If the parameter is actually used in the reaction
          // it is changed to the global quantity.
          if (pReaction->isLocalParameter(pParameter->getObjectName()))
            pReaction->setParameterMapping(pParameter->getObjectName(), pModelValue->getKey());

          Message << "  " << pParameter->getObjectName() << " in " << pReaction->getObjectName()
                  << " is replaced by " << pModelValue->getObjectName() << std::endl;
        }

      // We need to distinguish between initial and other expressions.
      if (itChanges->second->getObjectName().compare(0, 7, "Initial") == 0)
        NewCN = NewCNBase + "Initial";
      else
        NewCN = NewCNBase;

      // Replace the OldCN of the parameter with the NewCN of global quantity in all expressions.
      Infix = itChanges->second->getInfix();

      // There may be more than one occurrence.
      Start = 0;

      while ((Start = Infix.find(OldCN), Start) != std::string::npos)
        Infix.replace(Start, OldCN.length(), NewCN);

      const_cast< CExpression * >(itChanges->second)->setInfix(Infix);
    }

  CCopasiMessage(CCopasiMessage::WARNING, MCXML + 14, Message.str().c_str());
}
예제 #18
0
void CQPreferenceDialog::slotBtnOk()
{
  // We need to commit the changes
  unsigned C_INT32 newMaxFiles = 0;
  CConfigurationFile * configFile = CCopasiRootContainer::getConfiguration();

  QList< QTreeWidgetItem *> Items = mpTreeWidget->findItems("Max Last Visited Files", 0, 0);
  CCopasiParameter * pParameter = configFile->getRecentFiles().getParameter("MaxFiles");

  if (Items.size() > 0 &&
      pParameter != NULL)
    {
      newMaxFiles = Items[0]->text(COL_VALUE).toUInt();
      unsigned C_INT32 maxFiles = *pParameter->getValue().pUINT;

      if (newMaxFiles > 0 && newMaxFiles <= 20)
        pParameter->setValue(newMaxFiles);
      else
        {
          CQMessageBox::critical(this, "Incorrect Setting",
                                 "Max Last Visited Files should be a number between 1 and 20.",
                                 QMessageBox::Ok, QMessageBox::Ok);
          Items[0]->setText(COL_VALUE, QString::number(maxFiles));

          return;
        }
    }

  Items = mpTreeWidget->findItems("Max Last Visited SBML Files", 0, 0);
  pParameter = configFile->getRecentSBMLFiles().getParameter("MaxFiles");

  if (Items.size() > 0 &&
      pParameter != NULL)
    {
      newMaxFiles = Items[0]->text(COL_VALUE).toUInt();
      unsigned C_INT32 maxFiles = *pParameter->getValue().pUINT;

      if (newMaxFiles > 0 && newMaxFiles <= 20)
        pParameter->setValue(newMaxFiles);
      else
        {
          CQMessageBox::critical(this, "Incorrect Setting", "Max Last Visited SBML Files should be a number between 1 and 20.",
                                 QMessageBox::Ok, QMessageBox::Ok);

          Items[0]->setText(COL_VALUE, QString::number(maxFiles));

          return;
        }
    }

  Items = mpTreeWidget->findItems("Application for opening URLs", 0, 0);
  pParameter = configFile->getParameter("Application for opening URLs");

  if (Items.size() > 0 &&
      pParameter != NULL)
    {

      if (Items[0]->text(COL_VALUE) != FROM_UTF8(*pParameter->getValue().pSTRING))
        pParameter->setValue(std::string(TO_UTF8(Items[0]->text(COL_VALUE))));
    }

  Items = mpTreeWidget->findItems("Validate Units", 0, 0);
  pParameter = configFile->getParameter("Validate Units");

  if (Items.size() > 0 &&
      pParameter != NULL)
    {
      pParameter->setValue(Items[0]->text(COL_VALUE).toUpper() == "YES");
    }

  Items = mpTreeWidget->findItems("Use OpenGL", 0, 0);
  pParameter = configFile->getParameter("Use OpenGL");

  if (Items.size() > 0 &&
      pParameter != NULL)
    {
      pParameter->setValue(Items[0]->text(COL_VALUE).toUpper() == "YES");
    }

  Items = mpTreeWidget->findItems("Use Advanced Editing", 0, 0);
  pParameter = configFile->getParameter("Use Advanced Editing");

  if (Items.size() > 0 &&
      pParameter != NULL)
    {
      pParameter->setValue(Items[0]->text(COL_VALUE).toUpper() == "YES");
    }

  done(1);
}
예제 #19
0
// virtual
bool COPASIHandler::processEnd(const XML_Char * pszName)
{
  bool finished = false;

  switch (mCurrentElement.first)
    {
      case COPASI:
      {
        // We need to handle the unmapped parameters of type key.
        std::vector< std::string >::iterator it = mpData->UnmappedKeyParameters.begin();
        std::vector< std::string >::iterator end = mpData->UnmappedKeyParameters.end();

        for (; it != end; ++it)
          {
            CCopasiParameter * pParameter =
              dynamic_cast< CCopasiParameter * >(CCopasiRootContainer::getKeyFactory()->get(*it));

            if (pParameter != NULL &&
                pParameter->getType() == CCopasiParameter::KEY)
              {
                CCopasiObject * pObject =
                  mpData->mKeyMap.get(pParameter->getValue< std::string >());

                if (pObject != NULL)
                  pParameter->setValue(pObject->getKey());
                else
                  pParameter->setValue(std::string(""));
              }
          }

        // We need to remove the no longer needed expression "Objective Function" from the function list.
        if (mpData->pFunctionList != NULL &&
            mpData->pFunctionList->getIndex("Objective Function") != C_INVALID_INDEX)
          {
            mpData->pFunctionList->remove("Objective Function");
          }
      }

      finished = true;
      break;

      case ParameterGroup:
        finished = true;
        break;

      case ListOfFunctions:
      case Model:
      case ListOfTasks:
      case ListOfReports:
      case ListOfPlots:
      case ListOfLayouts:
      case SBMLReference:
      case ListOfUnitDefinitions:
        break;

      case GUI:
        if (mpData->pGUI == NULL)
          {
            CCopasiMessage::getLastMessage();
          }

        break;

      default:
        CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 2,
                       mpParser->getCurrentLineNumber(), mpParser->getCurrentColumnNumber(), pszName);
        break;
    }

  return finished;
}
예제 #20
0
void CQPreferenceDialog::init()
{
  mpTreeWidget->setColumnWidth(COL_NAME, 150);
  mpTreeWidget->setColumnWidth(COL_VALUE, 100);

  CConfigurationFile * configFile = CCopasiRootContainer::getConfiguration();

  CCopasiParameter * pParameter = configFile->getRecentFiles().getParameter("MaxFiles");

  if (pParameter != NULL)
    {
      QStringList Values;
      Values.append("Max Last Visited Files");
      Values.append(QString::number(*pParameter->getValue().pUINT));

      new QTreeWidgetItem(mpTreeWidget, Values);
    }

  pParameter = configFile->getRecentSBMLFiles().getParameter("MaxFiles");

  if (pParameter != NULL)
    {
      QStringList Values;
      Values.append("Max Last Visited SBML Files");
      Values.append(QString::number(*pParameter->getValue().pUINT));

      new QTreeWidgetItem(mpTreeWidget, Values);
    }

  pParameter = configFile->getParameter("Application for opening URLs");

  if (pParameter != NULL)
    {
      QStringList Values;
      Values.append("Application for opening URLs");
      Values.append(FROM_UTF8(*pParameter->getValue().pSTRING));

      new QTreeWidgetItem(mpTreeWidget, Values);
    }

  pParameter = configFile->getParameter("Validate Units");

  if (pParameter != NULL)
    {
      QStringList Values;
      Values.append("Validate Units");
      Values.append((*pParameter->getValue().pBOOL ? "YES" : "NO"));
      new QTreeWidgetItem(mpTreeWidget, Values);
    }

  pParameter = configFile->getParameter("Use OpenGL");

  if (pParameter != NULL)
    {
      QStringList Values;
      Values.append("Use OpenGL");
      Values.append((*pParameter->getValue().pBOOL ? "YES" : "NO"));
      new QTreeWidgetItem(mpTreeWidget, Values);
    }

  pParameter = configFile->getParameter("Use Advanced Editing");

  if (pParameter != NULL)
    {
      QStringList Values;
      Values.append("Use Advanced Editing");
      Values.append((*pParameter->getValue().pBOOL ? "YES" : "NO"));
      new QTreeWidgetItem(mpTreeWidget, Values);
    }
}
예제 #21
0
int main(int argc, char** argv)
{
  // initialize the backend library
  CCopasiRootContainer::init(argc, argv);
  assert(CCopasiRootContainer::getRoot() != NULL);
  // create a new datamodel
  CCopasiDataModel* pDataModel = CCopasiRootContainer::addDatamodel();
  assert(CCopasiRootContainer::getDatamodelList()->size() == 1);

  // the only argument to the main routine should be the name of an SBML file
  if (argc == 2)
    {
      std::string filename = argv[1];

      try
        {
          // load the model without progress report
          pDataModel->importSBML(filename, NULL);
        }
      catch (...)
        {
          std::cerr << "Error while importing the model from file named \"" << filename << "\"." << std::endl;
          CCopasiRootContainer::destroy();
          return 1;
        }

      CModel* pModel = pDataModel->getModel();
      assert(pModel != NULL);
      // create a report with the correct filename and all the species against
      // time.
      CReportDefinitionVector* pReports = pDataModel->getReportDefinitionList();
      // create a new report definition object
      CReportDefinition* pReport = pReports->createReportDefinition("Report", "Output for timecourse");
      // set the task type for the report definition to timecourse
      pReport->setTaskType(CTaskEnum::timeCourse);
      // we don't want a table
      pReport->setIsTable(false);
      // the entries in the output should be seperated by a ", "
      pReport->setSeparator(", ");

      // we need a handle to the header and the body
      // the header will display the ids of the metabolites and "time" for
      // the first column
      // the body will contain the actual timecourse data
      std::vector<CRegisteredObjectName>* pHeader = pReport->getHeaderAddr();
      std::vector<CRegisteredObjectName>* pBody = pReport->getBodyAddr();
      pBody->push_back(CCopasiObjectName(pDataModel->getModel()->getCN() + ",Reference=Time"));
      pBody->push_back(CRegisteredObjectName(pReport->getSeparator().getCN()));
      pHeader->push_back(CCopasiStaticString("time").getCN());
      pHeader->push_back(pReport->getSeparator().getCN());

      size_t i, iMax = pModel->getMetabolites().size();

      for (i = 0; i < iMax; ++i)
        {
          CMetab* pMetab = &pModel->getMetabolites()[i];
          assert(pMetab != NULL);

          // we don't want output for FIXED metabolites right now
          if (pMetab->getStatus() != CModelEntity::FIXED)
            {
              // we want the concentration oin the output
              // alternatively, we could use "Reference=Amount" to get the
              // particle number
              pBody->push_back(pMetab->getObject(CCopasiObjectName("Reference=Concentration"))->getCN());
              // after each entry, we need a seperator
              pBody->push_back(pReport->getSeparator().getCN());

              // add the corresponding id to the header
              pHeader->push_back(CCopasiStaticString(pMetab->getSBMLId()).getCN());
              // and a seperator
              pHeader->push_back(pReport->getSeparator().getCN());
            }
        }

      if (iMax > 0)
        {
          // delete the last separator
          // since we don't need one after the last element on each line
          if ((*pBody->rbegin()) == pReport->getSeparator().getCN())
            {
              pBody->erase(--pBody->end());
            }

          if ((*pHeader->rbegin()) == pReport->getSeparator().getCN())
            {
              pHeader->erase(--pHeader->end());
            }
        }

      // get the task list
      CCopasiVectorN< CCopasiTask > & TaskList = * pDataModel->getTaskList();

      // get the trajectory task object
      CTrajectoryTask* pTrajectoryTask = dynamic_cast<CTrajectoryTask*>(&TaskList["Time-Course"]);

      // if there isn't one
      if (pTrajectoryTask == NULL)
        {
          // remove any existing trajectory task just to be sure since in
          // theory only the cast might have failed above
          TaskList.remove("Time-Course");

          // create a new one
          pTrajectoryTask = new CTrajectoryTask(& TaskList);

          // add the new time course task to the task list
          TaskList.add(pTrajectoryTask, true);
        }

      // run a deterministic time course
      pTrajectoryTask->setMethodType(CTaskEnum::deterministic);

      // Activate the task so that it will be run when the model is saved
      // and passed to CopasiSE
      pTrajectoryTask->setScheduled(true);

      // set the report for the task
      pTrajectoryTask->getReport().setReportDefinition(pReport);
      // set the output filename
      pTrajectoryTask->getReport().setTarget("example3.txt");
      // don't append output if the file exists, but overwrite the file
      pTrajectoryTask->getReport().setAppend(false);

      // get the problem for the task to set some parameters
      CTrajectoryProblem* pProblem = dynamic_cast<CTrajectoryProblem*>(pTrajectoryTask->getProblem());

      // simulate 100 steps
      pProblem->setStepNumber(100);
      // start at time 0
      pDataModel->getModel()->setInitialTime(0.0);
      // simulate a duration of 10 time units
      pProblem->setDuration(10);
      // tell the problem to actually generate time series data
      pProblem->setTimeSeriesRequested(true);

      // set some parameters for the LSODA method through the method
      CTrajectoryMethod* pMethod = dynamic_cast<CTrajectoryMethod*>(pTrajectoryTask->getMethod());

      CCopasiParameter* pParameter = pMethod->getParameter("Absolute Tolerance");
      assert(pParameter != NULL);
      pParameter->setValue(1.0e-12);

      try
        {
          // initialize the trajectory task
          // we want complete output (HEADER, BODY and FOOTER)
          //
          // The output has to be set to OUTPUT_UI, otherwise the time series will not be
          // kept in memory and some of the assert further down will fail
          // If it is OK that the output is only written to file, the output type can
          // be set to OUTPUT_SE
          pTrajectoryTask->initialize(CCopasiTask::OUTPUT_UI, pDataModel, NULL);
          // now we run the actual trajectory
          pTrajectoryTask->process(true);
        }
      catch (...)
        {
          std::cerr << "Error. Running the time course simulation failed." << std::endl;

          // check if there are additional error messages
          if (CCopasiMessage::size() > 0)
            {
              // print the messages in chronological order
              std::cerr << CCopasiMessage::getAllMessageText(true);
            }

          CCopasiRootContainer::destroy();
          return 1;
        }

      // restore the state of the trajectory
      pTrajectoryTask->restore();

      // look at the timeseries
      const CTimeSeries* pTimeSeries = &pTrajectoryTask->getTimeSeries();
      // we simulated 100 steps, including the initial state, this should be
      // 101 step in the timeseries
      assert(pTimeSeries->getRecordedSteps() == 101);
      std::cout << "The time series consists of " << pTimeSeries->getRecordedSteps() << "." << std::endl;
      std::cout << "Each step contains " << pTimeSeries->getNumVariables() << " variables." << std::endl;
      std::cout << "The final state is: " << std::endl;
      iMax = pTimeSeries->getNumVariables();
      size_t lastIndex = pTimeSeries->getRecordedSteps() - 1;

      for (i = 0; i < iMax; ++i)
        {
          // here we get the particle number (at least for the species)
          // the unit of the other variables may not be particle numbers
          // the concentration data can be acquired with getConcentrationData
          std::cout << pTimeSeries->getTitle(i) << ": " << pTimeSeries->getData(lastIndex, i) << std::endl;
        }
    }
  else
    {
      std::cerr << "Usage: example3 SBMLFILE" << std::endl;
      CCopasiRootContainer::destroy();
      return 1;
    }

  // clean up the library
  CCopasiRootContainer::destroy();
}
예제 #22
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;
}
예제 #23
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;
}
예제 #24
0
void CLsodaMethod::initializeParameter()
{
  CCopasiParameter *pParm;

  mpReducedModel =
    assertParameter("Integrate Reduced Model", CCopasiParameter::BOOL, (bool) false)->getValue().pBOOL;
  mpRelativeTolerance =
    assertParameter("Relative Tolerance", CCopasiParameter::UDOUBLE, (C_FLOAT64) 1.0e-6)->getValue().pUDOUBLE;
  mpAbsoluteTolerance =
    assertParameter("Absolute Tolerance", CCopasiParameter::UDOUBLE, (C_FLOAT64) 1.0e-12)->getValue().pUDOUBLE;
  mpMaxInternalSteps =
    assertParameter("Max Internal Steps", CCopasiParameter::UINT, (unsigned C_INT32) 10000)->getValue().pUINT;

  // Check whether we have a method with the old parameter names
  if ((pParm = getParameter("LSODA.RelativeTolerance")) != NULL)
    {
      *mpRelativeTolerance = *pParm->getValue().pUDOUBLE;
      removeParameter("LSODA.RelativeTolerance");

      if ((pParm = getParameter("LSODA.AbsoluteTolerance")) != NULL)
        {
          *mpAbsoluteTolerance = *pParm->getValue().pUDOUBLE;
          removeParameter("LSODA.AbsoluteTolerance");
        }

      if ((pParm = getParameter("LSODA.AdamsMaxOrder")) != NULL)
        {
          removeParameter("LSODA.AdamsMaxOrder");
        }

      if ((pParm = getParameter("LSODA.BDFMaxOrder")) != NULL)
        {
          removeParameter("LSODA.BDFMaxOrder");
        }

      if ((pParm = getParameter("LSODA.MaxStepsInternal")) != NULL)
        {
          *mpMaxInternalSteps = *pParm->getValue().pUINT;
          removeParameter("LSODA.MaxStepsInternal");
        }
    }

  // Check whether we have a method with "Use Default Absolute Tolerance"
  if ((pParm = getParameter("Use Default Absolute Tolerance")) != NULL)
    {
      C_FLOAT64 NewValue;

      if (*pParm->getValue().pBOOL)
        {
          // The default
          NewValue = 1.e-12;
        }
      else
        {
          C_FLOAT64 OldValue = *mpAbsoluteTolerance;
          CCopasiDataModel* pDataModel = getObjectDataModel();
          assert(pDataModel != NULL);
          CModel * pModel = pDataModel->getModel();

          if (pModel == NULL)
            // The default
            NewValue = 1.e-12;
          else
            {
              const CCopasiVectorNS< CCompartment > & Compartment = pModel->getCompartments();
              unsigned C_INT32 i, imax;
              C_FLOAT64 Volume = DBL_MAX;

              for (i = 0, imax = Compartment.size(); i < imax; i++)
                if (Compartment[i]->getValue() < Volume)
                  Volume = Compartment[i]->getValue();

              if (Volume == DBL_MAX)
                // The default
                NewValue = 1.e-12;
              else
                // Invert the scaling as best as we can
                NewValue = OldValue / (Volume * pModel->getQuantity2NumberFactor());
            }
        }

      *mpAbsoluteTolerance = NewValue;
      removeParameter("Use Default Absolute Tolerance");
    }

  // These parameters are no longer supported.
  removeParameter("Adams Max Order");
  removeParameter("BDF Max Order");
}
예제 #25
0
std::string CODEExporterC::KineticFunction2ODEmember(const CReaction *reac)
{
  std::ostringstream equation;

  if (reac->getFunction()->getType() != CEvaluationTree::MassAction)
    {
      const CFunctionParameters & params = reac->getFunctionParameters();
      size_t k, params_size = params.size();
      const std::vector<std::vector<std::string> > & keyMap = reac->getParameterMappings();
      std::string name;
      equation << NameMap[reac->getFunction()->getKey()] << "(";

      for (k = 0; k < params_size; ++k)
        {

          CFunctionParameter::Role role = params[k]->getUsage();

          CCopasiObject * obj = CCopasiRootContainer::getKeyFactory()->get(keyMap[k][0]);

          if ((role == CFunctionParameter::SUBSTRATE)
              || (role == CFunctionParameter::PRODUCT)
              || (role == CFunctionParameter::MODIFIER))
            {
              if (obj)
                name = NameMap[obj->getKey()];
              else
                name = "unknown";
            }

          if (role == CFunctionParameter::PARAMETER)
            {
              if (!(reac->isLocalParameter(k)))
                {
                  CModelValue* modval;
                  modval = dynamic_cast< CModelValue * >(obj);
                  name = NameMap[modval->getKey()];
                }
              else
                {
                  CCopasiParameter* param;
                  param = dynamic_cast< CCopasiParameter * >(obj);
                  name = NameMap[param->getKey()];
                }
            }

          if (role == CFunctionParameter::VOLUME)
            {
              CCompartment* comp;
              comp = dynamic_cast< CCompartment * >(obj);
              name = NameMap[comp->getKey()];
            }

          if (role == CFunctionParameter::TIME)
            {
              name = "T";
            }

          if (name.empty())
            {
              std::string message = "Could not export C code, since one of the arguments could not be resolved. Please consider filing a bug with the COPASI tracker: http://www.copasi.org/tracker";
              CCopasiMessage(CCopasiMessage::EXCEPTION, message.c_str());
            }

          equation << name;

          if (k != params_size - 1)
            equation << ", ";
        }

      equation << ")";
    }
  else
    {
      const CCopasiVector<CChemEqElement> & substrs = reac->getChemEq().getSubstrates();
      const CCopasiVector<CChemEqElement> & prods = reac->getChemEq().getProducts();
      const std::vector<std::vector<std::string> > & keyMap = reac->getParameterMappings();
      CCopasiObject * obj;

      size_t substrs_size = substrs.size(), prods_size = prods.size();
      size_t k, m, mult;

      const CChemEqElement* substr;
      const CChemEqElement* prod;

      const CMassAction & cMassAction = *static_cast<const CMassAction*>(reac->getFunction());

      equation << "(";

      obj = CCopasiRootContainer::getKeyFactory()->get(keyMap[0][0]);

      if (!(reac->isLocalParameter(0)))
        {
          CModelValue* modval;
          modval = dynamic_cast< CModelValue * >(obj);

          equation << NameMap[modval->getKey()];
        }
      else
        {
          CCopasiParameter* param;
          param = dynamic_cast< CCopasiParameter * >(obj);

          equation << NameMap[param->getKey()];
        }

      for (k = 0; k < substrs_size; ++k)
        {
          substr = &substrs[k];
          mult = (size_t) substr->getMultiplicity();

          assert(substr->getMetabolite());
          equation << " * " << NameMap[substr->getMetabolite()->getKey()];

          if (mult > 1)
            for (m = 1; m < mult; ++m)
              equation << " * " << NameMap[substr->getMetabolite()->getKey()];
        }

      if (cMassAction.isReversible() == TriTrue)
        {
          equation << " - ";

          obj = CCopasiRootContainer::getKeyFactory()->get(keyMap[2][0]);

          if (!(reac->isLocalParameter(2)))
            {
              CModelValue* modval;
              modval = dynamic_cast< CModelValue * >(obj);

              equation << NameMap[modval->getKey()];
            }
          else
            {
              CCopasiParameter* param;
              param = dynamic_cast< CCopasiParameter * >(obj);

              equation << NameMap[param->getKey()];
            }

          for (k = 0; k < prods_size; ++k)
            {
              prod = &prods[k];
              mult = (size_t) prod->getMultiplicity();

              assert(prod->getMetabolite());
              equation << " * " << NameMap[prod->getMetabolite()->getKey()];

              if (mult > 1)
                for (m = 1; m < mult; ++m)
                  equation << " * " << NameMap[prod->getMetabolite()->getKey()];
            }
        }

      equation << ") ";
    }

  return equation.str();
}
예제 #26
0
bool CTrajectoryTask::initialize(const OutputFlag & of,
                                 COutputHandler * pOutputHandler,
                                 std::ostream * pOstream)
{
  assert(mpProblem && mpMethod);

  mpTrajectoryProblem = dynamic_cast<CTrajectoryProblem *>(mpProblem);
  assert(mpTrajectoryProblem);

  mpTrajectoryMethod = dynamic_cast<CTrajectoryMethod *>(mpMethod);
  assert(mpTrajectoryMethod);

  mpTrajectoryMethod->setProblem(mpTrajectoryProblem);

  bool success = mpMethod->isValidProblem(mpProblem);

  CCopasiParameter * pParameter = mpMethod->getParameter("Integrate Reduced Model");

  if (pParameter != NULL)
    mUpdateMoieties = *pParameter->getValue().pBOOL;
  else
    mUpdateMoieties = false;

  pdelete(mpCurrentState);
  mpCurrentState = new CState(mpTrajectoryProblem->getModel()->getState());
  mpCurrentTime = &mpCurrentState->getTime();

  //mpOutputStartTime = & mpTrajectoryProblem->getOutputStartTime();

  // Handle the time series as a regular output.
  mTimeSeriesRequested = mpTrajectoryProblem->timeSeriesRequested();

  if ((pOutputHandler != NULL) &&
      mTimeSeriesRequested &&
      (of & CCopasiTask::TIME_SERIES))
    {
      mTimeSeries.allocate(mpTrajectoryProblem->getStepNumber());
      pOutputHandler->addInterface(&mTimeSeries);
    }
  else
    {
      mTimeSeries.clear();
    }

  mpTrajectoryProblem->getModel()->getMathModel()->getProcessQueue().setContinueSimultaneousEvents(mpTrajectoryProblem->getContinueSimultaneousEvents());

  if (mpTrajectoryProblem->getStartInSteadyState())
    {
      mpSteadyState =
        dynamic_cast<CSteadyStateTask *>((*mpTrajectoryProblem->getObjectDataModel()->getTaskList())["Steady-State"]);

      if (mpSteadyState == NULL) fatalError();

      mpSteadyState->initialize(CCopasiTask::NO_OUTPUT, NULL, NULL);
    }
  else
    {
      mpSteadyState = NULL;
    }

  if (!CCopasiTask::initialize(of, pOutputHandler, pOstream)) success = false;

  return success;
}