COPASI API  4.16.103
CReaction.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 // CReaction
16 //
17 // Derived from Gepasi's cstep.cpp
18 // (C) Pedro Mendes 1995-2000
19 //
20 // Converted for COPASI by Stefan Hoops
21 
22 #include "copasi.h"
23 
24 #include <algorithm>
25 #include <stdio.h>
26 
28 #include "CReaction.h"
29 #include "CCompartment.h"
30 #include "CModel.h"
31 #include "utilities/CReadConfig.h"
35 #include "utilities/utility.h"
36 #include "function/CFunctionDB.h"
38 #include "report/CKeyFactory.h"
39 #include "CMetabNameInterface.h"
40 #include "CChemEqInterface.h" //only for load()
41 #include "CChemEqElement.h"
42 #include "function/CExpression.h"
44 #include "sbml/Species.h"
45 #include "sbml/Parameter.h"
46 #include "sbml/Compartment.h"
47 #include "sbml/SBMLImporter.h"
48 
50 
51 CReaction::CReaction(const std::string & name,
52  const CCopasiContainer * pParent):
53  CCopasiContainer(name, pParent, "Reaction"),
54  CAnnotation(),
55  mChemEq("Chemical Equation", this),
56  mpFunction(NULL),
57  mFlux(0),
58  mpFluxReference(NULL),
59  mParticleFlux(0),
60  mpParticleFluxReference(NULL),
61  mPropensity(0),
62  mpPropensityReference(NULL),
63  mScalingFactor(&mDefaultScalingFactor),
64  mUnitScalingFactor(&mDefaultScalingFactor),
65  mMetabKeyMap(),
66  mParameters("Parameters", this),
67  mFast(false)
68 {
70 
72  initObjects();
74 }
75 
77  const CCopasiContainer * pParent):
78  CCopasiContainer(src, pParent),
79  CAnnotation(src),
80  mChemEq(src.mChemEq, this),
81  mpFunction(src.mpFunction),
82  mFlux(src.mFlux),
83  mpFluxReference(NULL),
84  mParticleFlux(src.mParticleFlux),
85  mpParticleFluxReference(NULL),
86  mPropensity(src.mPropensity),
87  mpPropensityReference(NULL),
88  mScalingFactor(src.mScalingFactor),
89  mUnitScalingFactor(src.mUnitScalingFactor),
90  mMap(src.mMap),
91  mMetabKeyMap(src.mMetabKeyMap),
92  mParameters(src.mParameters, this),
93  mFast(src.mFast)
94 {
96 
98  initObjects();
99 
100  if (mpFunction)
101  {
102  //compileParameters();
103  }
104 
106 }
107 
109 {
111  cleanup();
113 }
114 
115 // virtual
116 std::string CReaction::getChildObjectUnits(const CCopasiObject * pObject) const
117 {
118  const CModel * pModel =
119  dynamic_cast< const CModel * >(getObjectAncestor("Model"));
120 
121  if (pModel == NULL) return "";
122 
123  const std::string & Name = pObject->getObjectName();
124 
125  if (Name == "ParticleFlux")
126  return pModel->getFrequencyUnitsDisplayString();
127  else if (Name == "Flux")
128  return pModel->getQuantityRateUnitsDisplayString();
129  else if (Name == "Propensity")
130  return pModel->getFrequencyUnitsDisplayString();
131 
132  return "";
133 }
134 
136 {
137  // TODO: mMap.cleanup();
138  //mParameterDescription.cleanup();
139 }
140 
142 {
143  bool success = CCopasiContainer::setObjectParent(pParent);
144 
145  return success;
146 }
147 
149 {
150  C_INT32 Fail = 0;
151 
152  std::string tmp;
153 
154  if ((Fail = configbuffer.getVariable("Step", "string", &tmp,
156  return Fail;
157 
158  setObjectName(tmp);
159 
160  std::string ChemEq;
161 
162  if ((Fail = configbuffer.getVariable("Equation", "string", &ChemEq)))
163  return Fail;
164 
165  CModel * pModel
166  = dynamic_cast< CModel * >(getObjectAncestor("Model"));
167  CChemEqInterface::setChemEqFromString(pModel, *this, ChemEq);
168 
169  if ((Fail = configbuffer.getVariable("KineticType", "string", &tmp)))
170  return Fail;
171 
172  setFunction(tmp);
173 
174  if (mpFunction == NULL)
175  return Fail = 1;
176 
177  bool revers;
178 
179  if ((Fail = configbuffer.getVariable("Reversible", "bool", &revers,
181  return Fail;
182 
183  mChemEq.setReversibility(revers); // TODO: this should be consistent with the ChemEq string
184 
185  Fail = loadOld(configbuffer);
186 
187  return Fail;
188 }
189 
190 const std::string & CReaction::getKey() const {return CAnnotation::getKey();}
191 
193 {return mFlux;}
194 
196 {return this->mpFluxReference;}
197 
199 {return this->mpFluxReference;}
200 
202 {return mParticleFlux;}
203 
205 {return mpParticleFluxReference;}
206 
208 {return mpParticleFluxReference;}
209 
211 {return mpPropensityReference;}
212 
214 {return mpPropensityReference;}
215 
217 {
218  return mMap.getPointers();
219 }
220 
221 //****************************************
222 
224 {return mChemEq;}
225 
227 {return mChemEq;}
228 
230 {return mChemEq.getReversibility();}
231 
232 bool CReaction::addSubstrate(const std::string & metabKey,
233  const C_FLOAT64 & multiplicity)
234 {return mChemEq.addMetabolite(metabKey, multiplicity, CChemEq::SUBSTRATE);}
235 
236 bool CReaction::addProduct(const std::string & metabKey,
237  const C_FLOAT64 & multiplicity)
238 {return mChemEq.addMetabolite(metabKey, multiplicity, CChemEq::PRODUCT);}
239 
240 bool CReaction::addModifier(const std::string & metabKey,
241  const C_FLOAT64 & multiplicity)
242 {return mChemEq.addMetabolite(metabKey, multiplicity, CChemEq::MODIFIER);}
243 
244 //bool CReaction::deleteModifier(const std::string &name)
245 //{return false;} /* :TODO: this needs to be implemented on CChemEq first. */
246 
247 void CReaction::setReversible(bool reversible)
248 {mChemEq.setReversibility(reversible);}
249 
250 //****************************************
251 
253 {return mpFunction;}
254 
255 bool CReaction::setFunction(const std::string & functionName)
256 {
257  CFunction * pFunction =
258  dynamic_cast<CFunction *>(CCopasiRootContainer::getFunctionList()->findLoadFunction(functionName));
259 
260  if (!pFunction)
261  CCopasiMessage(CCopasiMessage::ERROR, MCReaction + 1, functionName.c_str());
262 
263  return setFunction(pFunction);
264 }
265 
267 {
269 
270  if (!pFunction)
272  else
273  mpFunction = pFunction;
274 
276 
278  initializeMetaboliteKeyMap(); //needs to be called before initializeParamters();
280 
281  return true;
282 }
283 
284 //****************************************
285 
286 // TODO: check if function is set and map initialized in the following methods
287 /**
288  * Retrieve the index of the given parameter name in the function call
289  * @param const std::string & parameterName
290  * @return size_t index;
291  */
292 size_t CReaction::getParameterIndex(const std::string & parameterName, CFunctionParameter::DataType * pType) const
293 {
294  if (pType != NULL)
295  {
296  return mMap.findParameterByName(parameterName, *pType);
297  }
298 
300  return mMap.findParameterByName(parameterName, Type);
301 }
302 
303 void CReaction::setParameterValue(const std::string & parameterName,
304  const C_FLOAT64 & value,
305  const bool & updateStatus)
306 {
307  if (!mpFunction) fatalError();
308 
309  mParameters.setValue(parameterName, value);
310 
311  if (!updateStatus) return;
312 
313  //make sure that this local parameter is actually used:
314 
315  //first find index
316  size_t index = getParameterIndex(parameterName);
317 
318  if (index == C_INVALID_INDEX) return;
319 
320  if (getFunctionParameters()[index]->getType() != CFunctionParameter::FLOAT64) fatalError(); //wrong data type
321 
322  //set the key map
323  mMetabKeyMap[index][0] = mParameters.getParameter(parameterName)->getKey();
324 }
325 
326 const C_FLOAT64 & CReaction::getParameterValue(const std::string & parameterName) const
327 {
328  if (!mpFunction) fatalError();
329 
330  return * mParameters.getValue(parameterName).pDOUBLE;
331 }
332 
334 {return mParameters;}
335 
337 {return mParameters;}
338 
339 void CReaction::setParameterMapping(const size_t & index, const std::string & key)
340 {
341  if (!mpFunction) fatalError();
342 
343  if (getFunctionParameters()[index]->getType() != CFunctionParameter::FLOAT64) fatalError(); //wrong data type
344 
345  mMetabKeyMap[index][0] = key;
346 }
347 
348 void CReaction::addParameterMapping(const size_t & index, const std::string & key)
349 {
350  if (!mpFunction) fatalError();
351 
352  if (getFunctionParameters()[index]->getType() != CFunctionParameter::VFLOAT64) fatalError(); //wrong data type
353 
354  mMetabKeyMap[index].push_back(key);
355 }
356 
357 bool CReaction::setParameterMapping(const std::string & parameterName, const std::string & key)
358 {
359  if (!mpFunction) fatalError();
360 
362  size_t index = getParameterIndex(parameterName, &type);
363 
364  if (C_INVALID_INDEX == index)
365  return false;
366 
368 
369  mMetabKeyMap[index][0] = key;
370 
371  return true;
372 }
373 
374 void CReaction::addParameterMapping(const std::string & parameterName, const std::string & key)
375 {
376  if (!mpFunction) fatalError();
377 
379  size_t index;
380  index = getParameterIndex(parameterName, &type);
381 
382  if (C_INVALID_INDEX == index)
383  return;
384 
386 
387  mMetabKeyMap[index].push_back(key);
388 }
389 
390 void CReaction::setParameterMappingVector(const std::string & parameterName,
391  const std::vector<std::string> & keys)
392 {
393  if (!mpFunction) fatalError();
394 
396  size_t index;
397  index = getParameterIndex(parameterName, &type);
398 
399  if (C_INVALID_INDEX == index)
400  return;
401 
402  if ((type == CFunctionParameter::FLOAT64) && (keys.size() != 1)) fatalError();
403 
404  mMetabKeyMap[index] = keys;
405 }
406 
407 void CReaction::clearParameterMapping(const std::string & parameterName)
408 {
409  if (!mpFunction) fatalError();
410 
412  size_t index;
413  index = getParameterIndex(parameterName, &type);
414 
415  if (C_INVALID_INDEX == index)
416  return;
417 
418  if (type != CFunctionParameter::VFLOAT64) fatalError(); //wrong data type
419 
420  mMetabKeyMap[index].clear();
421 }
422 
423 void CReaction::clearParameterMapping(const size_t & index)
424 {
425  if (!mpFunction) fatalError();
426 
427  if (getFunctionParameters()[index]->getType() != CFunctionParameter::VFLOAT64) fatalError();
428 
429  mMetabKeyMap[index].clear();
430 }
431 
432 const std::vector<std::string> & CReaction::getParameterMapping(const size_t & index) const
433 {
434  if (!mpFunction) fatalError();
435 
436  if (C_INVALID_INDEX == index || index >= mMetabKeyMap.size())
437  return mMetabKeyMap[0]; //TODO this is kind of ugly!
438 
439  return mMetabKeyMap[index];
440 }
441 
442 const std::vector<std::string> & CReaction::getParameterMapping(const std::string & parameterName) const
443 {
444  size_t index = getParameterIndex(parameterName);
445 
446  return getParameterMapping(index);
447 }
448 
449 bool CReaction::isLocalParameter(const size_t & index) const
450 {
451  size_t i, imax = mParameters.size();
452 
453  for (i = 0; i < imax; ++i)
454  {
455  if (mParameters.getParameter(i)->getKey() == mMetabKeyMap[index][0])
456  return true;
457  }
458 
459  return false;
460 }
461 
462 bool CReaction::isLocalParameter(const std::string & parameterName) const
463 {
464  if (!mpFunction) fatalError();
465 
467  size_t index = getParameterIndex(parameterName, &type);
468 
469  if (C_INVALID_INDEX == index)
470  return false;
471 
473 
474  return isLocalParameter(index);
475 }
476 //***********************************************************************************************
477 
478 // virtual
480 {
481  const CCopasiObject * pObject =
482  static_cast< const CCopasiObject * >(CCopasiContainer::getObject(cn));
483 
484  if (pObject == NULL ||
485  pObject->isStaticString()) return pObject;
486 
487  const CCopasiContainer * pParent = pObject->getObjectParent();
488 
489  while (pParent != this)
490  {
491  if (pParent->getObjectParent() == &mParameters)
492  {
493  if (isLocalParameter(pParent->getObjectName()))
494  {
495  return pObject;
496  }
497  else
498  {
499  return NULL;
500  }
501  }
502 
503  pParent = pParent->getObjectParent();
504  }
505 
506  return pObject;
507 }
508 
510 {
511  if (!mpFunction) fatalError();
512 
513  size_t i;
515  size_t pos;
516  std::string name;
517 
518  /* We have to be more intelligent here because during an XML load we have
519  already the correct parameters */
520 
521  /* Add missing parameters with default value 1.0. */
522  for (i = 0, pos = 0; i < imax; ++i)
523  {
525 
526  // param.setName(name);
527  if (!mParameters.getParameter(name))
528  {
531  (C_FLOAT64) 1.0);
532  }
533 
534  CCopasiParameter * tmpPar = mParameters.getParameter(name);
535  mMetabKeyMap[pos - 1][0] = tmpPar->getKey();
536  }
537 
538  /* Remove parameters not fitting current function */
541  std::vector< std::string > ToBeDeleted;
542 
543  for (; it != end; ++it)
544  {
545  name = (*it)->getObjectName();
546 
547  if (getParameterIndex(name) == C_INVALID_INDEX)
548  ToBeDeleted.push_back(name);
549  }
550 
551  std::vector< std::string >::const_iterator itToBeDeleted = ToBeDeleted.begin();
552  std::vector< std::string >::const_iterator endToBeDeleted = ToBeDeleted.end();
553 
554  for (; itToBeDeleted != endToBeDeleted; ++itToBeDeleted)
555  mParameters.removeParameter(*itToBeDeleted);
556 }
557 
559 {
560  if (!mpFunction) fatalError();
561 
562  size_t i;
563  size_t imax = mMap.getFunctionParameters().size();
564 
565  mMetabKeyMap.resize(imax);
566 
567  for (i = 0; i < imax; ++i)
568  {
570  mMetabKeyMap[i].resize(0);
571  else
572  mMetabKeyMap[i].resize(1);
573  }
574 }
575 
577 {
578  if (!mpFunction) fatalError();
579 
580  return mMap.getFunctionParameters();
581 }
582 
584 {
586  std::set< const CCopasiObject * > Dependencies;
587 
588  CCopasiObject * pObject;
589 
590  if (mpFunction)
591  {
593  {
595 
598  }
599  else
600  {
601  mFlux = 0.0;
602  mParticleFlux = 0.0;
603 
606  }
607 
608  size_t i, j, jmax;
609  size_t imax = mMap.getFunctionParameters().size();
610  std::string paramName;
611 
612  for (i = 0; i < imax; ++i)
613  {
614  paramName = getFunctionParameters()[i]->getObjectName();
615 
617  {
618  mMap.clearCallParameter(paramName);
619  jmax = mMetabKeyMap[i].size();
620 
621  for (j = 0; j < jmax; ++j)
622  if ((pObject = CCopasiRootContainer::getKeyFactory()->get(mMetabKeyMap[i][j])) != NULL)
623  {
624  mMap.addCallParameter(paramName, pObject);
625  Dependencies.insert(pObject->getValueObject());
626  }
627  else
628  {
630  }
631  }
632  else if ((pObject = CCopasiRootContainer::getKeyFactory()->get(mMetabKeyMap[i][0])) != NULL)
633  {
634  mMap.setCallParameter(paramName, pObject);
635  Dependencies.insert(pObject->getValueObject());
636  }
637  else
638  {
640  }
641  }
642  }
643 
646 
647  for (; it != end; ++it)
648  addDirectDependency((*it)->getMetabolite());
649 
650  it = mChemEq.getProducts().begin();
651  end = mChemEq.getProducts().end();
652 
653  for (; it != end; ++it)
654  addDirectDependency((*it)->getMetabolite());
655 
656  it = mChemEq.getModifiers().begin();
657  end = mChemEq.getModifiers().end();
658 
659  for (; it != end; ++it)
660  addDirectDependency((*it)->getMetabolite());
661 
662  mpFluxReference->setDirectDependencies(Dependencies);
664 
666 }
667 
670  const std::string & prefix)
671 {
672  const CModel * pModel
673  = dynamic_cast< const CModel * >(getObjectAncestor("Model"));
674  const CCopasiVector< CMetab > & Metabolites = pModel->getMetabolites();
675 
676  size_t pos;
677 
678  C_INT32 i, imax;
679  C_INT32 index;
680  std::string name, parName, metabName;
681  const CFunctionParameter* pParameter;
682  CCopasiDataModel* pDataModel = getObjectDataModel();
683  assert(pDataModel != NULL);
684 
685  if (mMap.getFunctionParameters().isVector(role))
686  {
688  {
689  // not exactly one variable of this role as vector.
690  fatalError();
691  }
692 
693  pos = 0;
694  pParameter = mMap.getFunctionParameters().getParameterByUsage(role, pos);
695 
696  if (!pParameter)
697  {
698  // could not find variable.
699  fatalError();
700  }
701 
702  parName = pParameter->getObjectName();
703  clearParameterMapping(parName);
704 
705  for (i = 0; i < n; i++)
706  {
707  name = StringPrint(std::string(prefix + "%d").c_str(), i);
708  configbuffer.getVariable(name, "C_INT32", &index);
709 
710  metabName = (*pDataModel->pOldMetabolites)[index]->getObjectName();
711  addParameterMapping(parName, Metabolites[pModel->findMetabByName(metabName)]->getKey());
712  }
713  }
714  else //no vector
715  {
717 
718  if (imax > n)
719  {
720  // no. of metabs not matching function definition.
721  fatalError();
722  }
723 
724  for (i = 0, pos = 0; i < imax; i++)
725  {
726  name = StringPrint(std::string(prefix + "%d").c_str(), i);
727  configbuffer.getVariable(name, "C_INT32", &index);
728 
729  metabName = (*pDataModel->pOldMetabolites)[index]->getObjectName();
730 
731  pParameter = mMap.getFunctionParameters().getParameterByUsage(role, pos);
732 
733  if (!pParameter)
734  {
735  // could not find variable.
736  fatalError();
737  }
738 
739  if (pParameter->getType() >= CFunctionParameter::VINT32)
740  {
741  // unexpected vector variable.
742  fatalError();
743  }
744 
745  parName = pParameter->getObjectName();
746  setParameterMapping(parName, Metabolites[pModel->findMetabByName(metabName)]->getKey());
747 
748  // in the old files the chemical equation does not contain
749  // information about modifiers. This has to be extracted from here.
750  if (role == CFunctionParameter::MODIFIER)
751  mChemEq.addMetabolite(Metabolites[pModel->findMetabByName(metabName)]->getKey(),
752  1, CChemEq::MODIFIER);
753  }
754 
755  //just throw away the rest (the Gepasi files gives all species, not only
756  //those that influence the kinetics)
757  for (i = imax; i < n; i++)
758  {
759  name = StringPrint(std::string(prefix + "%d").c_str(), i);
760  configbuffer.getVariable(name, "C_INT32", &index);
761  }
762  }
763 
764  return true;
765 }
766 
768 {
769  C_INT32 SubstrateSize, ProductSize, ModifierSize, ParameterSize;
770 
771  configbuffer.getVariable("Substrates", "C_INT32", &SubstrateSize);
772  configbuffer.getVariable("Products", "C_INT32", &ProductSize);
773  configbuffer.getVariable("Modifiers", "C_INT32", &ModifierSize);
774  configbuffer.getVariable("Constants", "C_INT32", &ParameterSize);
775 
776  // Construct metabolite mappings
778  SubstrateSize, "Subs");
779 
781  ProductSize, "Prod");
782 
784  ModifierSize, "Modf");
785 
786  C_INT32 Fail = 0;
787 
788  // Construct parameters
790  != (size_t) ParameterSize)
791  {
792  // no. of parameters not matching function definition.
793  fatalError();
794  }
795 
796  size_t i, pos;
797  std::string name;
798  const CFunctionParameter* pParameter;
799  C_FLOAT64 value;
800 
801  for (i = 0, pos = 0; i < (size_t) ParameterSize; i++)
802  {
803  name = StringPrint("Param%d", i);
804  configbuffer.getVariable(name, "C_FLOAT64", &value);
805 
807 
808  if (!pParameter)
809  {
810  // could not find variable.
811  fatalError();
812  }
813 
814  if (pParameter->getType() != CFunctionParameter::FLOAT64)
815  {
816  // unexpected parameter type.
817  fatalError();
818  }
819 
820  setParameterValue(pParameter->getObjectName(), value);
821  }
822 
823  return Fail;
824 }
825 
827 {
828  calculate();
829  return mFlux;
830 }
831 
833 {
835  calculate();
836 
837  return mParticleFlux;
838 }
839 
841 {
844  return;
845 }
846 
848  const C_FLOAT64 & derivationFactor,
849  const C_FLOAT64 & resolution)
850 {
851  if (mpFunction->dependsOn(pXi, mMap.getPointers()))
852  {
853  C_FLOAT64 store = *pXi;
854  C_FLOAT64 f1, f2;
855  C_FLOAT64 tmp =
856  (store < resolution) ? resolution * (1.0 + derivationFactor) : store; //TODO: why assymmetric?
857 
858  *pXi = tmp * (1.0 + derivationFactor);
860 
861  *pXi = tmp * (1.0 - derivationFactor);
863 
864  *pXi = store;
865 
866  return *mScalingFactor * (f1 - f2) / (2.0 * tmp * derivationFactor);
867  //this is d(flow)/d(concentration)
868  }
869  else
870  return 0.0;
871 }
872 
874 {return mChemEq.getCompartmentNumber();}
875 
877 {return mChemEq.getLargestCompartment();}
878 
880 {
881  const CCompartment * pCompartment = NULL;
882 
883  if (1 == getCompartmentNumber())
884  {
885  const CMetab *pMetab = NULL;
886 
887  if (mChemEq.getSubstrates().size())
888  pMetab = mChemEq.getSubstrates()[0]->getMetabolite();
889  else if (mChemEq.getProducts().size())
890  pMetab = mChemEq.getProducts()[0]->getMetabolite();
891 
892  if (pMetab != NULL)
893  pCompartment = pMetab->getCompartment();
894  }
895 
896  if (pCompartment != NULL)
897  {
898  mScalingFactor = (C_FLOAT64 *) pCompartment->getValuePointer();
899 
900  std::set< const CCopasiObject * > Dependencies = mpFluxReference->getDirectDependencies();
901 
902  Dependencies.insert(pCompartment->getValueReference());
903 
904  mpFluxReference->setDirectDependencies(Dependencies);
906  }
907  else
909 
910 #ifdef XXXX
911 
912  if (mpFunctionCompartment)
913  {
914  // should propably check if the compartment appears in the chemical equation
915  mScalingFactor = & mpFunctionCompartment->getVolume();
916  }
917  else
918  {
919  try
920  {mScalingFactor = & mChemEq.CheckAndGetFunctionCompartment()->getVolume();}
921  catch (CCopasiException Exc)
922  {
923  size_t nr = Exc.getMessage().getNumber();
924 
925  if ((MCChemEq + 2 == nr) || (MCChemEq + 3 == nr))
927 
928  if (MCChemEq + 1 == nr)
930 
931  throw;
932  }
933  }
934 
935 #endif // XXXX
936 
937  CModel * pModel = (CModel *) getObjectAncestor("Model");
938 
939  if (pModel)
941  else
943 }
944 
946 {
950 
954 
957 }
958 
959 std::set< const CCopasiObject * > CReaction::getDeletedObjects() const
960 {
961  std::set< const CCopasiObject * > Deleted;
962 
963  Deleted.insert(this);
964  Deleted.insert(mpFluxReference);
965  Deleted.insert(mpParticleFluxReference);
966 
967  // We need to add all local reaction parameters
970 
971  for (; it != end ; ++it)
972  {
973  if (isLocalParameter((*it)->getObjectName()))
974  Deleted.insert((*it)->getValueReference());
975  }
976 
977  return Deleted;
978 }
979 
980 // virtual
981 bool CReaction::mustBeDeleted(const CCopasiObject::DataObjectSet & deletedObjects) const
982 {
983  bool MustBeDeleted = false;
984 
985  DataObjectSet DeletedObjects = deletedObjects;
986  // We need to ignore all local reaction parameters
989 
990  for (; itParameter != endParameter ; ++itParameter)
991  {
992  if (isLocalParameter((*itParameter)->getObjectName()))
993  {
994  DeletedObjects.erase((*itParameter)->getValueReference());
995  }
996  }
997 
998  DataObjectSet ChildObjects;
999  ChildObjects.insert(this);
1000  ChildObjects.insert(mpFluxReference);
1001  ChildObjects.insert(mpParticleFluxReference);
1002 
1003  DataObjectSet::const_iterator it = ChildObjects.begin();
1004  DataObjectSet::const_iterator end = ChildObjects.end();
1005 
1006  for (; it != end; ++it)
1007  {
1008  if (*it == this)
1009  {
1010  if ((*it)->CCopasiObject::mustBeDeleted(DeletedObjects))
1011  {
1012  MustBeDeleted = true;
1013  break;
1014  }
1015 
1016  continue;
1017  }
1018 
1019  if ((*it)->mustBeDeleted(DeletedObjects))
1020  {
1021  MustBeDeleted = true;
1022  break;
1023  }
1024  }
1025 
1026  return MustBeDeleted;
1027 }
1028 
1029 std::ostream & operator<<(std::ostream &os, const CReaction & d)
1030 {
1031  os << "CReaction: " << d.getObjectName() << std::endl;
1032  os << " SBML id: " << d.mSBMLId << std::endl;
1033 
1034  os << " mChemEq " << std::endl;
1035  os << d.mChemEq;
1036 
1037  if (d.mpFunction)
1038  os << " *mpFunction " << d.mpFunction->getObjectName() << std::endl;
1039  else
1040  os << " mpFunction == 0 " << std::endl;
1041 
1042  //os << " mParameterDescription: " << std::endl << d.mParameterDescription;
1043  os << " mFlux: " << d.mFlux << std::endl;
1044 
1045  if (d.mScalingFactor)
1046  os << " *mScalingFactor " << *(d.mScalingFactor) << std::endl;
1047  else
1048  os << " mScalingFactor == NULL " << std::endl;
1049 
1050  if (d.mUnitScalingFactor)
1051  os << " *mUnitScalingFactor " << *(d.mUnitScalingFactor) << std::endl;
1052  else
1053  os << " mUnitScalingFactor == NULL " << std::endl;
1054 
1055  os << " parameter group:" << std::endl;
1056  os << d.mParameters;
1057 
1058  os << " key map:" << std::endl;
1059  size_t i, j;
1060 
1061  for (i = 0; i < d.mMetabKeyMap.size(); ++i)
1062  {
1063  os << i << ": ";
1064 
1065  for (j = 0; j < d.mMetabKeyMap[i].size(); ++j)
1066  os << d.mMetabKeyMap[i][j] << ", ";
1067 
1068  os << std::endl;
1069  }
1070 
1071  os << "----CReaction" << std::endl;
1072 
1073  return os;
1074 }
1075 
1076 CEvaluationNodeVariable* CReaction::object2variable(const CEvaluationNodeObject* objectNode, std::map<std::string, std::pair<CCopasiObject*, CFunctionParameter*> >& replacementMap, std::map<CCopasiObject*, SBase*>& copasi2sbmlmap)
1077 {
1078  CEvaluationNodeVariable* pVariableNode = NULL;
1079  std::string objectCN = objectNode->getData();
1080  CModel * pModel
1081  = dynamic_cast< CModel * >(getObjectAncestor("Model"));
1082  std::vector<CCopasiContainer*> containers = std::vector<CCopasiContainer*>();
1083  containers.push_back(pModel);
1084  CCopasiObject* object = getObjectDataModel()->ObjectFromName(containers, CCopasiObjectName(objectCN.substr(1, objectCN.size() - 2)));
1085  std::string id;
1086 
1087  // if the object if of type reference
1088  if (object)
1089  {
1090  if (dynamic_cast<CCopasiObjectReference<C_FLOAT64>*>(object))
1091  {
1092  object = object->getObjectParent();
1093 
1094  if (object)
1095  {
1096  std::map<CCopasiObject*, SBase*>::iterator pos = copasi2sbmlmap.find(object);
1097 
1098  //assert(pos!=copasi2sbmlmap.end());
1099  // check if it is a CMetab, a CModelValue or a CCompartment
1100  if (dynamic_cast<CMetab*>(object))
1101  {
1102  Species* pSpecies = dynamic_cast<Species*>(pos->second);
1103  id = pSpecies->getId();
1104 
1105  // We need to check that we have no reserved name.
1106  const char *Reserved[] =
1107  {
1108  "pi", "exponentiale", "true", "false", "infinity", "nan",
1109  "PI", "EXPONENTIALE", "TRUE", "FALSE", "INFINITY", "NAN"
1110  };
1111 
1112  size_t j, jmax = 12;
1113 
1114  for (j = 0; j < jmax; j++)
1115  if (id == Reserved[j]) break;
1116 
1117  if (j != jmax)
1118  id = "\"" + id + "\"";
1119 
1120  pVariableNode = new CEvaluationNodeVariable(CEvaluationNodeVariable::ANY, id);
1121 
1122  if (replacementMap.find(id) == replacementMap.end())
1123  {
1124  // check whether it is a substrate, a product or a modifier
1125  bool found = false;
1127  unsigned int i;
1128  //std::string usage;
1130 
1131  for (i = 0; i < v->size(); ++i)
1132  {
1133  if (((*v)[i]->getMetabolite()) == static_cast<CMetab *>(object))
1134  {
1135  found = true;
1137  break;
1138  }
1139  }
1140 
1141  if (!found)
1142  {
1143  v = &this->getChemEq().getProducts();
1144 
1145  for (i = 0; i < v->size(); ++i)
1146  {
1147  if (((*v)[i]->getMetabolite()) == static_cast<CMetab *>(object))
1148  {
1149  found = true;
1151  break;
1152  }
1153  }
1154 
1155  if (!found)
1156  {
1157  v = &this->getChemEq().getModifiers();
1158 
1159  for (i = 0; i < v->size(); ++i)
1160  {
1161  if (((*v)[i]->getMetabolite()) == static_cast<CMetab *>(object))
1162  {
1163  found = true;
1165  break;
1166  }
1167  }
1168 
1169  if (!found)
1170  {
1171  // if we are reading an SBML Level 1 file
1172  // we can assume that this is a modifier since
1173  // Level 1 did not define these in the reaction
1174  if (pSpecies->getLevel() == 1)
1175  {
1176  found = true;
1178  }
1179  else
1180  {
1181  delete pVariableNode;
1182  pVariableNode = NULL;
1183  CCopasiMessage(CCopasiMessage::EXCEPTION, MCReaction + 7, id.c_str(), this->getSBMLId().c_str());
1184  }
1185  }
1186  }
1187  }
1188 
1189  if (found)
1190  {
1192  replacementMap[id] = std::make_pair(object, pFunParam);
1193  }
1194  }
1195  }
1196  else if (dynamic_cast<CModelValue*>(object))
1197  {
1198  // usage = "PARAMETER"
1199  id = dynamic_cast<Parameter*>(pos->second)->getId();
1200  pVariableNode = new CEvaluationNodeVariable(CEvaluationNodeVariable::ANY, id);
1201 
1202  if (replacementMap.find(id) == replacementMap.end())
1203  {
1206  replacementMap[id] = std::make_pair(object, pFunParam);
1207  }
1208  }
1209  else if (dynamic_cast<CCompartment*>(object))
1210  {
1211  // usage = "VOLUME"
1212  id = dynamic_cast<Compartment*>(pos->second)->getId();
1213  pVariableNode = new CEvaluationNodeVariable(CEvaluationNodeVariable::ANY, id);
1214 
1215  if (replacementMap.find(id) == replacementMap.end())
1216  {
1219  replacementMap[id] = std::make_pair(object, pFunParam);
1220  }
1221  }
1222  else if (dynamic_cast<CModel*>(object))
1223  {
1224  id = object->getObjectName();
1225  id = this->escapeId(id);
1226  pVariableNode = new CEvaluationNodeVariable(CEvaluationNodeVariable::ANY, id);
1227 
1228  if (replacementMap.find(id) == replacementMap.end())
1229  {
1232  replacementMap[id] = std::make_pair(object, pFunParam);
1233  }
1234  }
1235  else if (dynamic_cast<CReaction*>(object))
1236  {
1237  const CReaction* pReaction = static_cast<const CReaction*>(object);
1238  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 88, pReaction->getSBMLId().c_str(), this->getSBMLId().c_str());
1239  }
1240  else
1241  {
1242  // error
1244  }
1245  }
1246  }
1247  else if (dynamic_cast<CCopasiParameter*>(object))
1248  {
1249  id = object->getObjectName();
1250  id = this->escapeId(id);
1251  pVariableNode = new CEvaluationNodeVariable(CEvaluationNodeVariable::ANY, id);
1252 
1253  if (replacementMap.find(id) == replacementMap.end())
1254  {
1257  replacementMap[id] = std::make_pair(object, pFunParam);
1258  }
1259  }
1260  /*
1261  else if (dynamic_cast<CModel*>(object))
1262  {
1263  // usage = "TIME"
1264  id = object->getObjectName();
1265  id = this->escapeId(id);
1266  pVariableNode = new CEvaluationNodeVariable(CEvaluationNodeVariable::ANY, id);
1267  if (replacementMap.find(id) == replacementMap.end())
1268  {
1269  CFunctionParameter* pFunParam = new CFunctionParameter(id, CFunctionParameter::FLOAT64,
1270  CFunctionParameter::TIME);
1271  replacementMap[id] = std::make_pair(object, pFunParam);
1272  }
1273  }
1274  */
1275  else
1276  {
1277  // error
1279  }
1280  }
1281 
1282  return pVariableNode;
1283 }
1284 
1285 CEvaluationNode* CReaction::objects2variables(const CEvaluationNode* pNode, std::map<std::string, std::pair<CCopasiObject*, CFunctionParameter*> >& replacementMap, std::map<CCopasiObject*, SBase*>& copasi2sbmlmap)
1286 {
1288 
1289  CEvaluationNode* pResult = NULL;
1290 
1291  while (itNode.next() != itNode.end())
1292  {
1293  if (*itNode == NULL)
1294  {
1295  continue;
1296  }
1297 
1298  switch (CEvaluationNode::type(itNode->getType()))
1299  {
1301  // convert to a variable node
1302  pResult = object2variable(static_cast<const CEvaluationNodeObject * >(*itNode), replacementMap, copasi2sbmlmap);
1303  break;
1304 
1306  // this should not occur here
1307  fatalError();
1308  break;
1309 
1311  // error variables may not be in an expression
1313  pResult = NULL;
1314  break;
1315 
1317  // create an error message until there is a class for it
1318  CCopasiMessage(CCopasiMessage::ERROR, MCReaction + 5, "MV_FUNCTION");
1319  pResult = NULL;
1320  break;
1321 
1324  // create an error message
1325  pResult = NULL;
1326  break;
1327 
1328  default:
1329  pResult = itNode->copyNode(itNode.context());
1330  break;
1331  }
1332 
1333  if (pResult != NULL &&
1334  itNode.parentContextPtr() != NULL)
1335  {
1336  itNode.parentContextPtr()->push_back(pResult);
1337  }
1338  }
1339 
1340  return pResult;
1341 }
1342 
1343 CFunction * CReaction::setFunctionFromExpressionTree(const CExpression & expression, std::map<CCopasiObject*, SBase*>& copasi2sbmlmap, CFunctionDB* pFunctionDB)
1344 {
1345  // walk the tree and replace all object nodes with variable nodes.
1346  CFunction* pTmpFunction = NULL;
1347 
1348  const CEvaluationNode * pOrigNode = expression.getRoot();
1349 
1350  std::map<std::string, std::pair<CCopasiObject*, CFunctionParameter*> > replacementMap = std::map<std::string , std::pair<CCopasiObject*, CFunctionParameter*> >();
1351 
1352  CEvaluationNode* copy = pOrigNode->copyBranch();
1353  CEvaluationNode* pFunctionTree = objects2variables(copy, replacementMap, copasi2sbmlmap);
1354  delete copy;
1355 
1356  if (pFunctionTree)
1357  {
1358  // create the function object
1359 
1360  // later I might have to find out if I have to create a generic
1361  // function or a kinetic function
1362  // this can be distinguished by looking if the replacement map
1363  // contains CFunctionParameters that don't have the usage PARAMETER
1364 
1365  // create a unique name first
1366  pTmpFunction = new CKinFunction("\t"); // tab is an invalid name
1367 
1368  pTmpFunction->setRoot(pFunctionTree);
1369  pTmpFunction->setReversible(this->isReversible() ? TriTrue : TriFalse);
1370 
1371  pFunctionDB->add(pTmpFunction, true);
1372  // add the variables
1373  // and do the mapping
1374  std::map<std::string, std::pair<CCopasiObject*, CFunctionParameter*> >::iterator it = replacementMap.begin();
1375  std::map<std::string, std::pair<CCopasiObject*, CFunctionParameter*> >::iterator endIt = replacementMap.end();
1376 
1377  while (it != endIt)
1378  {
1379  CFunctionParameter* pFunPar = it->second.second;
1380  pTmpFunction->addVariable(pFunPar->getObjectName(), pFunPar->getUsage(), pFunPar->getType());
1381  ++it;
1382  }
1383 
1384  pTmpFunction->compile();
1385 
1386  setFunction(pTmpFunction);
1387  it = replacementMap.begin();
1388 
1389  while (it != endIt)
1390  {
1391  CFunctionParameter* pFunPar = it->second.second;
1392  std::string id = it->first;
1393  setParameterMapping(pFunPar->getObjectName(), it->second.first->getKey());
1394  delete pFunPar;
1395  ++it;
1396  }
1397 
1398  std::string functionName = "Function for " + this->getObjectName();
1399 
1400  if (expression.getObjectName() != "Expression")
1401  {
1402  functionName = expression.getObjectName();
1403  }
1404 
1405  std::string appendix = "";
1406  unsigned int counter = 0;
1407  std::ostringstream numberStream;
1408  CFunction * pExistingFunction = NULL;
1409 
1410  while ((pExistingFunction = pFunctionDB->findFunction(functionName + appendix)) != NULL)
1411  {
1412  if (SBMLImporter::areEqualFunctions(pExistingFunction, pTmpFunction))
1413  {
1415  mpFunction = pExistingFunction;
1417 
1418  // The functions and their signature are equal however the role of the variables
1419  // might not be defined for the existing function if this is the first time it is used
1420  mpFunction->setReversible(pTmpFunction->isReversible());
1421  mpFunction->getVariables() = pTmpFunction->getVariables();
1422 
1423  pdelete(pTmpFunction);
1424 
1425  return NULL;
1426  }
1427 
1428  counter++;
1429  numberStream.str("");
1430  numberStream << "_" << counter;
1431  appendix = numberStream.str();
1432  }
1433 
1434  pTmpFunction->setObjectName(functionName + appendix);
1435  }
1436 
1437  return pTmpFunction;
1438 }
1439 
1441 {
1442  CEvaluationNode* pTmpNode = NULL;
1443  CEvaluationNode* pChildNode = NULL;
1444  CEvaluationNode* pChildNode2 = NULL;
1445 
1446  switch (CEvaluationNode::type(expression->getType()))
1447  {
1449  pTmpNode = new CEvaluationNodeNumber(static_cast<CEvaluationNodeNumber::SubType>((int) CEvaluationNode::subType(expression->getType())), expression->getData());
1450  break;
1451 
1453  pTmpNode = new CEvaluationNodeConstant(static_cast<CEvaluationNodeConstant::SubType>((int) CEvaluationNode::subType(expression->getType())), expression->getData());
1454  break;
1455 
1457  pTmpNode = new CEvaluationNodeOperator(static_cast<CEvaluationNodeOperator::SubType>((int) CEvaluationNode::subType(expression->getType())), expression->getData());
1458  // convert the two children as well
1459  pChildNode = this->variables2objects(static_cast<CEvaluationNode*>(expression->getChild()));
1460 
1461  if (pChildNode)
1462  {
1463  pTmpNode->addChild(pChildNode);
1464  pChildNode = this->variables2objects(static_cast<CEvaluationNode*>(expression->getChild()->getSibling()));
1465 
1466  if (pChildNode)
1467  {
1468  pTmpNode->addChild(pChildNode);
1469  }
1470  else
1471  {
1472  delete pTmpNode;
1473  pTmpNode = NULL;
1474  }
1475  }
1476  else
1477  {
1478  delete pTmpNode;
1479  pTmpNode = NULL;
1480  }
1481 
1482  break;
1483 
1485  pTmpNode = new CEvaluationNodeObject(static_cast<CEvaluationNodeObject::SubType>((int) CEvaluationNode::subType(expression->getType())), expression->getData());
1486  break;
1487 
1489  pTmpNode = new CEvaluationNodeFunction(static_cast<CEvaluationNodeFunction::SubType>((int) CEvaluationNode::subType(expression->getType())), expression->getData());
1490  // convert the only child as well
1491  pChildNode = this->variables2objects(static_cast<CEvaluationNode*>(expression->getChild()));
1492 
1493  if (pChildNode)
1494  {
1495  pTmpNode->addChild(pChildNode);
1496  }
1497  else
1498  {
1499  delete pTmpNode;
1500  pTmpNode = NULL;
1501  }
1502 
1503  break;
1504 
1505  case CEvaluationNode::CALL:
1506  pTmpNode = new CEvaluationNodeCall(static_cast<CEvaluationNodeCall::SubType>((int) CEvaluationNode::subType(expression->getType())), expression->getData());
1507  // convert all children
1508  pChildNode2 = static_cast<CEvaluationNode*>(expression->getChild());
1509 
1510  while (pChildNode2)
1511  {
1512  pChildNode = this->variables2objects(static_cast<CEvaluationNode*>(pChildNode2));
1513 
1514  if (pChildNode)
1515  {
1516  pTmpNode->addChild(pChildNode);
1517  }
1518  else
1519  {
1520  delete pTmpNode;
1521  pTmpNode = NULL;
1522  }
1523 
1524  pChildNode2 = static_cast<CEvaluationNode*>(pChildNode2->getSibling());
1525  }
1526 
1527  break;
1528 
1530  pTmpNode = new CEvaluationNodeStructure(static_cast<CEvaluationNodeStructure::SubType>((int) CEvaluationNode::subType(expression->getType())), expression->getData());
1531  break;
1532 
1534  pTmpNode = new CEvaluationNodeChoice(static_cast<CEvaluationNodeChoice::SubType>((int) CEvaluationNode::subType(expression->getType())), expression->getData());
1535  // convert the two children as well
1536  pChildNode = this->variables2objects(static_cast<CEvaluationNode*>(expression->getChild()));
1537 
1538  if (pChildNode)
1539  {
1540  pTmpNode->addChild(pChildNode);
1541  pChildNode = this->variables2objects(static_cast<CEvaluationNode*>(expression->getChild()->getSibling()));
1542 
1543  if (pChildNode)
1544  {
1545  pTmpNode->addChild(pChildNode);
1546  }
1547  else
1548  {
1549  delete pTmpNode;
1550  pTmpNode = NULL;
1551  }
1552  }
1553  else
1554  {
1555  delete pTmpNode;
1556  pTmpNode = NULL;
1557  }
1558 
1559  break;
1560 
1562  pTmpNode = this->variable2object(static_cast<CEvaluationNodeVariable*>(expression));
1563  break;
1564 
1566  pTmpNode = new CEvaluationNodeWhiteSpace(static_cast<CEvaluationNodeWhiteSpace::SubType>((int) CEvaluationNode::subType(expression->getType())), expression->getData());
1567  break;
1568 
1570  pTmpNode = new CEvaluationNodeLogical(static_cast<CEvaluationNodeLogical::SubType>((int) CEvaluationNode::subType(expression->getType())), expression->getData());
1571  // convert the two children as well
1572  pChildNode = this->variables2objects(static_cast<CEvaluationNode*>(expression->getChild()));
1573 
1574  if (pChildNode)
1575  {
1576  pTmpNode->addChild(pChildNode);
1577  pChildNode = this->variables2objects(static_cast<CEvaluationNode*>(expression->getChild()->getSibling()));
1578 
1579  if (pChildNode)
1580  {
1581  pTmpNode->addChild(pChildNode);
1582  }
1583  else
1584  {
1585  delete pTmpNode;
1586  pTmpNode = NULL;
1587  }
1588  }
1589  else
1590  {
1591  delete pTmpNode;
1592  pTmpNode = NULL;
1593  }
1594 
1595  break;
1596 
1598  // create an error message until there is a class for it
1599  CCopasiMessage(CCopasiMessage::ERROR, MCReaction + 5, "MV_FUNCTION");
1600  break;
1601 
1604  // create an error message
1605  break;
1606 
1607  default:
1608  break;
1609  }
1610 
1611  return pTmpNode;
1612 }
1613 
1615 {
1616  CEvaluationNodeObject* pObjectNode = NULL;
1617  const std::string paraName = static_cast<const std::string>(pVariableNode->getData());
1619  size_t index = this->getFunction()->getVariables().findParameterByName(paraName, type);
1620 
1621  if (index == C_INVALID_INDEX)
1622  {
1623  CCopasiMessage(CCopasiMessage::EXCEPTION, MCReaction + 8, (static_cast<std::string>(pVariableNode->getData())).c_str());
1624  }
1625 
1627  {
1628  CCopasiMessage(CCopasiMessage::EXCEPTION, MCReaction + 10, (static_cast<std::string>(pVariableNode->getData())).c_str());
1629  }
1630 
1631  const std::string& key = this->getParameterMappings()[index][0];
1632 
1634 
1635  if (!pObject)
1636  {
1638  }
1639 
1640  pObjectNode = new CEvaluationNodeObject(CEvaluationNodeObject::CN, "<" + pObject->getCN() + ">");
1641  return pObjectNode;
1642 }
1643 
1645 {
1646  return this->variables2objects(const_cast<CFunction*>(this->getFunction())->getRoot());
1647 }
1648 
1649 void CReaction::setSBMLId(const std::string& id)
1650 {
1651  this->mSBMLId = id;
1652 }
1653 
1654 const std::string& CReaction::getSBMLId() const
1655 {
1656  return this->mSBMLId;
1657 }
1658 
1659 std::string CReaction::escapeId(const std::string& id)
1660 {
1661  std::string s = id;
1662  std::string::size_type idx = s.find('\\');
1663 
1664  while (idx != std::string::npos)
1665  {
1666  s.insert(idx, "\\");
1667  ++idx;
1668  idx = s.find('\\', ++idx);
1669  }
1670 
1671  idx = s.find('"');
1672 
1673  while (idx != std::string::npos)
1674  {
1675  s.insert(idx, "\\");
1676  ++idx;
1677  idx = s.find('"', ++idx);
1678  }
1679 
1680  if (s.find(' ') != std::string::npos || s.find('\t') != std::string::npos)
1681  {
1682  s = std::string("\"") + s + std::string("\"");
1683  }
1684 
1685  return s;
1686 }
1687 
1688 std::string CReaction::getObjectDisplayName(bool regular, bool richtext) const
1689 {
1690  CModel* tmp = dynamic_cast<CModel*>(this->getObjectAncestor("Model"));
1691 
1692  if (tmp)
1693  {
1694  return "(" + getObjectName() + ")";
1695  }
1696 
1697  return CCopasiObject::getObjectDisplayName(regular, richtext);
1698 }
1699 
1701 {}
1702 
1703 void CReaction::setFast(const bool & fast)
1704 {
1705  mFast = fast;
1706 }
1707 
1708 /**
1709  * Check whether the reaction needs to be treated as fast
1710  * @ return const bool & fast
1711  */
1712 const bool & CReaction::isFast() const
1713 {
1714  return mFast;
1715 }
Header file of class CExpression.
CCopasiDataModel * getObjectDataModel()
virtual bool setObjectParent(const CCopasiContainer *pParent)
void initObjects()
Definition: CReaction.cpp:945
CCopasiParameterGroup mParameters
Definition: CReaction.h:610
void calculate()
Definition: CReaction.cpp:840
CCopasiContainer * getObjectAncestor(const std::string &type) const
bool remove(const std::string &key)
size_t getCompartmentNumber() const
Definition: CChemEq.cpp:110
void setReversible(bool reversible)
Definition: CReaction.cpp:247
virtual bool setRoot(CEvaluationNode *pRootNode)
CEvaluationNode * copyBranch() const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
CCopasiObjectReference< C_FLOAT64 > * mpFluxReference
Definition: CReaction.h:569
void clearDirectDependencies()
void setRefresh(CType *pType, void(CType::*method)(void))
void cleanup()
Definition: CReaction.cpp:135
virtual bool dependsOn(const C_FLOAT64 *parameter, const CCallParameters< C_FLOAT64 > &callParameters) const
Definition: CFunction.cpp:168
#define pdelete(p)
Definition: copasi.h:215
#define MCChemEq
void clearCallParameter(const std::string paramName)
static CFunction * getUndefinedFunction()
const CFunctionParameter::DataType & getType() const
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
CCopasiObject * getParticleFluxReference()
Definition: CReaction.cpp:207
CCopasiObjectReference< C_FLOAT64 > * mpPropensityReference
Definition: CReaction.h:581
std::ostream & operator<<(std::ostream &os, const CReaction &d)
Definition: CReaction.cpp:1029
CFunction * setFunctionFromExpressionTree(const CExpression &tree, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CFunctionDB *pFunctionDB)
Definition: CReaction.cpp:1343
C_INT32 loadOld(CReadConfig &configbuffer)
Definition: CReaction.cpp:767
const C_FLOAT64 & getParticleFlux() const
Definition: CReaction.cpp:201
static void setChemEqFromString(CModel *model, CReaction &rea, const std::string &ces)
CFunction * mpFunction
Definition: CReaction.h:563
virtual CCopasiObjectName getCN() const
bool addSubstrate(const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
Definition: CReaction.cpp:232
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
const std::string & getObjectName() const
std::string getFrequencyUnitsDisplayString() const
Definition: CModel.cpp:4539
CEvaluationNode * copyNode(CEvaluationNode *child1, CEvaluationNode *child2) const
virtual size_t size() const
virtual std::string getChildObjectUnits(const CCopasiObject *pObject) const
Definition: CReaction.cpp:116
CCopasiObject * get(const std::string &key)
virtual const std::string & getKey() const
Definition: CReaction.cpp:190
const CCopasiMessage & getMessage() const
bool isVector(CFunctionParameter::Role role) const
iterator begin()
virtual ~CReaction()
Definition: CReaction.cpp:108
void setParameterValue(const std::string &parameterName, const C_FLOAT64 &value, const bool &updateStatus=true)
Definition: CReaction.cpp:303
#define fatalError()
const Type & getType() const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
Definition: CReaction.cpp:1688
const CFunctionParameters & getFunctionParameters() const
void setDirectDependencies(const DataObjectSet &directDependencies)
std::string getQuantityRateUnitsDisplayString() const
Definition: CModel.cpp:4657
size_t findParameterByName(const std::string &name, CFunctionParameter::DataType &dataType) const
const size_t & getNumber() const
const CCallParameters< C_FLOAT64 > & getCallParameters() const
Definition: CReaction.cpp:216
size_t getNumberOfParametersByUsage(CFunctionParameter::Role usage) const
bool addProduct(const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
Definition: CReaction.cpp:236
C_FLOAT64 mParticleFlux
Definition: CReaction.h:574
bool isLocalParameter(const size_t &index) const
Definition: CReaction.cpp:449
C_FLOAT64 calculatePartialDerivative(C_FLOAT64 *pXi, const C_FLOAT64 &derivationFactor, const C_FLOAT64 &resolution)
Definition: CReaction.cpp:847
index_iterator endIndex() const
CEvaluationNode * objects2variables(const CEvaluationNode *expression, std::map< std::string, std::pair< CCopasiObject *, CFunctionParameter * > > &replacementMap, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap)
Definition: CReaction.cpp:1285
const std::string & getObjectType() const
#define C_INVALID_INDEX
Definition: copasi.h:222
void clearParameterMapping(const std::string &parameterName)
Definition: CReaction.cpp:407
const C_FLOAT64 & calculateFlux()
Definition: CReaction.cpp:826
bool addVariable(const std::string &name, CFunctionParameter::Role usage=CFunctionParameter::VARIABLE, const CFunctionParameter::DataType &type=CFunctionParameter::FLOAT64)
Definition: CFunction.cpp:154
CCallParameters< C_FLOAT64 > & getPointers()
void setMiriamAnnotation(const std::string &miriamAnnotation, const std::string &newId, const std::string &oldId)
const C_FLOAT64 & getFlux() const
Definition: CReaction.cpp:192
#define C_INT32
Definition: copasi.h:90
CCopasiObject * getPropensityReference()
Definition: CReaction.cpp:210
CFunction * findLoadFunction(const std::string &functionName)
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
Definition: CReaction.cpp:479
const CNodeIteratorMode::State & next()
void setParameterMappingVector(const std::string &parameterName, const std::vector< std::string > &keys)
Definition: CReaction.cpp:390
Definition: CMetab.h:178
const std::string & getMiriamAnnotation() const
void setReversible(const TriLogic &reversible)
Definition: CFunction.cpp:142
virtual std::set< const CCopasiObject * > getDeletedObjects() const
Definition: CReaction.cpp:959
CEvaluationNodeVariable * object2variable(const CEvaluationNodeObject *objectNode, std::map< std::string, std::pair< CCopasiObject *, CFunctionParameter * > > &replacementMap, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap)
Definition: CReaction.cpp:1076
const C_FLOAT64 * mUnitScalingFactor
Definition: CReaction.h:593
const std::string & getSBMLId() const
Definition: CReaction.cpp:1654
virtual const std::string & getKey() const
std::string mKey
Definition: CAnnotation.h:119
CChemEq mChemEq
Definition: CReaction.h:558
void compile()
Definition: CReaction.cpp:583
void setScalingFactor()
Definition: CReaction.cpp:879
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
bool removeParameter(const std::string &name)
static Type type(const Type &type)
const CFunction * getFunction() const
Definition: CReaction.cpp:252
#define DESTRUCTOR_TRACE
Definition: copasi.h:206
#define MCSBML
iterator end()
void addDirectDependency(const CCopasiObject *pObject)
CEvaluationNode * variables2objects(CEvaluationNode *expression)
Definition: CReaction.cpp:1440
const C_FLOAT64 & getQuantity2NumberFactor() const
Definition: CModel.cpp:2354
virtual bool mustBeDeleted(const DataObjectSet &deletedObjects) const
Definition: CReaction.cpp:981
const CFunctionParameters & getFunctionParameters() const
Definition: CReaction.cpp:576
CReaction(const std::string &name="NoName", const CCopasiContainer *pParent=NULL)
Definition: CReaction.cpp:51
void printDebug() const
Definition: CReaction.cpp:1700
size_t getParameterIndex(const std::string &parameterName, CFunctionParameter::DataType *pType=NULL) const
Definition: CReaction.cpp:292
size_t findMetabByName(const std::string &Target) const
Definition: CModel.cpp:1198
bool addModifier(const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
Definition: CReaction.cpp:240
CFunctionParameterMap mMap
Definition: CReaction.h:599
const TriLogic & isReversible() const
Definition: CFunction.cpp:145
virtual const std::string & getKey() const
bool setFunction(const std::string &functionName)
Definition: CReaction.cpp:255
static bool areEqualFunctions(const CFunction *pFun, const CFunction *pFun2)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
const bool & getReversibility() const
Definition: CChemEq.cpp:77
void setSBMLId(const std::string &id)
Definition: CReaction.cpp:1649
index_iterator beginIndex() const
C_INT32 load(CReadConfig &configbuffer)
Definition: CReaction.cpp:148
bool setValue(const std::string &name, const CType &value)
const C_FLOAT64 & calculateParticleFlux()
Definition: CReaction.cpp:832
Context * parentContextPtr()
const CFunctionParameter * getParameterByUsage(CFunctionParameter::Role usage, size_t &pos) const
CCopasiParameter * getParameter(const std::string &name)
virtual void * getValuePointer() const
std::string add(const std::string &prefix, CCopasiObject *pObject)
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
bool isReversible() const
Definition: CReaction.cpp:229
static CFunctionDB * getFunctionList()
virtual const C_FLOAT64 & calcValue(const CCallParameters< C_FLOAT64 > &callParameters)
Definition: CFunction.cpp:159
bool addMetabolite(const std::string &key, const C_FLOAT64 multiplicity, const MetaboliteRole &role)
Definition: CChemEq.cpp:80
#define MCReaction
const CArrayAnnotation * pResult
const bool & isFast() const
Definition: CReaction.cpp:1712
virtual const DataObjectSet & getDirectDependencies(const DataObjectSet &context=DataObjectSet()) const
C_FLOAT64 mPropensity
Definition: CReaction.h:580
static Type subType(const Type &type)
const C_FLOAT64 * mScalingFactor
Definition: CReaction.h:588
C_FLOAT64 mFlux
Definition: CReaction.h:568
static CKeyFactory * getKeyFactory()
#define C_FLOAT64
Definition: copasi.h:92
const CCopasiVector< CChemEqElement > & getModifiers() const
Definition: CChemEq.cpp:66
const CCopasiParameterGroup & getParameters() const
Definition: CReaction.cpp:333
const CCompartment * getLargestCompartment() const
Definition: CReaction.cpp:876
void initializeFromFunctionParameters(const CFunctionParameters &src)
void setParameterMapping(const size_t &index, const std::string &key)
Definition: CReaction.cpp:339
size_t getCompartmentNumber() const
Definition: CReaction.cpp:873
void setCallParameter(const std::string paramName, const CCopasiObject *obj)
void removeDirectDependency(const CCopasiObject *pObject)
std::string StringPrint(const char *format,...)
Definition: utility.cpp:87
bool addParameter(const CCopasiParameter &parameter)
bool loadOneRole(CReadConfig &configbuffer, CFunctionParameter::Role role, C_INT32 n, const std::string &prefix)
Definition: CReaction.cpp:668
virtual bool compile()
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
static CCopasiObject * pUnmappedObject
const CCopasiParameter::Value & getValue(const std::string &name) const
Definition: CModel.h:50
bool mFast
Definition: CReaction.h:623
C_INT32 getVariable(const std::string &name, const std::string &type, void *pout, CReadConfig::Mode mode=CReadConfig::NEXT)
Definition: CReadConfig.cpp:81
bool isStaticString() const
void setFast(const bool &fast)
Definition: CReaction.cpp:1703
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
virtual const Data & getData() const
Definition: CCopasiNode.h:118
std::string escapeId(const std::string &id)
Definition: CReaction.cpp:1659
void addCallParameter(const std::string paramName, const CCopasiObject *obj)
CEvaluationNodeObject * variable2object(CEvaluationNodeVariable *pVariableNode)
Definition: CReaction.cpp:1614
virtual bool setObjectParent(const CCopasiContainer *pParent)
Definition: CReaction.cpp:141
virtual const Data & getData() const
CNodeIteratorMode::State end() const
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
CEvaluationNode * getExpressionTree()
Definition: CReaction.cpp:1644
const std::vector< std::vector< std::string > > & getParameterMappings() const
Definition: CReaction.h:285
static C_FLOAT64 mDefaultScalingFactor
Definition: CReaction.h:553
virtual const CCopasiObject * getValueObject() const
void initializeParameters()
Definition: CReaction.cpp:509
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
const CCompartment * getLargestCompartment() const
Definition: CChemEq.cpp:137
bool setObjectName(const std::string &name)
parameterGroup::iterator index_iterator
std::set< const CCopasiObject * > DataObjectSet
CCopasiVectorS< CMetabOld > * pOldMetabolites
CFunction * findFunction(const std::string &functionName)
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
CCopasiObject * addObjectReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
void setReversibility(const bool &reversible)
Definition: CChemEq.cpp:72
CCopasiObjectReference< C_FLOAT64 > * mpParticleFluxReference
Definition: CReaction.h:575
const CChemEq & getChemEq() const
Definition: CReaction.cpp:223
size_t findParameterByName(const std::string &name, CFunctionParameter::DataType &dataType) const
CEvaluationNode * getRoot()
const C_FLOAT64 & getParameterValue(const std::string &parameterName) const
Definition: CReaction.cpp:326
std::string mSBMLId
Definition: CReaction.h:617
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
CCopasiContainer * getObjectParent() const
void addParameterMapping(const size_t &index, const std::string &key)
Definition: CReaction.cpp:348
void initializeMetaboliteKeyMap()
Definition: CReaction.cpp:558
virtual const std::string & getKey() const
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202
const std::vector< std::string > & getParameterMapping(const size_t &index) const
Definition: CReaction.cpp:432
CCopasiObject * getFluxReference()
Definition: CReaction.cpp:198
bool add(CFunction *pFunction, const bool &adopt)
CCopasiObject * getValueReference() const