17 #include <sbml/SBMLDocument.h>
20 #include <sedml/SedDocument.h>
86 size_t oldSize = oldCN.size();
89 for (; it != itEnd; ++it)
91 currentSize = (*it)->size();
94 if ((currentSize == oldSize ||
95 (currentSize > oldSize && (**it)[oldSize] ==
',')) &&
96 oldCN.compare(0, oldSize, **it, 0, oldSize) == 0)
98 (**it).replace(0, oldSize, newCN);
129 const std::string & type,
159 const std::string & pwd,
161 const bool & deleteOldData)
171 if (!Line.compare(0, 8,
"Version="))
173 in.seekg(0, std::ios_base::beg);
180 "Can't handle Gepasi Files with Version>=4.");
200 else if (!Line.find(
"<?xml") != std::string::npos)
202 in.seekg(0, std::ios_base::beg);
220 if (!XML.
load(in, pwd))
305 const bool & deleteOldData)
310 std::string FileName = fileName;
327 "File error when opening '%s'.",
332 if (!
loadModel(File, PWD, pProcessReport, deleteOldData))
353 if (strcasecmp(Suffix.c_str(),
".gps") != 0)
374 const bool & autoSave)
436 std::string TmpFileName;
442 if (!XML.CCopasiXMLInterface::save(TmpFileName, FileName))
459 if (autoSave || !success)
463 if (!XML.CCopasiXMLInterface::save(FileName, FileName))
486 std::string AutoSave;
490 if (AutoSave ==
"")
return false;
497 AutoSave +=
"untitled";
503 if (!
saveModel(AutoSave, NULL,
true,
true))
return false;
516 const bool & deleteOldData)
528 const bool & deleteOldData)
545 SBMLDocument * pSBMLDocument = NULL;
546 std::map<CCopasiObject*, SBase*> Copasi2SBMLMap;
553 pSBMLDocument, Copasi2SBMLMap, pLol,
this);
597 )->setContinueSimultaneousEvents(
true);
605 const bool & deleteOldData)
614 std::string FileName = fileName;
630 SBMLDocument * pSBMLDocument = NULL;
631 std::map<CCopasiObject*, SBase*> Copasi2SBMLMap;
644 pSBMLDocument, Copasi2SBMLMap, pLol,
this);
688 )->setContinueSimultaneousEvents(
true);
696 if (strcasecmp(Suffix.c_str(),
".xml") != 0)
712 SBMLDocument* pOrigSBMLDocument = NULL;
714 #if LIBSBML_VERSION >= 40100
720 ((this->mData.pCurrentSBMLDocument->getLevel() > 2 && sbmlLevel < 3) ||
729 #endif // LIBSBML_VERSION
731 static std::string failedCompile(
"The model cannot be exported, as it failed to compile. \n%s");
779 std::map<const CCopasiObject*, SBase*>::const_iterator it = exporter.
getCOPASI2SBMLMap().begin();
780 std::map<const CCopasiObject*, SBase*>::const_iterator endit = exporter.
getCOPASI2SBMLMap().end();
784 mData.
mCopasi2SBMLMap.insert(std::pair<CCopasiObject*, SBase*>(const_cast<CCopasiObject*>(it->first), it->second));
790 else if (pOrigSBMLDocument != NULL)
802 if (fileName ==
"")
return false;
807 std::string FileName = fileName;
833 static std::string failedCompile(
"The model cannot be exported, as it failed to compile. \n%s");
856 SBMLDocument* pOrigSBMLDocument = NULL;
858 #if LIBSBML_VERSION >= 40100
864 ((this->mData.pCurrentSBMLDocument->getLevel() > 2 && sbmlLevel < 3) ||
873 #endif // LIBSBML_VERSION
876 if (!exporter.
exportModel(*
this, FileName, sbmlLevel, sbmlVersion, overwriteFile))
return false;
897 std::map<const CCopasiObject*, SBase*>::const_iterator it = exporter.
getCOPASI2SBMLMap().begin();
898 std::map<const CCopasiObject*, SBase*>::const_iterator endit = exporter.
getCOPASI2SBMLMap().end();
902 mData.
mCopasi2SBMLMap.insert(std::pair<CCopasiObject*, SBase*>(const_cast<CCopasiObject*>(it->first), it->second));
908 else if (pOrigSBMLDocument != NULL)
921 if (filter ==
"C Files (*.c)")
925 else if (filter ==
"Berkeley Madonna Files (*.mmd)")
929 else if (filter ==
"XPPAUT (*.ode)")
934 if (pExporter == NULL)
953 for (; it != end; ++it)
954 if ((*it)->isUsed())
break;
959 std::ostringstream os;
970 const std::string & filter,
bool overwriteFile)
974 if (fileName ==
"")
return false;
1016 for (; it != end; ++it)
1017 if ((*it)->isUsed())
break;
1024 if (filter ==
"C Files (*.c)")
1028 else if (filter ==
"Berkeley Madonna Files (*.mmd)")
1032 else if (filter ==
"XPPAUT (*.ode)")
1037 if (pExporter == NULL)
1057 bool CCopasiDataModel::importSEDMLFromString(
const std::string& sedmlDocumentText,
1059 const bool & deleteOldData)
1076 SedDocument * pSEDMLDocument = NULL;
1077 std::map<CCopasiObject*, SedBase*> Copasi2SEDMLMap;
1078 std::map<CCopasiObject*, SBase*> Copasi2SBMLMap;
1080 SBMLDocument * pSBMLDocument = NULL;
1086 pModel = importer.
parseSEDML(sedmlDocumentText, pImportHandler, pSBMLDocument, pSEDMLDocument,
1087 Copasi2SEDMLMap, Copasi2SBMLMap, pLol, pLotList,
this);
1122 mData.pCurrentSEDMLDocument = pSEDMLDocument;
1123 mData.mCopasi2SEDMLMap = Copasi2SEDMLMap;
1132 bool CCopasiDataModel::importSEDML(
const std::string & fileName,
1134 const bool & deleteOldData)
1144 std::string FileName = fileName;
1160 SedDocument * pSEDMLDocument = NULL;
1161 std::map<CCopasiObject*, SedBase*> Copasi2SEDMLMap;
1162 std::map<CCopasiObject*, SBase*> Copasi2SBMLMap;
1164 SBMLDocument * pSBMLDocument = NULL;
1177 pModel = importer.
readSEDML(FileName, pImportHandler, pSBMLDocument, pSEDMLDocument,
1178 Copasi2SEDMLMap, Copasi2SBMLMap, pLol, pLotList,
this);
1223 mData.pCurrentSEDMLDocument = pSEDMLDocument;
1224 mData.mCopasi2SEDMLMap = Copasi2SEDMLMap;
1233 if (strcasecmp(Suffix.c_str(),
".sedml") != 0)
1246 SedDocument* CCopasiDataModel::getCurrentSEDMLDocument()
1248 return mData.pCurrentSEDMLDocument;
1251 bool CCopasiDataModel::setSEDMLFileName(
const std::string & fileName)
1262 const std::string & CCopasiDataModel::getSEDMLFileName()
const
1263 {
return mData.mSEDMLFileName;}
1265 std::map<CCopasiObject*, SedBase*>& CCopasiDataModel::getCopasi2SEDMLMap()
1267 return mData.mCopasi2SEDMLMap;
1270 std::string CCopasiDataModel::exportSEDMLToString(
CProcessReport* pExportHandler,
int sedmlLevel,
int sedmlVersion)
1273 SedDocument* pOrigSEDMLDocument = NULL;
1276 static std::string failedCompile(
"The model cannot be exported, as it failed to compile. \n%s");
1303 if (pOrigSEDMLDocument != NULL)
1305 mData.pCurrentSEDMLDocument = pOrigSEDMLDocument;
1311 bool CCopasiDataModel::exportSEDML(
const std::string & fileName,
bool overwriteFile,
int sedmlLevel,
int sedmlVersion,
bool ,
bool exportCOPASIMIRIAM,
CProcessReport* pExportHandler)
1315 if (fileName ==
"")
return false;
1320 std::string FileName = fileName;
1346 static std::string failedCompile(
"The model cannot be exported, as it failed to compile. \n%s");
1369 SedDocument* pOrigSEDMLDocument = NULL;
1374 std::string sbmlDocument =
"";
1378 if (sbmlDocument ==
"")
1383 if (!exporter.
exportModelAndTasks(*
this, FileName, sbmlDocument, sedmlLevel, sedmlVersion, overwriteFile))
return false;
1513 std::set< const CCopasiObject * > & dependentTasks)
const
1515 size_t Size = dependentTasks.size();
1517 std::set< const CCopasiObject * >::const_iterator it = candidates.begin();
1518 std::set< const CCopasiObject * >::const_iterator end = candidates.end();
1523 for (; it != end; ++it)
1527 if (pReportDefinition == NULL)
1532 for (; itTask != endTask; ++itTask)
1534 if ((*itTask)->getReport().getReportDefinition() == pReportDefinition)
1536 dependentTasks.insert(*itTask);
1541 return Size < dependentTasks.size();
1553 pReport->
setComment(
"Automatically generated report.");
1570 pReport->
setComment(
"Automatically generated report.");
1579 pReport->
setComment(
"Automatically generated report.");
1593 pReport->
getBodyAddr()->push_back(
CCopasiObjectName(
"CN=Root,Vector=TaskList[Optimization],Problem=Optimization,Reference=Function Evaluations"));
1595 pReport->
getBodyAddr()->push_back(
CCopasiObjectName(
"CN=Root,Vector=TaskList[Optimization],Problem=Optimization,Reference=Best Value"));
1597 pReport->
getBodyAddr()->push_back(
CCopasiObjectName(
"CN=Root,Vector=TaskList[Optimization],Problem=Optimization,Reference=Best Parameters"));
1608 pReport->
setComment(
"Automatically generated report.");
1622 pReport->
getBodyAddr()->push_back(
CCopasiObjectName(
"CN=Root,Vector=TaskList[Parameter Estimation],Problem=Parameter Estimation,Reference=Function Evaluations"));
1624 pReport->
getBodyAddr()->push_back(
CCopasiObjectName(
"CN=Root,Vector=TaskList[Parameter Estimation],Problem=Parameter Estimation,Reference=Best Value"));
1626 pReport->
getBodyAddr()->push_back(
CCopasiObjectName(
"CN=Root,Vector=TaskList[Parameter Estimation],Problem=Parameter Estimation,Reference=Best Parameters"));
1637 pReport->
setComment(
"Automatically generated report.");
1654 pReport->
setComment(
"Automatically generated report.");
1671 pReport->
setComment(
"Automatically generated report.");
1688 pReport->
setComment(
"Automatically generated report.");
1705 pReport->
setComment(
"Automatically generated report.");
1751 if (pTask && pReportDef)
1864 for (i = 0; i < iMax; ++i)
1896 size_t containerIndex;
1897 std::string::size_type pos;
1900 for (containerIndex = 0;
1901 containerIndex < listOfContainer.size() && !pObject;
1904 pContainer = listOfContainer[containerIndex];
1906 if (pContainer == NULL)
1911 ContainerName = pContainer->
getCN();
1918 if ((pos = objName.find(ContainerName)) == std::string::npos)
1921 if (pos + ContainerName.length() == objName.length())
1922 pObject = pContainer;
1924 pObject = pContainer->
getObject(objName.substr(pos + ContainerName.length() + 1));
1928 if (pObject == NULL)
1960 pReportDefinitionList(NULL),
1961 pPlotDefinitionList(NULL),
1962 pListOfLayouts(NULL),
1964 pCurrentSBMLDocument(NULL),
1969 mAutoSaveNeeded(false),
1973 , pCurrentSEDMLDocument(NULL)
1979 pTaskList(src.pTaskList),
1980 pReportDefinitionList(src.pReportDefinitionList),
1981 pPlotDefinitionList(src.pPlotDefinitionList),
1982 pListOfLayouts(src.pListOfLayouts),
1984 pCurrentSBMLDocument(src.pCurrentSBMLDocument),
1985 mWithGUI(src.mWithGUI),
1986 mSaveFileName(src.mSaveFileName),
1987 mFileType(src.mFileType),
1988 mChanged(src.mChanged),
1989 mAutoSaveNeeded(src.mAutoSaveNeeded),
1990 mSBMLFileName(src.mSBMLFileName),
1991 mReferenceDir(src.mReferenceDir)
1993 , pCurrentSEDMLDocument(src.pCurrentSEDMLDocument)
2018 pCurrentSEDMLDocument = rhs.pCurrentSEDMLDocument;
2025 return (pModel != NULL &&
2026 pTaskList != NULL &&
2027 pReportDefinitionList != NULL &&
2028 pPlotDefinitionList != NULL &&
2029 pListOfLayouts != NULL &&
2030 (pGUI != NULL || mWithGUI ==
false));
2035 bool condition =
true;
2037 condition =
mOldData.pCurrentSEDMLDocument == NULL;
2070 const bool & deleteOldData)
2165 if (
mOldData.pCurrentSEDMLDocument ==
mData.pCurrentSEDMLDocument)
2166 mOldData.pCurrentSEDMLDocument = NULL;
2180 for (; it != end; ++it)
2190 bool update = (*it)->isUpdateModel();
2191 (*it)->setUpdateModel(
false);
2193 (*it)->setUpdateModel(update);
virtual bool setObjectParent(const CCopasiContainer *pParent)
void setImportCOPASIMIRIAM(bool import)
CCopasiVectorN< CFunction > & loadedFunctions()
CCopasiObject * getDataObject(const CCopasiObjectName &CN) const
SBMLDocument * getCurrentSBMLDocument()
static bool remove(const std::string &path)
const CModelParameterSet & getModelParameterSet() const
bool setSBMLFileName(const std::string &fileName)
static bool move(const std::string &from, const std::string &to)
static const std::string TypeName[]
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)
CData & operator=(const CData &rhs)
virtual CCopasiObjectName getCN() const
bool setTaskType(const CCopasiTask::Type &taskType)
CCopasiObjectName getRemainder() const
static bool isRelativePath(const std::string &path)
void commonAfterLoad(CProcessReport *pProcessReport, const bool &deleteOldData)
const CCopasiVectorN< CModelValue > & getModelValues() const
bool appendDependentTasks(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependentTasks) const
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
virtual size_t size() const
bool setModel(CModel *pModel)
CCopasiObject * get(const std::string &key)
void setTitle(bool title)
CListOfLayouts * getLayoutList() const
static std::string getAllMessageText(const bool &chronological=true)
bool newModel(CProcessReport *pProcessReport, const bool &deleteOldData)
CReportDefinitionVector * pReportDefinitionList
CObjectInterface * ObjectFromCN(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &objName) const
void setImportHandler(CProcessReport *pHandler)
bool setFunctionList(CCopasiVectorN< CFunction > *pFunctionList)
bool importSBML(const std::string &fileName, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
static std::string fileName(const std::string &path)
std::string mSaveFileName
CData(const bool &withGUI=false)
virtual size_t getIndex(const std::string &name) const
void setSeparator(const CCopasiReportSeparator &Separator)
const std::string exportModelAndTasksToString(CCopasiDataModel &dataModel, std::string &sbmldocument, unsigned int sedmlLevel, unsigned int sedmlVersion)
COutputDefinitionVector * getPlotList() const
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)
void changed(const bool &changed=true)
std::string mReferenceDir
static std::string baseName(const std::string &path)
SBMLDocument * getSBMLDocument()
void setIsTable(bool table)
static std::string dirName(const std::string &path)
virtual bool setModel(CModel *pModel)
COutputDefinitionVector * pPlotDefinitionList
virtual ~CCopasiDataModel()
const std::string & getFileName() const
const CReportDefinitionVector * getReportDefinitionList() const
CCopasiDataModel(const bool withGUI=false)
const std::string & getReferenceDirectory() const
virtual void handle(const std::string &oldCN, const std::string &newCN) const
void setExportCOPASIMIRIAM(bool exportMIRIAM)
std::vector< CType * >::const_iterator const_iterator
bool setDatamodel(CCopasiDataModel *pDataModel)
bool removeLayout(const std::string &key)
CDataModelRenameHandler()
virtual bool add(const CType &src)
void setComment(const std::string &comment)
static bool exist(const std::string &path)
std::vector< CRegisteredObjectName > * getFooterAddr()
bool setTaskList(CCopasiVectorN< CCopasiTask > *pTaskList)
static const std::string Separator
CModel * parseSBML(const std::string &sbmlDocumentText, CFunctionDB *funDB, SBMLDocument *&pSBMLDocument, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, CCopasiDataModel *pDataModel)
const std::string & getSBMLFileName() const
CListOfLayouts * pListOfLayouts
CCopasiVectorN< CCopasiTask > * getTaskList()
static bool isWritable(const std::string &path)
CReportDefinition * addReport(const CCopasiTask::Type &taskType)
void removeSBMLIdFromFunctions()
bool setPlotList(COutputDefinitionVector *pPlotList)
bool loadModel(std::istream &in, const std::string &pwd, CProcessReport *pProcessReport, const bool &deleteOldData=true)
CListOfLayouts * getListOfLayouts()
void setEnabled(const bool &enabled)
bool saveModel(const std::string &fileName, CProcessReport *pProcessReport, bool overwriteFile=false, const bool &autoSave=false)
static std::string createTmpName(const std::string &dir, const std::string &suffix)
bool setLayoutList(const CListOfLayouts &reportList)
CCopasiTask * addTask(const CCopasiTask::Type &taskType)
static CFunctionDB * getFunctionList()
static void getValue(const std::string &name, CType &value)
CCopasiVectorN< CCopasiTask > * pTaskList
const std::string exportModelToString(CCopasiDataModel &dataModel, unsigned int sbmlLevel, unsigned int sbmlVersion)
CReportDefinitionVector * getReportList() const
SBMLDocument * pCurrentSBMLDocument
void load(CReadConfig &configBuffer)
static const std::set< CRegisteredObjectName * > & getSet()
virtual bool setObjectParent(const CCopasiContainer *pParent)
void setImportHandler(CProcessReport *pHandler)
bool exportSBML(const std::string &fileName, bool overwriteFile=false, int sbmlLevel=2, int sbmlVersion=1, bool exportIncomplete=false, bool exportCOPASIMIRIAM=true, CProcessReport *pExportHandler=NULL)
CModel * getModel() const
bool exportToStream(const CCopasiDataModel *pDataModel, std::ostream &os)
static CKeyFactory * getKeyFactory()
bool setGUI(SCopasiXMLGUI *pGUI)
const COutputDefinitionVector * getPlotDefinitionList() const
bool setReportList(CReportDefinitionVector *pReportList)
bool compileIfNecessary(CProcessReport *pProcessReport)
static CCopasiMessage getLastMessage()
std::vector< CRegisteredObjectName > * getBodyAddr()
bool importSBMLFromString(const std::string &sbmlDocumentText, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
virtual bool add(CCopasiObject *pObject, const bool &adopt=true)
static std::string normalize(const std::string &path)
bool updateInitialValues()
virtual bool refreshFromModel(const bool &modifyExistence)
bool exportMathModel(const std::string &fileName, CProcessReport *pProcessReport, const std::string &filter, bool overwriteFile=false)
std::map< CCopasiObject *, SBase * > mCopasi2SBMLMap
virtual bool load(std::istream &is, const std::string &pwd)
void disownSBMLDocument()
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
std::string mSBMLFileName
static CLocaleString fromUtf8(const std::string &utf8)
static void setRenameHandler(CRenameHandler *rh)
CReportDefinition * getReportDefinition()
static bool makePathAbsolute(std::string &relativePath, const std::string &absoluteTo)
void setReportDefinition(CReportDefinition *reportDef)
CModel * readSBML(std::string filename, CFunctionDB *funDB, SBMLDocument *&pSBMLDocument, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, CCopasiDataModel *pDataModel)
CDataModelRenameHandler mRenameHandler
std::string exportMathModelToString(CProcessReport *pProcessReport, const std::string &filter)
CCopasiVectorS< CMetabOld > * pOldMetabolites
std::map< CCopasiObject *, SBase * > & getCopasi2SBMLMap()
void load(CReadConfig &configBuffer)
CCopasiVectorN< CCopasiTask > * getTaskList() const
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
std::vector< CRegisteredObjectName > * getHeaderAddr()
bool exportModelAndTasks(CCopasiDataModel &dataModel, const std::string &SEDMLFilename, const std::string &SBMLFilename, unsigned int sedmlLevel=1, unsigned int sedmlVersion=1, bool overwrite=false)
static std::string suffix(const std::string &path)
const std::map< const CCopasiObject *, SBase * > & getCOPASI2SBMLMap() const
void importTasks(std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap)
bool exportModel(CCopasiDataModel &dataModel, const std::string &filename, unsigned int sbmlLevel=2, unsigned int sbmlVersion=1, bool overwrite=false)
virtual bool updateModel()
C_INT32 load(CReadConfig &configBuffer)