COPASI API  4.16.103
StateSubwidget.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/UI/StateSubwidget.cpp,v $
3 // $Revision: 1.35 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/05/10 16:03:10 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 #include "StateSubwidget.h"
20 
21 #include <sstream>
22 
23 #include "copasi.h"
25 
26 #include "UI/qtUtilities.h"
27 #include "UI/listviews.h"
28 #include "UI/CopasiFileDialog.h"
29 
30 #include "model/CChemEqInterface.h"
31 #include "model/CModel.h"
35 #include "steadystate/CEigen.h"
37 #include "optimization/COptTask.h"
39 
40 /*
41  * Constructs a StateSubwidget which is a child of 'parent', with the
42  * name 'name'.'
43  */
44 StateSubwidget::StateSubwidget(QWidget* parent, const char* name)
45  : CopasiWidget(parent, name)
46 {
47  setupUi(this);
48 
49  init();
50 }
51 
52 /*
53  * Destroys the object and frees any allocated resources
54  */
56 {
57  // no need to delete child widgets, Qt does it all for us
58 }
59 
61 {
62  topLabel->setText("");
63 
64  mpModel = NULL;
65  mpTask = NULL;
66 
68 }
69 
71 {
72  // Fill the table
75  int i = 0;
76 
77  mpTblMetabolites->setRowCount((int) mpModel->getMetabolites().size());
78 
79  for (; it != end; ++it)
80  if ((*it)->getStatus() == CModelEntity::ODE ||
81  ((*it)->getStatus() == CModelEntity::REACTIONS && (*it)->isUsed()))
82  {
83  mpTblMetabolites->setItem(i, 0, new QTableWidgetItem(FROM_UTF8(CMetabNameInterface::getDisplayName(mpModel, **it, false))));
84  mpTblMetabolites->setItem(i, 1, new QTableWidgetItem(FROM_UTF8(CModelEntity::StatusName[(*it)->getStatus()])));
85  mpTblMetabolites->setItem(i, 2, new QTableWidgetItem(QString::number((*it)->getConcentration())));
86  mpTblMetabolites->setItem(i, 3, new QTableWidgetItem(QString::number((*it)->getValue())));
87  mpTblMetabolites->setItem(i, 4, new QTableWidgetItem(QString::number((*it)->getConcentrationRate())));
88  mpTblMetabolites->setItem(i, 5, new QTableWidgetItem(QString::number((*it)->getRate())));
89  mpTblMetabolites->setItem(i, 6, new QTableWidgetItem(QString::number((*it)->getTransitionTime())));
90 
91  i++;
92  }
93 
94  mpTblMetabolites->setRowCount(i);
95  mpTblMetabolites->resizeColumnsToContents();
96  mpTblMetabolites->resizeRowsToContents();
97 }
98 
100 {
103  C_INT32 i = 0;
104 
105  mpTblCompartments->setRowCount((int) mpModel->getCompartments().size());
106 
107  for (; it != end; ++it)
108  if ((*it)->getStatus() == CModelEntity::ODE)
109  {
110  mpTblCompartments->setItem(i, 0, new QTableWidgetItem(FROM_UTF8((*it)->getObjectName())));
111  mpTblCompartments->setItem(i, 1, new QTableWidgetItem(FROM_UTF8(CModelEntity::StatusName[(*it)->getStatus()])));
112  mpTblCompartments->setItem(i, 2, new QTableWidgetItem(QString::number((*it)->getValue())));
113  mpTblCompartments->setItem(i, 3, new QTableWidgetItem(QString::number((*it)->getRate())));
114  i++;
115  }
116 
117  mpTblCompartments->setRowCount(i);
118  mpTblCompartments->resizeColumnsToContents();
119  mpTblCompartments->resizeRowsToContents();
120 }
121 
123 {
124  // Fill the table
127  C_INT32 i = 0;
128 
129  mpTblReactions->setRowCount((int) mpModel->getReactions().size());
130 
131  for (; it != end; ++it)
132  {
133  mpTblReactions->setItem(i, 0, new QTableWidgetItem(FROM_UTF8((*it)->getObjectName())));
134  mpTblReactions->setItem(i, 1, new QTableWidgetItem(QString::number((*it)->getFlux())));
135  mpTblReactions->setItem(i, 2, new QTableWidgetItem(QString::number((*it)->getParticleFlux())));
136  mpTblReactions->setItem(i, 3, new QTableWidgetItem(FROM_UTF8(CChemEqInterface::getChemEqString(mpModel, **it, false))));
137 
138  i++;
139  }
140 
141  mpTblReactions->resizeColumnsToContents();
142  mpTblReactions->resizeRowsToContents();
143 }
144 
146 {
149  C_INT32 i = 0;
150 
151  mpTblModelValues->setRowCount((int) mpModel->getModelValues().size());
152 
153  for (; it != end; ++it)
154  if ((*it)->getStatus() == CModelEntity::ODE)
155  {
156  mpTblModelValues->setItem(i, 0, new QTableWidgetItem(FROM_UTF8((*it)->getObjectName())));
157  mpTblModelValues->setItem(i, 1, new QTableWidgetItem(FROM_UTF8(CModelEntity::StatusName[(*it)->getStatus()])));
158  mpTblModelValues->setItem(i, 2, new QTableWidgetItem(QString::number((*it)->getValue())));
159  mpTblModelValues->setItem(i, 3, new QTableWidgetItem(QString::number((*it)->getRate())));
160  i++;
161  }
162 
163  mpTblModelValues->setRowCount(i);
164  mpTblModelValues->resizeColumnsToContents();
165  mpTblModelValues->resizeRowsToContents();
166 }
167 
169 {
170  const CArrayAnnotation * JacAnn = mpTask->getJacobianAnnotated();
171 
172  CColorScaleBiLog * tcs = new CColorScaleBiLog();
173  mpJacobianAnnotationWidget->setColorCoding(tcs);
174  mpJacobianAnnotationWidget->setColorScalingAutomatic(true);
175  mpJacobianAnnotationWidget->setLegendEnabled(false);
176  mpJacobianAnnotationWidget->setArrayAnnotation(JacAnn);
177 
178  //Eigenvalues...
179  const CVector< C_FLOAT64 > & eigen_i = mpTask->getEigenValues().getI();
180  const CVector< C_FLOAT64 > & eigen_r = mpTask->getEigenValues().getR();
181 
182  size_t i, imax = eigen_i.size();
183  tableEigenValues->setRowCount((int) imax);
184 
185  for (i = 0; i < imax; ++i)
186  {
187  tableEigenValues->setItem((int) i, 0, new QTableWidgetItem(QString::number(eigen_r[i])));
188  tableEigenValues->setItem((int) i, 1, new QTableWidgetItem(QString::number(eigen_i[i])));
189  }
190 
191  tableEigenValues->resizeColumnsToContents();
192  tableEigenValues->resizeRowsToContents();
193 
194  //JacobianX
195 
196  const CArrayAnnotation * JacXAnn = mpTask->getJacobianXAnnotated();
197 
198  tcs = new CColorScaleBiLog();
199  mpJacobianXAnnotationWidget->setColorCoding(tcs);
200  mpJacobianXAnnotationWidget->setColorScalingAutomatic(true);
201  mpJacobianXAnnotationWidget->setLegendEnabled(false);
202  mpJacobianXAnnotationWidget->setArrayAnnotation(JacXAnn);
203 
204  //Eigenvalues...
205  const CVector< C_FLOAT64 > & eigen_iX = mpTask->getEigenValuesReduced().getI();
206  const CVector< C_FLOAT64 > & eigen_rX = mpTask->getEigenValuesReduced().getR();
207 
208  imax = eigen_iX.size();
209  tableEigenValuesX->setRowCount((int) imax);
210 
211  for (i = 0; i < imax; ++i)
212  {
213  tableEigenValuesX->setItem((int) i, 0, new QTableWidgetItem(QString::number(eigen_rX[i])));
214  tableEigenValuesX->setItem((int) i, 1, new QTableWidgetItem(QString::number(eigen_iX[i])));
215  }
216 
217  tableEigenValuesX->resizeColumnsToContents();
218  tableEigenValuesX->resizeRowsToContents();
219 
220  //stability report
221  stabilityTextEdit->setReadOnly(true);
222 
223  std::ostringstream ss;
224  ss << mpTask->getEigenValuesReduced();
225 
226  stabilityTextEdit->setText(FROM_UTF8(ss.str()));
227  return;
228 }
229 
231 {
232  if (mpModel == NULL)
233  return;
234 
235  // Update the column titles
236 
237  QString TimeUnits = FROM_UTF8(mpModel->getTimeUnitsDisplayString());
238 
239  if (!TimeUnits.isEmpty())
240  TimeUnits = "\n(" + TimeUnits + ")";
241 
242  QString FrequencyUnits = FROM_UTF8(mpModel->getFrequencyUnitsDisplayString());
243 
244  if (!FrequencyUnits.isEmpty())
245  FrequencyUnits = "\n(" + FrequencyUnits + ")";
246 
247  QString ConcentrationUnits = FROM_UTF8(mpModel->getConcentrationUnitsDisplayString());
248 
249  if (!ConcentrationUnits.isEmpty())
250  ConcentrationUnits = "\n(" + ConcentrationUnits + ")";
251 
252  QString ConcentrationRateUnits = FROM_UTF8(mpModel->getConcentrationRateUnitsDisplayString());
253 
254  if (!ConcentrationRateUnits.isEmpty())
255  ConcentrationRateUnits = "\n(" + ConcentrationRateUnits + ")";
256 
257  QString VolumeUnits = FROM_UTF8(mpModel->getVolumeUnitsDisplayString());
258 
259  if (!VolumeUnits.isEmpty())
260  VolumeUnits = "\n(" + VolumeUnits + ")";
261 
262  QString VolumeRateUnits = FROM_UTF8(mpModel->getVolumeRateUnitsDisplayString());
263 
264  if (!VolumeRateUnits.isEmpty())
265  VolumeRateUnits = "\n(" + VolumeRateUnits + ")";
266 
267  QString QuantityRateUnits = FROM_UTF8(mpModel->getQuantityRateUnitsDisplayString());
268 
269  if (!QuantityRateUnits.isEmpty())
270  QuantityRateUnits = "\n(" + QuantityRateUnits + ")";
271 
272  mpTblCompartments->horizontalHeaderItem(2)->setText("Volume" + VolumeUnits);
273  mpTblCompartments->horizontalHeaderItem(3)->setText("Rate" + VolumeRateUnits);
274 
275  mpTblMetabolites->horizontalHeaderItem(2)->setText("Concentration" + ConcentrationUnits);
276  mpTblMetabolites->horizontalHeaderItem(3)->setText("Particle Numbers");
277  mpTblMetabolites->horizontalHeaderItem(4)->setText("Rate" + ConcentrationRateUnits);
278  mpTblMetabolites->horizontalHeaderItem(5)->setText("Rate" + FrequencyUnits);
279  mpTblMetabolites->horizontalHeaderItem(6)->setText("Transition Time" + TimeUnits);
280 
281  mpTblReactions->horizontalHeaderItem(1)->setText("Flux" + QuantityRateUnits);
282  mpTblReactions->horizontalHeaderItem(2)->setText("Particle Flux" + FrequencyUnits);
283 }
284 
286 {
287  mpTask = pTask;
288  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
289  mpModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
290 
291  if (mpTask == NULL || mpModel == NULL)
292  {
293  clear();
294  return false;
295  }
296 
297  CState * pState = const_cast<CState *>(mpTask->getState());
298  mpModel->setState(*pState);
301 
303  topLabel->setText("A steady state with given resolution was found.");
305  topLabel->setText("No steady state with given resolution was found!");
307  topLabel->setText("An equilibrium steady state (zero fluxes) was found.");
309  topLabel->setText("An invalid steady state (negative concentrations) was found.");
310  else
311  topLabel->setText("A steady state with given resolution couldn't be found.");
312 
314 
315  loadMetabolites();
317  loadModelValues();
318  loadReactions();
319 
320  const CSteadyStateProblem* pProblem =
321  dynamic_cast<const CSteadyStateProblem *>(mpTask->getProblem());
322  assert(pProblem);
323 
324  int Last = mpTabWidget->count() - 1;
325 
326  // enable/disable tab widgets
327 
328  // jacobian and stability
329  if (pProblem->isJacobianRequested() ||
330  pProblem->isStabilityAnalysisRequested())
331  {
332  mpTabWidget->setTabEnabled(Last - 3, true);
333  mpTabWidget->setTabEnabled(Last - 2, true);
334  mpTabWidget->setTabEnabled(Last - 1, true);
335 
336  loadJacobian();
337  }
338 
339  else
340  {
341  mpTabWidget->setTabEnabled(Last - 3, false);
342  mpTabWidget->setTabEnabled(Last - 2, false);
343  mpTabWidget->setTabEnabled(Last - 1, false);
344  }
345 
346  // protocol
347  if (true)
348  {
349  mpTabWidget->setTabEnabled(Last, true);
350 
351  const CSteadyStateMethod * pMethod =
352  dynamic_cast<const CSteadyStateMethod *>(mpTask->getMethod());
353  assert(pMethod);
354  protocolTextEdit->setText(FROM_UTF8(pMethod->getMethodLog()));
355  }
356  else
357  {
358  mpTabWidget->setTabEnabled(Last, false);
359  }
360 
361  return true;
362 }
363 
365 {
366  topLabel->setText("No result available, please execute the steady-state task.");
367 
368  mpTblMetabolites->setRowCount(0);
369  mpTblCompartments->setRowCount(0);
370  mpTblModelValues->setRowCount(0);
371  mpTblReactions->setRowCount(0);
372 
373  mpJacobianAnnotationWidget->setArrayAnnotation(NULL);
374  mpJacobianXAnnotationWidget->setArrayAnnotation(NULL);
375 
376  tableEigenValues->setRowCount(0);
377  tableEigenValuesX->setRowCount(0);
378 
379  stabilityTextEdit->setText("");
380  protocolTextEdit->setText("");
381 }
382 
383 void StateSubwidget::setFramework(int framework)
384 {
385  CopasiWidget::setFramework(framework);
386 
387  // TODO hide/show columns
388  switch (mFramework)
389  {
390  case 0:
391  mpTblMetabolites->showColumn(2);
392  mpTblMetabolites->hideColumn(3);
393  mpTblMetabolites->showColumn(4);
394  mpTblMetabolites->hideColumn(5);
395  mpTblReactions->showColumn(1);
396  mpTblReactions->hideColumn(2);
397  break;
398 
399  case 1:
400  mpTblMetabolites->hideColumn(2);
401  mpTblMetabolites->showColumn(3);
402  mpTblMetabolites->hideColumn(4);
403  mpTblMetabolites->showColumn(5);
404  mpTblReactions->hideColumn(1);
405  mpTblReactions->showColumn(2);
406  break;
407  }
408 
409  showUnits();
410 }
411 
413  ListViews::Action action,
414  const std::string & /* key */)
415 {
416  switch (objectType)
417  {
418  case ListViews::MODEL:
419 
420  // For a new model we need to remove references to no longer existing metabolites
421  switch (action)
422  {
423  case ListViews::ADD:
424  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
425  mpModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
426  clear();
427  showUnits();
428  mpTask = NULL;
429  break;
430 
431  case ListViews::CHANGE:
432  showUnits();
433  break;
434 
435  default:
436  break;
437  }
438 
439  break;
440 
441  default:
442  break;
443  }
444 
445  return true;
446 }
447 
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
const CSteadyStateMethod::ReturnCode & getResult() const
const CArrayAnnotation * getJacobianAnnotated() const
objectType
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CCopasiProblem * getProblem()
std::string getTimeUnitsDisplayString() const
Definition: CModel.cpp:4531
static const std::string StatusName[]
Definition: CModelValue.h:67
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
std::string getConcentrationRateUnitsDisplayString() const
Definition: CModel.cpp:4607
std::string getFrequencyUnitsDisplayString() const
Definition: CModel.cpp:4539
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
virtual size_t size() const
StateSubwidget(QWidget *parent=0, const char *name=0)
void updateNonSimulatedValues(void)
Definition: CModel.cpp:1892
iterator begin()
void updateSimulatedValues(const bool &updateMoieties)
Definition: CModel.cpp:1851
std::string getQuantityRateUnitsDisplayString() const
Definition: CModel.cpp:4657
const CSteadyStateTask * mpTask
Definition: CState.h:305
std::string getVolumeRateUnitsDisplayString() const
Definition: CModel.cpp:4571
bool isStabilityAnalysisRequested() const
const CState * getState() const
const CArrayAnnotation * getJacobianXAnnotated() const
#define C_INT32
Definition: copasi.h:90
static std::string getDisplayName(const CModel *model, const std::string &key, const bool &quoted)
const CVector< C_FLOAT64 > & getI() const
Definition: CEigen.cpp:687
const CEigen & getEigenValues() const
CModel * mpModel
CTSSATask * pTask
std::string getMethodLog() const
iterator end()
virtual bool loadAll(const CSteadyStateTask *pTask)
virtual void init()
std::string getVolumeUnitsDisplayString() const
Definition: CModel.cpp:4547
void setState(const CState &state)
Definition: CModel.cpp:1785
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
std::string getChemEqString(bool expanded) const
virtual void setFramework(int framework)
const CVector< C_FLOAT64 > & getR() const
Definition: CEigen.cpp:690
size_t size() const
Definition: CVector.h:100
std::string getConcentrationUnitsDisplayString() const
Definition: CModel.cpp:4587
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
CCopasiMethod * getMethod()
const CEigen & getEigenValuesReduced() const
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
bool isJacobianRequested() const
virtual void setFramework(int framework)