Beispiel #1
0
    def simulate(self, traj):
        cell = arb.cable_cell(self.morphology, self.labels)
        cell.compartments_length(20)
        cell.set_properties(tempK=self.defaults.tempK,
                            Vm=self.defaults.Vm,
                            cm=self.defaults.cm,
                            rL=self.defaults.rL)
        for region, vs in self.regions:
            cell.paint(f'"{region}"',
                       tempK=vs.tempK,
                       Vm=vs.Vm,
                       cm=vs.cm,
                       rL=vs.rL)
        for region, ion, e in self.ions:
            cell.paint(f'"{region}"', ion, rev_pot=e)
        cell.set_ion('ca',
                     int_con=5e-5,
                     ext_con=2.0,
                     method=arb.mechanism('nernst/x=ca'))

        tmp = defaultdict(dict)
        for key, val in traj.individual.items():
            region, mech, valuename = key.split('.')
            tmp[(region, mech)][valuename] = val

        for (region, mech), values in tmp.items():
            cell.paint(f'"{region}"', arb.mechanism(mech, values))

        cell.place('"center"', arb.iclamp(200, 1000, 0.15))
        model = arb.single_cell_model(cell)
        model.probe('voltage', '"center"', frequency=200000)
        model.properties.catalogue = arb.allen_catalogue()
        model.properties.catalogue.extend(arb.default_catalogue(), '')
        model.run(tfinal=1400, dt=0.005)
        voltages = np.array(model.traces[0].value[:])
        return (((voltages - self.reference)**2).sum(), )
Beispiel #2
0
labels = arbor.label_dict({'soma': '(tag 2)', 'center': '(location 0 0.5)'})

cell = arbor.cable_cell(tree, labels)

# Set initial membrane potential everywhere on the cell to -40 mV.
cell.set_properties(Vm=-40)
# Put hh dynamics on soma, and passive properties on the dendrites.
cell.paint('soma', 'hh')
# Attach stimuli with duration of 2 ms and current of 0.8 nA.
cell.place('center', arbor.iclamp(10, 2, 0.8))
# Add a spike detector with threshold of -10 mV.
cell.place('center', arbor.spike_detector(-10))

# Make single cell model.
m = arbor.single_cell_model(cell)

# Attach voltage probes, sampling at 10 kHz.
m.probe('voltage', 'center', 10000)

# Run simulation for 100 ms of simulated activity.
tfinal = 30
m.run(tfinal)

# Print spike times.
if len(m.spikes) > 0:
    print('{} spikes:'.format(len(m.spikes)))
    for s in m.spikes:
        print('  {:7.4f}'.format(s))
else:
    print('no spikes')
Beispiel #3
0
                         'center': '(location 0 0.5)'})
cell = arb.cable_cell(morphology, labels) # see !\circled{3}!
cell.compartments_length(20) # discretisation strategy: max compartment length
# !\circled{4}! load and assign electro-physical parameters
defaults, regions, ions, mechanisms = utils.load_allen_fit('fit.json')
# set defaults and override by region
cell.set_properties(tempK=defaults.tempK, Vm=defaults.Vm,
                    cm=defaults.cm, rL=defaults.rL)
for region, vs in regions:
    cell.paint('"'+region+'"', tempK=vs.tempK, Vm=vs.Vm, cm=vs.cm, rL=vs.rL)
# set reversal potentials
for region, ion, e in ions:
    cell.paint('"'+region+'"', ion, rev_pot=e)
cell.set_ion('ca', int_con=5e-5, ext_con=2.0, method=arb.mechanism('nernst/x=ca'))
# assign ion dynamics
for region, mech, values in mechanisms:
    cell.paint('"'+region+'"', arb.mechanism(mech, values))
    print(mech)
# !\circled{5}! attach stimulus and spike detector
cell.place('"center"', arb.iclamp(200, 1000, 0.15))
cell.place('"center"', arb.spike_detector(-40))
# !\circled{6}! set up runnable simulation
model = arb.single_cell_model(cell)
model.probe('voltage', '"center"', frequency=200000) # see !\circled{5}!
# !\circled{7}! assign catalogues
model.properties.catalogue = arb.allen_catalogue()
model.properties.catalogue.extend(arb.default_catalogue(), '')
# !\circled{8}! run simulation and plot results
model.run(tfinal=1400, dt=0.005)
utils.plot_results(model)
Beispiel #4
0
def run_arb(fit, swc, current, t_start, t_stop):
    tree = arbor.load_swc_allen(swc, no_gaps=False)

    # Load mechanism data
    with open(fit) as fd:
        fit = json.load(fd)
    ## collect parameters in dict
    mechs = defaultdict(dict)

    ### Passive parameters
    ra = float(fit['passive'][0]['ra'])

    ### Remaining parameters
    for block in fit['genome']:
        mech = block['mechanism'] or 'pas'
        region = block['section']
        name = block['name']
        if name.endswith('_' + mech):
            name = name[:-(len(mech) + 1)]
        mechs[(mech, region)][name] = float(block['value'])
    # Label regions
    labels = arbor.label_dict({
        'soma': '(tag 1)',
        'axon': '(tag 2)',
        'dend': '(tag 3)',
        'apic': '(tag 4)',
        'center': '(location 0 0.5)'
    })

    properties = fit['conditions'][0]
    T = properties['celsius'] + 273.15
    Vm = properties['v_init']

    # Run simulation
    morph = arbor.morphology(tree)

    # Build cell and attach Clamp and Detector
    cell = arbor.cable_cell(morph, labels)
    cell.place('center', arbor.iclamp(t_start, t_stop - t_start, current))
    cell.place('center', arbor.spike_detector(-40))
    cell.compartments_length(20)

    # read json file and proceed to set parameters and mechanisms

    # set global values
    print('Setting global parameters')
    print(f"  * T  =  {T}K = {T - 273.15}C")
    print(f"  * Vm =  {Vm}mV")
    cell.set_properties(tempK=T, Vm=Vm, rL=ra)

    # Set reversal potentials
    print("Setting reversal potential for")
    for kv in properties['erev']:
        region = kv['section']
        for k, v in kv.items():
            if k == 'section':
                continue
            ion = k[1:]
            print(f'  * region {region:6} species {ion:5}: {v:10}')
            cell.paint(region, arbor.ion(ion, rev_pot=float(v)))

    cell.set_ion('ca',
                 int_con=5e-5,
                 ext_con=2.0,
                 method=arbor.mechanism('default_nernst/x=ca'))

    # Setup mechanisms and parameters
    print('Setting up mechanisms')
    ## Now paint the cell using the dict
    for (mech, region), vs in mechs.items():
        print(f"  * {region:10} -> {mech:10}: {str(vs):>60}", end=' ')
        try:
            if mech != 'pas':
                m = arbor.mechanism(mech, vs)
                cell.paint(region, m)
            else:
                m = arbor.mechanism('default_pas', {
                    'e': vs['e'],
                    'g': vs['g']
                })
                cell.paint(region, m)
                cell.paint(region, cm=vs["cm"] / 100, rL=vs["Ra"])
            print("OK")
        except Exception as e:
            print("ERROR")
            print("When trying to set", mech, vs)
            print("  ->", e)
            exit()

    # Run the simulation, collecting voltages
    print('Simulation', end=' ')
    default = arbor.default_catalogue()
    catalogue = arbor.allen_catalogue()
    catalogue.extend(default, 'default_')

    model = arbor.single_cell_model(cell)
    model.properties.catalogue = catalogue
    model.probe('voltage', 'center', frequency=200000)
    model.run(tfinal=t_start + t_stop, dt=1000 / 200000)
    print('DONE')
    for t in model.traces:
        ts = t.time[:]
        vs = t.value[:]
        break
    spikes = np.array(model.spikes)
    count = len(spikes)
    print('Counted spikes', count)
    return np.array(ts), np.array(vs) + 14
Beispiel #5
0

# put hh dynamics on soma and passive properties on the dendrites
#dd1_cell.paint('"soma"', 'Leak')
dd1_cell.paint('"soma"', 'k_slow')
dd1_cell.paint('"soma"', 'k_fast')
dd1_cell.paint('"soma"', 'CaPoolTH')
dd1_cell.paint('"soma"', 'ca_boyle')
#dd1_cell.paint('"soma"', 'hh')

dd1_cell.place('"center"', arbor.iclamp(100, 300, 0.0087))
dd1_cell.place('"center"', arbor.spike_detector(-26))


# (4) Make single cell model.
m = arbor.single_cell_model(dd1_cell)

# (5) Attach voltage probe sampling at 10 kHz (every 0.1 ms).
m.probe('voltage', '"center"', frequency=10000)

# (6) Run simulation for 30 ms of simulated activity.
m.run(tfinal=500)

# (7) Print spike times, if any.
if len(m.spikes)>0:
    print('{} spikes:'.format(len(m.spikes)))
    for s in m.spikes:
        print('{:3.3f}'.format(s))
else:
    print('no spikes')