示例#1
0
 def dipole_insert(self, yscale):
     # insert dipole into each section of this cell
     # dends must have already been created!!
     # it's easier to use wholetree here, this includes soma
     seclist = h.SectionList()
     seclist.wholetree(sec=self.soma)
     # create a python section list list_all
     self.list_all = [sec for sec in seclist]
     for sect in self.list_all:
         sect.insert('dipole')
     # Dipole is defined in dipole_pp.mod
     self.dipole_pp = [h.Dipole(1, sec=sect) for sect in self.list_all]
     # setting pointers and ztan values
     for sect, dpp in zip(self.list_all, self.dipole_pp):
         # assign internal resistance values to dipole point process (dpp)
         dpp.ri = h.ri(1, sec=sect)
         # sets pointers in dipole mod file to the correct locations
         # h.setpointer(ref, ptr, obj)
         h.setpointer(sect(0.99)._ref_v, 'pv', dpp)
         if self.celltype.startswith('L2'):
             h.setpointer(h._ref_dp_total_L2, 'Qtotal', dpp)
         elif self.celltype.startswith('L5'):
             h.setpointer(h._ref_dp_total_L5, 'Qtotal', dpp)
         # gives INTERNAL segments of the section, non-endpoints
         # creating this because need multiple values simultaneously
         loc = np.array([seg.x for seg in sect])
         # these are the positions, including 0 but not L
         pos = np.array([seg.x for seg in sect.allseg()])
         # diff in yvals, scaled against the pos np.array. y_long as in longitudinal
         y_scale = (yscale[sect.name()] * sect.L) * pos
         # y_long = (h.y3d(1, sec=sect) - h.y3d(0, sec=sect)) * pos
         # diff values calculate length between successive section points
         y_diff = np.diff(y_scale)
         # y_diff = np.diff(y_long)
         # doing range to index multiple values of the same np.array simultaneously
         for i in range(len(loc)):
             # assign the ri value to the dipole
             sect(loc[i]).dipole.ri = h.ri(loc[i], sec=sect)
             # range variable 'dipole'
             # set pointers to previous segment's voltage, with boundary condition
             if i:
                 h.setpointer(
                     sect(loc[i - 1])._ref_v, 'pv',
                     sect(loc[i]).dipole)
             else:
                 h.setpointer(sect(0)._ref_v, 'pv', sect(loc[i]).dipole)
             # set aggregate pointers
             h.setpointer(dpp._ref_Qsum, 'Qsum', sect(loc[i]).dipole)
             if self.celltype.startswith('L2'):
                 h.setpointer(h._ref_dp_total_L2, 'Qtotal',
                              sect(loc[i]).dipole)
             elif self.celltype.startswith('L5'):
                 h.setpointer(h._ref_dp_total_L5, 'Qtotal',
                              sect(loc[i]).dipole)
             # add ztan values
             sect(loc[i]).dipole.ztan = y_diff[i]
         # set the pp dipole's ztan value to the last value from y_diff
         dpp.ztan = y_diff[-1]
示例#2
0
文件: cell.py 项目: samikane/hnn-core
    def insert_dipole(self, yscale):
        """Insert dipole into each section of this cell.

        Parameters
        ----------
        yscale : dict
            Dictionary of length scales to calculate dipole without
            3d shape.
        """
        self.dpl_vec = h.Vector(1)
        self.dpl_ref = self.dpl_vec._ref_x[0]

        # dends must have already been created!!
        # it's easier to use wholetree here, this includes soma
        sec_list = h.SectionList()
        sec_list.wholetree(sec=self.soma)
        sec_list = [sec for sec in sec_list]
        for sect in sec_list:
            sect.insert('dipole')
        # Dipole is defined in dipole_pp.mod
        self.dipole_pp = [h.Dipole(1, sec=sect) for sect in sec_list]
        # setting pointers and ztan values
        for sect, dpp in zip(sec_list, self.dipole_pp):
            dpp.ri = h.ri(1, sec=sect)  # assign internal resistance
            # sets pointers in dipole mod file to the correct locations
            dpp._ref_pv = sect(0.99)._ref_v
            dpp._ref_Qtotal = self.dpl_ref
            # gives INTERNAL segments of the section, non-endpoints
            # creating this because need multiple values simultaneously
            pos_all = np.array([seg.x for seg in sect.allseg()])
            # diff in yvals, scaled against the pos np.array. y_long as
            # in longitudinal
            sect_name = sect.name().split('_', 1)[1]
            y_scale = (yscale[sect_name] * sect.L) * pos_all
            # y_long = (h.y3d(1, sec=sect) - h.y3d(0, sec=sect)) * pos
            # diff values calculate length between successive section points
            y_diff = np.diff(y_scale)
            # y_diff = np.diff(y_long)
            # doing range to index multiple values of the same
            # np.array simultaneously
            for idx, pos in enumerate(pos_all[1:-1]):
                # assign the ri value to the dipole
                # ri not defined at 0 and L
                sect(pos).dipole.ri = h.ri(pos, sec=sect)
                # range variable 'dipole'
                # set pointers to previous segment's voltage, with
                # boundary condition
                sect(pos).dipole._ref_pv = sect(pos_all[idx])._ref_v

                # set aggregate pointers
                sect(pos).dipole._ref_Qsum = dpp._ref_Qsum
                sect(pos).dipole._ref_Qtotal = self.dpl_ref
                # add ztan values
                sect(pos).dipole.ztan = y_diff[idx]
            # set the pp dipole's ztan value to the last value from y_diff
            dpp.ztan = y_diff[-1]
        self.dipole = h.Vector().record(self.dpl_ref)
示例#3
0
    def _insert_dipole(self, sec_name_apical):
        """Insert dipole into each section of this cell.

        Parameters
        ----------
        sec_name_apical : str
            The name of the section along which dipole moment is calculated.
        """
        self.dpl_vec = h.Vector(1)
        self.dpl_ref = self.dpl_vec._ref_x[0]
        cos_thetas = _get_cos_theta(self.sections, 'apical_trunk')

        # setting pointers and ztan values
        for sect_name in self.sections:
            sect = self._nrn_sections[sect_name]
            sect.insert('dipole')

            dpp = h.Dipole(1, sec=sect)  # defined in dipole_pp.mod
            self.dipole_pp.append(dpp)
            dpp.ri = h.ri(1, sec=sect)  # assign internal resistance
            # sets pointers in dipole mod file to the correct locations
            dpp._ref_pv = sect(0.99)._ref_v
            dpp._ref_Qtotal = self.dpl_ref
            # gives INTERNAL segments of the section, non-endpoints
            # creating this because need multiple values simultaneously
            pos_all = np.array([seg.x for seg in sect.allseg()])
            seg_lens = np.diff(pos_all) * sect.L
            seg_lens_z = seg_lens * cos_thetas[sect_name]

            # alternative procedure below with y_long(itudinal)
            # y_long = (h.y3d(1, sec=sect) - h.y3d(0, sec=sect)) * pos
            # y_diff = np.diff(y_long)

            # doing range to index multiple values of the same
            # np.array simultaneously
            for idx, pos in enumerate(pos_all[1:-1]):
                # assign the ri value to the dipole
                # ri not defined at 0 and L
                sect(pos).dipole.ri = h.ri(pos, sec=sect)
                # range variable 'dipole'
                # set pointers to previous segment's voltage, with
                # boundary condition
                sect(pos).dipole._ref_pv = sect(pos_all[idx])._ref_v

                # set aggregate pointers
                sect(pos).dipole._ref_Qsum = dpp._ref_Qsum
                sect(pos).dipole._ref_Qtotal = self.dpl_ref
                # add ztan values
                sect(pos).dipole.ztan = seg_lens_z[idx]
            # set the pp dipole's ztan value to the last value from seg_lens_z
            dpp.ztan = seg_lens_z[-1]
        self.dipole = h.Vector().record(self.dpl_ref)
示例#4
0
def test_direct_memory_transfer():
    #h('''create soma''')
    cell = h.rinzelnrn()
    #h.psection()
    #dir(h)
    #h.soma.L=5.6419
    #h.soma.diam=5.6419
    #h.soma.insert("rinzelnrn")
    gc = 2.1
    pp = 0.5

    cell.soma.Ra = 1
    cell.dend.Ra = 1
    global_Ra = (1e-6 / (gc / pp *
                         (h.area(0.5) * 1e-8) * 1e-3)) / (2 * h.ri(0.5))
    cell.soma.Ra = global_Ra
    cell.soma.cm = 3
    cell.dend.Ra = global_Ra
    cell.dend.cm = 3

    # soma
    cell.soma.insert("pas")
    cell.soma.insert("kdr")
    cell.soma.insert("nafPR")

    cell.soma.gmax_nafPR = 30e-3
    cell.soma.gmax_kdr = 15e-3
    cell.soma.g_pas = 0.1e-3
    cell.soma.e_pas = -60

    # dend
    cell.dend.insert("pas")
    cell.dend.insert("rcadecay")
    cell.dend.insert("cal")
    cell.dend.insert("kcRT03")
    cell.dend.insert("rkq")

    cell.dend.g_pas = 0.1e-3
    cell.dend.e_pas = -60
    cell.dend.phi_rcadecay = 130
    cell.dend.gmax_cal = 00010e-3
    cell.dend.erev_cal = 80
    cell.dend.gmax_kcRT03 = 00015e-3
    cell.dend.gmax_rkq = 0000.8e-3
    cell.dend.ek = -75

    ic = h.IClamp(cell.soma(.5))
    ic.delay = .5
    ic.dur = 0.1
    ic.amp = 0.3

    #for testing external mod file
    #h.soma.insert("hh")

    h.cvode.use_fast_imem(1)
    h.cvode.cache_efficient(1)

    h.tstop = 50
    h.celsius = 37.0
    h.v_init = -60
    v = h.Vector()
    v.record(cell.soma(.5)._ref_v, sec=cell.soma)
    i_mem = h.Vector()
    i_mem.record(cell.soma(.5)._ref_i_membrane_, sec=cell.soma)
    tv = h.Vector()
    tv.record(h._ref_t, sec=cell.soma)
    h.run()
    vstd = v.cl()
    tvstd = tv.cl()
    i_memstd = i_mem.cl()
    # Save current (after run) value to compare with transfer back from coreneuron
    #tran_std = [h.t, cell.soma(.5).v, cell.soma(.5).hh.m]

    from neuron import coreneuron
    coreneuron.enable = True

    pc = h.ParallelContext()
    pc.set_maxstep(10)

    h.stdinit()
    pc.psolve(h.tstop)
    #tran = [h.t, cell.soma(.5).v, cell.soma(.5).hh.m]

    assert (tv.eq(tvstd))
    #assert(v.cl().sub(vstd).abs().max() < 1e-10)
    assert (i_mem.cl().sub(i_memstd).abs().max() < 1e-10)
    #assert(h.Vector(tran_std).sub(h.Vector(tran)).abs().max() < 1e-10)

    f = open('v.dat', 'w')
    for i in range(tv.size()):
        print('{} {}'.format(tv[i], v[i]), file=open("v.dat", "a"))

    h.quit()
示例#5
0
def make_rec(recid,
             population,
             gid,
             cell,
             sec=None,
             loc=None,
             ps=None,
             param='v',
             label=None,
             dt=None,
             description=''):
    """
    Makes a recording vector for the specified quantity in the specified section and location.

    :param recid: str
    :param population: str
    :param gid: integer
    :param cell: :class:'BiophysCell'
    :param sec: :class:'HocObject'
    :param loc: float
    :param ps: :class:'HocObject'
    :param param: str
    :param dt: float
    :param ylabel: str
    :param description: str
    """
    vec = h.Vector()
    if (sec is None) and (loc is None) and (ps is not None):
        hocobj = ps
        seg = ps.get_segment()
        if seg is not None:
            loc = seg.x
            sec = seg.sec
            origin = list(cell.soma)[0]
            distance = h.distance(origin(0.5), seg)
            ri = h.ri(loc, sec=sec)
        else:
            distance = None
            ri = None
    elif (sec is not None) and (loc is not None):
        hocobj = sec(loc)
        if cell.soma.__class__.__name__.lower() == "section":
            origin = cell.soma
        else:
            origin = list(cell.soma)[0]
        h.distance(sec=origin)
        distance = h.distance(origin(0.5), sec(loc))
        ri = h.ri(loc, sec=sec)
    else:
        raise RuntimeError(
            'make_rec: either sec and loc or ps must be specified')
    section_index = None
    if sec is not None:
        for i, this_section in enumerate(cell.sections):
            if this_section == sec:
                section_index = i
                break
    if label is None:
        label = param
    if dt is None:
        vec.record(getattr(hocobj, f'_ref_{param}'))
    else:
        vec.record(getattr(hocobj, f'_ref_{param}'), dt)
    rec_dict = {
        'name': recid,
        'gid': gid,
        'cell': cell,
        'population': population,
        'loc': loc,
        'section': section_index,
        'distance': distance,
        'ri': ri,
        'description': description,
        'vec': vec,
        'label': label
    }

    return rec_dict
示例#6
0
def pr(sec):
    for seg in sec.allseg():
        print sec.name(), seg.x, h.area(seg.x, sec=sec), h.ri(seg.x, sec=sec)