/home/msneddon/eclipse/galileoSR1_cpp/workspace/NFsim/src/NFcore/NFcore.hh

Go to the documentation of this file.
00001 
00004 #ifndef NFCORE_HH_
00005 #define NFCORE_HH_
00006 
00007 //Include stl IO and string functionality
00008 #include <iostream>
00009 #include <fstream>
00010 #include <string>
00011 
00012 //Include stl containers
00013 #include <vector>
00014 #include <list>
00015 #include <queue>
00016 #include <map>
00017 
00018 // Include various NFsim classes from other files
00019 #include "../NFscheduler/NFstream.h"
00020 #include "../NFutil/NFutil.hh"
00021 #include "../NFreactions/NFreactions.hh"
00022 #include "moleculeLists/moleculeList.hh"
00023 #include "../NFfunction/NFfunction.hh"
00024 #include "../NFoutput/NFoutput.hh"
00025 #include "reactionSelector/reactionSelector.hh"
00026 
00027 
00028 #include "templateMolecule.hh"
00029 #include "observable.hh"
00030 
00031 #define DEBUG 0                         // Set to 1 to display all debug messages
00032 #define BASIC_MESSAGE 0         // Set to 1 to display basic messages (eg runtime)
00033 
00034 
00035 using namespace std;
00036 
00038 
00048 namespace NFcore
00049 {
00050 
00051         //Forward declarations to deal with cyclic dependencies
00052         class MapGenerator;
00053         class MappingSet;
00054         class ReactantList;
00055         class TransformationSet;
00056         class MoleculeList;
00057 
00058         class GlobalFunction;
00059         class CompositeFunction;
00060         //class FunctionReference;
00061         class LocalFunction;
00062 
00063         class Outputter;
00064         class DumpMoleculeType;
00065         class DumpSystem;
00066 
00067         class TemplateMolecule;
00068         class Observable;
00069         class MoleculesObservable;
00070         class SpeciesObservable;
00071 
00072         /*****************************************
00073          * Class declarations
00074          *    Here is the list of classes that are defined in this
00075          *    header file and are used throughout the NFsim program
00076          */
00077 
00078         class System;  /* the system that contains necessary information to set up,
00079                           run, and output results of the simulation */
00080 
00081         class MoleculeType;  /* indicates the "type" of molecule */
00082         class Molecule;  /* the actual class that represents instances of a molecule */
00083         //class TemplateMolecule; /* used to determine if a molecule matches a particular pattern
00084         //                           think of these as regular expressions for molecule comparison */
00085 
00086         class ReactionClass; /* defines a reaction class, (in other words, a rxn rule) */
00087 
00088         class Observable;  /* object that moniters counts of things we want to keep track of */
00089 
00090         class Complex;  /* collection of molecules that are bonded to each
00091                                                 other and whose membership dynamically can change*/
00092 
00093         class ComplexList;  /* a container class to organize complexes */
00094 
00095         class ReactantList;
00096 
00097         class ReactionSelector;
00098 
00099 
00100 
00102 
00105         class ComplexList
00106         {
00107                 public:
00108                     // constructor, destructor..
00109                         ComplexList();
00110                         ~ComplexList();
00111 
00112                         // initialize, queries, etc
00113                         bool isUsingComplex ( ) const { return useComplex; }
00114             void setUseComplex ( bool _useComplex ) { useComplex = _useComplex; }
00115             void setSystem ( System * _sys ) { sys = _sys; }
00116 
00117             // core methods of this class
00118                         int createComplex(Molecule * m);
00119                         Complex * getComplex(int ID_complex) const { return allComplexes.at(ID_complex); };
00120                         Complex * getNextAvailableComplex();
00121                         void notifyThatComplexIsAvailable(int ID_complex);
00122 
00123                         // output and printing
00124                         void printAllComplexes();
00125                         void purgeAndPrintAvailableComplexList(); /*< ONLY USE FOR DEBUG PURPOSES, AS THIS DELETES ALL COMPLEX BOOKKEEPING */
00126                         void outputComplexSizes(double cSampleTime);
00127                         void outputMoleculeTypeCountPerComplex(MoleculeType *m);
00128                         double outputMeanCount(MoleculeType *m);
00129                         double calculateMeanCount(MoleculeType *m);
00130 
00131             // a public iterator:
00132                         // sets an iternal iterator to the beginning of the vector
00133                         void resetComplexIter() {  complexIter_public = allComplexes.begin();  };
00134 
00135                         // returns the next complex ptr on the vector and increments iterator.  Returns 0 if at the end of the vector.
00136                         Complex * nextComplex() {  return (complexIter_public < allComplexes.end() ? *complexIter_public++ : 0);  };
00137 
00138 
00139                 protected:
00140                         vector <Complex * > allComplexes;         
00141                         queue <int> nextAvailableComplex;         
00143                         System * sys;                             /* pointer to the system which this ComplexList belongs to */
00144                         bool useComplex;                          /* true if the system is tracking complexes */
00145 
00146                 private:
00147                         vector <Complex *>::iterator  complexIter;         /* to iterate over allComplexes */
00148                         vector <Complex *>::iterator  complexIter_public;  /* to iterator over allComplexes, associated with public iterator */
00149         };
00150 
00151 
00152 
00154 
00166         class System
00167         {
00168         
00169                 // _NETGEN_
00170             // Netgen is a system wrapper for network generation and
00171                 // needs access to protected elements of System.
00172                 friend class Netgen;
00173 
00174                 public:
00175 
00180                         System(string name);
00181 
00186                         System(string name, bool useComplex);
00187 
00192                         System(string name, bool useComplex, int globalMoleculeLimit);
00193 
00197                         ~System();
00198 
00199                         // Basic functions to get the properties and objects of the system
00200                         string getName() const { return name; };
00201                         bool isUsingComplex() { return useComplex; };   // NETGEN -- is this needed?
00202                         bool isOutputtingBinary() { return useBinaryOutput; };
00203                         double getCurrentTime() const { return current_time; };
00204                         int getGlobalMoleculeLimit() const { return globalMoleculeLimit; };
00205 
00206                         int getMolObsCount(int moleculeTypeIndex, int observableIndex) const;
00207                         Observable * getObservableByName(string obsName);
00208                         double getAverageGroupValue(string groupName, int valIndex);
00209 
00210                         ReactionClass *getReaction(int rIndex) { return allReactions.at(rIndex); };
00211 
00212                         MoleculeType * getMoleculeType(int mtIndex) { return allMoleculeTypes.at(mtIndex); };
00213                         MoleculeType * getMoleculeTypeByName(string name);
00214                         int getNumOfMoleculeTypes() { return allMoleculeTypes.size(); };
00215                         Molecule * getMoleculeByUid(int uid);
00216                     int getNumOfMolecules();
00217 
00218                         //Functions used when setting up the system.  Note that most of these methods
00219                         //are called automatically when you create an object (notable exception are
00220                         //reactions), so use these methods with caution!  You probably don't need to
00221                         //use them!
00222                         int addMoleculeType(MoleculeType *moleculeType);
00223                         void addReaction(ReactionClass *reaction);
00224                         void addNecessaryUpdateReaction(ReactionClass *reaction);
00225                         // NETGEN
00226                         //int createComplex(Molecule * m);
00227 
00228                         bool addGlobalFunction(GlobalFunction *gf);
00229                         GlobalFunction * getGlobalFunctionByName(string fName);
00230                         bool addCompositeFunction(CompositeFunction *cf);
00231                         CompositeFunction * getCompositeFunctionByName(string fName);
00232                         void finalizeCompositeFunctions();
00233 
00234                         void printAllFunctions();
00235 
00236 
00237                         LocalFunction * getLocalFunctionByName(string fName);
00238                         //bool addFunctionReference(FunctionReference *fr);
00239 
00240                         /* once all elements are added, we need to prepare and initialize for simulations */
00241                         void prepareForSimulation();
00242 
00243 
00244                         void setUniversalTraversalLimit(int utl);
00245 
00246 
00247 
00248                         /* tell the system where to ouptut results*/
00249                         void setOutputToBinary();
00250                         void registerOutputFileLocation(string filename);
00251 
00252 
00253                         void setDumpOutputter(DumpSystem *ds);
00254                         void tryToDump();
00255 
00256                         void turnOnGlobalFuncOut() { this->outputGlobalFunctionValues=true; };
00257                         void turnOffGlobalFuncOut() { this->outputGlobalFunctionValues=false; };
00258 
00259 
00260                         void tagReaction(int rID);
00261 
00262 
00263 
00264                         void addLocalFunction(LocalFunction *lf);
00265                         void getLocalFunction(string funcName) const { cout<<"getLocalFunction not yet implemented."<<endl;exit(1);};
00266 
00267 
00268                         /* functions to output simulation properties to the registered file*/
00269                         void outputAllObservableNames();
00270                         void outputAllObservableCounts();
00271                         void outputAllObservableCounts(double cSampleTime);
00272                         void outputAllObservableCounts(double cSampleTime,int eventCounter);
00273                         int getNumOfSpeciesObs() const;
00274                         Observable * getSpeciesObs(int index) const;
00275 
00276                         /* functions that print out other information to the console */
00277                         // NETGEN
00278                         //void printAllComplexes();
00279                         void printAllReactions();
00280                         void printIndexAndNames();
00281                         void printAllMoleculeTypes();
00282 
00283                         void printAllObservableCounts();
00284                         void printAllObservableCounts(double cSampleTime);
00285                         void printAllObservableCounts(double cSampleTime,int eventCounter);
00286 
00287                         // NETGEN
00288                         //void purgeAndPrintAvailableComplexList(); /*< ONLY USE FOR DEBUG PURPOSES, AS THIS DELETES ALL COMPLEX BOOKKEEPING */
00289                         //void outputComplexSizes(double cSampleTime);
00290                         //void outputMoleculeTypeCountPerComplex(MoleculeType *m);
00291                         //double outputMeanCount(MoleculeType *m);
00292                         //double calculateMeanCount(MoleculeType *m);
00293 
00294                         void update_A_tot(ReactionClass *r, double old_a, double new_a);
00295 
00296 
00297 
00298 
00299                         void evaluateAllLocalFunctions();
00300 
00301 
00302                         void addObservableForOutput(Observable *o);
00303 
00304                         void addOutputter(Outputter *op);
00305                         void dumpOutputters();
00306 
00307 
00308                         /* functions needed while running the simulation */
00309                         // NETGEN
00310                         //Complex * getComplex(int ID_complex) const { return allComplexes.at(ID_complex); };
00311                         //Complex * getNextAvailableComplex();
00312                         //void notifyThatComplexIsAvailable(int ID_complex);
00313 
00314                         double sim(double time, long int sampleTimes);
00315 
00316                         /* run the simulation for a given length of time, output all results to the registered
00317                          * file.  The number of sample times is the number of times the function will output to
00318                          * a file divided equally throughout the elapsed time  */
00319                         double sim(double time, long int sampleTimes, bool verbose);
00320 
00321                         /* run the simulation up until the stopping time (but not exceding the stopping time. This
00322                          * will not output anything to file (so must be done manually) and returns the current time
00323                          * of the simulation, which will always be less than the stopping time */
00324                         double stepTo(double stoppingTime);
00325 
00326                         void singleStep();
00327 
00328                         /* runs the simulation without output for the given time.  After, the clock is reset to
00329                          * to the start time, so it is as if no time has elapsed */
00330                         void equilibrate(double duration);
00331                         void equilibrate(double duration, int statusReports);
00332 
00333 
00334                         //For moleculeTypes to do a quick lookup and see where a particular reaction
00335                         //is mapped to.  This is an optimization....
00336                         void registerRxnIndex(int rxnId, int rxnPos, int rxnIndex) {rxnIndexMap[rxnId][rxnPos]=rxnIndex;};
00337                         int getRxnIndex(int rxnId, int rxnPos) const { return rxnIndexMap[rxnId][rxnPos]; };
00338 
00339                         void turnOff_OnTheFlyObs();
00340                         void turnOnOutputEventCounter() { outputEventCounter=true; };
00341 
00342                         void addParameter(string name,double value);
00343                         double getParameter(string name);
00344                         void setParameter(string name, double value);
00345                         void updateSystemWithNewParameters();
00346                         void printAllParameters();
00347 
00348                 NFstream& getOutputFileStream();
00349 
00350                 // NETGEN -- method to access allComplexes
00351                 ComplexList & getAllComplexes( )  {  return allComplexes;  };
00352 
00356                         static int NULL_EVENT_COUNTER;
00357 
00362                         void turnOnCSVformat() { this->csvFormat = true; };
00363 
00364                 protected:
00365 
00367                         // The invariant system properties, created when the system is created and before
00368                         // the system is prepared
00369                         string name;         
00370                         // NETGEN -- is this needed?
00371                         bool useComplex;     
00372                         bool useBinaryOutput; 
00373                         int universalTraversalLimit; 
00374                         bool onTheFlyObservables;    
00375                     bool outputGlobalFunctionValues; /*< set to true to output the value of all global functions at each output step */
00376                     int globalMoleculeLimit; /*< total number of any particular molecule that can be created, default=100,000 */
00377                     bool outputEventCounter; /*< set to true to output the cumulative number of events at each output step */
00378 
00379                     int globalEventCounter;
00380 
00382                         // The container objects that maintain the core system configuration
00383                         vector <MoleculeType *> allMoleculeTypes;  
00384                         vector <ReactionClass *> allReactions;    
00385             // NETGEN
00386                         //vector <Complex * > allComplexes;         /*!< container of all complexes in the simulation */
00387                         //queue <int> nextAvailableComplex;         /*!< queue tells us which complexes can be used next */
00388                         vector <Outputter *> allOutputters;    
00390                         ComplexList  allComplexes;                
00392                         vector <Observable *> obsToOutput; 
00393                         vector <Observable *> speciesObservables;
00394 
00395                         DumpSystem *ds;
00396 
00397 
00399                         // The container objects that maintain the functional expressions
00400                         //vector <FunctionReference *> functionReferences;
00401                         vector <GlobalFunction *> globalFunctions;    
00402                         vector <LocalFunction *> localFunctions;      
00403                         vector <ReactionClass *> necessaryUpdateRxns; 
00405                         vector <CompositeFunction *> compositeFunctions;
00406 
00407 
00409                         // Properties of the system that update in time
00410                         double a_tot;        /*< the sum of all a's (propensities) of all reactions */
00411                         double current_time; /*< keeps track of the simulation time */
00412                         ReactionClass * nextReaction;  /*< keeps track of the next reaction to fire */
00413 
00415                         // protected functions needed only by the system while running a simulation
00416                         double get_A_tot() const { return a_tot; };
00417                         double recompute_A_tot();
00418                         double getNextRxn();
00419 
00420 
00422                         // Neccessary variables and methods for outputting
00423                         //ofstream outputFileStream; /* the stream to a file to write out the results */
00424                         NFstream outputFileStream; /* NFstream is a smart stream that uses ofstream or stringstream depending on whether NF_MPI is defined */
00425                         void outputGroupDataHeader();
00426 
00427 
00428                         void outputAllPropensities(double time, int rxnFired);
00429                         ofstream propensityDumpStream;
00430 
00431                         bool csvFormat;
00432 
00433 
00435                         //random data structures and variables used for optimization....
00436                         int **rxnIndexMap; 
00440                         map <string,double> paramMap;
00441 
00442 
00443 
00444                         //Data structure that performs the selection of the next reaction class
00445                         ReactionSelector * selector;
00446 
00447 
00448                 private:
00449                         list <Molecule *> molList;
00450                         list <Molecule *>::iterator molListIter;
00451 
00453                         //Iterators that allow fast traversal of the object containers
00454 
00455                         vector<Observable *>::iterator obsIter;
00456                         vector<MoleculeType *>::iterator molTypeIter;  /* to iterate over allMoleculeType */
00457                         vector <ReactionClass *>::iterator rxnIter;    /* to iterate over allReactions */
00458                         // NETGEN -- moved to ComplexList class
00459                         //vector <Complex *>::iterator complexIter;      /* to iterate over allComplexes */
00460                         vector <GlobalFunction *>::iterator functionIter; /* to iterate over Global Functions */
00461         };
00462 
00463 
00464 
00466 
00477         class MoleculeType
00478         {
00479                 public:
00480 
00481                         MoleculeType(
00482                                         string name,
00483                                         vector <string> &compName,
00484                                         System *s);
00485 
00486                         MoleculeType(
00487                                         string name,
00488                                         vector <string> &compName,
00489                                         vector <string> &defaultCompState,
00490                                         System *s);
00491 
00492                         MoleculeType(
00493                                         string name,
00494                                         vector <string> &compName,
00495                                         vector <string> &defaultCompState,
00496                                         vector < vector<string> > &possibleCompStates,
00497                                         System *system);
00498 
00499                         MoleculeType(
00500                                         string name,
00501                                         vector <string> &compName,
00502                                         vector <string> &defaultCompState,
00503                                         vector < vector<string> > &possibleCompStates,
00504                                         vector <bool> isIntegerComponent,
00505                                         System *system);
00506 
00507 
00508                         ~MoleculeType();
00509 
00510                         string getName() const { return name; };
00511                         int getTypeID() const { return type_id; };
00512                         System * getSystem() const { return system; };
00513 
00514                         //Function to access component information
00515                         int getNumOfComponents() const { return numOfComponents; };
00516                         string getComponentName(int cIndex) const;
00517                         void getPossibleComponentStates(int cIndex, list <string> &nameList);
00518                         int getDefaultComponentState(int cIndex) const { return defaultCompState[cIndex]; };
00519 
00520                         int getCompIndexFromName(string cName) const;
00521                         string getComponentStateName(int cIndex, int cValue);
00522                         int getStateValueFromName(int cIndex, string stateName) const;
00523 
00524 
00525                         //set of functions that deal with equivalent (aka symmetric) components
00526                         int getNumOfEquivalencyClasses() const { return this->n_eqComp; };
00527                         string *getEquivalencyClassCompNames() const { return this->eqCompOriginalName; };
00528                         void addEquivalentComponents(vector <vector <string> > &identicalComponents);
00529                         bool isEquivalentComponent(string cName) const;
00530                         bool isEquivalentComponent(int cIndex) const;
00531                         void getEquivalencyClass(int *&components, int &n_components, string cName) const;
00532                         int getEquivalencyClassNumber(string cName) const;
00533 
00534 
00535                         bool isIntegerComponent(string cName) const;
00536                         bool isIntegerComponent(int cIndex) const;
00537 
00538                         //functions that handle the observables
00539                         int getNumOfMolObs() const { return (int)molObs.size(); };
00540                         string getMolObsName(int obsIndex) const;
00541                         MoleculesObservable * getMolObs(int obsIndex) const { return molObs.at(obsIndex); };
00542                         int getMolObsCount(int obsIndex) const;
00543                         void removeFromObservables(Molecule * m);
00544                         void addToObservables(Molecule * m);
00545                         void outputMolObsNames(NFstream &fout);
00546                         void outputMolObsCounts(NFstream &fout);
00547                         void printMolObsNames();
00548                         void printMolObsCounts();
00549 
00550 
00551 
00552                         void addAllToObservables();
00553 
00554 
00555                         //function to access particular molecules or reactions (these are really only
00556                         //used when debugging or running the walker...
00557                         Molecule * getMolecule(int ID_molecule) const;
00558                         int getMoleculeCount() const;
00559 
00560                         int getReactionCount() const { return reactions.size(); };
00561                         int getRxnIndex(ReactionClass * rxn, int rxnPosition);
00562 
00563 
00564 
00565                         //Functions to generate molecules, remove molecules at the beginning
00566                         //or during a running simulation
00567                         Molecule *genDefaultMolecule();
00568 
00569                         void addMoleculeToRunningSystem(Molecule *&mol);
00570                         void removeMoleculeFromRunningSystem(Molecule *&m);
00571                         void removeFromRxns(Molecule * m);
00572 
00573 
00574 
00575                         //Adds the basic components that this MoleculeType needs to reference
00576                         void addReactionClass(ReactionClass * r, int rPosition);
00577                         void addMolObs(MoleculesObservable * mo) { molObs.push_back(mo); }; //could add check here to make sure observable is of this type
00578                         // TODO: Question by Justin... why doesn't the Molecule construct create the complex directly?
00579                         // I believe it is because the System must know about all complexes that are created. -michael
00580                         int createComplex(Molecule *m) { return (system->getAllComplexes()).createComplex(m); };
00581                         void addTemplateMolecule(TemplateMolecule *t);
00582 
00583                         /* handle DOR reactions */
00584                         //void addDORrxnClass(ReactionClass * r, int rPosition);
00585                         //int getDORrxnCount() const { return indexOfDORrxns.size(); };
00586                         //ReactionClass * getDORrxn(int index) const { return reactions.at(indexOfDORrxns.at(index)); };
00587                         //int getDORreactantPosition(int index) const { return reactionPositions.at(indexOfDORrxns.at(index)); };
00588                         //int getDORreactantIndex(int index) const { return indexOfDORrxns.at(index); };
00589 
00590 
00591                         /* updates a molecules membership (assumes molecule is of type this) */
00592                         void updateRxnMembership(Molecule * m);
00593 
00594                         /* auto populate with default molecules */
00595                         void populateWithDefaultMolecules(int moleculeCount);
00596 
00597                         /* this method assumes all molecules in the simulation
00598                          * have been defined, and all reaction classes and observables
00599                          * have been added.  Then, this function will add those
00600                          * molecules to rxn lists and instantiate the counts of the observables.
00601                          * In general, you do not need to worry about this function because
00602                          * it automatically gets called by the System when you prepare the System*/
00603                         void prepareForSimulation();
00604 
00605 
00606                         //Debugging function that prints some useful information about this MoleculeType
00607                         void printDetails() const;
00608                         void printAllMolecules();
00609 
00610 
00611                         //Functionality for local functions
00612 
00613                         /* Type I local functions are functions that this molecule type needs to have
00614                          * always updated because it can react in a DOR reaction which needs the specified
00615                          * function.  DOR reactions identify these MoleculeTypes and add their function to
00616                          * the list of Type I functions for this MoleculeType.
00617                          *
00618                          * Type II local functions are those that require this MoleculeType as an observable
00619                          * or counter to be evaluated.  When this molecule gets updated, it has to automatically
00620                          * update all of its type II local functions.
00621                          *
00622                          * These functions return the index in the array indicating where these functions were
00623                          * added.  This allows local functions to quickly update molecules that need the local
00624                          * function information.
00625                          */
00626                         int addLocalFunc_TypeI(LocalFunction *lf);
00627                         int addLocalFunc_TypeII(LocalFunction *lf);
00628                         vector <LocalFunction *> locFuncs_typeI;
00629                         vector <LocalFunction *> locFuncs_typeII;
00630 
00631                         int getNumOfTypeIFunctions() const {return locFuncs_typeI.size(); };
00632                         LocalFunction *getTypeILocalFunction(int index) { return locFuncs_typeI.at(index); };
00633                         int getNumOfTypeIIFunctions() const {return locFuncs_typeII.size(); };
00634                         LocalFunction *getTypeIILocalFunction(int index) { return locFuncs_typeII.at(index); };
00635 
00636                         int getNumOfDORrxns() const { return indexOfDORrxns.size(); };
00637                         ReactionClass * getDORrxn(int dorRxnIndex) const { return reactions.at(indexOfDORrxns.at(dorRxnIndex)); };
00638                         int getDORrxnIndex(int dorRxnIndex) const { return indexOfDORrxns.at(dorRxnIndex); };
00639                         int getDORrxnPosition(int dorRxnIndex) const { return reactionPositions.at(indexOfDORrxns.at(dorRxnIndex)); };
00640 
00641                         void setUpLocalFunctionListForMolecules();
00642 
00643                 protected:
00644 
00645                         void init(
00646                                 string name,
00647                                 vector <string> &compName,
00648                                 vector <string> &defaultCompState,
00649                                 vector < vector<string> > &possibleCompStates,
00650                                 vector <bool> isIntegerComponent,
00651                                 System *system);
00652 
00653 
00654                         //basic info
00655                         System *system;
00656                         string name;
00657                         int type_id;
00658 
00659                         //keeps track of the key information about a MoleculeType - the component
00660                         int numOfComponents;
00661                         string *compName;
00662                         vector < vector < string > > possibleCompStates;
00663                         int *defaultCompState;
00664                         bool *isIntegerCompState;
00665 
00666 
00667                         //set of variables to keep track of equivalent (aka symmetric) components
00668                         int n_eqComp;
00669                         string *eqCompOriginalName;
00670                         int * eqCompSizes;
00671                         string **eqCompName;
00672                         int **eqCompIndex;
00673 
00674 
00675                         //Lists and vectors of everything we need to know
00676                         MoleculeList * mList;
00677 
00678                         vector <ReactionClass *> reactions; /* List of reactions that this type can be involved with */
00679                         vector <int> reactionPositions;   /* the position in the reaction for this type of molecule */
00680 
00681                         vector <int> indexOfDORrxns;
00682 
00683 
00684                         vector <MoleculesObservable *> molObs;  /* list of things to keep track of */
00685 
00686                         vector <TemplateMolecule *> allTemplates; /* keep track of all templates that exist of this type
00687                                                                                                                         so that they are easy to delete from memory at the end */
00688 
00689                         ReactionClass *rxn; /*used so we don't need to redeclare this at every call to updateRxnMembership */
00690 
00691 
00692 
00693                 private:
00694                         //Some iterators so we don't have to instantiate a new iterator every time
00695                         vector<Molecule *>::iterator molIter;  /* to iterate over mInstances */
00696                         vector<MoleculesObservable *>::iterator molObsIter; /* to iterate over observables */
00697                         vector <ReactionClass *>::iterator rxnIter; /* to iterate over reactions */
00698         };
00699 
00700 
00701 
00703 
00712         class Molecule
00713         {
00714                 public:
00715 
00716                         /* constructors / deconstuctors */
00717                         Molecule(MoleculeType * parentMoleculeType, int listId);
00718                         ~Molecule();
00719 
00720                         /* basic get functions for name, type, complex, and IDs*/
00721                         int getMolListId() const { return listId; };
00722                         string getMoleculeTypeName() const { return parentMoleculeType->getName(); };
00723                         MoleculeType * getMoleculeType() const { return parentMoleculeType; };
00724                         int getUniqueID() const { return ID_unique; };
00725                         bool isAlive() const { return isAliveInSim; };
00726                         void setAlive(bool isAlive) { isAliveInSim = isAlive; };
00727 
00728                         void setComplexID(int currentComplex) { this->ID_complex=currentComplex; }
00729 
00730                         int getComplexID() const { return ID_complex; };
00731                         Complex * getComplex() const { return (parentMoleculeType->getSystem()->getAllComplexes()).getComplex(ID_complex); };
00732                         int getDegree();
00733 
00734 
00736                         int getComponentState(int cIndex) const { return component[cIndex]; };
00737                         int getComponentIndexOfBond(int cIndex) const { return indexOfBond[cIndex]; };
00738                         void setComponentState(int cIndex, int newValue);
00739                         void setComponentState(string cName, int newValue);
00740 
00741 
00743                         void setLocalFunctionValue(double newValue,int localFunctionIndex);
00744                         double getLocalFunctionValue(int localFunctionIndex);
00745                         LocalFunction * getLocalFunction(int localFunctionIndex);
00746                         void setUpLocalFunctionList();
00747 
00748 
00750 
00751                         /* accessor functions for checking binding sites */
00752                         bool isBindingSiteOpen(int bIndex) const;
00753                         bool isBindingSiteBonded(int bIndex) const;
00754                         Molecule * getBondedMolecule(int bSiteIndex) const;
00755                         int getBondedMoleculeBindingSiteIndex(int cIndex) const;
00756 
00757                         int getRxnListMappingId(int rxnIndex) const { return rxnListMappingId[rxnIndex]; };
00758                         void setRxnListMappingId(int rxnIndex, int rxnListMappingId) {
00759                                         this->rxnListMappingId[rxnIndex] = rxnListMappingId;
00760                         };
00761 
00762                         /* set functions for states, bonds, and complexes */
00763                         //void setState(const char * stateName, int value);
00764                         //void setState(int stateIndex, int value);
00765                         void setBondTo(Molecule * m2, int bindingSiteIndex);
00766                         void moveToNewComplex(int newComplexID) { ID_complex = newComplexID; };
00767 
00768 
00769                         /* static functions which bind and unbind two molecules */
00770                         static void bind(Molecule *m1, int cIndex1, Molecule *m2, int cIndex2);
00771                         static void bind(Molecule *m1, string compName1, Molecule *m2, string compName2);
00772                         static void unbind(Molecule *m1, int bSiteIndex);
00773                         static void unbind(Molecule *m1, char * bSiteName);
00774 
00775 
00776                         /* functions needed to traverse a complex and get all components
00777                          * which is important when we want to update reactions and complexes */
00778                         void traverseBondedNeighborhood(list <Molecule *> &members, int traversalLimit);
00779                         static void breadthFirstSearch(list <Molecule *> &members, Molecule *m, int depth);
00780                         void depthFirstSearch(list <Molecule *> &members);
00781 
00782                         /* when we are ready to begin simulations, moleculeType calls this function
00783                          * so that this molecule can add itself to all the necessary lists */
00784                         void prepareForSimulation();
00785 
00786                         /* function that tells this molecule that it changed states or bonds
00787                          * and it should update its reaction membership */
00788                         void updateRxnMembership();
00789                         void removeFromObservables();
00790                         void addToObservables();
00791                         //void updateDORs();
00792 
00793                         //double getDORvalueFromGroup(string groupName, int valueIndex);
00794 
00795 
00796 
00797                         /* DOR Functions*/
00798                         void updateTypeIIFunctions();
00799                         void updateDORRxnValues();
00800 
00801 
00802 
00803                         /* print functions for debugging */
00804                         void printDetails();
00805                         void printDetails(ostream &o);
00806                         static void printMoleculeList(list <Molecule *> &members);
00807 
00808                         static int getUniqueIdCount() { return uniqueIdCount; };
00809                         static const int NOT_IN_RXN = -1;
00810 
00811 
00812                         int isObs(int oIndex) const { return isObservable[oIndex]; };
00813                         void setIsObs(int oIndex, int isObs) { isObservable[oIndex]=isObs; };
00814 
00815 
00816                         /* used for traversing a molecule complex */
00817                         bool hasVisitedMolecule;
00818                         bool * hasVisitedBond;
00819                         TemplateMolecule *isMatchedTo;
00820 
00821                         /* used when reevaluating local functions */
00822                         bool hasEvaluatedMolecule;
00823 
00824 
00825                         static const int NOSTATE = -1;
00826                         static const int NOBOND = 0;
00827                         static const int NOINDEX = -1;
00828 
00829 
00830                         //void addDependentUpdateMolecule(Molecule *m);
00831                         //void removeDependentUpdateMolecule(Molecule *m);
00832                         //void traverseBondedNeighborhoodForUpdate(list <Molecule *> &members, int traversalLimit);
00833 
00834 
00835                         //Unnecessary functions now that were once used to
00836                         //mark a molecule that is not in the simulation
00837                         //bool isMolAlive() const { return !isDead; };
00838                         //bool isMolDead() const { return isDead; };
00839                         //void kill() { isDead = true; };
00840                         //void create() { isDead = false; };
00841 
00842 
00843                 protected:
00844 
00845 
00846                         bool isPrepared;
00847                         bool isAliveInSim;
00848 
00849                         /* Set of IDs which identifies uniquely this molecule */
00850                         int ID_complex;
00851                         int ID_type;
00852                         int ID_unique;
00853                         int listId;
00854 
00855 
00856                         static int uniqueIdCount;
00857 
00858                         /* The type of this molecule */
00859                         MoleculeType *parentMoleculeType;
00860                         bool useComplex;
00861 
00862 
00863                         /* store the states and bonds in arrays */
00864 
00865 
00867                         /* list of components */
00868                         int *component;
00869                         int numOfComponents;
00870                         Molecule **bond;
00871                         int *indexOfBond; /* gives the index of the component that is bonded to this molecule */
00872 
00873 
00875                         double *localFunctionValues;
00876 
00877 
00878                         //keep track of which observables I match (and how many times I match it)
00879                         int *isObservable;
00880 
00881 
00882                         //Used to keep track of which reactions this molecule is in...
00883                         int * rxnListMappingId;
00884                         int nReactions;
00885 
00886 
00887                         // dependent update molecule list, so that when this molecule updates,
00888                         // it necessarily updates whatever is on this list.  This list will capture non
00889                         // local interactions that need to be maintained that result from the connected-to syntax
00890                         // list <Molecule *> dependentUpdateMolecules
00891                         //list <Molecule *> dependentUpdateMolecules;
00892 
00893 
00894                 private:
00895 
00896                         static queue <Molecule *> q;
00897                         static queue <int> d;
00898                         static list <Molecule *>::iterator molIter;
00899                         //static list <Molecule *>::iterator molIter2;
00900 
00901         };
00902 
00903 
00904 
00905 
00906 
00907 
00908 
00909 
00910 
00911 
00913 
00932         class ReactionClass
00933         {
00934                 // _NETGEN_
00935                 friend class MatchSetIter;
00936                 friend class Netgen;
00937 
00938                 public:
00939                         static const int NO_LIMIT = -3;
00940 
00941                         static const int BASIC_RXN = 0;
00942                         static const int DOR_RXN = 1;
00943                         static const int OBS_DEPENDENT_RXN = 2;
00944 
00945 
00946 
00947                         ReactionClass(string name, double rate, string baseRateParameterName, TransformationSet *transformationSet, System *s);
00948                         virtual ~ReactionClass();
00949 
00950                         int getNumOfReactants() const { return n_reactants; };
00951 
00952                         string getName() const { return name; };
00953                         double getBaseRate() const { return baseRate; };
00954                         int getRxnType() const { return reactionType; };
00955 
00956                         void setBaseRate(double newBaseRate,string newBaseRateName) {
00957                                 if(isDimerStyle) {
00958                                         this->baseRate=newBaseRate*0.5;
00959                                 }
00960                                 else this->baseRate=newBaseRate;
00961                                 this->baseRateParameterName=newBaseRateName;
00962                                 update_a();
00963                         };
00964 
00965                         void resetBaseRateFromSystemParamter();
00966 
00967                         void setTraversalLimit(int limit) { this->traversalLimit = limit; };
00968 
00969                         double get_a() const { return a; };
00970                         virtual void printDetails() const;
00971                         void fire(double random_A_number);
00972 
00973                         //For DOR reactions
00974                         virtual void notifyRateFactorChange(Molecule * m, int reactantIndex, int rxnListIndex) = 0;
00975                         virtual int getDORreactantPosition() const { cerr<<"Trying to get DOR reactant Position from a reaction that is not of type DOR!"<<endl;
00976                         cerr<<"this is an internal error, and so I will quit."<<endl; exit(1); return -1; };
00977 
00978 
00979                         //The main virtual functions that must be implemented in all implementing classes
00980                         virtual void init() = 0; //called when the reaction is added to the system
00981                         virtual void prepareForSimulation() = 0; //called once everything is added to the system
00982                         virtual bool tryToAdd(Molecule *m, unsigned int reactantPos) = 0;
00983                         virtual void remove(Molecule *m, unsigned int reactantPos) = 0;
00984 
00985                         virtual double update_a() = 0;
00986 
00987 
00988 
00989                         /* turn the tag of this guy on */
00990                         void tag() { tagged = true; };
00991 
00992 
00993                         virtual unsigned int getReactantCount(unsigned int reactantIndex) const = 0;
00994                         virtual void printFullDetails() const = 0;
00995 
00996 
00997                         void setRxnId(int rxnId) { this->rxnId = rxnId; };
00998                         int getRxnId() const { return rxnId; };
00999 
01000 
01001                         void turnOff_OnTheFlyObs() { onTheFlyObservables=false; };
01002 
01003 
01004                         void setTotalRateFlag(bool totalRate) { totalRateFlag = totalRate; };
01005 
01006                         // _NETGEN_
01007                         void set_match( vector <MappingSet *> & match_set );
01008                         void apply( vector <Molecule *> & product_molecules );
01009 
01010 
01011                 protected:
01012                         virtual void pickMappingSets(double randNumber) const=0;
01013 
01014                         int rxnId;
01015 
01016                         /* if this reaction is tagged, it outputs a message everytime it is fired */
01017                         bool tagged;
01018 
01019                         string name;
01020                         int reactionType;
01021                         unsigned int n_reactants;
01022 
01023                         System * system;
01024 
01025                         double baseRate;
01026                         string baseRateParameterName;
01027                         double a;
01028                         unsigned int fireCounter;
01029 
01030                         unsigned int traversalLimit;
01031 
01032                         TemplateMolecule **reactantTemplates;
01033                         TransformationSet * transformationSet;
01034                         MappingSet **mappingSet;
01035 
01036                         bool onTheFlyObservables;
01037                         bool isDimerStyle;
01038 
01039 
01040                         list <Molecule *> products;
01041                         list <Molecule *>::iterator molIter;
01042 
01043                         //Used by the reaction class to make sure that it only updates
01044                         //each complex once (for observables, and matchOnce reactants)
01045                         vector <int> updatedComplexes;
01046 
01047 
01051                         bool totalRateFlag;
01052         };
01053 
01054 
01055 
01056 
01057 
01058 
01059 
01060 
01061 
01062 
01063 
01064 
01065 
01067 
01070         class Complex
01071         {
01072                 public:
01073                         Complex(System * s, int ID_complex, Molecule * m);
01074                         ~Complex();
01075 
01076 
01077                         bool isAlive();
01078                         int getComplexID() const { return ID_complex; };
01079                         int getComplexSize() const {return complexMembers.size();};
01080                         int getMoleculeCountOfType(MoleculeType *m);
01081 
01082                         void mergeWithList(Complex * c);
01083 
01084 
01085                         void updateComplexMembership(Molecule * m);
01086 
01087 
01088                         void refactorToNewComplex(int new_ID_complex);
01089 
01090                         void emptyComplexForever() {};
01091 
01092                         static const int UNIFORM = 0;
01093                         static const int FIXED_POINT = 1;
01094                         static const int DIFFUSE_3D = 2;
01095 
01096 
01097                         void printDegreeDistribution();
01098                         void getDegreeDistribution(vector <int> &degreeDist);
01099                         void printDetails();
01100                         void printDetailsLong();
01101 
01102                         //Diffusion functions
01103                         double getDistance(Complex * c) {return 1000.0; };
01104                         double getXpos() { return 0; };
01105                         double getYpos() { return 0; };
01106                         double getZpos() { return 0; };
01107 
01108                         //This is public so that anybody can access the molecules quickly
01109                         list <Molecule *> complexMembers;
01110                         list <Molecule *>::iterator molIter;
01111 
01112 
01113 
01114                 protected:
01115                         System * system;
01116                         int ID_complex;
01117 
01118 
01119                 private:
01120 
01121         };
01122 
01123 }
01124 
01125 #endif /*NFCORE_HH_*/

Generated on Thu Dec 9 11:02:48 2010 for NFsim by  doxygen 1.5.4