24 #include <sedml/SedTypes.h>
25 #include <sbml/math/FormulaFormatter.h>
78 x < 0.0 ? -floor(-x + 0.5) : floor(x + 0.5);
95 std::map<CCopasiObject*, SedBase*>& copasi2sedmlmap)
98 switch (sedmlsim->getTypeCode())
100 case SEDML_SIMULATION_UNIFORMTIMECOURSE:
107 SedUniformTimeCourse* tc =
static_cast<SedUniformTimeCourse*
>(sedmlsim);
109 tProblem->
setDuration(tc->getOutputEndTime() - tc->getOutputStartTime());
114 if (tc->isSetAlgorithm())
116 const SedAlgorithm* alg = tc->getAlgorithm();
118 if (alg->isSetKisaoID())
130 case SEDML_SIMULATION_ONESTEP:
137 SedOneStep* step =
static_cast<SedOneStep*
>(sedmlsim);
147 case SEDML_SIMULATION_STEADYSTATE:
168 if (task == NULL || task->getSedDocument() == NULL)
return false;
170 const SedDocument* doc = task->getSedDocument();
172 if (task->isSetSimulationReference())
174 const SedSimulation* sim = doc->getSimulation(task->getSimulationReference());
177 sim->getTypeCode() == SEDML_SIMULATION_UNIFORMTIMECOURSE))
187 if (task == NULL || task->getSedDocument() == NULL)
return false;
189 const SedDocument* doc = task->getSedDocument();
191 if (task->isSetSimulationReference())
193 const SedSimulation* sim = doc->getSimulation(task->getSimulationReference());
196 sim->getTypeCode() == SEDML_SIMULATION_STEADYSTATE ||
197 sim->getTypeCode() == SEDML_SIMULATION_ONESTEP ||
198 sim->getTypeCode() == SEDML_SIMULATION_UNIFORMTIMECOURSE))
207 if (task == NULL || task->getSedDocument() == NULL)
return false;
209 const SedDocument* doc = task->getSedDocument();
211 if (task->isSetSimulationReference())
213 const SedSimulation* sim = doc->getSimulation(task->getSimulationReference());
216 sim->getTypeCode() == SEDML_SIMULATION_STEADYSTATE ||
217 sim->getTypeCode() == SEDML_SIMULATION_ONESTEP ||
218 sim->getTypeCode() == SEDML_SIMULATION_UNIFORMTIMECOURSE))
222 for (
size_t i = 0; i < task->getNumSubTasks(); ++i)
224 const SedSubTask* subTask = task->getSubTask(i);
225 const SedTask* t = doc->getTask(subTask->getTask());
227 if (
isScan(t))
return true;
235 SedDocument *pSEDMLDocument,
236 std::map<CCopasiObject*, SedBase*>& copasi2sedmlmap)
238 size_t i, numOutput = pSEDMLDocument->getNumOutputs();
244 for (i = 0; i < numOutput; ++i)
246 SedOutput* current = pSEDMLDocument->getOutput(i);
248 switch (current->getTypeCode())
250 case SEDML_OUTPUT_REPORT:
252 SedReport* r =
static_cast<SedReport*
>(current);
253 std::string name = current->isSetName() ? current->getName() : current->getId();
268 std::vector<CRegisteredObjectName>* pHeader = def->
getHeaderAddr();
269 std::vector<CRegisteredObjectName>* pBody = def->
getBodyAddr();
271 bool isTimeCourse =
false;
272 bool isScanTask =
false;
274 for (
size_t i = 0; i < r->getNumDataSets(); ++i)
276 SedDataSet* ds = r->getDataSet(i);
277 const SedDataGenerator* generator = pSEDMLDocument->getDataGenerator(ds->getDataReference());
280 if (generator == NULL || tmp == NULL)
continue;
282 std::string title = ds->isSetLabel() ? ds->getLabel() : generator->isSetName() ? generator->getName() : ds->getId();
287 pBody->push_back(tmp->
getCN());
290 if (!isTimeCourse && !isScanTask)
291 for (
size_t j = 0; j < generator->getNumVariables(); ++j)
293 const SedTask* t =
mpSEDMLDocument->getTask(generator->getVariable(j)->getTaskReference());
295 if (t == NULL)
continue;
297 isScanTask = t->getTypeCode() == SEDML_TASK_REPEATEDTASK &&
isScan((
const SedRepeatedTask*)t);
298 isTimeCourse =
isTC(t);
317 case SEDML_OUTPUT_PLOT2D:
319 SedPlot2D* p =
static_cast<SedPlot2D*
>(current);
320 std::string name = current->isSetName() ? current->getName() :
337 for (
unsigned int ic = 0; ic < p->getNumCurves(); ++ic)
339 SedCurve *curve = p->getCurve(ic);
341 std::string xDataReference = curve->getXDataReference();
342 std::string yDataReference = curve->getYDataReference();
344 const SedDataGenerator* xGenerator = pSEDMLDocument->getDataGenerator(xDataReference);
345 const SedDataGenerator* yGenerator = pSEDMLDocument->getDataGenerator(yDataReference);
351 if (tmpX != NULL && tmpY != NULL)
354 std::string itemTitle;
356 if (curve->isSetName())
357 itemTitle = curve->getName();
358 else if (yGenerator != NULL && yGenerator->isSetName())
359 itemTitle = yGenerator->getName();
364 plItem->
setValue(
"Line width", 2.0);
369 logX = logX || (curve->isSetLogX() && curve->getLogX());
370 logY = logY || (curve->isSetLogY() && curve->getLogY());
390 SBMLDocument *& pSBMLDocument,
391 SedDocument*& pSedDocument,
392 std::map<CCopasiObject*, SedBase*>& copasi2sedmlmap,
393 std::map<CCopasiObject*, SBase*>& copasi2sbmlmap,
406 std::ostringstream stringStream;
424 pDataModel->setSEDMLFileName(filename);
426 return this->
parseSEDML(stringStream.str(), pImportHandler,
427 pSBMLDocument, pSedDocument, copasi2sedmlmap, copasi2sbmlmap, prLol, plotList, pDataModel);
437 SBMLDocument *& pSBMLDocument,
438 SedDocument *& pSEDMLDocument,
439 std::map<CCopasiObject*, SedBase*>& copasi2sedmlmap,
440 std::map<CCopasiObject*, SBase*>& copasi2sbmlmap,
465 unsigned C_INT32 step = 0, totalSteps = 0;
497 for (i = 0; (i < iMax) && (fatal == -1); ++i)
503 switch (pSEDMLError->getSeverity())
506 case LIBSEDML_SEV_WARNING:
510 if (pSEDMLError->getErrorId() == SedInvalidNamespaceOnSed)
524 pSEDMLError->getErrorId(), pSEDMLError->getLine(),
525 pSEDMLError->getColumn(),
526 pSEDMLError->getMessage().c_str());
529 case LIBSEDML_SEV_ERROR:
538 pSEDMLError->getErrorId(), pSEDMLError->getLine(),
539 pSEDMLError->getColumn(),
540 pSEDMLError->getMessage().c_str());
543 case LIBSEDML_SEV_FATAL:
548 if (pSEDMLError->getErrorId() == 10804)
554 pSEDMLError->getErrorId(), pSEDMLError->getLine(),
555 pSEDMLError->getColumn(),
556 pSEDMLError->getMessage().c_str());
571 pSEDMLError->getLine(), pSEDMLError->getColumn(),
572 pSEDMLError->getMessage().c_str());
592 this->
mLevel = pSEDMLDocument->getLevel();
595 this->
mVersion = pSEDMLDocument->getVersion();
621 if (current->isSetModelReference() && current->getModelReference() != this->
mImportedModel)
624 switch (current->getTypeCode())
628 SedSimulation* sedmlsim =
634 case SEDML_TASK_REPEATEDTASK:
636 SedRepeatedTask *repeat =
static_cast<SedRepeatedTask*
>(current);
637 SedRange* range = repeat->getRange(repeat->getRangeId());
639 if (range == NULL || range->getTypeCode() != SEDML_RANGE_UNIFORMRANGE)
645 SedUniformRange* urange =
static_cast<SedUniformRange*
>(range);
650 if (urange != NULL && repeat->getNumTaskChanges() == 0)
656 for (
unsigned int j = 0; j < repeat->getNumTaskChanges(); ++j)
658 SedSetValue* sv = repeat->getTaskChange(j);
660 if (SBML_formulaToString(sv->getMath()) != sv->getRange())
663 "This version of COPASI only supports setValue elements that apply range values.");
666 std::string target = sv->getTarget();
679 (!urange->isSetType() || urange->getType().empty() || urange->getType() ==
"linear") ?
false
684 if (repeat->getNumSubTasks() != 1)
692 SedSubTask* subTask = repeat->getSubTask(0);
694 if (!subTask->isSetTask())
702 if (actualSubTask == NULL || !actualSubTask->isSetSimulationReference())
708 int code =
mpSEDMLDocument->getSimulation(actualSubTask->getSimulationReference())->getTypeCode();
710 if (code == SEDML_SIMULATION_STEADYSTATE)
715 else if (code == SEDML_SIMULATION_ONESTEP || code == SEDML_SIMULATION_UNIFORMTIMECOURSE)
725 const char* name = SedTypeCode_toString(current->getTypeCode());
727 "Encountered unsupported Task type '%s'. This task cannot be imported in COPASI",
728 name != NULL ? name :
"unknown");
733 std::map<CReportDefinition*, std::string>::const_iterator it =
mReportMap.begin();
748 if (modelParameter == NULL || obj == NULL)
return false;
761 for (
unsigned int i = 0; i < numChilren; ++i)
776 while (it != set.
end())
795 std::stringstream str;
806 SBMLDocument *& pSBMLDocument,
807 std::map<CCopasiObject*, SBase*>& copasi2sbmlmap,
811 std::string SBMLFileName, fileContent;
822 CCopasiMessage(
CCopasiMessage::WARNING,
"COAPSI currently only supports the import of SED-ML models, that involve one model only. Only the simulations for the first model will be imported");
825 std::string modelSource =
"";
826 std::string modelId =
"";
827 SedModel* sedmlModel = NULL;
829 for (ii = 0; ii < iiMax; ++ii)
835 if (sedmlModel->getLanguage().find(
"urn:sedml:language:sbml") == std::string::npos)
837 "Sorry currently, only SBML models are supported.");
839 if (sedmlModel->getSource() != modelId)
841 modelId = sedmlModel->getId();
843 if ((sedmlModel->getListOfChanges()->size()) > 0)
845 "changing model entities. Only value changes are imported into the model.");
847 modelSource = sedmlModel->getSource();
852 assert(modelSource !=
"");
858 std::string FileName;
861 FileName = modelSource;
876 std::ostringstream sbmlStringStream;
881 sbmlStringStream << c;
897 std::map<CCopasiObject*, SBase*> Copasi2SBMLMap;
926 if (sedmlModel != NULL && sedmlModel->getNumChanges() > 0)
929 bool valueChanged =
false;
931 for (
unsigned int i = 0; i < sedmlModel->getNumChanges(); ++i)
933 SedChangeAttribute* change =
dynamic_cast<SedChangeAttribute*
>(sedmlModel->getChange(i));
935 if (change == NULL)
continue;
937 const std::string& target = change->getTarget();
938 const std::string& newValue = change->getNewValue();
954 mIgnoredSEDMLMessages(),
955 mIncompleteModel(false),
961 mpSEDMLDocument(NULL),
962 mpImportHandler(NULL),
967 mUsedSEDMLIdsPopulated(false),
void setSubtask(CCopasiTask::Type type)
Header file of class CExpression.
CCopasiDataModel * getObjectDataModel()
void setImportCOPASIMIRIAM(bool import)
std::set< unsigned int > mIgnoredSEDMLMessages
const CModelParameterSet & getModelParameterSet() const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
bool setSBMLFileName(const std::string &fileName)
Header file of class CModelEntity and CModelValue.
std::string mArchiveFileName
void setScheduled(const bool &scheduled)
std::vector< CModelParameter * >::iterator iterator
bool mUsedSEDMLIdsPopulated
void readListOfPlotsFromSedMLOutput(COutputDefinitionVector *pPlotList, CModel *pModel, SedDocument *pSedDocument, std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap)
CCopasiProblem * getProblem()
CModel * readSEDML(std::string filename, CProcessReport *pImportHandler, SBMLDocument *&pSBMLDocument, SedDocument *&pSedDocument, std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, COutputDefinitionVector *&plotList, CCopasiDataModel *pDataModel)
virtual CCopasiObjectName getCN() const
void setContinueSimultaneousEvents(const bool &continueSimultaneousEvents)
virtual const CModelParameter * getChild(const size_t &index) const
virtual bool setName(const std::string &name)
const CCopasiReportSeparator & getSeparator() const
void setImportHandler(CProcessReport *pHandler)
void addChannel(const CPlotDataChannelSpec &channel)
void updateCopasiTaskForSimulation(SedSimulation *sedmlsim, std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap)
CModel * importFirstSBMLModel(CProcessReport *pImportHandler, SBMLDocument *&pSBMLDocument, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, CCopasiDataModel *pDataModel)
void setDuration(const C_FLOAT64 &duration)
const std::string getArchiveFileName()
void setSeparator(const CCopasiReportSeparator &Separator)
void setAppend(const bool &append)
void setConfirmOverwrite(const bool &confirmOverwrite)
CModel * parseSEDML(const std::string &sedmlDocumentText, CProcessReport *pImportHandler, SBMLDocument *&pSBMLDocument, SedDocument *&pSEDMLDocument, std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, COutputDefinitionVector *&plotList, CCopasiDataModel *pDataModel)
static const CCopasiObject * resolveDatagenerator(const CModel *model, const SedDataGenerator *dataReference)
const CCopasiObjectName & getCN() const
CPlotItem * createItem(const std::string &name, CPlotItem::Type type)
void setIsTable(bool table)
static std::string dirName(const std::string &path)
CCopasiParameterGroup * addScanItem(CScanProblem::Type type, size_t steps=5, const CCopasiObject *obj=NULL)
bool applyValueToModelParameter(CModelParameter *modelParameter, CCopasiObject *obj, double newValue)
const CReportDefinitionVector * getReportDefinitionList() const
bool isScan(const SedTask *task)
virtual void setValue(const double &value, const Framework &framework)
virtual bool add(const CType &src)
void setComment(const std::string &comment)
CProcessReport * mpImportHandler
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
bool applyValueToParameterSet(CModelParameterSet &set, CCopasiObject *obj, double newValue)
static bool exist(const std::string &path)
static const std::string Separator
CModel * parseSBML(const std::string &sbmlDocumentText, CFunctionDB *funDB, SBMLDocument *&pSBMLDocument, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, CCopasiDataModel *pDataModel)
std::map< CReportDefinition *, std::string > mReportMap
virtual size_t getNumChildren() const
const Value & getValue() const
CCopasiVectorN< CCopasiTask > * getTaskList()
void setStepNumber(const unsigned C_INT32 &stepNumber)
bool setValue(const std::string &name, const CType &value)
virtual bool finishItem(const size_t &handle)
CPlotSpecification * createPlotSpec(const std::string &name, CPlotItem::Type type=CPlotItem::plot2d)
CCopasiParameter * getParameter(const std::string &name)
static CFunctionDB * getFunctionList()
static C_FLOAT64 round(const C_FLOAT64 &x)
void setTarget(const std::string &target)
void setContinueFromCurrentState(bool aic)
void setOutputInSubtask(bool ois)
void setImportHandler(CProcessReport *pHandler)
std::string mImportedModel
SedDocument * mpSEDMLDocument
unsigned int mOriginalLevel
static const CCopasiObject * resolveXPath(const CModel *model, const std::string &xpath, bool initial=false)
bool isTC(const SedTask *task)
std::vector< CRegisteredObjectName > * getBodyAddr()
unsigned C_INT32 mTotalSteps
CProcessReport * getImportHandlerAddr()
static std::string getNextId(const std::string &base, int count)
void setOutputStartTime(const C_FLOAT64 &endTime)
Header file of class CEvent.
static CLocaleString fromUtf8(const std::string &utf8)
void setReportDefinition(CReportDefinition *reportDef)
unsigned C_INT32 mImportStep
CCopasiDataModel * mpDataModel
std::map< CCopasiObject *, SBase * > & getCopasi2SBMLMap()
virtual bool setMethodType(const int &type)
std::vector< CRegisteredObjectName > * getHeaderAddr()
#define SEDML_KISAO_STOCHASTIC
void importTasks(std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap)
CCopasiContainer * getObjectParent() const
bool applyAttributeChange(CModel *pCopasiModel, CModelParameterSet &set, const std::string &target, const std::string &newValue)