File size: 6,666 Bytes
7e59e4c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | // Copyright (C) 2019 - 2020 by Pedro Mendes, Rector and Visitors of the
// University of Virginia, University of Heidelberg, and University
// of Connecticut School of Medicine.
// All rights reserved.
// Copyright (C) 2017 - 2018 by Pedro Mendes, Virginia Tech Intellectual
// Properties, Inc., University of Heidelberg, and University of
// of Connecticut School of Medicine.
// All rights reserved.
// Copyright (C) 2015 - 2016 by Pedro Mendes, Virginia Tech Intellectual
// Properties, Inc., University of Heidelberg, and The University
// of Manchester.
// All rights reserved.
#define COPASI_MAIN
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include "copasi/copasi.h"
#include "copasi/CopasiDataModel/CDataModel.h"
#include "copasi/core/CRootContainer.h"
#include "copasi/model/CMetab.h"
#include "copasi/core/CRegisteredCommonName.h"
#include "copasi/core/CDataVector.h"
#include "copasi/model/CModel.h"
#include "copasi/utilities/CCopasiException.h"
#include "copasi/commandline/COptionParser.h"
#include "copasi/commandline/COptions.h"
#include "copasi/trajectory/CTrajectoryTask.h"
#include "copasi/trajectory/CTrajectoryMethod.h"
#include "copasi/trajectory/CTrajectoryProblem.h"
#include "copasi/steadystate/CSteadyStateTask.h"
#include "copasi/steadystate/CSteadyStateMethod.h"
#include "copasi/steadystate/CSteadyStateProblem.h"
#include "copasi/steadystate/CMCATask.h"
#include "copasi/steadystate/CMCAMethod.h"
#include "copasi/steadystate/CMCAProblem.h"
#include "copasi/report/CReportDefinitionVector.h"
#include "copasi/report/CReportDefinition.h"
int main(int argc, char *argv[])
{
// Parse the commandline options
// 1. argument is the SBML filename
// 2. argument is the filename where the results are to be written
try
{
// Create the root container.
CRootContainer::init(0, NULL, false);
}
catch (copasi::autoexcept &e)
{}
catch (copasi::option_error &e)
{}
if (argc < 3)
{
std::cout << "Usage: mca_test_wrapper SBMLFILENAME OUTPUTFILE_PREFIX" << std::endl;
exit(1);
}
char* pSBMLFilename = argv[1];
const char* pOutputFilename = argv[2];
std::string CWD = COptions::getPWD();
try
{
// Create the global data model.
CDataModel* pDataModel = CRootContainer::addDatamodel();
// Import the SBML File
pDataModel->importSBML(pSBMLFilename);
// create a report with the correct filename and all the species against
// time.
CReportDefinitionVector* pReports = pDataModel->getReportDefinitionList();
CReportDefinition* pSteadyStateReport = &(*pReports)["Steady-State"];
CReportDefinition* pReport = &(*pReports)["Metabolic Control Analysis"];
//**** create a task ****
CMCATask* pMCATask = new CMCATask(pDataModel);
//pMCATask->setMethodType(CCopasiMethod::Newton);
pMCATask->getProblem()->setModel(pDataModel->getModel());
pMCATask->setScheduled(true);
pMCATask->getReport().setReportDefinition(pSteadyStateReport);
pMCATask->getReport().setTarget(pOutputFilename + std::string(".res1"));
pMCATask->getReport().setAppend(false);
//**** specify problem ****
CMCAProblem* pProblem = dynamic_cast<CMCAProblem*>(pMCATask->getProblem());
//pProblem->setStepNumber((const unsigned C_INT32)stepNumber);
//pDataModel->getModel()->setInitialTime((const C_FLOAT64)startTime);
//**** method settings ****
CMCAMethod* pMethod = dynamic_cast<CMCAMethod*>(pMCATask->getMethod());
pMethod->getParameter("Maximum duration for forward integration")->setValue(1.0e5);
pMethod->getParameter("Use Back Integration")->setValue(false);
pMethod->getParameter("Maximum duration for backward integration")->setValue(1.0e3);
//pMethod->getParameter("Absolute Tolerance")->setValue(1.0e-12);
//***** run the task *********
CDataVectorN< CCopasiTask > & TaskList = * pDataModel->getTaskList();
TaskList.remove("Metabolic Control Analysis");
TaskList.add(pMCATask, true);
// save the file for control purposes
std::string saveFilename = pOutputFilename + std::string("1.cps");
pDataModel->saveModel(saveFilename, NULL, true);
pMCATask->getReport().setReportDefinition(pReport);
pMCATask->getReport().setTarget(pOutputFilename + std::string(".res"));
pMCATask->getReport().setAppend(false);
// save the file for control purposes
saveFilename = pOutputFilename + std::string(".cps");
pDataModel->saveModel(saveFilename, NULL, true);
// Run the task
// 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
//pSSTask->getReport().setTarget(pOutputFilename);
pMCATask->initialize(CCopasiTask::OUTPUT_SE, pDataModel, NULL);
pMCATask->process(true);
pDataModel->finish();
pMCATask->restore();
//status output
//CSteadyStateMethod::ReturnCode rc = pSSTask->getResult();
std::string resultCode;
/*
switch (rc)
{
case CSteadyStateMethod::notFound: resultCode = "###0 No steady state found."; break;
case CSteadyStateMethod::found: resultCode = "###1 Steady state found."; break;
case CSteadyStateMethod::foundEquilibrium: resultCode = "###2 Equilibrium found."; break;
case CSteadyStateMethod::foundNegative: resultCode = "###3 Negative steady state found."; break;
}
std::cout << resultCode << std::endl;
*/
std::string resultFileName = pOutputFilename + std::string(".txt");
std::ofstream resultFile(resultFileName.c_str());
resultFile << resultCode << std::endl;
resultFile.close();
//write method log to separate file
//std::string methodlog = dynamic_cast<CSteadyStateMethod*>(pSSTask->getMethod())->getMethodLog();
//std::string logname = pOutputFilename + std::string(".log");
//std::ofstream ofs(logname.c_str());
//ofs << methodlog;
//ofs.close();
}
catch (CCopasiException Exception)
{
std::cerr << Exception.getMessage().getText() << std::endl;
}
std::string Text = "";
while (CCopasiMessage::size() > 0)
{
const CCopasiMessage& message = CCopasiMessage::getLastMessage();
if (message.getType() < CCopasiMessage::RAW_FILTERED)
{
if (Text != "") Text += "\n";
Text += message.getText();
}
}
if (Text != "") std::cerr << Text << std::endl;
//finish
CRootContainer::destroy();
return 0;
}
|