コード例 #1
0
    def __init__(self, cell, probes):
        # The base C++ class constructor must be called first, to ensure that
        # all memory in the C++ class is initialized correctly.
        arbor.recipe.__init__(self)
        self.the_cell = cell
        self.the_probes = probes

        self.the_cat = arbor.default_catalogue()
        self.the_cat.extend(arbor.allen_catalogue(), "")

        self.the_props = arbor.cable_global_properties()
        self.the_props.set_property(Vm=-65, tempK=300, rL=35.4, cm=0.01)
        self.the_props.set_ion(ion='na', int_con=10,   ext_con=140, rev_pot=50, method='nernst/na')
        self.the_props.set_ion(ion='k',  int_con=54.4, ext_con=2.5, rev_pot=-77)
        self.the_props.set_ion(ion='ca', int_con=5e-5, ext_con=2, rev_pot=132.5)

        self.the_props.register(self.the_cat)
コード例 #2
0
ファイル: model.py プロジェクト: brenthuisman/l2l-arbor
    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(), )
コード例 #3
0
model = arbor.single_cell_model(cell)

# (6) Set the model default properties

model.properties.set_property(Vm=-65, tempK=300, rL=35.4, cm=0.01)
model.properties.set_ion('na',
                         int_con=10,
                         ext_con=140,
                         rev_pot=50,
                         method='nernst/na')
model.properties.set_ion('k', int_con=54.4, ext_con=2.5, rev_pot=-77)

# Extend the default catalogue with the allen catalogue.

model.catalogue.extend(arbor.allen_catalogue(), "")

# (7) Add probes.

model.probe('voltage', where='"custom_terminal"', frequency=50)

# (8) Run the simulation.

model.run(tfinal=100, dt=0.025)

# (9) Print the spikes.

print(len(model.spikes), 'spikes recorded:')

# Print the spike times.
コード例 #4
0
# (6) Set the model default properties

model.properties.set_property(Vm=-65, tempK=300, rL=35.4, cm=0.01)
model.properties.set_ion('na',
                         int_con=10,
                         ext_con=140,
                         rev_pot=50,
                         method='nernst/na')
model.properties.set_ion('k', int_con=54.4, ext_con=2.5, rev_pot=-77)

# Extend the default catalogue with the Allen catalogue.
# The function takes a second string parameter that can prefix
# the name of the mechanisms to avoid collisions between catalogues
# in this case we have no collisions so we use an empty prefix string.
model.properties.catalogue.extend(arbor.allen_catalogue(), "")

# (7) Add probes.

# Add voltage probes on the "custom_terminal" locset
# which sample the voltage at 50 kHz
model.probe('voltage', where='"custom_terminal"', frequency=50)

# (8) Run the simulation for 100 ms, with a dt of 0.025 ms

model.run(tfinal=100, dt=0.025)

# (9) Print the spikes.

print(len(model.spikes), 'spikes recorded:')
for s in model.spikes:
コード例 #5
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
コード例 #6
0
ファイル: model.py プロジェクト: arbor-sim/arbor-materials
                         '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)