/**
 * Virtual function to make the data structures from the 
 * object oriented specification of the signaling network.
 */
void GssaStoich::rebuildMatrix( Eref stoich, vector< Id >& ret )
{
	Stoich::rebuildMatrix( stoich, ret );
	// Stuff here to set up the dependencies.
	unsigned int numRates = N_.nColumns();
	assert ( numRates == rates_.size() );

	// Here we fix the issue of having a single substrate at
	// more than first order. Its rate must be computed differently
	// for stoch calculations, since one molecule is consumed for
	// each order.
	for ( unsigned int i = 0; i < numRates; ++i ) {
		vector< unsigned int > molIndex;
		if ( rates_[i]->getReactants( molIndex, S_ ) > 1 ) {
			if ( molIndex.size() == 2 && molIndex[0] == molIndex[1] ) {
				RateTerm* oldRate = rates_[i];
				rates_[ i ] = new StochSecondOrderSingleSubstrate(
					oldRate->getR1(), &S_[ molIndex[ 0 ] ]
				);
				delete oldRate;
			} else if ( molIndex.size() > 2 ) {
				RateTerm* oldRate = rates_[ i ];
				vector< const double* > v;
				for ( vector< unsigned int >::iterator j = 
					molIndex.begin(); j != molIndex.end(); ++j )
					v.push_back( &S_[ *j ] );
				rates_[ i ] = new StochNOrder( oldRate->getR1(), v);
				delete oldRate;
			}
		}
	}

	// Here we set up dependency stuff. First the basic reac deps.
	transN_.setSize( numRates, N_.nRows() );
	assert( N_.nRows() == nMols_ );
	N_.transpose( transN_ );
	transN_.truncateRow( nVarMols_ );
	dependency_.resize( numRates );
	for ( unsigned int i = 0; i < numRates; ++i ) {
		transN_.getGillespieDependence( i, dependency_[ i ] );
	}

	// Fill in dependency list for MMEnzs: they depend on their enzymes.
	fillMmEnzDep();

	// Fill in dependency list for SumTots on reactions
	fillMathDep();

	makeReacDepsUnique();
}
Exemple #2
0
void Gsolve::rebuildGssaSystem()
{
	stoichPtr_->convertRatesToStochasticForm();
	sys_.transposeN = stoichPtr_->getStoichiometryMatrix();
	sys_.transposeN.transpose();
	sys_.transposeN.truncateRow( stoichPtr_->getNumVarPools() );
	vector< vector< unsigned int > > & dep = sys_.dependency;
	dep.resize( stoichPtr_->getNumRates() );
	for ( unsigned int i = 0; i < stoichPtr_->getNumRates(); ++i ) {
		sys_.transposeN.getGillespieDependence( i, dep[i] );
	}
	fillMmEnzDep();
	fillMathDep();
	makeReacDepsUnique();
	for ( vector< GssaVoxelPools >::iterator 
					i = pools_.begin(); i != pools_.end(); ++i ) {
		i->setNumReac( stoichPtr_->getNumRates() );
	}
	sys_.isReady = true;
}