copasi API  0.1
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends
CHybridMethod Class Reference

#include <CHybridMethod.h>

Inheritance diagram for CHybridMethod:
CTrajectoryMethod CCopasiMethod CCopasiParameterGroup CCopasiParameter CCopasiContainer CCopasiObject CHybridNextReactionRKMethod

List of all members.

Public Member Functions

 CHybridMethod (const CHybridMethod &src, const CCopasiContainer *pParent=NULL)
 ~CHybridMethod ()
virtual bool elevateChildren ()
virtual Status step (const double &deltaT)
virtual void start (const CState *initialState)
virtual bool isValidProblem (const CCopasiProblem *pProblem)

Static Public Member Functions

static CHybridMethodcreateHybridMethod ()

Protected Types

enum  metabStatus { LOW = 0, HIGH }

Protected Member Functions

 CHybridMethod (const CCopasiContainer *pParent=NULL)
void initMethod (C_FLOAT64 time)
void cleanup ()
virtual C_FLOAT64 doSingleStep (C_FLOAT64 currentTime, C_FLOAT64 endTime)=0
void integrateDeterministicPart (C_FLOAT64 ds)
void integrateDeterministicPartEuler (C_FLOAT64 ds)
void rungeKutta (C_FLOAT64 dt)
void calculateDerivative (std::vector< C_FLOAT64 > &deriv)
void getState (std::vector< C_FLOAT64 > &target)
void setState (std::vector< C_FLOAT64 > &source)
void getStochTimeAndIndex (C_FLOAT64 &ds, C_INT32 &rIndex)
void fireReaction (C_INT32 rIndex)
void updatePriorityQueue (C_INT32 rIndex, C_FLOAT64 time)
C_FLOAT64 generateReactionTime (C_INT32 rIndex)
void calculateAmu (C_INT32 rIndex)
void updateTauMu (C_INT32 rIndex, C_FLOAT64 time)
void setupBalances ()
void setupDependencyGraph ()
void setupMetab2React ()
void setupMetab2ReactPlusModifier ()
void setupMetab2ReactComplete ()
void setupPartition ()
void setupPriorityQueue (C_FLOAT64 startTime=0.0)
void partitionSystem ()
void insertDeterministicReaction (C_INT32 rIndex)
void removeDeterministicReaction (C_INT32 rIndex)
std::set< std::string > * getDependsOn (C_INT32 rIndex)
std::set< std::string > * getAffects (C_INT32 rIndex)
std::set< C_INT32 > * getParticipatesIn (C_INT32 rIndex)
void outputData (std::ostream &os, C_INT32 mode)
void outputDebug (std::ostream &os, C_INT32 level)

Static Protected Member Functions

static C_INT32 checkModel (CModel *model)
static bool modelHasAssignments (const CModel *pModel)

Protected Attributes

CVersion mVersion
CModelmpModel
unsigned C_INT32 mNumVariableMetabs
unsigned C_INT32 mFirstMetabIndex
unsigned C_INT32 mMaxSteps
bool mMaxStepsReached
bool mUseRandomSeed
unsigned C_INT32 mRandomSeed
C_INT32 mMaxBalance
C_INT32 mMaxIntBeforeStep
bool mDoCorrection
const CCopasiVectorNS
< CReaction > * 
mpReactions
CCopasiVector< CMetab > * mpMetabolites
CMatrix< C_FLOAT64 > mStoi
std::vector< C_FLOAT64 > temp
std::vector< C_FLOAT64 > currentState
std::vector< C_FLOAT64 > k1
std::vector< C_FLOAT64 > k2
std::vector< C_FLOAT64 > k3
std::vector< C_FLOAT64 > k4
std::vector< CHybridStochFlagmReactionFlags
CHybridStochFlagmFirstReactionFlag
std::vector< metabStatusmMetabFlags
std::vector< std::vector
< CHybridBalance > > 
mLocalBalances
std::vector< std::vector
< CHybridBalance > > 
mLocalSubstrates
C_FLOAT64 mLowerStochLimit
C_FLOAT64 mUpperStochLimit
unsigned C_INT32 mPartitioningInterval
unsigned C_INT32 mStepsAfterPartitionSystem
C_FLOAT64 mStepsize
std::vector< std::set< C_INT32 > > mMetab2React
std::vector< C_FLOAT64 > mAmu
std::vector< C_FLOAT64 > mAmuOld
std::set< C_INT32 > mUpdateSet
CRandommpRandomGenerator
CDependencyGraph mDG
CIndexedPriorityQueue mPQ
std::ofstream mOutputFile
std::string mOutputFileName
C_INT32 mOutputCounter
bool mHasAssignments

Friends

CTrajectoryMethodCTrajectoryMethod::createTrajectoryMethod (CCopasiMethod::SubType subType, CTrajectoryProblem *pProblem)

Member Enumeration Documentation

enum CHybridMethod::metabStatus [protected]

Status of the metabolites. Particle number can be high or low.

Enumerator:
LOW 
HIGH 

Constructor & Destructor Documentation

CHybridMethod::CHybridMethod ( const CHybridMethod src,
const CCopasiContainer pParent = NULL 
)

Copy constructor

Parameters:
constCHybridMethod & src
constCCopasiContainer * pParent (default: NULL)
CHybridMethod::~CHybridMethod ( )

Destructor.

CHybridMethod::CHybridMethod ( const CCopasiContainer pParent = NULL) [protected]

Default constructor.

Parameters:
constCCopasiContainer * pParent (default: NULL)

CHybridMethod

This class implements an hybrid algorithm for the simulation of a biochemical system over time.

File name: CHybridMethod.cpp Author: Juergen Pahle Email: juergen.pahle@eml-r.villa-bosch.de

Last change: 14, December 2004

(C) European Media Lab 2003. Default constructor.


Member Function Documentation

void CHybridMethod::calculateAmu ( C_INT32  rIndex) [protected]

Calculates an amu value for a given reaction.

Parameters:
rIndexA C_INT32 specifying the reaction to be updated
void CHybridMethod::calculateDerivative ( std::vector< C_FLOAT64 > &  deriv) [protected]

Calculates the derivative of the system and writes it into the vector deriv. Length of deriv must be mNumVariableMetabs. CAUTION: Only deterministic reactions are taken into account. That is, this is only the derivative of the deterministic part of the system.

Parameters:
derivA vector reference of length mNumVariableMetabs, into which the derivative is written
C_INT32 CHybridMethod::checkModel ( CModel model) [static, protected]

Test the model if it is proper to perform stochastic simulations on. Several properties are tested (e.g. integer stoichometry, all reactions take place in one compartment only, irreversibility...).

Parameters:
modelThe model to be checked
Returns:
1, if hybrid simulation is possible; <0, if an error occured.

Test the model if it is proper to perform stochastic simulations on. Several properties are tested (e.g. integer stoichometry, all reactions take place in one compartment only, irreversibility...).

Returns:
0, if everything is ok; <0, if an error occured.
void CHybridMethod::cleanup ( ) [protected]

Cleans up memory, etc.

CHybridMethod * CHybridMethod::createHybridMethod ( ) [static]

Creates a HybridMethod adequate for the problem. (only CHybridNextReactionRKMethod so far)

virtual C_FLOAT64 CHybridMethod::doSingleStep ( C_FLOAT64  currentTime,
C_FLOAT64  endTime 
) [protected, pure virtual]

Simulates the system over the next interval of time. The current time and the end time of the current step() are given as arguments.

Parameters:
currentTimeA C_FLOAT64 specifying the current time
endTimeA C_FLOAT64 specifying the end time of the step()
Returns:
A C_FLOAT giving the new time

Implemented in CHybridNextReactionRKMethod.

bool CHybridMethod::elevateChildren ( ) [virtual]

This methods must be called to elevate subgroups to derived objects. The default implementation does nothing.

Returns:
bool success

Reimplemented from CCopasiParameterGroup.

void CHybridMethod::fireReaction ( C_INT32  rIndex) [protected]

Executes the specified reaction in the system once.

Parameters:
rIndexA C_INT32 specifying the index of the reaction, which will be fired.

Executes the specified reaction in the system once.

Parameters:
rIndexA C_INT32 specifying the index of the reaction, which will be fired.
timeThe current time
C_FLOAT64 CHybridMethod::generateReactionTime ( C_INT32  rIndex) [protected]

Generates a putative reaction time for the given reaction.

Parameters:
rIndexA C_INT32 specifying the index of the reaction
Returns:
A C_FLOAT64 holding the calculated reaction time
std::set< std::string > * CHybridMethod::getAffects ( C_INT32  rIndex) [protected]

Gets the set of metabolites which change number when a given reaction is executed.

Parameters:
rIndexThe index of the reaction being executed.
Returns:
The set of affected metabolites.
std::set< std::string > * CHybridMethod::getDependsOn ( C_INT32  rIndex) [protected]

Gets the set of metabolites on which a given reaction depends.

Parameters:
rIndexThe index of the reaction being executed.
Returns:
The set of metabolites depended on.
std::set< C_INT32 > * CHybridMethod::getParticipatesIn ( C_INT32  rIndex) [protected]

Gets the set of metabolites, which participate in the given reaction either as substrate, product or modifier.

Parameters:
rIndexThe index of the reaction being executed.
Returns:
The set of participating metabolites.
void CHybridMethod::getState ( std::vector< C_FLOAT64 > &  target) [protected]

Gathers the state of the system into the array target. Later on CState should be used for this. Length of the array target must be mNumVariableMetabs.

Parameters:
targetA vector reference of length mNumVariableMetabs, into which the state of the system is written

Gathers the state of the system into the array target. Later on CState should be used for this. Length of the array target must be mNumVariableMetabs.

Parameters:
targetAn array of C_FLOAT64s with length mNumVariableMetabs, into which the state of the system is written
void CHybridMethod::getStochTimeAndIndex ( C_FLOAT64 &  ds,
C_INT32 &  rIndex 
) [protected]

Find the reaction index and the reaction time of the stochastic (!) reaction with the lowest reaction time.

Parameters:
dsA reference to a C_FLOAT64. The putative reaction time for the first stochastic reaction is written into this variable.
rIndexA reference to a C_INT32. The index of the first stochastic reaction is written into this variable.
void CHybridMethod::initMethod ( C_FLOAT64  start_time) [protected]

Initializes the solver.

Parameters:
timethe current time

Initializes the solver and sets the model to be used.

Parameters:
modelA reference to an instance of a CModel
void CHybridMethod::insertDeterministicReaction ( C_INT32  rIndex) [protected]

Inserts a new deterministic reaction into the linked list in the vector mReactionFlags.

Parameters:
rIndexA C_INT32 giving the index of the reaction to be inserted into the list of deterministic reactions.

Inserts a new deterministic reaction into the linked list in the array mReactionFlags.

Parameters:
rIndexA C_INT32 giving the index of the reaction to be inserted into the list of deterministic reactions.
void CHybridMethod::integrateDeterministicPart ( C_FLOAT64  dt) [protected]

Integrates the deterministic reactions of the system over the specified time interval.

Parameters:
dsA C_FLOAT64 specifying the stepsize.
void CHybridMethod::integrateDeterministicPartEuler ( C_FLOAT64  dt) [protected]

Integrates the deterministic reactions of the system over the specified time interval.

Parameters:
dsA C_FLOAT64 specifying the stepsize.
bool CHybridMethod::isValidProblem ( const CCopasiProblem pProblem) [virtual]

Check if the method is suitable for this problem

Returns:
bool suitability of the method

Reimplemented from CTrajectoryMethod.

bool CHybridMethod::modelHasAssignments ( const CModel pModel) [static, protected]

tests if the model contains a global value with an assignment rule that is used in calculations

void CHybridMethod::outputData ( std::ostream &  os,
C_INT32  mode 
) [protected]

Prints out data on standard output.

Prints out data on standard output. Deprecated.

void CHybridMethod::outputDebug ( std::ostream &  os,
C_INT32  level 
) [protected]

Prints out various data on standard output for debugging purposes.

void CHybridMethod::partitionSystem ( ) [protected]

Updates the partitioning of the system depending on the particle numbers present.

void CHybridMethod::removeDeterministicReaction ( C_INT32  rIndex) [protected]

Removes a deterministic reaction from the linked list in the vector mReactionFlags.

Parameters:
rIndexA C_INT32 giving the index of the reaction to be removed from the list of deterministic reactions.

Removes a deterministic reaction from the linked list in the array mReactionFlags.

Parameters:
rIndexA C_INT32 giving the index of the reaction to be removed from the list of deterministic reactions.
void CHybridMethod::rungeKutta ( C_FLOAT64  dt) [protected]

Does one 4th order RungeKutta step to integrate the system numerically.

Parameters:
dtA C_FLOAT64 specifying the stepsize
resultA reference to a vector, into which the result, that is the increment vector, will be written
void CHybridMethod::setState ( std::vector< C_FLOAT64 > &  source) [protected]

Writes the state specified in the array source into the model. Length of the vector source must be mNumVariableMetabs. (Number of non-fixed metabolites in the model).

Parameters:
sourceA vector reference with length mNumVariableMetabs, holding the state of the system to be set in the model

Writes the state specified in the vector source into the model. Length of the vector source must be mNumVariableMetabs. (Number of non-fixed metabolites in the model).

Parameters:
sourceA vector reference with length mNumVariableMetabs, holding the state of the system to be set in the model
void CHybridMethod::setupBalances ( ) [protected]

Sets up an internal representation of the balances for each reaction. This is done in order to be able to deal with fixed metabolites and to avoid a time consuming search for the indices of metabolites in the model.

void CHybridMethod::setupDependencyGraph ( ) [protected]

Sets up the dependency graph

Sets up the dependency graph.

void CHybridMethod::setupMetab2React ( ) [protected]

Creates for each metabolite a set of reaction indices. If the metabolite participates in a reaction as substrate or product this reaction is added to the corresponding set.

Creates for each metabolite a set of reaction indices. If the metabolite participates in a reaction as substrate or product (that means: balance != 0) this reaction is added to the corresponding set.

void CHybridMethod::setupMetab2ReactComplete ( ) [protected]

Creates for each metabolite a set of reaction indices. Each reaction is dependent on each metabolite resulting in a complete switch.

void CHybridMethod::setupMetab2ReactPlusModifier ( ) [protected]

Creates for each metabolite a set of reaction indices. If the metabolite participates in a reaction as substrate, product or modifier this reaction is added to the corresponding set.

void CHybridMethod::setupPartition ( ) [protected]

Creates an initial partitioning of the system. Deterministic and stochastic reactions are determined. The array mStochReactions is initialized.

Creates an initial partitioning of the system. Deterministic and stochastic reactions are determined. The vector mReactionFlags and the vector mMetabFlags are initialized.

void CHybridMethod::setupPriorityQueue ( C_FLOAT64  startTime = 0.0) [protected]

Sets up the priority queue.

Parameters:
startTimeThe time at which the simulation starts.
void CHybridMethod::start ( const CState initialState) [virtual]

This instructs the method to prepare for integration starting with the initialState given.

Parameters:
const CState *initialState

Reimplemented from CTrajectoryMethod.

CTrajectoryMethod::Status CHybridMethod::step ( const double &  deltaT) [virtual]

This instructs the method to calculate a time step of deltaT starting with the current state, i.e., the result of the previous step. The new state (after deltaT) is expected in the current state. The return value is the actual timestep taken.

Parameters:
const double &deltaT
Returns:
Status status

Reimplemented from CTrajectoryMethod.

void CHybridMethod::updatePriorityQueue ( C_INT32  rIndex,
C_FLOAT64  time 
) [protected]

Updates the priority queue.

Parameters:
rIndexA C_INT32 giving the index of the fired reaction
timeA C_FLOAT64 holding the time taken by this reaction

Updates the priority queue.

Parameters:
rIndexA C_INT32 giving the index of the fired reaction (-1, if no stochastic reaction has fired)
timeA C_FLOAT64 holding the current time
void CHybridMethod::updateTauMu ( C_INT32  rIndex,
C_FLOAT64  time 
) [protected]

Updates the putative reaction time of a stochastic reaction in the priority queue. The corresponding amu and amu_old must be set prior to the call of this method.

Parameters:
rIndexA C_INT32 specifying the index of the reaction
timeA C_FLOAT64 specifying the current time

Updates the putative reaction time of a stochastic reaction in the priority queue. The corresponding amu and amu_old must be set prior to the call of this method.

Parameters:
rIndexA C_INT32 specifying the index of the reaction

Friends And Related Function Documentation

CTrajectoryMethod* CTrajectoryMethod::createTrajectoryMethod ( CCopasiMethod::SubType  subType,
CTrajectoryProblem pProblem 
) [friend]

Member Data Documentation

std::vector<C_FLOAT64> CHybridMethod::currentState [protected]
std::vector<C_FLOAT64> CHybridMethod::k1 [protected]
std::vector<C_FLOAT64> CHybridMethod::k2 [protected]
std::vector<C_FLOAT64> CHybridMethod::k3 [protected]
std::vector<C_FLOAT64> CHybridMethod::k4 [protected]
std::vector<C_FLOAT64> CHybridMethod::mAmu [protected]

The propensities of the stochastic reactions.

std::vector<C_FLOAT64> CHybridMethod::mAmuOld [protected]

The graph of reactions and their dependent reactions. When a reaction is executed, the propensities for each of its dependents must be updated.

bool CHybridMethod::mDoCorrection [protected]

indicates if the correction N^2 -> N*(N-1) should be performed

unsigned C_INT32 CHybridMethod::mFirstMetabIndex [protected]

index of the first metab in CState

Indicates whether the model has global quantities with assignment rules. If it has, we will use a less efficient way to update the model state to handle this.

std::vector<std::vector <CHybridBalance> > CHybridMethod::mLocalBalances [protected]

Internal representation of the balances of each reaction. The index of each metabolite in the reaction is provided.

std::vector<std::vector <CHybridBalance> > CHybridMethod::mLocalSubstrates [protected]

Internal representation of the substrates of each reaction. The index of each substrate-metabolite is provided.

C_FLOAT64 CHybridMethod::mLowerStochLimit [protected]

Limit for particle numbers. If a particle number is < StochLimit the corresponding reactions must be simulated stochastically.

C_INT32 CHybridMethod::mMaxBalance [protected]

maximal increase of a particle number in one step.

C_INT32 CHybridMethod::mMaxIntBeforeStep [protected]

This is set to maxint - mMaxSteps*mMaxBalance

unsigned C_INT32 CHybridMethod::mMaxSteps [protected]

Max number of doSingleStep() per step()

std::vector<std::set <C_INT32> > CHybridMethod::mMetab2React [protected]

Vector of relations between metabolites to reactions.

std::vector<metabStatus> CHybridMethod::mMetabFlags [protected]

Vector holding information on the status of metabolites. They can have low or high particle numbers.

unsigned C_INT32 CHybridMethod::mNumVariableMetabs [protected]

Dimension of the system. Total number of metabolites.

C_INT32 CHybridMethod::mOutputCounter [protected]

Output counter.

std::ofstream CHybridMethod::mOutputFile [protected]

File output stream to write data.

std::string CHybridMethod::mOutputFileName [protected]

Output filename.

unsigned C_INT32 CHybridMethod::mPartitioningInterval [protected]

The system gets repartitioned after this number of elementary steps.

A pointer to the metabolites of the model.

Pointer to the model

The set of putative stochastic (!) reactions and associated times at which each reaction occurs. This is represented as a priority queue, sorted by the reaction time. This heap changes dynamically as stochastic reactions become deterministic (delete this reaction from the queue) or vice versa (insert a new reaction into the queue).

The random number generator.

A pointer to the reactions of the model.

unsigned C_INT32 CHybridMethod::mRandomSeed [protected]

The random seed to use.

Vector to hold information about how many metabolites of a reaction have low particle numbers. If no metabolite of one reaction has low particle numbers this reaction will be simulated det.

unsigned C_INT32 CHybridMethod::mStepsAfterPartitionSystem [protected]

Number of elementary steps after the last partitioning.

C_FLOAT64 CHybridMethod::mStepsize [protected]

Stepsize for the rungeKutta steps of the numerical integrator.

CMatrix<C_FLOAT64> CHybridMethod::mStoi [protected]

The stoichometry matrix of the model.

std::set<C_INT32> CHybridMethod::mUpdateSet [protected]

Set of the reactions, which must be updated.

C_FLOAT64 CHybridMethod::mUpperStochLimit [protected]

Specifies if the mRandomSeed should be used. otherwise a randomly chosen seed is used.

Version number of this class

std::vector<C_FLOAT64> CHybridMethod::temp [protected]

Vectors to hold the system state and intermediate results


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines