COPASI API  4.16.103
Public Types | Public Member Functions | Public Attributes | Protected Attributes | List of all members
CODEExporter Class Reference

#include <CODEExporter.h>

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

Public Types

enum  Object {
  INITIAL = 0, FIXED, ASSIGNMENT, HEADERS,
  FUNCTIONS, ODEs
}
 

Public Member Functions

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)
 
virtual bool exportSingleCompartment (const CCompartment *comp, std::string &expression, std::string &comments)
 
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 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 CModel *copasiModel, std::ostream &os)
 
virtual std::string exportTitleString (const size_t tmp)
 
bool exportToStream (const CCopasiDataModel *pDataModel, std::ostream &os)
 
void findFunctionsCalls (const CEvaluationNode *pNode)
 
CCopasiObjectfindObjectFromRefresh (const CCopasiObject *tmp, const Refresh *ref)
 
virtual std::string getDisplayExpressionString (CExpression *tmp)
 
virtual std::string getDisplayFunctionString (CFunction *func)
 
virtual std::string getSingleLineComment ()
 
virtual bool isEmptyString (std::string &str)
 
std::string isModelEntityExpressionODEExporterCompatible (CModelEntity *tmp, const CExpression *pExpression, const CCopasiDataModel *pDataModel)
 
virtual std::string KineticFunction2ODEmember (const CReaction *reac)
 
void modifyTreeForMassAction (CFunction *tmpfunc)
 
virtual bool preprocess (const CModel *copasiModel)
 
virtual std::string setConcentrationName (const std::string &objName)
 
virtual std::string setODEName (const std::string &objName)
 
virtual void setReservedNames ()
 
virtual std::string translateObjectName (const std::string &realName)
 
virtual std::string translateTimeVariableName ()
 
virtual ~CODEExporter ()
 

Public Attributes

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
 

Protected Attributes

std::set< std::string > mExportedFunctions
 

Detailed Description

Definition at line 27 of file CODEExporter.h.

Member Enumeration Documentation

Enumerator
INITIAL 
FIXED 
ASSIGNMENT 
HEADERS 
FUNCTIONS 
ODEs 

Definition at line 162 of file CODEExporter.h.

Constructor & Destructor Documentation

CODEExporter::CODEExporter ( )

Constructor for the exporter.

Definition at line 55 of file CODEExporter.cpp.

57 {}
std::set< std::string > mExportedFunctions
Definition: CODEExporter.h:30
CODEExporter::~CODEExporter ( )
virtual

Destructor for the exporter.

Definition at line 62 of file CODEExporter.cpp.

63 {}

Member Function Documentation

void CODEExporter::assembleSubTreeForMassAction ( CEvaluationNode newNode,
CEvaluationNode child1,
CEvaluationNode child2 
)

This method assembles an expression sub tree for some internal call of Mass Action. The sub tree has to be included in the tree of corresponding root kinetic function in order to export this function whithout the user defined internall Mass Action calls

Definition at line 1735 of file CODEExporter.cpp.

References CCopasiNode< _Data >::addChild(), CEvaluationNode::copyBranch(), CEvaluationNode::create(), CEvaluationNode::getType(), CEvaluationNodeOperator::MULTIPLY, CEvaluationNode::OPERATOR, CEvaluationNode::type(), CEvaluationNode::VARIABLE, and CEvaluationNode::VECTOR.

Referenced by modifyTreeForMassAction().

1736 {
1737  CEvaluationNode* newparent = newNode;
1738  CEvaluationNode* newchild1 = child1->copyBranch();
1739  newparent->addChild(newchild1, NULL);
1740  CEvaluationNode* newchild2;
1741 
1743  {
1746  newparent->addChild(newchild2, newchild1);
1747  newparent = newchild2;
1748  newchild1 = child2->copyBranch();
1749  newparent->addChild(newchild1, NULL);
1750  newchild2 = child2->copyBranch();
1751  newparent->addChild(newchild2, newchild1);
1752  }
1753 
1754  if (0) // *************** TODO: the current Copasi version does not support the case bellow, the following part is not tested
1756  {
1757  const std::vector<CEvaluationNode *> & vector = dynamic_cast< CEvaluationNodeVector *>(child2) ->getVector();
1758  std::vector<CEvaluationNode *>::const_iterator it = vector.begin();
1759  std::vector<CEvaluationNode *>::const_iterator end = vector.end();
1760 
1761  size_t i = 0;
1762 
1763  while (it != end)
1764  {
1767  newparent->addChild(newchild2, newchild1);
1768 
1769  newparent = newchild2;
1770  newchild1 = dynamic_cast<CEvaluationNode*>(vector[i]);
1771  newparent->addChild(newchild1, NULL);
1772  it++;
1773  i++;
1774  }
1775 
1776  if (it == end)
1777  {
1778  newchild2 = dynamic_cast<CEvaluationNode*>(vector[i]);
1779  newparent->addChild(newchild2, newchild1);
1780  }
1781  } // END of this TODO. ****************************************************************************************************
1782 }
CEvaluationNode * copyBranch() const
const Type & getType() const
static CEvaluationNode * create(const Type &type, const Data &data)
static Type type(const Type &type)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
bool CODEExporter::exportClosingData ( const CModel copasiModel,
std::ostream &  os 
)
virtual

Reimplemented in CODEExporterXPPAUT.

Definition at line 1312 of file CODEExporter.cpp.

Referenced by exportToStream().

1314 {return true;}
std::string CODEExporter::exportClosingString ( const size_t  tmp)
virtual

Reimplemented in CODEExporterC.

Definition at line 1660 of file CODEExporter.cpp.

Referenced by exportToStream().

1661 {return " ";}
bool CODEExporter::exportCompartments ( const CModel copasiModel)

Definition at line 1074 of file CODEExporter.cpp.

References CModelEntity::ASSIGNMENT, exportNumber(), exportSingleCompartment(), CModelEntity::FIXED, CModel::getCompartments(), CModelEntity::getInitialValue(), CCopasiObject::getObjectName(), CModelEntity::getStatus(), CModelEntity::ODE, CCopasiVector< T >::size(), and CModelEntity::StatusName.

Referenced by exportToStream().

1075 {
1076  const CCopasiVector< CCompartment > & comps = copasiModel->getCompartments();
1077 
1078  size_t comps_size = comps.size();
1079  size_t i;
1080 
1081  for (i = 0; i < comps_size; i++)
1082  {
1083  CCompartment* comp;
1084  comp = comps[i];
1085 
1086  std::ostringstream comments;
1087  std::ostringstream expression;
1088 
1089  std::string str1;
1090  std::string str2;
1091 
1092  comments << "compartment \'" << comp->getObjectName() << "\':" << CModelEntity::StatusName[comp->getStatus()];
1093 
1094  switch (comp->getStatus())
1095  {
1096  case CModelEntity::FIXED:
1097  {
1098  expression << exportNumber(comp->getInitialValue());
1099 
1100  break;
1101  }
1102 
1104 
1105  break;
1106 
1107  case CModelEntity::ODE:
1108  {
1109 
1110  expression << exportNumber(comp->getInitialValue());
1111 
1112  break;
1113  }
1114 
1115  default:
1116  return false;
1117  break;
1118  }
1119 
1120  str1 = expression.str();
1121  str2 = comments.str();
1122 
1123  if (comp->getStatus() != CModelEntity::ASSIGNMENT)
1124  if (!exportSingleCompartment(comp, str1, str2)) return false;
1125  }
1126 
1127  return true;
1128 }
static const std::string StatusName[]
Definition: CModelValue.h:67
const std::string & getObjectName() const
virtual size_t size() const
const C_FLOAT64 & getInitialValue() const
virtual bool exportSingleCompartment(const CCompartment *comp, std::string &expression, std::string &comments)
virtual std::string exportNumber(double number)
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
const CModelEntity::Status & getStatus() const
std::string CODEExporter::exportExpression ( const CExpression pExpression,
const CCopasiDataModel pDataModel 
)

Definition at line 558 of file CODEExporter.cpp.

References C_INVALID_INDEX, CEvaluationNode::CALL, equations, exportNumber(), CEvaluationNodeCall::getCalledTree(), CCopasiDataModel::getDataObject(), getDisplayExpressionString(), CMetab::getInitialConcentration(), CModelEntity::getInitialValue(), CModelEntity::getKey(), CCopasiObject::getKey(), CModel::getMetabolitesX(), CCopasiDataModel::getModel(), CEvaluationTree::getNodeList(), CModel::getNumIndependentReactionMetabs(), CModel::getNumODEMetabs(), CEvaluationNodeObject::getObjectCN(), CCopasiObject::getObjectName(), CCopasiObject::getObjectParent(), CCopasiObject::getObjectType(), CTrajectoryProblem::getOutputStartTime(), CCopasiTask::getProblem(), CModel::getQuantity2NumberFactor(), getQuantityParameterOrValue(), getReactionIndex(), CModel::getReactions(), CModel::getRedStoi(), CModelEntity::getStatus(), CMetab::isDependent(), isEmptyString(), CCopasiObject::isReference(), NameMap, CEvaluationNode::OBJECT, CModelEntity::ODE, CModelEntity::REACTIONS, timeKey, and CEvaluationNode::type().

Referenced by exportModelEntityExpression().

559 {
560 
561  std::string result;
562 
563  CExpression* tmpExpression;
564  tmpExpression = new CExpression(*pExpression, pDataModel);
565  assert(pDataModel != NULL);
566 
567  const std::vector<CEvaluationNode*>& objectNodes = tmpExpression->getNodeList();
568  size_t j, jMax = objectNodes.size();
569 
570  for (j = 0; j < jMax; ++j)
571  {
572  if (CEvaluationNode::type(objectNodes[j]->getType()) == CEvaluationNode::CALL)
573  {
574  CEvaluationNodeCall* pObjectNode = dynamic_cast<CEvaluationNodeCall*>(objectNodes[j]);
575  assert(pObjectNode);
576  objectNodes[j]->setData(NameMap[pObjectNode->getCalledTree()->getKey()]);
577  }
578  else if (CEvaluationNode::type(objectNodes[j]->getType()) == CEvaluationNode::OBJECT)
579  {
580  CEvaluationNodeObject* pObjectNode = dynamic_cast<CEvaluationNodeObject*>(objectNodes[j]);
581  assert(pObjectNode);
582  CCopasiObjectName cn = pObjectNode->getObjectCN();
583 
584  const CCopasiObject* pObject = pDataModel->getDataObject(cn);
585  assert(pObject);
586  std::string objectName = pObject->getObjectName();
587 
588  if (pObject->isReference()) pObject = pObject->getObjectParent();
589 
590  std::string objectType = pObject->getObjectType();
591 
592  if (objectType == "Model")
593  {
594  if (objectName == "Time")
595  objectNodes[j]->setData(NameMap[timeKey]);
596 
597  if (objectName == "Avogadro Constant")
598  {
599  std::ostringstream value;
600  value << pDataModel->getModel()->getQuantity2NumberFactor();
601  objectNodes[j]->setData(value.str());
602  }
603 
604  if (objectName == "Initial Time")
605  {
606  const CTrajectoryTask * pTrajectory =
607  dynamic_cast<CTrajectoryTask *>((*const_cast<CCopasiDataModel*>(pDataModel)->getTaskList())["Time-Course"]);
608 
609  const CTrajectoryProblem * pTrajectoryProblem =
610  dynamic_cast<const CTrajectoryProblem *>(pTrajectory->getProblem());
611 
612  std::ostringstream value;
613  value << pTrajectoryProblem->getOutputStartTime();
614  objectNodes[j]->setData(value.str());
615  }
616  }
617  else if (objectType == "ModelValue")
618  {
619  if (objectName == "Value") objectNodes[j]->setData(NameMap[pObject->getKey()]);
620 
621  if (objectName == "InitialValue")
622  {
623  const CModelValue* modval;
624  modval = dynamic_cast<const CModelValue * >(pObject);
625  std::ostringstream value;
626  value << exportNumber(modval->getInitialValue());
627  objectNodes[j]->setData(value.str());
628  }
629 
630  if (objectName == "Rate")
631  {
632  const CModelValue* modval;
633  modval = dynamic_cast<const CModelValue * >(pObject);
634 
635  if (modval->getStatus() == CModelEntity::ODE)
636  {
637 
638  if ((isEmptyString(equations[modval->getKey()])))
639  {
640  std::ostringstream odeKey;
641  odeKey << "ode_" << modval->getKey();
642  objectNodes[j]->setData(NameMap[odeKey.str()]);
643  }
644  else
645  {
646  std::ostringstream str1;
647  str1 << "(" << equations[modval->getKey()] << ")";
648  objectNodes[j]->setData(str1.str());
649  }
650  }
651  }
652  }
653  else if (objectType == "Metabolite")
654  {
655  if (objectName == "Concentration")
656  objectNodes[j]->setData(NameMap[pObject->getKey()]);
657 
658  if (objectName == "ParticleNumber")
659  {
660  std::ostringstream str;
661  str << NameMap["sm_" + pObject->getKey()] << " * "
662  << getQuantityParameterOrValue(NameMap, pDataModel)
663  << " ";
664  objectNodes[j]->setData(str.str());
665  }
666 
667  if (objectName == "InitialConcentration")
668  {
669  const CMetab* metab;
670  metab = dynamic_cast<const CMetab * >(pObject);
671  std::ostringstream value;
672  value << metab->getInitialConcentration();
673  objectNodes[j]->setData(value.str());
674  }
675 
676  if (objectName == "Rate")
677  {
678  const CMetab* metab;
679  metab = dynamic_cast<const CMetab * >(pObject);
680 
681  if ((metab->getStatus() == CModelEntity::REACTIONS && !metab->isDependent()) || metab->getStatus() == CModelEntity::ODE)
682  {
683  if ((isEmptyString(equations[metab->getKey()])))
684  {
685  std::ostringstream odeKey;
686  odeKey << "ode_" << metab->getKey();
687  objectNodes[j]->setData(NameMap[odeKey.str()]);
688  }
689  else
690  {
691  std::ostringstream str1;
692  str1 << "(" << equations[metab->getKey()] << ")";
693  objectNodes[j]->setData(str1.str());
694  }
695  }
696  }
697  }
698  else if (objectType == "Compartment")
699  {
700  if (objectName == "Volume")
701  objectNodes[j]->setData(NameMap[pObject->getKey()]);
702 
703  if (objectName == "InitialVolume")
704  {
705  const CCompartment* comp;
706  comp = dynamic_cast<const CCompartment * >(pObject);
707  std::ostringstream value;
708  value << exportNumber(comp-> getInitialValue());
709  objectNodes[j]->setData(value.str());
710  }
711 
712  if (objectName == "Rate")
713  {
714 
715  const CCompartment* comp;
716  comp = dynamic_cast<const CCompartment * >(pObject);
717 
718  if (comp->getStatus() == CModelEntity::ODE)
719  {
720 
721  if ((isEmptyString(equations[comp->getKey()])))
722  {
723  std::ostringstream odeKey;
724  odeKey << "ode_" << comp->getKey();
725  objectNodes[j]->setData(NameMap[odeKey.str()]);
726  }
727  else
728  {
729  std::ostringstream str1;
730  str1 << "(" << equations[comp->getKey()] << ")";
731  objectNodes[j]->setData(str1.str());
732  }
733  }
734  }
735  }
736  else if (objectType == "Parameter")
737  {
738  if (objectName == "Value")
739  objectNodes[j]->setData(NameMap[pObject->getKey()]);
740  }
741  else if (objectType == "Reaction")
742  {
743  if (objectName == "Flux")
744  {
745  const CModel* copasiModel = pDataModel->getModel();
746  const CReaction *react = static_cast<const CReaction*>(pObject);
747  const CCopasiVector< CReaction > & reacs = copasiModel->getReactions();
748 
749  size_t index = getReactionIndex(reacs, react);
750 
751  if (index == C_INVALID_INDEX)
752  {
753  objectNodes[j]->setData("0");
754  continue;
755  }
756 
757  const CCopasiVector< CMetab > & metabs = copasiModel->getMetabolitesX();
758  size_t indep_size = copasiModel->getNumIndependentReactionMetabs();
759  size_t ode_size = copasiModel->getNumODEMetabs();
760  const CMatrix< C_FLOAT64 > & redStoi = copasiModel->getRedStoi();
761 
762  std::ostringstream jequation;
763 
764  for (size_t j1 = 0; j1 < indep_size; ++j1)
765  {
766  if (fabs(redStoi[j1][index]) > 0.0)
767  {
768  jequation << equations[metabs[ode_size + j1]->getKey()];
769  }
770  }
771 
772  objectNodes[j]->setData(jequation.str());
773  }
774  }
775  }
776  }
777 
778  result = getDisplayExpressionString(tmpExpression);
779 
780  return result;
781 }
CCopasiObject * getDataObject(const CCopasiObjectName &CN) const
const CEvaluationTree * getCalledTree() const
objectType
CCopasiProblem * getProblem()
const std::string & getObjectName() const
const C_FLOAT64 & getInitialConcentration() const
Definition: CMetab.cpp:220
const CRegisteredObjectName & getObjectCN() const
virtual std::string getDisplayExpressionString(CExpression *tmp)
const std::string & getObjectType() const
#define C_INVALID_INDEX
Definition: copasi.h:222
size_t getNumODEMetabs() const
Definition: CModel.cpp:1124
Definition: CMetab.h:178
const CMatrix< C_FLOAT64 > & getRedStoi() const
Definition: CModel.cpp:1154
std::map< std::string, std::string > equations
Definition: CODEExporter.h:153
virtual const std::string & getKey() const
const C_FLOAT64 & getInitialValue() const
virtual bool isEmptyString(std::string &str)
static Type type(const Type &type)
const C_FLOAT64 & getQuantity2NumberFactor() const
Definition: CModel.cpp:2354
bool isReference() const
virtual const std::string & getKey() const
std::string getQuantityParameterOrValue(const std::map< std::string, std::string > &map, const CCopasiDataModel *pDataModel)
size_t getNumIndependentReactionMetabs() const
Definition: CModel.cpp:1130
bool isDependent() const
Definition: CMetab.cpp:989
virtual std::string exportNumber(double number)
const C_FLOAT64 & getOutputStartTime() const
std::map< std::string, std::string > NameMap
Definition: CODEExporter.h:151
std::string timeKey
Definition: CODEExporter.h:152
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
Definition: CModel.h:50
const CModelEntity::Status & getStatus() const
const CCopasiVector< CMetab > & getMetabolitesX() const
Definition: CModel.cpp:1057
const std::vector< CEvaluationNode * > & getNodeList() const
size_t getReactionIndex(const CCopasiVector< CReaction > &reacs, const CReaction *react)
CCopasiContainer * getObjectParent() const
bool CODEExporter::exportKineticFunction ( CReaction reac)
virtual

Reimplemented in CODEExporterC.

Definition at line 1362 of file CODEExporter.cpp.

References exportSingleFunction(), exportSingleObject(), functions, CKeyFactory::get(), CReaction::getChemEq(), getDisplayFunctionString(), CReaction::getFunction(), CModelEntity::getKey(), CReaction::getKey(), CCopasiParameter::getKey(), CCopasiObject::getKey(), CCopasiRootContainer::getKeyFactory(), CChemEqElement::getMetaboliteKey(), CChemEqElement::getMultiplicity(), CCopasiObject::getObjectName(), CReaction::getParameterMappings(), CChemEq::getProducts(), CEvaluationTree::getRoot(), CChemEq::getSubstrates(), CEvaluationTree::getType(), CFunction::getVariableIndex(), CFunction::getVariables(), CReaction::isLocalParameter(), CFunction::isReversible(), CEvaluationTree::MassAction, CFunctionParameter::MODIFIER, modifyTreeForMassAction(), NameMap, CFunctionParameter::PARAMETER, CFunctionParameter::PRODUCT, CCopasiVector< T >::size(), CFunctionParameter::SUBSTRATE, CFunctionParameter::TIME, timeKey, translateObjectName(), TriTrue, CEvaluationNode::type(), CEvaluationNode::VARIABLE, and CFunctionParameter::VOLUME.

Referenced by exportReacParamsAndFuncs().

1363 {
1364 
1365  std::ostringstream comments;
1366  std::ostringstream expression;
1367 
1368  const CFunction* func;
1369 
1370  func = reac->getFunction();
1371 
1372  comments << "reaction \'" << reac->getObjectName() << "\': "
1373  << "kinetic function \'" << func ->getObjectName() << "\'";
1374 
1375  if (func->getType() != CEvaluationTree::MassAction)
1376  {
1377  CFunction* tmpfunc;
1378  tmpfunc = new CFunction(*func);
1379 
1380  const std::vector<std::vector<std::string> > & keyMap = reac->getParameterMappings();
1382 
1383  modifyTreeForMassAction(tmpfunc);
1384 
1385  while (treeIt != NULL)
1386  {
1387  if (CEvaluationNode::type(treeIt->getType()) == CEvaluationNode::VARIABLE)
1388  {
1389 
1390  size_t index;
1392  std::string tmpname;
1393  std::string name;
1394 
1395  name = tmpfunc->getVariables()[treeIt->getData()]->getObjectName();
1396  index = tmpfunc->getVariableIndex(name);
1397  role = tmpfunc->getVariables()[index]->getUsage();
1398 
1399  CCopasiObject * obj = CCopasiRootContainer::getKeyFactory()->get(keyMap[index][0]);
1400 
1401  if ((role == CFunctionParameter::SUBSTRATE)
1402  || (role == CFunctionParameter::PRODUCT)
1403  || (role == CFunctionParameter::MODIFIER))
1404  {
1405  if (obj)
1406  tmpname = NameMap[obj->getKey()];
1407  else
1408  tmpname = "unknown";
1409  }
1410 
1411  if (role == CFunctionParameter::PARAMETER)
1412  {
1413  if (!(reac->isLocalParameter(index)))
1414  {
1415  CModelValue* modval;
1416  modval = dynamic_cast< CModelValue * >(obj);
1417  tmpname = NameMap[modval ->getKey()];
1418  }
1419  else
1420  {
1421  CCopasiParameter* param;
1422  param = dynamic_cast< CCopasiParameter * >(obj);
1423  tmpname = NameMap[param->getKey()];
1424  }
1425  }
1426 
1427  if (role == CFunctionParameter::VOLUME)
1428  {
1429  CCompartment* comp;
1430  comp = dynamic_cast< CCompartment * >(obj);
1431  tmpname = NameMap[comp->getKey()];
1432  }
1433 
1434  if (role == CFunctionParameter::TIME)
1435  tmpname = NameMap[timeKey];
1436 
1437  treeIt->setData(tmpname);
1438  }
1439 
1440  ++treeIt;
1441  }
1442 
1443  size_t index = 0;
1444 
1445  if (!exportSingleFunction(tmpfunc->getRoot(), reac, index)) return false;
1446 
1447  expression << getDisplayFunctionString(tmpfunc);
1448  }
1449  else
1450  {
1451 
1452  const CCopasiVector<CChemEqElement> & substrs = reac->getChemEq().getSubstrates();
1453  const CCopasiVector<CChemEqElement> & prods = reac->getChemEq().getProducts();
1454  const std::vector<std::vector<std::string> > & keyMap = reac->getParameterMappings();
1455  CCopasiObject * obj;
1456 
1457  size_t substrs_size = substrs.size(), prods_size = prods.size();
1458  size_t k, m, mult;
1459 
1460  CChemEqElement* substr;
1461  CChemEqElement* prod;
1462 
1463  const CMassAction cMassAction = *static_cast<const CMassAction*>(reac->getFunction());
1464 
1465  obj = CCopasiRootContainer::getKeyFactory()->get(keyMap[0][0]);
1466 
1467  if (!(reac->isLocalParameter(0)))
1468  {
1469  CModelValue* modval;
1470  modval = dynamic_cast< CModelValue * >(obj);
1471  expression << NameMap[modval ->getKey()];
1472  }
1473  else
1474  {
1475  CCopasiParameter * param;
1476  param = dynamic_cast< CCopasiParameter * >(obj);
1477  expression << NameMap[param->getKey()];
1478  }
1479 
1480  for (k = 0; k < substrs_size; ++k)
1481  {
1482  substr = substrs[k];
1483  mult = (size_t) substr->getMultiplicity();
1484 
1485  expression << "*" << NameMap[substr->getMetaboliteKey()];
1486 
1487  if (mult > 1)
1488  for (m = 1; m < mult; ++m)
1489  expression << "*" << NameMap[substr->getMetaboliteKey()];
1490  }
1491 
1492  if (cMassAction.isReversible() == TriTrue)
1493  {
1494  expression << "-";
1495 
1496  obj = CCopasiRootContainer::getKeyFactory()->get(keyMap[2][0]);
1497 
1498  if (!(reac->isLocalParameter(2)))
1499  {
1500  CModelValue * modval;
1501  modval = dynamic_cast< CModelValue * >(obj);
1502  expression << NameMap[modval ->getKey()];
1503  }
1504  else
1505  {
1506  CCopasiParameter * param;
1507  param = dynamic_cast< CCopasiParameter * >(obj);
1508  expression << NameMap[param->getKey()];
1509  }
1510 
1511  for (k = 0; k < prods_size; ++k)
1512  {
1513  prod = prods[k];
1514  mult = (size_t) prod->getMultiplicity();
1515 
1516  expression << "*" << NameMap[prod->getMetaboliteKey()];
1517 
1518  if (mult > 1)
1519  for (m = 1; m < mult; ++m)
1520  expression << "*" << NameMap[prod->getMetaboliteKey()];
1521  }
1522  }
1523  }
1524 
1525  std::string name = translateObjectName(reac->getFunction()->getObjectName());
1526  std::ostringstream localKey;
1527  localKey << reac->getKey() << "_root_func";
1528  NameMap[localKey.str()] = name;
1529 
1530  std::string str1 = expression.str();
1531  std::string str2 = comments.str();
1532 
1533  //functions << std::endl;
1534 
1535  if (!exportSingleObject(functions, name, str1, str2)) return false;
1536 
1537  //functions << std::endl;
1538 
1539  return true;
1540 }
virtual size_t getVariableIndex(const std::string &name) const
Definition: CFunction.cpp:133
const std::string & getObjectName() const
virtual size_t size() const
CCopasiObject * get(const std::string &key)
virtual const std::string & getKey() const
Definition: CReaction.cpp:190
virtual bool exportSingleObject(std::ostringstream &which, const std::string &name, const std::string &expression, const std::string &comments)
bool isLocalParameter(const size_t &index) const
Definition: CReaction.cpp:449
const CEvaluationTree::Type & getType() const
virtual const std::string & getKey() const
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
static Type type(const Type &type)
const CFunction * getFunction() const
Definition: CReaction.cpp:252
std::ostringstream functions
Definition: CODEExporter.h:158
const TriLogic & isReversible() const
Definition: CFunction.cpp:145
virtual const std::string & getKey() const
virtual const std::string & getKey() const
const C_FLOAT64 & getMultiplicity() const
const std::string & getMetaboliteKey() const
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
virtual std::string translateObjectName(const std::string &realName)
void modifyTreeForMassAction(CFunction *tmpfunc)
static CKeyFactory * getKeyFactory()
std::map< std::string, std::string > NameMap
Definition: CODEExporter.h:151
std::string timeKey
Definition: CODEExporter.h:152
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
const std::vector< std::vector< std::string > > & getParameterMappings() const
Definition: CReaction.h:285
virtual std::string getDisplayFunctionString(CFunction *func)
const CChemEq & getChemEq() const
Definition: CReaction.cpp:223
CEvaluationNode * getRoot()
bool exportSingleFunction(const CFunction *func)
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
bool CODEExporter::exportKineticFunctionGroup ( const CModel copasiModel)
virtual

Reimplemented in CODEExporterC.

Definition at line 1651 of file CODEExporter.cpp.

Referenced by exportToStream().

1652 {return true;}
bool CODEExporter::exportMetabolites ( const CModel copasiModel)
virtual

Definition at line 889 of file CODEExporter.cpp.

References CModelEntity::ASSIGNMENT, C_FLOAT64, exportNumber(), exportSingleMetabolite(), exportSingleObject(), CModelEntity::FIXED, fixed, CMetab::getCompartment(), CMetabNameInterface::getDisplayName(), CMetab::getInitialConcentration(), CModelEntity::getInitialValue(), CCopasiObject::getKey(), CModel::getL(), CModel::getMetabolitesX(), CModel::getNumIndependentReactionMetabs(), CModel::getNumODEMetabs(), CCopasiObject::getObjectName(), CModelEntity::getStatus(), CMetab::isDependent(), NameMap, CModelEntity::ODE, CModelEntity::REACTIONS, CCopasiVector< T >::size(), and CModelEntity::StatusName.

Referenced by exportToStream().

890 {
891 
892  const CCopasiVector< CMetab > & metabs = copasiModel->getMetabolitesX();
893  const CLinkMatrixView & L = copasiModel->getL();
894 
895  size_t metabs_size = metabs.size();
896  size_t indep_size = copasiModel->getNumIndependentReactionMetabs();
897  size_t ode_size = copasiModel->getNumODEMetabs();
898  size_t conservedTotals = 0;
899  size_t i, j;
900  C_FLOAT64 value;
901 
902  for (i = 0; i < metabs_size; i++)
903  {
904  const CMetab * metab;
905  metab = metabs[i];
906 
907  //if (!metab->isUsed()) continue;
908 
909  std::ostringstream expression;
910  std::ostringstream comments;
911 
912  std::string str1;
913  std::string str2;
914 
915  comments << "metabolite \'" << CMetabNameInterface::getDisplayName(copasiModel, *metab, false)
916  << "\': " << CModelEntity::StatusName[metab->getStatus()];
917 
918  switch (metab->getStatus())
919  {
920  case CModelEntity::FIXED:
921  {
922  const CCompartment * comp;
923  comp = metab->getCompartment();
924  C_FLOAT64 volume = comp->getInitialValue();
925 
926  value = metab->getInitialConcentration() * volume;
927 
928  expression << exportNumber(value);
929 
930  break;
931  }
932 
934 
935  break;
936 
937  case CModelEntity::ODE:
938  {
939 
940  const CCompartment * comp;
941  comp = metab->getCompartment();
942  C_FLOAT64 volume = comp->getInitialValue();
943 
944  value = metab->getInitialConcentration() * volume;
945 
946  expression << exportNumber(value);
947 
948  break;
949  }
950 
952  {
953  const CCompartment * comp;
954  comp = metab->getCompartment();
955  C_FLOAT64 volume = comp->getInitialValue();
956 
957  std::ostringstream tmp;
958  std::ostringstream more;
959  value = metab->getInitialConcentration() * volume;
960  double eps = std::numeric_limits<double>::epsilon();
961  more.precision(16);
962 
963  if (metab->isDependent())
964  {
965  for (j = 0; j < indep_size; j++)
966  {
967 
968  if (fabs(L(i - ode_size, j)) > eps)
969  {
970 
971  if (L(i - ode_size, j) < 0.0)
972  {
973  tmp << "-";
974  }
975  else
976  {
977  tmp << "+";
978  }
979 
980  if (fabs(fabs(L(i - ode_size, j)) - 1.0) > eps)
981  {
982  tmp << fabs(L(i - ode_size, j)) << "*";
983  }
984 
985  std::ostringstream jsmKey;
986  jsmKey << "sm_" << metabs[ode_size + j]->getKey();
987 
988  tmp << NameMap[jsmKey.str()];
989  const CCompartment * compj = metabs[ode_size + j]->getCompartment();
990 
991  value -= L(i - ode_size, j) * metabs[ode_size + j]->getInitialConcentration() * compj->getInitialValue();
992  }
993 
994  // comments << " dependent ";
995  }
996 
997  more << value;
998  std::stringstream stream; stream << "ct[" << (conservedTotals++) << "]";
999  std::string ctName(stream.str());
1000  NameMap["CT " + metab->getObjectName()] = ctName;
1001  stream.clear(); stream << " conserved total for '" << metab->getObjectName() << "'";
1002  exportSingleObject(fixed, ctName, more.str(), stream.str());
1003  expression << ctName << tmp.str();
1004  }
1005  else
1006  {
1007  more << exportNumber(value);
1008  expression << more.str() << tmp.str();
1009  }
1010 
1011  break;
1012  }
1013 
1014  default:
1015 
1016  return false;
1017 
1018  break;
1019  }
1020 
1021  str1 = expression.str();
1022  str2 = comments.str();
1023 
1024  if (metab->getStatus() != CModelEntity::ASSIGNMENT)
1025  if (!exportSingleMetabolite(metab, str1, str2)) return false;
1026  }
1027 
1028  return true;
1029 }
static const std::string StatusName[]
Definition: CModelValue.h:67
const CLinkMatrixView & getL() const
Definition: CModel.cpp:1166
const std::string & getObjectName() const
virtual size_t size() const
const C_FLOAT64 & getInitialConcentration() const
Definition: CMetab.cpp:220
virtual bool exportSingleObject(std::ostringstream &which, const std::string &name, const std::string &expression, const std::string &comments)
size_t getNumODEMetabs() const
Definition: CModel.cpp:1124
static std::string getDisplayName(const CModel *model, const std::string &key, const bool &quoted)
Definition: CMetab.h:178
virtual const std::string & getKey() const
const C_FLOAT64 & getInitialValue() const
size_t getNumIndependentReactionMetabs() const
Definition: CModel.cpp:1130
bool isDependent() const
Definition: CMetab.cpp:989
virtual std::string exportNumber(double number)
#define C_FLOAT64
Definition: copasi.h:92
std::map< std::string, std::string > NameMap
Definition: CODEExporter.h:151
virtual bool exportSingleMetabolite(const CMetab *metab, std::string &expression, std::string &comments)
std::ostringstream fixed
Definition: CODEExporter.h:156
const CModelEntity::Status & getStatus() const
const CCopasiVector< CMetab > & getMetabolitesX() const
Definition: CModel.cpp:1057
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
bool CODEExporter::exportMetabolitesConcentrations ( const CModel copasiModel)
virtual

Definition at line 1032 of file CODEExporter.cpp.

References assignment, exportSingleObject(), CMetabNameInterface::getDisplayName(), CModelEntity::getKey(), CCopasiObject::getKey(), CModel::getMetabolitesX(), CModelEntity::getStatus(), NameMap, CCopasiVector< T >::size(), and CModelEntity::StatusName.

Referenced by exportToStream().

1033 {
1034 
1035  const CCopasiVector< CMetab > & metabs = copasiModel->getMetabolitesX();
1036 
1037  size_t metabs_size = metabs.size();
1038 
1039  size_t i;
1040 
1041  for (i = 0; i < metabs_size; i++)
1042  {
1043  const CMetab * metab;
1044  metab = metabs[i];
1045 
1046  //if (!metab->isUsed()) continue;
1047 
1048  std::string str1;
1049  std::string str2;
1050 
1051  std::ostringstream expression;
1052  std::ostringstream comments;
1053 
1054  comments << "concentration of metabolite \'" << CMetabNameInterface::getDisplayName(copasiModel, *metab, false)
1055  << "\': " << CModelEntity::StatusName[metab->getStatus()];
1056 
1057  std::ostringstream smKey;
1058  smKey << "sm_" << metab->getKey();
1059 
1060  expression << NameMap[smKey.str()] << "/" << NameMap[metabs[i]->getCompartment()->getKey()];
1061 
1062  str1 = expression.str();
1063  str2 = comments.str();
1064 
1065  if (!exportSingleObject(assignment, NameMap[metab->getKey()], str1, str2))
1066  return false;
1067  }
1068 
1069  return true;
1070 }
static const std::string StatusName[]
Definition: CModelValue.h:67
virtual size_t size() const
virtual bool exportSingleObject(std::ostringstream &which, const std::string &name, const std::string &expression, const std::string &comments)
static std::string getDisplayName(const CModel *model, const std::string &key, const bool &quoted)
Definition: CMetab.h:178
virtual const std::string & getKey() const
virtual const std::string & getKey() const
std::map< std::string, std::string > NameMap
Definition: CODEExporter.h:151
std::ostringstream assignment
Definition: CODEExporter.h:157
const CModelEntity::Status & getStatus() const
const CCopasiVector< CMetab > & getMetabolitesX() const
Definition: CModel.cpp:1057
bool CODEExporter::exportModelEntityExpression ( CCopasiObject obj,
const CCopasiDataModel pDataModel 
)

Definition at line 291 of file CODEExporter.cpp.

References CModelEntity::ASSIGNMENT, equations, exportExpression(), exportSingleModelEntity(), exportSingleODE(), findFunctionsCalls(), CModelEntity::FIXED, CMetab::getCompartment(), CModelEntity::getExpressionPtr(), CModelEntity::getKey(), CCopasiObject::getObjectName(), CCopasiObject::getObjectParent(), CCopasiObject::getObjectType(), CEvaluationTree::getRoot(), CModelEntity::getStatus(), isEmptyString(), isModelEntityExpressionODEExporterCompatible(), CCopasiObject::isReference(), NameMap, CModelEntity::ODE, and CModelEntity::StatusName.

Referenced by exportModelValuesExpressions(), and exportSimulatedObject().

292 {
293  if (obj == NULL || pDataModel == NULL)
294  return false;
295 
296  if (obj->isReference())
297  {
298  CCopasiObject* parent = obj->getObjectParent();
299  return exportModelEntityExpression(parent, pDataModel);
300  }
301  else
302  {
303  std::string typeString = obj->getObjectType();
304 
305  CModelEntity* tmp;
306  tmp = dynamic_cast< CModelEntity * >(obj);
307 
308  std::ostringstream comments;
309  std::ostringstream expression;
310 
311  std::string str1;
312  std::string str2;
313 
314  comments << "model entity \'" << tmp->getObjectName() << "\':" << CModelEntity::StatusName[tmp->getStatus()];
315 
316  if (tmp->getStatus() == CModelEntity::ODE)
317  {
318  const CExpression* pExpression = tmp->getExpressionPtr();
319  assert(pExpression);
320 
321  findFunctionsCalls(pExpression->getRoot());
322 
323  std::string result;
324  result = isModelEntityExpressionODEExporterCompatible(tmp, pExpression, pDataModel);
325 
326  if ((isEmptyString(result)))
327  {
328  expression << exportExpression(pExpression, pDataModel);
329  }
330 
331  equations[tmp->getKey()] = expression.str();
332  }
333 
334  switch (tmp->getStatus())
335  {
336  case CModelEntity::FIXED:
337  break;
338 
340  {
341 
342  const CExpression* pExpression = tmp->getExpressionPtr();
343  assert(pExpression);
344 
345  findFunctionsCalls(pExpression->getRoot());
346 
347  std::string result;
348  result = isModelEntityExpressionODEExporterCompatible(tmp, pExpression, pDataModel);
349 
350  if (!(isEmptyString(result)))
351  comments << result;
352  else
353  {
354  expression << exportExpression(pExpression, pDataModel);
355  }
356 
357  str1 = expression.str();
358  str2 = comments.str();
359 
360  CMetab* metab;
361  metab = dynamic_cast< CMetab * >(tmp);
362 
363  if (metab)
364  {
365  std::ostringstream convert;
366  const CCompartment * comp = metab->getCompartment();
367  convert << " * " << NameMap[comp->getKey()];
368  str1 += convert.str();
369  }
370 
371  if (!exportSingleModelEntity(tmp, str1, str2)) return false;
372 
373  break;
374  }
375 
376  case CModelEntity::ODE:
377  {
378 
379  const CExpression* pExpression = tmp->getExpressionPtr();
380  assert(pExpression);
381 
382  findFunctionsCalls(pExpression->getRoot());
383 
384  std::string result;
385  result = isModelEntityExpressionODEExporterCompatible(tmp, pExpression, pDataModel);
386 
387  if (!(isEmptyString(result)))
388  comments << result;
389 
390  str1 = equations[tmp->getKey()];
391  str2 = comments.str();
392 
393  CMetab* metab;
394  metab = dynamic_cast< CMetab * >(tmp);
395 
396  if (metab)
397  {
398  std::ostringstream convert;
399  const CCompartment * comp = metab->getCompartment();
400  convert << " * " << NameMap[comp->getKey()];
401  str1 += convert.str();
402  }
403 
404  if (!exportSingleODE(tmp, str1, str2)) return false;
405 
406  break;
407  }
408 
409  default:
410  return false;
411  break;
412  }
413  }
414 
415  return true;
416 }
const CExpression * getExpressionPtr() const
std::string isModelEntityExpressionODEExporterCompatible(CModelEntity *tmp, const CExpression *pExpression, const CCopasiDataModel *pDataModel)
static const std::string StatusName[]
Definition: CModelValue.h:67
const std::string & getObjectName() const
const std::string & getObjectType() const
Definition: CMetab.h:178
std::map< std::string, std::string > equations
Definition: CODEExporter.h:153
std::string exportExpression(const CExpression *pExpression, const CCopasiDataModel *pDataModel)
virtual bool isEmptyString(std::string &str)
bool isReference() const
virtual const std::string & getKey() const
virtual bool exportSingleModelEntity(const CModelEntity *tmp, std::string &expression, std::string &comments)
bool exportModelEntityExpression(CCopasiObject *obj, const CCopasiDataModel *pDataModel)
virtual bool exportSingleODE(const CModelEntity *mentity, std::string &equation, std::string &comments)
std::map< std::string, std::string > NameMap
Definition: CODEExporter.h:151
void findFunctionsCalls(const CEvaluationNode *pNode)
const CModelEntity::Status & getStatus() const
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
CEvaluationNode * getRoot()
CCopasiContainer * getObjectParent() const
bool CODEExporter::exportModelValues ( const CModel copasiModel)

Definition at line 1132 of file CODEExporter.cpp.

References CModelEntity::ASSIGNMENT, exportNumber(), exportSingleModVal(), CModelEntity::FIXED, CModelEntity::getInitialValue(), CModel::getModelValues(), CCopasiObject::getObjectName(), CModelEntity::getStatus(), CModelEntity::ODE, CCopasiVector< T >::size(), and CModelEntity::StatusName.

Referenced by exportToStream().

1133 {
1134  const CCopasiVector< CModelValue > & modvals = copasiModel->getModelValues();
1135 
1136  size_t modvals_size = modvals.size();
1137  size_t i;
1138 
1139  for (i = 0; i < modvals_size; i++)
1140  {
1141  CModelValue* modval;
1142  modval = modvals[i];
1143 
1144  std::ostringstream comments;
1145  std::ostringstream expression;
1146 
1147  std::string str1;
1148  std::string str2;
1149 
1150  comments << "global quantity \'" << modval->getObjectName() << "\':" << CModelEntity::StatusName[modval->getStatus()];
1151 
1152  switch (modval->getStatus())
1153  {
1154  case CModelEntity::FIXED:
1155  {
1156  expression << exportNumber(modval->getInitialValue());
1157 
1158  break;
1159  }
1160 
1162  //{
1163  //CExpression *cexpression = new CExpression(*modval->getExpressionPtr());
1164  //CEvaluationNode *node = cexpression->getRoot();
1165  //const std::string &key = modval->getKey();
1166  //size_t index = 0;
1167  //if (!exportSingleFunction(node, key, index))
1168  // return false;
1169  //expression << getDisplayExpressionString(cexpression);
1170  //}
1171  break;
1172 
1173  case CModelEntity::ODE:
1174  {
1175  expression << exportNumber(modval->getInitialValue());
1176 
1177  break;
1178  }
1179 
1180  default:
1181  return false;
1182  break;
1183  }
1184 
1185  str1 = expression.str();
1186  str2 = comments.str();
1187 
1188  if (modval->getStatus() != CModelEntity::ASSIGNMENT)
1189  if (!exportSingleModVal(modval, str1, str2)) return false;
1190  }
1191 
1192  return true;
1193 }
virtual bool exportSingleModVal(const CModelValue *modval, std::string &expression, std::string &comments)
static const std::string StatusName[]
Definition: CModelValue.h:67
const std::string & getObjectName() const
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
virtual size_t size() const
const C_FLOAT64 & getInitialValue() const
virtual std::string exportNumber(double number)
const CModelEntity::Status & getStatus() const
bool CODEExporter::exportModelValuesExpressions ( const CModel copasiModel)

Definition at line 96 of file CODEExporter.cpp.

References CModelEntity::ASSIGNMENT, exportModelEntityExpression(), findFunctionsCalls(), CModel::getCompartments(), CModelEntity::getExpressionPtr(), CModel::getMetabolites(), CModel::getModelValues(), CModel::getNumMetabs(), CModel::getNumModelValues(), CCopasiObject::getObjectDataModel(), CEvaluationTree::getRoot(), CModelEntity::getStatus(), and CCopasiVector< T >::size().

Referenced by exportToStream().

97 {
98  size_t i, size = copasiModel->getNumModelValues();
99 
100  for (i = 0; i < size; ++i)
101  {
102  CModelEntity* entity = copasiModel->getModelValues()[i];
103 
104  if (entity->getStatus() == CModelEntity::ASSIGNMENT)
105  {
106  if (entity->getExpressionPtr() == NULL || entity->getExpressionPtr()->getRoot() == NULL)
107  continue;
108 
111  }
112  }
113 
114  size = copasiModel->getNumMetabs();
115 
116  for (i = 0; i < size; ++i)
117  {
118  CModelEntity* entity = copasiModel->getMetabolites()[i];
119 
120  if (entity->getStatus() == CModelEntity::ASSIGNMENT)
121  {
122  if (entity->getExpressionPtr() == NULL || entity->getExpressionPtr()->getRoot() == NULL)
123  continue;
124 
127  }
128  }
129 
130  size = copasiModel->getCompartments().size();
131 
132  for (i = 0; i < size; ++i)
133  {
134  CModelEntity* entity = copasiModel->getCompartments()[i];
135 
136  if (entity->getStatus() == CModelEntity::ASSIGNMENT)
137  {
138  if (entity->getExpressionPtr() == NULL || entity->getExpressionPtr()->getRoot() == NULL)
139  continue;
140 
143  }
144  }
145 
146  return true;
147 }
const CExpression * getExpressionPtr() const
CCopasiDataModel * getObjectDataModel()
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
virtual size_t size() const
size_t getNumMetabs() const
Definition: CModel.cpp:1118
bool exportModelEntityExpression(CCopasiObject *obj, const CCopasiDataModel *pDataModel)
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
size_t getNumModelValues() const
Definition: CModel.cpp:1139
void findFunctionsCalls(const CEvaluationNode *pNode)
const CModelEntity::Status & getStatus() const
CEvaluationNode * getRoot()
std::string CODEExporter::exportNumber ( double  number)
virtual

Reimplemented in CODEExporterC.

Definition at line 882 of file CODEExporter.cpp.

Referenced by exportCompartments(), exportExpression(), exportMetabolites(), and exportModelValues().

883 {
884  std::stringstream str; str << number;
885  return str.str();
886 }
void CODEExporter::exportObjectNodesFromModel ( const CCopasiDataModel pDataModel)

Definition at line 197 of file CODEExporter.cpp.

References exportSimulatedObject(), findObjectFromRefresh(), CModel::getListOfSimulatedRefreshes(), and CCopasiDataModel::getModel().

Referenced by exportToStream().

198 {
199 
200  size_t i, imax;
201 
202  imax = pDataModel->getModel()->getListOfSimulatedRefreshes().size();
203 
204  for (i = 0; i < imax; ++i)
205  {
206  CCopasiObject * obj = findObjectFromRefresh(pDataModel, pDataModel->getModel()->getListOfSimulatedRefreshes()[i]);
207 
208  if (obj) exportSimulatedObject(obj, pDataModel);
209  }
210 }
void exportSimulatedObject(CCopasiObject *obj, const CCopasiDataModel *pDataModel)
const std::vector< Refresh * > & getListOfSimulatedRefreshes() const
Definition: CModel.cpp:4136
CCopasiObject * findObjectFromRefresh(const CCopasiObject *tmp, const Refresh *ref)
bool CODEExporter::exportODEs ( const CModel copasiModel)

Definition at line 1276 of file CODEExporter.cpp.

References equations, exportSingleODE(), CModelEntity::getKey(), CModel::getMetabolitesX(), CModel::getNumIndependentReactionMetabs(), CModel::getNumODEMetabs(), CModelEntity::getStatus(), CMetab::isDependent(), CModelEntity::REACTIONS, and CCopasiVector< T >::size().

Referenced by exportToStream().

1277 {
1278  const CCopasiVector< CMetab > & metabs = copasiModel->getMetabolitesX();
1279  size_t indep_size = copasiModel->getNumIndependentReactionMetabs();
1280  size_t ode_size = copasiModel->getNumODEMetabs();
1281  size_t metabs_size = metabs.size();
1282 
1283  size_t i;
1284 
1285  for (i = 0; i < indep_size && i + ode_size < metabs_size; ++i)
1286  {
1287  CMetab * metab = metabs[ode_size + i];
1288 
1289  std::string str1 = equations[metab->getKey()];
1290  std::string str2 = " ";
1291 
1292  if ((metab->getStatus() == CModelEntity::REACTIONS && !(metab->isDependent())))
1293  if (!exportSingleODE(metab, str1, str2)) return false;
1294  }
1295 
1296  for (i = indep_size; i + ode_size < metabs_size; ++i)
1297  {
1298  CMetab * metab = metabs[ode_size + i];
1299 
1300  if (metab->getStatus() == CModelEntity::REACTIONS && !metab->isDependent())
1301  {
1302  std::string str1 = "0";
1303  std::string str2 = " ";
1304 
1305  if (!exportSingleODE(metab, str1, str2)) return false;
1306  }
1307  }
1308 
1309  return true;
1310 }
virtual size_t size() const
size_t getNumODEMetabs() const
Definition: CModel.cpp:1124
Definition: CMetab.h:178
std::map< std::string, std::string > equations
Definition: CODEExporter.h:153
virtual const std::string & getKey() const
size_t getNumIndependentReactionMetabs() const
Definition: CModel.cpp:1130
bool isDependent() const
Definition: CMetab.cpp:989
virtual bool exportSingleODE(const CModelEntity *mentity, std::string &equation, std::string &comments)
const CModelEntity::Status & getStatus() const
const CCopasiVector< CMetab > & getMetabolitesX() const
Definition: CModel.cpp:1057
bool CODEExporter::exportReacParamsAndFuncs ( const CModel copasiModel)

Definition at line 1197 of file CODEExporter.cpp.

References equations, exportKineticFunction(), exportSingleParameter(), CReaction::getCompartmentNumber(), CCopasiObject::getKey(), CModel::getMetabolitesX(), CModel::getNumIndependentReactionMetabs(), CModel::getNumODEMetabs(), CCopasiObject::getObjectName(), CCopasiParameterGroup::getParameter(), CReaction::getParameters(), CModel::getReactions(), CModel::getRedStoi(), CCopasiParameter::getValue(), isEmptyString(), CReaction::isLocalParameter(), KineticFunction2ODEmember(), NameMap, CCopasiParameter::Value::pDOUBLE, CCopasiVector< T >::size(), and CCopasiParameterGroup::size().

Referenced by exportToStream().

1198 {
1199 
1200  const CCopasiVector< CMetab > & metabs = copasiModel->getMetabolitesX();
1201  const CCopasiVector< CReaction > & reacs = copasiModel->getReactions();
1202 
1203  size_t reacs_size = reacs.size();
1204  size_t indep_size = copasiModel->getNumIndependentReactionMetabs();
1205  size_t ode_size = copasiModel->getNumODEMetabs();
1206 
1207  const CMatrix< C_FLOAT64 > & redStoi = copasiModel->getRedStoi();
1208 
1209  size_t i, j;
1210 
1211  for (i = 0; i < reacs_size; ++i)
1212  {
1213  CReaction* reac;
1214  reac = reacs[i];
1215 
1216  std::string name = reac->getObjectName();
1217 
1218  size_t params_size = reac->getParameters().size();
1219 
1220  for (j = 0; j < params_size; ++j)
1221  {
1222  if (!reac->isLocalParameter(j))
1223  continue;
1224 
1225  std::ostringstream comments;
1226  std::ostringstream expression;
1227 
1228  CCopasiParameter* param;
1229 
1230  param = reac->getParameters().getParameter(j);
1231  expression << *param->getValue().pDOUBLE;
1232 
1233  comments << "reaction \'" << name << "\': " <<
1234  " kinetic parameter \'" << param->getObjectName() << "\'";
1235 
1236  std::string str1 = expression.str();
1237  std::string str2 = comments.str();
1238 
1239  if (!exportSingleParameter(param, str1, str2)) return false;
1240  }
1241 
1242  if (!exportKineticFunction(reac)) return false;
1243 
1244  for (j = 0; j < indep_size; ++j)
1245  {
1246  std::ostringstream jequation;
1247 
1248  if (fabs(redStoi[j][i]) > 0.0)
1249  {
1250  if (redStoi[j][i] < 0.0)
1251  jequation << "-";
1252  else
1253  {
1254  std::string str1 = equations[metabs[ode_size + j]->getKey()];
1255 
1256  if (!(isEmptyString(str1)))
1257  jequation << "+";
1258  }
1259 
1260  if (fabs(redStoi[j][i]) != 1.0)
1261  jequation << fabs(redStoi[j][i]) << "*";
1262 
1263  jequation << KineticFunction2ODEmember(reac);
1264 
1265  if (reac->getCompartmentNumber() == 1) jequation << "*" << NameMap[metabs[ode_size + j]->getCompartment()->getKey()];
1266 
1267  equations[metabs[ode_size + j]->getKey()] += jequation.str();
1268  }
1269  }
1270  }
1271 
1272  return true;
1273 }
virtual bool exportKineticFunction(CReaction *reac)
const std::string & getObjectName() const
virtual size_t size() const
bool isLocalParameter(const size_t &index) const
Definition: CReaction.cpp:449
size_t getNumODEMetabs() const
Definition: CModel.cpp:1124
const CMatrix< C_FLOAT64 > & getRedStoi() const
Definition: CModel.cpp:1154
std::map< std::string, std::string > equations
Definition: CODEExporter.h:153
virtual const std::string & getKey() const
virtual bool isEmptyString(std::string &str)
const Value & getValue() const
virtual bool exportSingleParameter(const CCopasiParameter *param, std::string &expression, std::string &comments)
CCopasiParameter * getParameter(const std::string &name)
size_t getNumIndependentReactionMetabs() const
Definition: CModel.cpp:1130
std::map< std::string, std::string > NameMap
Definition: CODEExporter.h:151
const CCopasiParameterGroup & getParameters() const
Definition: CReaction.cpp:333
size_t getCompartmentNumber() const
Definition: CReaction.cpp:873
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
virtual std::string KineticFunction2ODEmember(const CReaction *reac)
const CCopasiVector< CMetab > & getMetabolitesX() const
Definition: CModel.cpp:1057
void CODEExporter::exportSimulatedObject ( CCopasiObject obj,
const CCopasiDataModel pDataModel 
)

Definition at line 256 of file CODEExporter.cpp.

References exportModelEntityExpression(), CCopasiObject::getObjectName(), CCopasiObject::getObjectParent(), CCopasiObject::getObjectType(), and CCopasiObject::isReference().

Referenced by exportObjectNodesFromModel().

257 {
258  if (obj == NULL || pDataModel == NULL)
259  return;
260 
261  if (obj->isReference())
262  {
263  CCopasiObject* parent = obj->getObjectParent();
264  assert(parent);
265  std::string typeString = parent->getObjectType();
266  std::string name = obj->getObjectName();
267 
268  if (typeString == "Metabolite" || typeString == "ModelValue" || typeString == "Compartment")
269  {
270  if (name == "Concentration" || name == "Value"
271  || name == "Volume" || name == "Rate"
272  || name == "ParticleNumberRate")
273  {
274  if (!exportModelEntityExpression(obj, pDataModel))
275  {
276  return;
277  }
278  else
279  {
280  return;
281  }
282  }
283  }
284 
285  //TODO warning for initial assignments
286  }
287 
288  return;
289 }
const std::string & getObjectName() const
const std::string & getObjectType() const
bool isReference() const
bool exportModelEntityExpression(CCopasiObject *obj, const CCopasiDataModel *pDataModel)
CCopasiContainer * getObjectParent() const
bool CODEExporter::exportSingleCompartment ( const CCompartment comp,
std::string &  expression,
std::string &  comments 
)
virtual

Reimplemented in CODEExporterC, CODEExporterXPPAUT, and CODEExporterBM.

Definition at line 1342 of file CODEExporter.cpp.

Referenced by exportCompartments().

1345 {return true;}
bool CODEExporter::exportSingleFunction ( const CFunction func)

Definition at line 65 of file CODEExporter.cpp.

References mExportedFunctions.

Referenced by exportKineticFunction(), CODEExporterC::exportKineticFunctionGroup(), exportSingleFunction(), and findFunctionsCalls().

66 {
68 }
std::set< std::string > mExportedFunctions
Definition: CODEExporter.h:30
bool exportSingleFunction(const CFunction *func)
bool CODEExporter::exportSingleFunction ( const CFunction func,
std::set< std::string > &  isExported 
)
virtual

Reimplemented in CODEExporterC.

Definition at line 149 of file CODEExporter.cpp.

150 {
151  return true;
152 }
bool CODEExporter::exportSingleFunction ( CEvaluationNode pNode,
const CReaction reac,
size_t &  index 
)

Definition at line 1542 of file CODEExporter.cpp.

References exportSingleFunction(), and CReaction::getKey().

1543 {
1544  return exportSingleFunction(pNode, reac->getKey(), index);
1545 }
virtual const std::string & getKey() const
Definition: CReaction.cpp:190
bool exportSingleFunction(const CFunction *func)
bool CODEExporter::exportSingleFunction ( CEvaluationNode pNode,
const std::string &  key,
size_t &  index 
)

Definition at line 1547 of file CODEExporter.cpp.

References CCopasiNode< _Data >::addChild(), CEvaluationNode::CALL, CEvaluationNode::copyBranch(), exportSingleFunction(), exportSingleObject(), CFunctionDB::findFunction(), functions, getDisplayFunctionString(), CCopasiRootContainer::getFunctionList(), CCopasiObject::getObjectName(), CEvaluationTree::getRoot(), CFunction::getVariableIndex(), modifyTreeForMassAction(), NameMap, CCopasiNode< _Data >::removeChild(), translateObjectName(), CEvaluationNode::type(), and CEvaluationNode::VARIABLE.

1548 {
1549  if (pNode)
1550  {
1553 
1554  while (treeIt != NULL)
1555  {
1556  if (CEvaluationNode::type(treeIt->getType()) == CEvaluationNode::CALL)
1557  {
1558  const CFunction* func;
1559  func = static_cast<CFunction*>(pFunctionDB->findFunction((*treeIt).getData()));
1560 
1561  CFunction* tmpfunc = NULL;
1562  tmpfunc = new CFunction(*func);
1563 
1564  std::ostringstream localKey;
1565 
1566  if (index)
1567  localKey << key << "_func_" << index;
1568  else
1569  localKey << key << "_root_func";
1570 
1571  index++;
1572 
1573  std::string name = translateObjectName(func->getObjectName());
1574  NameMap[localKey.str()] = name;
1575 
1576  treeIt->setData(name);
1577 
1579 
1580  size_t i, vindex;
1581  CEvaluationNode* tmproot = tmpfunc->getRoot();
1582  CCopasiTree<CEvaluationNode>::iterator iIt, newIt = tmproot;
1583 
1584  if (CEvaluationNode::type(newIt->getType()) == CEvaluationNode::VARIABLE)
1585  {
1586  CEvaluationNode* child = dynamic_cast<CEvaluationNode*>(treeIt->getChild());
1587  tmproot = child->copyBranch();
1588  }
1589  else while (newIt != NULL)
1590  {
1591  if (CEvaluationNode::type(newIt->getType()) == CEvaluationNode::VARIABLE)
1592  {
1593  vindex = tmpfunc->getVariableIndex((*newIt).getData());
1594 
1595  CEvaluationNode* child = dynamic_cast<CEvaluationNode*>(treeIt->getChild());
1596 
1597  for (i = 0; i < vindex ; i++)
1598  child = dynamic_cast<CEvaluationNode*>((child)->getSibling());
1599 
1600  CEvaluationNode* parent = dynamic_cast<CEvaluationNode*>(newIt->getParent());
1601  CEvaluationNode* newnode = child->copyBranch();
1602 
1603  iIt = newIt;
1604 
1605  ++newIt;
1606 
1607  if (parent)
1608  {
1609  parent->addChild(newnode, &(*iIt));
1610  parent->removeChild(&(*iIt));
1611  }
1612 
1613  delete &(*iIt);
1614  }
1615  else
1616  ++newIt;
1617  }
1618 
1619  if (!exportSingleFunction(tmproot, key, index)) return false;
1620 
1621  std::string expression;
1622  std::string comments = " ";
1623 
1624  expression = getDisplayFunctionString(tmpfunc);
1625 
1626  //functions << std::endl;
1627 
1628  if (!exportSingleObject(functions, name, expression, comments)) return false;
1629 
1630  //functions << std::endl;
1631  }
1632 
1633  ++treeIt;
1634  }
1635  }
1636 
1637  return true;
1638 }
CEvaluationNode * copyBranch() const
virtual size_t getVariableIndex(const std::string &name) const
Definition: CFunction.cpp:133
const std::string & getObjectName() const
virtual bool exportSingleObject(std::ostringstream &which, const std::string &name, const std::string &expression, const std::string &comments)
static Type type(const Type &type)
std::ostringstream functions
Definition: CODEExporter.h:158
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
static CFunctionDB * getFunctionList()
virtual std::string translateObjectName(const std::string &realName)
void modifyTreeForMassAction(CFunction *tmpfunc)
std::map< std::string, std::string > NameMap
Definition: CODEExporter.h:151
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
virtual bool removeChild(CCopasiNode< Data > *pChild)
Definition: CCopasiNode.h:181
CFunction * findFunction(const std::string &functionName)
virtual std::string getDisplayFunctionString(CFunction *func)
CEvaluationNode * getRoot()
bool exportSingleFunction(const CFunction *func)
bool CODEExporter::exportSingleMetabolite ( const CMetab metab,
std::string &  expression,
std::string &  comments 
)
virtual

Reimplemented in CODEExporterC, CODEExporterXPPAUT, and CODEExporterBM.

Definition at line 1337 of file CODEExporter.cpp.

Referenced by exportMetabolites().

1340 {return true;}
bool CODEExporter::exportSingleModelEntity ( const CModelEntity tmp,
std::string &  expression,
std::string &  comments 
)
virtual

Reimplemented in CODEExporterC, CODEExporterXPPAUT, and CODEExporterBM.

Definition at line 1352 of file CODEExporter.cpp.

Referenced by exportModelEntityExpression().

1355 {return true;}
bool CODEExporter::exportSingleModVal ( const CModelValue modval,
std::string &  expression,
std::string &  comments 
)
virtual

Reimplemented in CODEExporterC, CODEExporterXPPAUT, and CODEExporterBM.

Definition at line 1347 of file CODEExporter.cpp.

Referenced by exportModelValues().

1350 {return true;}
bool CODEExporter::exportSingleObject ( std::ostringstream &  which,
const std::string &  name,
const std::string &  expression,
const std::string &  comments 
)
virtual
bool CODEExporter::exportSingleODE ( const CModelEntity mentity,
std::string &  equation,
std::string &  comments 
)
virtual

Reimplemented in CODEExporterC, CODEExporterXPPAUT, and CODEExporterBM.

Definition at line 1646 of file CODEExporter.cpp.

Referenced by exportModelEntityExpression(), and exportODEs().

1649 {return true;}
bool CODEExporter::exportSingleParameter ( const CCopasiParameter param,
std::string &  expression,
std::string &  comments 
)
virtual

Reimplemented in CODEExporterC, CODEExporterXPPAUT, and CODEExporterBM.

Definition at line 1357 of file CODEExporter.cpp.

Referenced by exportReacParamsAndFuncs().

1360 {return true;}
bool CODEExporter::exportTitleData ( const CModel copasiModel,
std::ostream &  os 
)
virtual

Reimplemented in CODEExporterC.

Definition at line 878 of file CODEExporter.cpp.

Referenced by exportToStream().

880 {return true;}
std::string CODEExporter::exportTitleString ( const size_t  tmp)
virtual

Reimplemented in CODEExporterC, CODEExporterXPPAUT, and CODEExporterBM.

Definition at line 1657 of file CODEExporter.cpp.

Referenced by exportToStream().

1658 {return " ";}
bool CODEExporter::exportToStream ( const CCopasiDataModel pDataModel,
std::ostream &  os 
)

Definition at line 154 of file CODEExporter.cpp.

References assignment, ASSIGNMENT, exportClosingData(), exportClosingString(), exportCompartments(), exportKineticFunctionGroup(), exportMetabolites(), exportMetabolitesConcentrations(), exportModelValues(), exportModelValuesExpressions(), exportObjectNodesFromModel(), exportODEs(), exportReacParamsAndFuncs(), exportTitleData(), exportTitleString(), fixed, FIXED, functions, FUNCTIONS, CCopasiDataModel::getModel(), headers, HEADERS, initial, INITIAL, mExportedFunctions, ode, ODEs, and preprocess().

Referenced by CCopasiDataModel::exportMathModel(), and CCopasiDataModel::exportMathModelToString().

155 {
156  mExportedFunctions.clear();
157 
158  /* translate COPASI data names in exporter syntax */
159  if (!preprocess(pDataModel->getModel())) return false;
160 
161  /* export COPASI data */
162 
163  if (!exportMetabolites(pDataModel->getModel())) return false;
164 
165  if (!exportCompartments(pDataModel->getModel())) return false;
166 
167  if (!exportModelValues(pDataModel->getModel())) return false;
168 
169  if (!exportReacParamsAndFuncs(pDataModel->getModel())) return false;
170 
171  if (!exportKineticFunctionGroup(pDataModel->getModel())) return false;
172 
173  if (!exportODEs(pDataModel->getModel())) return false;
174 
175  if (!exportModelValuesExpressions(pDataModel->getModel())) return false;
176 
177  exportObjectNodesFromModel(pDataModel);
178 
179  if (!exportMetabolitesConcentrations(pDataModel->getModel())) return false;
180 
181  // export title data, so that a list of additionally created entities can be exported.
182  // NOTE: this does not change the order in the file
183  if (!exportTitleData(pDataModel->getModel(), os)) return false;
184 
185  os << std::endl << exportTitleString(INITIAL) << std::endl << initial.str() << exportClosingString(INITIAL);
186  os << std::endl << exportTitleString(FIXED) << std::endl << fixed.str() << exportClosingString(FIXED);
187  os << std::endl << exportTitleString(ASSIGNMENT) << std::endl << assignment.str() << exportClosingString(ASSIGNMENT);
188  os << std::endl << exportTitleString(HEADERS) << std::endl << headers.str() << exportClosingString(HEADERS);
189  os << std::endl << exportTitleString(FUNCTIONS) << std::endl << functions.str() << exportClosingString(FUNCTIONS);
190  os << std::endl << exportTitleString(ODEs) << std::endl << ode.str() << exportClosingString(ODEs);
191 
192  if (!exportClosingData(pDataModel->getModel(), os)) return false;
193 
194  return true;
195 }
std::ostringstream headers
Definition: CODEExporter.h:159
virtual std::string exportTitleString(const size_t tmp)
virtual bool exportTitleData(const CModel *copasiModel, std::ostream &os)
virtual bool exportMetabolitesConcentrations(const CModel *copasiModel)
virtual bool preprocess(const CModel *copasiModel)
virtual bool exportMetabolites(const CModel *copasiModel)
std::ostringstream initial
Definition: CODEExporter.h:155
bool exportCompartments(const CModel *copasiModel)
virtual std::string exportClosingString(const size_t tmp)
std::ostringstream ode
Definition: CODEExporter.h:160
std::ostringstream functions
Definition: CODEExporter.h:158
bool exportModelValuesExpressions(const CModel *copasiModel)
virtual bool exportKineticFunctionGroup(const CModel *copasiModel)
bool exportReacParamsAndFuncs(const CModel *copasiModel)
bool exportModelValues(const CModel *copasiModel)
std::ostringstream assignment
Definition: CODEExporter.h:157
std::set< std::string > mExportedFunctions
Definition: CODEExporter.h:30
std::ostringstream fixed
Definition: CODEExporter.h:156
void exportObjectNodesFromModel(const CCopasiDataModel *pDataModel)
virtual bool exportClosingData(const CModel *copasiModel, std::ostream &os)
bool exportODEs(const CModel *copasiModel)
void CODEExporter::findFunctionsCalls ( const CEvaluationNode pNode)

Definition at line 70 of file CODEExporter.cpp.

References CEvaluationNode::CALL, exportSingleFunction(), CFunctionDB::findFunction(), CCopasiRootContainer::getFunctionList(), CEvaluationTree::getRoot(), CEvaluationTree::getType(), CEvaluationTree::MassAction, and CEvaluationNode::type().

Referenced by CODEExporterC::exportKineticFunctionGroup(), exportModelEntityExpression(), and exportModelValuesExpressions().

71 {
72  if (pNode == NULL) return;
73 
76 
77  while (treeIt != NULL)
78  {
79  if (CEvaluationNode::type(treeIt->getType()) == CEvaluationNode::CALL)
80  {
81  const CFunction* ifunc;
82  ifunc = static_cast<CFunction*>(pFunctionDB->findFunction((*treeIt).getData()));
83 
84  findFunctionsCalls(ifunc->getRoot());
85 
86  if (ifunc->getType() != CEvaluationTree::MassAction)
87  {
88  if (!exportSingleFunction(ifunc)) return;
89  }
90  }
91 
92  ++treeIt;
93  }
94 }
const CEvaluationTree::Type & getType() const
static Type type(const Type &type)
static CFunctionDB * getFunctionList()
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
void findFunctionsCalls(const CEvaluationNode *pNode)
CFunction * findFunction(const std::string &functionName)
CEvaluationNode * getRoot()
bool exportSingleFunction(const CFunction *func)
CCopasiObject * CODEExporter::findObjectFromRefresh ( const CCopasiObject tmp,
const Refresh ref 
)

Definition at line 212 of file CODEExporter.cpp.

References CCopasiContainer::getObjects(), and CCopasiObject::isContainer().

Referenced by exportObjectNodesFromModel().

213 {
214 
215  CCopasiObject* obj = NULL;
216 
217  if (tmp->isContainer())
218  {
219 
220  CCopasiContainer* container;
221  container = (CCopasiContainer*)tmp;
222 
223  CCopasiContainer::objectMap::const_iterator it = container->getObjects().begin();
224 
225  for (; it != container->getObjects().end(); ++it)
226  {
227 
228  //skip if the contained object is not owned by this container
229 
230  if (it->second->getObjectParent() != container) continue;
231 
232  if (it->second->getRefresh() == ref)
233  {
234  obj = it->second;
235 
236  return obj;
237  }
238 
239  //the next line skips name references...
240 
241  if (it->second->getObjectName() == "Name") continue;
242 
243  if (it->second->getObjectType() == "Function") continue;
244 
245  obj = findObjectFromRefresh(it->second, ref);
246 
247  if (obj) return obj;
248  }
249 
250  return NULL;
251  }
252 
253  return NULL;
254 }
bool isContainer() const
virtual const objectMap & getObjects() const
CCopasiObject * findObjectFromRefresh(const CCopasiObject *tmp, const Refresh *ref)
std::string CODEExporter::getDisplayExpressionString ( CExpression tmp)
virtual

Reimplemented in CODEExporterC, CODEExporterXPPAUT, and CODEExporterBM.

Definition at line 1643 of file CODEExporter.cpp.

Referenced by exportExpression().

1644 {return " ";}
std::string CODEExporter::getDisplayFunctionString ( CFunction func)
virtual

Reimplemented in CODEExporterXPPAUT, and CODEExporterBM.

Definition at line 1640 of file CODEExporter.cpp.

Referenced by exportKineticFunction(), and exportSingleFunction().

1641 {return " ";}
std::string CODEExporter::getSingleLineComment ( )
virtual

Reimplemented in CODEExporterC.

Definition at line 418 of file CODEExporter.cpp.

Referenced by isModelEntityExpressionODEExporterCompatible().

419 {
420  return "";
421 }
bool CODEExporter::isEmptyString ( std::string &  str)
virtual

This method tests if a string consists only of whitespace characters

Definition at line 1666 of file CODEExporter.cpp.

Referenced by exportExpression(), exportModelEntityExpression(), exportReacParamsAndFuncs(), and CODEExporterXPPAUT::exportSingleODE().

1667 {return (str.find_first_not_of(" \n\t\r") == std::string::npos);}
std::string CODEExporter::isModelEntityExpressionODEExporterCompatible ( CModelEntity tmp,
const CExpression pExpression,
const CCopasiDataModel pDataModel 
)

Definition at line 423 of file CODEExporter.cpp.

References CEvaluationTree::getNodeList(), CEvaluationNodeObject::getObjectCN(), CCopasiObject::getObjectName(), CCopasiObject::getObjectParent(), CCopasiObject::getObjectType(), getSingleLineComment(), CModelEntity::getStatus(), CMetab::isDependent(), CCopasiObject::isReference(), CEvaluationNode::OBJECT, CCopasiDataModel::ObjectFromName(), CModelEntity::REACTIONS, and CEvaluationNode::type().

Referenced by exportModelEntityExpression().

424 {
425 
426  std::ostringstream result;
427  const std::vector<CEvaluationNode*>& objectNodes = pExpression->getNodeList();
428  size_t j, jMax = objectNodes.size();
429  assert(pDataModel != NULL);
430 
431  for (j = 0; j < jMax; ++j)
432  {
433  if (CEvaluationNode::type(objectNodes[j]->getType()) == CEvaluationNode::OBJECT)
434  {
435  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(objectNodes[j]);
436  assert(pObjectNode);
437  std::vector<CCopasiContainer*> containers;
438  containers.push_back(const_cast<CCopasiDataModel*>(pDataModel)->getModel());
439  const CCopasiObject* pObject = pDataModel->ObjectFromName(containers, pObjectNode->getObjectCN());
440  assert(pObject);
441 
442  if (pObject->isReference())
443  {
444  CCopasiObject* pObjectParent = pObject->getObjectParent();
445  assert(pObjectParent);
446  std::string typeString = pObjectParent->getObjectType();
447 
448  if (typeString == "Compartment")
449  {
450  if (pObject->getObjectName() != "Volume"
451  && pObject->getObjectName() != "InitialVolume"
452  && pObject->getObjectName() != "Rate")
453  {
454  result << std::endl << getSingleLineComment() << "WARNING : reference to property other than transient volume for compartment \"" << pObjectParent->getObjectName() << "\" in expression for \"" << tmp->getObjectType() << "\" \"" << tmp->getObjectName() << "\".";
455  }
456  }
457  else if (typeString == "Metabolite")
458  {
459 
460  if (pObject->getObjectName() != "Concentration"
461  && pObject->getObjectName() != "InitialConcentration"
462  && pObject->getObjectName() != "ParticleNumber"
463  && pObject->getObjectName() != "Rate")
464  {
465 
466  result << std::endl << getSingleLineComment() << "WARNING : reference to property other than transient concentration, initial concentration or concentrations rate for metabolite \"" << pObjectParent->getObjectName() << "\" in expression for \"" << tmp->getObjectType() << "\" \"" << tmp->getObjectName() << "\".";
467  }
468 
469  CMetab* metab;
470  metab = dynamic_cast< CMetab * >(pObjectParent);
471 
472  if ((metab->getStatus() == CModelEntity::REACTIONS && metab->isDependent()) && pObject->getObjectName() == "Rate")
473  {
474 
475  result << std::endl << getSingleLineComment() << "WARNING : reference to rate of dependent (defined from moiety) metabolite \"" << pObjectParent->getObjectName() << "\" in expression for \"" << tmp->getObjectType() << "\" \"" << tmp->getObjectName() << "\".";
476  }
477  }
478  else if (typeString == "ModelValue")
479  {
480  if (pObject->getObjectName() != "Value"
481  && pObject->getObjectName() != "InitialValue"
482  && pObject->getObjectName() != "Rate")
483  {
484 
485  result << std::endl << getSingleLineComment() << "WARNING : reference to property other than transient value, initial value or rate for \"" << typeString << "\" \"" << pObjectParent->getObjectName() << "\" in expression for \"" << tmp->getObjectType() << "\" \"" << tmp->getObjectName() << "\".";
486  }
487  }
488  else if (typeString == "Model")
489  {
490 
491  if (pObject->getObjectName() != "Time" && pObject->getObjectName() != "Initial Time" && pObject->getObjectName() != "Avogadro Constant")
492  {
493 
494  result << std::endl << getSingleLineComment() << "WARNING : reference to property other than initial time or transient time for model \"" << pObjectParent->getObjectName() << "\" in expression for \"" << tmp->getObjectType() << "\" \"" << tmp->getObjectName() << "\".";
495  }
496  }
497  else if (typeString == "Parameter")
498  {
499 
500  if (pObject->getObjectName() != "Value")
501  {
502 
503  result << std::endl << getSingleLineComment() << "WARNING : reference to property other than initial time or transient time for model \"" << pObjectParent->getObjectName() << "\" in expression for \"" << tmp->getObjectType() << "\" \"" << tmp->getObjectName() << "\".";
504  }
505  }
506  else if (typeString == "Reaction")
507  {
508  if (pObject->getObjectName() != "Flux")
509  {
510  result << std::endl << getSingleLineComment() << "WARNING : reference to property other than Flux for Reaction \"" << pObjectParent->getObjectName() << "\" in expression for \"" << tmp->getObjectType() << "\" \"" << tmp->getObjectName() << "\".";
511  }
512  }
513  else
514  {
515  result << std::endl << getSingleLineComment() << "WARNING : expression for \"" << tmp->getObjectType() << "\" \"" << tmp->getObjectName() << "\" contains reference to a value in object \"" << pObjectParent->getObjectName() << "\" of type \"" << typeString << "\" which is not supported in this ODE exporter Version.";
516  }
517  }
518  else
519  {
520  result << std::endl << getSingleLineComment() << "WARNING : expression for \"" << tmp->getObjectType() << "\" \"" << tmp->getObjectName() << "\" contains reference to a object named \"" << pObject->getObjectName() << "\" of type \"" << pObject->getObjectType() << "\" which is not supported in this ODE exporter Version.";
521  }
522  }
523  }
524 
525  return result.str();
526 }
const std::string & getObjectName() const
const CRegisteredObjectName & getObjectCN() const
const std::string & getObjectType() const
Definition: CMetab.h:178
static Type type(const Type &type)
virtual std::string getSingleLineComment()
bool isReference() const
bool isDependent() const
Definition: CMetab.cpp:989
const CModelEntity::Status & getStatus() const
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
const std::vector< CEvaluationNode * > & getNodeList() const
CCopasiContainer * getObjectParent() const
std::string CODEExporter::KineticFunction2ODEmember ( const CReaction reac)
virtual

Reimplemented in CODEExporterC, CODEExporterXPPAUT, and CODEExporterBM.

Definition at line 1654 of file CODEExporter.cpp.

Referenced by exportReacParamsAndFuncs().

1655 {return " ";}
void CODEExporter::modifyTreeForMassAction ( CFunction tmpfunc)

This method modifies the export tree of the function for internal calls of Mass Action

Definition at line 1672 of file CODEExporter.cpp.

References CCopasiNode< _Data >::addChild(), assembleSubTreeForMassAction(), CEvaluationNode::CALL, CEvaluationNode::create(), CFunctionDB::findFunction(), CCopasiRootContainer::getFunctionList(), CCopasiObject::getObjectName(), CEvaluationTree::getRoot(), CEvaluationTree::getType(), CEvaluationTree::MassAction, CEvaluationNodeOperator::MINUS, CEvaluationNodeOperator::MULTIPLY, CEvaluationNode::OPERATOR, CCopasiNode< _Data >::removeChild(), and CEvaluationNode::type().

Referenced by exportKineticFunction(), CODEExporterC::exportSingleFunction(), and exportSingleFunction().

1673 {
1675 
1677 
1678  while (treeIt != NULL)
1679  {
1680  if (CEvaluationNode::type(treeIt->getType()) == CEvaluationNode::CALL)
1681  {
1682  const CFunction* callfunc;
1683  callfunc = static_cast<CFunction*>(pFunctionDB->findFunction((*treeIt).getData()));
1684 
1685  if (callfunc->getType() == CEvaluationTree::MassAction)
1686  {
1687  CEvaluationNode* parent = dynamic_cast<CEvaluationNode*>(treeIt->getParent());
1688  CEvaluationNode* child1 = dynamic_cast<CEvaluationNode*>(treeIt->getChild());
1689  CEvaluationNode* child2 = dynamic_cast<CEvaluationNode*>((treeIt->getChild())->getSibling());
1690 
1691  CEvaluationNode* newNode = NULL;
1694 
1695  CODEExporter::assembleSubTreeForMassAction(newNode1, child1, child2);
1696 
1697  if (callfunc->getObjectName() == "Mass action (irreversible)") newNode = newNode1;
1698 
1699  if (callfunc->getObjectName() == "Mass action (reversible)")
1700  {
1703  newNode->addChild(newNode1, NULL);
1704 
1707  CEvaluationNode* child3 = dynamic_cast<CEvaluationNode*>((child2)->getSibling());
1708  CEvaluationNode* child4 = dynamic_cast<CEvaluationNode*>((child3)->getSibling());
1709 
1710  CODEExporter::assembleSubTreeForMassAction(newNode2, child3, child4);
1711 
1712  newNode->addChild(newNode2, newNode1);
1713  }
1714 
1715  if (parent)
1716  {
1717  parent->addChild(newNode, &(*treeIt));
1718  parent->removeChild(&(*treeIt));
1719  }
1720 
1721  delete &(*treeIt);
1722  treeIt = newNode;
1723  }
1724  }
1725 
1726  ++treeIt;
1727  }
1728 }
const std::string & getObjectName() const
static CEvaluationNode * create(const Type &type, const Data &data)
const CEvaluationTree::Type & getType() const
void assembleSubTreeForMassAction(CEvaluationNode *newNode, CEvaluationNode *child1, CEvaluationNode *child2)
static Type type(const Type &type)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
static CFunctionDB * getFunctionList()
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
virtual bool removeChild(CCopasiNode< Data > *pChild)
Definition: CCopasiNode.h:181
CFunction * findFunction(const std::string &functionName)
CEvaluationNode * getRoot()
bool CODEExporter::preprocess ( const CModel copasiModel)
virtual

Reimplemented in CODEExporterC.

Definition at line 783 of file CODEExporter.cpp.

References CModel::getCompartments(), CModelEntity::getKey(), CCopasiObject::getKey(), CModel::getMetabolitesX(), CModel::getModelValues(), CCopasiObject::getObjectName(), CModel::getReactions(), CModelEntity::getStatus(), CMetab::isDependent(), NameMap, CModelEntity::ODE, CModelEntity::REACTIONS, setConcentrationName(), setODEName(), setReservedNames(), CCopasiVector< T >::size(), timeKey, translateObjectName(), and translateTimeVariableName().

Referenced by exportToStream().

784 {
785  size_t i, j;
786 
788 
789  timeKey = "time";
790 
792 
793  const CCopasiVector< CMetab > & metabs = copasiModel->getMetabolitesX();
794  size_t metabs_size = metabs.size();
795 
796  for (i = 0; i < metabs_size; i++)
797  {
798  CMetab * metab = metabs[i];
799 
800  //if (metab->isUsed()) //changed
801  {
802 
803  std::string name = translateObjectName(metab->getObjectName());
804 
805  std::ostringstream smKey;
806  smKey << "sm_" << metab->getKey();
807 
808  NameMap[smKey.str()] = name; // mass fraction
809 
810  NameMap[metab->getKey()] = setConcentrationName(name); //concentration
811 
812  if ((metab->getStatus() == CModelEntity::REACTIONS && !metab->isDependent()) || metab->getStatus() == CModelEntity::ODE)
813  {
814  std::ostringstream odeKey;
815  odeKey << "ode_" << metab->getKey();
816  NameMap[odeKey.str()] = setODEName(name);
817  }
818  }
819  }
820 
821  size_t comps_size = copasiModel->getCompartments().size();
822  const CCopasiVector< CCompartment > & comps = copasiModel->getCompartments();
823 
824  for (i = 0; i < comps_size; i++)
825  {
826  CCompartment* comp = comps[i];
827  std::string name = translateObjectName(comp->getObjectName());
828  NameMap[comp->getKey()] = name;
829 
830  if (comp->getStatus() == CModelEntity::ODE)
831  {
832  std::ostringstream odeKey;
833  odeKey << "ode_" << comp->getKey();
834  NameMap[odeKey.str()] = setODEName(name);
835  }
836  }
837 
838  size_t modvals_size = copasiModel->getModelValues().size();
839  const CCopasiVector< CModelValue > & modvals = copasiModel->getModelValues();
840 
841  for (i = 0; i < modvals_size; i++)
842  {
843  CModelValue* modval = modvals[i];
844  std::string name = translateObjectName(modval->getObjectName());
845  NameMap[modval->getKey()] = name;
846 
847  if (modval->getStatus() == CModelEntity::ODE)
848  {
849  std::ostringstream odeKey;
850  odeKey << "ode_" << modval->getKey();
851  NameMap[odeKey.str()] = setODEName(name);
852  }
853  }
854 
855  size_t reacs_size = copasiModel->getReactions().size();
856 
857  const CCopasiVector< CReaction > & reacs = copasiModel->getReactions();
858 
859  for (i = 0; i < reacs_size; ++i)
860  {
861  size_t params_size;
862 
863  params_size = reacs[i]->getParameters().size();
864 
865  for (j = 0; j < params_size; ++j)
866  {
867  if (reacs[i]->isLocalParameter(j))
868  {
869  NameMap[reacs[i]->getParameters().getParameter(j)->getKey()] =
870  translateObjectName(reacs[i]->getParameters().getParameter(j)->getObjectName());
871  }
872  }
873  }
874 
875  return true;
876 }
virtual std::string setODEName(const std::string &objName)
const std::string & getObjectName() const
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
virtual size_t size() const
virtual std::string setConcentrationName(const std::string &objName)
virtual void setReservedNames()
Definition: CMetab.h:178
virtual const std::string & getKey() const
virtual const std::string & getKey() const
virtual std::string translateTimeVariableName()
bool isDependent() const
Definition: CMetab.cpp:989
virtual std::string translateObjectName(const std::string &realName)
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
std::map< std::string, std::string > NameMap
Definition: CODEExporter.h:151
std::string timeKey
Definition: CODEExporter.h:152
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
const CModelEntity::Status & getStatus() const
const CCopasiVector< CMetab > & getMetabolitesX() const
Definition: CModel.cpp:1057
std::string CODEExporter::setConcentrationName ( const std::string &  objName)
virtual

Reimplemented in CODEExporterBM, and CODEExporterXPPAUT.

Definition at line 1328 of file CODEExporter.cpp.

Referenced by preprocess().

1329 {return " ";}
std::string CODEExporter::setODEName ( const std::string &  objName)
virtual

Reimplemented in CODEExporterC, CODEExporterXPPAUT, and CODEExporterBM.

Definition at line 1325 of file CODEExporter.cpp.

Referenced by preprocess().

1326 {return " ";}
void CODEExporter::setReservedNames ( )
virtual

Reimplemented in CODEExporterC, CODEExporterXPPAUT, and CODEExporterBM.

Definition at line 1316 of file CODEExporter.cpp.

Referenced by preprocess().

1317 {return;}
std::string CODEExporter::translateObjectName ( const std::string &  realName)
virtual

Reimplemented in CODEExporterC, CODEExporterXPPAUT, and CODEExporterBM.

Definition at line 1322 of file CODEExporter.cpp.

Referenced by exportKineticFunction(), exportSingleFunction(), and preprocess().

1323 {return " ";}
std::string CODEExporter::translateTimeVariableName ( )
virtual

Reimplemented in CODEExporterC, CODEExporterXPPAUT, and CODEExporterBM.

Definition at line 1319 of file CODEExporter.cpp.

Referenced by preprocess().

1320 {return " ";}

Member Data Documentation

std::ostringstream CODEExporter::assignment
std::map< std::string, std::string > CODEExporter::equations
std::ostringstream CODEExporter::fixed
std::ostringstream CODEExporter::functions
std::ostringstream CODEExporter::headers

Definition at line 159 of file CODEExporter.h.

Referenced by CODEExporterC::exportSingleFunction(), and exportToStream().

std::ostringstream CODEExporter::initial
std::set<std::string> CODEExporter::mExportedFunctions
protected

Definition at line 30 of file CODEExporter.h.

Referenced by exportSingleFunction(), and exportToStream().

std::map< std::string, std::string > CODEExporter::NameMap
std::ostringstream CODEExporter::ode
std::string CODEExporter::timeKey

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