COPASI API  4.16.103
CMassAction.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/function/CMassAction.cpp,v $
3 // $Revision: 1.44 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/06/15 15:32:27 $
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 /**
24  * CMassAction
25  *
26  * Created for COPASI by Stefan Hoops
27  * (C) Stefan Hoops 2001
28  */
29 
30 #include "copasi.h"
31 #include "CMassAction.h"
32 #include "utilities/utility.h"
33 
34 // static
35 const char * CMassAction::Infix[] =
36  {"k1*PRODUCT<substrate_i>-k2*PRODUCT<product_j>", "k1*PRODUCT<substrate_i>"};
37 
38 CMassAction::CMassAction(const std::string & name,
39  const CCopasiContainer * pParent):
40  CFunction(name, pParent, CEvaluationTree::MassAction)
41 {}
42 
44  const CCopasiContainer * pParent):
45  CFunction(src, pParent)
46 {}
47 
49  const CCopasiContainer * pParent):
50  CFunction((reversible == TriTrue) ?
51  "Mass action (reversible)" :
52  "Mass action (irreversible)",
53  pParent,
54  CFunction::MassAction)
55 {
57 
58  if (reversible != TriFalse && reversible != TriTrue)
60 
61  if (reversible == TriTrue)
62  setInfix(Infix[0]);
63  else
64  setInfix(Infix[1]);
65 }
66 
68 
70 {
71  CCallParameters<C_FLOAT64>::const_iterator pCallParameters = callParameters.begin();
72 
73  CCallParameters<C_FLOAT64>::const_iterator Factor = (pCallParameters + 1)->vector->begin();
74  CCallParameters<C_FLOAT64>::const_iterator End = (pCallParameters + 1)->vector->end();
75 
76  mValue = 0.0;
77 
78  if (Factor != End)
79  {
80  mValue = *(pCallParameters + 0)->value // k1
81  * *(Factor++)->value; // first substrate.
82 
83  while (Factor != End)
84  mValue *= *(Factor++)->value;
85  }
86 
87  if (isReversible() == TriFalse)
88  return mValue;
89 
90  C_FLOAT64 Products = 0.0;
91 
92  Factor = (pCallParameters + 3)->vector->begin();
93  End = (pCallParameters + 3)->vector->end();
94 
95  if (Factor != End)
96  {
97  Products = *(pCallParameters + 2)->value // k2
98  * *(Factor++)->value; // first product.
99 
100  while (Factor != End)
101  Products *= *(Factor++)->value;
102  }
103 
104  return mValue -= Products;
105 }
106 
107 bool CMassAction::dependsOn(const C_FLOAT64 * parameter,
108  const CCallParameters<C_FLOAT64> & callParameters) const
109 {
110  if (parameter == callParameters[0].value) return true;
111 
114 
115  it = callParameters[1].vector->begin();
116  end = callParameters[1].vector->end();
117 
118  for (; it != end; it++) if (parameter == it->value) return true;
119 
120  if (isReversible() != TriTrue) return false;
121 
122  if (parameter == callParameters[2].value) return true;
123 
124  it = callParameters[3].vector->begin();
125  end = callParameters[3].vector->end();
126 
127  for (; it != end; it++) if (parameter == it->value) return true;
128 
129  return false;
130 }
131 
132 bool CMassAction::setInfix(const std::string & infix)
133 {
134  if (infix == "k1*PRODUCT<substrate_i>-k2*PRODUCT<product_j>")
136  else if (infix == "k1*PRODUCT<substrate_i>")
138  else
139  return false;
140 
141  CFunction::setInfix(infix);
142  getVariables().cleanup();
143 
144  getVariables().add("k1",
147  getVariables().add("substrate",
150 
151  if (isReversible() == TriTrue)
152  {
153  getVariables().add("k2",
156  getVariables().add("product",
159  }
160 
161  return true;
162 }
163 
165 {
166  mUsable = true;
167  return true;
168 }
169 
170 #include "utilities/copasimathml.h"
171 
172 // virtual
173 std::string CMassAction::writeMathML(const std::vector< std::vector< std::string > > & variables,
174  bool /* expand */, bool /* fullExpand */) const
175 {
176  std::ostringstream out;
177 
178  bool rev = (isReversible() == TriTrue);
179 
180  if (rev)
181  out << "<mfenced>" << std::endl;
182 
183  out << "<mrow>" << std::endl;
184 
185  out << variables[0][0] << std::endl;
186 
187  size_t i, imax = variables[1].size();
188 
189  for (i = 0; i < imax; ++i)
190  {
191  out << "<mo>&CenterDot;</mo>" << std::endl;
192  out << variables[1][i] << std::endl;
193  }
194 
195  if (rev)
196  {
197  out << "<mo>-</mo>" << std::endl;
198  out << variables[2][0] << std::endl;
199 
200  size_t i, imax = variables[3].size();
201 
202  for (i = 0; i < imax; ++i)
203  {
204  out << "<mo>&CenterDot;</mo>" << std::endl;
205  out << variables[3][i] << std::endl;
206  }
207  }
208 
209  out << "</mrow>" << std::endl;
210 
211  if (rev)
212  out << "</mfenced>" << std::endl;
213 
214  return out.str();
215 }
const_iterator begin() const
virtual const C_FLOAT64 & calcValue(const CCallParameters< C_FLOAT64 > &callParameters)
Definition: CMassAction.cpp:69
static const char * Infix[]
Definition: CMassAction.h:34
virtual bool compile()
virtual std::string writeMathML(const std::vector< std::vector< std::string > > &variables, bool expand=true, bool fullExpand=true) const
TriLogic
Definition: copasi.h:125
#define MCMassAction
virtual bool setInfix(const std::string &infix)
Definition: CFunction.cpp:73
void setReversible(const TriLogic &reversible)
Definition: CFunction.cpp:142
CMassAction(const std::string &name="NoName", const CCopasiContainer *pParent=NULL)
Definition: CMassAction.cpp:38
#define DESTRUCTOR_TRACE
Definition: copasi.h:206
void add(const CFunctionParameter &parameter)
const TriLogic & isReversible() const
Definition: CFunction.cpp:145
virtual bool dependsOn(const C_FLOAT64 *parameter, const CCallParameters< C_FLOAT64 > &callParameters) const
#define C_FLOAT64
Definition: copasi.h:92
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
const_iterator end() const
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202
virtual bool setInfix(const std::string &infix)