def cell_description(self, gid): c = A.cable_cell(self.the_morphology, A.label_dict()) c.set_properties(Vm=0.0, cm=0.01, rL=30, tempK=300) c.paint('(all)', "pas") c.place('(location 0 0)', A.iclamp(current=10 if gid == 0 else 20)) c.place('(sum (on-branches 0.3) (location 0 0.6))', "expsyn") return c
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.density(f'pas/e={self.Vm}', {'g': self.g})) decor.place('"start"', arbor.iclamp(self.stimulus_start, self.stimulus_duration, self.stimulus_amplitude), "iclamp") policy = arbor.cv_policy_max_extent(self.cv_policy_max_extent) decor.discretization(policy) return arbor.cable_cell(tree, labels, decor)
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
def cell_description(self, gid): tree = arb.segment_tree() tree.append(arb.mnpos, arb.mpoint(-3, 0, 0, 3), arb.mpoint(3, 0, 0, 3), tag=1) decor = arb.decor() decor.place('(location 0 0.5)', arb.gap_junction_site(), "gj") return arb.cable_cell(tree, arb.label_dict(), decor)
def cable_cell(cls, morphology=0, decor=None, labels=None): try: import arbor except ImportError: raise ImportError("`arbor` unavailable, can't make arbor models.") morph, labels, decor = cls.cable_cell_template(morphology, decor, labels) return arbor.cable_cell(morph, labels, decor)
def make_cable_cell(gid): # (1) Build a segment tree tree = arbor.segment_tree() # Soma (tag=1) with radius 6 μm, modelled as cylinder of length 2*radius s = tree.append(arbor.mnpos, arbor.mpoint(-12, 0, 0, 6), arbor.mpoint(0, 0, 0, 6), tag=1) # Single dendrite (tag=3) of length 50 μm and radius 2 μm attached to soma. b0 = tree.append(s, arbor.mpoint(0, 0, 0, 2), arbor.mpoint(50, 0, 0, 2), tag=3) # Attach two dendrites (tag=3) of length 50 μm to the end of the first dendrite. # Radius tapers from 2 to 0.5 μm over the length of the dendrite. b1 = tree.append(b0, arbor.mpoint(50, 0, 0, 2), arbor.mpoint(50 + 50 / sqrt(2), 50 / sqrt(2), 0, 0.5), tag=3) # Constant radius of 1 μm over the length of the dendrite. b2 = tree.append(b0, arbor.mpoint(50, 0, 0, 1), arbor.mpoint(50 + 50 / sqrt(2), -50 / sqrt(2), 0, 1), tag=3) # Associate labels to tags labels = arbor.label_dict() labels['soma'] = '(tag 1)' labels['dend'] = '(tag 3)' # (2) Mark location for synapse at the midpoint of branch 1 (the first dendrite). labels['synapse_site'] = '(location 1 0.5)' labels['synapse_site2'] = '(location 1 0.5)' # Mark the root of the tree. labels['root'] = '(root)' # (3) Create a decor and a cable_cell decor = arbor.decor() # Put hh dynamics on soma, and passive properties on the dendrites. decor.paint('"soma"', 'hh') decor.paint('"dend"', 'pas') # (4) Attach a single synapse. decor.place('"synapse_site"', 'expsyn') decor.place('"synapse_site2"', 'expsyn') # Attach a spike detector with threshold of -10 mV. decor.place('"root"', arbor.spike_detector(-10)) cell = arbor.cable_cell(tree, labels, decor) return cell
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() self.props.catalogue = arb.load_catalogue(cat) d = arb.decor() d.paint('(all)', 'dummy') d.set_property(Vm=0.0) self.cell = arb.cable_cell(self.tree, arb.label_dict(), d)
def make_cable_cell(gid): # (1) Build a segment tree # https://docs.arbor-sim.org/en/latest/concepts/morphology.html tree = arbor.segment_tree() # Soma (tag=1) with radius 6 μm, modelled as cylinder of length 2*radius s = tree.append(arbor.mnpos, arbor.mpoint(-12, 0, 0, 6), arbor.mpoint(0, 0, 0, 6), tag=1) # Single dendrite (tag=3) of length 50 μm and radius 2 μm attached to soma. b0 = tree.append(s, arbor.mpoint(0, 0, 0, 2), arbor.mpoint(50, 0, 0, 2), tag=3) # Attach two dendrites (tag=3) of length 50 μm to the end of the first dendrite. # Radius tapers from 2 to 0.5 μm over the length of the dendrite. b1 = TODO # Constant radius of 1 μm over the length of the dendrite. b2 = TODO # Associate labels to tags # https://docs.arbor-sim.org/en/latest/concepts/labels.html labels = arbor.label_dict() labels['soma'] = '(tag 1)' labels['dend'] = '(tag 3)' # (2) Mark location for synapse at the midpoint of branch 1 (the first dendrite). # https://docs.arbor-sim.org/en/latest/concepts/labels.html labels['synapse_site'] = TODO # Mark the root of the tree. labels['root'] = TODO # (3) Create a decor and a cable_cell # https://docs.arbor-sim.org/en/latest/python/decor.html decor = arbor.decor() # Put hh dynamics on soma, and passive properties on the dendrites. decor.paint('"soma"', 'hh') decor.paint('"dend"', 'pas') # (4) Attach a single synapse. decor.place('"synapse_site"', 'expsyn', 'syn') # Attach a spike detector with threshold of -10 mV. decor.place(TODO) cell = arbor.cable_cell(tree, labels, decor) return cell
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)
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()
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)
def make_cable_cell(gid): # Build a segment tree tree = arbor.segment_tree() # Soma with radius 5 μm and length 2 * radius = 10 μm, (tag = 1) s = tree.append(arbor.mnpos, arbor.mpoint(-10, 0, 0, 5), arbor.mpoint(0, 0, 0, 5), tag=1) # Single dendrite with radius 2 μm and length 40 μm, (tag = 2) b = tree.append(s, arbor.mpoint(0, 0, 0, 2), arbor.mpoint(40, 0, 0, 2), tag=2) # Label dictionary for cell components labels = arbor.label_dict() labels['soma'] = '(tag 1)' labels['dend'] = '(tag 2)' # Mark location for synapse site at midpoint of dendrite (branch 0 = soma + dendrite) labels['synapse_site'] = '(location 0 0.6)' # Gap junction site at connection point of soma and dendrite labels['gj_site'] = '(location 0 0.2)' # Label root of the tree labels['root'] = '(root)' # Paint dynamics onto the cell, hh on soma and passive properties on dendrite decor = arbor.decor() decor.paint('"soma"', arbor.density("hh")) decor.paint('"dend"', arbor.density("pas")) # Attach one synapse and gap junction each on their labeled sites decor.place('"synapse_site"', arbor.synapse('expsyn'), 'syn') decor.place('"gj_site"', arbor.junction('gj'), 'gj') # Attach spike detector to cell root decor.place('"root"', arbor.spike_detector(-10), 'detector') cell = arbor.cable_cell(tree, labels, decor) return cell
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
def cable_cell(): # (1) Create a morphology with a single (cylindrical) segment of length=diameter=6 μm tree = arbor.segment_tree() tree.append( arbor.mnpos, arbor.mpoint(-3, 0, 0, 3), arbor.mpoint(3, 0, 0, 3), tag=1, ) # (2) Define the soma and its midpoint labels = arbor.label_dict({'soma': '(tag 1)', 'midpoint': '(location 0 0.5)'}) # (3) Create cell and set properties decor = arbor.decor() decor.set_property(Vm=-40) decor.paint('"soma"', arbor.density('hh')) decor.place('"midpoint"', arbor.iclamp( 10, 2, 0.8), "iclamp") decor.place('"midpoint"', arbor.spike_detector(-10), "detector") return arbor.cable_cell(tree, labels, decor)
def create_arbor_cell(cell, nl_network, gid): if cell.arbor_cell=='cable_cell': default_tree = arbor.segment_tree() radius = evaluate(cell.parameters['radius'], nl_network.parameters) if 'radius' in cell.parameters else 3 default_tree.append(arbor.mnpos, arbor.mpoint(-1*radius, 0, 0, radius), arbor.mpoint(radius, 0, 0, radius), tag=1) labels = arbor.label_dict({'soma': '(tag 1)', 'center': '(location 0 0.5)'}) labels['root'] = '(root)' decor = arbor.decor() v_init = evaluate(cell.parameters['v_init'], nl_network.parameters) if 'v_init' in cell.parameters else -70 decor.set_property(Vm=v_init) decor.paint('"soma"', cell.parameters['mechanism']) if gid==0: ic = arbor.iclamp( nl_network.parameters['input_del'], nl_network.parameters['input_dur'], nl_network.parameters['input_amp']) print_v("Stim: %s"%ic) decor.place('"center"', ic) decor.place('"center"', arbor.spike_detector(-10)) # (2) Mark location for synapse at the midpoint of branch 1 (the first dendrite). labels['synapse_site'] = '(location 0 0.5)' # (4) Attach a single synapse. decor.place('"synapse_site"', 'expsyn') default_cell = arbor.cable_cell(default_tree, labels, decor) print_v("Created a new cell for gid %i: %s"%(gid,cell)) print_v("%s"%(default_cell)) return default_cell
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 in [0, 1] 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({ 'cell': '(tag 1)', 'gj_site': '(location 0 0.5)' }) decor = arbor.decor() decor.set_property(Vm=self.Vms[gid]) decor.set_property(cm=self.cm) decor.set_property(rL=self.rL) # add a gap junction mechanism at the "gj_site" location and label that specific mechanism on that location "gj_label" junction_mech = arbor.junction('gj', {"g": self.gj_g}) decor.place('"gj_site"', junction_mech, 'gj_label') decor.paint('"cell"', arbor.density(f'pas/e={self.Vms[gid]}', {'g': self.g})) if self.cv_policy_max_extent is not None: policy = arbor.cv_policy_max_extent(self.cv_policy_max_extent) decor.discretization(policy) else: decor.discretization(arbor.cv_policy_single()) return arbor.cable_cell(tree, labels, decor)
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(), )
decor.place('"root"', arbor.iclamp(10, 1, current=2), "iclamp0") decor.place('"root"', arbor.iclamp(30, 1, current=2), "iclamp1") decor.place('"root"', arbor.iclamp(50, 1, current=2), "iclamp2") decor.place('"axon_terminal"', arbor.spike_detector(-10), "detector") # Set cv_policy soma_policy = arbor.cv_policy_single('"soma"') dflt_policy = arbor.cv_policy_max_extent(1.0) policy = dflt_policy | soma_policy decor.discretization(policy) # Create a cell cell = arbor.cable_cell(morph, labels, decor) # (2) Declare a probe. probe = arbor.cable_probe_membrane_voltage('"custom_terminal"') # (3) Create a recipe class and instantiate a recipe class single_recipe(arbor.recipe): 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
import arbor # Create a sample tree with a single sample of radius 3 μm tree = arbor.sample_tree() tree.append(arbor.msample(x=0, y=0, z=0, radius=3, tag=2)) 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:
# Associate labels to tags labels = arbor.label_dict() labels['soma'] = '(tag 0)' labels['axon'] = '(tag 1)' labels['dend_2'] = '(tag 2)' labels['neur_3'] = '(tag 3)' labels['neur_4'] = '(tag 4)' labels['center'] = '(location 0 0.5)' # create dd1 morphology morph = arbor.morphology(tree) # create cell 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")
import utils, arbor as arb # !\circled{1}! read in geometry segment_tree = arb.load_swc_allen('cell.swc', no_gaps=False) morphology = arb.morphology(segment_tree) # !\circled{2}! assign names to regions defined by SWC and center of soma 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)
arbor.mpoint(-3, 0, 0, 3), arbor.mpoint(3, 0, 0, 3), tag=1) # (2) Define the soma and its midpoint labels = arbor.label_dict({'soma': '(tag 1)', 'midpoint': '(location 0 0.5)'}) # (3) Create cell and set properties decor = arbor.decor() decor.set_property(Vm=-40) decor.paint('"soma"', 'hh') decor.place('"midpoint"', arbor.iclamp(10, 2, 0.8)) decor.place('"midpoint"', arbor.spike_detector(-10)) # (4) Create cell and the single cell model based on it cell = arbor.cable_cell(tree, labels, decor) # (5) Make single cell model. m = arbor.single_cell_model(cell) # (6) Attach voltage probe sampling at 10 kHz (every 0.1 ms). m.probe('voltage', '"midpoint"', frequency=10000) # (7) Run simulation for 30 ms of simulated activity. m.run(tfinal=30) # (8) Print spike times. if len(m.spikes) > 0: print('{} spikes:'.format(len(m.spikes))) for s in m.spikes: print('{:3.3f}'.format(s))
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) # number of CVs per branch policy = arbor.cv_policy_fixed_per_branch(nseg) decor.discretization(policy) # create cell and set properties cell = arbor.cable_cell(morphology, labels, decor) # create single cell model model = arbor.single_cell_model(cell) # instantiate recipe with cell recipe = Recipe(cell) # instantiate simulation context = arbor.context() domains = arbor.partition_load_balance(recipe, context) sim = arbor.simulation(recipe, domains, context) # set up sampling on probes schedule = arbor.regular_schedule(0.1) v_handle = sim.sample(recipe.vprobe_id, schedule, arbor.sampling_policy.exact)
'uniform0': '(uniform (tag 3) 0 9 0)', 'uniform1': '(uniform (tag 3) 0 9 1)', 'branchmid': '(on-branches 0.5)', 'distal': '(distal (region "rad36"))', 'proximal':'(proximal (region "rad36"))', 'distint_in': '(sum (location 1 0.5) (location 2 0.7) (location 5 0.1))', 'proxint_in': '(sum (location 1 0.8) (location 2 0.3))', 'loctest' : '(distal (complete (join (branch 1) (branch 0))))', 'restrict': '(restrict (terminal) (tag 3))', } labels = {**regions, **locsets} d = arbor.label_dict(labels) # Create a cell to concretise the region and locset definitions cell = arbor.cable_cell(label_morph, d, arbor.decor()) ############################################################################### # Tutorial Example: single_cell_detailed ############################################################################### tree = arbor.segment_tree() tree.append(mnpos, mpoint(0, 0.0, 0, 2.0), mpoint( 4, 0.0, 0, 2.0), tag=1) tree.append(0, mpoint(4, 0.0, 0, 0.8), mpoint( 8, 0.0, 0, 0.8), tag=3) tree.append(1, mpoint(8, 0.0, 0, 0.8), mpoint(12, -0.5, 0, 0.8), tag=3) tree.append(2, mpoint(12, -0.5, 0, 0.8), mpoint(20, 4.0, 0, 0.4), tag=3) tree.append(3, mpoint(20, 4.0, 0, 0.4), mpoint(26, 6.0, 0, 0.2), tag=3) tree.append(2, mpoint(12, -0.5, 0, 0.5), mpoint(19, -3.0, 0, 0.5), tag=3) tree.append(5, mpoint(19, -3.0, 0, 0.5), mpoint(24, -7.0, 0, 0.2), tag=4) tree.append(5, mpoint(19, -3.0, 0, 0.5), mpoint(23, -1.0, 0, 0.2), tag=4) tree.append(7, mpoint(23, -1.0, 0, 0.2), mpoint(36, -2.0, 0, 0.2), tag=4)
'uniform0': '(uniform (tag 3) 0 9 0)', 'uniform1': '(uniform (tag 3) 0 9 1)', 'branchmid': '(on-branches 0.5)', 'distal': '(distal (region "rad36"))', 'proximal': '(proximal (region "rad36"))', 'distint_in': '(sum (location 1 0.5) (location 2 0.7) (location 5 0.1))', 'proxint_in': '(sum (location 1 0.8) (location 2 0.3))', 'loctest': '(distal (complete (join (branch 1) (branch 0))))', 'restrict': '(restrict (terminal) (tag 3))', } labels = {**regions, **locsets} d = arbor.label_dict(labels) # Create a cell to concretise the region and locset definitions cell = arbor.cable_cell(label_morph, d, arbor.decor()) ############################################################################### # Tutorial Example ############################################################################### tree = arbor.segment_tree() tree.append(mnpos, mpoint(0, 0.0, 0, 2.0), mpoint(4, 0.0, 0, 2.0), tag=1) tree.append(0, mpoint(4, 0.0, 0, 0.8), mpoint(8, 0.0, 0, 0.8), tag=3) tree.append(1, mpoint(8, 0.0, 0, 0.8), mpoint(12, -0.5, 0, 0.8), tag=3) tree.append(2, mpoint(12, -0.5, 0, 0.8), mpoint(20, 4.0, 0, 0.4), tag=3) tree.append(3, mpoint(20, 4.0, 0, 0.4), mpoint(26, 6.0, 0, 0.2), tag=3) tree.append(2, mpoint(12, -0.5, 0, 0.5), mpoint(19, -3.0, 0, 0.5), tag=3) tree.append(5, mpoint(19, -3.0, 0, 0.5), mpoint(24, -7.0, 0, 0.2), tag=4) tree.append(5, mpoint(19, -3.0, 0, 0.5), mpoint(23, -1.0, 0, 0.2), tag=4) tree.append(7, mpoint(23, -1.0, 0, 0.2), mpoint(36, -2.0, 0, 0.2), tag=4)
'uniform0': '(uniform (tag 3) 0 9 0)', 'uniform1': '(uniform (tag 3) 0 9 1)', 'branchmid': '(on-branches 0.5)', 'distal': '(distal (region "rad36"))', 'proximal': '(proximal (region "rad36"))', 'distint_in': '(sum (location 1 0.5) (location 2 0.7) (location 5 0.1))', 'proxint_in': '(sum (location 1 0.8) (location 2 0.3))', 'loctest': '(distal (complete (join (branch 1) (branch 0))))', 'restrict': '(restrict (terminal) (tag 3))', } labels = {**regions, **locsets} d = arbor.label_dict(labels) # Create a cell to concretise the region and locset definitions cell = arbor.cable_cell(label_morph, d) ################################################################################ # Output all of the morphologies and reion/locset definitions to a Python script # that can be run during the documentation build to generate images. ################################################################################ f = open('inputs.py', 'w') f.write('import representation\n') f.write('from representation import Segment\n') f.write('\n############# morphologies\n\n') f.write(write_morphology('label_morph', label_morph)) f.write(write_morphology('detached_morph', detached_morph)) f.write(write_morphology('stacked_morph', stacked_morph)) f.write(write_morphology('sphere_morph', sphere_morph)) f.write(write_morphology('branch_morph1', branch_morph1))
def create_arbor_cell(self, cell, gid, pop_id, index): if cell.arbor_cell == "cable_cell": default_tree = arbor.segment_tree() radius = (evaluate(cell.parameters["radius"], self.nl_network.parameters) if "radius" in cell.parameters else 3) default_tree.append( arbor.mnpos, arbor.mpoint(-1 * radius, 0, 0, radius), arbor.mpoint(radius, 0, 0, radius), tag=1, ) labels = arbor.label_dict({ "soma": "(tag 1)", "center": "(location 0 0.5)" }) labels["root"] = "(root)" decor = arbor.decor() v_init = (evaluate(cell.parameters["v_init"], self.nl_network.parameters) if "v_init" in cell.parameters else -70) decor.set_property(Vm=v_init) decor.paint('"soma"', arbor.density(cell.parameters["mechanism"])) decor.place('"center"', arbor.spike_detector(0), "detector") for ip in self.input_info: if self.input_info[ip][0] == pop_id: print_v("Stim: %s (%s) being placed on %s" % (ip, self.input_info[ip], pop_id)) for il in self.input_lists[ip]: cellId, segId, fract, weight = il if cellId == index: if self.input_info[ip][ 1] == 'i_clamp': # TODO: remove hardcoding of this... ic = arbor.iclamp( self.nl_network.parameters["input_del"], self.nl_network.parameters["input_dur"], self.nl_network.parameters["input_amp"], ) print_v("Stim: %s on %s" % (ic, gid)) decor.place('"center"', ic, "iclamp") # (2) Mark location for synapse at the midpoint of branch 1 (the first dendrite). labels["synapse_site"] = "(location 0 0.5)" # (4) Attach a single synapse. decor.place('"synapse_site"', arbor.synapse("expsyn"), "syn") default_cell = arbor.cable_cell(default_tree, labels, decor) print_v("Created a new cell for gid %i: %s" % (gid, cell)) print_v("%s" % (default_cell)) return default_cell
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