COPASI API  4.16.103
CModelParameterSet.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 - 2014 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 #include "CModelParameterSet.h"
7 
8 #include "model/CModel.h"
9 #include "model/CCompartment.h"
11 #include "report/CKeyFactory.h"
14 
15 CModelParameterSet::CModelParameterSet(const std::string & name,
16  const CCopasiContainer * pParent):
17  CCopasiContainer(name, pParent, "ModelParameterSet"),
19  CAnnotation(),
20  mKey(CCopasiRootContainer::getKeyFactory()->add("ModelParameterSet", this)),
21  mpModel(NULL)
22 {
23  setObjectParent(pParent);
24 }
25 
27  const CCopasiContainer * pParent,
28  const bool & createMissing):
29  CCopasiContainer(src, pParent),
30  CModelParameterGroup(src, NULL, createMissing),
31  CAnnotation(src),
32  mKey(CCopasiRootContainer::getKeyFactory()->add("ModelParameterSet", this)),
33  mpModel(NULL)
34 {
35  setObjectParent(pParent);
36 
37  if (mpModel == NULL)
38  {
39  mpModel = src.getModel();
40  }
41 
42  compile();
43 }
44 
45 // virtual
47 {
49 }
50 
51 // virtual
52 const std::string & CModelParameterSet::getKey() const
53 {
54  return mKey;
55 }
56 
57 // virtual
59 {
60  bool success = CCopasiObject::setObjectParent(pParent);
61 
62  mpModel = dynamic_cast< CModel * >(getObjectAncestor("Model"));
63 
64  return success;
65 }
66 
67 // virtual
69 {
70  assert(mpModel != NULL);
71 
72  return mpModel;
73 }
74 
76 {
77  clear();
78 
79  if (mpModel == NULL)
80  {
81  return;
82  }
83 
84  CModelParameter * pParameter;
85  CModelParameterGroup * pGroup;
86 
87  // TODO CRITICAL Create the proper structure that fits the parameter overview in the GUI
88  pGroup = static_cast< CModelParameterGroup *>(CModelParameterGroup::add(Group));
89  pGroup->setCN(CCopasiStaticString("Initial Time").getCN());
90 
91  pParameter = pGroup->add(Model);
92  pParameter->setCN(mpModel->getCN());
94 
95  pGroup = static_cast< CModelParameterGroup *>(CModelParameterGroup::add(Group));
96  pGroup->setCN(CCopasiStaticString("Initial Compartment Sizes").getCN());
97 
100 
101  for (; itCompartment != endCompartment; ++itCompartment)
102  {
103  pParameter = pGroup->add(Compartment);
104  pParameter->setCN((*itCompartment)->getCN());
105  pParameter->setSimulationType((*itCompartment)->getStatus());
106  pParameter->setValue((*itCompartment)->getInitialValue(), ParticleNumbers);
107  pParameter->setInitialExpression((*itCompartment)->getInitialExpression());
108  }
109 
110  pGroup = static_cast< CModelParameterGroup *>(CModelParameterGroup::add(Group));
111  pGroup->setCN(CCopasiStaticString("Initial Species Values").getCN());
112 
115 
116  for (; itSpecies != endSpecies; ++itSpecies)
117  {
118  pParameter = pGroup->add(Species);
119  pParameter->setCN((*itSpecies)->getCN());
120  pParameter->setSimulationType((*itSpecies)->getStatus());
121  pParameter->setValue((*itSpecies)->getInitialValue(), ParticleNumbers);
122  pParameter->setInitialExpression((*itSpecies)->getInitialExpression());
123  }
124 
125  pGroup = static_cast< CModelParameterGroup *>(CModelParameterGroup::add(Group));
126  pGroup->setCN(CCopasiStaticString("Initial Global Quantities").getCN());
127 
130 
131  for (; itModelValue != endModelValue; ++itModelValue)
132  {
133  pParameter = pGroup->add(ModelValue);
134  pParameter->setCN((*itModelValue)->getCN());
135  pParameter->setSimulationType((*itModelValue)->getStatus());
136  pParameter->setValue((*itModelValue)->getInitialValue(), ParticleNumbers);
137  pParameter->setInitialExpression((*itModelValue)->getInitialExpression());
138  }
139 
140  pGroup = static_cast< CModelParameterGroup *>(CModelParameterGroup::add(Group));
141  pGroup->setCN(CCopasiStaticString("Kinetic Parameters").getCN());
142 
145 
146  for (; itReaction != endReaction; ++itReaction)
147  {
148  CModelParameterGroup * pReaction = static_cast< CModelParameterGroup *>(pGroup->add(Reaction));
149  pReaction->setCN((*itReaction)->getCN());
150 
151  CCopasiParameterGroup::index_iterator itParameter = (*itReaction)->getParameters().beginIndex();
152  CCopasiParameterGroup::index_iterator endParameter = (*itReaction)->getParameters().endIndex();
153 
154  for (; itParameter != endParameter; ++itParameter)
155  {
156  pParameter = pReaction->add(ReactionParameter);
157  pParameter->setCN((*itParameter)->getCN());
158 
159  // Check whether this refers to a global quantity.
160  if ((*itReaction)->isLocalParameter((*itParameter)->getObjectName()))
161  {
163  pParameter->setValue(*(*itParameter)->getValue().pDOUBLE, ParticleNumbers);
164  }
165  else
166  {
168  const std::vector<std::string> ModelValue = (*itReaction)->getParameterMapping((*itParameter)->getObjectName());
169 
170  if (ModelValue.size() != 1) fatalError();
171 
172  const CModelValue * pModelValue = static_cast< CModelValue * >(CCopasiRootContainer::getKeyFactory()->get(ModelValue[0]));
173 
174  if (pModelValue == NULL) fatalError();
175 
176  pParameter->setValue(pModelValue->getInitialValue(), ParticleNumbers);
177  pParameter->setInitialExpression("<" + pModelValue->getInitialValueReference()->getCN() + ">");
178  }
179  }
180  }
181 
182  compile();
183 }
184 
186 {
187  if (mpModel == NULL)
188  {
189  return false;
190  }
191 
192  CModelParameterSet Tmp("Current", mpModel);
193  Tmp.createFromModel();
194 
195  return (diff(Tmp, framework, true) == CModelParameter::Identical);
196 }
197 
198 // virtual
199 std::string CModelParameterSet::getName() const
200 {
201  return getObjectName();
202 }
203 
204 // virtual
206 {
207  if (mpModel == NULL)
208  {
209  return false;
210  }
211 
212  compile();
213 
214  bool success = CModelParameterGroup::updateModel();
215 
217 
218  return success;
219 }
220 
222 {
223  if (mpModel == NULL)
224  {
225  return false;
226  }
227 
228  return (mpModel->getModelParameterSet().getKey() == mKey);
229 }
230 
232  const bool & createMissing)
233 {
234  assignGroupContent(src, createMissing);
235  compile();
236 }
237 
238 bool CModelParameterSet::saveToStream(std::ostream & os,
239  const CModelParameter::Framework & framework,
240  const std::string & mode,
241  const std::string & separator)
242 {
243  bool success = true;
244 
246 
247  if (mode == "report")
248  {
250 
251  while (itNode.next() != itNode.end())
252  {
253  if (*itNode != NULL)
254  {
255  for (unsigned int i = 1; i < itNode.level(); i++)
256  {
257  os << separator;
258  }
259 
260  os << itNode->getName();
261 
262  for (unsigned int i = itNode.level(); i < 6; i++)
263  {
264  os << separator;
265  }
266 
267  if (itNode->getType() != Group &&
268  itNode->getType() != Set)
269  {
270  os << itNode->getValue(framework) << " " << itNode->getUnit(framework);
271  }
272 
273  os << std::endl;
274  }
275  }
276  }
277  else if (mode == "table")
278  {
280 
281  while (itNode.next() != itNode.end())
282  {
283  if (*itNode != NULL)
284  {
285  if (itNode->getType() != Group &&
286  itNode->getType() != Set)
287  {
288  os << itNode->getName() << " " << itNode->getUnit(framework) << separator;
289  }
290  }
291  }
292 
293  os << std::endl;
294 
297 
298  while (itNode.next() != itNode.end())
299  {
300  if (*itNode != NULL)
301  {
302  if (itNode->getType() != Group &&
303  itNode->getType() != Set)
304  {
305  os << itNode->getValue(framework) << separator;
306  }
307  }
308  }
309 
310  os << std::endl;
311  }
312  else
313  {
314  success = false;
315  }
316 
317  return success;
318 }
virtual bool setObjectParent(const CCopasiContainer *pParent)
CCopasiContainer * getObjectAncestor(const std::string &type) const
bool remove(const std::string &key)
const CModelParameterSet & getModelParameterSet() const
Definition: CModel.cpp:1072
virtual std::string getName() const
virtual std::string getName() const
virtual CCopasiObjectName getCN() const
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
bool compareWithModel(const CModelParameter::Framework &framework)
const std::string & getObjectName() const
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
CCopasiObject * get(const std::string &key)
CCopasiObject * getInitialValueReference() const
iterator begin()
#define fatalError()
const std::string getUnit(const Framework &framework) const
const CNodeIteratorMode::State & next()
const CCopasiObjectName & getCN() const
bool saveToStream(std::ostream &os, const CModelParameter::Framework &framework, const std::string &mode, const std::string &separator)
void setInitialExpression(const std::string &initialExpression)
const C_FLOAT64 & getInitialValue() const
iterator end()
std::vector< CType * >::const_iterator const_iterator
Definition: CCopasiVector.h:57
virtual void setValue(const double &value, const Framework &framework)
virtual const std::string & getKey() const
CModelParameterSet(const std::string &name, const CCopasiContainer *pParent=NULL)
virtual bool setObjectParent(const CCopasiContainer *pParent)
void assignGroupContent(const CModelParameterGroup &src, const bool &createMissing)
const C_FLOAT64 & getInitialTime() const
Definition: CModel.cpp:1184
virtual const double & getValue(const Framework &framework) const
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
void setProcessingModes(const CNodeIteratorMode::Flag &processingModes)
static CKeyFactory * getKeyFactory()
virtual const CompareResult & diff(const CModelParameter &other, const CModelParameter::Framework &framework, const bool &createMissing=false)
virtual void setCN(const CCopasiObjectName &cn)
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
bool updateInitialValues()
Definition: CModel.cpp:1461
Definition: CModel.h:50
const Type & getType() const
CNodeIteratorMode::State end() const
bool setSimulationType(const CModelEntity::Status &simulationType)
CModelParameter * add(const CModelParameter::Type &type)
parameterGroup::iterator index_iterator
void assignSetContent(const CModelParameterSet &src, const bool &createMissing)
virtual bool updateModel()
CModel * getModel() const