예제 #1
0
def make_kc_with_dynaclamp(kc_name,
                           kc_file,
                           inject,
                           tstart,
                           tend,
                           ggn_vm=None):
    """Read KC model from `kc_file`, inject current `inject` nA, apply
    dynamic clamp `ggn_vm`, which should be a 2D array with time (ms)
    in column 0, and voltage (mV) in column 1.

    """
    global model_dict
    kc = nu.create_cell(kc_name, filename=kc_file)
    model_dict[kc] = None
    iclamp = ephys.setup_current_clamp(kc.soma,
                                       pos=0.5,
                                       delay=Q_(tstart, 'ms'),
                                       duration=Q_((tend - tstart), 'ms'),
                                       amplitude=Q_(inject, 'nA'))
    model_dict[iclamp] = None
    ggn_g_vec = None
    if ggn_vm is not None:
        syn = h.GradedSyn(kc.soma(0.5))
        for attr, value in GGN_KC_SYN_PARAMS.items():
            setattr(syn, attr, value)
        model_dict[syn] = None
        ggn_comp = h.Section('ggn')
        model_dict[ggn_comp] = None
        h.setpointer(ggn_comp(0.5)._ref_v, 'vpre', syn)
        ggn_vm_vec = h.Vector(ggn_vm[:, 1])
        tvec = h.Vector(ggn_vm[:, 0])
        model_dict[tvec] = None
        # vec.play(var_reference, t, continuous) for interpolating
        ret = ggn_vm_vec.play(ggn_comp(0.5)._ref_v, tvec, 1)
        print('####', ret)
        model_dict[ggn_vm_vec] = None
        ggn_g_vec = h.Vector()
        ggn_g_vec.record(syn._ref_g)
        model_dict[ggn_g_vec] = None
    kc_vm_vec = h.Vector()
    kc_vm_vec.record(kc.soma(0.5)._ref_v)
    model_dict[kc_vm_vec] = None
    print('Built model')
    return (kc_vm_vec, ggn_g_vec)
예제 #2
0
    args = parser.parse_args()
    inputs = args.inputs
    celltemplate = args.celltemplate
    syncount = args.syncount
    onset = args.onset
    tau = args.tau
    gmax = args.gmax
    diascale = args.diascale
    dialim = args.dialim
    mechs = {'pas': {'g': 3e-5, 'e': -51.0}}
    # {'name': 'caiiag', 'gbar': 2.5e-5},
    # {'name': 'ka', 'gbar': 0.03}]

    h.xopen(celltemplate)
    ggn = nu.create_cell(args.cellname,
                         filename=args.celltemplate,
                         mechparams=mechs)
    if (args.diascale is not None) and (args.dialim is not None):
        count = 0
        ggn.soma.push()
        ordered_tree = h.SectionList()
        ordered_tree.wholetree()
        h.pop_section()
        for sec in ordered_tree:
            sec.push()
            for ii, seg in enumerate(sec):
                if seg.diam < dialim:
                    seg.diam = seg.diam * diascale
                    # print('Changed diameter of segment', ii, seg.x, 'of section', sec.name(), 'to', seg.diam)
                    count += 1
            h.pop_section()
예제 #3
0
def setup_model(args):
    """Setup the model with synapses and recording tables."""
    cell_template = args['celltemplate']
    input_regions = args['inputs']
    syn_counts = args['syncounts']
    onset = args['onset']
    tau = args['tau']
    gsyn = args['gsyn']
    mechs = {
        'pas': {
            'g': Q_(args['gpas'], 'S/cm**2'),
            'e': Q_(args['Em'], 'mV')
        }
    }
    if args['gk'] > 0:
        mechs['ka'] = {'gbar': Q_(args['gk'], 'S/cm**2')}
    if args['gca'] > 0:
        mechs['cam'] = {'gbar': Q_(args['gca'], 'S/cm**2')}
    h.xopen(cell_template)
    ggn = nu.create_cell(args['cellname'],
                         filename=args['celltemplate'],
                         mechparams=mechs)
    for sec in ggn.allsec():
        sec.Ra = args['RA']
    g0 = nu.nrngraph(ggn)
    g, nmap = ng.renumber_nodes(g0, ggn.soma.name())
    # Pick out nodes with sections associated with them (not terminal dummy nodes)
    sec_nodes = [n for n in g.nodes() if g.node[n]['orig'] is not None]
    # Select the nodes for synapse insertion
    if args['synfile'] is not None:  # This option is to allow replication
        syn_nodes = []
        sec_node_map = get_section_node_map(g)
        with open(args['synfile']) as fd:
            for line in fd:
                try:
                    secname = line.strip()
                    syn_nodes.append(sec_node_map[secname])
                except KeyError:
                    print('Could not fidn section "{}"'.format(secname))
                    raise
    else:
        syn_nodes_by_sid = ng.select_random_nodes_by_sid(
            g.subgraph(sec_nodes), args['inputs'], args['syncounts'])
        syn_nodes = list(
            np.concatenate(
                [v for v in syn_nodes_by_sid.values() if len(v) > 0]))
        # If np.concatenate arg contains empty list, the result gets converted to float
    syn_secs = []
    synapses = []
    for syn_node in syn_nodes:
        sec = g.node[syn_node]['orig']
        syn_secs.append(sec)
        syn = insert_alphasynapse(sec(1.0),
                                  onset=args['onset'],
                                  gmax=args['gsyn'],
                                  tau=args['tau'])
        synapses.append(syn)
    if args['recfile'] is not None:
        rec_nodes = []
        sec_node_map = get_section_node_map(g)
        with open(args['recfile']) as fd:
            for line in fd:
                try:
                    secname = line.strip()
                    rec_nodes.append(sec_node_map[secname])
                except KeyError:
                    print('Could not fidn section "{}"'.format(secname))
                    raise
    else:
        if args['recbyreg']:
            rec_regions = [1, 3, 4, 5, 6, 7, 8]
            rec_nodes_by_sid = ng.select_random_nodes_by_sid(
                g.subgraph(sec_nodes), rec_regions,
                [args['reccount']] * len(rec_regions))
            rec_nodes = np.concatenate(
                [v for v in rec_nodes_by_sid.values() if len(v) > 0])
            rec_nodes = list(rec_nodes)
        else:
            rec_nodes = list(
                np.random.choice(sec_nodes,
                                 size=args['reccount'],
                                 replace=False))
    rec_nodes = list(set(rec_nodes + syn_nodes))
    rec_secs = [g.node[n]['orig'] for n in rec_nodes]
    t_vec = h.Vector()
    t_vec.record(h._ref_t)
    v_vecs = setup_recording(rec_secs)
    syn_vecs = []
    for syn in synapses:
        vec = h.Vector()
        vec.record(syn._ref_i)
        syn_vecs.append(vec)
    return {
        'cell': ggn,
        'cellgraph': g,
        'synapses': synapses,
        'synsecs': syn_secs,
        'synnodes': syn_nodes,
        'recsecs': rec_secs,
        'recnodes': rec_nodes,
        'tvec': t_vec,
        'vvecs': v_vecs,
        'synvecs': syn_vecs
    }
예제 #4
0
                        dest='rec',
                        default=0)

    args = parser.parse_args()
    inputs = args.inputs
    celltemplate = args.celltemplate
    syncount = args.syncount
    onset = args.onset
    gmax = args.gmax
    diascale = args.diascale
    dialim = args.dialim
    maxrate = args.maxrate / 1000.0  # s^-1 to per ms^-1
    mechs = {'pas': {'g': '{} S/cm**2'.format(args.gpas), 'e': '-51.0mV'}}
    h.xopen(celltemplate)
    ggn = nu.create_cell(args.cellname,
                         mechparams=mechs,
                         Ra='{}ohm*cm'.format(args.RA),
                         filename=args.celltemplate)
    if (args.diascale is not None) and (args.dialim is not None):
        count = 0
        ggn.soma.push()
        ordered_tree = h.SectionList()
        ordered_tree.wholetree()
        h.pop_section()
        for sec in ordered_tree:
            sec.push()
            for ii, seg in enumerate(sec):
                if seg.diam < dialim:
                    seg.diam = seg.diam * diascale
                    count += 1
            h.pop_section()
        print('Scaled diameters of', count, 'sections whose diameters were <',
예제 #5
0
     'vslope': Q_('5.0mV').to('mV').m,
     'e': Q_('-80mV').to('mV').m,
     'gbar': Q_('1e-3uS').to('uS').m,
     'tau': Q_('4.0ms').to('ms').m
 }
 # Note: I increased threshold to avoid transmission during low  frequency stimulus
 # where KC can have sustained depolarization.
 kc_ggn_syn_params = {
     'threshold': Q_('-10.0mV').to('mV').m,
     'delay': Q_('1.0ms').to('ms').m,
     'e': Q_('0.0mV').to('mV').m,
     'tau1': Q_('13.333ms').to('ms').m,
     'tau2': Q_('13.333ms').to('ms').m,
     'gmax': Q_('5pS').to('uS').m
 }
 kc = nu.create_cell(args.kc, filename=args.kcfile)
 kc_solo = nu.create_cell(args.kc, filename=args.kcfile)
 ggn = nu.create_cell(args.ggn, filename=args.ggnfile)
 model = make_ggn_kc_conn(ggn, kc, ggn_kc_syn_params)
 tstart = 0.5e3
 tend = 3.1e3
 if len(args.freq) > 1:
     inject = make_driving_current(kc.soma, 0.5, args.amp[0], 1.0, tstart,
                                   tend)
     inject_solo = make_driving_current(kc_solo.soma, 0.5, args.amp[0], 1.0,
                                        tstart, tend)
 else:
     inject = ephys.setup_current_clamp(kc.soma,
                                        delay=Q_(tstart, 'ms'),
                                        duration=Q_((tend - tstart), 'ms'),
                                        amplitude=Q_(args.amp[0], 'nA'),