# Path: stochpy/implementations/StochPyTools.py
# class Species():
# class StochPySSA_Shared(): 
#     def __init__(self):
#     def Parse(self,model_file,model_dir,IsTauleaping=False,IsNRM=False,IsDelayed = False,IsSMM = False,IsQuiet=False):
#     def SpeciesSelection(self):
#     def RateSelection(self):
#     def SetEvents(self):
#     def Propensities(self,IsTauleaping=False):
#     def BuildPropensityCodes(self, propensities = None): # 21-11-2013 
#     def HandleEvents(self,IsTauleapingStep=False):    
#     def AssignmentRules(self):
#     def rateFunc(self,rate_eval_code,r_vec):
#     def Initial_Conditions(self,IsTauleaping = False):              
#     def GenerateOutput(self,IsTauleaping = False,completion_delayed = False):


import sys,copy,time,os
from .StochPyTools import __species__,StochPySSA_Shared,np
            self.SpeciesSelection()   
            self.RateSelection()                           
            self.SetEvents()  # April 15, moved into here, because otherwise each new cell division cycle starts with a time event, if specified            
            if not settings.IsOnlyLastTimepoint:
                self.Initial_Conditions()   
            # Delayed Direct method specific         
            self.Tstruct = [(0, np.nan), (np.inf, np.nan)]  # Will hold delayed reactions      
            
        #Step 3 Initialize P        
        m_randoms = np.random.random(size = self.n_reactions)
        self.P = -1*np.log(m_randoms)                       # Exponential (unit rate) distribution
        self.T = np.zeros(self.n_reactions)                 # Step 1
        self.BuildTaus()                                    # Step 4, initialization        
        
        nstep_counter = 1
        t1 = time.time()
        while self.sim_t < settings.endtime and self.timestep < settings.timesteps:
            if self.sim_a_mu.sum() == 0 and len(self.Tstruct) <= 2:       # All reactants got exhausted and no delayed reactions pending.
                 settings.endtime = 10**50
                 break      

            self.RunExactTimestep()                         # Step 5-10             
            self.HandleEvents()

            #Update system, only if max time or steps is not passed
            if (self.sim_t < settings.endtime) and (self.timestep < settings.timesteps):                
                # Bug Fix Maxim september 05, 2014
                if self._IsPerformEvent:             
                    m_randoms = np.random.random(size = self.n_reactions)
                    self.P = -1*np.log(m_randoms)           # Exponential (unit rate) distribution

# Path: stochpy/implementations/StochPyTools.py
# class Species():
# class StochPySSA_Shared(): 
#     def __init__(self):
#     def Parse(self,model_file,model_dir,IsTauleaping=False,IsNRM=False,IsDelayed = False,IsSMM = False,IsQuiet=False):
#     def SpeciesSelection(self):
#     def RateSelection(self):
#     def SetEvents(self):
#     def Propensities(self,IsTauleaping=False):
#     def BuildPropensityCodes(self, propensities = None): # 21-11-2013 
#     def HandleEvents(self,IsTauleapingStep=False):    
#     def AssignmentRules(self):
#     def rateFunc(self,rate_eval_code,r_vec):
#     def Initial_Conditions(self,IsTauleaping = False):              
#     def GenerateOutput(self,IsTauleaping = False,completion_delayed = False):


# Path: stochpy/implementations/DelayedNRM.py
import sys,copy,time,os
from .StochPyTools import __species__,StochPySSA_Shared,np

            self.SpeciesSelection()   
            self.RateSelection()                           
            self.SetEvents()  # April 15, moved into here, because otherwise each new cell division cycle starts with a time event, if specified            
            if not settings.IsOnlyLastTimepoint:
                self.Initial_Conditions()   
            # Delayed Direct method specific         
            self.Tstruct = [(0, np.nan), (np.inf, np.nan)]  # Will hold delayed reactions      
            
        #Step 3 Initialize P        
        m_randoms = np.random.random(size = self.n_reactions)
        self.P = -1*np.log(m_randoms)                       # Exponential (unit rate) distribution
        self.T = np.zeros(self.n_reactions)                 # Step 1
        self.BuildTaus()                                    # Step 4, initialization        
        
        nstep_counter = 1
        t1 = time.time()
        while self.sim_t < settings.endtime and self.timestep < settings.timesteps:
            if self.sim_a_mu.sum() == 0 and len(self.Tstruct) <= 2:       # All reactants got exhausted and no delayed reactions pending.
                 settings.endtime = 10**50
                 break      

            self.RunExactTimestep()                         # Step 5-10             
            self.HandleEvents()

            #Update system, only if max time or steps is not passed
            if (self.sim_t < settings.endtime) and (self.timestep < settings.timesteps):                
                # Bug Fix Maxim september 05, 2014
                if self._IsPerformEvent:             
                    m_randoms = np.random.random(size = self.n_reactions)
                    self.P = -1*np.log(m_randoms)           # Exponential (unit rate) distribution

                    self.T = np.zeros(self.n_reactions)     # Step 1