COPASI API  4.16.103
CObjectLists.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/model/CObjectLists.cpp,v $
3 // $Revision: 1.28 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/04/19 14:42:58 $
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 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
20 // Properties, Inc. and EML Research, gGmbH.
21 // All rights reserved.
22 
23 #include "copasi.h"
24 
25 #include "CObjectLists.h"
26 #include "report/CCopasiObject.h"
27 #include "model/CModel.h"
28 #include "report/CKeyFactory.h"
31 
32 
33 //static
34 const std::string CObjectLists::ListTypeName[] =
35 {
36  "Not Set", // EMPTY_LIST = 0
37  "Single Object", // SINGLE_OBJECT
38 
39  "Species", // METABS
40  "Initial Concentrations", // METAB_INITIAL_CONCENTRATIONS
41  "Initial Numbers", // METAB_INITIAL_NUMBERS
42  "Concentrations of Species", // METAB_CONCENTRATIONS
43  "Numbers of Species", // METAB_NUMBERS
44  "Non-Constant Concentrations of Species", // NON_CONST_METAB_CONCENTRATIONS
45  "Non-Constant Numbers of Species", // NON_CONST_METAB_NUMBERS,
46  "Constant Concentrations of Species", // CONST_METAB_CONCENTRATIONS,
47  "Constant Numbers of Species", // CONST_METAB_NUMBERS,
48  "Concentrations of Species with ODE", // ODE_METAB_CONCENTRATIONS,
49  "Numbers of Species with ODE", // ODE_METAB_NUMBERS,
50  "Concentrations of Species determined by Reactions", // REACTION_METAB_CONCENTRATIONS,
51  "Numbers of Species determined by Reactions", // REACTION_METAB_NUMBERS,
52  "Concentrations of Species with Assignment", // ASS_METAB_CONCENTRATIONS,
53  "Numbers of Species with Assignment", // ASS_METAB_NUMBERS,
54  "Concentration Rates", // METAB_CONC_RATES
55  "Particle Rates", // METAB_PART_RATES
56  "Transition Time", // METAB_TRANSITION_TIME,
57 
58  "Reactions", // REACTIONS
59  "Concentration Fluxes of Reactions", // REACTION_CONC_FLUXES
60  "Particle Fluxes of Reactions", // REACTION_PART_FLUXES,
61 
62  "Global Quantity", // GLOBAL_PARAMETERS
63  "Global Quantity Initial Values", // GLOBAL_PARAMETER_INITIAL_VALUES
64  "Global Quantity Values", // GLOBAL_PARAMETER_VALUES
65  "Non-Constant Global Quantity Values", // NON_CONST_GLOBAL_PARAMETER_VALUES
66  "Constant Global Quantity Values", // CONST_GLOBAL_PARAMETER_VALUES
67  "Values of Global Quantities with ODE", // ODE_GLOBAL_PARAMETER_VALUES
68  "Values of Global Quantities with Assignment", // ASS_GLOBAL_PARAMETER_VALUES
69  "Global Quantity Rates", // GLOBAL_PARAMETER_RATES
70 
71  "Compartments", // COMPARTMENTS
72  "Compartment Initial Volumes", // COMPARTMENT_INITIAL_VOLUMES
73  "Compartment Volumes", // COMPARTMENT_VOLUMES
74  "Non-Constant Compartment Volumes", // NON_CONST_COMPARTMENT_VOLUMES
75  "Constant Compartment Volumes", // CONST_COMPARTMENT_VOLUMES
76  "Values of Compartment Volumes with ODE", // ODE_COMPARTMENT_VOLUMES
77  "Values of Compartment Volumes with Assignment", // ASS_COMPARTMENT_VOLUMES
78  "Compartment Volume Rates", // COMPARTMENT_RATES
79 
80  "All initial Values", // ALL_INITIAL_VALUES
81  "Local Parameter Values", // ALL_LOCAL_PARAMETER_VALUES
82 
83  "All Parameter Values", // ALL_PARAMETER_VALUES
84  "All Parameter and Initial Values", // ALL_PARAMETER_AND_INITIAL_VALUES
85 
86  "All Variables of the model", // ALL_VARIABLES
87  "All independent Variables of the model", // ALL_ODE_VARIABLES
88 
89  "Real part of eigenvalues of the reduced jacobian", //REDUCED_JACOBIAN_EV_RE
90  "Imaginary part of eigenvalues of the reduced jacobian", //REDUCED_JACOBIAN_EV_IM
91 
92  "" // End of the list do not remove!
93 };
94 
95 //static
96 std::vector<CCopasiObject*>
98 {
99  std::vector< const CCopasiObject * > src = getListOfConstObjects(t, model);
100  std::vector< CCopasiObject * > target;
101  target.resize(src.size());
102 
103  std::vector< const CCopasiObject * >::iterator itSrc = src.begin();
104  std::vector< const CCopasiObject * >::iterator endSrc = src.end();
105  std::vector< CCopasiObject * >::iterator itTarget = target.begin();
106 
107  for (; itSrc != endSrc; ++itSrc, ++itTarget)
108  *itTarget = const_cast< CCopasiObject * >(*itSrc);
109 
110  return target;
111 
112  //I know this is unnecessary copying. But I want to avoid reinterpret_cast
113 }
114 
115 //static
116 std::vector<const CCopasiObject*>
118 {
119  ObjectList ret;
120 
123 
126 
129 
132 
133  std::set< const CModelEntity * > EventTargets = getEventTargets(pModel);
134 
135  switch (t)
136  {
137  case EMPTY_LIST:
138  case SINGLE_OBJECT:
139  break;
140 
141  // Metabolites
142  case METABS:
143 
144  for (; itMetab != endMetab; ++itMetab)
145  ret.push_back(*itMetab);
146 
147  break;
148 
150 
151  for (; itMetab != endMetab; ++itMetab)
152  if ((*itMetab)->getStatus() != CModelEntity::ASSIGNMENT)
153  ret.push_back((*itMetab)->getInitialConcentrationReference());
154 
155  break;
156 
158 
159  for (; itMetab != endMetab; ++itMetab)
160  if ((*itMetab)->getStatus() != CModelEntity::ASSIGNMENT)
161  ret.push_back((*itMetab)->getInitialValueReference());
162 
163  break;
164 
166 
167  for (; itMetab != endMetab; ++itMetab)
168  ret.push_back((*itMetab)->getConcentrationReference());
169 
170  break;
171 
172  case METAB_NUMBERS:
173 
174  for (; itMetab != endMetab; ++itMetab)
175  ret.push_back((*itMetab)->getValueReference());
176 
177  break;
178 
180 
181  for (; itMetab != endMetab; ++itMetab)
182  if ((*itMetab)->getStatus() != CModelEntity::FIXED ||
183  EventTargets.count(*itMetab) > 0)
184  ret.push_back((*itMetab)->getConcentrationReference());
185 
186  break;
187 
189 
190  for (; itMetab != endMetab; ++itMetab)
191  if ((*itMetab)->getStatus() != CModelEntity::FIXED ||
192  EventTargets.count(*itMetab) > 0)
193  ret.push_back((*itMetab)->getValueReference());
194 
195  break;
196 
198 
199  for (; itMetab != endMetab; ++itMetab)
200  if ((*itMetab)->getStatus() == CModelEntity::FIXED)
201  ret.push_back((*itMetab)->getConcentrationReference());
202 
203  break;
204 
205  case CONST_METAB_NUMBERS:
206 
207  for (; itMetab != endMetab; ++itMetab)
208  if ((*itMetab)->getStatus() == CModelEntity::FIXED)
209  ret.push_back((*itMetab)->getValueReference());
210 
211  break;
212 
214 
215  for (; itMetab != endMetab; ++itMetab)
216  if ((*itMetab)->getStatus() == CModelEntity::ODE)
217  ret.push_back((*itMetab)->getConcentrationReference());
218 
219  break;
220 
221  case ODE_METAB_NUMBERS:
222 
223  for (; itMetab != endMetab; ++itMetab)
224  if ((*itMetab)->getStatus() == CModelEntity::ODE)
225  ret.push_back((*itMetab)->getValueReference());
226 
227  break;
228 
230 
231  for (; itMetab != endMetab; ++itMetab)
232  if ((*itMetab)->getStatus() == CModelEntity::REACTIONS)
233  ret.push_back((*itMetab)->getConcentrationReference());
234 
235  break;
236 
238 
239  for (; itMetab != endMetab; ++itMetab)
240  if ((*itMetab)->getStatus() == CModelEntity::REACTIONS)
241  ret.push_back((*itMetab)->getValueReference());
242 
243  break;
244 
246 
247  for (; itMetab != endMetab; ++itMetab)
248  if ((*itMetab)->getStatus() == CModelEntity::ASSIGNMENT)
249  ret.push_back((*itMetab)->getConcentrationReference());
250 
251  break;
252 
253  case ASS_METAB_NUMBERS:
254 
255  for (; itMetab != endMetab; ++itMetab)
256  if ((*itMetab)->getStatus() == CModelEntity::ASSIGNMENT)
257  ret.push_back((*itMetab)->getValueReference());
258 
259  break;
260 
261  case METAB_CONC_RATES:
262 
263  for (; itMetab != endMetab; ++itMetab)
264  if ((*itMetab)->getStatus() == CModelEntity::ODE ||
265  (*itMetab)->getStatus() == CModelEntity::REACTIONS)
266  ret.push_back((*itMetab)->getConcentrationRateReference());
267 
268  break; //not possible at the moment
269 
270  case METAB_PART_RATES:
271 
272  for (; itMetab != endMetab; ++itMetab)
273  if ((*itMetab)->getStatus() == CModelEntity::ODE ||
274  (*itMetab)->getStatus() == CModelEntity::REACTIONS)
275  ret.push_back((*itMetab)->getRateReference());
276 
277  break;
278 
280 
281  for (; itMetab != endMetab; ++itMetab)
282  if ((*itMetab)->getStatus() == CModelEntity::ODE ||
283  (*itMetab)->getStatus() == CModelEntity::REACTIONS)
284  ret.push_back(static_cast< const CCopasiObject * >((*itMetab)->getObject(CCopasiObjectName("Reference=TransitionTime"))));
285 
286  break;
287 
288  // reactions
289  case REACTIONS:
290 
291  for (; itReaction != endReaction; ++itReaction)
292  ret.push_back(*itReaction);
293 
294  break;
295 
297 
298  for (; itReaction != endReaction; ++itReaction)
299  ret.push_back(static_cast< const CCopasiObject * >((*itReaction)->getObject(CCopasiObjectName("Reference=Flux"))));
300 
301  break;
302 
304 
305  for (; itReaction != endReaction; ++itReaction)
306  ret.push_back(static_cast< const CCopasiObject * >((*itReaction)->getObject(CCopasiObjectName("Reference=ParticleFlux"))));
307 
308  break;
309 
310  // global quantities
311  case GLOBAL_PARAMETERS:
312 
313  for (; itValue != endValue; ++itValue)
314  ret.push_back(*itValue);
315 
316  break;
317 
319 
320  for (; itValue != endValue; ++itValue)
321  if ((*itValue)->getStatus() != CModelEntity::ASSIGNMENT)
322  ret.push_back((*itValue)->getInitialValueReference());
323 
324  break;
325 
327 
328  for (; itValue != endValue; ++itValue)
329  ret.push_back((*itValue)->getValueReference());
330 
331  break;
332 
334 
335  for (; itValue != endValue; ++itValue)
336  if ((*itValue)->getStatus() != CModelEntity::FIXED ||
337  EventTargets.count(*itValue) > 0)
338  ret.push_back((*itValue)->getValueReference());
339 
340  break;
341 
343 
344  for (; itValue != endValue; ++itValue)
345  if ((*itValue)->getStatus() == CModelEntity::FIXED)
346  ret.push_back((*itValue)->getInitialValueReference());
347 
348  break;
349 
351 
352  for (; itValue != endValue; ++itValue)
353  if ((*itValue)->getStatus() == CModelEntity::ODE)
354  ret.push_back((*itValue)->getValueReference());
355 
356  break;
357 
359 
360  for (; itValue != endValue; ++itValue)
361  if ((*itValue)->getStatus() == CModelEntity::ASSIGNMENT)
362  ret.push_back((*itValue)->getValueReference());
363 
364  break;
365 
367 
368  for (; itValue != endValue; ++itValue)
369  if ((*itValue)->getStatus() == CModelEntity::ODE)
370  ret.push_back((*itValue)->getRateReference());
371 
372  break;
373 
374  // compartments
375  case COMPARTMENTS:
376 
377  for (; itComp != endComp; ++itComp)
378  ret.push_back(*itComp);
379 
380  break;
381 
383 
384  for (; itComp != endComp; ++itComp)
385  if ((*itComp)->getStatus() != CModelEntity::ASSIGNMENT)
386  ret.push_back((*itComp)->getInitialValueReference());
387 
388  break;
389 
390  case COMPARTMENT_VOLUMES:
391 
392  for (; itComp != endComp; ++itComp)
393  ret.push_back((*itComp)->getValueReference());
394 
395  break;
396 
398 
399  for (; itComp != endComp; ++itComp)
400  if ((*itComp)->getStatus() != CModelEntity::FIXED ||
401  EventTargets.count(*itComp) > 0)
402  ret.push_back((*itComp)->getValueReference());
403 
404  break;
405 
407 
408  for (; itComp != endComp; ++itComp)
409  if ((*itComp)->getStatus() == CModelEntity::FIXED)
410  ret.push_back((*itComp)->getValueReference());
411 
412  break;
413 
415 
416  for (; itComp != endComp; ++itComp)
417  if ((*itComp)->getStatus() == CModelEntity::ODE)
418  ret.push_back((*itComp)->getValueReference());
419 
420  break;
421 
423 
424  for (; itComp != endComp; ++itComp)
425  if ((*itComp)->getStatus() == CModelEntity::ASSIGNMENT)
426  ret.push_back((*itComp)->getValueReference());
427 
428  break;
429 
430  case COMPARTMENT_RATES:
431 
432  for (; itComp != endComp; ++itComp)
433  if ((*itComp)->getStatus() == CModelEntity::ODE)
434  ret.push_back((*itComp)->getRateReference());
435 
436  break;
437 
438  case ALL_INITIAL_VALUES:
439  {
441 
443  ret.insert(ret.end(), tmp.begin(), tmp.end());
444 
446  ret.insert(ret.end(), tmp.begin(), tmp.end());
447  }
448  break;
449 
451  {
452  for (; itReaction != endReaction; ++itReaction)
453  {
454  const CFunctionParameters & params = (*itReaction)->getFunctionParameters();
455  size_t j, jmax = params.size();
456 
457  for (j = 0; j < jmax; ++j)
458  if (params[j]->getUsage() == CFunctionParameter::PARAMETER)
459  if ((*itReaction)->isLocalParameter(j))
460  {
461  CCopasiParameter * par =
462  dynamic_cast<CCopasiParameter*>
463  (CCopasiRootContainer::getKeyFactory()->get((*itReaction)->getParameterMappings()[j][0]));
464 
465  if (par)
466  ret.push_back(par->getValueReference());
467  }
468  }
469  }
470  break;
471 
473  {
475 
477  ret.insert(ret.end(), tmp.begin(), tmp.end());
478  }
479  break;
480 
482  {
484 
486  ret.insert(ret.end(), tmp.begin(), tmp.end());
487  }
488  break;
489 
490  case ALL_VARIABLES:
491  {
493 
495  ret.insert(ret.end(), tmp.begin(), tmp.end());
496 
498  ret.insert(ret.end(), tmp.begin(), tmp.end());
499  }
500  break;
501 
503  {
504  CCopasiContainer * pParent = dynamic_cast<CCopasiContainer*>(pModel->getObjectParent());
505 
506  if (!pParent)
507  break;
508 
509  const CArrayAnnotation * pEV = dynamic_cast<const CArrayAnnotation*>(pParent->getObject(CCopasiObjectName("Vector=TaskList[Steady-State],Array=Eigenvalues of reduced system Jacobian")));
510 
511  if (pEV->dimensionality() != 2) //2d matrix
512  break;
513 
514  if (pEV->size()[1] != 2) //must be two columns for Re and Im part
515  break;
516 
517  size_t imax = pEV->size()[0];
518  size_t i;
519 
520  for (i = 0; i < imax; ++i)
521  ret.push_back(static_cast< const CCopasiObject * >(pEV->addElementReference(i, 0)));
522  }
523  break;
524 
526  {
527  CCopasiContainer * pParent = dynamic_cast<CCopasiContainer*>(pModel->getObjectParent());
528 
529  if (!pParent)
530  break;
531 
532  const CArrayAnnotation * pEV = dynamic_cast<const CArrayAnnotation*>(pParent->getObject(CCopasiObjectName("Vector=TaskList[Steady-State],Array=Eigenvalues of reduced system Jacobian")));
533 
534  if (pEV->dimensionality() != 2) //2d matrix
535  break;
536 
537  if (pEV->size()[1] != 2) //must be two columns for Re and Im part
538  break;
539 
540  size_t imax = pEV->size()[0];
541  size_t i;
542 
543  for (i = 0; i < imax; ++i)
544  ret.push_back(static_cast< const CCopasiObject * >(pEV->addElementReference(i, 1)));
545 
546  }
547  break;
548 
549  default:
550  break;
551  }
552 
553  return ret;
554 }
555 
556 //static
558 {
559  bool fixedMetab = false;
560  const CCopasiVector< CMetab > & metabs = pModel->getMetabolites();
561  size_t i, imax = metabs.size();
562 
563  for (i = 0; i < imax; ++i)
564  if (metabs[i]->getStatus() == CModelEntity::FIXED)
565  {fixedMetab = true; break;}
566 
567  return fixedMetab;
568 }
569 
570 // static
571 std::set< const CModelEntity * > CObjectLists::getEventTargets(const CModel* pModel)
572 {
573  std::set< const CModelEntity * > EventTargets;
574 
576 
579 
580  for (; itEvent != endEvent; ++itEvent)
581  {
583  (*itEvent)->getAssignments().begin();
585  (*itEvent)->getAssignments().end();
586 
587  for (; itAssignment != endAssignment; ++itAssignment)
588  {
589  const CModelEntity * pModelEntity =
590  dynamic_cast< const CModelEntity * >(pKeyFactory->get((*itAssignment)->getObjectName()));
591 
592  if (pModelEntity != NULL)
593  {
594  EventTargets.insert(pModelEntity);
595  }
596  }
597  }
598 
599  return EventTargets;
600 }
CCopasiVectorN< CEvent > & getEvents()
Definition: CModel.cpp:1110
static std::vector< const CCopasiObject * > getListOfConstObjects(ListType t, const CModel *model)
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
virtual size_t size() const
CCopasiObject * get(const std::string &key)
static bool existsFixedMetab(const CModel *model)
iterator begin()
CCopasiObject * getValueReference() const
std::vector< const CCopasiObject * > ObjectList
Definition: CObjectLists.h:118
iterator end()
std::vector< CType * >::const_iterator const_iterator
Definition: CCopasiVector.h:57
static const std::string ListTypeName[]
Definition: CObjectLists.h:98
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
static CKeyFactory * getKeyFactory()
Header file of class CArrayAnnotation.
static std::vector< CCopasiObject * > getListOfObjects(ListType t, const CModel *model)
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
const CObjectInterface * addElementReference(CCopasiAbstractArray::index_type index) const
Definition: CModel.h:50
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
CCopasiAbstractArray::index_type size() const
size_t dimensionality() const
static std::set< const CModelEntity * > getEventTargets(const CModel *pModel)
CCopasiContainer * getObjectParent() const