COPASI API  4.16.103
CCompartment.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) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 // CCompartment
16 //
17 // Derived from Gepasi's ccompart.cpp
18 // (C) Pedro Mendes 1995-2000
19 //
20 // Converted for COPASI by Pedro Mendes
21 
22 #include <iostream>
23 #include <cmath>
24 
25 #include "copasi.h"
26 #include "utilities/CReadConfig.h"
28 #include "utilities/utility.h"
30 #include "report/CKeyFactory.h"
31 #include "report/CRenameHandler.h"
32 #include "CCompartment.h"
33 #include "CModel.h"
35 
36 CCompartment::CCompartment(const std::string & name,
37  const CCopasiContainer * pParent):
38  CModelEntity(name, pParent, "Compartment"),
39  mMetabolites("Metabolites", this),
40  mDimensionality(3)
41 {
42  initObjects();
43 
44  mKey = CCopasiRootContainer::getKeyFactory()->add("Compartment", this);
45 
47 
48  *mpIValue = 1.0;
49 
51 }
52 
54  const CCopasiContainer * pParent):
55  CModelEntity(src, pParent),
56  mMetabolites(src.mMetabolites, this),
57  mDimensionality(src.mDimensionality)
58 {
59  mKey = CCopasiRootContainer::getKeyFactory()->add("Compartment", this);
61  initObjects();
62 }
63 
65 {
68 }
69 
70 // virtual
71 std::string CCompartment::getChildObjectUnits(const CCopasiObject * pObject) const
72 {
73  if (mpModel == NULL) return "";
74 
75  if (pObject == mpValueReference ||
76  pObject == mpIValueReference)
77  {
78  switch (mDimensionality)
79  {
80  case 1:
82  break;
83 
84  case 2:
86  break;
87 
88  case 3:
90  break;
91 
92  default:
93  return "";
94  break;
95  }
96  }
97  else if (pObject == mpRateReference)
98  {
99  std::string Unit = getChildObjectUnits(mpValueReference);
100  std::string TimeUnit = mpModel->getTimeUnitsDisplayString();
101 
102  if (Unit == "")
103  {
104  if (TimeUnit == "")
105  {
106  return "";
107  }
108 
109  return "1/" + TimeUnit;
110  }
111 
112  if (TimeUnit == "")
113  {
114  return Unit;
115  }
116 
117  return Unit + "/" + TimeUnit;
118  }
119 
120  return "";
121 }
122 
124 
125 std::set< const CCopasiObject * > CCompartment::getDeletedObjects() const
126 {
127  std::set< const CCopasiObject * > Deleted = CModelEntity::getDeletedObjects();
128 
129  // We must not add the metabolites as CModel::appendDependentMetabolites does that.
130 
131  return Deleted;
132 }
133 
135 {
136  C_INT32 Fail = 0;
137  std::string tmp;
138 
139  if ((Fail = configbuffer.getVariable("Compartment", "string",
140  (void *) & tmp,
142  return Fail;
143 
144  setObjectName(tmp);
145 
146  C_FLOAT64 tmpdbl;
147 
148  if ((Fail = configbuffer.getVariable("Volume", "C_FLOAT64",
149  (void *) & tmpdbl)))
150  return Fail;
151 
152  setInitialValue(tmpdbl);
153 
154  return Fail;
155 }
156 
158 {return mMetabolites;}
159 
161 {return mMetabolites;}
162 
163 /* Note: the metabolite stored in mMetabolites has definitely mpCompartment set.
164  In the case the compartment is part of a model also mpModel is set. */
165 bool CCompartment::createMetabolite(const CMetab & metabolite)
166 {
167  CMetab * pMetab = new CMetab(metabolite);
168 
169  if (addMetabolite(pMetab)) return true;
170 
171  delete pMetab;
172  return false;
173 }
174 
176 {
177  if (!pMetabolite) return false;
178 
179  std::string oldCN = pMetabolite->getCN();
180 
181  bool success = mMetabolites.add(pMetabolite, true);
182 
183  //if a metabolite is added to a compartment successfully the CN of
184  //the metabolite is changed. This needs to be handled similarly to a
185  //rename.
186  if (success && smpRenameHandler && getObjectParent())
187  {
188  std::string newCN = pMetabolite->getCN();
189  smpRenameHandler->handle(oldCN, newCN);
190  }
191 
192  return success;
193 }
194 
196 {
197  if (dim > 3)
198  return false;
199 
200  mDimensionality = dim;
201  return true;
202 }
203 
205 {
206  return mDimensionality;
207 }
208 
210 {
211  mpIValueReference->setObjectName("InitialVolume");
212  mpValueReference->setObjectName("Volume");
213 }
214 
215 std::ostream & operator<<(std::ostream &os, const CCompartment & d)
216 {
217  os << "++++CCompartment: " << d.getObjectName() << " mValue " << *d.mpValue;
218  os << " CCompartment.mMetabolites " << std::endl << d.mMetabolites;
219  os << "----CCompartment " << std::endl;
220 
221  return os;
222 }
bool remove(const std::string &key)
CCopasiObjectReference< C_FLOAT64 > * mpIValueReference
Definition: CModelValue.h:356
bool addMetabolite(CMetab *metabolite)
CCopasiVectorNS< CMetab > & getMetabolites()
void initObjects()
std::string getTimeUnitsDisplayString() const
Definition: CModel.cpp:4531
virtual CCopasiObjectName getCN() const
const std::string & getObjectName() const
bool setDimensionality(unsigned C_INT32 dim)
virtual void handle(const std::string &oldCN, const std::string &newCN) const =0
C_INT32 load(CReadConfig &configbuffer)
unsigned C_INT32 getDimensionality() const
C_FLOAT64 * mpValue
Definition: CModelValue.h:321
static CRenameHandler * smpRenameHandler
CCopasiObjectReference< C_FLOAT64 > * mpRateReference
Definition: CModelValue.h:358
#define C_INT32
Definition: copasi.h:90
Definition: CMetab.h:178
virtual std::set< const CCopasiObject * > getDeletedObjects() const
C_FLOAT64 * mpIValue
Definition: CModelValue.h:326
std::string mKey
Definition: CAnnotation.h:119
virtual std::string getChildObjectUnits(const CCopasiObject *pObject) const
#define DESTRUCTOR_TRACE
Definition: copasi.h:206
std::string getLengthUnitsDisplayString() const
Definition: CModel.cpp:4563
virtual ~CCompartment()
virtual bool add(const CType &src)
CCompartment(const std::string &name="NoName", const CCopasiContainer *pParent=NULL)
std::string getVolumeUnitsDisplayString() const
Definition: CModel.cpp:4547
CCopasiVectorNS< CMetab > mMetabolites
Definition: CCompartment.h:45
virtual void setStatus(const CModelEntity::Status &status)
virtual void cleanup()
std::ostream & operator<<(std::ostream &os, const CCompartment &d)
CCopasiObjectReference< C_FLOAT64 > * mpValueReference
Definition: CModelValue.h:357
std::string add(const std::string &prefix, CCopasiObject *pObject)
virtual std::set< const CCopasiObject * > getDeletedObjects() const
static CKeyFactory * getKeyFactory()
#define C_FLOAT64
Definition: copasi.h:92
unsigned C_INT32 mDimensionality
Definition: CCompartment.h:155
bool createMetabolite(const CMetab &metabolite)
virtual void setInitialValue(const C_FLOAT64 &initialValue)
std::string getAreaUnitsDisplayString() const
Definition: CModel.cpp:4555
C_INT32 getVariable(const std::string &name, const std::string &type, void *pout, CReadConfig::Mode mode=CReadConfig::NEXT)
Definition: CReadConfig.cpp:81
bool setObjectName(const std::string &name)
CModel * mpModel
Definition: CModelValue.h:359
CCopasiContainer * getObjectParent() const
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202