COPASI API  4.16.103
Public Member Functions | Public Attributes | List of all members
CODEExporterBM Class Reference

#include <CODEExporterBM.h>

Inheritance diagram for CODEExporterBM:
Inheritance graph
[legend]
Collaboration diagram for CODEExporterBM:
Collaboration graph
[legend]

Public Member Functions

 CODEExporterBM ()
 
virtual bool exportSingleCompartment (const CCompartment *comp, std::string &expression, std::string &comments)
 
virtual bool exportSingleMetabolite (const CMetab *metab, std::string &expression, std::string &comments)
 
virtual bool exportSingleModelEntity (const CModelEntity *tmp, std::string &expression, std::string &comments)
 
virtual bool exportSingleModVal (const CModelValue *modval, std::string &expression, std::string &comments)
 
virtual bool exportSingleObject (std::ostringstream &which, const std::string &name, const std::string &expression, const std::string &comments)
 
virtual bool exportSingleODE (const CModelEntity *mentity, std::string &equation, std::string &comments)
 
virtual bool exportSingleParameter (const CCopasiParameter *param, std::string &expression, std::string &comments)
 
virtual bool exportTitleData (const CCopasiDataModel *pDataModel, std::ostream &os)
 
virtual std::string exportTitleString (const size_t tmp)
 
virtual std::string getDisplayExpressionString (CExpression *tmp)
 
virtual std::string getDisplayFunctionString (CFunction *func)
 
virtual std::string KineticFunction2ODEmember (const CReaction *reac)
 
std::string setConcentrationName (const std::string &objName)
 
std::string setODEName (const std::string &objName)
 
virtual void setReservedNames ()
 
std::string testName (const std::string &name)
 
virtual std::string translateObjectName (const std::string &realName)
 
virtual std::string translateTimeVariableName ()
 
- Public Member Functions inherited from CODEExporter
void assembleSubTreeForMassAction (CEvaluationNode *newNode, CEvaluationNode *child1, CEvaluationNode *child2)
 
 CODEExporter ()
 
virtual bool exportClosingData (const CModel *copasiModel, std::ostream &os)
 
virtual std::string exportClosingString (const size_t tmp)
 
bool exportCompartments (const CModel *copasiModel)
 
std::string exportExpression (const CExpression *pExpression, const CCopasiDataModel *pDataModel)
 
virtual bool exportKineticFunction (CReaction *reac)
 
virtual bool exportKineticFunctionGroup (const CModel *copasiModel)
 
virtual bool exportMetabolites (const CModel *copasiModel)
 
virtual bool exportMetabolitesConcentrations (const CModel *copasiModel)
 
bool exportModelEntityExpression (CCopasiObject *obj, const CCopasiDataModel *pDataModel)
 
bool exportModelValues (const CModel *copasiModel)
 
bool exportModelValuesExpressions (const CModel *copasiModel)
 
virtual std::string exportNumber (double number)
 
void exportObjectNodesFromModel (const CCopasiDataModel *pDataModel)
 
bool exportODEs (const CModel *copasiModel)
 
bool exportReacParamsAndFuncs (const CModel *copasiModel)
 
void exportSimulatedObject (CCopasiObject *obj, const CCopasiDataModel *pDataModel)
 
bool exportSingleFunction (const CFunction *func)
 
virtual bool exportSingleFunction (const CFunction *func, std::set< std::string > &isExported)
 
bool exportSingleFunction (CEvaluationNode *pNode, const CReaction *reac, size_t &index)
 
bool exportSingleFunction (CEvaluationNode *pNode, const std::string &key, size_t &index)
 
virtual bool exportTitleData (const CModel *copasiModel, std::ostream &os)
 
bool exportToStream (const CCopasiDataModel *pDataModel, std::ostream &os)
 
void findFunctionsCalls (const CEvaluationNode *pNode)
 
CCopasiObjectfindObjectFromRefresh (const CCopasiObject *tmp, const Refresh *ref)
 
virtual std::string getSingleLineComment ()
 
virtual bool isEmptyString (std::string &str)
 
std::string isModelEntityExpressionODEExporterCompatible (CModelEntity *tmp, const CExpression *pExpression, const CCopasiDataModel *pDataModel)
 
void modifyTreeForMassAction (CFunction *tmpfunc)
 
virtual bool preprocess (const CModel *copasiModel)
 
virtual ~CODEExporter ()
 

Public Attributes

std::map< std::string, size_t > Frequancy
 
std::set< std::string > NameSet
 
- Public Attributes inherited from CODEExporter
std::ostringstream assignment
 
std::map< std::string,
std::string > 
equations
 
std::ostringstream fixed
 
std::ostringstream functions
 
std::ostringstream headers
 
std::ostringstream initial
 
std::map< std::string,
std::string > 
NameMap
 
std::ostringstream ode
 
std::string timeKey
 

Additional Inherited Members

- Public Types inherited from CODEExporter
enum  Object {
  INITIAL = 0, FIXED, ASSIGNMENT, HEADERS,
  FUNCTIONS, ODEs
}
 
- Protected Attributes inherited from CODEExporter
std::set< std::string > mExportedFunctions
 

Detailed Description

Definition at line 20 of file CODEExporterBM.h.

Constructor & Destructor Documentation

CODEExporterBM::CODEExporterBM ( )

Constructor for the exporter.

Definition at line 54 of file CODEExporterBM.cpp.

55 {}

Member Function Documentation

bool CODEExporterBM::exportSingleCompartment ( const CCompartment comp,
std::string &  expression,
std::string &  comments 
)
virtual

Reimplemented from CODEExporter.

Definition at line 279 of file CODEExporterBM.cpp.

References CModelEntity::ASSIGNMENT, CODEExporter::assignment, exportSingleObject(), CModelEntity::FIXED, CODEExporter::fixed, CModelEntity::getKey(), CModelEntity::getStatus(), CODEExporter::initial, CODEExporter::NameMap, and CModelEntity::ODE.

280 {
281  switch (comp->getStatus())
282  {
283  case CModelEntity::FIXED:
284  {
285  if (!exportSingleObject(fixed, NameMap[comp->getKey()], expression, comments))
286  return false;
287 
288  break;
289  }
290 
291  case CModelEntity::ODE:
292  {
293  initial << "init ";
294 
295  if (!exportSingleObject(initial, NameMap[comp->getKey()], expression, comments))
296  return false;
297 
298  break;
299  }
300 
302  {
303  if (!exportSingleObject(assignment, NameMap[comp->getKey()], expression, comments))
304  return false;
305 
306  break;
307  }
308 
309  default:
310  return false;
311  break;
312  }
313 
314  return true;
315 }
std::ostringstream initial
Definition: CODEExporter.h:155
virtual const std::string & getKey() const
std::map< std::string, std::string > NameMap
Definition: CODEExporter.h:151
std::ostringstream assignment
Definition: CODEExporter.h:157
std::ostringstream fixed
Definition: CODEExporter.h:156
const CModelEntity::Status & getStatus() const
virtual bool exportSingleObject(std::ostringstream &which, const std::string &name, const std::string &expression, const std::string &comments)
bool CODEExporterBM::exportSingleMetabolite ( const CMetab metab,
std::string &  expression,
std::string &  comments 
)
virtual

Reimplemented from CODEExporter.

Definition at line 218 of file CODEExporterBM.cpp.

References CModelEntity::ASSIGNMENT, CODEExporter::assignment, exportSingleObject(), CModelEntity::FIXED, CODEExporter::fixed, CModelEntity::getKey(), CModelEntity::getStatus(), CODEExporter::initial, CMetab::isDependent(), CODEExporter::NameMap, CModelEntity::ODE, and CModelEntity::REACTIONS.

219 {
220  std::string name;
221 
222  std::ostringstream smKey;
223  smKey << "sm_" << metab->getKey();
224  name = NameMap[smKey.str()];
225 
226  switch (metab->getStatus())
227  {
228  case CModelEntity::FIXED:
229 
230  if (!exportSingleObject(fixed, name, expression, comments))
231  return false;
232 
233  break;
234 
236  {
237  if (metab->isDependent())
238  {
239  if (!exportSingleObject(assignment, name, expression, comments))
240  return false;
241  }
242  else
243  {
244  initial << "init ";
245 
246  if (!exportSingleObject(initial, name, expression, comments))
247  return false;
248  }
249 
250  break;
251  }
252 
253  case CModelEntity::ODE:
254  {
255  initial << "init ";
256 
257  if (!exportSingleObject(initial, name, expression, comments))
258  return false;
259 
260  break;
261  }
262 
264  {
265  if (!exportSingleObject(assignment, name, expression, comments))
266  return false;
267 
268  break;
269  }
270 
271  default:
272  return false;
273  break;
274  }
275 
276  return true;
277 }
std::ostringstream initial
Definition: CODEExporter.h:155
virtual const std::string & getKey() const
bool isDependent() const
Definition: CMetab.cpp:989
std::map< std::string, std::string > NameMap
Definition: CODEExporter.h:151
std::ostringstream assignment
Definition: CODEExporter.h:157
std::ostringstream fixed
Definition: CODEExporter.h:156
const CModelEntity::Status & getStatus() const
virtual bool exportSingleObject(std::ostringstream &which, const std::string &name, const std::string &expression, const std::string &comments)
bool CODEExporterBM::exportSingleModelEntity ( const CModelEntity tmp,
std::string &  expression,
std::string &  comments 
)
virtual

Reimplemented from CODEExporter.

Definition at line 355 of file CODEExporterBM.cpp.

References CModelEntity::ASSIGNMENT, CODEExporter::assignment, exportSingleObject(), CModelEntity::FIXED, CODEExporter::fixed, CModelEntity::getKey(), CModelEntity::getStatus(), CODEExporter::initial, CODEExporter::NameMap, and CModelEntity::ODE.

356 {
357 
358  std::string name;
359 
360  const CMetab* metab;
361  metab = dynamic_cast< const CMetab * >(tmp);
362 
363  if (metab)
364  {
365  std::ostringstream smKey;
366  smKey << "sm_" << metab->getKey();
367  name = NameMap[smKey.str()];
368  }
369  else
370  name = NameMap[tmp->getKey()];
371 
372  switch (tmp->getStatus())
373  {
374  case CModelEntity::FIXED:
375  {
376  if (!exportSingleObject(fixed, name, expression, comments))
377  return false;
378 
379  break;
380  }
381 
382  case CModelEntity::ODE:
383  {
384  if (!exportSingleObject(initial, name, expression, comments))
385  return false;
386 
387  break;
388  }
389 
391  {
392  if (!exportSingleObject(assignment, name, expression, comments))
393  return false;
394 
395  break;
396  }
397 
398  default:
399  return false;
400  break;
401  }
402 
403  return true;
404 }
std::ostringstream initial
Definition: CODEExporter.h:155
Definition: CMetab.h:178
virtual const std::string & getKey() const
std::map< std::string, std::string > NameMap
Definition: CODEExporter.h:151
std::ostringstream assignment
Definition: CODEExporter.h:157
std::ostringstream fixed
Definition: CODEExporter.h:156
const CModelEntity::Status & getStatus() const
virtual bool exportSingleObject(std::ostringstream &which, const std::string &name, const std::string &expression, const std::string &comments)
bool CODEExporterBM::exportSingleModVal ( const CModelValue modval,
std::string &  expression,
std::string &  comments 
)
virtual

Reimplemented from CODEExporter.

Definition at line 317 of file CODEExporterBM.cpp.

References CModelEntity::ASSIGNMENT, CODEExporter::assignment, exportSingleObject(), CModelEntity::FIXED, CODEExporter::fixed, CModelEntity::getKey(), CModelEntity::getStatus(), CODEExporter::initial, CODEExporter::NameMap, and CModelEntity::ODE.

318 {
319  switch (modval->getStatus())
320  {
321  case CModelEntity::FIXED:
322  {
323  if (!exportSingleObject(fixed, NameMap[modval->getKey()], expression, comments))
324  return false;
325 
326  break;
327  }
328 
329  case CModelEntity::ODE:
330  {
331  initial << "init ";
332 
333  if (!exportSingleObject(initial, NameMap[modval->getKey()], expression, comments))
334  return false;
335 
336  break;
337  }
338 
340  {
341  if (!exportSingleObject(assignment, NameMap[modval->getKey()], expression, comments))
342  return false;
343 
344  break;
345  }
346 
347  default:
348  return false;
349  break;
350  }
351 
352  return true;
353 }
std::ostringstream initial
Definition: CODEExporter.h:155
virtual const std::string & getKey() const
std::map< std::string, std::string > NameMap
Definition: CODEExporter.h:151
std::ostringstream assignment
Definition: CODEExporter.h:157
std::ostringstream fixed
Definition: CODEExporter.h:156
const CModelEntity::Status & getStatus() const
virtual bool exportSingleObject(std::ostringstream &which, const std::string &name, const std::string &expression, const std::string &comments)
bool CODEExporterBM::exportSingleObject ( std::ostringstream &  which,
const std::string &  name,
const std::string &  expression,
const std::string &  comments 
)
virtual

Reimplemented from CODEExporter.

Definition at line 207 of file CODEExporterBM.cpp.

Referenced by exportSingleCompartment(), exportSingleMetabolite(), exportSingleModelEntity(), exportSingleModVal(), exportSingleODE(), and exportSingleParameter().

211 {
212  which << name << " = " << expression
213  << '\t' << '\t' << "; " << comments << std::endl;
214 
215  return true;
216 }
bool CODEExporterBM::exportSingleODE ( const CModelEntity mentity,
std::string &  equation,
std::string &  comments 
)
virtual

Reimplemented from CODEExporter.

Definition at line 413 of file CODEExporterBM.cpp.

References exportSingleObject(), CModelEntity::getKey(), CODEExporter::NameMap, and CODEExporter::ode.

414 {
415  std::ostringstream odeKey;
416 
417  odeKey << "ode_" << mentity->getKey();
418 
419  if (!exportSingleObject(ode, NameMap[odeKey.str()], equation, comments)) return false;
420 
421  return true;
422 }
std::ostringstream ode
Definition: CODEExporter.h:160
virtual const std::string & getKey() const
std::map< std::string, std::string > NameMap
Definition: CODEExporter.h:151
virtual bool exportSingleObject(std::ostringstream &which, const std::string &name, const std::string &expression, const std::string &comments)
bool CODEExporterBM::exportSingleParameter ( const CCopasiParameter param,
std::string &  expression,
std::string &  comments 
)
virtual

Reimplemented from CODEExporter.

Definition at line 406 of file CODEExporterBM.cpp.

References exportSingleObject(), CODEExporter::fixed, CCopasiParameter::getKey(), and CODEExporter::NameMap.

407 {
408  if (!exportSingleObject(fixed, NameMap[param->getKey()], expression, comments)) return false;
409 
410  return true;
411 }
virtual const std::string & getKey() const
std::map< std::string, std::string > NameMap
Definition: CODEExporter.h:151
std::ostringstream fixed
Definition: CODEExporter.h:156
virtual bool exportSingleObject(std::ostringstream &which, const std::string &name, const std::string &expression, const std::string &comments)
bool CODEExporterBM::exportTitleData ( const CCopasiDataModel pDataModel,
std::ostream &  os 
)
virtual

Definition at line 56 of file CODEExporterBM.cpp.

References CTrajectoryProblem::getDuration(), CCopasiTask::getProblem(), and CTrajectoryProblem::getStepSize().

57 {
58  os << "METHOD stiff" << std::endl;
59  os << std::endl;
60  os << "STARTTIME = 0" << std::endl;
61 
62  const CTrajectoryTask * pTrajectory =
63  dynamic_cast<const CTrajectoryTask *>((*const_cast<CCopasiDataModel*>(pDataModel)->getTaskList())["Time-Course"]);
64  const CTrajectoryProblem * pTrajectoryProblem =
65  dynamic_cast<const CTrajectoryProblem *>(pTrajectory->getProblem());
66 
67  os << "STOPTIME = " << pTrajectoryProblem->getDuration() << std::endl;
68  os << "DT = " << pTrajectoryProblem->getStepSize() << std::endl;
69  os << std::endl;
70 
71  return true;
72 }
CCopasiProblem * getProblem()
const C_FLOAT64 & getStepSize() const
const C_FLOAT64 & getDuration() const
std::string CODEExporterBM::exportTitleString ( const size_t  tmp)
virtual

Reimplemented from CODEExporter.

Definition at line 445 of file CODEExporterBM.cpp.

References CODEExporter::ASSIGNMENT, CODEExporter::FIXED, CODEExporter::FUNCTIONS, CODEExporter::HEADERS, CODEExporter::INITIAL, and CODEExporter::ODEs.

446 {
447  switch (tmp)
448  {
449  case INITIAL:
450  return "{Initial values:}";
451 
452  case FIXED:
453  return "{Fixed Model Entities: }";
454 
455  case ASSIGNMENT:
456  return "{Assignment Model Entities: }";
457 
458  case FUNCTIONS:
459  return "{Kinetics: }";
460 
461  case HEADERS:
462  return " ";
463 
464  case ODEs:
465  return "{Equations:}";
466 
467  default:
468  return " ";
469  }
470 }
std::string CODEExporterBM::getDisplayExpressionString ( CExpression tmp)
virtual

Reimplemented from CODEExporter.

Definition at line 431 of file CODEExporterBM.cpp.

References CEvaluationNode::buildBerkeleyMadonnaString(), and CEvaluationTree::getRoot().

432 {
433  std::string str1;
434  str1 = tmp->getRoot()->buildBerkeleyMadonnaString();
435  return str1;
436 }
std::string buildBerkeleyMadonnaString() const
CEvaluationNode * getRoot()
std::string CODEExporterBM::getDisplayFunctionString ( CFunction func)
virtual

Reimplemented from CODEExporter.

Definition at line 424 of file CODEExporterBM.cpp.

References CEvaluationNode::buildBerkeleyMadonnaString(), and CEvaluationTree::getRoot().

425 {
426  std::string str1;
427  str1 = func->getRoot()->buildBerkeleyMadonnaString();
428  return str1;
429 }
std::string buildBerkeleyMadonnaString() const
CEvaluationNode * getRoot()
std::string CODEExporterBM::KineticFunction2ODEmember ( const CReaction reac)
virtual

Reimplemented from CODEExporter.

Definition at line 438 of file CODEExporterBM.cpp.

References CReaction::getKey(), and CODEExporter::NameMap.

439 {
440  std::ostringstream localKey;
441  localKey << reac->getKey() << "_root_func";
442  return NameMap[localKey.str()];
443 }
virtual const std::string & getKey() const
Definition: CReaction.cpp:190
std::map< std::string, std::string > NameMap
Definition: CODEExporter.h:151
std::string CODEExporterBM::setConcentrationName ( const std::string &  objName)
virtual

Reimplemented from CODEExporter.

Definition at line 197 of file CODEExporterBM.cpp.

198 {
199  return objName + "_c";
200 }
std::string CODEExporterBM::setODEName ( const std::string &  objName)
virtual

Reimplemented from CODEExporter.

Definition at line 202 of file CODEExporterBM.cpp.

203 {
204  return "d/dt(" + objName + ")";
205 }
void CODEExporterBM::setReservedNames ( )
virtual

Reimplemented from CODEExporter.

Definition at line 194 of file CODEExporterBM.cpp.

195 {return;} // TODO
std::string CODEExporterBM::testName ( const std::string &  name)

This method tests whether the given Berkeley Madonna name already assigned, put the new name (in cappital letters: all names can be upper or lower case) in the set of assigned names or modify the name

Definition at line 158 of file CODEExporterBM.cpp.

References Frequancy, and NameSet.

Referenced by translateObjectName().

159 {
160  std::locale C("C");
161  char ch;
162 
163  std::ostringstream newname, tmp;
164 
165  size_t name_size = name.size();
166  size_t i;
167 
168  for (i = 0; i < name_size; i++)
169  {
170  ch = name[i];
171 
172  if (std::isalpha(ch, C) && std::islower(ch, C))
173  tmp << (char) toupper(ch);
174  else
175  tmp << ch;
176  }
177 
178  if (NameSet.find(tmp.str()) == NameSet.end())
179  {
180  NameSet.insert(tmp.str());
181  Frequancy[tmp.str()] = 0;
182 
183  return name;
184  }
185  else
186  {
187  Frequancy[tmp.str()]++;
188  newname << name << "_" << Frequancy[tmp.str()];
189 
190  return testName(newname.str());
191  }
192 }
std::string testName(const std::string &name)
std::map< std::string, size_t > Frequancy
std::set< std::string > NameSet
std::string CODEExporterBM::translateObjectName ( const std::string &  realName)
virtual

This method adapt a Copasi name for Berkeley Madonna syntax: Names can not start with a number. Any other combination of letters and numbers is valid as is the underscore.

Reimplemented from CODEExporter.

Definition at line 82 of file CODEExporterBM.cpp.

References testName().

83 {
84  std::locale C("C");
85  char ch;
86 
87  std::ostringstream tmpName;
88 
89  size_t realName_size = realName.size();
90  size_t i;
91 
92  ch = realName[0];
93 
94  if (!std::isalpha(ch, C))
95  {
96  tmpName << "_";
97 
98  if (std::isdigit(ch, C)) tmpName << ch;
99  }
100  else tmpName << ch;
101 
102  for (i = 1; i < realName_size; i++)
103  {
104  ch = realName[i];
105 
106  if (std::isalpha(ch, C))
107  {
108  if (std::isspace(realName[i - 1], C) && std::islower(ch, C))
109  tmpName << (char) toupper(ch);
110  else
111  tmpName << ch;
112  }
113 
114  if (std::isdigit(ch, C)) tmpName << ch;
115 
116  if (std::ispunct(ch, C))
117  switch (ch)
118  {
119  case '_':
120  tmpName << ch;
121  break;
122 
123  case '-':
124  tmpName << "_";
125  break;
126 
127  case '{':
128  tmpName << "_";
129  break;
130 
131  case '}':
132  tmpName << "_";
133  break;
134 
135  case '(':
136  tmpName << "_";
137  break;
138 
139  case ')':
140  tmpName << "_";
141  break;
142 
143  default:
144  break;
145  }
146  }
147 
148  return testName(tmpName.str());
149 }
std::string testName(const std::string &name)
std::string CODEExporterBM::translateTimeVariableName ( )
virtual

Reimplemented from CODEExporter.

Definition at line 74 of file CODEExporterBM.cpp.

75 {return "TIME";}

Member Data Documentation

std::map< std::string, size_t > CODEExporterBM::Frequancy

Definition at line 72 of file CODEExporterBM.h.

Referenced by testName().

std::set<std::string> CODEExporterBM::NameSet

Definition at line 73 of file CODEExporterBM.h.

Referenced by testName().


The documentation for this class was generated from the following files: