Exemple #1
0
def test_push_section():
    h("""create hCable1, hCable2""")
    h.push_section("hCable1")
    assert h.secname() == "hCable1"
    h.pop_section()
    h.push_section("hCable2")
    assert h.secname() == "hCable2"
    h.pop_section()
    h.delete_section(sec=h.hCable1)
    h.delete_section(sec=h.hCable2)

    sections = [h.Section(name="pCable%d" % i) for i in range(2)]
    sections.append(h.Section())  # Anonymous in the past
    for sec in sections:
        name_in_hoc = h.secname(sec=sec)
        h.push_section(name_in_hoc)
        assert h.secname() == name_in_hoc
        h.pop_section()
    s = sections[-1]
    h.delete_section(sec=s)  # but not yet freed (though the name is now "")
    # not [no longer] a section pointer
    expect_err(
        "s.hoc_internal_name()"
    )  # this is what is generating the error in the next statement.
    expect_err('h.push_section(int(s.hoc_internal_name().replace("__nrnsec_", ""), 0))')

    # not a sectionname
    expect_hocerr(h.push_section, ("not_a_sectionname",))
Exemple #2
0
def test_push_section():
    h('''create hCable1, hCable2''')
    h.push_section("hCable1")
    assert (h.secname() == "hCable1")
    h.pop_section()
    h.push_section("hCable2")
    assert (h.secname() == "hCable2")
    h.pop_section()
    h.delete_section(sec=h.hCable1)
    h.delete_section(sec=h.hCable2)

    sections = [h.Section(name="pCable%d" % i) for i in range(2)]
    sections.append(h.Section())  # Anonymous in the past
    for sec in sections:
        name_in_hoc = h.secname(sec=sec)
        h.push_section(name_in_hoc)
        assert (h.secname() == name_in_hoc)
        h.pop_section()
    s = sections[-1]
    h.delete_section(sec=s)  # but not yet freed (though the name is now "")
    # not [no longer] a section pointer
    expect_hocerr(h.push_section,
                  (int(s.hoc_internal_name().replace("__nrnsec_", ""), 0), ))
    # not a sectionname
    expect_hocerr(h.push_section, ("not_a_sectionname", ))
Exemple #3
0
def get_sec_list():
    sec_list = []
    sec_dends = []
    sec_axons = []
    h.load_file('mosinit.hoc')
    h('''
    objref root
    root = new SectionRef()
    if (root.has_parent()){
	root = root.root()
	}
    ''')
    h('objref sec_list,axonal,dendritic')
    h('sec_list = new SectionList()')
    h('axonal = new SectionList()')
    h('dendritic = new SectionList()')
    h('forsec "dend"{dendritic.append()}')
    h('forsec "apic"{dendritic.append()}')
    h('forsec "axon"{axonal.append()}')
    h('access root.sec')
    h('distance()')
    h('sec_list.wholetree()')
    for curr_sec in h.sec_list:
        curr_name = h.secname(sec=curr_sec)
        sec_list.append(curr_name)
    for curr_sec in h.dendritic:
        curr_name = h.secname(sec=curr_sec)
        sec_dends.append(curr_name)
    for curr_sec in h.axonal:
        curr_name = h.secname(sec=curr_sec)
        sec_axons.append(curr_name)
    return sec_list, sec_dends, sec_axons
Exemple #4
0
    def initialise(self):

        save_stdout = sys.stdout  # To supress hoc output from Jupyter notebook
        # sys.stdout=open("trash","w")
        sys.stdout = open('stdout.txt', 'w')  # rather print it to the console

        self.load_mod_files()

        if self.hocpath is None:
            raise Exception(
                "Please give the path to the hoc file (eg. model.modelpath = \"/home/models/CA1_pyr/CA1_pyr_model.hoc\")"
            )

        h.load_file("stdrun.hoc")
        h.load_file(str(self.hocpath))

        if self.soma is None and self.SomaSecList_name is None:
            raise Exception(
                "Please give the name of the soma (eg. model.soma=\"soma[0]\"), or the name of the somatic section list (eg. model.SomaSecList_name=\"somatic\")"
            )

        try:
            if self.template_name is not None and self.SomaSecList_name is not None:

                h('objref testcell')
                h('testcell = new ' + self.template_name)

                exec('self.soma_ = h.testcell.' + self.SomaSecList_name)

                for s in self.soma_:
                    self.soma = h.secname()

            elif self.template_name is not None and self.SomaSecList_name is None:
                h('objref testcell')
                h('testcell = new ' + self.template_name)
                # in this case self.soma is set in the jupyter notebook
            elif self.template_name is None and self.SomaSecList_name is not None:
                exec('self.soma_ = h.' + self.SomaSecList_name)
                for s in self.soma_:
                    self.soma = h.secname()
            # if both is None, the model is loaded, self.soma will be used
        except AttributeError:
            print(
                "The provided model template is not accurate. Please verify!")
        except Exception:
            print(
                "If a model template is used, please give the name of the template to be instantiated (with parameters, if any). Eg. model.template_name=CCell(\"morph_path\")"
            )
            raise

        sys.stdout = save_stdout  # setting output back to normal
Exemple #5
0
def writeDistance(cell1, srlist1, cell2, srlist2, filename):
    f = open(filename, 'w')
    cnt = 0
    tmpdist = 0
    for sr1 in srlist1:
        cell1n = h.secname(sec=cell1.Dend[sr1])
        #print cell1.Type[sr1]
        for sr2 in srlist2:
            #print cell2.Type[sr2]
            cell2n = h.secname(sec=cell2.Dend[sr2])
            #            print cell1n, cell2n
            dist = CalcDistance(cell1.Dend[sr1], cell2.Dend[sr2])
            s = "%s,%s,%f\n"%(cell1n, cell2n, dist)
            f.write(s)
    f.close()
Exemple #6
0
def writeDistance(cell1, srlist1, cell2, srlist2, filename):
    f = open(filename, 'w')
    cnt = 0
    tmpdist = 0
    for sr1 in srlist1:
        cell1n = h.secname(sec=cell1.Dend[sr1])
        #print cell1.Type[sr1]
        for sr2 in srlist2:
            #print cell2.Type[sr2]
            cell2n = h.secname(sec=cell2.Dend[sr2])
            #            print cell1n, cell2n
            dist = CalcDistance(cell1.Dend[sr1], cell2.Dend[sr2])
            s = "%s,%s,%f\n" % (cell1n, cell2n, dist)
            f.write(s)
    f.close()
Exemple #7
0
 def __init__(self,origin,delay=1,duration=5,initial_amplitude=38.0,distance=1000,pulses=1,frequency=1):
     from numpy import pi
     self.origin=h.secname(sec=origin)
     self.sec=h.Section(name=str(self))
     self.sec.L=1000
     self.sec.diam=200 # um # Aravanis: 200 um # Gradinaru: 400 um
     self.stim=h.ostim(0.5,sec=self.sec)
     self.delay=delay
     self.pulses=pulses
     self.frequency=frequency
     self.duration=duration
     self.amplitude=initial_amplitude
     h.setpointer(h._ref_source_irradiance_chanrhod, 'irradiance',self.stim)
     h.setpointer(h._ref_source_photons_chanrhod,   'photons',self.stim)
     h.setpointer(h._ref_source_flux_chanrhod,      'flux',self.stim)
     h.setpointer(h._ref_tstimon_chanrhod,      'tstimon',self.stim)
     h.setpointer(h._ref_tstimoff_chanrhod,      'tstimoff',self.stim)
     self.stim.radius=self.sec.diam/2.0
     self.stim.pulses=self.pulses
     self.stim.isi = 1000 / self.frequency - self.duration #in ms
     self.stim.amp=initial_amplitude
     self.absorbance_coefficient = 0.1249 # (1/mm) # Range: (0.05233, 0.1975)
     self.scatter_coefficient = 7.37      # (1/mm) # Range: (6.679, 8.062)
     self.n = 1.36        # index of refraction of gray matter
     self.NA = 0.37        # numerical aperture of the optical fiber
     #self.NA = 0.48
     self.set_distance(origin, distance)
Exemple #8
0
 def __init__(self,model_path,special_path,base=os.getcwd()):
     #print "init"
     self.base_directory=base
     self.special=special_path
     self.model=model_path
     os.chdir(self.special)
     from neuron import h
     from nrn import *
     self.hoc_obj=h
     self.hoc_obj.load_file(str(self.model))
     self.hoc_obj.load_file("stdrun.hoc")
     self.vec=self.hoc_obj.Vector()
     os.chdir(self.base_directory)
     self.stimulus=None
     self.record=[]
     self.spike_times=None
     self.sections={}
     for n in h.allsec():
         self.sections[str(h.secname())]=n
     self.channels={}
     optimizerHandler.setmods(self.hoc_obj,self.sections)
     for sec in h.allsec():
         for seg in sec:
             for mech in seg:
                 self.channels[str(mech.name())]=mech
Exemple #9
0
def find_synapse_loc(synapse_or_segment, mapping_sections_to_subtree_index):
    ''' Returns the location  of the given synapse object'''

    if not isinstance(synapse_or_segment, neuron.nrn.Segment):
        synapse_or_segment = synapse_or_segment.get_segment()

    x = synapse_or_segment.x

    with push_section(synapse_or_segment.sec):
        # extracts the section type ("soma", "apic", "dend") and the section number
        # out of the section name
        full_sec_name = h.secname()
        sec_name_as_list = full_sec_name.split(".")
        short_sec_name = sec_name_as_list[len(sec_name_as_list) - 1]
        section_type = short_sec_name.split("[")[0]
        section_num = re.findall(r'\d+', short_sec_name)[0]

    # finds the index of the subtree that this synapse belongs to using the
    # given mapping_sections_to_subtree_index which maps sections to the
    # subtree indexes that they belong to
    if section_type == "apic":
        subtree_index = mapping_sections_to_subtree_index[("apic", section_num)]
    elif section_type == "dend":
        subtree_index = mapping_sections_to_subtree_index[("basal", section_num)]
    else:  # somatic synapse
        subtree_index, section_num, x = SOMA_LABEL, 0, 0

    return SynapseLocation(subtree_index, int(section_num), x)
Exemple #10
0
 def __info__(self):
     info=str(self)
     info+="\n-Section: %s" % self.origin
     xyz0,xyz1=self.xyz
     info+="\n-Base: %g,%g,%g" % (xyz0[0],xyz0[1],xyz0[2])
     info+="\n-Tip: %g,%g,%g" % (xyz1[0],xyz1[1],xyz1[2])
     info+="\n-Delay: %s" % self.delay
     info+="\n-Duration: %s" % self.duration
     info+="\n-Amplitude: %s" % self.amplitude
     info+="\n-Length: %g" % self.length
     info+="\n-Diameter: %g" % self.diameter
     info+="\n-closest_section: %s" % h.secname(sec=self.closest_section)
     return info
Exemple #11
0
 def __init__(self,model_path,special_path,base=os.getcwd()):
     #print "init"
     self.base_directory=base
     self.special=special_path
     self.model=model_path
     os.chdir(self.special)
     from neuron import h
     from nrn import *
     self.hoc_obj=h
     self.hoc_obj.load_file(str(self.model))
     self.hoc_obj.load_file("stdrun.hoc")
     self.vec=self.hoc_obj.Vector()
     os.chdir(self.base_directory)
     self.stimulus=None
     self.record=[]
     self.spike_times=None
     self.sections={}
     for n in h.allsec():
         self.sections[str(h.secname())]=n
     self.channels={}
     for sec in h.allsec():
         for seg in sec:
             for mech in seg:
                 self.channels[str(mech.name())]=mech
Exemple #12
0
soma = h.Section(name="soma")
dend = h.Section(name="dend")
dend.connect(soma(1))

aden = [h.Section(name="aden[%d]" % i) for i in range(4)]

axon = h.Section()
axon.connect(soma(0))

h('create apical')
h.apical.connect(soma(.5))

s = h.ref("")
for sec in h.allsec():
    h.sectionname(s)
    print((sec.name(), s[0], h.secname(1), sec.hoc_internal_name()))

h('''forall print secname(), " ", secname(1)''')

names = [h.secname(1) for _ in h.allsec()]

for s in names:
    h('%s print "hoc ", secname(1)' % s)

if False:  # direct Python access to h._pysec.name does not work
    for s in names:
        print(("h.%s" % s + ".name()"))
        print(("python %s %s" % (s, eval("h.%s" % s + ".name()"))))

h.load_file("pysecname.ses")
Exemple #13
0
 def section_index(self, section):
     return int(h.secname(sec=section).split('_')[-1])
Exemple #14
0
apicalDend5[0].insert('pas')
apicalDend6[0].insert('pas')
apicalDend7[0].insert('pas')
apicalDend8[0].insert('pas')
apicalDend1[0].nseg = 10
apicalDend2[0].nseg = 10
apicalDend3[0].nseg = 10
apicalDend4[0].nseg = 10
apicalDend5[0].nseg = 10
apicalDend6[0].nseg = 10
apicalDend7[0].nseg = 10
apicalDend8[0].nseg = 10

names = []
for sec in h.allsec():
    names.append(h.secname())

print names
# Connect neurons in network...
"""
syn = []
nc = []
for i in range(0,l):
	tempSectionName = "soma" + connections[i][9]
	print tempSectionName
	print soma8.name
	syn.append(h.ExpSyn(float(connections[i][8]), sec = tempSectionName))
"""

syn1 = h.ExpSyn(0.5, sec=soma1)
syn2 = h.ExpSyn(0.5, sec=soma2)
 def __info__(self):
     info = str(self)
     info += "\n-Axon Root: %s" % h.secname(sec=self.root)
     info += "\n-Axon Root XYZ: %s" % str(
         self.retrieve_coordinates(sec=self.root))
     return info
Exemple #16
0
 def compute_nseg(self):
     for sec in h.allsec():
         sec.nseg = int((sec.L/(0.1*h.lambda_f(100,sec=sec))+0.9)/2)*2 + 1
         if DEBUG:
             print('%s has %d segments.' % (h.secname(sec=sec),sec.nseg))
Exemple #17
0
import numpy
import types

h("objref p")
h("p = new PythonObject()")

try:
    import pylab
    from pylab import plot, arange, figure
    my_pylab_loaded = True
except ImportError:
    print "Pylab not imported"
    my_pylab_loaded = False

def htype (obj): st=obj.hname(); sv=st.split('['); return sv[0]
def secname (obj): obj.push(); print h.secname() ; h.pop_section()
def psection (obj): obj.push(); print h.psection() ; h.pop_section()

allsecs=None #global list containing all NEURON sections, initialized via mkallsecs

# still need to generate a full allsecs
def mkallsecs ():
  """ mkallsecs - make the global allsecs variable, containing
      all the NEURON sections.
  """
  global allsecs
  allsecs=h.SectionList() # no .clear() command
  roots=h.SectionList()
  roots.allroots()
  for s in roots:
    s.push()
Exemple #18
0
def find_section_number(section):
    ''' extracts and returns the section number from the given section object '''
    sec_name = h.secname(sec=section)
    ints_in_name = re.findall(r'\d+', sec_name)
    sec_num = ints_in_name[len(ints_in_name) - 1]  # extracts section number
    return sec_num