COPASI API  4.16.103
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
CReaction Class Reference

#include <CReaction.h>

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

Public Member Functions

bool addModifier (const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
 
void addParameterMapping (const size_t &index, const std::string &key)
 
void addParameterMapping (const std::string &parameterName, const std::string &key)
 
bool addProduct (const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
 
bool addSubstrate (const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
 
const C_FLOAT64calculateFlux ()
 
C_FLOAT64 calculatePartialDerivative (C_FLOAT64 *pXi, const C_FLOAT64 &derivationFactor, const C_FLOAT64 &resolution)
 
const C_FLOAT64calculateParticleFlux ()
 
void cleanup ()
 
void clearParameterMapping (const std::string &parameterName)
 
void clearParameterMapping (const size_t &index)
 
void compile ()
 
 CReaction (const std::string &name="NoName", const CCopasiContainer *pParent=NULL)
 
 CReaction (const CReaction &src, const CCopasiContainer *pParent=NULL)
 
const CCallParameters
< C_FLOAT64 > & 
getCallParameters () const
 
const CChemEqgetChemEq () const
 
CChemEqgetChemEq ()
 
virtual std::string getChildObjectUnits (const CCopasiObject *pObject) const
 
size_t getCompartmentNumber () const
 
virtual std::set< const
CCopasiObject * > 
getDeletedObjects () const
 
CEvaluationNodegetExpressionTree ()
 
const C_FLOAT64getFlux () const
 
CCopasiObjectgetFluxReference ()
 
const CCopasiObjectgetFluxReference () const
 
const CFunctiongetFunction () const
 
const CFunctionParametersgetFunctionParameters () const
 
virtual const std::string & getKey () const
 
const CCompartmentgetLargestCompartment () const
 
virtual const CObjectInterfacegetObject (const CCopasiObjectName &cn) const
 
virtual std::string getObjectDisplayName (bool regular=true, bool richtext=false) const
 
size_t getParameterIndex (const std::string &parameterName, CFunctionParameter::DataType *pType=NULL) const
 
const std::vector< std::string > & getParameterMapping (const size_t &index) const
 
const std::vector< std::string > & getParameterMapping (const std::string &parameterName) const
 
const std::vector< std::vector
< std::string > > & 
getParameterMappings () const
 
std::vector< std::vector
< std::string > > & 
getParameterMappings ()
 
const CCopasiParameterGroupgetParameters () const
 
CCopasiParameterGroupgetParameters ()
 
const C_FLOAT64getParameterValue (const std::string &parameterName) const
 
const C_FLOAT64getParticleFlux () const
 
CCopasiObjectgetParticleFluxReference ()
 
const CCopasiObjectgetParticleFluxReference () const
 
CCopasiObjectgetPropensityReference ()
 
const CCopasiObjectgetPropensityReference () const
 
const std::string & getSBMLId () const
 
const bool & isFast () const
 
bool isLocalParameter (const size_t &index) const
 
bool isLocalParameter (const std::string &parameterName) const
 
bool isReversible () const
 
C_INT32 load (CReadConfig &configbuffer)
 
virtual bool mustBeDeleted (const DataObjectSet &deletedObjects) const
 
void printDebug () const
 
void setFast (const bool &fast)
 
bool setFunction (const std::string &functionName)
 
bool setFunction (CFunction *pFunction)
 
CFunctionsetFunctionFromExpressionTree (const CExpression &tree, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CFunctionDB *pFunctionDB)
 
virtual bool setObjectParent (const CCopasiContainer *pParent)
 
void setParameterMapping (const size_t &index, const std::string &key)
 
bool setParameterMapping (const std::string &parameterName, const std::string &key)
 
void setParameterMappingVector (const std::string &parameterName, const std::vector< std::string > &keys)
 
void setParameterValue (const std::string &parameterName, const C_FLOAT64 &value, const bool &updateStatus=true)
 
void setReversible (bool reversible)
 
void setSBMLId (const std::string &id)
 
virtual ~CReaction ()
 
- Public Member Functions inherited from CCopasiContainer
virtual bool add (CCopasiObject *pObject, const bool &adopt=true)
 
 CCopasiContainer (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &type="CN", const unsigned C_INT32 &flag=CCopasiObject::Container)
 
 CCopasiContainer (const CCopasiContainer &src, const CCopasiContainer *pParent=NULL)
 
virtual const objectMapgetObjects () const
 
virtual std::string getUnits () const
 
virtual const CCopasiObjectgetValueObject () const
 
virtual bool remove (CCopasiObject *pObject)
 
virtual ~CCopasiContainer ()
 
- Public Member Functions inherited from CCopasiObject
void addDirectDependency (const CCopasiObject *pObject)
 
 CCopasiObject (const CCopasiObject &src, const CCopasiContainer *pParent=NULL)
 
void clearDirectDependencies ()
 
void clearRefresh ()
 
bool dependsOn (DataObjectSet candidates, const DataObjectSet &context=DataObjectSet()) const
 
void getAllDependencies (DataObjectSet &dependencies, const DataObjectSet &context) const
 
virtual CCopasiObjectName getCN () const
 
virtual const DataObjectSetgetDirectDependencies (const DataObjectSet &context=DataObjectSet()) const
 
CCopasiContainergetObjectAncestor (const std::string &type) const
 
CCopasiDataModelgetObjectDataModel ()
 
const CCopasiDataModelgetObjectDataModel () const
 
const std::string & getObjectName () const
 
CCopasiContainergetObjectParent () const
 
const std::string & getObjectType () const
 
virtual const
CObjectInterface::ObjectSet
getPrerequisites () const
 
virtual RefreshgetRefresh () const
 
UpdateMethodgetUpdateMethod () const
 
virtual voidgetValuePointer () const
 
bool hasCircularDependencies (DataObjectSet &candidates, DataObjectSet &verified, const DataObjectSet &context) const
 
bool hasUpdateMethod () const
 
bool isArray () const
 
bool isContainer () const
 
bool isDataModel () const
 
bool isMatrix () const
 
bool isNameVector () const
 
bool isNonUniqueName () const
 
virtual bool isPrerequisiteForContext (const CObjectInterface *pObject, const CMath::SimulationContextFlag &context, const CObjectInterface::ObjectSet &changedObjects) const
 
bool isReference () const
 
bool isRoot () const
 
bool isSeparator () const
 
bool isStaticString () const
 
bool isValueBool () const
 
bool isValueDbl () const
 
bool isValueInt () const
 
bool isValueInt64 () const
 
bool isValueString () const
 
bool isVector () const
 
virtual void print (std::ostream *ostream) const
 
void removeDirectDependency (const CCopasiObject *pObject)
 
void setDirectDependencies (const DataObjectSet &directDependencies)
 
bool setObjectName (const std::string &name)
 
void setObjectValue (const C_FLOAT64 &value)
 
void setObjectValue (const C_INT32 &value)
 
void setObjectValue (const bool &value)
 
template<class CType >
void setRefresh (CType *pType, void(CType::*method)(void))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const C_FLOAT64 &))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const C_INT32 &))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const bool &))
 
virtual ~CCopasiObject ()
 
- Public Member Functions inherited from CObjectInterface
 CObjectInterface ()
 
virtual ~CObjectInterface ()
 
- Public Member Functions inherited from CAnnotation
bool addUnsupportedAnnotation (const std::string &name, const std::string &xml)
 
 CAnnotation ()
 
 CAnnotation (const CAnnotation &src)
 
const std::string & getMiriamAnnotation () const
 
const std::string & getNotes () const
 
UnsupportedAnnotationgetUnsupportedAnnotations ()
 
const UnsupportedAnnotationgetUnsupportedAnnotations () const
 
bool operator== (const CAnnotation &rhs) const
 
bool removeUnsupportedAnnotation (const std::string &name)
 
bool replaceUnsupportedAnnotation (const std::string &name, const std::string &xml)
 
void setMiriamAnnotation (const std::string &miriamAnnotation, const std::string &newId, const std::string &oldId)
 
void setNotes (const std::string &notes)
 
virtual ~CAnnotation ()
 

Private Member Functions

void calculate ()
 
std::string escapeId (const std::string &id)
 
void initializeMetaboliteKeyMap ()
 
void initializeParameters ()
 
void initObjects ()
 
C_INT32 loadOld (CReadConfig &configbuffer)
 
bool loadOneRole (CReadConfig &configbuffer, CFunctionParameter::Role role, C_INT32 n, const std::string &prefix)
 
CEvaluationNodeVariableobject2variable (const CEvaluationNodeObject *objectNode, std::map< std::string, std::pair< CCopasiObject *, CFunctionParameter * > > &replacementMap, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap)
 
CEvaluationNodeobjects2variables (const CEvaluationNode *expression, std::map< std::string, std::pair< CCopasiObject *, CFunctionParameter * > > &replacementMap, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap)
 
CReactionoperator= (const CReaction &)
 
void setScalingFactor ()
 
CEvaluationNodeObjectvariable2object (CEvaluationNodeVariable *pVariableNode)
 
CEvaluationNodevariables2objects (CEvaluationNode *expression)
 

Private Attributes

CChemEq mChemEq
 
bool mFast
 
C_FLOAT64 mFlux
 
CFunctionParameterMap mMap
 
std::vector< std::vector
< std::string > > 
mMetabKeyMap
 
CCopasiParameterGroup mParameters
 
C_FLOAT64 mParticleFlux
 
CCopasiObjectReference
< C_FLOAT64 > * 
mpFluxReference
 
CFunctionmpFunction
 
CCopasiObjectReference
< C_FLOAT64 > * 
mpParticleFluxReference
 
CCopasiObjectReference
< C_FLOAT64 > * 
mpPropensityReference
 
C_FLOAT64 mPropensity
 
std::string mSBMLId
 
const C_FLOAT64mScalingFactor
 
const C_FLOAT64mUnitScalingFactor
 

Static Private Attributes

static C_FLOAT64 mDefaultScalingFactor = 1.0
 

Friends

std::ostream & operator<< (std::ostream &os, const CReaction &d)
 

Additional Inherited Members

- Public Types inherited from CCopasiContainer
typedef std::multimap
< std::string, CCopasiObject * > 
objectMap
 
- Public Types inherited from CCopasiObject
typedef std::set< const
CCopasiObject * > 
DataObjectSet
 
typedef std::vector< Refresh * > DataUpdateSequence
 
- Public Types inherited from CObjectInterface
typedef std::set< const
CObjectInterface * > 
ObjectSet
 
typedef std::vector
< CObjectInterface * > 
UpdateSequence
 
- Public Types inherited from CAnnotation
typedef std::map< std::string,
std::string > 
UnsupportedAnnotation
 
- Static Public Member Functions inherited from CCopasiObject
static std::vector< Refresh * > buildUpdateSequence (const DataObjectSet &objects, const DataObjectSet &uptoDateObjects, const DataObjectSet &context=DataObjectSet())
 
static void setRenameHandler (CRenameHandler *rh)
 
- Static Public Member Functions inherited from CAnnotation
static CAnnotationcastObject (CCopasiObject *pObject)
 
static const CAnnotationcastObject (const CCopasiObject *pObject)
 
- Static Public Attributes inherited from CCopasiContainer
static const std::vector
< CCopasiContainer * > 
EmptyList
 
- Protected Types inherited from CCopasiObject
enum  Flag {
  Container = 0x1, Vector = 0x2, Matrix = 0x4, NameVector = 0x8,
  Reference = 0x10, ValueBool = 0x20, ValueInt = 0x40, ValueInt64 = 0x80,
  ValueDbl = 0x100, NonUniqueName = 0x200, StaticString = 0x400, ValueString = 0x800,
  Separator = 0x1000, ModelEntity = 0x2000, Array = 0x4000, DataModel = 0x8000,
  Root = 0x10000, Gui = 0x20000
}
 
- Protected Member Functions inherited from CCopasiContainer
template<class CType >
CCopasiObjectaddMatrixReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
template<class CType >
CCopasiObjectaddObjectReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
template<class CType >
CCopasiObjectaddVectorReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
void initObjects ()
 
- Protected Member Functions inherited from CCopasiObject
 CCopasiObject ()
 
 CCopasiObject (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &type="CN", const unsigned C_INT32 &flag=0)
 
- Protected Attributes inherited from CCopasiContainer
objectMap mObjects
 
- Protected Attributes inherited from CAnnotation
std::string mKey
 
- Static Protected Attributes inherited from CCopasiObject
static CRenameHandlersmpRenameHandler = NULL
 

Detailed Description

Definition at line 44 of file CReaction.h.

Constructor & Destructor Documentation

CReaction::CReaction ( const std::string &  name = "NoName",
const CCopasiContainer pParent = NULL 
)

Default constructor

Parameters
conststd::string & name (default: "NoName")
constCCopasiContainer * pParent (default: NULL)

Definition at line 51 of file CReaction.cpp.

References CKeyFactory::add(), CONSTRUCTOR_TRACE, CCopasiRootContainer::getKeyFactory(), CCopasiObject::getObjectType(), CCopasiRootContainer::getUndefinedFunction(), initObjects(), CAnnotation::mKey, and setFunction().

52  :
53  CCopasiContainer(name, pParent, "Reaction"),
54  CAnnotation(),
55  mChemEq("Chemical Equation", this),
56  mpFunction(NULL),
57  mFlux(0),
58  mpFluxReference(NULL),
59  mParticleFlux(0),
61  mPropensity(0),
65  mMetabKeyMap(),
66  mParameters("Parameters", this),
67  mFast(false)
68 {
70 
72  initObjects();
74 }
void initObjects()
Definition: CReaction.cpp:945
CCopasiParameterGroup mParameters
Definition: CReaction.h:610
CCopasiObjectReference< C_FLOAT64 > * mpFluxReference
Definition: CReaction.h:569
static CFunction * getUndefinedFunction()
CCopasiObjectReference< C_FLOAT64 > * mpPropensityReference
Definition: CReaction.h:581
CFunction * mpFunction
Definition: CReaction.h:563
C_FLOAT64 mParticleFlux
Definition: CReaction.h:574
const std::string & getObjectType() const
const C_FLOAT64 * mUnitScalingFactor
Definition: CReaction.h:593
std::string mKey
Definition: CAnnotation.h:119
CChemEq mChemEq
Definition: CReaction.h:558
bool setFunction(const std::string &functionName)
Definition: CReaction.cpp:255
std::string add(const std::string &prefix, CCopasiObject *pObject)
C_FLOAT64 mPropensity
Definition: CReaction.h:580
const C_FLOAT64 * mScalingFactor
Definition: CReaction.h:588
C_FLOAT64 mFlux
Definition: CReaction.h:568
static CKeyFactory * getKeyFactory()
bool mFast
Definition: CReaction.h:623
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
static C_FLOAT64 mDefaultScalingFactor
Definition: CReaction.h:553
CCopasiObjectReference< C_FLOAT64 > * mpParticleFluxReference
Definition: CReaction.h:575
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202
CReaction::CReaction ( const CReaction src,
const CCopasiContainer pParent = NULL 
)

Copy constructor

Parameters
const CReaction &src
constCCopasiContainer * pParent (default: NULL)

Definition at line 76 of file CReaction.cpp.

References CKeyFactory::add(), CONSTRUCTOR_TRACE, CCopasiRootContainer::getKeyFactory(), CAnnotation::getMiriamAnnotation(), CCopasiObject::getObjectType(), initObjects(), CAnnotation::mKey, mpFunction, and CAnnotation::setMiriamAnnotation().

77  :
78  CCopasiContainer(src, pParent),
79  CAnnotation(src),
80  mChemEq(src.mChemEq, this),
82  mFlux(src.mFlux),
83  mpFluxReference(NULL),
90  mMap(src.mMap),
92  mParameters(src.mParameters, this),
93  mFast(src.mFast)
94 {
96 
98  initObjects();
99 
100  if (mpFunction)
101  {
102  //compileParameters();
103  }
104 
106 }
void initObjects()
Definition: CReaction.cpp:945
CCopasiParameterGroup mParameters
Definition: CReaction.h:610
CCopasiObjectReference< C_FLOAT64 > * mpFluxReference
Definition: CReaction.h:569
CCopasiObjectReference< C_FLOAT64 > * mpPropensityReference
Definition: CReaction.h:581
CFunction * mpFunction
Definition: CReaction.h:563
C_FLOAT64 mParticleFlux
Definition: CReaction.h:574
const std::string & getObjectType() const
void setMiriamAnnotation(const std::string &miriamAnnotation, const std::string &newId, const std::string &oldId)
const std::string & getMiriamAnnotation() const
const C_FLOAT64 * mUnitScalingFactor
Definition: CReaction.h:593
std::string mKey
Definition: CAnnotation.h:119
CChemEq mChemEq
Definition: CReaction.h:558
CFunctionParameterMap mMap
Definition: CReaction.h:599
std::string add(const std::string &prefix, CCopasiObject *pObject)
C_FLOAT64 mPropensity
Definition: CReaction.h:580
const C_FLOAT64 * mScalingFactor
Definition: CReaction.h:588
C_FLOAT64 mFlux
Definition: CReaction.h:568
static CKeyFactory * getKeyFactory()
bool mFast
Definition: CReaction.h:623
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
CCopasiObjectReference< C_FLOAT64 > * mpParticleFluxReference
Definition: CReaction.h:575
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202
CReaction::~CReaction ( )
virtual

Destructor

Definition at line 108 of file CReaction.cpp.

References cleanup(), DESTRUCTOR_TRACE, CCopasiRootContainer::getKeyFactory(), CAnnotation::mKey, and CKeyFactory::remove().

109 {
111  cleanup();
113 }
bool remove(const std::string &key)
void cleanup()
Definition: CReaction.cpp:135
std::string mKey
Definition: CAnnotation.h:119
#define DESTRUCTOR_TRACE
Definition: copasi.h:206
static CKeyFactory * getKeyFactory()

Member Function Documentation

bool CReaction::addModifier ( const std::string &  metabKey,
const C_FLOAT64 multiplicity = 1.0 
)

Add a modifier to the reaction

Parameters
std::string& metabKey
constC_FLOAT64 & multiplicity (Default 1.0)
Returns
bool success

Definition at line 240 of file CReaction.cpp.

References CChemEq::addMetabolite(), mChemEq, and CChemEq::MODIFIER.

Referenced by CModelAdd::addReactions(), CModel::convert2NonReversible(), SBMLImporter::createCReactionFromReaction(), CModelExpansion::duplicateReaction(), and CCopasiXMLParser::ModifierElement::start().

242 {return mChemEq.addMetabolite(metabKey, multiplicity, CChemEq::MODIFIER);}
CChemEq mChemEq
Definition: CReaction.h:558
bool addMetabolite(const std::string &key, const C_FLOAT64 multiplicity, const MetaboliteRole &role)
Definition: CChemEq.cpp:80
void CReaction::addParameterMapping ( const size_t &  index,
const std::string &  key 
)

Add a parameter mapping for the indexed parameter.

Parameters
constsize_t & index
conststd::string & key

Definition at line 348 of file CReaction.cpp.

References fatalError, getFunctionParameters(), mMetabKeyMap, mpFunction, and CFunctionParameter::VFLOAT64.

Referenced by CModelAdd::addReactions(), CModelExpansion::createDiffusionReaction(), SBMLImporter::doMapping(), CModelExpansion::duplicateReaction(), loadOneRole(), and CReactionInterface::writeBackToReaction().

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 }
CFunction * mpFunction
Definition: CReaction.h:563
#define fatalError()
const CFunctionParameters & getFunctionParameters() const
Definition: CReaction.cpp:576
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
void CReaction::addParameterMapping ( const std::string &  parameterName,
const std::string &  key 
)

Add a parameter mapping for the named parameter.

Parameters
conststd::string & parameterName
conststd::string & key

Definition at line 374 of file CReaction.cpp.

References C_INVALID_INDEX, fatalError, getParameterIndex(), mMetabKeyMap, mpFunction, and CFunctionParameter::VFLOAT64.

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 }
CFunction * mpFunction
Definition: CReaction.h:563
#define fatalError()
#define C_INVALID_INDEX
Definition: copasi.h:222
size_t getParameterIndex(const std::string &parameterName, CFunctionParameter::DataType *pType=NULL) const
Definition: CReaction.cpp:292
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
bool CReaction::addProduct ( const std::string &  metabKey,
const C_FLOAT64 multiplicity = 1.0 
)
bool CReaction::addSubstrate ( const std::string &  metabKey,
const C_FLOAT64 multiplicity = 1.0 
)

Add a substrate to the reaction

Parameters
std::string& metabKey
constC_FLOAT64 & multiplicity (Default 1.0)
Returns
bool success

Definition at line 232 of file CReaction.cpp.

References CChemEq::addMetabolite(), mChemEq, and CChemEq::SUBSTRATE.

Referenced by CModelAdd::addReactions(), CModel::convert2NonReversible(), SBMLImporter::createCReactionFromReaction(), CModelExpansion::createDiffusionReaction(), CModelExpansion::duplicateReaction(), and CCopasiXMLParser::SubstrateElement::start().

234 {return mChemEq.addMetabolite(metabKey, multiplicity, CChemEq::SUBSTRATE);}
CChemEq mChemEq
Definition: CReaction.h:558
bool addMetabolite(const std::string &key, const C_FLOAT64 multiplicity, const MetaboliteRole &role)
Definition: CChemEq.cpp:80
void CReaction::calculate ( void  )
private

Calculate the kinetic function

Definition at line 840 of file CReaction.cpp.

References CFunction::calcValue(), CFunctionParameterMap::getPointers(), mFlux, mMap, mParticleFlux, mpFunction, mScalingFactor, and mUnitScalingFactor.

Referenced by calculateFlux(), calculateParticleFlux(), compile(), and initObjects().

841 {
844  return;
845 }
CFunction * mpFunction
Definition: CReaction.h:563
C_FLOAT64 mParticleFlux
Definition: CReaction.h:574
CCallParameters< C_FLOAT64 > & getPointers()
const C_FLOAT64 * mUnitScalingFactor
Definition: CReaction.h:593
CFunctionParameterMap mMap
Definition: CReaction.h:599
virtual const C_FLOAT64 & calcValue(const CCallParameters< C_FLOAT64 > &callParameters)
Definition: CFunction.cpp:159
const C_FLOAT64 * mScalingFactor
Definition: CReaction.h:588
C_FLOAT64 mFlux
Definition: CReaction.h:568
const C_FLOAT64 & CReaction::calculateFlux ( )

Calculate the kinetic function and returns the flux

Returns
const C_FLOAT64 & Flux

Definition at line 826 of file CReaction.cpp.

References calculate(), and mFlux.

827 {
828  calculate();
829  return mFlux;
830 }
void calculate()
Definition: CReaction.cpp:840
C_FLOAT64 mFlux
Definition: CReaction.h:568
C_FLOAT64 CReaction::calculatePartialDerivative ( C_FLOAT64 pXi,
const C_FLOAT64 derivationFactor,
const C_FLOAT64 resolution 
)

Calculate partial derivative of the flux

Parameters
C_FLOAT64* pXi
constC_FLOAT64 & derivationFactor
constC_FLOAT64 & resolution (unscaled resolution)
Returns
C_FLOAT64 partial

Definition at line 847 of file CReaction.cpp.

References C_FLOAT64, CFunction::calcValue(), CFunction::dependsOn(), CFunctionParameterMap::getPointers(), mMap, mpFunction, and mScalingFactor.

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 }
virtual bool dependsOn(const C_FLOAT64 *parameter, const CCallParameters< C_FLOAT64 > &callParameters) const
Definition: CFunction.cpp:168
CFunction * mpFunction
Definition: CReaction.h:563
CCallParameters< C_FLOAT64 > & getPointers()
CFunctionParameterMap mMap
Definition: CReaction.h:599
virtual const C_FLOAT64 & calcValue(const CCallParameters< C_FLOAT64 > &callParameters)
Definition: CFunction.cpp:159
const C_FLOAT64 * mScalingFactor
Definition: CReaction.h:588
#define C_FLOAT64
Definition: copasi.h:92
const C_FLOAT64 & CReaction::calculateParticleFlux ( )

Calculates the kinetic function and returns the particle flux

Returns
const C_FLOAT64 & ParticleFlux

Definition at line 832 of file CReaction.cpp.

References calculate(), CCopasiRootContainer::getUndefinedFunction(), mParticleFlux, and mpFunction.

833 {
835  calculate();
836 
837  return mParticleFlux;
838 }
void calculate()
Definition: CReaction.cpp:840
static CFunction * getUndefinedFunction()
CFunction * mpFunction
Definition: CReaction.h:563
C_FLOAT64 mParticleFlux
Definition: CReaction.h:574
void CReaction::cleanup ( )

Delete

Definition at line 135 of file CReaction.cpp.

Referenced by ~CReaction().

136 {
137  // TODO: mMap.cleanup();
138  //mParameterDescription.cleanup();
139 }
void CReaction::clearParameterMapping ( const std::string &  parameterName)

Clear the parameter mapping for the named parameter.

Parameters
constsize_t & index

Definition at line 407 of file CReaction.cpp.

References C_INVALID_INDEX, fatalError, getParameterIndex(), mMetabKeyMap, mpFunction, and CFunctionParameter::VFLOAT64.

Referenced by CModelAdd::addReactions(), CModelExpansion::duplicateReaction(), loadOneRole(), and CReactionInterface::writeBackToReaction().

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 }
CFunction * mpFunction
Definition: CReaction.h:563
#define fatalError()
#define C_INVALID_INDEX
Definition: copasi.h:222
size_t getParameterIndex(const std::string &parameterName, CFunctionParameter::DataType *pType=NULL) const
Definition: CReaction.cpp:292
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
void CReaction::clearParameterMapping ( const size_t &  index)

Clear the parameter mapping for the indexed parameter.

Parameters
constsize_t & index

Definition at line 423 of file CReaction.cpp.

References fatalError, getFunctionParameters(), mMetabKeyMap, mpFunction, and CFunctionParameter::VFLOAT64.

424 {
425  if (!mpFunction) fatalError();
426 
427  if (getFunctionParameters()[index]->getType() != CFunctionParameter::VFLOAT64) fatalError();
428 
429  mMetabKeyMap[index].clear();
430 }
CFunction * mpFunction
Definition: CReaction.h:563
#define fatalError()
const CFunctionParameters & getFunctionParameters() const
Definition: CReaction.cpp:576
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
void CReaction::compile ( )

Compile the reaction, i.e., links the metabolites and parameters with the rate function. The connection of the reaction and the function parameter mapping to the actual metabolites is established (before compile() the chemical equation and the reaction only hold the names of the metabolites).

Parameters
CCopasiVectorNS < CCompartment > &compartments

Definition at line 583 of file CReaction.cpp.

References CFunctionParameterMap::addCallParameter(), CCopasiObject::addDirectDependency(), CCopasiVector< T >::begin(), calculate(), CFunctionParameterMap::clearCallParameter(), CCopasiObject::clearDirectDependencies(), CCopasiObject::clearRefresh(), CCopasiVector< T >::end(), CFunctionParameterMap::getFunctionParameters(), getFunctionParameters(), CCopasiRootContainer::getKeyFactory(), CChemEq::getModifiers(), CCopasiObject::getObjectName(), CChemEq::getProducts(), CChemEq::getSubstrates(), CCopasiRootContainer::getUndefinedFunction(), CCopasiObject::getValueObject(), mChemEq, mFlux, mMap, mMetabKeyMap, mParticleFlux, mpFluxReference, mpFunction, mpParticleFluxReference, CFunctionParameterMap::pUnmappedObject, CFunctionParameterMap::setCallParameter(), CCopasiObject::setDirectDependencies(), CCopasiObject::setRefresh(), setScalingFactor(), CFunctionParameters::size(), and CFunctionParameter::VINT32.

Referenced by CModel::convert2NonReversible(), and CReactionInterface::writeBackToReaction().

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 }
void calculate()
Definition: CReaction.cpp:840
CCopasiObjectReference< C_FLOAT64 > * mpFluxReference
Definition: CReaction.h:569
void clearDirectDependencies()
void setRefresh(CType *pType, void(CType::*method)(void))
void clearCallParameter(const std::string paramName)
static CFunction * getUndefinedFunction()
CFunction * mpFunction
Definition: CReaction.h:563
const std::string & getObjectName() const
iterator begin()
const CFunctionParameters & getFunctionParameters() const
void setDirectDependencies(const DataObjectSet &directDependencies)
C_FLOAT64 mParticleFlux
Definition: CReaction.h:574
CChemEq mChemEq
Definition: CReaction.h:558
void setScalingFactor()
Definition: CReaction.cpp:879
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
iterator end()
void addDirectDependency(const CCopasiObject *pObject)
const CFunctionParameters & getFunctionParameters() const
Definition: CReaction.cpp:576
CFunctionParameterMap mMap
Definition: CReaction.h:599
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
C_FLOAT64 mFlux
Definition: CReaction.h:568
static CKeyFactory * getKeyFactory()
const CCopasiVector< CChemEqElement > & getModifiers() const
Definition: CChemEq.cpp:66
void setCallParameter(const std::string paramName, const CCopasiObject *obj)
static CCopasiObject * pUnmappedObject
void addCallParameter(const std::string paramName, const CCopasiObject *obj)
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
virtual const CCopasiObject * getValueObject() const
CCopasiObjectReference< C_FLOAT64 > * mpParticleFluxReference
Definition: CReaction.h:575
std::string CReaction::escapeId ( const std::string &  id)
private

Escapes double quotes and backslashes in a string and puts strings with tabs and spaces in double quotes.

Definition at line 1659 of file CReaction.cpp.

Referenced by object2variable().

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 }
const CCallParameters< C_FLOAT64 > & CReaction::getCallParameters ( ) const

Retrieve the call parameter given to the kinetic function.

Returns
const CCallParameters< C_FLOAT64 > & callParameters

Definition at line 216 of file CReaction.cpp.

References CFunctionParameterMap::getPointers(), and mMap.

Referenced by CMathObject::compileFlux().

217 {
218  return mMap.getPointers();
219 }
CCallParameters< C_FLOAT64 > & getPointers()
CFunctionParameterMap mMap
Definition: CReaction.h:599
const CChemEq & CReaction::getChemEq ( ) const
CChemEq & CReaction::getChemEq ( )

Retrieves the chemical equation of the reaction

Returns
CChemEq & chemEq

Definition at line 226 of file CReaction.cpp.

References mChemEq.

227 {return mChemEq;}
CChemEq mChemEq
Definition: CReaction.h:558
std::string CReaction::getChildObjectUnits ( const CCopasiObject pObject) const
virtual

Retrieve the units of the child object.

Returns
std::string units

Reimplemented from CCopasiContainer.

Definition at line 116 of file CReaction.cpp.

References CModel::getFrequencyUnitsDisplayString(), CCopasiObject::getObjectAncestor(), CCopasiObject::getObjectName(), and CModel::getQuantityRateUnitsDisplayString().

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 }
CCopasiContainer * getObjectAncestor(const std::string &type) const
const std::string & getObjectName() const
std::string getFrequencyUnitsDisplayString() const
Definition: CModel.cpp:4539
std::string getQuantityRateUnitsDisplayString() const
Definition: CModel.cpp:4657
Definition: CModel.h:50
size_t CReaction::getCompartmentNumber ( ) const

Retrieves the number of compartments the reaction is acting in.

Returns
"size_t" the compartment number

Definition at line 873 of file CReaction.cpp.

References CChemEq::getCompartmentNumber(), and mChemEq.

Referenced by CSBMLExporter::createKineticLaw(), CODEExporter::exportReacParamsAndFuncs(), CModelParameter::getUnit(), CModel::printParameterOverview(), setScalingFactor(), and CMMLOutput::writeRHS().

874 {return mChemEq.getCompartmentNumber();}
size_t getCompartmentNumber() const
Definition: CChemEq.cpp:110
CChemEq mChemEq
Definition: CReaction.h:558
std::set< const CCopasiObject * > CReaction::getDeletedObjects ( ) const
virtual

Retrieve the list of deleted numeric child objects;

Returns
std::set< const CCopasiObject * > deletedObjects

Definition at line 959 of file CReaction.cpp.

References CCopasiParameterGroup::beginIndex(), CCopasiParameterGroup::endIndex(), isLocalParameter(), mParameters, mpFluxReference, and mpParticleFluxReference.

Referenced by CModel::appendDependentModelObjects(), CModel::removeReaction(), CQReactionDM::removeRows(), and ReactionsWidget1::slotBtnDelete().

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 }
CCopasiParameterGroup mParameters
Definition: CReaction.h:610
CCopasiObjectReference< C_FLOAT64 > * mpFluxReference
Definition: CReaction.h:569
bool isLocalParameter(const size_t &index) const
Definition: CReaction.cpp:449
index_iterator endIndex() const
index_iterator beginIndex() const
parameterGroup::iterator index_iterator
CCopasiObjectReference< C_FLOAT64 > * mpParticleFluxReference
Definition: CReaction.h:575
CEvaluationNode * CReaction::getExpressionTree ( )

Converts the function tree into the corresponding expression tree. All variable nodes are replaced by object nodes.

Definition at line 1644 of file CReaction.cpp.

References getFunction(), and variables2objects().

1645 {
1646  return this->variables2objects(const_cast<CFunction*>(this->getFunction())->getRoot());
1647 }
const CFunction * getFunction() const
Definition: CReaction.cpp:252
CEvaluationNode * variables2objects(CEvaluationNode *expression)
Definition: CReaction.cpp:1440
const C_FLOAT64 & CReaction::getFlux ( ) const

Retrieves the flux of the reaction

Returns
const C_FLOAT64 & flux

Definition at line 192 of file CReaction.cpp.

References mFlux.

Referenced by CQReactionDM::data(), operator<<(), and ReactionsWidget1::setFramework().

193 {return mFlux;}
C_FLOAT64 mFlux
Definition: CReaction.h:568
CCopasiObject * CReaction::getFluxReference ( )

Retrieve object referencing the flux

Returns
CCopasiObject * fluxReference

Definition at line 198 of file CReaction.cpp.

References mpFluxReference.

Referenced by CMathObject::compileParticleFlux(), CModel::convert2NonReversible(), and CMathReaction::initialize().

199 {return this->mpFluxReference;}
CCopasiObjectReference< C_FLOAT64 > * mpFluxReference
Definition: CReaction.h:569
const CCopasiObject * CReaction::getFluxReference ( ) const

Retrieve const object referencing the flux

Returns
CCopasiObject * fluxReference

Definition at line 195 of file CReaction.cpp.

References mpFluxReference.

196 {return this->mpFluxReference;}
CCopasiObjectReference< C_FLOAT64 > * mpFluxReference
Definition: CReaction.h:569
const CFunction * CReaction::getFunction ( ) const
const CFunctionParameters & CReaction::getFunctionParameters ( ) const
const std::string & CReaction::getKey ( ) const
virtual
const CCompartment * CReaction::getLargestCompartment ( ) const

Retrieve the largest compartment that the reaction touches. This is time dependent it can only be called after update initial values has been called. Note for an empty reaction a NULL pointer is returned.

Returns
const CCompartment * pCompartment

Definition at line 876 of file CReaction.cpp.

References CChemEq::getLargestCompartment(), and mChemEq.

877 {return mChemEq.getLargestCompartment();}
CChemEq mChemEq
Definition: CReaction.h:558
const CCompartment * getLargestCompartment() const
Definition: CChemEq.cpp:137
const CObjectInterface * CReaction::getObject ( const CCopasiObjectName cn) const
virtual

We are hiding local reaction parameter which are covered by global quantities.

Parameters
constCCopasiObjectName & cn
Returns
const CObjectInterface * pObject

Reimplemented from CCopasiContainer.

Definition at line 479 of file CReaction.cpp.

References CCopasiContainer::getObject(), CCopasiObject::getObjectName(), CCopasiObject::getObjectParent(), isLocalParameter(), CCopasiObject::isStaticString(), and mParameters.

Referenced by CQSimpleSelectionTree::populateTree().

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 }
CCopasiParameterGroup mParameters
Definition: CReaction.h:610
const std::string & getObjectName() const
bool isLocalParameter(const size_t &index) const
Definition: CReaction.cpp:449
bool isStaticString() const
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
CCopasiContainer * getObjectParent() const
std::string CReaction::getObjectDisplayName ( bool  regular = true,
bool  richtext = false 
) const
virtual

Overload display name. Special treatment for reaction to provide a shorter display

Reimplemented from CCopasiObject.

Definition at line 1688 of file CReaction.cpp.

References CCopasiObject::getObjectAncestor(), CCopasiObject::getObjectDisplayName(), and CCopasiObject::getObjectName().

Referenced by CQSelectionWizardPage::fillTree().

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 }
CCopasiContainer * getObjectAncestor(const std::string &type) const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
const std::string & getObjectName() const
Definition: CModel.h:50
size_t CReaction::getParameterIndex ( const std::string &  parameterName,
CFunctionParameter::DataType pType = NULL 
) const

Retrieve the index of the given parameter name in the function call. If pType is not NULL the type of the parameter is returned

Parameters
conststd::string & parameterName
CFunctionParameter::DataType* pType (default: NULL)
Returns
size_t index;

Retrieve the index of the given parameter name in the function call

Parameters
conststd::string & parameterName
Returns
size_t index;

Definition at line 292 of file CReaction.cpp.

References CFunctionParameterMap::findParameterByName(), and mMap.

Referenced by addParameterMapping(), clearParameterMapping(), SBMLImporter::findCorrespondingFunction(), getParameterMapping(), CModelParameter::getUnit(), initializeParameters(), isLocalParameter(), setParameterMapping(), setParameterMappingVector(), and setParameterValue().

293 {
294  if (pType != NULL)
295  {
296  return mMap.findParameterByName(parameterName, *pType);
297  }
298 
300  return mMap.findParameterByName(parameterName, Type);
301 }
CFunctionParameterMap mMap
Definition: CReaction.h:599
size_t findParameterByName(const std::string &name, CFunctionParameter::DataType &dataType) const
const std::vector< std::string > & CReaction::getParameterMapping ( const size_t &  index) const

Definition at line 432 of file CReaction.cpp.

References C_INVALID_INDEX, fatalError, mMetabKeyMap, and mpFunction.

Referenced by CModel::convert2NonReversible(), CSBMLExporter::createKineticLaw(), getParameterMapping(), CModelParameter::refreshFromModel(), and ParameterTable::updateTable().

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 }
CFunction * mpFunction
Definition: CReaction.h:563
#define fatalError()
#define C_INVALID_INDEX
Definition: copasi.h:222
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
const std::vector< std::string > & CReaction::getParameterMapping ( const std::string &  parameterName) const

Definition at line 442 of file CReaction.cpp.

References getParameterIndex(), and getParameterMapping().

443 {
444  size_t index = getParameterIndex(parameterName);
445 
446  return getParameterMapping(index);
447 }
size_t getParameterIndex(const std::string &parameterName, CFunctionParameter::DataType *pType=NULL) const
Definition: CReaction.cpp:292
const std::vector< std::string > & getParameterMapping(const size_t &index) const
Definition: CReaction.cpp:432
const std::vector< std::vector<std::string> >& CReaction::getParameterMappings ( ) const
inline
std::vector< std::vector<std::string> >& CReaction::getParameterMappings ( )
inline

Definition at line 288 of file CReaction.h.

References mMetabKeyMap.

289  {return mMetabKeyMap;}
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
const CCopasiParameterGroup & CReaction::getParameters ( ) const
CCopasiParameterGroup & CReaction::getParameters ( )

Gets the list of kinetic parameter objects of the reaction/function

Definition at line 336 of file CReaction.cpp.

References mParameters.

337 {return mParameters;}
CCopasiParameterGroup mParameters
Definition: CReaction.h:610
const C_FLOAT64 & CReaction::getParameterValue ( const std::string &  parameterName) const

Retrieves a parameter value

Definition at line 326 of file CReaction.cpp.

References fatalError, CCopasiParameterGroup::getValue(), mParameters, mpFunction, and CCopasiParameter::Value::pDOUBLE.

Referenced by CModelAdd::addReactions(), CModel::convert2NonReversible(), CSBMLExporter::createKineticLaw(), CMMLOutput::createParameterMapping(), and CModelExpansion::duplicateReaction().

327 {
328  if (!mpFunction) fatalError();
329 
330  return * mParameters.getValue(parameterName).pDOUBLE;
331 }
CCopasiParameterGroup mParameters
Definition: CReaction.h:610
CFunction * mpFunction
Definition: CReaction.h:563
#define fatalError()
const CCopasiParameter::Value & getValue(const std::string &name) const
const C_FLOAT64 & CReaction::getParticleFlux ( ) const

Retrieves the scaled flux of the reaction

Returns
const C_FLOAT64 & scaledFlux

Definition at line 201 of file CReaction.cpp.

References mParticleFlux.

Referenced by CQReactionDM::data(), operator<<(), and ReactionsWidget1::setFramework().

202 {return mParticleFlux;}
C_FLOAT64 mParticleFlux
Definition: CReaction.h:574
CCopasiObject * CReaction::getParticleFluxReference ( )

Retrieve object referencing the particle flux

Returns
CCopasiObject * particleFluxReference

Definition at line 207 of file CReaction.cpp.

References mpParticleFluxReference.

Referenced by CMathObject::compilePropensity(), CModel::convert2NonReversible(), CMathReaction::initialize(), and CHybridMethodODE45::setupMetab2React().

208 {return mpParticleFluxReference;}
CCopasiObjectReference< C_FLOAT64 > * mpParticleFluxReference
Definition: CReaction.h:575
const CCopasiObject * CReaction::getParticleFluxReference ( ) const

Retrieve const object referencing the particle flux

Returns
CCopasiObject * particleFluxReference

Definition at line 204 of file CReaction.cpp.

References mpParticleFluxReference.

205 {return mpParticleFluxReference;}
CCopasiObjectReference< C_FLOAT64 > * mpParticleFluxReference
Definition: CReaction.h:575
CCopasiObject * CReaction::getPropensityReference ( )

Retrieve object referencing the propensity

Returns
CCopasiObject * propensityReference

Definition at line 210 of file CReaction.cpp.

References mpPropensityReference.

Referenced by CMathReaction::initialize().

211 {return mpPropensityReference;}
CCopasiObjectReference< C_FLOAT64 > * mpPropensityReference
Definition: CReaction.h:581
const CCopasiObject * CReaction::getPropensityReference ( ) const

Retrieve object referencing the propensity

Returns
CCopasiObject * propensityReference

Definition at line 213 of file CReaction.cpp.

References mpPropensityReference.

214 {return mpPropensityReference;}
CCopasiObjectReference< C_FLOAT64 > * mpPropensityReference
Definition: CReaction.h:581
const std::string & CReaction::getSBMLId ( ) const

Returns a reference to the SBML Id.

Definition at line 1654 of file CReaction.cpp.

References mSBMLId.

Referenced by SBMLImporter::applyStoichiometricExpressions(), CSBMLExporter::collectIds(), CSBMLExporter::createReaction(), object2variable(), SBMLImporter::replaceObjectNames(), CCopasiXML::saveModel(), and CEvaluationNodeObject::toAST().

1655 {
1656  return this->mSBMLId;
1657 }
std::string mSBMLId
Definition: CReaction.h:617
void CReaction::initializeMetaboliteKeyMap ( )
private

Initializes the mMetabNameMap vectors to the right size.

Definition at line 558 of file CReaction.cpp.

References fatalError, CFunctionParameterMap::getFunctionParameters(), mMap, mMetabKeyMap, mpFunction, CFunctionParameters::size(), and CFunctionParameter::VINT32.

Referenced by setFunction().

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 }
CFunction * mpFunction
Definition: CReaction.h:563
#define fatalError()
const CFunctionParameters & getFunctionParameters() const
CFunctionParameterMap mMap
Definition: CReaction.h:599
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
void CReaction::initializeParameters ( )
private

creates the mParamters List of CParameter objects. mMap needs to be initialized before.

Definition at line 509 of file CReaction.cpp.

References CCopasiParameterGroup::addParameter(), CCopasiParameterGroup::beginIndex(), C_FLOAT64, C_INVALID_INDEX, CCopasiParameter::DOUBLE, CCopasiParameterGroup::endIndex(), fatalError, CFunctionParameterMap::getFunctionParameters(), CCopasiParameter::getKey(), CFunctionParameters::getNumberOfParametersByUsage(), CCopasiObject::getObjectName(), CCopasiParameterGroup::getParameter(), CFunctionParameters::getParameterByUsage(), getParameterIndex(), mMap, mMetabKeyMap, mParameters, mpFunction, CFunctionParameter::PARAMETER, and CCopasiParameterGroup::removeParameter().

Referenced by setFunction().

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 }
CCopasiParameterGroup mParameters
Definition: CReaction.h:610
CFunction * mpFunction
Definition: CReaction.h:563
const std::string & getObjectName() const
#define fatalError()
const CFunctionParameters & getFunctionParameters() const
size_t getNumberOfParametersByUsage(CFunctionParameter::Role usage) const
index_iterator endIndex() const
#define C_INVALID_INDEX
Definition: copasi.h:222
bool removeParameter(const std::string &name)
size_t getParameterIndex(const std::string &parameterName, CFunctionParameter::DataType *pType=NULL) const
Definition: CReaction.cpp:292
CFunctionParameterMap mMap
Definition: CReaction.h:599
virtual const std::string & getKey() const
index_iterator beginIndex() const
const CFunctionParameter * getParameterByUsage(CFunctionParameter::Role usage, size_t &pos) const
CCopasiParameter * getParameter(const std::string &name)
#define C_FLOAT64
Definition: copasi.h:92
bool addParameter(const CCopasiParameter &parameter)
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
parameterGroup::iterator index_iterator
void CReaction::initObjects ( )
private

Definition at line 945 of file CReaction.cpp.

References CCopasiContainer::addObjectReference(), calculate(), mFlux, mParticleFlux, mpFluxReference, mpParticleFluxReference, mpPropensityReference, mPropensity, CCopasiObject::setRefresh(), and CCopasiObject::ValueDbl.

Referenced by CReaction().

946 {
950 
954 
957 }
void calculate()
Definition: CReaction.cpp:840
CCopasiObjectReference< C_FLOAT64 > * mpFluxReference
Definition: CReaction.h:569
void setRefresh(CType *pType, void(CType::*method)(void))
CCopasiObjectReference< C_FLOAT64 > * mpPropensityReference
Definition: CReaction.h:581
C_FLOAT64 mParticleFlux
Definition: CReaction.h:574
C_FLOAT64 mPropensity
Definition: CReaction.h:580
C_FLOAT64 mFlux
Definition: CReaction.h:568
CCopasiObject * addObjectReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
CCopasiObjectReference< C_FLOAT64 > * mpParticleFluxReference
Definition: CReaction.h:575
const bool & CReaction::isFast ( ) const

Check whether the reaction needs to be treated as fast @ return const bool & fast

Definition at line 1712 of file CReaction.cpp.

References mFast.

Referenced by ReactionsWidget1::loadFromReaction(), CCopasiXML::saveModel(), and ReactionsWidget1::saveToReaction().

1713 {
1714  return mFast;
1715 }
bool mFast
Definition: CReaction.h:623
bool CReaction::isLocalParameter ( const size_t &  index) const

Check whether the indexed parameter is a local parameter.

Parameters
constsize_t & index
Returns
bool isLocal

Definition at line 449 of file CReaction.cpp.

References CCopasiParameter::getKey(), CCopasiParameterGroup::getParameter(), mMetabKeyMap, mParameters, and CCopasiParameterGroup::size().

Referenced by CModelAdd::addReactions(), CFixLocalReactionParameters::changeModel(), CModel::convert2NonReversible(), CSBMLExporter::createKineticLaw(), CMMLOutput::createParameterMapping(), CModelExpansion::duplicateReaction(), CODEExporter::exportKineticFunction(), CODEExporter::exportReacParamsAndFuncs(), CODEExporterC::exportTitleData(), CQSimpleSelectionTree::filter(), getDeletedObjects(), CReactionInterface::getDeletedParameters(), getObject(), isLocalParameter(), CODEExporterC::KineticFunction2ODEmember(), CReactionInterface::loadMappingAndValues(), mustBeDeleted(), CQSimpleSelectionTree::populateTree(), CModel::printParameterOverview(), and CModelParameter::refreshFromModel().

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 }
CCopasiParameterGroup mParameters
Definition: CReaction.h:610
virtual const std::string & getKey() const
CCopasiParameter * getParameter(const std::string &name)
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
bool CReaction::isLocalParameter ( const std::string &  parameterName) const

Check whether the named parameter is a local parameter.

Parameters
conststd::string & parameterName
Returns
bool isLocal

Definition at line 462 of file CReaction.cpp.

References C_INVALID_INDEX, fatalError, CFunctionParameter::FLOAT64, getParameterIndex(), isLocalParameter(), and mpFunction.

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 }
CFunction * mpFunction
Definition: CReaction.h:563
#define fatalError()
bool isLocalParameter(const size_t &index) const
Definition: CReaction.cpp:449
#define C_INVALID_INDEX
Definition: copasi.h:222
size_t getParameterIndex(const std::string &parameterName, CFunctionParameter::DataType *pType=NULL) const
Definition: CReaction.cpp:292
bool CReaction::isReversible ( ) const
C_INT32 CReaction::load ( CReadConfig configbuffer)

Loads an object with data coming from a CReadConfig object. (CReadConfig object reads an input stream)

Parameters
pconfigbufferreference to a CReadConfig object.
Returns
mFail
See Also
mFail

Definition at line 148 of file CReaction.cpp.

References C_INT32, CCopasiObject::getObjectAncestor(), CReadConfig::getVariable(), loadOld(), mChemEq, mpFunction, CReadConfig::SEARCH, CChemEqInterface::setChemEqFromString(), setFunction(), CCopasiObject::setObjectName(), and CChemEq::setReversibility().

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 }
CCopasiContainer * getObjectAncestor(const std::string &type) const
C_INT32 loadOld(CReadConfig &configbuffer)
Definition: CReaction.cpp:767
static void setChemEqFromString(CModel *model, CReaction &rea, const std::string &ces)
CFunction * mpFunction
Definition: CReaction.h:563
#define C_INT32
Definition: copasi.h:90
CChemEq mChemEq
Definition: CReaction.h:558
bool setFunction(const std::string &functionName)
Definition: CReaction.cpp:255
Definition: CModel.h:50
C_INT32 getVariable(const std::string &name, const std::string &type, void *pout, CReadConfig::Mode mode=CReadConfig::NEXT)
Definition: CReadConfig.cpp:81
bool setObjectName(const std::string &name)
void setReversibility(const bool &reversible)
Definition: CChemEq.cpp:72
C_INT32 CReaction::loadOld ( CReadConfig configbuffer)
private

Loads a reaction from a Gepasi file

Definition at line 767 of file CReaction.cpp.

References C_FLOAT64, C_INT32, fatalError, CFunctionParameter::FLOAT64, CFunctionParameterMap::getFunctionParameters(), CFunctionParameters::getNumberOfParametersByUsage(), CCopasiObject::getObjectName(), CFunctionParameters::getParameterByUsage(), CFunctionParameter::getType(), CReadConfig::getVariable(), loadOneRole(), mMap, CFunctionParameter::MODIFIER, CFunctionParameter::PARAMETER, CFunctionParameter::PRODUCT, setParameterValue(), StringPrint(), and CFunctionParameter::SUBSTRATE.

Referenced by load().

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 }
const CFunctionParameter::DataType & getType() const
const std::string & getObjectName() const
void setParameterValue(const std::string &parameterName, const C_FLOAT64 &value, const bool &updateStatus=true)
Definition: CReaction.cpp:303
#define fatalError()
const CFunctionParameters & getFunctionParameters() const
size_t getNumberOfParametersByUsage(CFunctionParameter::Role usage) const
#define C_INT32
Definition: copasi.h:90
CFunctionParameterMap mMap
Definition: CReaction.h:599
const CFunctionParameter * getParameterByUsage(CFunctionParameter::Role usage, size_t &pos) const
#define C_FLOAT64
Definition: copasi.h:92
std::string StringPrint(const char *format,...)
Definition: utility.cpp:87
bool loadOneRole(CReadConfig &configbuffer, CFunctionParameter::Role role, C_INT32 n, const std::string &prefix)
Definition: CReaction.cpp:668
C_INT32 getVariable(const std::string &name, const std::string &type, void *pout, CReadConfig::Mode mode=CReadConfig::NEXT)
Definition: CReadConfig.cpp:81
bool CReaction::loadOneRole ( CReadConfig configbuffer,
CFunctionParameter::Role  role,
C_INT32  n,
const std::string &  prefix 
)
private

Used for loading Gepasi files. Loads the mapping for one role

Definition at line 668 of file CReaction.cpp.

References CChemEq::addMetabolite(), addParameterMapping(), C_INT32, clearParameterMapping(), fatalError, CModel::findMetabByName(), CFunctionParameterMap::getFunctionParameters(), CCopasiObject::getKey(), CModel::getMetabolites(), CFunctionParameters::getNumberOfParametersByUsage(), CCopasiObject::getObjectAncestor(), CCopasiObject::getObjectDataModel(), CCopasiObject::getObjectName(), CFunctionParameters::getParameterByUsage(), CFunctionParameter::getType(), CReadConfig::getVariable(), CFunctionParameters::isVector(), mChemEq, mMap, CChemEq::MODIFIER, CFunctionParameter::MODIFIER, CCopasiDataModel::pOldMetabolites, setParameterMapping(), StringPrint(), and CFunctionParameter::VINT32.

Referenced by loadOld().

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 }
CCopasiDataModel * getObjectDataModel()
CCopasiContainer * getObjectAncestor(const std::string &type) const
const CFunctionParameter::DataType & getType() const
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
const std::string & getObjectName() const
bool isVector(CFunctionParameter::Role role) const
#define fatalError()
const CFunctionParameters & getFunctionParameters() const
size_t getNumberOfParametersByUsage(CFunctionParameter::Role usage) const
void clearParameterMapping(const std::string &parameterName)
Definition: CReaction.cpp:407
#define C_INT32
Definition: copasi.h:90
virtual const std::string & getKey() const
CChemEq mChemEq
Definition: CReaction.h:558
size_t findMetabByName(const std::string &Target) const
Definition: CModel.cpp:1198
CFunctionParameterMap mMap
Definition: CReaction.h:599
const CFunctionParameter * getParameterByUsage(CFunctionParameter::Role usage, size_t &pos) const
bool addMetabolite(const std::string &key, const C_FLOAT64 multiplicity, const MetaboliteRole &role)
Definition: CChemEq.cpp:80
void setParameterMapping(const size_t &index, const std::string &key)
Definition: CReaction.cpp:339
std::string StringPrint(const char *format,...)
Definition: utility.cpp:87
Definition: CModel.h:50
C_INT32 getVariable(const std::string &name, const std::string &type, void *pout, CReadConfig::Mode mode=CReadConfig::NEXT)
Definition: CReadConfig.cpp:81
CCopasiVectorS< CMetabOld > * pOldMetabolites
void addParameterMapping(const size_t &index, const std::string &key)
Definition: CReaction.cpp:348
bool CReaction::mustBeDeleted ( const DataObjectSet deletedObjects) const
virtual

Check whether an object must be deleted because its prerequisites can no longer be fulfilled due to the given deleted objects

Parameters
constDataObjectSet & deletedObjects
Returns
bool mustBeDeleted

Reimplemented from CCopasiObject.

Definition at line 981 of file CReaction.cpp.

References CCopasiParameterGroup::beginIndex(), CCopasiParameterGroup::endIndex(), isLocalParameter(), mParameters, mpFluxReference, and mpParticleFluxReference.

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 }
CCopasiParameterGroup mParameters
Definition: CReaction.h:610
CCopasiObjectReference< C_FLOAT64 > * mpFluxReference
Definition: CReaction.h:569
bool isLocalParameter(const size_t &index) const
Definition: CReaction.cpp:449
index_iterator endIndex() const
index_iterator beginIndex() const
parameterGroup::iterator index_iterator
std::set< const CCopasiObject * > DataObjectSet
CCopasiObjectReference< C_FLOAT64 > * mpParticleFluxReference
Definition: CReaction.h:575
CEvaluationNodeVariable * CReaction::object2variable ( const CEvaluationNodeObject objectNode,
std::map< std::string, std::pair< CCopasiObject *, CFunctionParameter * > > &  replacementMap,
std::map< CCopasiObject *, SBase * > &  copasi2sbmlmap 
)
private

Converts a single object node to a variable node. The usage term of the variable nodes is recorded in terms of CFunctionParameters that are stored in the replacementMap. On failure a NULL pointer is returned.

Definition at line 1076 of file CReaction.cpp.

References CEvaluationNodeVariable::ANY, CCopasiMessage::ERROR, escapeId(), CCopasiMessage::EXCEPTION, CFunctionParameter::FLOAT64, getChemEq(), CEvaluationNodeObject::getData(), CChemEq::getModifiers(), CCopasiObject::getObjectAncestor(), CCopasiObject::getObjectDataModel(), CCopasiObject::getObjectParent(), CChemEq::getProducts(), getSBMLId(), CChemEq::getSubstrates(), MCReaction, MCSBML, CFunctionParameter::MODIFIER, CCopasiDataModel::ObjectFromName(), CFunctionParameter::PARAMETER, CFunctionParameter::PRODUCT, CCopasiVector< T >::size(), CFunctionParameter::SUBSTRATE, CFunctionParameter::TIME, and CFunctionParameter::VOLUME.

Referenced by objects2variables().

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 }
CCopasiDataModel * getObjectDataModel()
CCopasiContainer * getObjectAncestor(const std::string &type) const
virtual size_t size() const
Definition: CMetab.h:178
const std::string & getSBMLId() const
Definition: CReaction.cpp:1654
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
#define MCSBML
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
#define MCReaction
const CCopasiVector< CChemEqElement > & getModifiers() const
Definition: CChemEq.cpp:66
Definition: CModel.h:50
std::string escapeId(const std::string &id)
Definition: CReaction.cpp:1659
virtual const Data & getData() const
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
const CChemEq & getChemEq() const
Definition: CReaction.cpp:223
CCopasiContainer * getObjectParent() const
CEvaluationNode * CReaction::objects2variables ( const CEvaluationNode expression,
std::map< std::string, std::pair< CCopasiObject *, CFunctionParameter * > > &  replacementMap,
std::map< CCopasiObject *, SBase * > &  copasi2sbmlmap 
)
private

Replaces all object nodes in an expression tree by variable nodes. The usage term of the variable nodes is recorded in terms of CFunctionParameters that are stored in the replacementMap. On failure a NULL pointer is returned.

Definition at line 1285 of file CReaction.cpp.

References CNodeContextIterator< Node, Context >::context(), CEvaluationNode::copyNode(), CNodeContextIterator< Node, Context >::end(), CCopasiMessage::ERROR, fatalError, CEvaluationNode::getType(), CEvaluationNode::INVALID, MCReaction, CEvaluationNode::MV_FUNCTION, CNodeContextIterator< Node, Context >::next(), CEvaluationNode::OBJECT, object2variable(), CNodeContextIterator< Node, Context >::parentContextPtr(), pResult, CEvaluationNode::STRUCTURE, CEvaluationNode::type(), and CEvaluationNode::VARIABLE.

Referenced by setFunctionFromExpressionTree().

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 }
CEvaluationNode * copyNode(CEvaluationNode *child1, CEvaluationNode *child2) const
#define fatalError()
CEvaluationNodeVariable * object2variable(const CEvaluationNodeObject *objectNode, std::map< std::string, std::pair< CCopasiObject *, CFunctionParameter * > > &replacementMap, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap)
Definition: CReaction.cpp:1076
static Type type(const Type &type)
#define MCReaction
const CArrayAnnotation * pResult
CReaction& CReaction::operator= ( const CReaction )
private
void CReaction::printDebug ( ) const

Definition at line 1700 of file CReaction.cpp.

1701 {}
void CReaction::setFast ( const bool &  fast)

Set whether the reaction is to be treated as fast

Parameters
constbool & fast

Definition at line 1703 of file CReaction.cpp.

References mFast.

Referenced by ReactionsWidget1::saveToReaction(), and CCopasiXMLParser::ReactionElement::start().

1704 {
1705  mFast = fast;
1706 }
bool mFast
Definition: CReaction.h:623
bool CReaction::setFunction ( const std::string &  functionName)

Sets the rate function of the reaction

Parameters
conststring & functionName
Returns
bool success

Definition at line 255 of file CReaction.cpp.

References CCopasiMessage::ERROR, CFunctionDB::findLoadFunction(), CCopasiRootContainer::getFunctionList(), and MCReaction.

Referenced by CModelAdd::addReactions(), CModel::convert2NonReversible(), CReaction(), SBMLImporter::createCReactionFromReaction(), CModelExpansion::createDiffusionReaction(), CModelExpansion::duplicateReaction(), CCopasiXMLParser::KineticLawElement::end(), load(), setFunctionFromExpressionTree(), test000058::test_bug1025_1(), test000058::test_bug1025_6(), test000059::test_unique_id_10(), test000059::test_unique_id_13(), test000059::test_unique_id_15(), test000059::test_unique_id_16(), test000059::test_unique_id_4(), test000059::test_unique_id_7(), test000059::test_unique_id_9(), and CReactionInterface::writeBackToReaction().

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 }
CFunction * findLoadFunction(const std::string &functionName)
bool setFunction(const std::string &functionName)
Definition: CReaction.cpp:255
static CFunctionDB * getFunctionList()
#define MCReaction
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
bool CReaction::setFunction ( CFunction pFunction)

Sets the rate function of the reaction

Parameters
CFunction* pFunction
Returns
bool success

Definition at line 266 of file CReaction.cpp.

References CCopasiObject::addDirectDependency(), CCopasiRootContainer::getUndefinedFunction(), CFunction::getVariables(), CFunctionParameterMap::initializeFromFunctionParameters(), initializeMetaboliteKeyMap(), initializeParameters(), mMap, mpFunction, and CCopasiObject::removeDirectDependency().

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 }
static CFunction * getUndefinedFunction()
CFunction * mpFunction
Definition: CReaction.h:563
void addDirectDependency(const CCopasiObject *pObject)
CFunctionParameterMap mMap
Definition: CReaction.h:599
void initializeFromFunctionParameters(const CFunctionParameters &src)
void removeDirectDependency(const CCopasiObject *pObject)
void initializeParameters()
Definition: CReaction.cpp:509
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
void initializeMetaboliteKeyMap()
Definition: CReaction.cpp:558
CFunction * CReaction::setFunctionFromExpressionTree ( const CExpression tree,
std::map< CCopasiObject *, SBase * > &  copasi2sbmlmap,
CFunctionDB pFunctionDB 
)

Converts an expression tree into a CFunction object and sets the mapping for the reaction.

Definition at line 1343 of file CReaction.cpp.

References CFunctionDB::add(), CCopasiObject::addDirectDependency(), CFunction::addVariable(), SBMLImporter::areEqualFunctions(), CEvaluationTree::compile(), CEvaluationNode::copyBranch(), CFunctionDB::findFunction(), CCopasiObject::getObjectName(), CEvaluationTree::getRoot(), CFunctionParameter::getType(), CFunctionParameter::getUsage(), CFunction::getVariables(), CFunction::isReversible(), isReversible(), mpFunction, objects2variables(), pdelete, CCopasiObject::removeDirectDependency(), setFunction(), CCopasiObject::setObjectName(), setParameterMapping(), CFunction::setReversible(), CEvaluationTree::setRoot(), TriFalse, and TriTrue.

Referenced by SBMLImporter::createCReactionFromReaction().

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 }
virtual bool setRoot(CEvaluationNode *pRootNode)
CEvaluationNode * copyBranch() const
#define pdelete(p)
Definition: copasi.h:215
const CFunctionParameter::DataType & getType() const
CFunction * mpFunction
Definition: CReaction.h:563
const std::string & getObjectName() const
CEvaluationNode * objects2variables(const CEvaluationNode *expression, std::map< std::string, std::pair< CCopasiObject *, CFunctionParameter * > > &replacementMap, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap)
Definition: CReaction.cpp:1285
bool addVariable(const std::string &name, CFunctionParameter::Role usage=CFunctionParameter::VARIABLE, const CFunctionParameter::DataType &type=CFunctionParameter::FLOAT64)
Definition: CFunction.cpp:154
void setReversible(const TriLogic &reversible)
Definition: CFunction.cpp:142
void addDirectDependency(const CCopasiObject *pObject)
const TriLogic & isReversible() const
Definition: CFunction.cpp:145
bool setFunction(const std::string &functionName)
Definition: CReaction.cpp:255
static bool areEqualFunctions(const CFunction *pFun, const CFunction *pFun2)
bool isReversible() const
Definition: CReaction.cpp:229
void setParameterMapping(const size_t &index, const std::string &key)
Definition: CReaction.cpp:339
void removeDirectDependency(const CCopasiObject *pObject)
virtual bool compile()
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
bool setObjectName(const std::string &name)
CFunction * findFunction(const std::string &functionName)
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
bool add(CFunction *pFunction, const bool &adopt)
bool CReaction::setObjectParent ( const CCopasiContainer pParent)
virtual

Sets the parent of the metabolite;

Parameters
constCCopasiContainer * pParent
Returns
bool success

Reimplemented from CCopasiObject.

Definition at line 141 of file CReaction.cpp.

References CCopasiObject::setObjectParent().

142 {
143  bool success = CCopasiContainer::setObjectParent(pParent);
144 
145  return success;
146 }
virtual bool setObjectParent(const CCopasiContainer *pParent)
void CReaction::setParameterMapping ( const size_t &  index,
const std::string &  key 
)

Sets a parameter mapping for the indexed parameter.

Parameters
constsize_t & index
conststd::string & key

Definition at line 339 of file CReaction.cpp.

References fatalError, CFunctionParameter::FLOAT64, getFunctionParameters(), mMetabKeyMap, and mpFunction.

Referenced by CModelAdd::addReactions(), CFixLocalReactionParameters::changeModel(), CModel::convert2NonReversible(), CModelExpansion::createDiffusionReaction(), SBMLImporter::doMapping(), CModelExpansion::duplicateReaction(), loadOneRole(), setFunctionFromExpressionTree(), CModelParameter::updateModel(), and CReactionInterface::writeBackToReaction().

340 {
341  if (!mpFunction) fatalError();
342 
343  if (getFunctionParameters()[index]->getType() != CFunctionParameter::FLOAT64) fatalError(); //wrong data type
344 
345  mMetabKeyMap[index][0] = key;
346 }
CFunction * mpFunction
Definition: CReaction.h:563
#define fatalError()
const CFunctionParameters & getFunctionParameters() const
Definition: CReaction.cpp:576
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
bool CReaction::setParameterMapping ( const std::string &  parameterName,
const std::string &  key 
)

Sets a parameter mapping for the named parameter.

Parameters
conststd::string & parameterName
conststd::string & key
Returns
bool success

Definition at line 357 of file CReaction.cpp.

References C_INVALID_INDEX, fatalError, CFunctionParameter::FLOAT64, getParameterIndex(), mMetabKeyMap, and mpFunction.

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 }
CFunction * mpFunction
Definition: CReaction.h:563
#define fatalError()
#define C_INVALID_INDEX
Definition: copasi.h:222
size_t getParameterIndex(const std::string &parameterName, CFunctionParameter::DataType *pType=NULL) const
Definition: CReaction.cpp:292
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
void CReaction::setParameterMappingVector ( const std::string &  parameterName,
const std::vector< std::string > &  keys 
)

Set the mapping for the name parameter which must be of type vector

Parameters
conststd::string & parameterName
conststd::vector<std::string> & keys

Definition at line 390 of file CReaction.cpp.

References C_INVALID_INDEX, fatalError, CFunctionParameter::FLOAT64, getParameterIndex(), mMetabKeyMap, and mpFunction.

Referenced by CModel::convert2NonReversible(), and CCopasiXMLParser::KineticLawElement::end().

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 }
CFunction * mpFunction
Definition: CReaction.h:563
#define fatalError()
#define C_INVALID_INDEX
Definition: copasi.h:222
size_t getParameterIndex(const std::string &parameterName, CFunctionParameter::DataType *pType=NULL) const
Definition: CReaction.cpp:292
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
void CReaction::setParameterValue ( const std::string &  parameterName,
const C_FLOAT64 value,
const bool &  updateStatus = true 
)

Sets a parameter value if updateStatus==true the status is also updated to make sure the value is actually used (instead of a global value that may have been used before). if updateStatus==false only the value of the local parameter is set, even if it is not used

Parameters
conststd::string & parameterName
constC_FLOAT64 & value
constbool & updateStatus (default: true(

Definition at line 303 of file CReaction.cpp.

References C_INVALID_INDEX, fatalError, CFunctionParameter::FLOAT64, getFunctionParameters(), CCopasiParameter::getKey(), CCopasiParameterGroup::getParameter(), getParameterIndex(), mMetabKeyMap, mParameters, mpFunction, and CCopasiParameterGroup::setValue().

Referenced by CModelAdd::addReactions(), CModel::convert2NonReversible(), CModelExpansion::duplicateReaction(), loadOld(), test000058::test_bug1025_1(), test000058::test_bug1025_6(), test000059::test_unique_id_10(), test000059::test_unique_id_13(), test000059::test_unique_id_15(), test000059::test_unique_id_16(), test000059::test_unique_id_4(), test000059::test_unique_id_7(), test000059::test_unique_id_9(), and CReactionInterface::writeBackToReaction().

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 }
CCopasiParameterGroup mParameters
Definition: CReaction.h:610
CFunction * mpFunction
Definition: CReaction.h:563
#define fatalError()
#define C_INVALID_INDEX
Definition: copasi.h:222
const CFunctionParameters & getFunctionParameters() const
Definition: CReaction.cpp:576
size_t getParameterIndex(const std::string &parameterName, CFunctionParameter::DataType *pType=NULL) const
Definition: CReaction.cpp:292
virtual const std::string & getKey() const
bool setValue(const std::string &name, const CType &value)
CCopasiParameter * getParameter(const std::string &name)
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
void CReaction::setReversible ( bool  reversible)

Sets whether the reaction is reversible

Parameters
boolreversible

Definition at line 247 of file CReaction.cpp.

References mChemEq, and CChemEq::setReversibility().

Referenced by CModelAdd::addReactions(), CModel::convert2NonReversible(), SBMLImporter::createCReactionFromReaction(), CModelExpansion::createDiffusionReaction(), CModelExpansion::duplicateReaction(), and CCopasiXMLParser::ReactionElement::start().

248 {mChemEq.setReversibility(reversible);}
CChemEq mChemEq
Definition: CReaction.h:558
void setReversibility(const bool &reversible)
Definition: CChemEq.cpp:72
void CReaction::setSBMLId ( const std::string &  id)

Sets the SBMLId.

Definition at line 1649 of file CReaction.cpp.

References mSBMLId.

Referenced by SBMLImporter::createCReactionFromReaction(), CSBMLExporter::createReaction(), CCopasiXMLParser::ReactionElement::start(), and CCopasiXMLParser::SBMLMapElement::start().

1650 {
1651  this->mSBMLId = id;
1652 }
std::string mSBMLId
Definition: CReaction.h:617
void CReaction::setScalingFactor ( )
private

Sets the scaling factor of the for the fluxes

Definition at line 879 of file CReaction.cpp.

References C_FLOAT64, CCopasiMessage::ERROR, CMetab::getCompartment(), getCompartmentNumber(), CCopasiObject::getDirectDependencies(), CCopasiException::getMessage(), CCopasiMessage::getNumber(), CCopasiObject::getObjectAncestor(), CCopasiObject::getObjectName(), CChemEq::getProducts(), CModel::getQuantity2NumberFactor(), CChemEq::getSubstrates(), CModelEntity::getValuePointer(), CModelEntity::getValueReference(), MCChemEq, mChemEq, MCReaction, mDefaultScalingFactor, mpFluxReference, mpParticleFluxReference, mScalingFactor, mUnitScalingFactor, CCopasiObject::setDirectDependencies(), and CCopasiVector< T >::size().

Referenced by compile().

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 }
CCopasiContainer * getObjectAncestor(const std::string &type) const
CCopasiObjectReference< C_FLOAT64 > * mpFluxReference
Definition: CReaction.h:569
#define MCChemEq
const std::string & getObjectName() const
virtual size_t size() const
const CCopasiMessage & getMessage() const
void setDirectDependencies(const DataObjectSet &directDependencies)
const size_t & getNumber() const
Definition: CMetab.h:178
const C_FLOAT64 * mUnitScalingFactor
Definition: CReaction.h:593
CChemEq mChemEq
Definition: CReaction.h:558
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
const C_FLOAT64 & getQuantity2NumberFactor() const
Definition: CModel.cpp:2354
virtual void * getValuePointer() const
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
#define MCReaction
virtual const DataObjectSet & getDirectDependencies(const DataObjectSet &context=DataObjectSet()) const
const C_FLOAT64 * mScalingFactor
Definition: CReaction.h:588
#define C_FLOAT64
Definition: copasi.h:92
size_t getCompartmentNumber() const
Definition: CReaction.cpp:873
Definition: CModel.h:50
static C_FLOAT64 mDefaultScalingFactor
Definition: CReaction.h:553
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
CCopasiObjectReference< C_FLOAT64 > * mpParticleFluxReference
Definition: CReaction.h:575
CCopasiObject * getValueReference() const
CEvaluationNodeObject * CReaction::variable2object ( CEvaluationNodeVariable pVariableNode)
private

Converts a single variable node to an object node. On failure a NULL pointer is returned.

Definition at line 1614 of file CReaction.cpp.

References C_INVALID_INDEX, CEvaluationNodeObject::CN, CCopasiMessage::EXCEPTION, CFunctionParameters::findParameterByName(), CKeyFactory::get(), CCopasiObject::getCN(), CCopasiNode< _Data >::getData(), getFunction(), CCopasiRootContainer::getKeyFactory(), getParameterMappings(), CFunction::getVariables(), MCReaction, CFunctionParameter::VFLOAT64, and CFunctionParameter::VINT32.

Referenced by variables2objects().

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 }
virtual CCopasiObjectName getCN() const
CCopasiObject * get(const std::string &key)
size_t findParameterByName(const std::string &name, CFunctionParameter::DataType &dataType) const
#define C_INVALID_INDEX
Definition: copasi.h:222
const CFunction * getFunction() const
Definition: CReaction.cpp:252
#define MCReaction
static CKeyFactory * getKeyFactory()
virtual const Data & getData() const
Definition: CCopasiNode.h:118
const std::vector< std::vector< std::string > > & getParameterMappings() const
Definition: CReaction.h:285
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
CEvaluationNode * CReaction::variables2objects ( CEvaluationNode expression)
private

Replaces all variable nodes in a function tree by object nodes. On failure a NULL pointer is returned.

Definition at line 1440 of file CReaction.cpp.

References CCopasiNode< _Data >::addChild(), CEvaluationNode::CALL, CEvaluationNode::CHOICE, CEvaluationNode::CONSTANT, CCopasiMessage::ERROR, CEvaluationNode::FUNCTION, CCopasiNode< _Data >::getChild(), CCopasiNode< _Data >::getData(), CCopasiNode< _Data >::getSibling(), CEvaluationNode::getType(), CEvaluationNode::INVALID, CEvaluationNode::LOGICAL, MCReaction, CEvaluationNode::MV_FUNCTION, CEvaluationNode::NUMBER, CEvaluationNode::OBJECT, CEvaluationNode::OPERATOR, CEvaluationNode::STRUCTURE, CEvaluationNode::subType(), CEvaluationNode::type(), CEvaluationNode::VARIABLE, variable2object(), and CEvaluationNode::WHITESPACE.

Referenced by getExpressionTree().

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 }
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
const Type & getType() const
static Type type(const Type &type)
CEvaluationNode * variables2objects(CEvaluationNode *expression)
Definition: CReaction.cpp:1440
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
#define MCReaction
static Type subType(const Type &type)
virtual const Data & getData() const
Definition: CCopasiNode.h:118
CEvaluationNodeObject * variable2object(CEvaluationNodeVariable *pVariableNode)
Definition: CReaction.cpp:1614
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const CReaction d 
)
friend

Friend declaration for ostream operator

Parameters
std::ostream& os
constCReaction & d
Returns
std::ostream & os

Definition at line 1029 of file CReaction.cpp.

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 }
CCopasiParameterGroup mParameters
Definition: CReaction.h:610
CFunction * mpFunction
Definition: CReaction.h:563
const std::string & getObjectName() const
const C_FLOAT64 * mUnitScalingFactor
Definition: CReaction.h:593
CChemEq mChemEq
Definition: CReaction.h:558
const C_FLOAT64 * mScalingFactor
Definition: CReaction.h:588
C_FLOAT64 mFlux
Definition: CReaction.h:568
std::vector< std::vector< std::string > > mMetabKeyMap
Definition: CReaction.h:605
std::string mSBMLId
Definition: CReaction.h:617

Member Data Documentation

CChemEq CReaction::mChemEq
private
C_FLOAT64 CReaction::mDefaultScalingFactor = 1.0
staticprivate

The default scaling factor of a reaction which is 1.

Definition at line 553 of file CReaction.h.

Referenced by setScalingFactor().

bool CReaction::mFast
private

This flag indicates whether the reaction is treated as fast. The interpretation of fast is up to to the integration algorithm.

Definition at line 623 of file CReaction.h.

Referenced by isFast(), and setFast().

C_FLOAT64 CReaction::mFlux
private

The flux of the reaction, as amount of substance/time

Definition at line 568 of file CReaction.h.

Referenced by calculate(), calculateFlux(), compile(), getFlux(), initObjects(), and operator<<().

CFunctionParameterMap CReaction::mMap
private

This describes the mapping of the species and parameters to the function parameters. Here are the pointers to the actual objects and values.

Definition at line 599 of file CReaction.h.

Referenced by calculate(), calculatePartialDerivative(), compile(), getCallParameters(), getFunctionParameters(), getParameterIndex(), initializeMetaboliteKeyMap(), initializeParameters(), loadOld(), loadOneRole(), and setFunction().

std::vector< std::vector< std::string > > CReaction::mMetabKeyMap
private

This describes the mapping of the species to the function parameters. Here the keys of the metabolites (as in the chemical equation) are stored.

Definition at line 605 of file CReaction.h.

Referenced by addParameterMapping(), clearParameterMapping(), compile(), getParameterMapping(), getParameterMappings(), initializeMetaboliteKeyMap(), initializeParameters(), isLocalParameter(), operator<<(), setParameterMapping(), setParameterMappingVector(), and setParameterValue().

CCopasiParameterGroup CReaction::mParameters
private
C_FLOAT64 CReaction::mParticleFlux
private

The scaled flux of the reaction, as particle number/time

Definition at line 574 of file CReaction.h.

Referenced by calculate(), calculateParticleFlux(), compile(), getParticleFlux(), and initObjects().

CCopasiObjectReference<C_FLOAT64>* CReaction::mpFluxReference
private
CFunction* CReaction::mpFunction
private
CCopasiObjectReference<C_FLOAT64>* CReaction::mpParticleFluxReference
private
CCopasiObjectReference<C_FLOAT64>* CReaction::mpPropensityReference
private

Definition at line 581 of file CReaction.h.

Referenced by getPropensityReference(), and initObjects().

C_FLOAT64 CReaction::mPropensity
private

The propensity of the reaction

Definition at line 580 of file CReaction.h.

Referenced by initObjects().

std::string CReaction::mSBMLId
private

The id of the corresponding reaction in an SBML file. This value is either set upon importing an SBML file, or when the object is first exported to an SBML file.

Definition at line 617 of file CReaction.h.

Referenced by getSBMLId(), operator<<(), and setSBMLId().

const C_FLOAT64* CReaction::mScalingFactor
private

A pointer to the scaling factor for the flux to calculate the particle number changes. For a single compartment reaction this is the volume of the compartment

Definition at line 588 of file CReaction.h.

Referenced by calculate(), calculatePartialDerivative(), operator<<(), and setScalingFactor().

const C_FLOAT64* CReaction::mUnitScalingFactor
private

The unit conversion factor

Definition at line 593 of file CReaction.h.

Referenced by calculate(), operator<<(), and setScalingFactor().


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