How to use the neuron.h.allsec function in NEURON

To help you get started, we’ve selected a few NEURON examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github research-team / robot-dream / Nociception / python_model / model_part.py View on Github external
if new_fig:
        pyplot.figure(figsize=(8,4)) # Default figsize is (8,6)
    soma_plot = pyplot.plot(t_vec, soma_v_vec, color='red')
    dend_plot = pyplot.plot(t_vec, dend_v_vec, color='black')
    pyplot.legend(soma_plot + dend_plot, ['soma', 'dend(0.5)'])
    pyplot.xlabel('time (ms)')
    pyplot.ylabel('mV')

cell = BallAndStick()
diff = h.AtP_4(cell.dend(0.5))
rec = h.p2x3(cell.dend(0.5))
diff.h = 0.1
diff.tx1 = 10
rec.Ev = -40
h.setpointer(diff._ref_atp, 'patp', rec)
for sec in h.allsec():
    h.psection(sec=sec)
soma_v_vec, dend_v_vec, t_vec = set_recording_vectors(cell)
simulate()
show_output(soma_v_vec, dend_v_vec, t_vec)
pyplot.show()
#pyplot.savefig('/Users/sulgod/Desktop/Nociception/onespike.pdf')
github mattions / neuronvisio / src / neuronvisio / visio.py View on Github external
def draw_model(self):
        """Draw the model.
        Params:
        controls - the main gui obj."""
        
        # Draw the new one
        h.define_shape()
        num_sections = 0

        
        # Disable the render. Faster drawing.
         
        self.mayavi.visualization.scene.disable_render = True
        for sec in h.allsec():
            if self.selected_cyl is not None:
                self.update_color(self.selected_cyl, self.selected_cyl_color)
#                if sec.name() == selected_sec.name():
#                    self.draw_section(sec, selected_color)
            else:
                self.draw_section(sec, self.default_cyl_color)
        
        # ReEnable the rendering
        self.mayavi.visualization.scene.disable_render = False
github neuronsimulator / nrn / share / lib / python / neuron / rxd / species.py View on Github external
def _ion_register(self):
        """modified from neuron.rxd.species.Species._ion_register"""
        if self._species is not None:
            ion_type = h.ion_register(self._species, self._charge)
            if ion_type == -1:
                raise RxDException('Unable to register species: %s' % self._species)
            # insert the species if not already present
            ion_forms = [self._species + 'i', self._species + 'o', 'i' + self._species, 'e' + self._species]
            for s in h.allsec():
                try:
                    for i in ion_forms:
                    # this throws an exception if one of the ion forms is missing
                        temp = s.__getattribute__(i)
                except:
                    s.insert(self._species + '_ion')
                # set to recalculate reversal potential automatically
                # the last 1 says to set based on global initial concentrations
                # e.g. nao0_na_ion, etc...
                # TODO: this is happening GLOBALLY even to sections that aren't inside the extracellular domain (FIX THIS)
                h.ion_style(self._species + '_ion', 3, 2, 1, 1, 1, sec=s)
github mattions / neuronvisio / neuronvisio / visio.py View on Github external
def get_selection_scalar(self, selected_secs, scalar_values=None):
        """ Return a scalar array with zero everywhere but one 
        for the selected sections
        
        :param: selected_secs - list with the names of the selected sections 
        
        """
        
        new_scalar = []
        for sec in (h.allsec()):
            if sec.name() in selected_secs:
                if scalar_values:
                    indx = selected_secs.index(sec.name())
                    sec_scalar = self.build_sec_scalar(sec, scalar_values[indx])
                    logger.debug(scalar_values[indx])
                else:
                    sec_scalar = self.build_sec_scalar(sec, 1.)
            else:
                sec_scalar = self.build_sec_scalar(sec, 0.)
            new_scalar.extend(sec_scalar) 

        return np.array(new_scalar)
github neuronsimulator / nrn / share / lib / python / neuron / rxd / morphology.py View on Github external
from neuron import h
import itertools

# aliases to avoid repeatedly doing multiple hash-table lookups
_h_section_ref = h.SectionRef
_h_allsec = h.allsec
_h_parent_connection = h.parent_connection
_h_section_orientation = h.section_orientation
_itertools_combinations = itertools.combinations

def parent(sec):
    """Return the parent of sec or None if sec is a root"""
    sref = _h_section_ref(sec=sec)
    if sref.has_trueparent():
        return sref.trueparent().sec
    elif sref.has_parent():
        temp = sref.parent().sec
        # check if temp owns the connection point
        if _h_section_ref(sec=temp).has_parent() and _h_parent_connection(sec=temp) == _h_section_orientation(sec=temp):
            # connection point belongs to temp's ancestor
            return parent(temp)
        return temp
github research-team / robot-dream / Nociception / cfiber / cfiber.py View on Github external
def build_subsets(self):
        self.all = h.SectionList()
        for sec in h.allsec():
            self.all.append(sec=sec)    
    def __init__(self):
github research-team / robot-dream / Nociception / cfiber.py View on Github external
def build_subsets(self):
        '''
        adds sections in NEURON SectionList
        '''
        self.all = h.SectionList()
        for sec in h.allsec():
          self.all.append(sec=sec)  
    def connect2target(self, target):
github AllenInstitute / biophys_optimize / biophys_optimize / passive_fitting / neuron_passive_fit_elec.py View on Github external
def main(input_file, output_file):
    with open(input_file, "r") as f:
        input = json.load(f)

    swc_path = input["paths"]["swc"].encode('ascii', 'ignore')
    up_data = np.loadtxt(input["paths"]["up"])
    down_data = np.loadtxt(input["paths"]["down"])
    with open(input["paths"]["passive_info"], "r") as f:
        info = json.load(f)

    h.load_file("stdgui.hoc")
    h.load_file("import3d.hoc")
    load_morphology(swc_path)

    for sec in h.allsec():
        if sec.name().startswith("axon"):
            h.delete_section(sec=sec)
    axon = h.Section()
    axon.L = 60
    axon.diam = 1
    axon.connect(h.soma[0], 0.5, 0)

    h.define_shape()

    for sec in h.allsec():
        sec.insert('pas')
        for seg in sec:
            seg.pas.e = 0

    for file_path in input["paths"]["fit3"]:
        h.load_file(file_path.encode("ascii", "ignore"))
github Neurosim-lab / netpyne / netpyne / utils.py View on Github external
globs
        
    example: 

    TODO:Refactor code to make it smaller.
    NOTE:  
    '''      
    
    dirCell = dir(cell)

    if 'all_sec' in dirCell:
        secs = cell.all_sec
    elif 'sec' in dirCell:
        secs = [cell.sec]
    elif 'allsec' in dir(h):
        secs = [sec for sec in h.allsec()]
    elif 'soma' in dirCell:
        secs = [cell.soma]
    else:
        secs = []
    

    # create dict with hname of each element in dir(cell)
    dirCellHnames = {}  
    for dirCellName in dirCell:
        try:
            dirCellHnames.update({getattr(cell, dirCellName).hname(): dirCellName})
        except:
            pass
    # create dict with dir(cell) name corresponding to each hname 
    dirCellSecNames = {} 
    for sec in secs:
github arbor-sim / arbor / nrn / simple_synapse.py View on Github external
soma = h.Section(name='soma')
dend = h.Section(name='dend')

dend.connect(soma(1))

# Surface area of cylinder is 2*pi*r*h (sealed ends are implicit).
# Here we make a square cylinder in that the diameter
# is equal to the height, so diam = h. ==> Area = 4*pi*r^2
# We want a soma of 500 microns squared:
# r^2 = 500/(4*pi) ==> r = 6.2078, diam = 12.6157
soma.L = soma.diam = 12.6157 # Makes a soma of 500 microns squared.
dend.L = 200 # microns
dend.diam = 1 # microns

for sec in h.allsec():
    sec.Ra = 100    # Axial resistance in Ohm * cm
    sec.cm = 1      # Membrane capacitance in micro Farads / cm^2

# Insert active Hodgkin-Huxley current in the soma
soma.insert('hh')
soma.gnabar_hh = 0.12  # Sodium conductance in S/cm2
soma.gkbar_hh = 0.036  # Potassium conductance in S/cm2
soma.gl_hh = 0.0003    # Leak conductance in S/cm2
soma.el_hh = -54.3     # Reversal potential in mV

# Insert passive current in the dendrite
dend.insert('pas')
dend.g_pas = 0.001  # Passive conductance in S/cm2
dend.e_pas = -65    # Leak reversal potential mV

# create a stimulator that stimulates once at 9 ms