コード例 #1
0
ファイル: split.py プロジェクト: JustasB/Mig3DTest
def splitmitral(mgid, cell, piecelist):
  ''' split a mitral cell into secondary dendrites and the soma/priden/axon
      and destroy pieces not on this cpu and connect pieces with multisplit.
      Note that -1 is the piece that includes the soma.
      Also note that secondary dendrites have branches and the piecelist is
      for the indices of secondary dentrites that connect to the soma.
      The {mgid:cell} is added to mgid2piece so the assumption is that
      piecelist is not empty.
  '''
  isecden = secden_indices_connected_to_soma(cell)
  #disconnect all secden and destroy what is not supposed to exist
  for i in isecden:
    s = cell.secden[i]
    h.disconnect(sec = s)
    if i not in piecelist:
      subtree = h.SectionList()
      subtree.wholetree(sec = s)
      for ss in subtree:
        h.delete_section(sec = ss)
  rest = h.SectionList()
  rest.wholetree(sec = cell.soma)
  if -1 not in piecelist:
    for s in rest:
      h.delete_section(sec = s)
  #multisplit connect using mgid
  for i in piecelist:
    if i == -1:
      pc.multisplit(0.5, mgid, sec = cell.soma)
    else:
      pc.multisplit(0.0, mgid, sec=cell.secden[i])
  # add to piece dictionary
  model.mgid2piece.update({mgid:cell})
コード例 #2
0
def find_and_disconnect_axon(soma_ref):
    '''Searching for an axon, it can be a child of the soma or a parent of the soma.'''
    axon_section, axon_parent, soma_axon_x  = [], False, None

    for sec in soma_ref.child:
        name = sec.hname().lower()
        if 'axon' in name or 'hill' in name:
            axon_section.append(sec)
            # disconnect axon
            soma_axon_x = sec.parentseg().x
            sec.push()
            h.disconnect()
            h.define_shape()

    if soma_ref.has_parent():
        name = soma_ref.parent().sec.hname().lower()
        if 'axon' in name or 'hill' in name:
            axon_section.append(soma_ref.parent())
            axon_parent = True
            soma_axon_x = None
            soma_ref.push()
            h.disconnect()
        else:
            raise Exception('Soma has a parent which is not an axon')

    if len(axon_section) > 1:
        raise Exception('Soma has a two axons')

    return axon_section, axon_parent, soma_axon_x
コード例 #3
0
ファイル: split.py プロジェクト: ModelDBRepository/240116
def splitmitral(mgid, cell, piecelist):
    ''' split a mitral cell into secondary dendrites and the soma/priden/axon
      and destroy pieces not on this cpu and connect pieces with multisplit.
      Note that -1 is the piece that includes the soma.
      Also note that secondary dendrites have branches and the piecelist is
      for the indices of secondary dentrites that connect to the soma.
      The {mgid:cell} is added to mgid2piece so the assumption is that
      piecelist is not empty.
  '''
    isecden = secden_indices_connected_to_soma(cell)

    #disconnect all secden and destroy what is not supposed to exist
    for i in isecden:
        s = cell.secden[i]
        h.disconnect(sec=s)
        if i not in piecelist:
            subtree = h.SectionList()
            subtree.wholetree(sec=s)
            for ss in subtree:
                h.delete_section(sec=ss)
    rest = h.SectionList()
    rest.wholetree(sec=cell.soma)
    if -1 not in piecelist:
        for s in rest:
            h.delete_section(sec=s)

    #multisplit connect using mgid
    for i in piecelist:
        if i == -1:
            pc.multisplit(0.5, mgid, sec=cell.soma)
        else:
            pc.multisplit(0.0, mgid, sec=cell.secden[i])

    # add to piece dictionary
    model.mgid2piece.update({mgid: cell})
コード例 #4
0
 def disconnect_dendrites_from_soma(self):
     #
     # ============Implement disconnect_all_dendrites capability============
     #
     cca(capability_name="disconnect_dendrites_from_soma",
         CerebUnitCapability=CanDisconnectDendrites)  # check capab.
     #
     #for d in self.cell.dend:
     #    if h.SectionRef(sec = d).has_parent != 0:
     #        h.disconnect(sec = d)
     h.disconnect(sec=self.cell.dend[0])
コード例 #5
0
 def move_spine(self, new_parent):
     ''' move spine from one section to another (using default orientation)
     '''
     h.disconnect(sec=self.neck)
     self.neck.connect(new_parent(1),0)
     self.parent = new_parent
     
        
 
 
                 
コード例 #6
0
ファイル: test_del.py プロジェクト: neuronsimulator/nrntest
def test():
    sec = h.Section(name='dend')

    for sec in h.allsec():
        h.disconnect(sec=sec)
        sref = h.SectionRef(sec=sec)
        #defeated the guards against deleting the Section pointed to by
        # a PythonSection
        sref.rename('delete')
        h.disconnect(sec=sec)
        #used to be allowed only for hoc sections (create ...)
        h.delete_section(sec=sec)
コード例 #7
0
ファイル: conftest.py プロジェクト: hewhocannotbetamed/nrn
def neuron_instance(neuron_import):
    """Sets/Resets the rxd test environment.

    Provides 'data', a dictionary used to store voltages and rxd node
    values for comparisons with the 'correct_data'.
    """

    h, rxd = neuron_import
    data = {'record_count': 0, 'data': []}
    h.load_file('stdrun.hoc')
    cvode = h.CVode()
    cvode.active(False)
    cvode.atol(1e-3)
    h.dt = 0.025
    h.stoprun = False

    def gather():
        return collect_data(h, rxd, data)

    cvode.extra_scatter_gather(0, gather)
    yield (h, rxd, data)
    rxd.region._all_regions = []
    rxd.region._region_count = 0
    rxd.region._c_region_lookup = None
    for r in rxd.rxd._all_reactions[:]:
        if r():
            rxd.rxd._unregister_reaction(r)

    for s in rxd.species._all_species:
        if s():
            s().__del__()
    rxd.species._species_counts = 0
    rxd.section1d._rxd_sec_lookup = {}
    rxd.section1d._purge_cptrs()
    rxd.initializer.has_initialized = False
    rxd.rxd.free_conc_ptrs()
    rxd.rxd.free_curr_ptrs()
    rxd.rxd.rxd_include_node_flux1D(0, None, None, None)
    for sec in h.allsec():
        h.disconnect(sec=sec)
        sref = h.SectionRef(sec=sec)
        sref.rename('delete')
        h.delete_section(sec=sec)
    rxd.species._has_1d = False
    rxd.species._has_3d = False
    rxd.rxd._memb_cur_ptrs = []
    rxd.rxd._rxd_induced_currents = None
    rxd.rxd._curr_indices = None
    rxd.rxd._zero_volume_indices = numpy.ndarray(0, dtype=numpy.int_)
    rxd.set_solve_type(dimension=1)
    cvode.extra_scatter_gather_remove(gather)
コード例 #8
0
def AddSoma_callback():

    s = ttk.Style()
    s.configure('Gray.TEntry', background='gray')

    if GUI.Buttons['AddSoma']['text'] == 'Add Soma':

        soma_size = float(GUI.Entries['soma']['soma.diam']['Var'].get())
        soma_cm = float(GUI.Entries['soma']['soma.cm']['Var'].get())
        Simulator.CreateCompartment('soma',
                                    L=soma_size,
                                    diam=soma_size,
                                    Ra=110,
                                    e_pas=h.v_init,
                                    g_pas=1.0 / 1500.0,
                                    nseg=int(soma_size) * 5,
                                    cm=soma_cm)

        h.disconnect(sec=Simulator.soma)
        Simulator.dend.connect(
            Simulator.soma, 1, 0
        )  # Disconnect from parents if exist (following weird bug in which soma was created as child of last created section (spine head))
        h.define_shape()  # !Explain this

        GUI.Buttons['AddSoma'][
            'text'] = 'Remove Soma'  #!Toggle soma function inside GUI
        GUI.RadioButtons['volt_loc']['Buttons'][2].config(state='normal')

    elif GUI.Buttons['AddSoma']['text'] == 'Remove Soma':
        h.delete_section(sec=Simulator.soma)
        Simulator.soma = None
        GUI.Buttons['AddSoma']['text'] = 'Add Soma'

        GUI.RadioButtons['volt_loc']['Var'].set(2)
        GUI.RadioButtons['volt_loc']['Buttons'][2].config(state='disabled')

    GUI.DrawSections(colors)
    UpdatePresentedValues(GUI.ChangingLabels)
コード例 #9
0
def test_disconnect():
    print("test_disconnect")
    for sec in h.allsec():
        h.delete_section(sec=sec)
    h.topology()
    n = 5

    def setup(n):
        sections = [h.Section(name="s%d" % i) for i in range(n)]
        for i, sec in enumerate(sections[1:]):
            sec.connect(sections[i])
        return sections

    sl = setup(n)

    def chk(sections, i):
        print(sections, i)
        h.topology()
        x = len(sections[0].wholetree())
        assert x == i

    chk(sl, n)

    h.disconnect(sec=sl[2])
    chk(sl, 2)

    sl = setup(n)
    sl[2].disconnect()
    chk(sl, 2)

    sl = setup(n)
    expect_err("h.disconnect(sl[2])")
    expect_err("h.delete_section(sl[2])")

    del sl
    locals()
コード例 #10
0
def subtree_reductor(original_cell,
                     synapses_list,
                     netcons_list,
                     reduction_frequency,
                     model_filename='model.hoc',
                     total_segments_manual=-1,
                     PP_params_dict=None,
                     mapping_type='impedance',
                     return_seg_to_seg=False
                     ):

    '''
    Receives an instance of a cell with a loaded full morphology, a list of
    synapse objects, a list of NetCon objects (the i'th netcon in the list
    should correspond to the i'th synapse), the filename (string) of the model
    template hoc file that the cell was instantiated from, the desired
    reduction frequency as a float, optional parameter for the approximate
    desired number of segments in the new model (if this parameter is empty,
    the number of segments will be such that there is a segment for every 0.1
    lambda), and an optional param for the point process to be compared before
    deciding on whether to merge a synapse or not and reduces the cell (using
    the given reduction_frequency). Creates a reduced instance using the model
    template in the file whose filename is given as a parameter, and merges
    synapses of the same type that get mapped to the same segment
    (same "reduced" synapse object for them all, but different NetCon objects).



    model_filename : model.hoc  will use a default template
    total_segments_manual: sets the number of segments in the reduced model
                           can be either -1, a float between 0 to 1, or an int
                           if total_segments_manual = -1 will do automatic segmentation
                           if total_segments_manual>1 will set the number of segments
                           in the reduced model to total_segments_manual
                           if 0>total_segments_manual>1 will automatically segment the model
                           but if the automatic segmentation will produce a segment number that
                           is lower than original_number_of_segments*total_segments_manual it
                           will set the number of segments in the reduced model to:
                           original_number_of_segments*total_segments_manual
    return_seg_to_seg: if True the function will also return a textify version of the mapping
                       between the original segments to the reduced segments 


    Returns the new reduced cell, a list of the new synapses, and the list of
    the inputted netcons which now have connections with the new synapses.

    Notes:
    1) The original cell instance, synapses and Netcons given as arguments are altered
    by the function and cannot be used outside of it in their original context.
    2) Synapses are determined to be of the same type and mergeable if their reverse
    potential, tau1 and tau2 values are identical.
    3) Merged synapses are assigned a single new synapse object that represents them
    all, but keep their original NetCon objects. Each such NetCon now connects the
    original synapse's NetStim with
    the reduced synapse.
    '''
    if PP_params_dict is None:
        PP_params_dict = {}

    h.init()

    model_obj_name = load_model(model_filename)

    # finds soma properties
    soma = original_cell.soma[0] if original_cell.soma.hname()[-1] == ']' else original_cell.soma

    soma_cable = CableParams(length=soma.L, diam=soma.diam, space_const=None,
                             cm=soma.cm, rm=1.0 / soma.g_pas, ra=soma.Ra, e_pas=soma.e_pas,
                             electrotonic_length=None)

    has_apical = len(list(original_cell.apical)) != 0

    soma_ref = h.SectionRef(sec=soma)
    axon_section, axon_is_parent, soma_axon_x = find_and_disconnect_axon(soma_ref)
    roots_of_subtrees, num_of_subtrees = gather_subtrees(soma_ref)

    sections_to_delete, section_per_subtree_index, mapping_sections_to_subtree_index = \
        gather_cell_subtrees(roots_of_subtrees)

    # preparing for reduction

    # remove active conductances and get seg_to_mech dictionary
    segment_to_mech_vals = create_segments_to_mech_vals(sections_to_delete)

    # disconnects all the subtrees from the soma
    subtrees_xs = []
    for subtree_root in roots_of_subtrees:
        subtrees_xs.append(subtree_root.parentseg().x)
        h.disconnect(sec=subtree_root)

    # reducing the subtrees
    new_cable_properties = [reduce_subtree(roots_of_subtrees[i], reduction_frequency)
                            for i in num_of_subtrees]

    if total_segments_manual > 1:
        new_cables_nsegs = calculate_nsegs_from_manual_arg(new_cable_properties,
                                                           total_segments_manual)
    else:
        new_cables_nsegs = calculate_nsegs_from_lambda(new_cable_properties)
        if total_segments_manual > 0:
            original_cell_seg_n = (sum(i.nseg for i in list(original_cell.basal)) +
                                   sum(i.nseg for i in list(original_cell.apical))
                                   )
            min_reduced_seg_n = int(round((total_segments_manual * original_cell_seg_n)))
            if sum(new_cables_nsegs) < min_reduced_seg_n:
                logger.debug("number of segments calculated using lambda is {}, "
                      "the original cell had {} segments.  "
                      "The min reduced segments is set to {}% of reduced cell segments".format(
                          sum(new_cables_nsegs),
                          original_cell_seg_n,
                          total_segments_manual * 100))
                logger.debug("the reduced cell nseg is set to %s" % min_reduced_seg_n)
                new_cables_nsegs = calculate_nsegs_from_manual_arg(new_cable_properties,
                                                                   min_reduced_seg_n)

    cell, basals = create_reduced_cell(soma_cable,
                                       has_apical,
                                       original_cell,
                                       model_obj_name,
                                       new_cable_properties,
                                       new_cables_nsegs,
                                       subtrees_xs)

    new_synapses_list, subtree_ind_to_q = merge_and_add_synapses(
        num_of_subtrees,
        new_cable_properties,
        PP_params_dict,
        synapses_list,
        mapping_sections_to_subtree_index,
        netcons_list,
        has_apical,
        roots_of_subtrees,
        original_cell,
        basals,
        cell,
        reduction_frequency)

    # create segment to segment mapping
    original_seg_to_reduced_seg, reduced_seg_to_original_seg = create_seg_to_seg(
        original_cell,
        section_per_subtree_index,
        roots_of_subtrees,
        mapping_sections_to_subtree_index,
        new_cable_properties,
        has_apical,
        cell.apic,
        basals,
        subtree_ind_to_q,
        mapping_type,
        reduction_frequency)

    # copy active mechanisms
    copy_dendritic_mech(original_seg_to_reduced_seg,
                        reduced_seg_to_original_seg,
                        cell.apic,
                        basals,
                        segment_to_mech_vals,
                        mapping_type)
    
    if return_seg_to_seg:
        original_seg_to_reduced_seg_text = textify_seg_to_seg(original_seg_to_reduced_seg)

    # Connect axon back to the soma
    if len(axon_section) > 0:
        if axon_is_parent:
            soma.connect(axon_section[0])
        else:
            axon_section[0].connect(soma, soma_axon_x)

    # Now we delete the original model
    for section in sections_to_delete:
        with push_section(section):
            h.delete_section()

    cell.axon = axon_section
    cell.dend = cell.hoc_model.dend

    with push_section(cell.hoc_model.soma[0]):
        h.delete_section()
    if return_seg_to_seg:
        return cell, new_synapses_list, netcons_list, original_seg_to_reduced_seg_text
    else:
        return cell, new_synapses_list, netcons_list
コード例 #11
0
def subtree_reductor(original_cell,
                     synapses_list,
                     netcons_list,
                     reduction_frequency,
                     model_filename='model.hoc',
                     total_segments_manual=-1,
                     PP_params_dict=None,
                     mapping_type='impedance'):
    '''
    Receives an instance of a cell with a loaded full morphology, a list of
    synapse objects, a list of NetCon objects (the i'th netcon in the list
    should correspond to the i'th synapse), the filename (string) of the model
    template hoc file that the cell was instantiated from, the desired
    reduction frequency as a float, optional parameter for the approximate
    desired number of segments in the new model (if this parameter is empty,
    the number of segments will be such that there is a segment for every 0.1
    lambda), and an optional param for the point process to be compared before
    deciding on whethet to merge a synapse or not and reduces the cell (using
    the given reduction_frequency). Creates a reduced instance using the model
    template in the file whose filename is given as a parameter, and merges
    synapses of the same type that get mapped to the same segment
    (same "reduced" synapse object for them all, but different NetCon objects).

    Returns the new reduced cell, a list of the new synapses, and the list of
    the inputted netcons which now have connections with the new synapses.
    note #0: a default template is available, one can use:
    model_filename=model.hoc note #1: The original cell instance, synapses and
    Netcons given as arguments are altered by the function and cannot be used
    outside of it in their original context.  note #2: Synapses are determined
    to be of the same type and mergeable if their reverse potential, tau1 and
    tau2 values are identical.  note #3: Merged synapses are assigned a single
    new synapse object that represents them all, but keep their original NetCon
    objects. Each such NetCon now connects the original synapse's NetStim with
    the reduced synapse.
    '''
    if PP_params_dict is None:
        PP_params_dict = {}

    h.init()

    model_obj_name = load_model(model_filename)

    # finds soma properties
    soma = original_cell.soma[0] if original_cell.soma.hname(
    )[-1] == ']' else original_cell.soma

    soma_cable = CableParams(length=soma.L,
                             diam=soma.diam,
                             space_const=None,
                             cm=soma.cm,
                             rm=1.0 / soma.g_pas,
                             ra=soma.Ra,
                             e_pas=soma.e_pas,
                             electrotonic_length=None)

    has_apical = len(list(original_cell.apical)) != 0

    soma_ref = h.SectionRef(sec=soma)
    axon_section, axon_is_parent = find_and_disconnect_axon(soma_ref)
    roots_of_subtrees, num_of_subtrees = gather_subtrees(soma_ref)

    sections_to_delete, section_per_subtree_index, mapping_sections_to_subtree_index = \
        gather_cell_subtrees(roots_of_subtrees)

    # preparing for reduction

    # remove active conductances and get seg_to_mech dictionary
    segment_to_mech_vals = create_segments_to_mech_vals(sections_to_delete)

    # disconnects all the subtrees from the soma
    for subtree_root in roots_of_subtrees:
        h.disconnect(sec=subtree_root)

    # reducing the subtrees
    new_cable_properties = [
        reduce_subtree(roots_of_subtrees[i], reduction_frequency)
        for i in num_of_subtrees
    ]

    if total_segments_manual != -1:
        new_cables_nsegs = calculate_nsegs_from_manual_arg(
            new_cable_properties, total_segments_manual)
    else:
        new_cables_nsegs = calculate_nsegs_from_lambda(new_cable_properties)

    cell, basals = create_reduced_cell(soma_cable, has_apical, original_cell,
                                       model_obj_name, new_cable_properties,
                                       new_cables_nsegs)

    new_synapses_list, subtree_ind_to_q = merge_and_add_synapses(
        num_of_subtrees, new_cable_properties, PP_params_dict, synapses_list,
        mapping_sections_to_subtree_index, netcons_list, has_apical,
        roots_of_subtrees, original_cell, basals, cell, reduction_frequency)

    # create segment to segment mapping
    original_seg_to_reduced_seg, reduced_seg_to_original_seg = create_seg_to_seg(
        original_cell, section_per_subtree_index, roots_of_subtrees,
        mapping_sections_to_subtree_index, new_cable_properties, has_apical,
        cell.apic, basals, subtree_ind_to_q, mapping_type, reduction_frequency)

    # copy active mechanisms
    copy_dendritic_mech(original_seg_to_reduced_seg,
                        reduced_seg_to_original_seg, cell.apic, basals,
                        segment_to_mech_vals, mapping_type)

    # Connect axon back to the soma
    if len(axon_section) > 0:
        if axon_is_parent:
            soma.connect(axon_section[0])
        else:
            axon_section[0].connect(soma)

    # Now we delete the original model
    for section in sections_to_delete:
        with push_section(section):
            h.delete_section()

    cell.axon = axon_section
    cell.dend = cell.hoc_model.dend

    with push_section(cell.hoc_model.soma[0]):
        h.delete_section()

    return cell, new_synapses_list, netcons_list
コード例 #12
0
ファイル: msgap.py プロジェクト: neuronsimulator/nrntest
proc init() {
  connect dend(0), soma(1)
  soma { L=10  diam= 10 insert hh }
  dend { L=20  diam=1   insert pas  g_pas = .001  e_pas = -65 }
}
endtemplate Cell

""")

# 1 cell for each rank
cell = h.Cell()

# rank 0 cell uses multisplit. Works if rank = 1
if rank == 0:
    h.disconnect(sec=cell.dend)
    pc.multisplit(0.0, rank, sec=cell.dend)
    pc.multisplit(1.0, rank, sec=cell.soma)

# gap junction between soma of rank i and rank (i+1)%nhost
# use sids of 2*i and 2*i + 1 for the source voltages
halfgaps = []


def mkgap(i):
    if rank == i:
        gap = h.HalfGap(cell.soma(0.5))
        halfgaps.append(gap)
        pc.source_var(cell.soma(0.5)._ref_v, i, sec=cell.soma)
        gap = pc.target_var(gap, gap._ref_vgap, i + 1)
    if rank == (i + 1) % nhost: