COPASI API  4.16.103
CMCATask.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2004 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 /**
16  * CMCATask class.
17  *
18  * This class implements a metabolic control analysis task which is comprised of a
19  * problem and a method. Additionally calls to the reporting
20  * methods are done when initialized.
21  *
22  * Created for Copasi by Ralph Gauges 2004
23  */
24 
25 #include "copasi.h"
26 
27 #include "CMCATask.h"
28 #include "CMCAProblem.h"
29 #include "CMCAMethod.h"
30 #include "CSteadyStateTask.h"
31 
33 #include "model/CModel.h"
34 #include "model/CState.h"
35 #include "report/CKeyFactory.h"
36 #include "report/CReport.h"
37 
38 #define XXXX_Reporting
39 
41  CCopasiTask(CCopasiTask::mca, pParent)
42 {
43  mpProblem = new CMCAProblem(this);
44 
46  this->add(mpMethod, true);
47 }
48 
50  const CCopasiContainer * pParent):
51  CCopasiTask(src, pParent)
52 {
53  mpProblem =
54  new CMCAProblem(*(CMCAProblem *) src.mpProblem, this);
55 
57  this->add(mpMethod, true);
58 }
59 
61 {}
62 
63 // virtual
64 CCopasiMethod * CMCATask::createMethod(const int & type) const
65 {
67 
68  return CMCAMethod::createMethod(Type);
69 }
70 
72 {}
73 
74 void CMCATask::load(CReadConfig & configBuffer)
75 {
76  configBuffer.getVariable("MCA", "bool", &mScheduled,
78 
79  ((CMCAProblem *) mpProblem)->load(configBuffer);
80 
81  ((CMCAMethod *) mpMethod)->load(configBuffer);
82 }
83 
85 {
86  assert(mpProblem != NULL && mpMethod != NULL);
87 
88  assert(dynamic_cast<CMCAProblem *>(mpProblem) != NULL);
89 
90  if (!mpMethod->isValidProblem(mpProblem)) return false;
91 
92  CMCAMethod * pMethod = dynamic_cast<CMCAMethod*>(mpMethod);
93 
94  if (!pMethod) return false;
95 
96  pMethod->setModel(mpProblem->getModel());
97  pMethod->resizeAllMatrices();
98 
99  return true;
100 }
101 
103  COutputHandler * pOutputHandler,
104  std::ostream * pOstream)
105 {
106  assert(mpProblem && mpMethod);
107 
108  CMCAProblem* pProblem =
109  dynamic_cast<CMCAProblem *>(mpProblem);
110  assert(pProblem);
111 
112  if (!mpMethod->isValidProblem(mpProblem)) return false;
113 
114  //we need to resize an initialize the result matrices before initializing the output
115  if (!updateMatrices()) return false;
116 
117  bool success = true;
118 
119  //initialize reporting
120  if (!CCopasiTask::initialize(of, pOutputHandler, pOstream)) success = false;
121 
122  if (!pProblem->getModel()->compileIfNecessary(mpCallBack)) success = false;
123 
124  CSteadyStateTask *pSubTask = pProblem->getSubTask();
125 
126  if (pSubTask)
127  success = pSubTask->initialize(CCopasiTask::NO_OUTPUT, NULL, mReport.getStream());
128 
129  //success = pSubTask->initialize(of, mReport.getStream());
130 
131  return success;
132 }
133 
134 bool CMCATask::process(const bool & useInitialValues)
135 {
136  bool success = true;
137 
138  assert(mpMethod);
139 
140  CMCAMethod* pMethod = dynamic_cast<CMCAMethod *>(mpMethod);
141  assert(pMethod);
142  // pMethod->setModel(mpProblem->getModel());
143 
144  CSteadyStateTask *pSubTask =
145  dynamic_cast<CMCAProblem *>(mpProblem)->getSubTask();
146 
147  if (pSubTask)
148  {
149  pSubTask->setCallBack(mpCallBack);
150  success &= pSubTask->process(useInitialValues);
151 
152  if (!success && useInitialValues)
153  {
155  }
156 
157  pMethod->setSteadyStateTask(pSubTask);
158  }
159  else
160  {
161  pMethod->setSteadyStateTask(NULL);
162 
163  if (useInitialValues)
164  {
166  }
167  }
168 
170 
171  pMethod->process();
172 
175 
176  return success;
177 }
178 
180 {
181  bool success = CCopasiTask::restore();
182 
183  CSteadyStateTask *pSubTask =
184  dynamic_cast<CMCAProblem *>(mpProblem)->getSubTask();
185 
186  if (pSubTask)
187  success &= pSubTask->restore();
188 
189  return success;
190 }
191 
192 std::ostream &operator<<(std::ostream &os, const CMCATask & C_UNUSED(A))
193 {
194  os << std::endl;
195 
196  os << std::endl;
197 
198  return os;
199 }
200 
201 void CMCATask::printResult(std::ostream * ostream) const
202 {
203  assert(mpProblem && mpMethod);
204 
205  CMCAProblem* pProblem =
206  dynamic_cast<CMCAProblem *>(mpProblem);
207  assert(pProblem);
208 
209  CMCAMethod* pMethod = dynamic_cast<CMCAMethod *>(mpMethod);
210  assert(pMethod);
211  pMethod->setModel(mpProblem->getModel());
212 
213  std::ostream & os = *ostream;
214 
215  bool showCCs = false; //show CCs?
216  bool showSS = false; //show Steady State result?
217 
218  if (pProblem->isSteadyStateRequested())
219  {
221  {
222  os << "A steady state was found. All coefficients are shown." << std::endl;
223  showCCs = true;
224  showSS = true;
225  }
226 
228  {
229  os << "Found equilibrium steady state. Only elasticities available." << std::endl;
230  showSS = true;
231  }
232 
234  {
235  os << "Invalid steady state found (negative concentrations)." << std::endl;
236  showSS = true;
237  }
238 
240  {
241  os << "No steady state found. Only elasticities available." << std::endl;
242  }
243  }
244  else
245  {
246  os << "Since no steady state calculation was requested only elasticities are shown." << std::endl;
247  }
248 
249  os << std::endl;
250  os << *pMethod->getUnscaledElasticitiesAnn() << std::endl;
251  os << *pMethod->getScaledElasticitiesAnn() << std::endl;
252 
253  if (showCCs)
254  {
255  os << *pMethod->getUnscaledConcentrationCCAnn() << std::endl;
256  os << *pMethod->getScaledConcentrationCCAnn() << std::endl;
257 
258  os << *pMethod->getUnscaledFluxCCAnn() << std::endl;
259  os << *pMethod->getScaledFluxCCAnn() << std::endl;
260  }
261 
262  if (showSS)
263  {
264  if (!pProblem->getSubTask())
265  {
266  os << "Problem with steady state calculation. Please report as bug!" << std::endl;
267  return;
268  }
269 
270  os << "Results of the steady state subtask (the state for which the MCA was performed):" << std::endl;
271  os << *pProblem->getSubTask();
272  }
273 }
const CArrayAnnotation * getUnscaledFluxCCAnn() const
Definition: CMCAMethod.h:94
virtual bool setCallBack(CProcessReport *pCallBack)
void load(CReadConfig &configBuffer)
Definition: CMCATask.cpp:74
CCopasiMethod * mpMethod
Definition: CCopasiTask.h:239
const CArrayAnnotation * getScaledConcentrationCCAnn() const
Definition: CMCAMethod.h:92
virtual bool process(const bool &useInitialValues)
virtual CCopasiMethod * createMethod(const int &type) const
Definition: CMCATask.cpp:64
void setSteadyStateTask(CSteadyStateTask *pSteadyStateTask)
Definition: CMCAMethod.cpp:773
virtual bool initialize(const OutputFlag &of, COutputHandler *pOutputHandler, std::ostream *pOstream)
virtual bool updateMatrices()
Definition: CMCATask.cpp:84
bool mScheduled
Definition: CCopasiTask.h:217
CProcessReport * mpCallBack
Definition: CCopasiTask.h:249
virtual bool initialize(const OutputFlag &of, COutputHandler *pOutputHandler, std::ostream *pOstream)
Definition: CMCATask.cpp:102
virtual void output(const COutputInterface::Activity &activity)
const CCopasiMethod::SubType & getSubType() const
#define C_UNUSED(p)
Definition: copasi.h:220
CReport mReport
Definition: CCopasiTask.h:244
virtual void resizeAllMatrices()
Definition: CMCAMethod.cpp:160
void applyInitialValues()
Definition: CModel.cpp:1236
virtual bool isValidProblem(const CCopasiProblem *pProblem)
CCopasiProblem * mpProblem
Definition: CCopasiTask.h:234
const CSteadyStateMethod::ReturnCode & getSteadyStateStatus() const
Definition: CMCAMethod.h:147
void printResult(std::ostream *ostream) const
Definition: CMCATask.cpp:201
bool isSteadyStateRequested() const
const CArrayAnnotation * getUnscaledConcentrationCCAnn() const
Definition: CMCAMethod.h:90
const CArrayAnnotation * getScaledElasticitiesAnn() const
Definition: CMCAMethod.h:88
std::ostream * getStream() const
Definition: CReport.cpp:392
virtual bool process()
Definition: CMCAMethod.cpp:757
const CArrayAnnotation * getScaledFluxCCAnn() const
Definition: CMCAMethod.h:96
CSteadyStateTask * getSubTask() const
void cleanup()
Definition: CMCATask.cpp:71
virtual bool restore()
Definition: CMCATask.cpp:179
void setModel(CModel *model)
Definition: CMCAMethod.cpp:663
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
const CArrayAnnotation * getUnscaledElasticitiesAnn() const
Definition: CMCAMethod.h:86
virtual bool initialize(const OutputFlag &of, COutputHandler *pOutputHandler, std::ostream *pOstream)
std::ostream & operator<<(std::ostream &os, const CMCATask &C_UNUSED(A))
Definition: CMCATask.cpp:192
virtual bool add(CCopasiObject *pObject, const bool &adopt=true)
static CMCAMethod * createMethod(CCopasiMethod::SubType subType=CCopasiMethod::mcaMethodReder)
Definition: CMCAMethod.cpp:34
C_INT32 getVariable(const std::string &name, const std::string &type, void *pout, CReadConfig::Mode mode=CReadConfig::NEXT)
Definition: CReadConfig.cpp:81
virtual bool restore()
virtual ~CMCATask()
Definition: CMCATask.cpp:60
virtual bool restore()
CModel * getModel() const
virtual bool process(const bool &useInitialValues)
Definition: CMCATask.cpp:134
CMCATask(const CCopasiContainer *pParent=NULL)
Definition: CMCATask.cpp:40