COPASI API  4.16.103
CReactionInterface.h
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/model/CReactionInterface.h,v $
3 // $Revision: 1.23 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/05/09 21:26:57 $
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 #ifndef CREACTIONINTERFACE_H
24 #define CREACTIONINTERFACE_H
25 
26 #include <vector>
27 #include <string>
28 #include "copasi.h"
29 //#include "model/CChemEq.h"
30 #include "model/CReaction.h"
31 #include "model/CChemEqInterface.h"
32 #include "function/CFunction.h"
33 
34 //class CFunction;
35 class CModel;
36 
37 /**
38  * This class provides an interface for dealing with reactions.
39  * For representing the parameter mappings it uses object names.
40  * A CReactionInterface allows editing a reaction while trying to
41  * keep everything consistent.
42  *
43  * Note: Many of the methods need to be provided with a model.
44  * While handling of the metabolites is completely independent of the
45  * model (they are handled by name, and they don't need to exist),
46  * the mapping of Compartments and global parameters is done with
47  * the entities that exist in the model. This may seem inconsistent,
48  * but the idea is that metabolites can be created from the gui by entering
49  * them into the reaction equation. Compartments and global parameters
50  * can only be chosen from the list of existing objects.
51  */
53 {
54 private:
56 
57  std::string emptyString;
58 
59  /**
60  * This is the key that identifies the Reaction that is beeing edited
61  */
62  std::string mReactionReferenceKey;
63 
64  /**
65  * A copy of the chemical equation of the reaction
66  */
68 
69  /**
70  * A pointer to the kinetic function of the reaction
71  */
73 
74  /**
75  * A copy of the function parameters
76  */
78 
79  /**
80  * what metabolite for what function parameter
81  */
82  std::vector< std::vector< std::string > > mNameMap;
83 
84  /**
85  * values of the kinetic parameters
86  */
87  std::vector< C_FLOAT64 > mValues;
88 
89  /**
90  * values of the kinetic parameters
91  */
92  std::vector<bool> mIsLocal;
93 
94 private:
96 
97 public:
98  CReactionInterface(CModel * pModel);
99 
101 
102  /**
103  * set a new chemical equation.
104  * newFunction suggests a new kinetic function which is only used if adequate.
105  */
106  void setChemEqString(const std::string & eq, const std::string & newFunction);
107 
108  std::string getChemEqString() const {return mChemEqI.getChemEqString(false);};
109 
110  const CChemEqInterface & getChemEqInterface() const {return mChemEqI;};
111 
112  bool isReversible() const {return mChemEqI.getReversibility();};
113 
114  /**
115  * this method tries to find out if the REACTION involves several compartments
116  * It only takes into account the metabs that
117  * actually exist in the model. A non existing metabolite is assumed
118  * not to be in a different compartment
119  */
120  bool isMulticompartment() const;
121 
122  /**
123  * set the reversibility.
124  * newFunction suggests a new kinetic function which is only used if adequate.
125  */
126  void setReversibility(bool rev, const std::string & newFunction);
127 
128  /**
129  * reverse the reaction and set the reversibility.
130  * newFunction suggests a new kinetic function which is only used if adequate.
131  */
132  void reverse(bool rev, const std::string & newFunction);
133 
134  /**
135  * This produces a list of metab names (from the chem eq) for use in
136  * the combo boxes. The role must be given like a usage, e.g. "SUBSTRATE".
137  */
138  const std::vector<std::string> & getListOfMetabs(CFunctionParameter::Role role) const;
139 
140  /**
141  * set the function. an empty mapping is created
142  */
143  void setFunctionWithEmptyMapping(const std::string & fn);
144 
145  /**
146  * set the function.
147  * a new mapping is created that tries to preserve as much information as
148  * possible from the old mapping. Then a default mapping is set from
149  * the chemical equation and the model (if possible).
150  */
151  void setFunctionAndDoMapping(const std::string & fn);
152 
153  const std::string & getFunctionName() const
154  {if (mpFunction) return mpFunction->getObjectName(); else return emptyString;};
155 
156  const std::string & getFunctionDescription() const
157  {if (mpFunction) return mpFunction->getInfix(); else return emptyString;};
158 
159  const CFunction * getFunction() const
160  {return mpFunction;}
161 
162  std::vector< std::string > getListOfPossibleFunctions() const;
163 
164  //query information about the function variables
165 
166  size_t size() const
167  {if (mpFunction) return mpParameters->size(); else return 0;};
168 
169  bool isVector(size_t index) const
170  {
171  if (mpFunction) return ((*mpParameters)[index]->getType() == CFunctionParameter::VFLOAT64);
172  else return (false);
173  }
174 
175  CFunctionParameter::Role getUsage(size_t index) const
176  {
177  if (mpFunction) return (*mpParameters)[index]->getUsage();
178  else return CFunctionParameter::VARIABLE;
179  }
180 
181  std::string getParameterName(size_t index) const
182  {
183  if (mpFunction) return (*mpParameters)[index]->getObjectName();
184  else return emptyString;
185  }
186 
187  // set/get the mapping
188 
189  void setMapping(size_t index, std::string mn);
190 
191  void removeMapping(size_t index, std::string mn);
192 
193  const std::vector< std::string > & getMappings(size_t index) const
194  {return mNameMap[index];}
195 
196  const std::string & getMapping(size_t index) const
197  {
198  assert(!isVector(index));
199  return mNameMap[index][0];
200  }
201 
202  void setLocalValue(size_t index, C_FLOAT64 value)
203  {
204  mValues[index] = value;
205  mIsLocal[index] = true;
206  }
207 
208  void setLocal(size_t index)
209  {
210  mIsLocal[index] = true;
211  }
212 
213  const C_FLOAT64 & getLocalValue(size_t index) const {return mValues[index];}
214 
215  bool isLocalValue(size_t index) const {return mIsLocal[index];};
216 
217  /**
218  * associate the function parameter referenced by "index" with the global
219  * parameter named pn. Only valid if the role for this function parameter is "PARAMETER".
220  * returns success
221  */
222  //bool setGlobalParameter(size_t index, std::string pn);
223 
224  //const std::string & getGlobalParameter(size_t index) const;
225 
226  //bool setCompartment(size_t index, std::string pn);
227 
228  //const std::string & getCompartment(size_t index) const;
229 
230  void initFromReaction(const std::string & key);
231  void initFromReaction(const C_INT32 index);
232  void initFromReaction(const CReaction* rea);
233 
234  /**
235  * writes the information back to a CReaction.
236  * createMetabolites() and createOtherObjects() should be called before.
237  */
238  bool writeBackToReaction(CReaction * rea);
239 
240  /**
241  * create all metabolites that are needed by the reaction but do
242  * not exist in the model yet.
243  */
244  bool createMetabolites();
245 
246  /**
247  * create all other objects that are needed by the reaction but do
248  * not exist in the model yet.
249  */
250  bool createOtherObjects() const;
251 
252  bool isValid() const;
253 
254  /**
255  * Is the mapping of this parameter locked?
256  * The bahaviour of this method is different for different roles:
257  * SUBSTRATE, PRODUCT: according to the chemical equation
258  * MODIFIER: always unlocked
259  * TIME: always locked
260  * VOLUME, PARAMETER: according to the model
261  *
262  * The idea is that in the reaction GUI new species can be entered
263  * in the chemical equation that are then created automatically.
264  * Compartments and global parameters can only be chosen from those
265  * existing in the model.
266  */
267  bool isLocked(size_t index) const;
268  bool isLocked(CFunctionParameter::Role usage) const;
269 
270  /**
271  * Retrieve the list of parameters which will be deleted
272  * @return std::set< const CCopasiObject * > DeletedParameters
273  */
274  std::set< const CCopasiObject * > getDeletedParameters() const;
275 
276 #ifdef COPASI_DEBUG
277  void printDebug() const;
278 #endif // COPASI_DEBUG
279 
280 private:
281 
282  /**
283  * initialize mapping (resize vectors and set names to "unknown").
284  * Also initializes mpParameters but doesn't delete the old mpParameters.
285  */
286  void initMapping();
287 
288  /**
289  * create new mapping, try to keep as much information from the current
290  * mapping. Calls initMapping().
291  */
292  void copyMapping();
293 
294  /**
295  * guesses how to connect metabs with parameters for a specific usage
296  */
298 
299  /**
300  * tries to determine the mapping for PARAMETER, VOLUME, TIME
301  * only if the current mapping is "unknown".
302  * Is typically called after initMapping() and copyMapping()
303  */
304  void connectNonMetabolites();
305 
306  /**
307  * updates the modifiers in the chemical equation according to
308  * the parameter mapping
309  */
311 
312  void clearFunction();
313 
314  /**
315  * checks if newFunction is an valid function for the reaction.
316  * If it is not or if newFunction="" another function is chosen.
317  */
318  void findAndSetFunction(const std::string & newFunction);
319 
320  /**
321  * returns a list of metabolites (from the chemical equation). Species can occur
322  * several times according to theit multiplicity
323  */
324  std::vector<std::string> getExpandedMetabList(CFunctionParameter::Role role) const;
325 
326  bool loadMappingAndValues(const CReaction & rea);
327 };
328 
329 #endif
std::string getParameterName(size_t index) const
void setChemEqString(const std::string &eq, const std::string &newFunction)
void findAndSetFunction(const std::string &newFunction)
bool createOtherObjects() const
const std::string & getObjectName() const
const std::vector< std::string > & getMappings(size_t index) const
const CChemEqInterface & getChemEqInterface() const
void connectFromScratch(CFunctionParameter::Role role)
void initFromReaction(const std::string &key)
bool isVector(size_t index) const
std::vector< C_FLOAT64 > mValues
#define C_INT32
Definition: copasi.h:90
void setLocal(size_t index)
const CFunction * getFunction() const
bool isLocked(size_t index) const
const C_FLOAT64 & getLocalValue(size_t index) const
const std::string & getMapping(size_t index) const
const std::string & getFunctionDescription() const
CFunctionParameter::Role getUsage(size_t index) const
std::string mReactionReferenceKey
bool loadMappingAndValues(const CReaction &rea)
std::vector< std::vector< std::string > > mNameMap
bool isReversible() const
void setMapping(size_t index, std::string mn)
std::string getChemEqString(bool expanded) const
void reverse(bool rev, const std::string &newFunction)
void setLocalValue(size_t index, C_FLOAT64 value)
std::set< const CCopasiObject * > getDeletedParameters() const
const std::vector< std::string > & getListOfMetabs(CFunctionParameter::Role role) const
std::vector< std::string > getExpandedMetabList(CFunctionParameter::Role role) const
#define C_FLOAT64
Definition: copasi.h:92
std::vector< bool > mIsLocal
CChemEqInterface mChemEqI
void removeMapping(size_t index, std::string mn)
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
std::string getChemEqString() const
Definition: CModel.h:50
const std::string & getFunctionName() const
CFunctionParameters * mpParameters
size_t size() const
bool writeBackToReaction(CReaction *rea)
bool getReversibility() const
const CFunction * mpFunction
bool isLocalValue(size_t index) const
std::vector< std::string > getListOfPossibleFunctions() const
bool isMulticompartment() const
void setFunctionAndDoMapping(const std::string &fn)
const std::string & getInfix() const
void setReversibility(bool rev, const std::string &newFunction)
void setFunctionWithEmptyMapping(const std::string &fn)