void System::outputAllObservableCounts(double cSampleTime, int eventCounter) { if(!onTheFlyObservables) { for(obsIter = obsToOutput.begin(); obsIter != obsToOutput.end(); obsIter++) { (*obsIter)->clear(); } for(molTypeIter = allMoleculeTypes.begin(); molTypeIter != allMoleculeTypes.end(); molTypeIter++ ) { (*molTypeIter)->addAllToObservables(); } int match = 0; // NETGEN -- this bit replaces the commented block below Complex * complex; allComplexes.resetComplexIter(); while( (complex = allComplexes.nextComplex()) ) { if( complex->isAlive() ) { for(obsIter = speciesObservables.begin(); obsIter != speciesObservables.end(); obsIter++) { match = (*obsIter)->isObservable( complex ); for (int k=0; k<match; k++) (*obsIter)->straightAdd(); } } } /* for(complexIter = allComplexes.begin(); complexIter != allComplexes.end(); complexIter++) { if((*complexIter)->isAlive()) { for(obsIter = speciesObservables.begin(); obsIter != speciesObservables.end(); obsIter++) { match = (*obsIter)->isObservable((*complexIter)); for(int k=0; k<match; k++) (*obsIter)->straightAdd(); } } } */ } if(useBinaryOutput) { double count=0.0; int oTot=0; outputFileStream.write((char *)&cSampleTime, sizeof(double)); for(obsIter = obsToOutput.begin(); obsIter != obsToOutput.end(); obsIter++) { count=((double)(*obsIter)->getCount()); outputFileStream.write((char *) &count, sizeof(double)); } if(outputGlobalFunctionValues) for( functionIter = globalFunctions.begin(); functionIter != globalFunctions.end(); functionIter++ ) { count=FuncFactory::Eval((*functionIter)->p); outputFileStream.write((char *) &count, sizeof(double)); } if(outputEventCounter) { count=eventCounter; outputFileStream.write((char *) &count, sizeof(double)); } } else { if(!csvFormat) { outputFileStream<<" "<<cSampleTime; for(obsIter = obsToOutput.begin(); obsIter != obsToOutput.end(); obsIter++) { outputFileStream<<" "<<((double)(*obsIter)->getCount()); } if(outputGlobalFunctionValues) for( functionIter = globalFunctions.begin(); functionIter != globalFunctions.end(); functionIter++ ) outputFileStream<<" "<<FuncFactory::Eval((*functionIter)->p); if(outputEventCounter) { outputFileStream<<" "<<eventCounter; } outputFileStream<<endl; } else { outputFileStream<<cSampleTime; for(obsIter = obsToOutput.begin(); obsIter != obsToOutput.end(); obsIter++) { outputFileStream<<", "<<((double)(*obsIter)->getCount()); } if(outputGlobalFunctionValues) for( functionIter = globalFunctions.begin(); functionIter != globalFunctions.end(); functionIter++ ) outputFileStream<<", "<<FuncFactory::Eval((*functionIter)->p); if(outputEventCounter) { outputFileStream<<", "<<eventCounter; } outputFileStream<<endl; } } }
//When you are ready to run the simulation (meaning that all moleculeTypes //all molecules, and all reactions have been created and registered with //the system) call this function to populate all the reactant lists and //observables. void System::prepareForSimulation() { this->selector = new DirectSelector(allReactions); cout<<"preparing simulation..."<<endl; //Note!! : the order of preparing the system matters! You have to prepare //some things before others, because certain things require other //First, set the observables up correctly, so when functions evaluate, they get the //correct values //for(molTypeIter = allMoleculeTypes.begin(); molTypeIter != allMoleculeTypes.end(); molTypeIter++ ) { // (*molTypeIter)->addAllToObservables(); //} //First, we have to prep all the functions... for( functionIter = globalFunctions.begin(); functionIter != globalFunctions.end(); functionIter++ ) (*functionIter)->prepareForSimulation(this); //cout<<"here 1..."<<endl; for( int f=0; f<localFunctions.size(); f++) localFunctions.at(f)->prepareForSimulation(this); //cout<<"here 2..."<<endl; for( int f=0; f<compositeFunctions.size(); f++) compositeFunctions.at(f)->prepareForSimulation(this); //cout<<"here 3..."<<endl; //this->printAllFunctions(); // now we prepare all reactions rxnIndexMap = new int * [allReactions.size()]; for(unsigned int r=0; r<allReactions.size(); r++) { rxnIndexMap[r] = new int[allReactions.at(r)->getNumOfReactants()]; allReactions.at(r)->setRxnId(r); } //cout<<"here 4..."<<endl; //This means we aren't going to add any more molecules to the system, so prep the rxns for(rxnIter = allReactions.begin(); rxnIter != allReactions.end(); rxnIter++ ) (*rxnIter)->prepareForSimulation(); //cout<<"here 5..."<<endl; //If there are local functions to be had, make sure we set up those local function lists in the molecules //before we try to add molecules to reactant lists if(this->localFunctions.size()>0) { for( molTypeIter = allMoleculeTypes.begin(); molTypeIter != allMoleculeTypes.end(); molTypeIter++ ) (*molTypeIter)->setUpLocalFunctionListForMolecules(); } //cout<<"here 6..."<<endl; //prep each molecule type for the simulation for( molTypeIter = allMoleculeTypes.begin(); molTypeIter != allMoleculeTypes.end(); molTypeIter++ ) (*molTypeIter)->prepareForSimulation(); //cout<<"here 7..."<<endl; //add all the molecules to the appropriate observables //NOT NECESSARY - molecules are added to observables when they are prepared //for(obsIter=obsToOutput.begin(); obsIter != obsToOutput.end(); obsIter++) // (*obsIter)->clear(); //for(molTypeIter = allMoleculeTypes.begin(); molTypeIter != allMoleculeTypes.end(); molTypeIter++ ) { // (*molTypeIter)->addAllToObservables(); //} //Add the complexes to Species observables int match = 0; for(obsIter = speciesObservables.begin(); obsIter != speciesObservables.end(); obsIter++) (*obsIter)->clear(); // NETGEN -- this bit replaces the commented block below Complex * complex; allComplexes.resetComplexIter(); while( (complex = allComplexes.nextComplex()) ) { if( complex->isAlive() ) { for(obsIter = speciesObservables.begin(); obsIter != speciesObservables.end(); obsIter++) { match = (*obsIter)->isObservable( complex ); for (int k=0; k<match; k++) (*obsIter)->straightAdd(); } } } /* for(complexIter = allComplexes.allComplexes.begin(); complexIter != allComplexes.end(); complexIter++) { if((*complexIter)->isAlive()) { for(obsIter = speciesObservables.begin(); obsIter != speciesObservables.end(); obsIter++) { match = (*obsIter)->isObservable((*complexIter)); for(int k=0; k<match; k++) (*obsIter)->straightAdd(); } } } */ //cout<<"here 8..."<<endl; //cout<<"here 9..."<<endl; //if(BASIC_MESSAGE) cout<<"preparing the system...\n"; //printIndexAndNames(); // if(go!=NULL) // { // go->writeGroupKeyFile(); // go->writeOutputFileHeader(); // } //finally, create the next reaction selector //this->selector = new LogClassSelector(allReactions); this->evaluateAllLocalFunctions(); recompute_A_tot(); }