COPASI API  4.16.103
CFunction.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 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) 2002 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #ifndef COPASI_CFunction
16 #define COPASI_CFunction
17 
22 
23 /*!
24  \brief The class for handling a chemical kinetic function
25 
26  This class is designed to handle all about a given chemical kinetic function from
27  editing and displaying (with help of MathML) the function to calculating the function value.
28  */
29 class CFunction:
30  public CEvaluationTree, public CAnnotation
31 {
32  // Operations
33 public:
34  /**
35  * Default constructor
36  * @param const std::string & name (default: "NoName")
37  * @param const CEvaluationTree::Type & type (default: Function)
38  * @param const CCopasiContainer * pParent (default: NULL)
39  */
40  CFunction(const std::string & name = "NoName",
41  const CCopasiContainer * pParent = NULL,
42  const Type & type = Function);
43 
44  /**
45  * Copy constructor
46  * @param const CFunction & src
47  * @param const CCopasiContainer * pParent (default: NULL)
48  */
49  CFunction(const CFunction & src,
50  const CCopasiContainer * pParent = NULL);
51 
52  /**
53  * Destructor
54  */
55  virtual ~CFunction();
56 
57  /**
58  * Retrieves the key of the EvaluationTree
59  * @return const std::string & key
60  */
61  const std::string & getKey() const;
62 
63  /**
64  * Sets the SBMLId.
65  */
66  void setSBMLId(const std::string& id);
67 
68  /**
69  * Returns a reference to the SBML Id.
70  */
71  const std::string& getSBMLId() const;
72 
73  /**
74  * Function to set the infix description of the tree and compile it.
75  * @param const std::string & infix
76  * @return bool success
77  */
78  virtual bool setInfix(const std::string & infix);
79 
80  /**
81  * Function to set the infix description of the tree and (optionally) compile it.
82  * @param const std::string & infix
83  * @param bool compile, boolean indicating whether the expression ought to be compiled
84  * @return bool success
85  */
86  virtual bool setInfix(const std::string & infix, bool compile);
87 
88  /**
89  * Comparison operator
90  * @param const CFunction & rhs
91  * @return bool equal
92  */
93  bool operator == (const CFunction & rhs) const;
94 
95  /**
96  * Function to calculate the value of the function
97  * @param const CCallParameters<C_FLOAT64> & callParameters
98  * @return const C_FLOAT64 & result
99  */
100  virtual const C_FLOAT64 & calcValue(const CCallParameters<C_FLOAT64> & callParameters);
101 
102  /**
103  * Function to return whether it depends on the given parameter
104  * @param const void * parameter
105  * @param const CCallParameters<C_FLOAT64> & callParameters
106  * @param bool dependsOn
107  */
108  virtual bool dependsOn(const C_FLOAT64 * parameter,
109  const CCallParameters<C_FLOAT64> & callParameters) const;
110 
111  /**
112  * Function to retrieve the index to the value of the named variable.
113  * @param const std::string & name
114  * @return size_t index
115  */
116  virtual size_t getVariableIndex(const std::string & name) const;
117 
118  /**
119  * Function to retrieve the value of the indexed variable.
120  *
121  * Note this function is only usable during calcValue, since the values
122  * of the call parameters are only defined during that time.
123  * @param const size_t & index
124  * @return const C_FLOAT64 & variableValue
125  */
126  virtual const C_FLOAT64 & getVariableValue(const size_t & index) const;
127 
128  /**
129  * Function to set whether it is reversible.
130  */
131  void setReversible(const TriLogic & reversible);
132 
133  /**
134  * Function to retrieve whether it is reversible.
135  */
136  const TriLogic & isReversible() const;
137 
138  /**
139  * Function to retrive the definition of the parameters
140  * @return CFunctionParameters & variables
141  */
143 
144  /**
145  * Function to retrive the definition of the parameters
146  * @return const CFunctionParameters & variables
147  */
148  const CFunctionParameters & getVariables() const;
149 
150  /**
151  * Function to add the description of a variable.
152  * @param const string & name
153  * @param const string & usage (Default: VARIABLE)
154  * @param const CFunctionParameters::DataType & type (Default: value)
155  * @return bool success
156  */
157  bool addVariable(const std::string & name,
160 
161  /**
162  * Function to load an object with data coming from a CReadConfig object.
163  * (CReadConfig object reads an input stream)
164  * @param "CReadConfig &" configBuffer
165  * @param "CReadConfig::Mode" mode (default: CReadConfig::SEARCH)
166  * @return Fail
167  */
168  virtual void load(CReadConfig & configBuffer,
170 
171  /**
172  * Function to determine whether it is suitable for a reaction with
173  * the given number of substrates and products and reversibility
174  */
175  bool isSuitable(const size_t noSubstrates,
176  const size_t noProducts,
177  const TriLogic reversible);
178 
179  /**
180  * Complete the list of evaluation tree such that all called trees are includes.
181  * @param std::vector< CFunction * > & list
182  * @param const size_t & added (Default: list.size())
183  * @return bool success
184  */
185  static bool completeFunctionList(std::vector< CFunction * > & list,
186  const size_t & added = 0);
187 
188 protected:
189  /**
190  * Function to initialize the parameters
191  * @return bool success
192  */
193  bool initVariables();
194 
195  // Attributes
196 private:
197 
198  /**
199  * The id of the corresponding function in an SBML file.
200  * This value is either set upon importing an SBML file,
201  * or when the object is first exported to an SBML file.
202  */
203  std::string mSBMLId;
204 
205  /**
206  * The description of the variables of the function.
207  * It describes which variables need to be passed to the function
208  * for evaluation and its eventual type.
209  */
211 
212  /**
213  * A pointer to the call parameters during calculation.
214  */
216 
217  /**
218  * Whether the function is reversible
219  */
221 
222 public:
223  /**
224  * This is an overloaded member function, provided for convenience.
225  * It behaves essentially like the above function.
226  * @param std::ostream & out
227  * @param size_t l
228  */
229  virtual void writeMathML(std::ostream & out, size_t l = 0) const;
230 
231  /**
232  * Function to write the mathematical formula in format of MathML.
233  * @param std::ostream & out
234  * @param const std::vector< std::vector< std::string > > & variables
235  * @param bool expand = true
236  * @param bool fullExpand
237  * @return std::string
238  */
239  virtual std::string writeMathML(const std::vector< std::vector< std::string > > & variables,
240  bool expand = true, bool fullExpand = true) const;
241 
242  /**
243  * Function to create a list of the names of the function parameters in MathML format.
244  * This list can be passed as the env argument to the writeMathML() method.
245  * @param std::vector<std::vector<std::string> > & env
246  */
247  void createListOfParametersForMathML(std::vector<std::vector<std::string> > & env);
248 
249  /**
250  * Insert operator
251  */
252  friend std::ostream& operator<<(std::ostream &os, const CFunction & f);
253 
254  /**
255  * Function to duplicate itself
256  */
257  CFunction * createCopy() const;
258 
259  /**
260  * Function to split
261  *
262  * @param const CEvaluationNode* node
263  * @param const std::string & name1
264  * @param const std::string & name2
265  */
266  std::pair<CFunction *, CFunction *> splitFunction(const CEvaluationNode* node,
267  const std::string & name1,
268  const std::string & name2) const;
269 };
270 
271 #include "CKinFunction.h"
272 #include "CMassAction.h"
273 
274 #endif // COPASI_CFunction
static bool completeFunctionList(std::vector< CFunction * > &list, const size_t &added=0)
Definition: CFunction.cpp:303
virtual bool dependsOn(const C_FLOAT64 *parameter, const CCallParameters< C_FLOAT64 > &callParameters) const
Definition: CFunction.cpp:168
bool operator==(const CFunction &rhs) const
Definition: CFunction.cpp:119
CFunctionParameters mVariables
Definition: CFunction.h:210
virtual size_t getVariableIndex(const std::string &name) const
Definition: CFunction.cpp:133
bool initVariables()
Definition: CFunction.cpp:219
std::string mSBMLId
Definition: CFunction.h:203
TriLogic
Definition: copasi.h:125
bool isSuitable(const size_t noSubstrates, const size_t noProducts, const TriLogic reversible)
Definition: CFunction.cpp:254
bool addVariable(const std::string &name, CFunctionParameter::Role usage=CFunctionParameter::VARIABLE, const CFunctionParameter::DataType &type=CFunctionParameter::FLOAT64)
Definition: CFunction.cpp:154
friend std::ostream & operator<<(std::ostream &os, const CFunction &f)
Definition: CFunction.cpp:410
virtual bool setInfix(const std::string &infix)
Definition: CFunction.cpp:73
const std::string & getKey() const
Definition: CFunction.cpp:58
void setReversible(const TriLogic &reversible)
Definition: CFunction.cpp:142
const TriLogic & isReversible() const
Definition: CFunction.cpp:145
virtual ~CFunction()
Definition: CFunction.cpp:53
void setSBMLId(const std::string &id)
Definition: CFunction.cpp:63
virtual void load(CReadConfig &configBuffer, CReadConfig::Mode mode=CReadConfig::SEARCH)
Definition: CFunction.cpp:182
std::pair< CFunction *, CFunction * > splitFunction(const CEvaluationNode *node, const std::string &name1, const std::string &name2) const
Definition: CFunction.cpp:445
virtual void writeMathML(std::ostream &out, size_t l=0) const
Definition: CFunction.cpp:389
virtual const C_FLOAT64 & getVariableValue(const size_t &index) const
Definition: CFunction.cpp:139
TriLogic mReversible
Definition: CFunction.h:220
void createListOfParametersForMathML(std::vector< std::vector< std::string > > &env)
Definition: CFunction.cpp:340
virtual const C_FLOAT64 & calcValue(const CCallParameters< C_FLOAT64 > &callParameters)
Definition: CFunction.cpp:159
CFunction(const std::string &name="NoName", const CCopasiContainer *pParent=NULL, const Type &type=Function)
Definition: CFunction.cpp:25
const std::string & getSBMLId() const
Definition: CFunction.cpp:68
CFunction * createCopy() const
Definition: CFunction.cpp:428
#define C_FLOAT64
Definition: copasi.h:92
CCallParameters< C_FLOAT64 >::const_iterator mCallParametersBegin
Definition: CFunction.h:215
virtual bool compile()
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148