Ejemplo n.º 1
0
    def test_empty(self):
        def len(cat):
            return sum(1 for _ in cat)

        def hash_(cat):
            return hash(" ".join(sorted(cat)))

        cat = arb.catalogue()
        ref = arb.default_catalogue()
        other = arb.default_catalogue()
        # Test empty constructor
        self.assertEqual(0, len(cat),
                         "Expected no mechanisms in `arbor.catalogue()`.")
        # Test empty extend
        other.extend(cat, "")
        self.assertEqual(hash_(ref), hash_(other),
                         "Extending cat with empty should not change cat.")
        self.assertEqual(0, len(cat),
                         "Extending cat with empty should not change empty.")
        other.extend(cat, "prefix/")
        self.assertEqual(
            hash_(ref), hash_(other),
            "Extending cat with prefixed empty should not change cat.")
        self.assertEqual(
            0, len(cat),
            "Extending cat with prefixed empty should not change empty.")
        cat.extend(other, "")
        self.assertEqual(
            hash_(other), hash_(cat),
            "Extending empty with cat should turn empty into cat.")
        cat = arb.catalogue()
        cat.extend(other, "prefix/")
        self.assertNotEqual(
            hash_(other), hash_(cat),
            "Extending empty with prefixed cat should not yield cat")
Ejemplo n.º 2
0
    def __init__(self, probes, Vms, length, radius, cm, rL, g, gj_g,
                 cv_policy_max_extent):
        """
        probes -- list of probes

        Vms -- membrane leak potentials of the two cells
        length -- length of cable in μm
        radius -- radius of cable in μm
        cm -- membrane capacitance in F/m^2
        rL -- axial resistivity in Ω·cm
        g -- membrane conductivity in S/cm^2
        gj_g -- gap junction conductivity in μS

        cv_policy_max_extent -- maximum extent of control volume in μm
        """

        # 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_probes = probes

        self.Vms = Vms
        self.length = length
        self.radius = radius
        self.cm = cm
        self.rL = rL
        self.g = g
        self.gj_g = gj_g

        self.cv_policy_max_extent = cv_policy_max_extent

        self.the_props = arbor.neuron_cable_properties()
        self.the_cat = arbor.default_catalogue()
        self.the_props.register(self.the_cat)
Ejemplo n.º 3
0
 def __init__(self, ncells_per_chain, nchains):
     arbor.recipe.__init__(self)
     self.nchains = nchains
     self.ncells_per_chain = ncells_per_chain
     self.props = arbor.neuron_cable_properties()
     self.cat = arbor.default_catalogue()
     self.props.register(self.cat)
Ejemplo n.º 4
0
    def __init__(self, dT, n_pairs):
        arbor.recipe.__init__(self)
        self.dT = dT
        self.n_pairs = n_pairs

        self.the_props = arbor.neuron_cable_properties()
        self.the_cat = arbor.default_catalogue()
        self.the_props.register(self.the_cat)
Ejemplo n.º 5
0
 def __init__(self, n=10):
     # 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.ncells = n
     self.props = arbor.neuron_cable_properties()
     self.cat = arbor.default_catalogue()
     self.props.register(self.cat)
Ejemplo n.º 6
0
 def make_catalogue(cls):
     """
     Override to return the catalogue required to run this model
     """
     try:
         import arbor
     except ImportError:
         raise ImportError("`arbor` unavailable, can't make arbor models.")
     return arbor.default_catalogue()
Ejemplo n.º 7
0
 def __init__(self, cell, probes):
     # (4.1) 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_props = arbor.neuron_cable_properties()
     self.the_cat = arbor.default_catalogue()
     self.the_props.register(self.the_cat)
Ejemplo n.º 8
0
 def __init__(self):
     A.recipe.__init__(self)
     st = A.segment_tree()
     i = st.append(A.mnpos, (0, 0, 0, 10), (1, 0, 0, 10), 1)
     st.append(i, (1, 3, 0, 5), 1)
     st.append(i, (1, -4, 0, 3), 1)
     self.the_morphology = A.morphology(st)
     self.the_cat = A.default_catalogue()
     self.the_props = A.neuron_cable_properties()
     self.the_props.register(self.the_cat)
    def __init__(self, cell, probes):
        # The base C++ class constructor must be called first to ensure that all memory
        # in the C++ class is initialised correctly
        arbor.recipe.__init__(self)
        self.the_cell = cell
        self.the_probes = probes

        self.the_cat = arbor.default_catalogue()

        self.the_props = arbor.cable_global_properties()
Ejemplo n.º 10
0
    def __init__(self, cell):
        super().__init__()

        self.the_cell = cell

        self.vprobe_id = (0, 0)
        self.iprobe_id = (0, 1)
        self.cprobe_id = (0, 2)

        self.the_props = arbor.neuron_cable_properties()
        self.the_cat = arbor.default_catalogue()
        self.the_props.register(self.the_cat)
Ejemplo n.º 11
0
 def __init__(self, nl_network, pop_indices_vs_gids, pops_vs_components, proj_weights, proj_delays):
     # 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.props = arbor.neuron_cable_properties()
     self.cat = arbor.default_catalogue()
     self.props.register(self.cat)
     self.pop_indices_vs_gids = pop_indices_vs_gids
     self.pops_vs_components = pops_vs_components
     self.nl_network = nl_network
     self.proj_weights = proj_weights
     self.proj_delays = proj_delays
Ejemplo n.º 12
0
    def __init__(self):
        A.recipe.__init__(self)
        st = A.segment_tree()
        st.append(A.mnpos, (0, 0, 0, 10), (1, 0, 0, 10), 1)

        dec = A.decor()

        dec.place('(location 0 0.08)', "expsyn")
        dec.place('(location 0 0.09)', "exp2syn")
        dec.paint('(all)', "hh")

        self.cell = A.cable_cell(st, A.label_dict(), dec)

        self.cat = A.default_catalogue()
        self.props = A.neuron_cable_propetries()
        self.props.register(self.cat)
Ejemplo n.º 13
0
    def __init__(self):
        arb.recipe.__init__(self)
        self.tree = arb.segment_tree()
        self.tree.append(arb.mnpos, (0, 0, 0, 10), (1, 0, 0, 10), 1)
        self.props = arb.neuron_cable_properties()
        try:
            self.cat = arb.default_catalogue()
            self.props.register(self.cat)
        except:
            print("Catalogue not found. Are you running from build directory?")
            raise

        d = arb.decor()
        d.paint('(all)', arb.density('pas'))
        d.set_property(Vm=0.0)
        self.cell = arb.cable_cell(self.tree, arb.label_dict(), d)
Ejemplo n.º 14
0
    def __init__(self):
        A.recipe.__init__(self)
        st = A.segment_tree()
        st.append(A.mnpos, (0, 0, 0, 10), (1, 0, 0, 10), 1)

        dec = A.decor()

        dec.place('(location 0 0.08)', A.synapse("expsyn"), "syn0")
        dec.place('(location 0 0.09)', A.synapse("exp2syn"), "syn1")
        dec.place('(location 0 0.1)', A.iclamp(20.), "iclamp")
        dec.paint('(all)', A.density("hh"))

        self.cell = A.cable_cell(st, A.label_dict(), dec)

        self.props = A.neuron_cable_properties()
        self.props.catalogue = A.default_catalogue()
Ejemplo n.º 15
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)
Ejemplo n.º 16
0
    def __init__(self, probes,
                 Vm, length, radius, cm, rL, g,
                 stimulus_start, stimulus_duration, stimulus_amplitude,
                 cv_policy_max_extent):
        """
        probes -- list of probes

        Vm -- membrane leak potential
        length -- length of cable in μm
        radius -- radius of cable in μm
        cm -- membrane capacitance in F/m^2
        rL -- axial resistivity in Ω·cm
        g -- membrane conductivity in S/cm^2

        stimulus_start -- start of stimulus in ms
        stimulus_duration -- duration of stimulus in ms
        stimulus_amplitude -- amplitude of stimulus in nA

        cv_policy_max_extent -- maximum extent of control volume in μm
        """

        # (4.1) 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_probes = probes

        self.Vm = Vm
        self.length = length
        self.radius = radius
        self.cm = cm
        self.rL = rL
        self.g = g

        self.stimulus_start = stimulus_start
        self.stimulus_duration = stimulus_duration
        self.stimulus_amplitude = stimulus_amplitude

        self.cv_policy_max_extent = cv_policy_max_extent

        self.the_props = arbor.neuron_cable_properties()
        self.the_cat = arbor.default_catalogue()
        self.the_props.register(self.the_cat)
Ejemplo n.º 17
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 initialised correctly
        arbor.recipe.__init__(self)
        self.the_cell = cell
        self.the_probes = probes

        self.the_cat = arbor.default_catalogue()

        self.the_props = arbor.cable_global_properties()
        self.the_props.set_property(Vm=-45, cm=0.01, rL=12000)
        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)
Ejemplo n.º 18
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(), )
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
 def __init__(self, n_cell):
     A.recipe.__init__(self)
     self.n_cell = n_cell
     self.cat = A.default_catalogue()
     self.props = A.neuron_cable_propetries()
     self.props.register(self.cat)
Ejemplo n.º 21
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
Ejemplo n.º 22
0
# (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')

# (8) Plot the recorded voltages over time.
print("Plotting results ...")
seaborn.set_theme()  # Apply some styling to the plot
df = pandas.DataFrame({'t/ms': m.traces[0].time, 'U/mV': m.traces[0].value})
seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",
                ci=None).savefig('single_cell_model_result_7_0.svg')

# (9) Optionally, you can store your results for later processing.
df.to_csv('single_cell_model_result_7_0.csv', float_format='%g')

cat = arbor.default_catalogue()

# Get mechanism_info for the 'expsyn' mechanism.
mech = cat['Leak']

# Query the mechanism_info for information about parameters.
print(mech.parameters.keys())

print(mech.parameters['gmax'].default)