Esempio n. 1
0
    def cell_description(self, gid):
        tree = arbor.segment_tree()
        tree.append(arbor.mnpos,
                    arbor.mpoint(-3, 0, 0, 3),
                    arbor.mpoint(3, 0, 0, 3),
                    tag=1)

        labels = arbor.label_dict({
            'soma': '(tag 1)',
            'center': '(location 0 0.5)'
        })

        decor = arbor.decor()
        decor.set_property(Vm=-40)
        decor.paint('(all)', arbor.density('hh'))

        decor.place('"center"', arbor.spike_detector(-10), "detector")
        decor.place('"center"', arbor.synapse('expsyn'), "synapse")

        mech = arbor.mechanism('expsyn_stdp')
        mech.set("max_weight", 1.)
        syn = arbor.synapse(mech)

        decor.place('"center"', syn, "stpd_synapse")

        cell = arbor.cable_cell(tree, labels, decor)

        return cell
Esempio n. 2
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(), )
Esempio n. 3
0
def make_cable_cell(morphology, clamp_location):
    # number of CVs per branch
    cvs_per_branch = 3

    # Label dictionary
    defs = {}
    labels = arbor.label_dict(defs)

    # decor
    decor = arbor.decor()

    # set initial voltage, temperature, axial resistivity, membrane capacitance
    decor.set_property(
        Vm=-65,  # Initial membrane voltage (mV)
        tempK=300,  # Temperature (Kelvin)
        rL=10000,  # Axial resistivity (Ω cm)
        cm=0.01,  # Membrane capacitance (F/m**2)
    )

    # set passive mechanism all over
    # passive mech w. leak reversal potential (mV)
    pas = arbor.mechanism('pas/e=-65')
    pas.set('g', 0.0001)  # leak conductivity (S/cm2)
    decor.paint('(all)', arbor.density(pas))

    # set number of CVs per branch
    policy = arbor.cv_policy_fixed_per_branch(cvs_per_branch)
    decor.discretization(policy)

    # place sinusoid input current
    iclamp = arbor.iclamp(
        5,  # stimulation onset (ms)
        1E8,  # stimulation duration (ms)
        -0.001,  # stimulation amplitude (nA)
        frequency=0.1,  # stimulation frequency (kHz)
        phase=0)  # stimulation phase)
    decor.place(str(clamp_location), iclamp, '"iclamp"')

    # create ``arbor.place_pwlin`` object
    p = arbor.place_pwlin(morphology)

    # create cell and set properties
    cell = arbor.cable_cell(morphology, labels, decor)

    return p, cell
Esempio n. 4
0
    def cell_description(self, gid):
        """A high level description of the cell with global identifier gid.

        For example the morphology, synapses and ion channels required
        to build a multi-compartment neuron.
        """
        assert gid == 0

        tree = arbor.segment_tree()

        tree.append(arbor.mnpos,
                    arbor.mpoint(0, 0, 0, self.radius),
                    arbor.mpoint(self.length, 0, 0, self.radius),
                    tag=1)

        labels = arbor.label_dict({
            'cable': '(tag 1)',
            'start': '(location 0 0)'
        })

        decor = arbor.decor()
        decor.set_property(Vm=self.Vm)
        decor.set_property(cm=self.cm)
        decor.set_property(rL=self.rL)

        decor.paint('"cable"',
                    arbor.mechanism(f'pas/e={self.Vm}', {'g': self.g}))

        decor.place(
            '"start"',
            arbor.iclamp(args.stimulus_start, args.stimulus_duration,
                         args.stimulus_amplitude), "iclamp")

        policy = arbor.cv_policy_max_extent(self.cv_policy_max_extent)
        decor.discretization(policy)

        cell = arbor.cable_cell(tree, labels, decor)

        return cell
Esempio n. 5
0
            Vm=e_pas,
        )

    ### Remaining parameters
    for block in fit['genome']:
        mech = block['mechanism'] or 'pas'
        region = block['section']
        name = block['name'][:-(len(mech) + 1)]
        mechs[(mech, region)][name] = block['value']

    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:
            m = arbor.mechanism(mech, vs)
            cell.paint(region, m)
            print("OK")
        except Exception as e:
            print("ERROR")
            print("  ->", e)

    # Run the simulation, collecting voltages
    print('Simulation', end=' ')
    model = arbor.single_cell_model(cell)
    model.probe('voltage', 'center', frequency=10000)
    model.run(tfinal=1500)
    print('DONE')
    for t in model.traces:
        ts = t.time[:]
        volts[i] = t.value[:]
Esempio n. 6
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
Esempio n. 7
0
labels = arbor.label_dict(defs)

# decor
decor = arbor.decor()

# set initial voltage, temperature, axial resistivity, membrane capacitance
decor.set_property(
    Vm=-65,  # Initial membrane voltage [mV]
    tempK=300,  # Temperature [Kelvin]
    rL=10000,  # Axial resistivity [Ω cm]
    cm=0.01,  # Membrane capacitance [F/m**2]
)

# set passive mechanism all over
# passive mech w. leak reversal potential (mV)
pas = arbor.mechanism('pas/e=-65')
pas.set('g', 0.0001)  # leak conductivity (S/cm2)
decor.paint('(all)', arbor.density(pas))

# set sinusoid input current at mid point of terminating CV (segment)
iclamp = arbor.iclamp(
    5,  # stimulation onset (ms)
    1E8,  # stimulation duration (ms)
    -0.001,  # stimulation amplitude (nA)
    frequency=0.1,  # stimulation frequency (kHz)
    phase=0)  # stimulation phase)
try:
    # arbor >= 0.5.2 fix
    decor.place('(location 4 0.16667)', iclamp, '"iclamp"')
except TypeError:
    decor.place('(location 4 0.16667)', iclamp)
Esempio n. 8
0
labels = arb.label_dict({'soma': '(tag 1)', 'axon': '(tag 2)',
                         'dend': '(tag 3)', 'apic': '(tag 4)',
                         '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)
Esempio n. 9
0
dd1_cell = arbor.cable_cell(morph, labels)


# neuroML: <specificCapacitance value="1 uF_per_cm2"/>, <initMembPotential value="-45 mV"/>, <resistivity value="12 kohm_cm"/>
# set cable properties
# Vm = initial membrane potential (-45 mV)
# cm = membrane capacitance (0.01 F / m²)
# rL = axial resistivity of cable (12000 Ohm * cm)
# tempK = temperature in Kelvin (not provided by c302)
dd1_cell.set_properties(Vm = -45, cm = 0.01, rL = 12000)

#cat = arbor.default_catalogue()

# define dynamics / mechanisms
# neuroML: <channelDensity id="Leak_all" ionChannel="Leak" condDensity="0.02 mS_per_cm2" erev="-50 mV" ion="non_specific"/>
Leak = arbor.mechanism("Leak")


# neuroML: <channelDensity id="k_slow_all" ionChannel="k_slow" condDensity="2 mS_per_cm2" erev="-60 mV" ion="k"/>
k_slow = arbor.mechanism("k_slow")


# neuroML: <channelDensity id="k_fast_all" ionChannel="k_fast" condDensity="0.2 mS_per_cm2" erev="-60 mV" ion="k"/>
k_fast = arbor.mechanism("k_fast")

# neuroML: <species id="ca" concentrationModel="CaPool" ion="ca" initialConcentration="0 mM" initialExtConcentration="2E-6 mol_per_cm3"/>
CaPoolTH = arbor.mechanism("CaPoolTH")


# neuroML: <channelDensity id="ca_boyle_all" ionChannel="ca_boyle" condDensity="2 mS_per_cm2" erev="40 mV" ion="ca"/>
ca_boyle_all = arbor.mechanism("ca_boyle")
Esempio n. 10
0
# Add locsets to the label dictionary.
labels['stim_site'] = '(location 0 0.5)'  # site for the stimulus
#labels['axon_end']  = '(restrict (terminal) (region "axon_group"))' # end of the axon.
labels[
    'dend_end'] = '(restrict (terminal) (region "dendrite_group"))'  # end of the axon.
labels[
    'root'] = '(root)'  # the start of the soma in this morphology is at the root of the cell.

labels['soma'] = '(location 0 0.5)'
#labels['dend1'] = '(location 1 0.5)'
#labels['dend2'] = '(location 2 0.5)'

decor = arbor.decor()

decor.paint('"all"', arbor.mechanism('pas', dict(g=2.01e-05)))

decor.place('"stim_site"', arbor.iclamp(100, 200, 0.1))

# Combine morphology with region and locset definitions to make a cable cell.
cell = arbor.cable_cell(morpho, labels, decor)
print(cell.locations('"dend_end"'))

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

m.probe('voltage', where='"root"', frequency=500)
m.probe('voltage', where='"dend_end"', frequency=500)

# Simulate the cell
print('Simulation start.')
Esempio n. 11
0
            if k == 'section':
                continue
            ion = k[1:]
            print(f'| {k:<3} | {region:6} | {v:10} |')
            cell.paint(region, arbor.ion(ion, rev_pot=float(v)))

    log_m = []
    log_p = []
            
    # Setup mechanisms and parameters
    print('Setting up mechanisms')
    ## Now paint the cell using the dict
    for (mech, region), vs in mechs.items():
        try:
            if mech != 'pas':
                m = arbor.mechanism(mech, vs)
                for k, v in vs.items():
                    log_p.append(f'| {mech:10} | {region:5} | {k:8} | {float(v):>12.6g} |')                
                log_m.append(f'||')
                cell.paint(region, m)
            else:
                m = arbor.mechanism('pas', {'e': vs['e'], 'g': vs['g']})
                for k, v in vs.items():
                    if k in {'e', 'g'}:
                        log_p.append(f'| {mech:10} | {region:5} | {k:8} | {float(v):>12.6g} |')                
                cell.paint(region, m)
                cell.paint(region, cm=vs["cm"]/100, rL=vs["Ra"])
        except Exception as e:
            print("ERROR")
            print("When trying to set", mech, vs)
            print("  ->", e)
Esempio n. 12
0
                    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))
# !\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)