<commit_before># This file load the simulation with the python interface
# Usage: open ipython shell and the run the file

import neuron
import numpy
from pylab import *
h = neuron.h

class MyNetStim(neuron.hclass(h.NetStim)):
    """NetStim that allows setting the parameters on the creation"""
    
    def __init__(self, start=50, noise=0, interval=10, number=10):
        self.start = start
        self.interval = interval
        self.noise = noise
        self.number = number
    
    def printPars(self):
        print "Start: %d\tInterval:%d\tNoise:%d\tNumber:%d" %(self.start, self.interval,
                                                              self.noise, self.number)

h.load_file("my_init.hoc")



def stimulGraph(t, stimul):
    """Create a vector of the inputs given to the synapse"""
        # Transforming the vecotr in numpy
    t = numpy.array(t)
    t = numpy.round(t, decimals=9) # round
    
    inputs_event = numpy.zeros_like(t)
    for indx, x in enumerate (t):
        for y in stimul:
            if x == y:
                inputs_event[indx] = 1
                
    masked = numpy.ma.masked_where(inputs_event == 0, inputs_event)
    #figure()
    #return masked
    plot(t, masked, 'k.', label = "stimul")   
    

from spine import *   
spine = Spine()
spine.attach(h.MSP_Cell[0].dend1_1[1], 0.5, 0)

ampa = spine.createAMPASyn()
synVecs = spine.createSynapseVecs(ampa)



####### RIG 

def createVecs(spine):
    """Spine taken as an argument. This has to change somehow"""
    
    vecs = {}
    
    vecs["t"] = h.Vector()
    vecs["t"].record(h._ref_t)
    
    vecs["v_soma"] = h.Vector()
    vecs["v_soma"].record(h.MSP_Cell[0].soma(0.5)._ref_v)
    
    vecs["ca_soma"] = h.Vector()
    vecs["ca_soma"].record(h.MSP_Cell[0].soma(0.5)._ref_cai)
    
    vecs["ca_dend"] = h.Vector()
    vecs["ca_dend"].record(spine.parent(0.5)._ref_cai)

    vecs["v_dend"] = h.Vector()
    #vecs["v_dend"].record(spine.parent(0.5)._ref_v)
    vecs["v_dend"].record(spine.parent(0.5)._ref_v)
    
    vecs["v_spine"] = h.Vector()
    vecs["v_spine"].record(spine(0.5)._ref_v)
    
    return vecs
    
    
def plotVoltage(vecs, synVecs):
    fig = figure()
    ax1 = fig.add_subplot(111) #sub for the two scales
    plot(vecs["t"], vecs["v_soma"], label="soma voltage")
    plot(vecs["t"], vecs["v_dend"], label="dendrite voltage")
    plot(vecs["t"], vecs["v_spine"], label="spine voltage")
    ylabel("voltage [mV]")
    xlabel("time [ms]")
    ax2 = ax1.twinx()
    stimulGraph(vecs["t"], synVecs["stimul"])
    ax2.set_ylim(0,4)
    ax2.set_axis_off()
    t = numpy.array(vecs["t"])
    t = numpy.round(t, decimals=9) # round
    ax1.set_xlim(t[0],t[-1])
    ax1.legend(loc=0)
    return ax1 # No really needed but handy

import neuron.gui
h.load_file("guiRig2.ses")


vecs = createVecs(spine)

def go():
    """Just run the model for the time"""
    h.run()
    plotVoltage(vecs, synVecs)
    show()<commit_msg>Reorganized the code for the init. More structured now<commit_after># This file load the simulation with the python interface
# Usage: open ipython shell and the run the file

import neuron
import numpy
from pylab import *
h = neuron.h

class MyNetStim(neuron.hclass(h.NetStim)):
    """NetStim that allows setting the parameters on the creation"""
    
    def __init__(self, start=50, noise=0, interval=10, number=10):
        self.start = start
        self.interval = interval
        self.noise = noise
        self.number = number
    
    def printPars(self):
        print "Start: %d\tInterval:%d\tNoise:%d\tNumber:%d" %(self.start, self.interval,
                                                              self.noise, self.number)

def stimulGraph(t, stimul):
    """Create a vector of the inputs given to the synapse"""
        # Transforming the vecotr in numpy
    t = numpy.array(t)
    t = numpy.round(t, decimals=9) # round
    
    inputs_event = numpy.zeros_like(t)
    for indx, x in enumerate (t):
        for y in stimul:
            if x == y:
                inputs_event[indx] = 1
                
    masked = numpy.ma.masked_where(inputs_event == 0, inputs_event)
    #figure()
    #return masked
    plot(t, masked, 'k.', label = "stimul")   
    
####### RIG 

def createVecs(spine):
    """Spine taken as an argument. This has to change somehow"""
    
    vecs = {}
    
    vecs["t"] = h.Vector()
    vecs["t"].record(h._ref_t)
    
    vecs["v_soma"] = h.Vector()
    vecs["v_soma"].record(h.MSP_Cell[0].soma(0.5)._ref_v)
    
    vecs["ca_soma"] = h.Vector()
    vecs["ca_soma"].record(h.MSP_Cell[0].soma(0.5)._ref_cai)
    
    vecs["ca_dend"] = h.Vector()
    vecs["ca_dend"].record(spine.parent(0.5)._ref_cai)

    vecs["v_dend"] = h.Vector()
    #vecs["v_dend"].record(spine.parent(0.5)._ref_v)
    vecs["v_dend"].record(spine.parent(0.5)._ref_v)
    
    vecs["v_spine"] = h.Vector()
    vecs["v_spine"].record(spine(0.5)._ref_v)
    
    return vecs
    
    
def plotVoltage(vecs, synVecs):
    fig = figure()
    ax1 = fig.add_subplot(111) #sub for the two scales
    plot(vecs["t"], vecs["v_soma"], label="soma voltage")
    plot(vecs["t"], vecs["v_dend"], label="dendrite voltage")
    plot(vecs["t"], vecs["v_spine"], label="spine voltage")
    ylabel("voltage [mV]")
    xlabel("time [ms]")
    ax2 = ax1.twinx()
    stimulGraph(vecs["t"], synVecs["stimul"])
    ax2.set_ylim(0,4)
    ax2.set_axis_off()
    t = numpy.array(vecs["t"])
    t = numpy.round(t, decimals=9) # round
    ax1.set_xlim(t[0],t[-1])
    ax1.legend(loc=0)
    return ax1 # No really needed but handy

def go():
    """Just run the model for the time"""
    h.run()
    plotVoltage(vecs, synVecs)
    show()

if __name__ == "__main__":
    
    h.load_file("my_init.hoc")
    from spine import *   
    spine = Spine()
    spine.attach(h.MSP_Cell[0].dend1_1[1], 0.5, 0)
    ampa = spine.createAMPASyn()
    synVecs = spine.createSynapseVecs(ampa)
    
    import neuron.gui
    h.load_file("guiRig2.ses")
    
    vecs = createVecs(spine)
{'fraction_non_alphanumeric': 0.15353871773522065, 'fraction_numerical': 0.016319733555370523, 'mean_word_length': 2.691456668715427, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '541599', 'n_tokens_mistral': 2326, 'n_tokens_neox': 2253, 'n_words': 470}