Ejemplo n.º 1
0
 def __init__(self, filename=None):
     ecell.ecs.setDMSearchPath( os.pathsep.join( ecell.config.dm_path ) )
     self.sim = ecell.emc.Simulator()
     if ecell.config.version < '3.2.0':
         self.ses = Session(self.sim, changeDirectory=False)
     else:
         self.ses = Session(self.sim)
     
     # Load the model
     self.ses.loadModel(filename)
     self.molToTrack = ('ca',
                        'moles_bound_ca_per_moles_cam',
                        'Rbar',
                        'PP2Bbar', 
                        'CaMKIIbar', 
                        'PP1abar', # Active PP1/Total PP1
                        'AMPAR', # 
                        'AMPAR_P',
                        'D',
                        'totDp',
                        'Dpbar'
                        )
     # Tracking the calcium
     self.ca =  self.ses.createEntityStub( 'Variable:/Spine:ca' )
     self.CaMKIIbar = self.ses.createEntityStub( 'Variable:/Spine:CaMKIIbar' )
     self.ampar_P = self.ses.createEntityStub('Variable:/Spine:AMPAR_P')
     self.ca_in = self.ses.createEntityStub('Process:/Spine:ca_in')
     self.ca_leak = self.ses.createEntityStub('Process:/Spine:ca_leak')
     self.ca_pump = self.ses.createEntityStub('Process:/Spine:ca_pump')
Ejemplo n.º 2
0
    def __init__(self, filename=None):
        ecell.ecs.setDMSearchPath(os.pathsep.join(ecell.config.dm_path))
        self.sim = ecell.emc.Simulator()
        if ecell.config.version < '3.2.0':
            self.ses = Session(self.sim, changeDirectory=False)
        else:
            self.ses = Session(self.sim)

        # Load the model
        self.ses.loadModel(filename)
        self.molToTrack = (
            'ca',
            'moles_bound_ca_per_moles_cam',
            'Rbar',
            'PP2Bbar',
            'CaMKIIbar',
            'PP1abar',  # Active PP1/Total PP1
            'AMPAR',  # 
            'AMPAR_P',
            'D',
            'totDp',
            'Dpbar')
        # Tracking the calcium
        self.ca = self.ses.createEntityStub('Variable:/Spine:ca')
        self.CaMKIIbar = self.ses.createEntityStub('Variable:/Spine:CaMKIIbar')
        self.ampar_P = self.ses.createEntityStub('Variable:/Spine:AMPAR_P')
        self.ca_in = self.ses.createEntityStub('Process:/Spine:ca_in')
        self.ca_leak = self.ses.createEntityStub('Process:/Spine:ca_leak')
        self.ca_pump = self.ses.createEntityStub('Process:/Spine:ca_pump')
Ejemplo n.º 3
0
class QuickEcell():

    def __init__(self, filename):
        """Initialize Ecell simulator creating a session and a simulator object
        and loading the model."""
        # set DM library   
        ecell.ecs.setDMSearchPath( os.pathsep.join( ecell.config.dm_path ) )
        # create sim obj
        self.sim = ecell.emc.Simulator()
        # create the session obj
        self.ses = Session(self.sim, changeDirectory=False)
        # Lod the model
        try:
            self.ses.loadModel(filename)
        except IOError:
            print "IOError: File %s not found." %filename
        
        
    def create_loggers(self, variables):
        """Create the loggers. The variable name is the Key, the ecell logger obj 
        is the Value"""
        
        loggers = {}
        for var in variables:
        	try:
        		loggers[var] = self.ses.createLoggerStub('Variable:/:' + var + ':Value')
	        	loggers[var].create()
	        except RuntimeError:
	        	print "Variable %s not in the model" %var
	        	print "You need to use the same name you've used in the em file."
	        
        return loggers

    def run_and_plot(self, time, variables, loggers):
        """Run the simulator and plot all the variables in the variables."""

        self.ses.run(time)        
        for var in variables:
            self.plot_var(var, loggers)
        plt.legend(loc=0)
        
    def plot_var(self, var, loggers):
        "Plot the specific variable"
        try:
        	var_array = loggers[var].getData()
    		plt.plot(var_array[:,0], var_array[:,1], label=var)
    	except RuntimeError:
    		print "Var %s not in the loggers. Skipping" %var
Ejemplo n.º 4
0
 def __init__(self, filename):
     """Initialize Ecell simulator creating a session and a simulator object
     and loading the model."""
     # set DM library   
     ecell.ecs.setDMSearchPath( os.pathsep.join( ecell.config.dm_path ) )
     # create sim obj
     self.sim = ecell.emc.Simulator()
     # create the session obj
     self.ses = Session(self.sim, changeDirectory=False)
     # Lod the model
     try:
         self.ses.loadModel(filename)
     except IOError:
         print "IOError: File %s not found." %filename
Ejemplo n.º 5
0
class EcellManager():
    """Control and instatiate the ecell simulator embedding it in an handy python object"""
    
    def __init__(self, filename=None):
        ecell.ecs.setDMSearchPath( os.pathsep.join( ecell.config.dm_path ) )
        self.sim = ecell.emc.Simulator()
        if ecell.config.version < '3.2.0':
            self.ses = Session(self.sim, changeDirectory=False)
        else:
            self.ses = Session(self.sim)
        
        # Load the model
        self.ses.loadModel(filename)
        self.molToTrack = ('ca',
                           'moles_bound_ca_per_moles_cam',
                           'Rbar',
                           'PP2Bbar', 
                           'CaMKIIbar', 
                           'PP1abar', # Active PP1/Total PP1
                           'AMPAR', # 
                           'AMPAR_P',
                           'D',
                           'totDp',
                           'Dpbar'
                           )
        # Tracking the calcium
        self.ca =  self.ses.createEntityStub( 'Variable:/Spine:ca' )
        self.CaMKIIbar = self.ses.createEntityStub( 'Variable:/Spine:CaMKIIbar' )
        self.ampar_P = self.ses.createEntityStub('Variable:/Spine:AMPAR_P')
        self.ca_in = self.ses.createEntityStub('Process:/Spine:ca_in')
        self.ca_leak = self.ses.createEntityStub('Process:/Spine:ca_leak')
        self.ca_pump = self.ses.createEntityStub('Process:/Spine:ca_pump')
        
    def createLoggers(self):
        """Create the logger to track the species"""
        loggers = {}
        #log = ecell.LoggerStub()
        
        for mol in self.molToTrack:
            loggers[mol]  = self.ses.createLoggerStub( "Variable:/Spine:" + mol 
                                                       + ":Value" )
            loggers[mol].create() # This creat the Logger Object in the backend
            if mol == 'ca':
                loggers['ca_conc']  = self.ses.createLoggerStub( "Variable:/Spine:" + mol 
                                                       + ":MolarConc" )
                loggers['ca_conc'].create() # This creat the Logger Object in the backend
        
        self.loggers = loggers
        
        
    def calcWeight(CaMKIIbar, PP2Bbar, alpha, beta, n=3, k=0.5):
        """Calc the weight of the synapses according to the CaMKII and Pospahtases
        PP2B and PP1"""
    
        # CaMKII term
        CaMKII_factor = math.pow(CaMKIIbar, n) / (math.pow(k, n) + 
                                                  math.pow(CaMKIIbar, n))
        Phosphatase_factor = math.pow(PP2Bbar, n) / (math.pow(k, n) + 
                                                     math.pow(PP2Bbar, n))
        scaled_CaMKII_factor = alpha * CaMKII_factor
        scaled_Phospatese_factor = beta * Phosphatase_factor 
        weight = 1 + scaled_CaMKII_factor - scaled_Phospatese_factor
        s = "Weight: %s CaMKII factor %s, Phosphatase factor %s" %(weight,
                                                                   scaled_CaMKII_factor,
                                                                   scaled_Phospatese_factor)
        return weight
        
    
    def calcium_peak(self, k_value, duration):
        """
        Mimic the calcium peak
        
        :Parameters
            k_value: the rate of calcium to enter
            duration: Duration of the spike
        """
        
        basal = self.ca_in['k']
        self.ca_in['k'] = k_value
        self.ses.run(duration)
        self.ca_in['k'] = basal
        
    def calciumTrain(self, spikes=30, interval=0.1):
        """Create a train of calcium with the specified number of spikes and interval
        
        :Parameter
            spikes: number of spikes
            interval: Interval between spikes
        """
        for i in range(spikes):
            self.calcium_peak(4.0e8, # Magic number from Lu
                         0.00001 #Really fast spike to avoid the overlap
                         )
            self.ses.run(interval)
        
    def converToTimeCourses(self):
        timeCourses = {}
        for key in self.loggers:
            timeCourses[key] = self.loggers[key].getData()
        
        self.timeCourses = timeCourses
Ejemplo n.º 6
0
class EcellManager():
    """Control and instatiate the ecell simulator embedding it in an handy python object"""
    def __init__(self, filename=None):
        ecell.ecs.setDMSearchPath(os.pathsep.join(ecell.config.dm_path))
        self.sim = ecell.emc.Simulator()
        if ecell.config.version < '3.2.0':
            self.ses = Session(self.sim, changeDirectory=False)
        else:
            self.ses = Session(self.sim)

        # Load the model
        self.ses.loadModel(filename)
        self.molToTrack = (
            'ca',
            'moles_bound_ca_per_moles_cam',
            'Rbar',
            'PP2Bbar',
            'CaMKIIbar',
            'PP1abar',  # Active PP1/Total PP1
            'AMPAR',  # 
            'AMPAR_P',
            'D',
            'totDp',
            'Dpbar')
        # Tracking the calcium
        self.ca = self.ses.createEntityStub('Variable:/Spine:ca')
        self.CaMKIIbar = self.ses.createEntityStub('Variable:/Spine:CaMKIIbar')
        self.ampar_P = self.ses.createEntityStub('Variable:/Spine:AMPAR_P')
        self.ca_in = self.ses.createEntityStub('Process:/Spine:ca_in')
        self.ca_leak = self.ses.createEntityStub('Process:/Spine:ca_leak')
        self.ca_pump = self.ses.createEntityStub('Process:/Spine:ca_pump')

    def createLoggers(self):
        """Create the logger to track the species"""
        loggers = {}
        #log = ecell.LoggerStub()

        for mol in self.molToTrack:
            loggers[mol] = self.ses.createLoggerStub("Variable:/Spine:" + mol +
                                                     ":Value")
            loggers[mol].create(
            )  # This creat the Logger Object in the backend
            if mol == 'ca':
                loggers['ca_conc'] = self.ses.createLoggerStub(
                    "Variable:/Spine:" + mol + ":MolarConc")
                loggers['ca_conc'].create(
                )  # This creat the Logger Object in the backend

        self.loggers = loggers

    def calcWeight(CaMKIIbar, PP2Bbar, alpha, beta, n=3, k=0.5):
        """Calc the weight of the synapses according to the CaMKII and Pospahtases
        PP2B and PP1"""

        # CaMKII term
        CaMKII_factor = math.pow(CaMKIIbar,
                                 n) / (math.pow(k, n) + math.pow(CaMKIIbar, n))
        Phosphatase_factor = math.pow(
            PP2Bbar, n) / (math.pow(k, n) + math.pow(PP2Bbar, n))
        scaled_CaMKII_factor = alpha * CaMKII_factor
        scaled_Phospatese_factor = beta * Phosphatase_factor
        weight = 1 + scaled_CaMKII_factor - scaled_Phospatese_factor
        s = "Weight: %s CaMKII factor %s, Phosphatase factor %s" % (
            weight, scaled_CaMKII_factor, scaled_Phospatese_factor)
        return weight

    def calcium_peak(self, k_value, duration):
        """
        Mimic the calcium peak
        
        :Parameters
            k_value: the rate of calcium to enter
            duration: Duration of the spike
        """

        basal = self.ca_in['k']
        self.ca_in['k'] = k_value
        self.ses.run(duration)
        self.ca_in['k'] = basal

    def calciumTrain(self, spikes=30, interval=0.1):
        """Create a train of calcium with the specified number of spikes and interval
        
        :Parameter
            spikes: number of spikes
            interval: Interval between spikes
        """
        for i in range(spikes):
            self.calcium_peak(
                4.0e8,  # Magic number from Lu
                0.00001  #Really fast spike to avoid the overlap
            )
            self.ses.run(interval)

    def converToTimeCourses(self):
        timeCourses = {}
        for key in self.loggers:
            timeCourses[key] = self.loggers[key].getData()

        self.timeCourses = timeCourses