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

#include <CModel.h>

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

Public Types

enum  AreaUnit {
  dimensionlessArea = 0, m2, dm2, cm2,
  mm2, microm2, nm2, pm2,
  fm2
}
 
enum  DependencyType { initial = 0, transient, physical }
 
enum  LengthUnit {
  dimensionlessLength = 0, m, dm, cm,
  mm, microm, nm, pm,
  fm
}
 
enum  ModelType { deterministic = 0, stochastic }
 
enum  QuantityUnit {
  dimensionlessQuantity = 0, Mol, mMol, microMol,
  nMol, pMol, fMol, number,
  OldXML
}
 
enum  TimeUnit {
  dimensionlessTime = 0, d, h, min,
  s, ms, micros, ns,
  ps, fs, OldMinute
}
 
enum  VolumeUnit {
  dimensionlessVolume = 0, m3, l, ml,
  microl, nl, pl, fl
}
 
- Public Types inherited from CModelEntity
enum  Status {
  FIXED = 0, ASSIGNMENT, REACTIONS, ODE,
  TIME
}
 
- 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
 

Public Member Functions

bool appendDependentModelObjects (const std::set< const CCopasiObject * > &candidates, std::set< const CCopasiObject * > &dependentReactions, std::set< const CCopasiObject * > &dependentMetabolites, std::set< const CCopasiObject * > &dependentCompartments, std::set< const CCopasiObject * > &dependentModelValues, std::set< const CCopasiObject * > &dependentEvents) const
 
bool appendDependentReactions (std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependents) const
 
void applyActiveParameterSet ()
 
void applyInitialValues ()
 
bool buildDependencyGraphs ()
 
std::vector< Refresh * > buildInitialRefreshSequence (std::set< const CCopasiObject * > &changedObjects)
 
void buildLinkZero ()
 
void buildMoieties ()
 
void buildRedStoi ()
 
void buildStoi ()
 
void calculateDerivatives (C_FLOAT64 *derivatives)
 
void calculateDerivativesX (C_FLOAT64 *derivativesX)
 
C_FLOAT64 calculateDivergence () const
 
void calculateElasticityMatrix (const C_FLOAT64 &factor, const C_FLOAT64 &resolution)
 
void calculateJacobian (CMatrix< C_FLOAT64 > &jacobian, const C_FLOAT64 &derivationFactor, const C_FLOAT64 &resolution)
 
void calculateJacobianX (CMatrix< C_FLOAT64 > &jacobianX, const C_FLOAT64 &derivationFactor, const C_FLOAT64 &resolution)
 
void calculateRootDerivatives (CVector< C_FLOAT64 > &rootDerivatives)
 
 CModel (CCopasiContainer *pParent)
 
bool compileIfNecessary (CProcessReport *pProcessReport)
 
bool convert2NonReversible ()
 
CCompartmentcreateCompartment (const std::string &name, const C_FLOAT64 &volume=1.0)
 
CEventcreateEvent (const std::string &name)
 
CMetabcreateMetabolite (const std::string &name, const std::string &compartment, const C_FLOAT64 &iconc=1.0, const CModelEntity::Status &status=CModelEntity::REACTIONS)
 
CModelValuecreateModelValue (const std::string &name, const C_FLOAT64 &value=0.0)
 
CReactioncreateReaction (const std::string &name)
 
void evaluateRoots (CVectorCore< C_FLOAT64 > &rootValues, const bool &ignoreDiscrete)
 
size_t findMetabByName (const std::string &Target) const
 
size_t findMoiety (const std::string &Target) const
 
bool forceCompile (CProcessReport *pProcessReport)
 
CModel::AreaUnit getAreaUnitEnum () const
 
std::string getAreaUnitName () const
 
std::string getAreaUnitsDisplayString () const
 
const C_FLOAT64getAvogadro () const
 
virtual std::string getChildObjectUnits (const CCopasiObject *pObject) const
 
CCopasiVectorNS< CCompartment > & getCompartments ()
 
const CCopasiVectorNS
< CCompartment > & 
getCompartments () const
 
std::string getConcentrationRateUnitsDisplayString () const
 
std::string getConcentrationUnitsDisplayString () const
 
CCopasiObjectgetCorrespondingTransientObject (const CCopasiObject *pObject) const
 
CCopasiVectorN< CEvent > & getEvents ()
 
const CCopasiVectorN< CEvent > & getEvents () const
 
std::string getFrequencyUnitsDisplayString () const
 
const CStategetInitialState () const
 
const C_FLOAT64getInitialTime () const
 
bool getInitialUpdateSequence (const CMath::SimulationContextFlag &context, const CCopasiObject::DataObjectSet &changedObjects, const CCopasiObject::DataObjectSet &requestedObjects, CCopasiObject::DataUpdateSequence &updateSequence) const
 
const std::string & getKey () const
 
const CLinkMatrixViewgetL () const
 
const CLinkMatrixgetL0 () const
 
CModel::LengthUnit getLengthUnitEnum () const
 
std::string getLengthUnitName () const
 
std::string getLengthUnitsDisplayString () const
 
const std::vector< Refresh * > & getListOfConstantRefreshes () const
 
const std::vector< Refresh * > & getListOfInitialRefreshes () const
 
const std::vector< Refresh * > & getListOfNonSimulatedRefreshes () const
 
const std::vector< Refresh * > & getListOfSimulatedRefreshes () const
 
const CMathModelgetMathModel () const
 
CMathModelgetMathModel ()
 
const CCopasiVector< CMetab > & getMetabolites () const
 
CCopasiVector< CMetab > & getMetabolites ()
 
const CCopasiVector< CMetab > & getMetabolitesX () const
 
CCopasiVector< CMetab > & getMetabolitesX ()
 
const CModelParameterSetgetModelParameterSet () const
 
CModelParameterSetgetModelParameterSet ()
 
const CCopasiVectorN
< CModelParameterSet > & 
getModelParameterSets () const
 
CCopasiVectorN
< CModelParameterSet > & 
getModelParameterSets ()
 
const ModelTypegetModelType () const
 
const CCopasiVectorN
< CModelValue > & 
getModelValues () const
 
CCopasiVectorN< CModelValue > & getModelValues ()
 
const CCopasiVector< CMoiety > & getMoieties () const
 
size_t getNumAssignmentMetabs () const
 
const C_FLOAT64getNumber2QuantityFactor () const
 
size_t getNumDependentReactionMetabs () const
 
size_t getNumIndependentReactionMetabs () const
 
size_t getNumMetabs () const
 
size_t getNumModelValues () const
 
size_t getNumODEMetabs () const
 
size_t getNumRoots () const
 
size_t getNumVariableMetabs () const
 
const CVector< C_FLOAT64 > & getParticleFlux () const
 
const C_FLOAT64getProcessQueueExecutionTime () const
 
const C_FLOAT64getQuantity2NumberFactor () const
 
std::string getQuantityRateUnitsDisplayString () const
 
CModel::QuantityUnit getQuantityUnitEnum () const
 
std::string getQuantityUnitName () const
 
std::string getQuantityUnitOldXMLName () const
 
std::string getQuantityUnitsDisplayString () const
 
CCopasiVectorNS< CReaction > & getReactions ()
 
const CCopasiVectorNS
< CReaction > & 
getReactions () const
 
const CMatrix< C_FLOAT64 > & getRedStoi () const
 
const CVector
< CMathTrigger::CRootFinder * > & 
getRootFinders () const
 
const CStategetState () const
 
const CStateTemplategetStateTemplate () const
 
CStateTemplategetStateTemplate ()
 
const CMatrix< C_FLOAT64 > & getStoi () const
 
const C_FLOAT64getTime () const
 
CModel::TimeUnit getTimeUnitEnum () const
 
std::string getTimeUnitName () const
 
std::string getTimeUnitsDisplayString () const
 
size_t getTotSteps () const
 
bool getTransientUpdateSequence (const CMath::SimulationContextFlag &context, const CCopasiObject::DataObjectSet &changedObjects, const CCopasiObject::DataObjectSet &requestedObjects, CCopasiObject::DataUpdateSequence &updateSequence) const
 
std::vector< const
CEvaluationTree * > 
getTreesWithDiscontinuities () const
 
const std::set< const
CCopasiObject * > & 
getUptoDateObjects () const
 
std::string getVolumeRateUnitsDisplayString () const
 
CModel::VolumeUnit getVolumeUnitEnum () const
 
std::string getVolumeUnitName () const
 
std::string getVolumeUnitsDisplayString () const
 
bool hasReversibleReaction () const
 
CVector< C_FLOAT64initializeAtolVector (const C_FLOAT64 &baseTolerance, const bool &reducedModel) const
 
void initializeMetabolites ()
 
const bool & isAutonomous () const
 
bool isStateVariable (const CCopasiObject *pObject) const
 
C_INT32 load (CReadConfig &configBuffer)
 
std::string printParameterOverview ()
 
bool processQueue (const C_FLOAT64 &time, const bool &equality, CProcessQueue::resolveSimultaneousAssignments pResolveSimultaneousAssignments)
 
void processRoots (const C_FLOAT64 &time, const bool &equality, const bool &correct, const CVector< C_INT > &roots)
 
void refreshActiveParameterSet ()
 
bool removeCompartment (const size_t index, const bool &recursive=true)
 
bool removeCompartment (const std::string &key, const bool &recursive=true)
 
bool removeCompartment (const CCompartment *pCompartment, const bool &recursive=true)
 
void removeDependentModelObjects (const std::set< const CCopasiObject * > &deletedObjects)
 
bool removeEvent (const size_t index, const bool &recursive=true)
 
bool removeEvent (const std::string &key, const bool &recursive=true)
 
bool removeEvent (const CEvent *pEvent, const bool &recursive=true)
 
bool removeLocalReactionParameter (const std::string &key, const bool &recursive=true)
 
bool removeMetabolite (const std::string &key, const bool &recursive=true)
 
bool removeMetabolite (const size_t index, const bool &recursive=true)
 
bool removeMetabolite (const CMetab *pMetabolite, const bool &recursive=true)
 
bool removeModelValue (const CModelValue *pModelValue, const bool &recursive=true)
 
bool removeModelValue (const std::string &key, const bool &recursive=true)
 
bool removeModelValue (const size_t index, const bool &recursive=true)
 
bool removeReaction (const CReaction *pReaction, const bool &recursive=true)
 
bool removeReaction (const std::string &key, const bool &recursive=true)
 
bool removeReaction (const size_t index, const bool &recursive=true)
 
bool setAreaUnit (const std::string &name)
 
bool setAreaUnit (const CModel::AreaUnit &unit)
 
void setAvogadro (const C_FLOAT64 &avogadro)
 
void setCompileFlag (bool flag=true)
 
void setInitialState (const CState &state)
 
void setInitialTime (const C_FLOAT64 &time)
 
bool setLengthUnit (const std::string &name)
 
bool setLengthUnit (const CModel::LengthUnit &unit)
 
void setModelType (const ModelType &modelType)
 
bool setQuantityUnit (const std::string &name)
 
bool setQuantityUnit (const CModel::QuantityUnit &unit)
 
void setState (const CState &state)
 
void setTime (const C_FLOAT64 &time)
 
bool setTimeUnit (const std::string &name)
 
bool setTimeUnit (const CModel::TimeUnit &unit)
 
bool setVolumeUnit (const std::string &name)
 
bool setVolumeUnit (const CModel::VolumeUnit &unit)
 
std::string suitableForStochasticSimulation () const
 
bool updateInitialValues ()
 
void updateInitialValues (std::set< const CCopasiObject * > &changedObjects)
 
void updateInitialValues (const CCopasiObject *changedObject)
 
void updateNonSimulatedValues (void)
 
void updateSimulatedValues (const bool &updateMoieties)
 
 ~CModel ()
 
- Public Member Functions inherited from CModelEntity
virtual void calculate ()
 
 CModelEntity (const std::string &name="NoName", const CCopasiContainer *pParent=NULL, const std::string &type="ModelEntity", const unsigned C_INT32 &flag=CCopasiObject::Container|CCopasiObject::ValueDbl)
 
 CModelEntity (const CModelEntity &src, const CCopasiContainer *pParent=NULL)
 
virtual std::set< const
CCopasiObject * > 
getDeletedObjects () const
 
std::string getExpression () const
 
const CExpressiongetExpressionPtr () const
 
CExpressiongetExpressionPtr ()
 
std::string getInitialExpression () const
 
const CExpressiongetInitialExpressionPtr () const
 
CExpressiongetInitialExpressionPtr ()
 
const C_FLOAT64getInitialValue () const
 
CCopasiObjectgetInitialValueReference () const
 
const C_FLOAT64getRate () const
 
CCopasiObjectgetRateReference () const
 
const std::string & getSBMLId () const
 
const CModelEntity::StatusgetStatus () const
 
const C_FLOAT64getValue () const
 
virtual const CCopasiObjectgetValueObject () const
 
virtual voidgetValuePointer () const
 
CCopasiObjectgetValueReference () const
 
bool isFixed () const
 
const bool & isUsed () const
 
virtual bool mustBeDeleted (const DataObjectSet &deletedObjects) const
 
virtual void refreshInitialValue ()
 
bool setExpression (const std::string &expression)
 
bool setExpressionPtr (CExpression *pExpression)
 
bool setInitialExpression (const std::string &expression)
 
bool setInitialExpressionPtr (CExpression *pExpression)
 
virtual void setInitialValue (const C_FLOAT64 &initialValue)
 
void setInitialValuePtr (C_FLOAT64 *pInitialValue)
 
virtual bool setObjectParent (const CCopasiContainer *pParent)
 
void setRate (const C_FLOAT64 &rate)
 
void setSBMLId (const std::string &id)
 
virtual void setStatus (const CModelEntity::Status &status)
 
void setUsed (const bool &used)
 
virtual void setValue (const C_FLOAT64 &value)
 
void setValuePtr (C_FLOAT64 *pValue)
 
 ~CModelEntity ()
 
- 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 CObjectInterfacegetObject (const CCopasiObjectName &cn) const
 
virtual const objectMapgetObjects () const
 
virtual std::string getUnits () 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
 
virtual std::string getObjectDisplayName (bool regular=true, bool richtext=false) const
 
const std::string & getObjectName () const
 
CCopasiContainergetObjectParent () const
 
const std::string & getObjectType () const
 
virtual const
CObjectInterface::ObjectSet
getPrerequisites () const
 
virtual RefreshgetRefresh () const
 
UpdateMethodgetUpdateMethod () 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 ()
 

Static Public Attributes

static const char * AreaUnitNames []
 
static const char * LengthUnitNames []
 
static const char * ModelTypeNames []
 
static const char * QuantityUnitNames []
 
static const char * QuantityUnitOldXMLNames []
 
static const char * TimeUnitNames []
 
static const char * VolumeUnitNames []
 
- Static Public Attributes inherited from CModelEntity
static const std::string StatusName []
 
static const char * XMLStatus []
 
- Static Public Attributes inherited from CCopasiContainer
static const std::vector
< CCopasiContainer * > 
EmptyList
 

Private Member Functions

bool appendDependentCompartments (std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependents) const
 
bool appendDependentEvents (std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependents) const
 
bool appendDependentMetabolites (std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependents) const
 
bool appendDependentModelValues (std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependents) const
 
bool buildApplyInitialValuesSequence ()
 
bool buildInitialSequence ()
 
bool buildNonSimulatedSequence ()
 
bool buildSimulatedSequence ()
 
bool buildStateTemplate ()
 
bool buildUserOrder ()
 
void clearMoieties ()
 
 CModel (const CModel &src)
 
bool compile ()
 
bool compileEvents ()
 
void determineIsAutonomous ()
 
bool getUpdateSequence (CMathDependencyGraph &dependencyGraph, const CMath::SimulationContextFlag &context, const CCopasiObject::DataObjectSet &changedObjects, const CCopasiObject::DataObjectSet &requestedObjects, CCopasiObject::DataUpdateSequence &updateSequence) const
 
bool handleUnusedMetabolites ()
 
void initObjects ()
 
CModeloperator= (const CModel &src)
 
void updateMatrixAnnotations ()
 
void updateMoietyValues ()
 

Private Attributes

std::string mActiveParameterSetKey
 
std::vector< Refresh * > mApplyInitialValuesRefreshes
 
AreaUnit mAreaUnit
 
C_FLOAT64 mAvogadro
 
bool mBuildInitialSequence
 
CCopasiVectorNS< CCompartmentmCompartments
 
bool mCompileIsNecessary
 
CState mCurrentState
 
CMatrix< C_FLOAT64mElasticities
 
CCopasiVectorN< CEventmEvents
 
CMathDependencyGraph mInitialDependencies
 
std::vector< Refresh * > mInitialRefreshes
 
CState mInitialState
 
bool mIsAutonomous
 
CVector< size_t > mJacobianPivot
 
CLinkMatrix mL
 
LengthUnit mLengthUnit
 
CLinkMatrixView mLView
 
CCopasiVector< CMetabmMetabolites
 
CCopasiVector< CMetabmMetabolitesX
 
CCopasiVector< CMoietymMoieties
 
std::vector< Refresh * > mNonSimulatedRefreshes
 
C_FLOAT64 mNumber2QuantityFactor
 
size_t mNumMetabolitesAssignment
 
size_t mNumMetabolitesODE
 
size_t mNumMetabolitesReaction
 
size_t mNumMetabolitesReactionIndependent
 
size_t mNumMetabolitesUnused
 
CModelParameterSet mParameterSet
 
CCopasiVectorN
< CModelParameterSet
mParameterSets
 
CVector< C_FLOAT64mParticleFluxes
 
CProcessReportmpCompileHandler
 
CMathDependencyGraph mPhysicalDependencies
 
CArrayAnnotationmpLinkMatrixAnnotation
 
CMathModelmpMathModel
 
CArrayAnnotationmpRedStoiAnnotation
 
CArrayAnnotationmpStoiAnnotation
 
C_FLOAT64 mQuantity2NumberFactor
 
QuantityUnit mQuantityUnit
 
CMatrix< C_FLOAT64mRedStoi
 
bool mReorderNeeded
 
std::vector< Refresh * > mSimulatedRefreshes
 
std::set< const CCopasiObject * > mSimulatedUpToDateObjects
 
CStateTemplate mStateTemplate
 
CCopasiVectorNS< CReactionmSteps
 
CMatrix< C_FLOAT64mStoi
 
CMatrix< C_FLOAT64mStoiInternal
 
TimeUnit mTimeUnit
 
CMathDependencyGraph mTransientDependencies
 
ModelType mType
 
CCopasiVectorN< CModelValuemValues
 
VolumeUnit mVolumeUnit
 

Additional Inherited Members

- 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)
 
- 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 CModelEntity
CExpressionmpExpression
 
CExpressionmpInitialExpression
 
C_FLOAT64mpIValue
 
CCopasiObjectReference
< C_FLOAT64 > * 
mpIValueReference
 
CModelmpModel
 
CCopasiObjectReference
< C_FLOAT64 > * 
mpRateReference
 
C_FLOAT64mpValue
 
CCopasiObjectReference
< C_FLOAT64 > * 
mpValueReference
 
C_FLOAT64 mRate
 
std::string mSBMLId
 
- 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 50 of file CModel.h.

Member Enumeration Documentation

Enum of valid area units

Enumerator
dimensionlessArea 
m2 
dm2 
cm2 
mm2 
microm2 
nm2 
pm2 
fm2 

Definition at line 66 of file CModel.h.

Enumerator
initial 
transient 
physical 

Definition at line 119 of file CModel.h.

119 {initial = 0, transient, physical};

Enum of valid length units

Enumerator
dimensionlessLength 
m 
dm 
cm 
mm 
microm 
nm 
pm 
fm 

Definition at line 76 of file CModel.h.

Enum of valid model types.

Enumerator
deterministic 
stochastic 

Definition at line 112 of file CModel.h.

Enum of valid quantity units

Enumerator
dimensionlessQuantity 
Mol 
mMol 
microMol 
nMol 
pMol 
fMol 
number 
OldXML 

Definition at line 96 of file CModel.h.

Enum of valid time units

Enumerator
dimensionlessTime 
d 
h 
min 
s 
ms 
micros 
ns 
ps 
fs 
OldMinute 

Definition at line 86 of file CModel.h.

Enum of valid volume units

Enumerator
dimensionlessVolume 
m3 
l 
ml 
microl 
nl 
pl 
fl 

Definition at line 56 of file CModel.h.

Constructor & Destructor Documentation

CModel::CModel ( const CModel src)
private

Copy constructor

Parameters
const CModel &src
CModel::CModel ( CCopasiContainer pParent)

constructor

Definition at line 90 of file CModel.cpp.

References compile(), CONSTRUCTOR_TRACE, forceCompile(), initializeMetabolites(), initObjects(), CModelEntity::mpIValue, CModelEntity::mpValue, mQuantityUnit, mSteps, mVolumeUnit, setQuantityUnit(), CModelEntity::setStatus(), CModelEntity::setUsed(), setVolumeUnit(), CCopasiVector< T >::size(), and CModelEntity::TIME.

90  :
91  CModelEntity("New Model", pParent, "Model"),
92  mInitialState(),
93  mCurrentState(),
94  mStateTemplate(*this, this->mInitialState, this->mCurrentState),
99 #ifdef USE_MATH_CONTAINER
100  mpMathContainer(NULL),
101 #endif // USE_MATH_CONTAINER
102  mVolumeUnit(ml),
103  mAreaUnit(m2),
104  mLengthUnit(m),
105  mTimeUnit(s),
108  mCompartments("Compartments", this),
109  mMetabolites("Metabolites", this),
110  mMetabolitesX("Reduced Model Metabolites", this),
111  mSteps("Reactions", this),
112  mEvents("Events", this),
113  mParticleFluxes(),
114  mValues("Values", this),
115  mParameterSet("Initial State", this),
116  mParameterSets("ParameterSets", this),
118  mMoieties("Moieties", this),
119  mStoiInternal(),
120  mpStoiAnnotation(NULL),
121  mStoi(),
122  mRedStoi(),
123  mpRedStoiAnnotation(NULL),
129  mL(),
131  mLView(mL),
132  mAvogadro(6.02214179e23),
135  mpCompileHandler(NULL),
140  mReorderNeeded(false),
141  mIsAutonomous(true),
142  mBuildInitialSequence(true),
143  mpMathModel(NULL)
144 {
145  initObjects();
146 
147  setStatus(TIME);
148  setUsed(true);
149 
150  *mpIValue = 0.0;
151  *mpValue = std::numeric_limits<C_FLOAT64>::quiet_NaN();
152 
153  size_t i, imax = mSteps.size();
154 
155  for (i = 0; i < imax; i++)
156  mSteps[i]->compile(/*mCompartments*/);
157 
159 
160  forceCompile(NULL);
161 
162  /* This following 2 lines added by Liang Xu
163  Because of the failure to initialize the parameter when creating a new models
164  */
165  setQuantityUnit(mQuantityUnit); // set the factors
166  setVolumeUnit(mVolumeUnit); // set the factors
167 
169 }
void initObjects()
Definition: CModel.cpp:3833
CArrayAnnotation * mpRedStoiAnnotation
Definition: CModel.h:1399
bool setVolumeUnit(const std::string &name)
Definition: CModel.cpp:2159
LengthUnit mLengthUnit
Definition: CModel.h:1304
CCopasiVectorN< CEvent > mEvents
Definition: CModel.h:1344
bool mIsAutonomous
Definition: CModel.h:1517
size_t mNumMetabolitesReactionIndependent
Definition: CModel.h:1441
virtual size_t size() const
C_FLOAT64 * mpValue
Definition: CModelValue.h:321
CModelParameterSet mParameterSet
Definition: CModel.h:1359
CCopasiVectorNS< CCompartment > mCompartments
Definition: CModel.h:1324
CLinkMatrixView mLView
Definition: CModel.h:1456
CMatrix< C_FLOAT64 > mStoi
Definition: CModel.h:1389
CMatrix< C_FLOAT64 > mRedStoi
Definition: CModel.h:1394
CLinkMatrix mL
Definition: CModel.h:1446
std::vector< Refresh * > mNonSimulatedRefreshes
Definition: CModel.h:1507
CCopasiVectorN< CModelValue > mValues
Definition: CModel.h:1354
C_FLOAT64 * mpIValue
Definition: CModelValue.h:326
size_t mNumMetabolitesUnused
Definition: CModel.h:1420
VolumeUnit mVolumeUnit
Definition: CModel.h:1294
CMathModel * mpMathModel
Definition: CModel.h:1532
CCopasiVector< CMetab > mMetabolites
Definition: CModel.h:1329
std::set< const CCopasiObject * > mSimulatedUpToDateObjects
Definition: CModel.h:1285
std::vector< Refresh * > mApplyInitialValuesRefreshes
Definition: CModel.h:1501
CStateTemplate mStateTemplate
Definition: CModel.h:1279
CArrayAnnotation * mpLinkMatrixAnnotation
Definition: CModel.h:1451
CVector< C_FLOAT64 > mParticleFluxes
Definition: CModel.h:1349
C_FLOAT64 mNumber2QuantityFactor
Definition: CModel.h:1473
bool mReorderNeeded
Definition: CModel.h:1512
bool compile()
Definition: CModel.cpp:381
virtual void setStatus(const CModelEntity::Status &status)
size_t mNumMetabolitesAssignment
Definition: CModel.h:1435
CCopasiVector< CMetab > mMetabolitesX
Definition: CModel.h:1334
std::vector< Refresh * > mInitialRefreshes
Definition: CModel.h:1490
void setUsed(const bool &used)
void initializeMetabolites()
Definition: CModel.cpp:942
QuantityUnit mQuantityUnit
Definition: CModel.h:1314
std::vector< Refresh * > mSimulatedRefreshes
Definition: CModel.h:1495
CState mInitialState
Definition: CModel.h:1272
CCopasiVectorN< CModelParameterSet > mParameterSets
Definition: CModel.h:1364
CMathDependencyGraph mTransientDependencies
Definition: CModel.h:1288
TimeUnit mTimeUnit
Definition: CModel.h:1309
bool mBuildInitialSequence
Definition: CModel.h:1523
CProcessReport * mpCompileHandler
Definition: CModel.h:1485
CMathDependencyGraph mInitialDependencies
Definition: CModel.h:1287
size_t mNumMetabolitesReaction
Definition: CModel.h:1430
std::string mActiveParameterSetKey
Definition: CModel.h:1369
CMatrix< C_FLOAT64 > mStoiInternal
Definition: CModel.h:1379
CCopasiVectorNS< CReaction > mSteps
Definition: CModel.h:1339
ModelType mType
Definition: CModel.h:1319
AreaUnit mAreaUnit
Definition: CModel.h:1299
bool setQuantityUnit(const std::string &name)
Definition: CModel.cpp:2250
CModelEntity(const std::string &name="NoName", const CCopasiContainer *pParent=NULL, const std::string &type="ModelEntity", const unsigned C_INT32 &flag=CCopasiObject::Container|CCopasiObject::ValueDbl)
Definition: CModelValue.cpp:62
C_FLOAT64 mAvogadro
Definition: CModel.h:1461
size_t mNumMetabolitesODE
Definition: CModel.h:1425
CArrayAnnotation * mpStoiAnnotation
Definition: CModel.h:1384
C_FLOAT64 mQuantity2NumberFactor
Definition: CModel.h:1467
CCopasiVector< CMoiety > mMoieties
Definition: CModel.h:1374
CMathDependencyGraph mPhysicalDependencies
Definition: CModel.h:1289
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202
CState mCurrentState
Definition: CModel.h:1274
bool forceCompile(CProcessReport *pProcessReport)
Definition: CModel.cpp:636
CModel::~CModel ( )

Destructor

Definition at line 227 of file CModel.cpp.

References DESTRUCTOR_TRACE, CCopasiRootContainer::getKeyFactory(), CAnnotation::mKey, CModelEntity::mpIValue, mpLinkMatrixAnnotation, mpRedStoiAnnotation, mpStoiAnnotation, CModelEntity::mpValue, pdelete, and CKeyFactory::remove().

228 {
229  mpIValue = NULL;
230  mpValue = NULL;
231 
235 
236 #ifdef USE_MATH_CONTAINER
237  pdelete(mpMathContainer);
238 #endif // USE_MATH_CONTAINER
239 
241 
243 }
bool remove(const std::string &key)
CArrayAnnotation * mpRedStoiAnnotation
Definition: CModel.h:1399
#define pdelete(p)
Definition: copasi.h:215
C_FLOAT64 * mpValue
Definition: CModelValue.h:321
C_FLOAT64 * mpIValue
Definition: CModelValue.h:326
std::string mKey
Definition: CAnnotation.h:119
#define DESTRUCTOR_TRACE
Definition: copasi.h:206
CArrayAnnotation * mpLinkMatrixAnnotation
Definition: CModel.h:1451
static CKeyFactory * getKeyFactory()
CArrayAnnotation * mpStoiAnnotation
Definition: CModel.h:1384

Member Function Documentation

bool CModel::appendDependentCompartments ( std::set< const CCopasiObject * >  candidates,
std::set< const CCopasiObject * > &  dependents 
) const
private

Appends pointers to compartments which are dependent on the candidates to the list.

Parameters
std::set<const CCopasiObject * > candidates
std::set<const CCopasiObject * > & dependents
Returns
bool objectsAppended

Definition at line 2538 of file CModel.cpp.

References CCopasiVector< T >::begin(), compileIfNecessary(), CCopasiVector< T >::end(), and mCompartments.

Referenced by appendDependentModelObjects(), convert2NonReversible(), and determineIsAutonomous().

2540 {
2541  const_cast< CModel * >(this)->compileIfNecessary(NULL);
2542 
2543  size_t Size = dependents.size();
2544 
2547 
2548  std::set< const CCopasiObject * >::const_iterator itSet;
2549  std::set< const CCopasiObject * >::const_iterator endSet;
2550 
2551  for (; it != end; ++it)
2552  {
2553  // Check whether the compartment is already in the list of deleted objects
2554  if (candidates.find(*it) == candidates.end())
2555  {
2556  if ((*it)->mustBeDeleted(candidates))
2557  {
2558  dependents.insert(*it);
2559  }
2560  }
2561  }
2562 
2563  return Size < dependents.size();
2564 }
iterator begin()
CCopasiVectorNS< CCompartment > mCompartments
Definition: CModel.h:1324
iterator end()
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
Definition: CModel.h:50
bool CModel::appendDependentEvents ( std::set< const CCopasiObject * >  candidates,
std::set< const CCopasiObject * > &  dependents 
) const
private

Appends a pointers to events which are dependent on the candidates to the list.

Parameters
std::set<const CCopasiObject * > candidates
std::set<const CCopasiObject * > & dependents
Returns
bool objectsAppended

Definition at line 2593 of file CModel.cpp.

References CCopasiVector< T >::begin(), compileIfNecessary(), CCopasiVector< T >::end(), and mEvents.

Referenced by appendDependentModelObjects(), convert2NonReversible(), and determineIsAutonomous().

2595 {
2596  const_cast< CModel * >(this)->compileIfNecessary(NULL);
2597 
2598  size_t Size = dependents.size();
2599 
2602 
2603  std::set< const CCopasiObject * >::const_iterator itSet;
2604  std::set< const CCopasiObject * >::const_iterator endSet;
2605 
2606  for (; it != end; ++it)
2607 
2608  // Check whether the model value is already in the list of deleted objects
2609  if (candidates.find(*it) == candidates.end())
2610  {
2611  if ((*it)->mustBeDeleted(candidates))
2612  {
2613  dependents.insert(*it);
2614  }
2615  }
2616 
2617  return Size < dependents.size();
2618 }
CCopasiVectorN< CEvent > mEvents
Definition: CModel.h:1344
iterator begin()
iterator end()
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
Definition: CModel.h:50
bool CModel::appendDependentMetabolites ( std::set< const CCopasiObject * >  candidates,
std::set< const CCopasiObject * > &  dependents 
) const
private

Appends pointers to metabolites which are dependent on the candidates to the list.

Parameters
std::set<const CCopasiObject * > candidates
std::set<const CCopasiObject * > & dependents
Returns
bool objectsAppended

Definition at line 2501 of file CModel.cpp.

References CCopasiVector< T >::begin(), CCopasiVector< CType >::begin(), compileIfNecessary(), CCopasiVector< CType >::end(), CCopasiVector< T >::end(), and mCompartments.

Referenced by appendDependentModelObjects(), convert2NonReversible(), and determineIsAutonomous().

2503 {
2504  const_cast< CModel * >(this)->compileIfNecessary(NULL);
2505 
2506  size_t Size = dependents.size();
2507 
2510 
2513 
2514  CCopasiObject::DataObjectSet::const_iterator itSet;
2515  CCopasiObject::DataObjectSet::const_iterator endSet;
2516 
2517  for (; itComp != endComp; ++itComp)
2518  {
2519  it = (*itComp)->getMetabolites().begin();
2520  end = (*itComp)->getMetabolites().end();
2521 
2522  for (; it != end; ++it)
2523  {
2524  // Check whether the species is already in the list of deleted objects
2525  if (candidates.find(*it) == candidates.end())
2526  {
2527  if ((*it)->mustBeDeleted(candidates))
2528  {
2529  dependents.insert(*it);
2530  }
2531  }
2532  }
2533  }
2534 
2535  return Size < dependents.size();
2536 }
iterator begin()
CCopasiVectorNS< CCompartment > mCompartments
Definition: CModel.h:1324
iterator end()
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
Definition: CModel.h:50
bool CModel::appendDependentModelObjects ( const std::set< const CCopasiObject * > &  candidates,
std::set< const CCopasiObject * > &  dependentReactions,
std::set< const CCopasiObject * > &  dependentMetabolites,
std::set< const CCopasiObject * > &  dependentCompartments,
std::set< const CCopasiObject * > &  dependentModelValues,
std::set< const CCopasiObject * > &  dependentEvents 
) const

Appends pointers to all model objects, which are dependent on the candidates to appropriate lists.

Parameters
conststd::set< const CCopasiObject * > & candidates
std::set<const CCopasiObject * > & dependentReactions
std::set<const CCopasiObject * > & dependentMetabolites
std::set<const CCopasiObject * > & dependentCompartments
std::set<const CCopasiObject * > & dependentModelValues
std::set<const CCopasiObject * > & dependentEvents
Returns
bool objectsAppended

Definition at line 2364 of file CModel.cpp.

References appendDependentCompartments(), appendDependentEvents(), appendDependentMetabolites(), appendDependentModelValues(), appendDependentReactions(), CCompartment::getDeletedObjects(), CReaction::getDeletedObjects(), CModelEntity::getDeletedObjects(), and CMetab::getDeletedObjects().

Referenced by CQMessageBox::confirmDelete(), CModelExpansion::SetOfModelElements::fillDependencies(), CFunctionDB::getUsedFunctions(), FunctionWidget1::leave(), and removeDependentModelObjects().

2370 {
2371  // We need a local copy since we recursively add deleted objects.
2372  std::set< const CCopasiObject * > DeletedObjects = deletedObjects;
2373 
2374  bool ObjectsAppended = false;
2375  bool DeleteObjects = DeletedObjects.size() > 0;
2376 
2377  // This is this implemented recursively. Since deleting a container may result
2378  // in the deletion of objects not dependent on the original set of deleted objects.
2379 
2380  while (DeleteObjects)
2381  {
2382  DeleteObjects = false;
2383 
2384  DeleteObjects |= appendDependentReactions(DeletedObjects, dependentReactions);
2385 
2386  if (dependentReactions.size() > 0)
2387  {
2388  std::set< const CCopasiObject * >::const_iterator it, itEnd = dependentReactions.end();
2389 
2390  for (it = dependentReactions.begin(); it != itEnd; ++it)
2391  if (DeletedObjects.find(*it) == DeletedObjects.end())
2392  {
2393  CCopasiObject::DataObjectSet AdditionalObjects =
2394  static_cast< const CReaction * >(*it)->getDeletedObjects();
2395 
2396  std::set< const CCopasiObject * >::const_iterator itDeleted = AdditionalObjects.begin();
2397  std::set< const CCopasiObject * >::const_iterator endDeleted = AdditionalObjects.end();
2398 
2399  for (; itDeleted != endDeleted; ++itDeleted)
2400  DeletedObjects.insert(*itDeleted);
2401  }
2402  }
2403 
2404  DeleteObjects |= appendDependentMetabolites(DeletedObjects, dependentMetabolites);
2405 
2406  if (dependentMetabolites.size() > 0)
2407  {
2408  std::set< const CCopasiObject * >::const_iterator it, itEnd = dependentMetabolites.end();
2409 
2410  for (it = dependentMetabolites.begin(); it != itEnd; ++it)
2411  if (DeletedObjects.find(*it) == DeletedObjects.end())
2412  {
2413  CCopasiObject::DataObjectSet AdditionalObjects =
2414  static_cast< const CMetab * >(*it)->getDeletedObjects();
2415 
2416  std::set< const CCopasiObject * >::const_iterator itDeleted = AdditionalObjects.begin();
2417  std::set< const CCopasiObject * >::const_iterator endDeleted = AdditionalObjects.end();
2418 
2419  for (; itDeleted != endDeleted; ++itDeleted)
2420  DeletedObjects.insert(*itDeleted);
2421  }
2422  }
2423 
2424  DeleteObjects |= appendDependentModelValues(DeletedObjects, dependentModelValues);
2425 
2426  if (dependentModelValues.size() > 0)
2427  {
2428  std::set< const CCopasiObject * >::const_iterator it, itEnd = dependentModelValues.end();
2429 
2430  for (it = dependentModelValues.begin(); it != itEnd; ++it)
2431  if (DeletedObjects.find(*it) == DeletedObjects.end())
2432  {
2433  CCopasiObject::DataObjectSet AdditionalObjects =
2434  static_cast< const CModelValue * >(*it)->getDeletedObjects();
2435 
2436  std::set< const CCopasiObject * >::const_iterator itDeleted = AdditionalObjects.begin();
2437  std::set< const CCopasiObject * >::const_iterator endDeleted = AdditionalObjects.end();
2438 
2439  for (; itDeleted != endDeleted; ++itDeleted)
2440  DeletedObjects.insert(*itDeleted);
2441  }
2442  }
2443 
2444  DeleteObjects |= appendDependentCompartments(DeletedObjects, dependentCompartments);
2445 
2446  if (dependentCompartments.size() > 0)
2447  {
2448  std::set< const CCopasiObject * >::const_iterator it, itEnd = dependentCompartments.end();
2449 
2450  for (it = dependentCompartments.begin(); it != itEnd; ++it)
2451  if (DeletedObjects.find(*it) == DeletedObjects.end())
2452  {
2453  CCopasiObject::DataObjectSet AdditionalObjects =
2454  static_cast< const CCompartment * >(*it)->getDeletedObjects();
2455 
2456  std::set< const CCopasiObject * >::const_iterator itDeleted = AdditionalObjects.begin();
2457  std::set< const CCopasiObject * >::const_iterator endDeleted = AdditionalObjects.end();
2458 
2459  for (; itDeleted != endDeleted; ++itDeleted)
2460  DeletedObjects.insert(*itDeleted);
2461  }
2462  }
2463 
2464  DeleteObjects |= appendDependentEvents(DeletedObjects, dependentEvents);
2465 
2466  ObjectsAppended |= DeleteObjects;
2467  }
2468 
2469  return ObjectsAppended;
2470 }
Definition: CMetab.h:178
virtual std::set< const CCopasiObject * > getDeletedObjects() const
virtual std::set< const CCopasiObject * > getDeletedObjects() const
Definition: CReaction.cpp:959
virtual DataObjectSet getDeletedObjects() const
Definition: CMetab.cpp:806
bool appendDependentReactions(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependents) const
Definition: CModel.cpp:2472
bool appendDependentCompartments(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependents) const
Definition: CModel.cpp:2538
bool appendDependentMetabolites(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependents) const
Definition: CModel.cpp:2501
virtual std::set< const CCopasiObject * > getDeletedObjects() const
bool appendDependentEvents(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependents) const
Definition: CModel.cpp:2593
std::set< const CCopasiObject * > DataObjectSet
bool appendDependentModelValues(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependents) const
Definition: CModel.cpp:2566
bool CModel::appendDependentModelValues ( std::set< const CCopasiObject * >  candidates,
std::set< const CCopasiObject * > &  dependents 
) const
private

Appends a pointers to model values which are dependent on the candidates to the list.

Parameters
std::set<const CCopasiObject * > candidates
std::set<const CCopasiObject * > & dependents
Returns
bool objectsAppended

Definition at line 2566 of file CModel.cpp.

References CCopasiVector< T >::begin(), compileIfNecessary(), CCopasiVector< T >::end(), and mValues.

Referenced by appendDependentModelObjects(), convert2NonReversible(), and determineIsAutonomous().

2568 {
2569  const_cast< CModel * >(this)->compileIfNecessary(NULL);
2570 
2571  size_t Size = dependents.size();
2572 
2575 
2576  std::set< const CCopasiObject * >::const_iterator itSet;
2577  std::set< const CCopasiObject * >::const_iterator endSet;
2578 
2579  for (; it != end; ++it)
2580 
2581  // Check whether the model value is already in the list of deleted objects
2582  if (candidates.find(*it) == candidates.end())
2583  {
2584  if ((*it)->mustBeDeleted(candidates))
2585  {
2586  dependents.insert(*it);
2587  }
2588  }
2589 
2590  return Size < dependents.size();
2591 }
iterator begin()
CCopasiVectorN< CModelValue > mValues
Definition: CModel.h:1354
iterator end()
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
Definition: CModel.h:50
bool CModel::appendDependentReactions ( std::set< const CCopasiObject * >  candidates,
std::set< const CCopasiObject * > &  dependents 
) const

Appends pointers to reactions which are dependent on the candidates to the list.

Parameters
std::set<const CCopasiObject * > candidates
std::set<const CCopasiObject * > & dependents
Returns
bool objectsAppended

Definition at line 2472 of file CModel.cpp.

References CCopasiVector< T >::begin(), compileIfNecessary(), CCopasiVector< T >::end(), and mSteps.

Referenced by appendDependentModelObjects(), determineIsAutonomous(), CQSpeciesDetail::loadReactionTable(), and CQSpeciesDetail::slotSwitchToReaction().

2474 {
2475  const_cast< CModel * >(this)->compileIfNecessary(NULL);
2476 
2477  size_t Size = dependents.size();
2478 
2481 
2482  CCopasiObject::DataObjectSet::const_iterator itSet;
2483  CCopasiObject::DataObjectSet::const_iterator endSet;
2484 
2485  for (; it != end; ++it)
2486  if (candidates.find(*it) == candidates.end())
2487  {
2488  // Check whether the reaction is already in the list of deleted objects
2489  if (candidates.find(*it) == candidates.end())
2490  {
2491  if ((*it)->mustBeDeleted(candidates))
2492  {
2493  dependents.insert(*it);
2494  }
2495  }
2496  }
2497 
2498  return Size < dependents.size();
2499 }
iterator begin()
iterator end()
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
CCopasiVectorNS< CReaction > mSteps
Definition: CModel.h:1339
Definition: CModel.h:50
void CModel::applyActiveParameterSet ( )

Update the model initial values from the active parameter set.

Definition at line 1082 of file CModel.cpp.

References CModelParameterSet::createFromModel(), CKeyFactory::get(), CModelParameterSet::getKey(), CCopasiRootContainer::getKeyFactory(), mActiveParameterSetKey, mParameterSet, and CModelParameterSet::updateModel().

1083 {
1084  CModelParameterSet * pParameterSet =
1086 
1087  if (pParameterSet != NULL)
1088  {
1089  pParameterSet->updateModel();
1090  }
1091  else
1092  {
1093  /*
1094  CModelParameterSet * pParameterSet = new CModelParameterSet(UTCTimeStamp());
1095  mParameterSets.add(pParameterSet, true);
1096  mActiveParameterSetKey = pParameterSet->getKey();
1097  pParameterSet->createFromModel();
1098  */
1099  }
1100 
1103 }
CCopasiObject * get(const std::string &key)
CModelParameterSet mParameterSet
Definition: CModel.h:1359
virtual const std::string & getKey() const
static CKeyFactory * getKeyFactory()
std::string mActiveParameterSetKey
Definition: CModel.h:1369
virtual bool updateModel()
void CModel::applyInitialValues ( )

initialize all values of the model with their initial values

Definition at line 1236 of file CModel.cpp.

References CMathModel::applyInitialValues(), mApplyInitialValuesRefreshes, mInitialState, mpMathModel, setState(), and updateSimulatedValues().

Referenced by CSensTask::process(), CLNATask::process(), CScanTask::process(), CLyapTask::process(), CMCATask::process(), CSteadyStateTask::process(), CTSSATask::processStart(), CTrajectoryTask::processStart(), CCrossSectionTask::processStart(), and CopasiUI3Window::slotApplyInitialState().

1237 {
1238  // Copy the initial state to the current state,
1240 
1241  // Since the initial state is in itself consistent we should not need to
1242  // do anything further. However, for species of type ODE and ASSIGNMENT
1243  // the effective state variable is the concentration, i.e., we need to update
1244  // their concentration here.
1245  std::vector< Refresh * >::const_iterator itRefresh = mApplyInitialValuesRefreshes.begin();
1246  std::vector< Refresh * >::const_iterator endRefresh = mApplyInitialValuesRefreshes.end();
1247 
1248  while (itRefresh != endRefresh)
1249  (**itRefresh++)();
1250 
1251  // Update all dependent objects needed for simulation.
1252  updateSimulatedValues(false);
1253 
1255 }
void updateSimulatedValues(const bool &updateMoieties)
Definition: CModel.cpp:1851
void applyInitialValues()
Definition: CMathModel.cpp:372
CMathModel * mpMathModel
Definition: CModel.h:1532
std::vector< Refresh * > mApplyInitialValuesRefreshes
Definition: CModel.h:1501
void setState(const CState &state)
Definition: CModel.cpp:1785
CState mInitialState
Definition: CModel.h:1272
bool CModel::buildApplyInitialValuesSequence ( )
private

Build the update sequence used by applyInitialValues to update values.

Returns
bool success

Definition at line 1627 of file CModel.cpp.

References CModelEntity::ASSIGNMENT, CStateTemplate::beginIndependent(), CCopasiObject::buildUpdateSequence(), CStateTemplate::endFixed(), mApplyInitialValuesRefreshes, mStateTemplate, and CModelEntity::ODE.

Referenced by buildSimulatedSequence(), and compile().

1628 {
1629  bool success = true;
1630 
1632 
1633  std::set< const CCopasiObject * > Objects;
1634 
1635  const CMetab * pMetab;
1636 
1638  CModelEntity ** ppEntityEnd = mStateTemplate.endFixed();
1639 
1640  for (; ppEntity != ppEntityEnd; ++ppEntity)
1641  {
1642  if ((*ppEntity)->getStatus() == ODE)
1643  {
1644  // TODO We need only to calculate rates which are constant since the other will
1645  // be updated by the simulation request.
1646  Objects.insert((*ppEntity)->getRateReference());
1647  }
1648 
1649  // Species of type assignment have a second pseudo state value the concentration,
1650  // which always can be directly calculated.
1651  if ((*ppEntity)->getStatus() == ASSIGNMENT &&
1652  (pMetab = dynamic_cast< const CMetab * >(*ppEntity)) != NULL)
1653  {
1654  mApplyInitialValuesRefreshes.push_back(pMetab->getConcentrationReference()->getApplyInitialValueRefresh());
1655  }
1656  }
1657 
1658  std::set< const CCopasiObject * > UpToDate;
1659 
1660  try
1661  {
1662  std::vector< Refresh * > RateRefreshes =
1663  CCopasiObject::buildUpdateSequence(Objects, UpToDate);
1664 
1666  RateRefreshes.begin(),
1667  RateRefreshes.end());
1668  }
1669  catch (...)
1670  {
1672  success = false;
1673  }
1674 
1675  return success;
1676 }
Definition: CMetab.h:178
std::vector< Refresh * > mApplyInitialValuesRefreshes
Definition: CModel.h:1501
CStateTemplate mStateTemplate
Definition: CModel.h:1279
CModelEntity ** endFixed()
Definition: CState.cpp:213
CModelEntity ** beginIndependent()
Definition: CState.cpp:208
static std::vector< Refresh * > buildUpdateSequence(const DataObjectSet &objects, const DataObjectSet &uptoDateObjects, const DataObjectSet &context=DataObjectSet())
bool CModel::buildDependencyGraphs ( )

Definition at line 547 of file CModel.cpp.

References CMathDependencyGraph::addObject(), CCopasiVector< T >::begin(), CStateTemplate::beginIndependent(), CMathDependencyGraph::clear(), CCopasiVector< T >::end(), CStateTemplate::endFixed(), CMathDependencyGraph::exportDOTFormat(), CMetab::getConcentrationReference(), CMetab::getInitialConcentrationReference(), mInitialDependencies, mMoieties, mPhysicalDependencies, mStateTemplate, mTransientDependencies, CModelEntity::ODE, and CModelEntity::REACTIONS.

Referenced by compile().

548 {
552 
553  // The initial values of the model entities
554  // We need to add the time for non-autonomous models.
555  CModelEntity **ppEntity = mStateTemplate.beginIndependent() - 1;
556  CModelEntity **ppEntityEnd = mStateTemplate.endFixed();
557 
558  for (; ppEntity != ppEntityEnd; ++ppEntity)
559  {
560  CMetab * pSpecies = dynamic_cast< CMetab * >(*ppEntity);
561 
562  mInitialDependencies.addObject((*ppEntity)->getInitialValueReference());
563  mTransientDependencies.addObject((*ppEntity)->getValueReference());
564 
565  if (pSpecies != NULL)
566  {
569  }
570 
571  switch ((*ppEntity)->getStatus())
572  {
573  case CModelEntity::ODE:
575  mTransientDependencies.addObject((*ppEntity)->getRateReference());
576  break;
577 
578  default:
579  break;
580  }
581  }
582 
585 
586  for (; itMoiety != endMoiety; ++itMoiety)
587  {
588  mInitialDependencies.addObject((*itMoiety)->getInitialValueReference());
589  mTransientDependencies.addObject((*itMoiety)->getTotalNumberReference());
590  mTransientDependencies.addObject((*itMoiety)->getDependentNumberReference());
591  }
592 
593 #ifdef COPASI_DEBUG_TRACE
594  std::ofstream File;
595 
596  File.open("InitialDependencies.dot");
597  mInitialDependencies.exportDOTFormat(File, "InitialDependencies");
598  File.close();
599 
600  File.open("SimulationDependencies.dot");
601  mTransientDependencies.exportDOTFormat(File, "SimulationDependencies");
602  File.close();
603 #endif //COPASI_DEBUG_TRACE
604  return true;
605 }
iterator begin()
Definition: CMetab.h:178
iterator end()
CStateTemplate mStateTemplate
Definition: CModel.h:1279
CModelEntity ** endFixed()
Definition: CState.cpp:213
void exportDOTFormat(std::ostream &os, const std::string &name) const
CModelEntity ** beginIndependent()
Definition: CState.cpp:208
CMathDependencyGraph mTransientDependencies
Definition: CModel.h:1288
iterator addObject(const CObjectInterface *pObject)
CMathDependencyGraph mInitialDependencies
Definition: CModel.h:1287
CConcentrationReference * getInitialConcentrationReference() const
Definition: CMetab.cpp:861
CCopasiVector< CMoiety > mMoieties
Definition: CModel.h:1374
CMathDependencyGraph mPhysicalDependencies
Definition: CModel.h:1289
CConcentrationReference * getConcentrationReference() const
Definition: CMetab.cpp:864
std::vector< Refresh * > CModel::buildInitialRefreshSequence ( std::set< const CCopasiObject * > &  changedObjects)

Build the update sequence used to calculate all initial values depending on the changed objects. For metabolites the initial particle number is updated by default unless itself is in the list of changed objects. In that case the initial concentration is updated.

Parameters
std::set<const CCopasiObject * > & changedObjects
Returns
std::vector< Refresh * > initialRefreshSequence

Definition at line 4164 of file CModel.cpp.

References CArrayAnnotation::appendElementReferences(), CModelEntity::ASSIGNMENT, CCopasiVector< T >::begin(), CStateTemplate::beginIndependent(), CCopasiVector< T >::end(), CStateTemplate::endFixed(), CCopasiMessage::EXCEPTION, CCopasiObject::getDirectDependencies(), CMetab::getInitialConcentrationReference(), CModelEntity::getInitialExpression(), CModelEntity::getInitialValueReference(), CCopasiParameterGroup::getParameter(), CModelEntity::getStatus(), CMetab::isInitialConcentrationChangeAllowed(), MCObject, mMoieties, mpLinkMatrixAnnotation, mpRedStoiAnnotation, mpStoiAnnotation, mStateTemplate, mSteps, CCopasiParameterGroup::size(), and sortObjectsByDependency().

Referenced by DataModelGUI::buildChangedObjects(), buildInitialSequence(), test000097::createModel(), CScanMethod::init(), CFitProblem::initialize(), CSensMethod::initialize(), COptProblem::initialize(), COptProblem::restoreModel(), SBMLImporter::setInitialValues(), CSlider::setSliderObject(), test000058::test_bug1025_10(), test000058::test_bug1025_6(), test000058::test_bug1025_7(), test000058::test_bug1025_8(), test000058::test_bug1025_9(), test000060::test_bug_1026(), test000059::test_unique_id_11(), test000059::test_unique_id_12(), test000059::test_unique_id_13(), test000059::test_unique_id_14(), test000059::test_unique_id_15(), test000059::test_unique_id_16(), and updateInitialValues().

4165 {
4166  // First we remove all objects which are of type assignment from the changed objects
4167  // since this may not be changed as they are under control of the assignment.
4168  std::set< const CCopasiObject * >::iterator itSet;
4169  std::set< const CCopasiObject * >::iterator endSet;
4170  std::set< const CCopasiObject * > Objects;
4171 
4172  CModelEntity **ppEntity;
4173  CModelEntity **ppEntityEnd = mStateTemplate.endFixed();
4174 
4175  const CModelEntity * pEntity;
4176  CMetab * pMetab;
4177 
4178  // If the changed objects are empty we assume that all changeable objects have been changed
4179  if (changedObjects.size() == 0)
4180  {
4181  // The objects which are changed are all initial values of of all model entities including
4182  // fixed and unused once. Additionally, all kinetic parameters are possibly changed.
4183  // This is basically all the parameters in the parameter overview whose value is editable.
4184 
4185  // :TODO: Theoretically, it is possible that also task parameters influence the initial
4186  // state of a model but that is currently not handled.
4187 
4188  // The initial values of the model entities
4189  ppEntity = mStateTemplate.beginIndependent() - 1; // Offset for time
4190 
4191  for (; ppEntity != ppEntityEnd; ++ppEntity)
4192  {
4193  // If we have an initial expression we have no initial values
4194  if (((*ppEntity)->getInitialExpression() != "" ||
4195  (*ppEntity)->getStatus() == ASSIGNMENT) &&
4196  (*ppEntity)->getInitialValueReference()->getDirectDependencies().size() > 0)
4197  continue;
4198 
4199  // Metabolites have two initial values
4200  if ((pMetab = dynamic_cast< CMetab * >(*ppEntity)) != NULL)
4201  {
4202  // The concentration is assumed to be fix accept when this would lead to circular dependencies,
4203  // for the parent's compartment's initial volume.
4205  changedObjects.insert(pMetab->getInitialConcentrationReference());
4206  else
4207  changedObjects.insert(pMetab->getInitialValueReference());
4208  }
4209  else
4210  changedObjects.insert((*ppEntity)->getInitialValueReference());
4211  }
4212 
4213  // The reaction parameters
4216  size_t i, imax;
4217 
4218  for (; itReaction != endReaction; ++itReaction)
4219  {
4220  const CCopasiParameterGroup & Group = (*itReaction)->getParameters();
4221 
4222  for (i = 0, imax = Group.size(); i < imax; i++)
4223  changedObjects.insert(Group.getParameter(i));
4224  }
4225 
4226  // Fix for Issue 1170: We need to add elements of the stoichiometry, reduced stoichiometry,
4227  // and link matrices.
4228  if (mpStoiAnnotation != NULL)
4229  mpStoiAnnotation->appendElementReferences(changedObjects);
4230 
4231  if (mpRedStoiAnnotation != NULL)
4233 
4234  if (mpLinkMatrixAnnotation != NULL)
4236  }
4237  else
4238  {
4239  // Remove all objects with initial assignments
4240  itSet = changedObjects.begin();
4241  endSet = changedObjects.end();
4242 
4243  for (; itSet != endSet; ++itSet)
4244  {
4245  if ((pEntity = dynamic_cast< const CModelEntity * >((*itSet)->getObjectParent())) != NULL &&
4246  (pEntity->getInitialExpression() != "" ||
4247  pEntity->getStatus() == ASSIGNMENT) &&
4248  pEntity->getInitialValueReference()->getDirectDependencies().size() > 0)
4249  Objects.insert(*itSet);
4250  }
4251 
4252  for (itSet = Objects.begin(), endSet = Objects.end(); itSet != endSet; ++itSet)
4253  changedObjects.erase(*itSet);
4254  }
4255 
4256  // We need to add all initial values which are dynamically calculated.
4257  // These are initial assignments and either a metabolite's initial particle number
4258  // or concentration.
4259  ppEntity = mStateTemplate.beginIndependent() - 1; // Offset for time
4260  Objects.clear();
4261 
4262  for (; ppEntity != ppEntityEnd; ++ppEntity)
4263  {
4264  if (((*ppEntity)->getInitialExpression() != "" ||
4265  (*ppEntity)->getStatus() == ASSIGNMENT))
4266  {
4267  Objects.insert((*ppEntity)->getInitialValueReference());
4268  continue;
4269  }
4270 
4271  // For metabolites we need to add the initial concentration or the initial
4272  // particle number..
4273  if ((pMetab = dynamic_cast< CMetab * >(*ppEntity)) != NULL)
4274  {
4275  if (changedObjects.count(pMetab->getInitialConcentrationReference()) != 0)
4276  {
4277  Objects.insert(pMetab->getInitialValueReference());
4278  }
4279  else
4280  {
4281  Objects.insert(pMetab->getInitialConcentrationReference());
4282  }
4283  }
4284  }
4285 
4286  // We need to add the total particle number of moieties.
4289 
4290  for (; itMoiety != endMoiety; ++itMoiety)
4291  Objects.insert((*itMoiety)->getInitialValueReference());
4292 
4293  std::set< const CCopasiObject * > DependencySet;
4294  std::set< const CCopasiObject * > VerifiedSet;
4295  std::pair<std::set< const CCopasiObject * >::iterator, bool> InsertedObject;
4296 
4297  assert(Objects.count(NULL) == 0);
4298 
4299  // Check whether we have any circular dependencies
4300  for (itSet = Objects.begin(), endSet = Objects.end(); itSet != endSet; ++itSet)
4301  if ((*itSet)->hasCircularDependencies(DependencySet, VerifiedSet, changedObjects))
4302  CCopasiMessage(CCopasiMessage::EXCEPTION, MCObject + 1, (*itSet)->getCN().c_str());
4303 
4304  // Build the complete set of dependencies
4305  for (itSet = Objects.begin(); itSet != endSet; ++itSet)
4306  {
4307  // At least the object itself needs to be up to date.
4308  InsertedObject = DependencySet.insert(*itSet);
4309 
4310  // Add all its dependencies
4311  if (InsertedObject.second)
4312  (*itSet)->getAllDependencies(DependencySet, changedObjects);
4313  }
4314 
4315  // Remove all objects which do not depend on the changed objects, or do not have a
4316  // refresh method.
4317  Objects.clear();
4318 
4319  // We now check which objects we need to refresh
4320  for (itSet = DependencySet.begin(), endSet = DependencySet.end(); itSet != endSet; ++itSet)
4321  {
4322  // No refresh method
4323  if ((*itSet)->getRefresh() == NULL)
4324  Objects.insert(*itSet);
4325  // Is a changed object
4326  else if (changedObjects.count(*itSet) != 0)
4327  Objects.insert(*itSet);
4328  // Not dependent on the changed objects.
4329  else if (!(*itSet)->dependsOn(changedObjects, changedObjects))
4330  Objects.insert(*itSet);
4331  }
4332 
4333  for (itSet = Objects.begin(), endSet = Objects.end(); itSet != endSet; ++itSet)
4334  DependencySet.erase(*itSet);
4335 
4336  // Create a properly sorted list.
4337  std::list< const CCopasiObject * > SortedList =
4338  sortObjectsByDependency(DependencySet.begin(), DependencySet.end(), changedObjects);
4339 
4340  std::list< const CCopasiObject * >::iterator itList;
4341  std::list< const CCopasiObject * >::iterator endList;
4342 
4343  // Build the vector of pointers to refresh methods
4344  Refresh * pRefresh;
4345 
4346  std::vector< Refresh * > UpdateVector;
4347  std::vector< Refresh * >::const_iterator itUpdate;
4348  std::vector< Refresh * >::const_iterator endUpdate;
4349 
4350  itList = SortedList.begin();
4351  endList = SortedList.end();
4352 
4353  for (; itList != endList; ++itList)
4354  {
4355  pRefresh = (*itList)->getRefresh();
4356  itUpdate = UpdateVector.begin();
4357  endUpdate = UpdateVector.end();
4358 
4359  while (itUpdate != endUpdate && !(*itUpdate)->isEqual(pRefresh)) ++itUpdate;
4360 
4361  if (itUpdate == endUpdate)
4362  UpdateVector.push_back(pRefresh);
4363  }
4364 
4365  return UpdateVector;
4366 }
CArrayAnnotation * mpRedStoiAnnotation
Definition: CModel.h:1399
CCopasiObject * getInitialValueReference() const
iterator begin()
#define MCObject
Definition: CMetab.h:178
std::list< const CCopasiObject * > sortObjectsByDependency(ForwardAccessIterator begin, ForwardAccessIterator end, const CCopasiObject::DataObjectSet &context)
iterator end()
CStateTemplate mStateTemplate
Definition: CModel.h:1279
CArrayAnnotation * mpLinkMatrixAnnotation
Definition: CModel.h:1451
std::vector< CType * >::const_iterator const_iterator
Definition: CCopasiVector.h:57
CModelEntity ** endFixed()
Definition: CState.cpp:213
const bool & isInitialConcentrationChangeAllowed() const
Definition: CMetab.cpp:664
std::string getInitialExpression() const
void appendElementReferences(std::set< const CCopasiObject * > &objects) const
CModelEntity ** beginIndependent()
Definition: CState.cpp:208
CCopasiParameter * getParameter(const std::string &name)
virtual const DataObjectSet & getDirectDependencies(const DataObjectSet &context=DataObjectSet()) const
CCopasiVectorNS< CReaction > mSteps
Definition: CModel.h:1339
const CModelEntity::Status & getStatus() const
CConcentrationReference * getInitialConcentrationReference() const
Definition: CMetab.cpp:861
CArrayAnnotation * mpStoiAnnotation
Definition: CModel.h:1384
CCopasiVector< CMoiety > mMoieties
Definition: CModel.h:1374
bool CModel::buildInitialSequence ( )
private

Build the update sequence used by updateInitialValues to update all initial values.

Returns
bool success

Definition at line 1395 of file CModel.cpp.

References CArrayAnnotation::appendElementReferences(), CModelEntity::ASSIGNMENT, CCopasiVector< T >::begin(), CStateTemplate::beginIndependent(), buildInitialRefreshSequence(), CCopasiVector< T >::end(), CStateTemplate::endFixed(), CCopasiContainer::getObject(), CCopasiParameterGroup::getParameter(), CCopasiParameter::getValueReference(), mBuildInitialSequence, mInitialRefreshes, mpLinkMatrixAnnotation, mpRedStoiAnnotation, mpStoiAnnotation, mStateTemplate, mSteps, and CCopasiParameterGroup::size().

Referenced by buildSimulatedSequence(), compile(), and updateInitialValues().

1396 {
1397  bool success = true;
1398 
1399  // The objects which are changed are all initial values of of all model entities including
1400  // fixed and unused once. Additionally, all kinetic parameters are possibly changed.
1401  // This is basically all the parameters in the parameter overview whose value is editable.
1402 
1403  // Issue 1170: We need to add elements of the stoichiometry, reduced stoichiometry,
1404  // and link matrix.
1405 
1407 
1408  Objects.insert(static_cast< const CCopasiObject * >(getObject(CCopasiObjectName("Reference=Avogadro Constant"))));
1409 
1410  // The initial values of the model entities
1411  CModelEntity **ppEntity = mStateTemplate.beginIndependent() - 1; // Offset for time
1412  CModelEntity **ppEntityEnd = mStateTemplate.endFixed();
1413 
1414  for (; ppEntity != ppEntityEnd; ++ppEntity)
1415  {
1416  // Assignments have no initial values
1417  if ((*ppEntity)->getStatus() != ASSIGNMENT ||
1418  (*ppEntity)->getInitialValueReference()->getDirectDependencies().size() == 0)
1419  Objects.insert((*ppEntity)->getInitialValueReference());
1420  }
1421 
1422  // The reaction parameters
1425  size_t i, imax;
1426 
1427  for (; itReaction != endReaction; ++itReaction)
1428  {
1429  const CCopasiParameterGroup & Group = (*itReaction)->getParameters();
1430 
1431  for (i = 0, imax = Group.size(); i < imax; i++)
1432  Objects.insert(Group.getParameter(i)->getValueReference());
1433  }
1434 
1435  // Fix for Issue 1170: We need to add elements of the stoichiometry, reduced stoichiometry,
1436  // and link matrices.
1437  if (mpStoiAnnotation != NULL)
1439 
1440  if (mpRedStoiAnnotation != NULL)
1442 
1443  if (mpLinkMatrixAnnotation != NULL)
1445 
1446  try
1447  {
1449  }
1450  catch (...)
1451  {
1452  mInitialRefreshes.clear();
1453  success = false;
1454  }
1455 
1456  mBuildInitialSequence = false;
1457 
1458  return success;
1459 }
CArrayAnnotation * mpRedStoiAnnotation
Definition: CModel.h:1399
iterator begin()
CCopasiObject * getValueReference() const
iterator end()
CStateTemplate mStateTemplate
Definition: CModel.h:1279
CArrayAnnotation * mpLinkMatrixAnnotation
Definition: CModel.h:1451
std::vector< CType * >::const_iterator const_iterator
Definition: CCopasiVector.h:57
CModelEntity ** endFixed()
Definition: CState.cpp:213
std::vector< Refresh * > mInitialRefreshes
Definition: CModel.h:1490
void appendElementReferences(std::set< const CCopasiObject * > &objects) const
CModelEntity ** beginIndependent()
Definition: CState.cpp:208
CCopasiParameter * getParameter(const std::string &name)
bool mBuildInitialSequence
Definition: CModel.h:1523
CCopasiVectorNS< CReaction > mSteps
Definition: CModel.h:1339
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
std::vector< Refresh * > buildInitialRefreshSequence(std::set< const CCopasiObject * > &changedObjects)
Definition: CModel.cpp:4164
std::set< const CCopasiObject * > DataObjectSet
CArrayAnnotation * mpStoiAnnotation
Definition: CModel.h:1384
void CModel::buildLinkZero ( )

Build the core of the link matrix L

Parameters
constCMatrix< C_FLOAT64 > & LU

Definition at line 3946 of file CModel.cpp.

References CLinkMatrix::build(), CLinkMatrix::doRowPivot(), CLinkMatrix::getNumIndependent(), mL, mNumMetabolitesReactionIndependent, mStoi, and mStoiInternal.

Referenced by compile().

3947 {
3950  mStoi = mStoiInternal;
3951  mL.doRowPivot(mStoi);
3952 
3953  return;
3954 }
bool build(const CMatrix< C_FLOAT64 > &matrix, size_t maxRank=C_INVALID_INDEX)
Definition: CLinkMatrix.cpp:44
size_t mNumMetabolitesReactionIndependent
Definition: CModel.h:1441
CMatrix< C_FLOAT64 > mStoi
Definition: CModel.h:1389
CLinkMatrix mL
Definition: CModel.h:1446
const size_t & getNumIndependent() const
bool doRowPivot(CMatrix< C_FLOAT64 > &matrix) const
CMatrix< C_FLOAT64 > mStoiInternal
Definition: CModel.h:1379
void CModel::buildMoieties ( )

Build the moieties based on the LU decomposition

Definition at line 905 of file CModel.cpp.

References CMoiety::add(), CCopasiVector< T >::add(), CMatrix< CType >::array(), CCopasiVector< T >::begin(), C_FLOAT64, CCopasiVector< T >::cleanup(), mL, mMetabolitesX, mMoieties, mNumMetabolitesODE, MNumMetabolitesReactionDependent, mNumMetabolitesReactionIndependent, and updateMoietyValues().

Referenced by compile().

906 {
907  // Independent metabs
910 
911  // Dependent metabs
912  CCopasiVector< CMetab >::iterator itDependent = endIndependent;
914 
915  C_FLOAT64 * pFactor = mL.array();
916 
917  CMoiety *pMoiety;
918  mMoieties.cleanup();
919 
920  for (; itDependent != endDependent; ++itDependent)
921  {
922  pMoiety = new CMoiety((*itDependent)->getObjectName());
923  pMoiety->add(1.0, *itDependent);
924 
925  if (pFactor != NULL)
926  {
927  for (itIndependent = mMetabolitesX.begin() + mNumMetabolitesODE; itIndependent != endIndependent; ++itIndependent, ++pFactor)
928  if (fabs(*pFactor) > std::numeric_limits< C_FLOAT64 >::epsilon())
929  pMoiety->add(- *pFactor, *itIndependent);
930  }
931 
932  mMoieties.add(pMoiety, true);
933  }
934 
936  return;
937 }
size_t mNumMetabolitesReactionIndependent
Definition: CModel.h:1441
iterator begin()
#define MNumMetabolitesReactionDependent
Definition: CModel.cpp:64
CLinkMatrix mL
Definition: CModel.h:1446
void updateMoietyValues()
Definition: CModel.cpp:896
virtual void cleanup()
CCopasiVector< CMetab > mMetabolitesX
Definition: CModel.h:1334
virtual bool add(const CType &src)
void add(C_FLOAT64 value, CMetab *metabolite)
Definition: CMoiety.cpp:96
#define C_FLOAT64
Definition: copasi.h:92
size_t mNumMetabolitesODE
Definition: CModel.h:1425
virtual CType * array()
Definition: CMatrix.h:337
CCopasiVector< CMoiety > mMoieties
Definition: CModel.h:1374
bool CModel::buildNonSimulatedSequence ( )
private

Build the update sequence used by updateNonSimulatedValues.

Returns
bool success

Definition at line 1678 of file CModel.cpp.

References CCopasiVector< T >::begin(), CCopasiObject::buildUpdateSequence(), CCopasiVector< T >::end(), mCompartments, mMetabolites, mNonSimulatedRefreshes, mSimulatedUpToDateObjects, mSteps, mValues, CModelEntity::ODE, and CModelEntity::REACTIONS.

Referenced by compile().

1679 {
1680  bool success = true;
1681 
1683 
1684  // Compartments
1687 
1688  for (; itComp != endComp; ++itComp)
1689  {
1690  Objects.insert((*itComp)->getValueReference());
1691 
1692  switch ((*itComp)->getStatus())
1693  {
1694  case ODE:
1695  Objects.insert((*itComp)->getRateReference());
1696  break;
1697 
1698  default:
1699  break;
1700  }
1701  }
1702 
1703  // Metabolites
1706 
1707  for (; itMetab != endMetab; ++itMetab)
1708  {
1709  Objects.insert((*itMetab)->getConcentrationReference());
1710  Objects.insert((*itMetab)->getValueReference());
1711 
1712  switch ((*itMetab)->getStatus())
1713  {
1714  case REACTIONS:
1715  case ODE:
1716  Objects.insert(static_cast< const CCopasiObject *>((*itMetab)->getObject(CCopasiObjectName("Reference=TransitionTime"))));
1717  Objects.insert((*itMetab)->getConcentrationRateReference());
1718  Objects.insert((*itMetab)->getRateReference());
1719  break;
1720 
1721  default:
1722  break;
1723  }
1724  }
1725 
1726  // Reactions
1729 
1730  for (; itStep != endStep; ++itStep)
1731  {
1732  Objects.insert(static_cast< const CCopasiObject * >((*itStep)->getObject(CCopasiObjectName("Reference=Flux"))));
1733  Objects.insert((*itStep)->getParticleFluxReference());
1734  }
1735 
1736  // Model Values
1739 
1740  for (; itValue != endValue; ++itValue)
1741  {
1742  Objects.insert((*itValue)->getValueReference());
1743 
1744  switch ((*itValue)->getStatus())
1745  {
1746  case ODE:
1747  Objects.insert((*itValue)->getRateReference());
1748  break;
1749 
1750  default:
1751  break;
1752  }
1753  }
1754 
1755  try
1756  {
1758  }
1759  catch (...)
1760  {
1761  mNonSimulatedRefreshes.clear();
1762  success = false;
1763  }
1764 
1765  return success;
1766 }
iterator begin()
CCopasiVectorNS< CCompartment > mCompartments
Definition: CModel.h:1324
std::vector< Refresh * > mNonSimulatedRefreshes
Definition: CModel.h:1507
CCopasiVectorN< CModelValue > mValues
Definition: CModel.h:1354
CCopasiVector< CMetab > mMetabolites
Definition: CModel.h:1329
std::set< const CCopasiObject * > mSimulatedUpToDateObjects
Definition: CModel.h:1285
iterator end()
CCopasiVectorNS< CReaction > mSteps
Definition: CModel.h:1339
std::vector< CType * >::iterator iterator
Definition: CCopasiVector.h:56
static std::vector< Refresh * > buildUpdateSequence(const DataObjectSet &objects, const DataObjectSet &uptoDateObjects, const DataObjectSet &context=DataObjectSet())
std::set< const CCopasiObject * > DataObjectSet
void CModel::buildRedStoi ( )

Build the core of the link matrix L

Parameters
constCMatrix< C_FLOAT64 > & LU Build the Reduced Stoichiometry Matrix from the LU decomposition

Definition at line 829 of file CModel.cpp.

References CLinkMatrix::applyRowPivot(), CVectorCore< CType >::array(), CCopasiVector< T >::begin(), mL, mMetabolitesX, mNumMetabolitesODE, mNumMetabolitesReaction, mNumMetabolitesReactionIndependent, mRedStoi, mStoi, CMatrix< CType >::numCols(), and CMatrix< CType >::resize().

Referenced by compile().

830 {
831  mRedStoi = mStoi;
833 
834  // The first metabolites are determined by ODEs we therefore cannot simply
835  // apply the pivot.
836 
837  // Create a temporary copy of metabolites determined by reactions.
838  CVector< CMetab * > ReactionMetabolites(mNumMetabolitesReaction);
839  CMetab ** ppMetab = ReactionMetabolites.array();
840  CMetab ** ppMetabEnd = ppMetab + mNumMetabolitesReaction;
842 
843  for (; ppMetab != ppMetabEnd; ++ppMetab, ++itMetabX)
844  {
845  *ppMetab = *itMetabX;
846  }
847 
848  // Apply the pivot on the temporary copy
849  mL.applyRowPivot(ReactionMetabolites);
850 
851  // Map the result on the actual metabolites
852  ppMetab = ReactionMetabolites.array();
853  itMetabX = mMetabolitesX.begin() + mNumMetabolitesODE;
854 
855  for (; ppMetab != ppMetabEnd; ++ppMetab, ++itMetabX)
856  {
857  *itMetabX = *ppMetab;
858  }
859 
860  return;
861 }
size_t mNumMetabolitesReactionIndependent
Definition: CModel.h:1441
iterator begin()
CMatrix< C_FLOAT64 > mStoi
Definition: CModel.h:1389
CMatrix< C_FLOAT64 > mRedStoi
Definition: CModel.h:1394
CLinkMatrix mL
Definition: CModel.h:1446
Definition: CMetab.h:178
bool applyRowPivot(CVectorCore< CType > &vector) const
Definition: CLinkMatrix.h:115
CCopasiVector< CMetab > mMetabolitesX
Definition: CModel.h:1334
virtual void resize(size_t rows, size_t cols, const bool &copy=false)
Definition: CMatrix.h:151
size_t mNumMetabolitesReaction
Definition: CModel.h:1430
virtual size_t numCols() const
Definition: CMatrix.h:144
size_t mNumMetabolitesODE
Definition: CModel.h:1425
bool CModel::buildSimulatedSequence ( )
private

Build the update sequence used by updateSimulatedValues.

Returns
bool success

Definition at line 1483 of file CModel.cpp.

References CModelEntity::ASSIGNMENT, CCopasiVector< T >::begin(), CStateTemplate::beginDependent(), CStateTemplate::beginIndependent(), buildApplyInitialValuesSequence(), buildInitialSequence(), CCopasiObject::buildUpdateSequence(), CModelEntity::compile(), CCopasiObject::dependsOn(), CCopasiVector< T >::end(), CStateTemplate::endDependent(), CStateTemplate::endFixed(), CStateTemplate::endIndependent(), CMetab::getConcentrationReference(), MNumMetabolitesReactionDependent, mNumMetabolitesReactionIndependent, mReorderNeeded, mSimulatedRefreshes, mSimulatedUpToDateObjects, mStateTemplate, mSteps, CStateTemplate::reorder(), and CStateTemplate::size().

Referenced by compile().

1484 {
1485  bool success = true;
1486 
1487  // We need to add each used model entity to the objects which need to be updated.
1488  mSimulatedUpToDateObjects.clear();
1489 
1490  // For CModelValues and CCompartment ODEs we need to add the Rate
1491  // For CMetab ODEs we need to add the Particle Rate
1494 
1495  for (; ppEntity != ppEntityEnd; ++ppEntity) //loop over all entities with ODEs
1496  mSimulatedUpToDateObjects.insert((*ppEntity)->getRateReference());
1497 
1498  // We do not add the rates for metabolites of type REACTION. These are automatically calculated
1499  // with dgemm in calculate derivatives based on the reaction fluxes added below.
1500  // In the case that other simulated values depend on such a rate this is taken care by
1501  // calculating all dependencies.
1502  // This mechanism may lead occasionally to multiple calculations of rates of metabolites when used
1503  // in assignments or ODEs. However this is acceptable and more than compensated by the performance
1504  // gains of dgemm.
1505 
1506  // Furthermore all reaction fluxes have to be calculated too (see CMetab REACTION above)
1509 
1510  for (; itReaction != endReaction; ++itReaction)
1511  mSimulatedUpToDateObjects.insert((*itReaction)->getParticleFluxReference());
1512 
1513  // We now detect unused assignments, i.e., the result of an assignment is not
1514  // used during updateSimulatedValues except for itself or another unused assignment.
1515  bool UnusedFound = true;
1516 
1517  std::set<const CCopasiObject * > Candidate;
1518  std::set< const CCopasiObject * >::iterator it;
1519  std::set< const CCopasiObject * >::iterator end = mSimulatedUpToDateObjects.end();
1520  CCopasiObject * pObject;
1521  CMetab * pMetab;
1522  ppEntityEnd = mStateTemplate.endDependent();
1523 
1524  while (UnusedFound)
1525  {
1526  UnusedFound = false;
1528  //now points to the first entity with assignment
1529 
1530  for (; ppEntity != ppEntityEnd; ++ppEntity) //over all entities with assignments
1531  if ((*ppEntity)->isUsed())
1532  {
1533  if ((*ppEntity)->getStatus() != ASSIGNMENT)
1534  pObject = *ppEntity;
1535  else if ((pMetab = dynamic_cast< CMetab *>(*ppEntity)) != NULL)
1536  pObject = pMetab->getConcentrationReference();
1537  else
1538  pObject = (*ppEntity)->getValueReference();
1539 
1540  Candidate.insert(pObject);
1541 
1542  for (it = mSimulatedUpToDateObjects.begin(), end = mSimulatedUpToDateObjects.end(); it != end; ++it)
1543  if (*it != pObject &&
1544  (*it)->dependsOn(Candidate))
1545  break;
1546 
1547  if (it == end)
1548  {
1549  UnusedFound = true;
1550  mReorderNeeded = true;
1551  (*ppEntity)->setUsed(false);
1552  }
1553 
1554  Candidate.erase(pObject);
1555  }
1556  }
1557 
1558  if (mReorderNeeded)
1559  {
1561  CModelEntity ** ppReorder = Reorder.array();
1562 
1563  ppEntity = mStateTemplate.beginIndependent();
1565 
1566  //range is for all entities with ODEs + all metabs dependent on Reactions
1567  for (; ppEntity != ppEntityEnd; ++ppEntity, ++ppReorder)
1568  *ppReorder = *ppEntity;
1569 
1570  // :TODO: This must be enhanced as the mMetaboliteX and the state template may get out of sync
1571  // when we use assignments for metabolites.
1572 
1573  // the entities with assignments are reordered according to the isUsed() flag
1574  ppEntityEnd = mStateTemplate.endDependent();
1575 
1576  for (; ppEntity != ppEntityEnd; ++ppEntity) //over all entities with assignments
1577  if ((*ppEntity)->isUsed())
1578  *ppReorder++ = *ppEntity;
1579 
1581 
1582  for (; ppEntity != ppEntityEnd; ++ppEntity) //again over all entities with assignments
1583  if (!(*ppEntity)->isUsed())
1584  *ppReorder++ = *ppEntity;
1585 
1586  ppEntityEnd = mStateTemplate.endFixed();
1587 
1588  for (; ppEntity != ppEntityEnd; ++ppEntity, ++ppReorder) //over all fixed entities
1589  *ppReorder = *ppEntity;
1590 
1591  mStateTemplate.reorder(Reorder);
1592  mReorderNeeded = false;
1593 
1594  // We need to recompile as pointers to values may have changed
1595  ppEntity = mStateTemplate.beginIndependent();
1596  ppEntityEnd = mStateTemplate.endFixed();
1597 
1598  for (; ppEntity != ppEntityEnd; ++ppEntity)
1599  (*ppEntity)->compile();
1600 
1601  itReaction = mSteps.begin();
1602  endReaction = mSteps.end();
1603 
1604  for (; itReaction != endReaction; ++itReaction)
1605  (*itReaction)->compile();
1606 
1607  // The compile might have broken some refresh pointers we need to rebuild the constant sequence
1610  }
1611 
1612  std::set< const CCopasiObject * > UpToDate;
1613 
1614  try
1615  {
1617  }
1618  catch (...)
1619  {
1620  mSimulatedRefreshes.clear();
1621  success = false;
1622  }
1623 
1624  return success;
1625 }
size_t mNumMetabolitesReactionIndependent
Definition: CModel.h:1441
iterator begin()
#define MNumMetabolitesReactionDependent
Definition: CModel.cpp:64
CModelEntity ** endDependent()
Definition: CState.cpp:211
Definition: CMetab.h:178
const size_t & size() const
Definition: CState.cpp:242
CModelEntity ** beginDependent()
Definition: CState.cpp:210
virtual bool compile()
std::set< const CCopasiObject * > mSimulatedUpToDateObjects
Definition: CModel.h:1285
iterator end()
CStateTemplate mStateTemplate
Definition: CModel.h:1279
bool mReorderNeeded
Definition: CModel.h:1512
CModelEntity ** endFixed()
Definition: CState.cpp:213
std::vector< Refresh * > mSimulatedRefreshes
Definition: CModel.h:1495
CModelEntity ** beginIndependent()
Definition: CState.cpp:208
bool buildApplyInitialValuesSequence()
Definition: CModel.cpp:1627
bool dependsOn(DataObjectSet candidates, const DataObjectSet &context=DataObjectSet()) const
CCopasiVectorNS< CReaction > mSteps
Definition: CModel.h:1339
std::vector< CType * >::iterator iterator
Definition: CCopasiVector.h:56
static std::vector< Refresh * > buildUpdateSequence(const DataObjectSet &objects, const DataObjectSet &uptoDateObjects, const DataObjectSet &context=DataObjectSet())
CModelEntity ** endIndependent()
Definition: CState.cpp:209
bool buildInitialSequence()
Definition: CModel.cpp:1395
void reorder(const CVector< CModelEntity * > &newOrder)
Definition: CState.cpp:98
CConcentrationReference * getConcentrationReference() const
Definition: CMetab.cpp:864
bool CModel::buildStateTemplate ( )
private

Build the state template for the model.

Returns
bool success

Definition at line 1262 of file CModel.cpp.

References CModelEntity::ASSIGNMENT, CCopasiVector< T >::begin(), CStateTemplate::beginIndependent(), CModelEntity::compile(), CCopasiVector< T >::end(), CStateTemplate::endFixed(), mCompartments, mMetabolitesX, mReorderNeeded, mStateTemplate, mSteps, mValues, CModelEntity::ODE, CStateTemplate::reorder(), CModelEntity::setUsed(), and CCopasiVector< T >::size().

Referenced by compile().

1263 {
1265  CModelEntity ** ppEntity = Entities.array();
1266 
1269 
1270  for (; itValue != endValue; ++itValue)
1271  if ((*itValue)->getStatus() == ODE)
1272  {
1273  *ppEntity = *itValue;
1274  (*ppEntity++)->setUsed(true);
1275  }
1276 
1279 
1280  for (; itCompartment != endCompartment; ++itCompartment)
1281  if ((*itCompartment)->getStatus() == ODE)
1282  {
1283  *ppEntity = *itCompartment;
1284  (*ppEntity++)->setUsed(true);
1285  }
1286 
1289 
1290  for (; itMetab != endMetab; ++itMetab)
1291  {
1292  if (!(*itMetab)->isUsed()) break;
1293 
1294  *ppEntity++ = *itMetab;
1295  }
1296 
1297  itCompartment = mCompartments.begin();
1298 
1299  for (; itCompartment != endCompartment; ++itCompartment)
1300  if ((*itCompartment)->getStatus() == ASSIGNMENT)
1301  {
1302  *ppEntity = *itCompartment;
1303  (*ppEntity++)->setUsed(true);
1304  }
1305 
1306  itValue = mValues.begin();
1307 
1308  for (; itValue != endValue; ++itValue)
1309  if ((*itValue)->getStatus() == ASSIGNMENT)
1310  {
1311  *ppEntity = *itValue;
1312  (*ppEntity++)->setUsed(true);
1313  }
1314 
1315  for (; itMetab != endMetab; ++itMetab)
1316  *ppEntity++ = *itMetab;
1317 
1318  itCompartment = mCompartments.begin();
1319 
1320  for (; itCompartment != endCompartment; ++itCompartment)
1321  if ((*itCompartment)->isFixed())
1322  *ppEntity++ = *itCompartment;
1323 
1324  itValue = mValues.begin();
1325 
1326  for (; itValue != endValue; ++itValue)
1327  if ((*itValue)->isFixed())
1328  *ppEntity++ = *itValue;
1329 
1330  mStateTemplate.reorder(Entities);
1331  mReorderNeeded = false;
1332 
1333  // Now all entities and reactions can be compiled
1334  ppEntity = mStateTemplate.beginIndependent();
1335  CModelEntity ** ppEntityEnd = mStateTemplate.endFixed();
1336 
1337  for (; ppEntity != ppEntityEnd; ++ppEntity)
1338  (*ppEntity)->compile();
1339 
1342 
1343  for (; itReaction != endReaction; ++itReaction)
1344  (*itReaction)->compile();
1345 
1346  return true;
1347 }
virtual size_t size() const
iterator begin()
CCopasiVectorNS< CCompartment > mCompartments
Definition: CModel.h:1324
CCopasiVectorN< CModelValue > mValues
Definition: CModel.h:1354
virtual bool compile()
iterator end()
CStateTemplate mStateTemplate
Definition: CModel.h:1279
bool mReorderNeeded
Definition: CModel.h:1512
CModelEntity ** endFixed()
Definition: CState.cpp:213
CCopasiVector< CMetab > mMetabolitesX
Definition: CModel.h:1334
void setUsed(const bool &used)
CModelEntity ** beginIndependent()
Definition: CState.cpp:208
CCopasiVectorNS< CReaction > mSteps
Definition: CModel.h:1339
std::vector< CType * >::iterator iterator
Definition: CCopasiVector.h:56
void reorder(const CVector< CModelEntity * > &newOrder)
Definition: CState.cpp:98
void CModel::buildStoi ( )

Build the Stoichiometry Matrix from the chemical equations of the steps

Definition at line 642 of file CModel.cpp.

References CProcessReport::addItem(), CMatrix< CType >::array(), CCopasiVector< T >::begin(), C_FLOAT64, C_INT32, CCopasiVector< T >::end(), CCopasiMessage::ERROR, CProcessReport::finishItem(), handleUnusedMetabolites(), initializeMetabolites(), MCReaction, mMetabolitesX, mNumMetabolitesODE, mNumMetabolitesReaction, mParticleFluxes, mpCompileHandler, mSteps, mStoiInternal, CProcessReport::progressItem(), CMatrix< CType >::resize(), CVector< CType >::resize(), and CCopasiVector< T >::size().

Referenced by compile().

643 {
644  unsigned C_INT32 i, numCols;
645 
647 
648  size_t numRows;
649  numRows = mNumMetabolitesReaction;
650  numCols = (unsigned C_INT32) mSteps.size();
651 
652  mParticleFluxes.resize(numCols);
653  mStoiInternal.resize(numRows, numCols);
654  mStoiInternal = 0.0;
655 
656  size_t hProcess;
657 
658  if (mpCompileHandler)
659  {
660  i = 0;
661  hProcess = mpCompileHandler->addItem("Building Stoichiometry",
662  i,
663  &numCols);
664  }
665 
666  C_FLOAT64 * pCol, *pColEnd;
667  pCol = mStoiInternal.array();
668  pColEnd = mStoiInternal.array() + numCols;
669 
670  C_FLOAT64 * pRow, *pRowEnd;
671  pRowEnd = mStoiInternal.array() + numRows * numCols;
672 
675 
676  for (; pCol < pColEnd; ++pCol, ++itStep)
677  {
678  if (mpCompileHandler && !mpCompileHandler->progressItem(hProcess)) return;
679 
680  // Since we are stepping through the reactions we can check whether
681  // the kinetic functions are usable.
682  if (!(*itStep)->getFunction()->isUsable())
684  (*itStep)->getObjectName().c_str(),
685  (*itStep)->getFunction()->getObjectName().c_str());
686 
687  const CCopasiVector< CChemEqElement > & Balance =
688  (*itStep)->getChemEq().getBalances();
691 
692  for (; itBalance != endBalance; ++itBalance)
693  {
694  const std::string & key = (*itBalance)->getMetaboliteKey();
695 
696  for (pRow = pCol, itMetab = mMetabolitesX.begin() + mNumMetabolitesODE;
697  pRow < pRowEnd;
698  pRow += numCols, ++itMetab)
699  if ((*itMetab)->getKey() == key)
700  {
701  *pRow = (*itBalance)->getMultiplicity();
702  break;
703  }
704  }
705  }
706 
707  // We need to have all unused and fixed metabolites at the end of mMetabolites.
708  // However we can only detect unused metabolites after building the
709  // stoichiometry matrix.
711 
712 #ifdef DEBUG_MATRIX
713  DebugFile << "Stoichiometry Matrix" << std::endl;
714  DebugFile << mStoiInternal << std::endl;
715 #endif
716 
717  if (mpCompileHandler)
718  mpCompileHandler->finishItem(hProcess);
719 
720  return;
721 }
virtual size_t size() const
iterator begin()
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
#define C_INT32
Definition: copasi.h:90
virtual bool progressItem(const size_t &handle)
iterator end()
CVector< C_FLOAT64 > mParticleFluxes
Definition: CModel.h:1349
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
CCopasiVector< CMetab > mMetabolitesX
Definition: CModel.h:1334
void initializeMetabolites()
Definition: CModel.cpp:942
bool handleUnusedMetabolites()
Definition: CModel.cpp:723
virtual bool finishItem(const size_t &handle)
virtual void resize(size_t rows, size_t cols, const bool &copy=false)
Definition: CMatrix.h:151
#define MCReaction
CProcessReport * mpCompileHandler
Definition: CModel.h:1485
size_t mNumMetabolitesReaction
Definition: CModel.h:1430
#define C_FLOAT64
Definition: copasi.h:92
CMatrix< C_FLOAT64 > mStoiInternal
Definition: CModel.h:1379
CCopasiVectorNS< CReaction > mSteps
Definition: CModel.h:1339
std::vector< CType * >::iterator iterator
Definition: CCopasiVector.h:56
size_t mNumMetabolitesODE
Definition: CModel.h:1425
virtual CType * array()
Definition: CMatrix.h:337
bool CModel::buildUserOrder ( )
private

Build the user order for the state template

Returns
bool success

Definition at line 1349 of file CModel.cpp.

References CVectorCore< CType >::array(), CCopasiVector< T >::begin(), CCopasiVector< T >::end(), CStateTemplate::getEntities(), CStateTemplate::getNumIndependent(), CStateTemplate::getUserOrder(), CModelEntity::isUsed(), mCompartments, mJacobianPivot, mMetabolites, MNumMetabolitesReactionDependent, mStateTemplate, mValues, CModelEntity::ODE, CModelEntity::REACTIONS, CVector< CType >::resize(), CStateTemplate::setUserOrder(), CVectorCore< CType >::size(), and CCopasiVector< T >::size().

Referenced by compile().

1350 {
1352  CModelEntity ** ppEntity = Entities.array();
1353 
1356 
1357  for (; itMetab != endMetab; ++itMetab)
1358  *ppEntity++ = *itMetab;;
1359 
1362 
1363  for (; itCompartment != endCompartment; ++itCompartment)
1364  *ppEntity++ = *itCompartment;
1365 
1368 
1369  for (; itValue != endValue; ++itValue)
1370  *ppEntity++ = *itValue;
1371 
1372  mStateTemplate.setUserOrder(Entities);
1373 
1375  //now sized to the number of entities with ODEs + all metabolites dependent on reactions
1376 
1377  const size_t * pUserOrder = mStateTemplate.getUserOrder().array();
1378  const size_t * pUserOrderEnd = pUserOrder + mStateTemplate.getUserOrder().size();
1379  ppEntity = mStateTemplate.getEntities();
1380 
1381  size_t i;
1382 
1383  for (i = 0; pUserOrder != pUserOrderEnd; ++pUserOrder)
1384  {
1385  const Status & Status = ppEntity[*pUserOrder]->getStatus();
1386 
1387  if (Status == ODE ||
1388  (Status == REACTIONS && ppEntity[*pUserOrder]->isUsed()))
1389  mJacobianPivot[i++] = *pUserOrder - 1;
1390  }
1391 
1392  return true;
1393 }
void setUserOrder(const CVector< CModelEntity * > &userOrder)
Definition: CState.cpp:189
size_t getNumIndependent() const
Definition: CState.cpp:222
virtual size_t size() const
iterator begin()
CCopasiVectorNS< CCompartment > mCompartments
Definition: CModel.h:1324
#define MNumMetabolitesReactionDependent
Definition: CModel.cpp:64
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
CCopasiVectorN< CModelValue > mValues
Definition: CModel.h:1354
CCopasiVector< CMetab > mMetabolites
Definition: CModel.h:1329
iterator end()
CStateTemplate mStateTemplate
Definition: CModel.h:1279
const bool & isUsed() const
size_t size() const
Definition: CVector.h:100
CType * array()
Definition: CVector.h:139
std::vector< CType * >::iterator iterator
Definition: CCopasiVector.h:56
const CVector< size_t > & getUserOrder() const
Definition: CState.cpp:201
CVector< size_t > mJacobianPivot
Definition: CModel.h:1415
CModelEntity ** getEntities()
Definition: CState.cpp:204
void CModel::calculateDerivatives ( C_FLOAT64 derivatives)

Calculate the changes of all model quantities determined by ODEs for the model in the current state. The parameter derivatives must at least provide space for state->getVariableNumberSize() double &param C_FLOAT64 * derivatives (output)

Definition at line 1903 of file CModel.cpp.

References CVectorCore< CType >::array(), CMatrix< CType >::array(), C_FLOAT64, C_INT, dgemm_(), CStateTemplate::getEntities(), CStateTemplate::getNumIndependent(), K, mNumMetabolitesReaction, mNumMetabolitesReactionIndependent, mParticleFluxes, mStateTemplate, mSteps, mStoi, and CCopasiVector< T >::size().

Referenced by CTSSAMethod::calculateDerivatives(), calculateJacobian(), CMathModel::calculateRootDerivatives(), CLyapWolfMethod::evalF(), CLsodaMethod::evalF(), CTrajectoryMethodDsaLsodar::evalF(), CTSSAMethod::evalF(), and CCSPMethod::step().

1904 {
1905  C_FLOAT64 * pTmp = derivatives;
1906 
1907  // First retrieve derivatives of quantities determined by ODE
1908  // The offset 1 is for the model time which is always the first
1909  // state variable.
1910  CModelEntity ** ppIt = mStateTemplate.getEntities() + 1;
1911  CModelEntity ** ppEnd =
1913 
1914  for (; ppIt != ppEnd; ++ppIt, ++pTmp)
1915  {
1916  *pTmp = (*ppIt)->getRate();
1917 
1918 #ifdef COPASI_DEBUG
1919 
1920  if (isnan(*pTmp))
1921  {
1922  std::cout << "Entity[" << ppIt - (mStateTemplate.getEntities() + 1) << "] is NaN" << std::endl;
1923  }
1924 
1925 #endif // COPASI_DEBUG
1926  }
1927 
1928  // Now calculate derivatives of all metabolites determined by reactions
1929  char T = 'N';
1930  C_INT M = 1;
1932  C_INT K = (C_INT) mSteps.size();
1933  C_FLOAT64 Alpha = 1.0;
1934  C_FLOAT64 Beta = 0.0;
1935 
1936  if (K != 0)
1937  dgemm_(&T, &T, &M, &N, &K, &Alpha, mParticleFluxes.array(), &M,
1938  mStoi.array(), &K, &Beta, pTmp, &M);
1939 }
#define C_INT
Definition: copasi.h:115
#define K
size_t getNumIndependent() const
Definition: CState.cpp:222
size_t mNumMetabolitesReactionIndependent
Definition: CModel.h:1441
virtual size_t size() const
CMatrix< C_FLOAT64 > mStoi
Definition: CModel.h:1389
CStateTemplate mStateTemplate
Definition: CModel.h:1279
CVector< C_FLOAT64 > mParticleFluxes
Definition: CModel.h:1349
int dgemm_(char *transa, char *transb, integer *m, integer *n, integer *k, doublereal *alpha, doublereal *a, integer *lda, doublereal *b, integer *ldb, doublereal *beta, doublereal *c, integer *ldc)
size_t mNumMetabolitesReaction
Definition: CModel.h:1430
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
CCopasiVectorNS< CReaction > mSteps
Definition: CModel.h:1339
virtual CType * array()
Definition: CMatrix.h:337
CModelEntity ** getEntities()
Definition: CState.cpp:204
void CModel::calculateDerivativesX ( C_FLOAT64 derivativesX)

Calculate the changes of all model quantities determined by ODEs for the reduced model in the current state. The parameter derivatives must at least provide space for state->getDependentNumberSize() double &param C_FLOAT64 * derivatives (output)

Definition at line 1941 of file CModel.cpp.

References CVectorCore< CType >::array(), CMatrix< CType >::array(), C_FLOAT64, C_INT, dgemm_(), CStateTemplate::getEntities(), CStateTemplate::getNumIndependent(), K, mNumMetabolitesReactionIndependent, mParticleFluxes, mRedStoi, mStateTemplate, mSteps, and CCopasiVector< T >::size().

Referenced by CNewtonMethod::calculateDerivativesX(), CTSSAMethod::calculateDerivativesX(), calculateJacobianX(), CLyapWolfMethod::evalF(), CLsodaMethod::evalF(), CTrajectoryMethodDsaLsodar::evalF(), CTSSAMethod::evalF(), and CCSPMethod::step().

1942 {
1943  C_FLOAT64 * pTmp = derivativesX;
1944 
1945  // First retrieve derivatives of quantities determined by ODE
1946  // The offset 1 is for the model time which is always the first
1947  // state variable.
1948  CModelEntity ** ppIt = mStateTemplate.getEntities() + 1;
1949  CModelEntity ** ppEnd =
1951 
1952  for (; ppIt != ppEnd; ++ppIt, ++pTmp)
1953  *pTmp = (*ppIt)->getRate();
1954 
1955  // Now calculate derivatives of the independent metabolites determined by reactions
1956  char T = 'N';
1957  C_INT M = 1;
1959  C_INT K = (C_INT) mSteps.size();
1960  C_FLOAT64 Alpha = 1.0;
1961  C_FLOAT64 Beta = 0.0;
1962 
1963  if (K != 0)
1964  dgemm_(&T, &T, &M, &N, &K, &Alpha, mParticleFluxes.array(), &M,
1965  mRedStoi.array(), &K, &Beta, pTmp, &M);
1966 }
#define C_INT
Definition: copasi.h:115
#define K
size_t getNumIndependent() const
Definition: CState.cpp:222
size_t mNumMetabolitesReactionIndependent
Definition: CModel.h:1441
virtual size_t size() const
CMatrix< C_FLOAT64 > mRedStoi
Definition: CModel.h:1394
CStateTemplate mStateTemplate
Definition: CModel.h:1279
CVector< C_FLOAT64 > mParticleFluxes
Definition: CModel.h:1349
int dgemm_(char *transa, char *transb, integer *m, integer *n, integer *k, doublereal *alpha, doublereal *a, integer *lda, doublereal *b, integer *ldb, doublereal *beta, doublereal *c, integer *ldc)
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
CCopasiVectorNS< CReaction > mSteps
Definition: CModel.h:1339
virtual CType * array()
Definition: CMatrix.h:337
CModelEntity ** getEntities()
Definition: CState.cpp:204
C_FLOAT64 CModel::calculateDivergence ( ) const

Calculates the divergence for the current state. calculateElasticityMatrix() needs to be called before. It makes only sense to use this method if the Jacobian is not also calculated. In this case it would be more efficient to use the trace of the Jacobian

Definition at line 2153 of file CModel.cpp.

References fatalError.

2154 {
2155  fatalError(); //not yet implemented
2156  return 0.0;
2157 }
#define fatalError()
void CModel::calculateElasticityMatrix ( const C_FLOAT64 factor,
const C_FLOAT64 resolution 
)

Calculates the elasticity matrix of the model for the current state and stores it in the provided matrix.

Parameters
CMatrix<C_FLOAT64 > & elasticityMatrix
constC_FLOAT64 & factor,
constC_FLOAT64 & resolution

Definition at line 1968 of file CModel.cpp.

References CMatrix< CType >::array(), CCopasiVector< T >::begin(), CStateTemplate::beginIndependent(), C_FLOAT64, CCopasiVector< T >::end(), CStateTemplate::endDependent(), CMetab::getCompartment(), CMetab::getConcentration(), CModelEntity::getValue(), mElasticities, mStateTemplate, mSteps, and CMatrix< CType >::numCols().

1970 {
1971  size_t Col;
1972  size_t nCol = mElasticities.numCols();
1973 
1974  C_FLOAT64 * itE;
1975  C_FLOAT64 * beginE = mElasticities.array();
1976 
1980 
1981  CModelEntity ** itEntity;
1982  CModelEntity ** beginEntity = mStateTemplate.beginIndependent();
1983  CModelEntity ** endEntity = mStateTemplate.endDependent();
1984 
1985  for (itEntity = beginEntity, Col = 0; itEntity != endEntity; ++itEntity, ++Col)
1986  {
1987  // :TODO: This only works for entities of type metabolites.
1988  // The scaling factor for other entities should be 1.
1989  const C_FLOAT64 invVolume =
1990  1.0 / static_cast<CMetab *>(*itEntity)->getCompartment()->getValue();
1991  C_FLOAT64 * pX =
1992  const_cast<C_FLOAT64 *>(&static_cast<CMetab *>(*itEntity)->getConcentration());
1993 
1994  for (itReaction = beginReaction, itE = beginE + Col;
1995  itReaction != endReaction;
1996  ++itReaction, itE += nCol)
1997  * itE = invVolume * (*itReaction)->calculatePartialDerivative(pX, factor, resolution);
1998  }
1999 
2000  // DebugFile << "CModel::calculateElasticityMatrix()" << std::endl;
2001  // DebugFile << mElasticities << std::endl;
2002 
2003  return;
2004 }
CMatrix< C_FLOAT64 > mElasticities
Definition: CModel.h:1404
iterator begin()
CModelEntity ** endDependent()
Definition: CState.cpp:211
Definition: CMetab.h:178
iterator end()
CStateTemplate mStateTemplate
Definition: CModel.h:1279
std::vector< CType * >::const_iterator const_iterator
Definition: CCopasiVector.h:57
CModelEntity ** beginIndependent()
Definition: CState.cpp:208
const C_FLOAT64 & getValue() const
#define C_FLOAT64
Definition: copasi.h:92
CCopasiVectorNS< CReaction > mSteps
Definition: CModel.h:1339
const C_FLOAT64 & getConcentration() const
Definition: CMetab.cpp:218
virtual size_t numCols() const
Definition: CMatrix.h:144
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
virtual CType * array()
Definition: CMatrix.h:337
void CModel::calculateJacobian ( CMatrix< C_FLOAT64 > &  jacobian,
const C_FLOAT64 derivationFactor,
const C_FLOAT64 resolution 
)

Calculates the jacobian of the full model for the current state and stores it in the provided matrix. calculateElasticityMatrix() needs to be called before.

Parameters
CMatrix<C_FLOAT64 > & jacobian
constC_FLOAT64 & derivationFactor,
constC_FLOAT64 & resolution

Definition at line 2006 of file CModel.cpp.

References CVectorCore< CType >::array(), CMatrix< CType >::array(), CState::beginIndependent(), C_FLOAT64, calculateDerivatives(), CState::getNumIndependent(), max, mCurrentState, MNumMetabolitesReactionDependent, CMatrix< CType >::resize(), and updateSimulatedValues().

Referenced by CSteadyStateMethod::doJacobian(), and CCSPMethod::step().

2009 {
2010  C_FLOAT64 DerivationFactor = std::max(derivationFactor, 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon());
2011 
2012  size_t Dim =
2014  //Dim now contains the number of entities with ODEs + number of metabs depending on reactions.
2015 
2016  size_t Col;
2017 
2018  jacobian.resize(Dim, Dim);
2019 
2020  C_FLOAT64 Store;
2021  C_FLOAT64 X1;
2022  C_FLOAT64 X2;
2023  C_FLOAT64 InvDelta;
2024 
2025  CVector< C_FLOAT64 > Y1(Dim);
2026  CVector< C_FLOAT64 > Y2(Dim);
2027 
2028  C_FLOAT64 * pY1;
2029  C_FLOAT64 * pY2;
2030 
2032  C_FLOAT64 * pXEnd = pX + Dim;
2033 
2034  C_FLOAT64 * pJacobian;
2035  C_FLOAT64 * pJacobianEnd = jacobian.array() + Dim * Dim;
2036 
2037  for (Col = 0; pX != pXEnd; ++pX, ++Col)
2038  {
2039  Store = *pX;
2040 
2041  // We only need to make sure that we do not have an underflow problem
2042  if (fabs(Store) < DerivationFactor)
2043  {
2044  X1 = 0.0;
2045 
2046  if (Store < 0.0)
2047  X2 = -2.0 * DerivationFactor;
2048  else
2049  X2 = 2.0 * DerivationFactor;
2050  }
2051  else
2052  {
2053  X1 = Store * (1.0 + DerivationFactor);
2054  X2 = Store * (1.0 - DerivationFactor);
2055  }
2056 
2057  InvDelta = 1.0 / (X2 - X1);
2058 
2059  *pX = X1;
2060  updateSimulatedValues(false);
2061  calculateDerivatives(Y1.array());
2062 
2063  *pX = X2;
2064  updateSimulatedValues(false);
2065  calculateDerivatives(Y2.array());
2066 
2067  *pX = Store;
2068 
2069  pJacobian = jacobian.array() + Col;
2070  pY1 = Y1.array();
2071  pY2 = Y2.array();
2072 
2073  for (; pJacobian < pJacobianEnd; pJacobian += Dim, ++pY1, ++pY2)
2074  * pJacobian = (*pY2 - *pY1) * InvDelta;
2075  }
2076 
2077  updateSimulatedValues(false);
2078 
2079  return;
2080 }
void updateSimulatedValues(const bool &updateMoieties)
Definition: CModel.cpp:1851
#define MNumMetabolitesReactionDependent
Definition: CModel.cpp:64
size_t getNumIndependent() const
Definition: CState.cpp:342
virtual void resize(size_t rows, size_t cols, const bool &copy=false)
Definition: CMatrix.h:151
#define C_FLOAT64
Definition: copasi.h:92
void calculateDerivatives(C_FLOAT64 *derivatives)
Definition: CModel.cpp:1903
virtual CType * array()
Definition: CMatrix.h:337
C_FLOAT64 * beginIndependent()
Definition: CState.cpp:328
CState mCurrentState
Definition: CModel.h:1274
#define max(a, b)
Definition: f2c.h:176
void CModel::calculateJacobianX ( CMatrix< C_FLOAT64 > &  jacobianX,
const C_FLOAT64 derivationFactor,
const C_FLOAT64 resolution 
)

Calculates the Jacobian of the reduced model for the current state and stores it in the provided matrix. calculateElasticityMatrix() needs to be called before.

Parameters
constC_FLOAT64 & derivationFactor,
constC_FLOAT64 & resolution
CMatrix<C_FLOAT64 > & jacobianX

Definition at line 2082 of file CModel.cpp.

References CVectorCore< CType >::array(), CMatrix< CType >::array(), CState::beginIndependent(), C_FLOAT64, calculateDerivativesX(), CState::getNumIndependent(), max, mCurrentState, CMatrix< CType >::resize(), and updateSimulatedValues().

Referenced by CLNAMethod::calculateCovarianceMatrixReduced(), CSteadyStateMethod::calculateJacobianX(), CSteadyStateMethod::doJacobian(), CLyapWolfMethod::evalF(), CILDMMethod::step(), CILDMModifiedMethod::step(), and CCSPMethod::step().

2085 {
2086  C_FLOAT64 DerivationFactor = std::max(derivationFactor, 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon());
2087 
2088  size_t Dim = mCurrentState.getNumIndependent();
2089  size_t Col;
2090 
2091  jacobianX.resize(Dim, Dim);
2092 
2093  C_FLOAT64 Store;
2094  C_FLOAT64 X1;
2095  C_FLOAT64 X2;
2096  C_FLOAT64 InvDelta;
2097 
2098  CVector< C_FLOAT64 > Y1(Dim);
2099  CVector< C_FLOAT64 > Y2(Dim);
2100 
2101  C_FLOAT64 * pY1;
2102  C_FLOAT64 * pY2;
2103 
2105  C_FLOAT64 * pXEnd = pX + Dim;
2106 
2107  C_FLOAT64 * pJacobian;
2108  C_FLOAT64 * pJacobianEnd = jacobianX.array() + Dim * Dim;
2109 
2110  for (Col = 0; pX != pXEnd; ++pX, ++Col)
2111  {
2112  Store = *pX;
2113 
2114  // We only need to make sure that we do not have an underflow problem
2115  if (fabs(Store) < DerivationFactor)
2116  {
2117  X1 = 0.0;
2118 
2119  if (Store < 0.0)
2120  X2 = -2.0 * DerivationFactor;
2121  else
2122  X2 = 2.0 * DerivationFactor;;
2123  }
2124  else
2125  {
2126  X1 = Store * (1.0 + DerivationFactor);
2127  X2 = Store * (1.0 - DerivationFactor);
2128  }
2129 
2130  InvDelta = 1.0 / (X2 - X1);
2131 
2132  *pX = X1;
2133  updateSimulatedValues(true);
2134  calculateDerivativesX(Y1.array());
2135 
2136  *pX = X2;
2137  updateSimulatedValues(true);
2138  calculateDerivativesX(Y2.array());
2139 
2140  *pX = Store;
2141 
2142  pJacobian = jacobianX.array() + Col;
2143  pY1 = Y1.array();
2144  pY2 = Y2.array();
2145 
2146  for (; pJacobian < pJacobianEnd; pJacobian += Dim, ++pY1, ++pY2)
2147  * pJacobian = (*pY2 - *pY1) * InvDelta;
2148  }
2149 
2150  updateSimulatedValues(true);
2151 }
void updateSimulatedValues(const bool &updateMoieties)
Definition: CModel.cpp:1851
size_t getNumIndependent() const
Definition: CState.cpp:342
virtual void resize(size_t rows, size_t cols, const bool &copy=false)
Definition: CMatrix.h:151
void calculateDerivativesX(C_FLOAT64 *derivativesX)
Definition: CModel.cpp:1941
#define C_FLOAT64
Definition: copasi.h:92
virtual CType * array()
Definition: CMatrix.h:337
C_FLOAT64 * beginIndependent()
Definition: CState.cpp:328
CState mCurrentState
Definition: CModel.h:1274
#define max(a, b)
Definition: f2c.h:176
void CModel::calculateRootDerivatives ( CVector< C_FLOAT64 > &  rootDerivatives)

Calculate the time derivative of all roots

Parameters
CVector<C_FLOAT64 > & rootDerivatives

Definition at line 4712 of file CModel.cpp.

References CMathModel::calculateRootDerivatives(), and mpMathModel.

Referenced by CLsodaMethod::createRootMask().

4713 {
4714  return mpMathModel->calculateRootDerivatives(rootDerivatives);
4715 }
CMathModel * mpMathModel
Definition: CModel.h:1532
void calculateRootDerivatives(CVector< C_FLOAT64 > &rootDerivatives)
Definition: CMathModel.cpp:417
void CModel::clearMoieties ( )
private

Clear all references to moieties

Definition at line 1257 of file CModel.cpp.

References CCopasiVector< T >::clear(), and mMoieties.

Referenced by removeEvent(), removeMetabolite(), and removeReaction().

1258 {
1259  mMoieties.clear();
1260 }
virtual void clear()
CCopasiVector< CMoiety > mMoieties
Definition: CModel.h:1374
bool CModel::compile ( )
privatevirtual

Compile the model value. This is only needed for status ASIGNMENT and ODE.

Returns
bool success

Reimplemented from CModelEntity.

Definition at line 381 of file CModel.cpp.

References CCopasiObject::addDirectDependency(), CProcessReport::addItem(), CCopasiVector< T >::begin(), buildApplyInitialValuesSequence(), buildDependencyGraphs(), buildInitialSequence(), buildLinkZero(), buildMoieties(), buildNonSimulatedSequence(), buildRedStoi(), buildSimulatedSequence(), buildStateTemplate(), buildStoi(), buildUserOrder(), C_INT32, CLinkMatrix::clearPivoting(), CMathModel::compile(), compileEvents(), CModelParameterSet::createFromModel(), determineIsAutonomous(), CCopasiVector< T >::end(), CProcessReport::finishItem(), mApplyInitialValuesRefreshes, mCompileIsNecessary, mInitialRefreshes, mIsAutonomous, mL, mMetabolitesX, mNonSimulatedRefreshes, mParameterSet, mpCompileHandler, mpMathModel, CModelEntity::mpValueReference, mSimulatedRefreshes, pdelete, CProcessReport::progressItem(), CRenameHandler::setEnabled(), CProcessReport::setName(), CCopasiObject::smpRenameHandler, and updateMatrixAnnotations().

Referenced by CModel(), compileIfNecessary(), and load().

382 {
383  bool success = true;
384 
386  {
388  }
389 
391 
393 
394  unsigned C_INT32 CompileStep = 0;
395  size_t hCompileStep;
396 
397  if (mpCompileHandler)
398  {
399  mpCompileHandler->setName("Compiling model...");
400  unsigned C_INT32 totalSteps = 7;
401  hCompileStep = mpCompileHandler->addItem("Compile Process",
402  CompileStep,
403  &totalSteps);
404  }
405 
406  // To assure that we do not produce access violations we clear the refresh sequences
407  // first
408  mInitialRefreshes.clear();
409  mSimulatedRefreshes.clear();
411  mNonSimulatedRefreshes.clear();
412 
413  CompileStep = 0;
414 
415  if (mpCompileHandler && !mpCompileHandler->progressItem(hCompileStep))
416  {
417  success = false;
418  goto finish;
419  }
420 
421  buildStoi();
422  CompileStep = 1;
423 
424  if (mpCompileHandler && !mpCompileHandler->progressItem(hCompileStep))
425  {
426  success = false;
427  goto finish;
428  }
429 
430  buildLinkZero();
431  CompileStep = 2;
432 
433  if (mpCompileHandler && !mpCompileHandler->progressItem(hCompileStep))
434  {
435  success = false;
436  goto finish;
437  }
438 
439  buildRedStoi();
440  CompileStep = 3;
441 
442  if (mpCompileHandler && !mpCompileHandler->progressItem(hCompileStep))
443  {
444  success = false;
445  goto finish;
446  }
447 
448  buildMoieties();
449  CompileStep = 4;
450 
451  if (mpCompileHandler && !mpCompileHandler->progressItem(hCompileStep))
452  {
453  success = false;
454  goto finish;
455  }
456 
458  CompileStep = 5;
459 
460  if (mpCompileHandler && !mpCompileHandler->progressItem(hCompileStep))
461  {
462  success = false;
463  goto finish;
464  }
465 
466  try
467  {
468  success &= buildInitialSequence();
469  success &= buildApplyInitialValuesSequence();
470  success &= buildSimulatedSequence();
471  success &= buildNonSimulatedSequence();
472  }
473  catch (...)
474  {
475  success = false;
476  }
477 
478  CompileStep = 6;
479 
480  if (mpCompileHandler && !mpCompileHandler->progressItem(hCompileStep))
481  {
482  success = false;
483  goto finish;
484  }
485 
486  buildUserOrder();
487 
488  if (mpCompileHandler) mpCompileHandler->finishItem(hCompileStep);
489 
490  {
493 
494  for (; itSpecies != endSpecies; ++itSpecies)
495  {
496  (*itSpecies)->compileIsInitialConcentrationChangeAllowed();
497  }
498  }
499 
500  //update annotations
502 
503  success &= compileEvents();
504  success &= mpMathModel->compile(this);
505 
506  if (!success)
507  {
508  mIsAutonomous = false;
509  }
510  else
511  {
512  mCompileIsNecessary = false;
514  }
515 
516  //writeDependenciesToDotFile();
517 
519 
520 #ifdef USE_MATH_CONTAINER
521  pdelete(mpMathContainer);
522  mpMathContainer = new CMathContainer(*this);
523 
524  // CMathContainer CopyModel(MathModel);
525 #endif // USE_MATH_CONTAINER
526 
527  // Update the parameter set
529 
530 finish:
531 
532  // Since we have applied the pivot to the stoichiometry matrix and the species
533  // we do not need them any longer. In fact it is detrimental if other functions rely
534  // on consistency between the stoichiometry matrix, reduced stoichiometry matrix and the Link matrix..
535  mL.clearPivoting();
536 
538  {
540  }
541 
542  mCompileIsNecessary = !success;
543 
544  return success;
545 }
#define pdelete(p)
Definition: copasi.h:215
bool mIsAutonomous
Definition: CModel.h:1517
bool buildUserOrder()
Definition: CModel.cpp:1349
void buildRedStoi()
Definition: CModel.cpp:829
CModelParameterSet mParameterSet
Definition: CModel.h:1359
static CRenameHandler * smpRenameHandler
virtual bool setName(const std::string &name)
iterator begin()
bool buildNonSimulatedSequence()
Definition: CModel.cpp:1678
void clearPivoting()
#define C_INT32
Definition: copasi.h:90
bool buildStateTemplate()
Definition: CModel.cpp:1262
CLinkMatrix mL
Definition: CModel.h:1446
std::vector< Refresh * > mNonSimulatedRefreshes
Definition: CModel.h:1507
virtual bool progressItem(const size_t &handle)
CMathModel * mpMathModel
Definition: CModel.h:1532
std::vector< Refresh * > mApplyInitialValuesRefreshes
Definition: CModel.h:1501
iterator end()
void addDirectDependency(const CCopasiObject *pObject)
bool buildDependencyGraphs()
Definition: CModel.cpp:547
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
void determineIsAutonomous()
Definition: CModel.cpp:3959
CCopasiVector< CMetab > mMetabolitesX
Definition: CModel.h:1334
std::vector< Refresh * > mInitialRefreshes
Definition: CModel.h:1490
bool mCompileIsNecessary
Definition: CModel.h:1479
std::vector< Refresh * > mSimulatedRefreshes
Definition: CModel.h:1495
virtual bool finishItem(const size_t &handle)
bool buildApplyInitialValuesSequence()
Definition: CModel.cpp:1627
void buildStoi()
Definition: CModel.cpp:642
CCopasiObjectReference< C_FLOAT64 > * mpValueReference
Definition: CModelValue.h:357
CProcessReport * mpCompileHandler
Definition: CModel.h:1485
void updateMatrixAnnotations()
Definition: CModel.cpp:863
void buildLinkZero()
Definition: CModel.cpp:3946
void buildMoieties()
Definition: CModel.cpp:905
bool compileEvents()
Definition: CModel.cpp:4116
bool buildInitialSequence()
Definition: CModel.cpp:1395
bool compile(CModel *pModel)
Definition: CMathModel.cpp:58
virtual void setEnabled(const bool &enabled)=0
bool buildSimulatedSequence()
Definition: CModel.cpp:1483
bool CModel::compileEvents ( )
private

Compile the events

Returns
bool success

Definition at line 4116 of file CModel.cpp.

References CCopasiVector< T >::begin(), CCopasiVector< T >::end(), and mEvents.

Referenced by compile().

4117 {
4118  bool success = true;
4119 
4120  std::vector< CCopasiContainer * > ListOfContainer;
4121 
4124 
4125  for (; it != end; ++ it)
4126  {
4127  success &= (*it)->compile(ListOfContainer);
4128  }
4129 
4130  return success;
4131 }
CCopasiVectorN< CEvent > mEvents
Definition: CModel.h:1344
iterator begin()
iterator end()
bool CModel::compileIfNecessary ( CProcessReport pProcessReport)

Compile the model if necessary

Parameters
CProcessReport*pProcessReport
Returns
bool success

Definition at line 612 of file CModel.cpp.

References compile(), mCompileIsNecessary, and mpCompileHandler.

Referenced by appendDependentCompartments(), appendDependentEvents(), appendDependentMetabolites(), appendDependentModelValues(), appendDependentReactions(), DataModelGUI::buildChangedObjects(), CCopasiDataModel::commonAfterLoad(), CModelExpansion::copyCompleteModel(), CCrossSectionTask::createEvent(), CModelExpansion::createLinearArray(), test000097::createModel(), CModelExpansion::createRectangularArray(), CCopasiDataModel::exportMathModel(), CCopasiDataModel::exportMathModelToString(), CCopasiDataModel::exportSBML(), CCopasiDataModel::exportSBMLToString(), forceCompile(), COscillationProblem::initialize(), CLNATask::initialize(), COptProblem::initialize(), CMCATask::initialize(), CCopasiTask::initialize(), CQUpdatesWidget::loadWidget(), CCopasiDataModel::saveModel(), SBMLImporter::setInitialValues(), CModelAdd::simpleCall(), CModelMerging::simpleCall(), CModelExpansion::simpleCall(), CopasiUI3Window::slotApplyInitialState(), CopasiUI3Window::slotUpdateInitialState(), CQSteadyStateResult::slotUpdateModel(), test000058::test_bug1025_10(), test000058::test_bug1025_6(), test000058::test_bug1025_7(), test000058::test_bug1025_8(), test000058::test_bug1025_9(), test000059::test_unique_id_11(), test000059::test_unique_id_12(), test000059::test_unique_id_13(), test000059::test_unique_id_14(), test000059::test_unique_id_15(), test000059::test_unique_id_16(), updateInitialValues(), and CSensTask::updateMatrices().

613 {
614  bool success = true;
615 
617  {
618  mpCompileHandler = pProcessReport;
619 
620  try
621  {
622  success &= compile();
623  }
624 
625  catch (...)
626  {
627  success = false;
628  }
629 
630  mpCompileHandler = NULL;
631  }
632 
633  return success;
634 }
bool compile()
Definition: CModel.cpp:381
bool mCompileIsNecessary
Definition: CModel.h:1479
CProcessReport * mpCompileHandler
Definition: CModel.h:1485
bool CModel::convert2NonReversible ( )

Converts the set of reactions to a set of reactions where all reactions are irreversible.

Definition at line 3205 of file CModel.cpp.

References CFunctionDB::addAndAdaptName(), CReaction::addModifier(), CReaction::addProduct(), CReaction::addSubstrate(), appendDependentCompartments(), appendDependentEvents(), appendDependentMetabolites(), appendDependentModelValues(), CModelEntity::ASSIGNMENT, CCopasiVector< T >::begin(), CReaction::compile(), createReaction(), CCopasiVector< T >::end(), CCopasiMessage::ERROR, findFunction(), CFunctionParameter::FLOAT64, CEvent::getAssignments(), CReaction::getChemEq(), CCopasiObject::getCN(), CEvent::getDelayExpression(), CCopasiObject::getDirectDependencies(), CModelEntity::getExpression(), CReaction::getFluxReference(), CReaction::getFunction(), CCopasiRootContainer::getFunctionList(), CReaction::getFunctionParameters(), CModelEntity::getInitialExpression(), CCopasiObject::getObjectName(), CCopasiParameterGroup::getParameter(), CReaction::getParameterMapping(), CReaction::getParameters(), CReaction::getParameterValue(), CReaction::getParticleFluxReference(), CEvent::getPriorityExpression(), CChemEq::getProducts(), getReactions(), CModelEntity::getStatus(), CChemEq::getSubstrates(), CEvent::getTriggerExpression(), CFunctionParameter::getType(), CFunctionParameter::getUsage(), CCopasiParameter::getValueReference(), CReaction::isLocalParameter(), mCompartments, MCReaction, mEvents, mMetabolitesX, CFunctionParameter::MODIFIER, mValues, CFunctionParameter::PARAMETER, pdelete, CFunctionParameter::PRODUCT, setCompileFlag(), CEvent::setDelayExpression(), CModelEntity::setExpression(), CReaction::setFunction(), CModelEntity::setInitialExpression(), CReaction::setParameterMapping(), CReaction::setParameterMappingVector(), CReaction::setParameterValue(), CEvent::setPriorityExpression(), CReaction::setReversible(), CEvent::setTriggerExpression(), CFunctionParameters::size(), CCopasiVector< T >::size(), CFunction::splitFunction(), stringReplace(), and CFunctionParameter::SUBSTRATE.

Referenced by CopasiUI3Window::slotConvertToIrreversible().

3206 {
3207  // TODO check if there are any reversible reactions
3208  // TODO warn the user
3209  // TODO tell the GUI about changes -> not from here
3210  // TODO generate report ?
3211  // TODO check if newly generated reaction names are valid
3212  // TODO map, so that the same function is split only once
3213 
3214  bool success = true;
3215 
3216  std::vector< CReaction * > reactionsToDelete;
3217 
3218  CReaction *reac0, *reac1, *reac2;
3219  std::string fn, rn1, rn2;
3220 
3221  //CModel* model = dynamic_cast< CModel * >(CCopasiRootContainer::getKeyFactory()->get(objKey));
3222  //if (!model) return false;
3223 
3224  CCopasiVectorN< CReaction > & steps = this->getReactions();
3225 
3226  size_t i, imax = steps.size();
3227 
3228  for (i = 0; i < imax; ++i)
3229  if (steps[i]->isReversible())
3230  {
3231  std::vector< std::pair< const CCopasiObject * , const CCopasiObject * > > ParameterMap;
3232 
3233  reac0 = steps[i];
3234  rn1 = reac0->getObjectName() + " (forward)";
3235  rn2 = reac0->getObjectName() + " (backward)";
3236 
3237  fn = reac0->getFunction()->getObjectName();
3238 
3239  const CFunction* pFunc = reac0->getFunction();
3240 
3241  bool massaction = (fn == "Mass action (reversible)");
3242 
3243  std::pair<CFunction *, CFunction *> tmp;
3244 
3245  if (massaction)
3246  {
3247  //set functions to mass action (irrev)
3248  tmp.first = dynamic_cast<CFunction*>
3249  (CCopasiRootContainer::getFunctionList()-> findFunction("Mass action (irreversible)"));
3250  assert(tmp.first);
3251  tmp.second = tmp.first;
3252  }
3253  else //not mass action
3254  {
3255  //try splitting
3256  tmp = pFunc->splitFunction(NULL, pFunc->getObjectName() + " (forward part)",
3257  pFunc->getObjectName() + " (backward part)");
3258 
3259  if ((tmp.first == NULL) || (tmp.second == NULL))
3260  {
3261  // Create a message that the conversion for this reaction failed.
3263  reac0->getObjectName().c_str(), fn.c_str());
3264  success = false;
3265 
3266  pdelete(tmp.first);
3267  pdelete(tmp.second);
3268  continue;
3269  }
3270 
3271  tmp.first = CCopasiRootContainer::getFunctionList()->addAndAdaptName(tmp.first);
3272 
3273  tmp.second = CCopasiRootContainer::getFunctionList()->addAndAdaptName(tmp.second);
3274  }
3275 
3276  size_t i, imax;
3277 
3278  //**** create 1st reaction.
3279  reac1 = createReaction(rn1);
3280  reac1->setReversible(false);
3281  //substrates
3282  imax = reac0->getChemEq().getSubstrates().size();
3283 
3284  for (i = 0; i < imax; ++i)
3285  reac1->addSubstrate(reac0->getChemEq().getSubstrates()[i]->getMetaboliteKey(),
3286  reac0->getChemEq().getSubstrates()[i]->getMultiplicity());
3287 
3288  //products
3289  imax = reac0->getChemEq().getProducts().size();
3290 
3291  for (i = 0; i < imax; ++i)
3292  reac1->addProduct(reac0->getChemEq().getProducts()[i]->getMetaboliteKey(),
3293  reac0->getChemEq().getProducts()[i]->getMultiplicity());
3294 
3295  //function
3296  reac1->setFunction(tmp.first);
3297 
3298  //**** create 2nd reaction.
3299  reac2 = createReaction(rn2);
3300  reac2->setReversible(false);
3301  //substrates -> products
3302  imax = reac0->getChemEq().getSubstrates().size();
3303 
3304  for (i = 0; i < imax; ++i)
3305  reac2->addProduct(reac0->getChemEq().getSubstrates()[i]->getMetaboliteKey(),
3306  reac0->getChemEq().getSubstrates()[i]->getMultiplicity());
3307 
3308  //products -> substrates
3309  imax = reac0->getChemEq().getProducts().size();
3310 
3311  for (i = 0; i < imax; ++i)
3312  reac2->addSubstrate(reac0->getChemEq().getProducts()[i]->getMetaboliteKey(),
3313  reac0->getChemEq().getProducts()[i]->getMultiplicity());
3314 
3315  //function
3316  reac2->setFunction(tmp.second);
3317 
3318  //mapping for both reactions
3319  if (massaction)
3320  {
3321  // the parameter names of the massaction kinetics are hardcoded here.
3322  if (reac0->isLocalParameter("k1"))
3323  reac1->setParameterValue("k1", reac0->getParameterValue("k1"));
3324  else
3325  reac1->setParameterMapping("k1", reac0->getParameterMapping("k1")[0]);
3326 
3327  reac1->setParameterMappingVector("substrate", reac0->getParameterMapping("substrate"));
3328 
3329  if (reac0->isLocalParameter("k2"))
3330  reac2->setParameterValue("k1", reac0->getParameterValue("k2"));
3331  else
3332  reac2->setParameterMapping("k1", reac0->getParameterMapping("k2")[0]);
3333 
3334  reac2->setParameterMappingVector("substrate", reac0->getParameterMapping("product"));
3335 
3336  // Bug 2143: We need to replace any occurrence of the reaction parameter of the
3337  // reversible reaction with its replacement in the forward or backwards reaction
3338  ParameterMap.push_back(std::make_pair(reac0->getParameters().getParameter("k1")->getValueReference(),
3339  reac1->getParameters().getParameter("k1")->getValueReference()));
3340  ParameterMap.push_back(std::make_pair(reac0->getParameters().getParameter("k2")->getValueReference(),
3341  reac2->getParameters().getParameter("k1")->getValueReference()));
3342  }
3343  else //not mass action
3344  {
3345  const CFunctionParameters & fps = reac0->getFunctionParameters();
3346  imax = fps.size();
3347 
3348  for (i = 0; i < imax; ++i)
3349  {
3350  const CFunctionParameter * fp = fps[i];
3351  assert(fp);
3352  assert(fp->getType() == CFunctionParameter::FLOAT64);
3353 
3354  switch (fp->getUsage())
3355  {
3357  reac1->setParameterMapping(fp->getObjectName(),
3358  reac0->getParameterMapping(fp->getObjectName())[0]);
3359 
3360  // It is possible (see Bug 1830) that the split function may have additional modifier.
3361  // This will happen e.g. if the product is referenced in the forward part of the reaction.
3362  if (reac2->setParameterMapping(fp->getObjectName(),
3363  reac0->getParameterMapping(fp->getObjectName())[0]))
3364  {
3365  reac2->addModifier(reac0->getParameterMapping(fp->getObjectName())[0]);
3366  }
3367 
3368  break;
3369 
3371 
3372  // It is possible (see Bug 1830) that the split function may have additional modifier.
3373  // This will happen e.g. if the product is referenced in the forward part of the reaction.
3374  if (reac1->setParameterMapping(fp->getObjectName(),
3375  reac0->getParameterMapping(fp->getObjectName())[0]))
3376  {
3377  reac1->addModifier(reac0->getParameterMapping(fp->getObjectName())[0]);
3378  }
3379 
3380  reac2->setParameterMapping(fp->getObjectName(),
3381  reac0->getParameterMapping(fp->getObjectName())[0]);
3382  break;
3383 
3385 
3386  if (reac1->setParameterMapping(fp->getObjectName(),
3387  reac0->getParameterMapping(fp->getObjectName())[0]))
3388  {
3389  // Add the modifier
3390  reac1->addModifier(reac0->getParameterMapping(fp->getObjectName())[0]);
3391  }
3392 
3393  if (reac2->setParameterMapping(fp->getObjectName(),
3394  reac0->getParameterMapping(fp->getObjectName())[0]))
3395  {
3396  // Add the modifier
3397  reac2->addModifier(reac0->getParameterMapping(fp->getObjectName())[0]);
3398  }
3399 
3400  break;
3401 
3403 
3404  if (reac0->isLocalParameter(fp->getObjectName()))
3405  {
3406 
3407  reac1->setParameterValue(fp->getObjectName(),
3408  reac0->getParameterValue(fp->getObjectName()));
3409  reac2->setParameterValue(fp->getObjectName(),
3410  reac0->getParameterValue(fp->getObjectName()));
3411  }
3412  else
3413  {
3414  reac1->setParameterMapping(fp->getObjectName(),
3415  reac0->getParameterMapping(fp->getObjectName())[0]);
3416  reac2->setParameterMapping(fp->getObjectName(),
3417  reac0->getParameterMapping(fp->getObjectName())[0]);
3418  }
3419 
3420  // Bug 2143: We need to replace any occurrence of the reaction parameter of the
3421  // reversible reaction with its replacement in the forward or backwards reaction
3422  {
3423  CCopasiParameter * pOldParameter = reac0->getParameters().getParameter(fp->getObjectName());
3424  CCopasiParameter * pNewParameter = reac1->getParameters().getParameter(fp->getObjectName());
3425 
3426  if (pNewParameter == NULL)
3427  {
3428  pNewParameter = reac2->getParameters().getParameter(fp->getObjectName());
3429  }
3430 
3431  ParameterMap.push_back(std::make_pair(pOldParameter->getValueReference(), pNewParameter->getValueReference()));
3432  }
3433 
3434  break;
3435 
3436  default:
3437  reac1->setParameterMapping(fp->getObjectName(),
3438  reac0->getParameterMapping(fp->getObjectName())[0]);
3439  reac2->setParameterMapping(fp->getObjectName(),
3440  reac0->getParameterMapping(fp->getObjectName())[0]);
3441  break;
3442  }
3443  }
3444  }
3445 
3446  reac1->compile();
3447  reac2->compile();
3448 
3449  std::string Old;
3450  std::string New;
3451  std::string Infix;
3452 
3453  // Bug 2143: We need to replace any occurrence of the reaction parameter of the
3454  // reversible reaction with its replacement in the forward or backwards reaction
3455  std::vector< std::pair< const CCopasiObject *, const CCopasiObject * > >::const_iterator itParameter = ParameterMap.begin();
3456  std::vector< std::pair< const CCopasiObject *, const CCopasiObject * > >::const_iterator endParameter = ParameterMap.end();
3457 
3458  for (; itParameter != endParameter; ++itParameter)
3459  {
3460  Old = "<" + itParameter->first->getCN() + ">";
3461  New = "<" + itParameter->second->getCN() + ">";
3462 
3463  // We need to find all expressions which reference the old parameter (first value of the itParameter)
3464  // Compartments (expression, initial expression)
3467 
3468  for (; itComp != endComp; ++itComp)
3469  {
3470  const CExpression * pExpression = (*itComp)->getExpressionPtr();
3471 
3472  if (pExpression != NULL)
3473  {
3474  const CCopasiObject::DataObjectSet & Dependencies = pExpression->getDirectDependencies();
3475 
3476  if (Dependencies.find(itParameter->first) != Dependencies.end())
3477  {
3478  Infix = (*itComp)->getExpression();
3479  stringReplace(Infix, Old, New);
3480  (*itComp)->setExpression(Infix);
3481  }
3482  }
3483 
3484  pExpression = (*itComp)->getInitialExpressionPtr();
3485 
3486  if (pExpression != NULL)
3487  {
3488  const CCopasiObject::DataObjectSet & Dependencies = pExpression->getDirectDependencies();
3489 
3490  if (Dependencies.find(itParameter->first) != Dependencies.end())
3491  {
3492  Infix = (*itComp)->getInitialExpression();
3493  stringReplace(Infix, Old, New);
3494  (*itComp)->setInitialExpression(Infix);
3495  }
3496  }
3497  }
3498 
3499  // Species (expression, initial expression)
3502 
3503  for (; itMetab != endMetab; ++itMetab)
3504  {
3505  const CExpression * pExpression = (*itMetab)->getExpressionPtr();
3506 
3507  if (pExpression != NULL)
3508  {
3509  const CCopasiObject::DataObjectSet & Dependencies = pExpression->getDirectDependencies();
3510 
3511  if (Dependencies.find(itParameter->first) != Dependencies.end())
3512  {
3513  Infix = (*itMetab)->getExpression();
3514  stringReplace(Infix, Old, New);
3515  (*itMetab)->setExpression(Infix);
3516  }
3517  }
3518 
3519  pExpression = (*itMetab)->getInitialExpressionPtr();
3520 
3521  if (pExpression != NULL)
3522  {
3523  const CCopasiObject::DataObjectSet & Dependencies = pExpression->getDirectDependencies();
3524 
3525  if (Dependencies.find(itParameter->first) != Dependencies.end())
3526  {
3527  Infix = (*itMetab)->getInitialExpression();
3528  stringReplace(Infix, Old, New);
3529  (*itMetab)->setInitialExpression(Infix);
3530  }
3531  }
3532  }
3533 
3534  // Model Quantities (expression, initial expression)
3537 
3538  for (; itValue != endValue; ++itValue)
3539  {
3540  const CExpression * pExpression = (*itValue)->getExpressionPtr();
3541 
3542  if (pExpression != NULL)
3543  {
3544  const CCopasiObject::DataObjectSet & Dependencies = pExpression->getDirectDependencies();
3545 
3546  if (Dependencies.find(itParameter->first) != Dependencies.end())
3547  {
3548  Infix = (*itValue)->getExpression();
3549  stringReplace(Infix, Old, New);
3550  (*itValue)->setExpression(Infix);
3551  }
3552  }
3553 
3554  pExpression = (*itValue)->getInitialExpressionPtr();
3555 
3556  if (pExpression != NULL)
3557  {
3558  const CCopasiObject::DataObjectSet & Dependencies = pExpression->getDirectDependencies();
3559 
3560  if (Dependencies.find(itParameter->first) != Dependencies.end())
3561  {
3562  Infix = (*itValue)->getInitialExpression();
3563  stringReplace(Infix, Old, New);
3564  (*itValue)->setInitialExpression(Infix);
3565  }
3566  }
3567  }
3568 
3569  // Events (trigger, delay, assignments)
3572 
3573  for (; itEvent != endEvent; ++itEvent)
3574  {
3575  const CExpression * pExpression = (*itEvent)->getTriggerExpressionPtr();
3576 
3577  if (pExpression != NULL)
3578  {
3579  const CCopasiObject::DataObjectSet & Dependencies = pExpression->getDirectDependencies();
3580 
3581  if (Dependencies.find(itParameter->first) != Dependencies.end())
3582  {
3583  Infix = (*itEvent)->getTriggerExpression();
3584  stringReplace(Infix, Old, New);
3585  (*itEvent)->setTriggerExpression(Infix);
3586  }
3587  }
3588 
3589  pExpression = (*itEvent)->getDelayExpressionPtr();
3590 
3591  if (pExpression != NULL)
3592  {
3593  const CCopasiObject::DataObjectSet & Dependencies = pExpression->getDirectDependencies();
3594 
3595  if (Dependencies.find(itParameter->first) != Dependencies.end())
3596  {
3597  Infix = (*itEvent)->getDelayExpression();
3598  stringReplace(Infix, Old, New);
3599  (*itEvent)->setDelayExpression(Infix);
3600  }
3601  }
3602 
3603  CCopasiVector< CEventAssignment >::iterator itAssignment = (*itEvent)->getAssignments().begin();
3604  CCopasiVector< CEventAssignment >::iterator endAssignment = (*itEvent)->getAssignments().end();
3605 
3606  for (; itAssignment != endAssignment; ++itAssignment)
3607  {
3608  pExpression = (*itAssignment)->getExpressionPtr();
3609 
3610  if (pExpression != NULL)
3611  {
3612  const CCopasiObject::DataObjectSet & Dependencies = pExpression->getDirectDependencies();
3613 
3614  if (Dependencies.find(itParameter->first) != Dependencies.end())
3615  {
3616  Infix = (*itAssignment)->getExpression();
3617  stringReplace(Infix, Old, New);
3618  (*itAssignment)->setExpression(Infix);
3619  }
3620  }
3621  }
3622  }
3623  }
3624 
3625  // BUG 1848. We need to replace all references to the flux and particle flux
3626  // with the difference of the forward and backward reaction fluxes and particle fluxes, i.e,
3627  // flux = forward.flux - backward.flux
3628 
3629  Old = "<" + reac0->getFluxReference()->getCN() + ">";
3630  New = "(<" + reac1->getFluxReference()->getCN() + "> - <" + reac2->getFluxReference()->getCN() + ">)";
3631 
3632  // Find all objects which directly depend on the flux or particle flux.
3633  std::set< const CCopasiObject * > Flux;
3634  Flux.insert(reac0->getFluxReference());
3635  std::set< const CCopasiObject * > FluxDependents;
3636 
3637  // Initial Expression and Expression
3638  appendDependentCompartments(Flux, FluxDependents);
3639  appendDependentModelValues(Flux, FluxDependents);
3640  appendDependentMetabolites(Flux, FluxDependents);
3641 
3642  std::set< const CCopasiObject * >::iterator it = FluxDependents.begin();
3643  std::set< const CCopasiObject * >::iterator end = FluxDependents.end();
3644 
3645  for (; it != end; ++it)
3646  {
3647  CModelEntity * pEntity = static_cast< CModelEntity * >(const_cast< CCopasiObject * >(*it));
3648 
3649  // Expression
3650  Infix = pEntity->getExpression();
3651 
3652  if (stringReplace(Infix, Old, New))
3653  {
3654  pEntity->setExpression(Infix);
3655  }
3656 
3657  // Initial Expression
3658  if (pEntity->getStatus() != CModelEntity::ASSIGNMENT)
3659  {
3660  Infix = pEntity->getInitialExpression();
3661 
3662  if (stringReplace(Infix, Old, New))
3663  {
3664  pEntity->setInitialExpression(Infix);
3665  }
3666  }
3667  }
3668 
3669  FluxDependents.clear();
3670 
3671  // Trigger and Assignments
3672  appendDependentEvents(Flux, FluxDependents);
3673 
3674  it = FluxDependents.begin();
3675  end = FluxDependents.end();
3676 
3677  for (; it != end; ++it)
3678  {
3679  CEvent * pEvent = static_cast< CEvent * >(const_cast< CCopasiObject * >(*it));
3680 
3681  // Trigger Expression
3682  Infix = pEvent->getTriggerExpression();
3683 
3684  if (stringReplace(Infix, Old, New))
3685  {
3686  pEvent->setTriggerExpression(Infix);
3687  }
3688 
3689  // Delay Expression
3690  Infix = pEvent->getDelayExpression();
3691 
3692  if (stringReplace(Infix, Old, New))
3693  {
3694  pEvent->setDelayExpression(Infix);
3695  }
3696 
3697  // Priority Expression
3698  Infix = pEvent->getPriorityExpression();
3699 
3700  if (stringReplace(Infix, Old, New))
3701  {
3702  pEvent->setPriorityExpression(Infix);
3703  }
3704 
3705  // Assignments
3708 
3709  for (; itAssignment != endAssignment; ++itAssignment)
3710  {
3711  Infix = (*itAssignment)->getExpression();
3712 
3713  if (stringReplace(Infix, Old, New))
3714  {
3715  (*itAssignment)->setExpression(Infix);
3716  }
3717  }
3718  }
3719 
3720  FluxDependents.clear();
3721  Flux.clear();
3722 
3723  // particleFlux = forward.particleFlux - backward.particleFlux
3724  Old = "<" + reac0->getParticleFluxReference()->getCN() + ">";
3725  New = "(<" + reac1->getParticleFluxReference()->getCN() + "> - <" + reac2->getParticleFluxReference()->getCN() + ">)";
3726 
3727  Flux.insert(reac0->getParticleFluxReference());
3728 
3729  // Initial Expression and Expression
3730  appendDependentCompartments(Flux, FluxDependents);
3731  appendDependentModelValues(Flux, FluxDependents);
3732  appendDependentMetabolites(Flux, FluxDependents);
3733 
3734  it = FluxDependents.begin();
3735  end = FluxDependents.end();
3736 
3737  for (; it != end; ++it)
3738  {
3739  CModelEntity * pEntity = static_cast< CModelEntity * >(const_cast< CCopasiObject * >(*it));
3740 
3741  // Expression
3742  Infix = pEntity->getExpression();
3743 
3744  if (stringReplace(Infix, Old, New))
3745  {
3746  pEntity->setExpression(Infix);
3747  }
3748 
3749  // Initial Expression
3750  if (pEntity->getStatus() != CModelEntity::ASSIGNMENT)
3751  {
3752  Infix = pEntity->getInitialExpression();
3753 
3754  if (stringReplace(Infix, Old, New))
3755  {
3756  pEntity->setInitialExpression(Infix);
3757  }
3758  }
3759  }
3760 
3761  FluxDependents.clear();
3762 
3763  // Trigger and Assignments
3764  appendDependentEvents(Flux, FluxDependents);
3765 
3766  it = FluxDependents.begin();
3767  end = FluxDependents.end();
3768 
3769  for (; it != end; ++it)
3770  {
3771  CEvent * pEvent = static_cast< CEvent * >(const_cast< CCopasiObject * >(*it));
3772 
3773  // Trigger Expression
3774  Infix = pEvent->getTriggerExpression();
3775 
3776  if (stringReplace(Infix, Old, New))
3777  {
3778  pEvent->setTriggerExpression(Infix);
3779  }
3780 
3781  // Delay Expression
3782  Infix = pEvent->getDelayExpression();
3783 
3784  if (stringReplace(Infix, Old, New))
3785  {
3786  pEvent->setDelayExpression(Infix);
3787  }
3788 
3789  // Priority Expression
3790  Infix = pEvent->getPriorityExpression();
3791 
3792  if (stringReplace(Infix, Old, New))
3793  {
3794  pEvent->setPriorityExpression(Infix);
3795  }
3796 
3797  // Assignments
3800 
3801  for (; itAssignment != endAssignment; ++itAssignment)
3802  {
3803  Infix = (*itAssignment)->getExpression();
3804 
3805  if (stringReplace(Infix, Old, New))
3806  {
3807  (*itAssignment)->setExpression(Infix);
3808  }
3809  }
3810  }
3811 
3812  // Schedule the old reaction for removal.
3813  reactionsToDelete.push_back(reac0);
3814  }
3815 
3816  imax = reactionsToDelete.size();
3817 
3818  for (i = 0; i < imax; ++i)
3819  {
3820  delete reactionsToDelete[i];
3821  }
3822 
3823  if (imax != 0)
3824  {
3825  setCompileFlag(true);
3826  }
3827 
3828  return success;
3829 }
bool stringReplace(std::string &str, const std::string &target, const std::string &replacement)
Definition: utility.cpp:165
Definition: CEvent.h:152
void setReversible(bool reversible)
Definition: CReaction.cpp:247
const CCopasiVectorN< CEventAssignment > & getAssignments() const
Definition: CEvent.cpp:678
CFunction * addAndAdaptName(CFunction *pFunction)
#define pdelete(p)
Definition: copasi.h:215
const CFunctionParameter::DataType & getType() const
CCopasiObject * getParticleFluxReference()
Definition: CReaction.cpp:207
virtual CCopasiObjectName getCN() const
bool addSubstrate(const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
Definition: CReaction.cpp:232
CCopasiVectorN< CEvent > mEvents
Definition: CModel.h:1344
const std::string & getObjectName() const
virtual size_t size() const
iterator begin()
void setParameterValue(const std::string &parameterName, const C_FLOAT64 &value, const bool &updateStatus=true)
Definition: CReaction.cpp:303
CCopasiObject * getValueReference() const
CCopasiVectorNS< CCompartment > mCompartments
Definition: CModel.h:1324
bool addProduct(const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
Definition: CReaction.cpp:236
bool isLocalParameter(const size_t &index) const
Definition: CReaction.cpp:449
bool setInitialExpression(const std::string &expression)
std::string getExpression() const
std::string getTriggerExpression() const
Definition: CEvent.cpp:524
void setParameterMappingVector(const std::string &parameterName, const std::vector< std::string > &keys)
Definition: CReaction.cpp:390
CCopasiVectorN< CModelValue > mValues
Definition: CModel.h:1354
void compile()
Definition: CReaction.cpp:583
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
const CFunction * getFunction() const
Definition: CReaction.cpp:252
iterator end()
const CFunctionParameters & getFunctionParameters() const
Definition: CReaction.cpp:576
bool addModifier(const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
Definition: CReaction.cpp:240
bool setFunction(const std::string &functionName)
Definition: CReaction.cpp:255
CReaction * createReaction(const std::string &name)
Definition: CModel.cpp:2760
std::pair< CFunction *, CFunction * > splitFunction(const CEvaluationNode *node, const std::string &name1, const std::string &name2) const
Definition: CFunction.cpp:445
bool setTriggerExpression(const std::string &expression)
Definition: CEvent.cpp:474
CCopasiVector< CMetab > mMetabolitesX
Definition: CModel.h:1334
std::string getInitialExpression() const
bool appendDependentCompartments(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependents) const
Definition: CModel.cpp:2538
bool appendDependentMetabolites(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependents) const
Definition: CModel.cpp:2501
CCopasiParameter * getParameter(const std::string &name)
bool setPriorityExpression(const std::string &expression)
Definition: CEvent.cpp:611
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
static CFunctionDB * getFunctionList()
std::string getDelayExpression() const
Definition: CEvent.cpp:591
void setCompileFlag(bool flag=true)
Definition: CModel.cpp:607
#define MCReaction
virtual const DataObjectSet & getDirectDependencies(const DataObjectSet &context=DataObjectSet()) const
bool setDelayExpression(const std::string &expression)
Definition: CEvent.cpp:544
const CCopasiParameterGroup & getParameters() const
Definition: CReaction.cpp:333
CFunction * findFunction(CCopasiVectorN< CFunction > &db, const CFunction *func)
void setParameterMapping(const size_t &index, const std::string &key)
Definition: CReaction.cpp:339
std::vector< CType * >::iterator iterator
Definition: CCopasiVector.h:56
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
bool appendDependentEvents(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependents) const
Definition: CModel.cpp:2593
const CModelEntity::Status & getStatus() const
bool setExpression(const std::string &expression)
std::set< const CCopasiObject * > DataObjectSet
std::string getPriorityExpression() const
Definition: CEvent.cpp:658
const CChemEq & getChemEq() const
Definition: CReaction.cpp:223
const C_FLOAT64 & getParameterValue(const std::string &parameterName) const
Definition: CReaction.cpp:326
bool appendDependentModelValues(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependents) const
Definition: CModel.cpp:2566
const std::vector< std::string > & getParameterMapping(const size_t &index) const
Definition: CReaction.cpp:432
CCopasiObject * getFluxReference()
Definition: CReaction.cpp:198
CCompartment * CModel::createCompartment ( const std::string &  name,
const C_FLOAT64 volume = 1.0 
)

Add a compartment to the model

Parameters
conststd::string &name
constC_FLOAT64 & volume (default 1.0)
Returns
bool success (false if failed)

Definition at line 2698 of file CModel.cpp.

References CCopasiVectorN< CType >::add(), C_INVALID_INDEX, CCopasiVectorN< CType >::getIndex(), mCompartments, mCompileIsNecessary, and CModelEntity::setInitialValue().

Referenced by CModelAdd::addCompartments(), SBMLImporter::createCCompartmentFromCompartment(), test000097::createModel(), CChemEqInterface::createNonExistingMetabs(), CReactionInterface::createOtherObjects(), CModelExpansion::duplicateCompartment(), CQSpecieDM::insertRows(), CQSpeciesDetail::slotBtnNew(), and test000058::test_bug1025_7().

2700 {
2701  // check if there is already a volume with this name
2702  if (mCompartments.getIndex(name) != C_INVALID_INDEX)
2703  return NULL;
2704 
2705  CCompartment * cpt = new CCompartment(name);
2706 
2707  cpt->setInitialValue(volume);
2708  //cpt->setVolume(volume);
2709 
2710  if (!mCompartments.add(cpt, true))
2711  {
2712  delete cpt;
2713  return NULL;
2714  }
2715 
2716  mCompileIsNecessary = true;
2717  return cpt;
2718 }
CCopasiVectorNS< CCompartment > mCompartments
Definition: CModel.h:1324
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual size_t getIndex(const std::string &name) const
virtual bool add(const CType &src)
bool mCompileIsNecessary
Definition: CModel.h:1479
virtual void setInitialValue(const C_FLOAT64 &initialValue)
CEvent * CModel::createEvent ( const std::string &  name)

Add a new event to the model

Parameters
conststd::string &name
Returns
bool success (false if failed)

Definition at line 2928 of file CModel.cpp.

References CCopasiVectorN< CType >::add(), C_INVALID_INDEX, CCopasiVectorN< CType >::getIndex(), mCompileIsNecessary, and mEvents.

Referenced by CModelAdd::addEvents(), CCrossSectionTask::createEvent(), CModelExpansion::duplicateEvent(), and SBMLImporter::importEvent().

2929 {
2930  if (mEvents.getIndex(name) != C_INVALID_INDEX)
2931  return NULL;
2932 
2933  CEvent * pEvent = new CEvent(name, this);
2934 
2935  if (!mEvents.add(pEvent, true))
2936  {
2937  delete pEvent;
2938  return NULL;
2939  }
2940 
2941  mCompileIsNecessary = true;
2942  return pEvent;
2943 }
Definition: CEvent.h:152
CCopasiVectorN< CEvent > mEvents
Definition: CModel.h:1344
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual size_t getIndex(const std::string &name) const
virtual bool add(const CType &src)
bool mCompileIsNecessary
Definition: CModel.h:1479
CMetab * CModel::createMetabolite ( const std::string &  name,
const std::string &  compartment,
const C_FLOAT64 iconc = 1.0,
const CModelEntity::Status status = CModelEntity::REACTIONS 
)

Add a metabolite to the model

Parameters
conststd::string & name
conststd::string & compartment
constC_FLOAT64 & iconc (default 1.0)
constCMetab::Status & status (default CMetab::METAB_VARIABL)
Returns
bool success (false if failed)
See Also
CMetab for more information

Definition at line 2622 of file CModel.cpp.

References CCopasiVector< T >::add(), C_INVALID_INDEX, CCopasiVector< T >::getIndex(), CCopasiVectorN< CType >::getIndex(), getMetabolites(), mCompartments, mCompileIsNecessary, mMetabolites, CMetab::refreshInitialValue(), CMetab::setInitialConcentration(), CMetab::setStatus(), and CCopasiVector< T >::size().

Referenced by CModelAdd::addMetabolites(), SBMLImporter::createCMetabFromSpecies(), CChemEqInterface::createNonExistingMetabs(), CModelExpansion::duplicateMetab(), CQSpecieDM::insertRows(), CQSpeciesDetail::slotBtnNew(), test000058::test_bug1025_8(), and test000059::test_unique_id_11().

2626 {
2627  size_t Index;
2628 
2629  if (mCompartments.size() == 0)
2630  return NULL;
2631 
2632  if (compartment == "")
2633  Index = 0;
2634  else if ((Index = mCompartments.getIndex(compartment)) == C_INVALID_INDEX)
2635  return NULL;
2636 
2637  if (mCompartments[Index]->getMetabolites().getIndex(name) != C_INVALID_INDEX)
2638  return NULL;
2639 
2640  CMetab * pMetab = new CMetab(name);
2641 
2642  if (!mCompartments[Index]->addMetabolite(pMetab))
2643  {
2644  delete pMetab;
2645  return NULL;
2646  }
2647 
2648  pMetab->setStatus(status);
2649  pMetab->setInitialConcentration(iconc);
2650  pMetab->refreshInitialValue();
2651 
2652  if (!mMetabolites.add(pMetab))
2653  return NULL;
2654 
2655  mCompileIsNecessary = true;
2656 
2657  return pMetab;
2658 }
void setInitialConcentration(const C_FLOAT64 &initialConcentration)
Definition: CMetab.cpp:257
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
virtual void setStatus(const CModelEntity::Status &status)
Definition: CMetab.cpp:291
virtual size_t size() const
CCopasiVectorNS< CCompartment > mCompartments
Definition: CModel.h:1324
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual size_t getIndex(const std::string &name) const
Definition: CMetab.h:178
CCopasiVector< CMetab > mMetabolites