COPASI API  4.16.103
CLNAResultSubwidget.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 - 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 /*
7  * CLNAResultSubwidget.cpp
8  *
9  *
10  * Created by Juergen Pahle on 2010-06-01.
11  *
12  */
13 
14 #include "CLNAResultSubwidget.h"
15 
16 #include <QtCore/QFileInfo>
17 #include <QtGui/QLineEdit>
18 #include <QtGui/QCheckBox>
19 #include <QtGui/QPainter>
20 #include <QtGui/QMessageBox>
21 
22 #include "copasi.h"
23 
24 #include "qtUtilities.h"
25 #include "model/CModel.h"
26 #include "lna/CLNAMethod.h"
28 
30 #include "lna/CLNATask.h"
31 #include "UI/CopasiFileDialog.h"
33 
34 /*
35  * Constructs a CLNAResultSubwidget as a child of 'parent', with the
36  * name 'name' and widget flags set to 'f'.
37  */
38 CLNAResultSubwidget::CLNAResultSubwidget(QWidget* parent, const char* name, Qt::WindowFlags fl)
39  : CopasiWidget(parent, name, fl)
40 {
41  setupUi(this);
42 
43  init();
44 }
45 
46 /*
47  * Destroys the object and frees any allocated resources
48  */
50 {
51  // no need to delete child widgets, Qt does it all for us
52 }
53 
55 {
56  /*
57  mSaveButton->setEnabled(false);
58  mSaveButton->hide();
59  */
60  mLNAMethod = NULL;
61 
62  clear();
63 }
64 
66 {
67  mLNAMethod = lnaMethod;
68 
69  if (lnaMethod)
70  {
71  if (!lnaMethod->getModel())
72  {
73  clear();
74  return;
75  }
76 
78  {
79  mTopLabel->setText("Steady State found.");
80  this->loadCovarianceMatrix(lnaMethod);
81  this->loadCovarianceMatrixReduced(lnaMethod);
82  this->loadBMatrixReduced(lnaMethod);
83  mTabWidget->setTabEnabled(0, true);
84  mTabWidget->setTabEnabled(1, true);
85  mTabWidget->setTabEnabled(2, true);
86  }
88  {
89  mTopLabel->setText("Equilibrium steady state.");
90  this->loadCovarianceMatrix(lnaMethod);
91  this->loadCovarianceMatrixReduced(lnaMethod);
92  this->loadBMatrixReduced(lnaMethod);
93  mTabWidget->setTabEnabled(0, true);
94  mTabWidget->setTabEnabled(1, true);
95  mTabWidget->setTabEnabled(2, true);
96  }
97  else
98  {
100  {
101  mTopLabel->setText("Invalid steady state (negative concentrations). No LNA calculated!");
102  }
103  else if (lnaMethod->getSteadyStateStatus() == CSteadyStateMethod::notFound)
104  {
105  mTopLabel->setText("No steady state found. No LNA calculated!");
106  }
108  {
109  mTopLabel->setText("The reduced system has non-negative Eigen values! No LNA calculated!");
110  }
111 
112  /*
113  this->loadCovarianceMatrix(lnaMethod);
114  this->loadCovarianceMatrixReduced(lnaMethod);
115  this->loadBMatrixReduced(lnaMethod);
116  */
117 
118  mpArrayCovarianceMatrix->setArrayAnnotation(NULL);
119  mpArrayCovarianceMatrixReduced->setArrayAnnotation(NULL);
120  mpArrayBMatrixReduced->setArrayAnnotation(NULL);
121  }
122  }
123  else
124  {
125  clear();
126  return;
127  }
128 }
129 
131 {
132  const CArrayAnnotation * covarianceMatrixAnn;
133 
134  if (mComboScale->currentIndex() == 0)
135  {
136  covarianceMatrixAnn = lnaMethod->getScaledCovarianceMatrixAnn();
137 
138  CColorScaleBiLog * tcs = new CColorScaleBiLog();
139  mpArrayCovarianceMatrix->setColorCoding(tcs);
140  mpArrayCovarianceMatrix->setColorScalingAutomatic(true);
141  }
142  else
143  {
144  covarianceMatrixAnn = lnaMethod->getUnscaledCovarianceMatrixAnn();
145 
146  CColorScaleBiLog * tcs = new CColorScaleBiLog();
147  mpArrayCovarianceMatrix->setColorCoding(tcs);
148  mpArrayCovarianceMatrix->setColorScalingAutomatic(true);
149  }
150 
151  mpArrayCovarianceMatrix->setArrayAnnotation(covarianceMatrixAnn);
152 }
153 
155 {
156  const CArrayAnnotation * covarianceMatrixReducedAnn;
157 
158  if (mComboScale->currentIndex() == 0)
159  {
160  covarianceMatrixReducedAnn = lnaMethod->getScaledCovarianceMatrixReducedAnn();
161 
162  CColorScaleBiLog * tcs = new CColorScaleBiLog();
163  mpArrayCovarianceMatrixReduced->setColorCoding(tcs);
164  mpArrayCovarianceMatrixReduced->setColorScalingAutomatic(true);
165  }
166  else
167  {
168  covarianceMatrixReducedAnn = lnaMethod->getUnscaledCovarianceMatrixReducedAnn();
169 
170  CColorScaleBiLog * tcs = new CColorScaleBiLog();
171  mpArrayCovarianceMatrixReduced->setColorCoding(tcs);
172  mpArrayCovarianceMatrixReduced->setColorScalingAutomatic(true);
173  }
174 
175  mpArrayCovarianceMatrixReduced->setArrayAnnotation(covarianceMatrixReducedAnn);
176 }
177 
179 {
180  const CArrayAnnotation * bMatrixReducedAnn;
181 
182  if (mComboScale->currentIndex() == 0)
183  {
184  bMatrixReducedAnn = lnaMethod->getScaledBMatrixReducedAnn();
185 
186  CColorScaleBiLog * tcs = new CColorScaleBiLog();
187  mpArrayBMatrixReduced->setColorCoding(tcs);
188  mpArrayBMatrixReduced->setColorScalingAutomatic(true);
189  }
190  else
191  {
192  bMatrixReducedAnn = lnaMethod->getUnscaledBMatrixReducedAnn();
193 
194  CColorScaleBiLog * tcs = new CColorScaleBiLog();
195  mpArrayBMatrixReduced->setColorCoding(tcs);
196  mpArrayBMatrixReduced->setColorScalingAutomatic(true);
197  }
198 
199  mpArrayBMatrixReduced->setArrayAnnotation(bMatrixReducedAnn);
200 }
201 
203 {
204  C_INT32 Answer = QMessageBox::No;
205  QString fileName;
206 
207  while (Answer == QMessageBox::No)
208  {
209  fileName =
210  CopasiFileDialog::getSaveFileName(this, "Save File Dialog",
211  "untitled.txt", "TEXT Files (*.txt)", "Save to");
212 
213  if (fileName.isEmpty()) return;
214 
215  // Checks whether the file exists
216  Answer = checkSelection(fileName);
217 
218  if (Answer == QMessageBox::Cancel) return;
219  }
220 
221  std::ofstream file(CLocaleString::fromUtf8(TO_UTF8(fileName)).c_str());
222 
223  if (file.fail())
224  return;
225 
226  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
227  CCopasiTask* mpTask =
228  dynamic_cast<CLNATask *>((*(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList())["Linear Noise Approximation"]);
229 
230  if (mpTask != NULL)
231  file << mpTask->getResult();
232 
233 // mpTask->printResult(file);
234 
235  return;
236 }
237 
239 {
241 }
242 
244 {
245  mTopLabel->setText("No result available, please execute the LNA task.");
246 
247  mpArrayCovarianceMatrix->setArrayAnnotation(NULL);
248  mpArrayCovarianceMatrixReduced->setArrayAnnotation(NULL);
249  mpArrayBMatrixReduced->setArrayAnnotation(NULL);
250 
251  return;
252 }
const CArrayAnnotation * getUnscaledBMatrixReducedAnn() const
Definition: CLNAMethod.h:124
const CLNAMethod::EVStatus & getEigenValueStatus() const
Definition: CLNAMethod.h:188
CLNAResultSubwidget(QWidget *parent=0, const char *name=0, Qt::WindowFlags fl=0)
virtual void loadCovarianceMatrix(const CLNAMethod *lnaMethod)
virtual void loadBMatrixReduced(const CLNAMethod *lnaMethod)
const CSteadyStateMethod::ReturnCode & getSteadyStateStatus() const
Definition: CLNAMethod.h:185
virtual void loadAll(const CLNAMethod *lnaMethod)
const CArrayAnnotation * getScaledBMatrixReducedAnn() const
Definition: CLNAMethod.h:121
const CArrayAnnotation * getScaledCovarianceMatrixAnn() const
Definition: CLNAMethod.h:127
#define C_INT32
Definition: copasi.h:90
const CModel * getModel() const
Definition: CLNAMethod.cpp:657
const CArrayAnnotation * getUnscaledCovarianceMatrixReducedAnn() const
Definition: CLNAMethod.h:136
const CArrayAnnotation * getUnscaledCovarianceMatrixAnn() const
Definition: CLNAMethod.h:133
C_INT32 checkSelection(const QString &file)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
const CLNAMethod * mLNAMethod
const CArrayAnnotation * getScaledCovarianceMatrixReducedAnn() const
Definition: CLNAMethod.h:130
Header file of class CArrayAnnotation.
const CResult & getResult() const
bool fl(const C_FLOAT64 &d1, const C_FLOAT64 &d2)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
static CLocaleString fromUtf8(const std::string &utf8)
static QString getSaveFileName(QWidget *parent=0, const char *name=0, const QString &startWith=QString::null, const QString &filter=QString::null, const QString &caption=QString::null, QString *pSelectedFilter=NULL, QFileDialog::Options options=0)
virtual void loadCovarianceMatrixReduced(const CLNAMethod *lnaMethod)