Created
June 2, 2021 11:44
-
-
Save Helveg/1a7221f3150ad96d10ae78272278a3b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arbor, dbbs_models | |
from patch import p | |
# cell = arbor.cable_cell(morph.morphology, labels, decor) | |
model = dbbs_models.StellateCell | |
cell = model.cable_cell() | |
neuron_cell = model() | |
print(neuron_cell.soma) | |
neuron_cell.record_soma() | |
neuron_time = p.time | |
p.celsius = 32 | |
p.finitialize(-40) | |
p.continuerun(100) | |
# (4) Define a recipe for a single cell and set of probes upon it. | |
# This constitutes the corresponding generic recipe version of | |
# `single_cell_model.py`. | |
class single_recipe(arbor.recipe): | |
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.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.set_ion(ion='h', valence=1, int_con=5e-5, ext_con=2, rev_pot=-34) | |
self.the_cat = arbor.default_catalogue() | |
self.the_cat.extend(arbor.dbbs_catalogue(), "") | |
self.the_props.register(self.the_cat) | |
def num_cells(self): | |
# (4.2) Override the num_cells method | |
return 31000 | |
def num_sources(self, gid): | |
# (4.3) Override the num_sources method | |
return 0 | |
def cell_kind(self, gid): | |
# (4.4) Override the cell_kind method | |
return arbor.cell_kind.cable | |
def cell_description(self, gid): | |
# (4.5) Override the cell_description method | |
return self.the_cell | |
def probes(self, gid): | |
# (4.6) Override the probes method | |
return self.the_probes | |
def global_properties(self, kind): | |
# (4.7) Override the global_properties method | |
return self.the_props | |
# (6) Create a default execution context and a default domain decomposition. | |
probe = arbor.cable_probe_membrane_voltage('(proximal (tag 1))') | |
recipe = single_recipe(cell, [probe]) | |
context = arbor.context() | |
domains = arbor.partition_load_balance(recipe, context) | |
# (7) Create and run simulation and set up 10 kHz (every 0.1 ms) sampling on the probe. | |
# The probe is located on cell 0, and is the 0th probe on that cell, thus has probe_id (0, 0). | |
sim = arbor.simulation(recipe, domains, context) | |
sim.record(arbor.spike_recording.all) | |
handle = sim.sample((0, 0), arbor.regular_schedule(0.1)) | |
sim.run(tfinal=100) | |
spikes = sim.spikes() | |
data, meta = sim.samples(handle)[0] | |
if len(spikes)>0: | |
print('{} spikes:'.format(len(spikes))) | |
for t in spikes['time']: | |
print('{:3.3f}'.format(t)) | |
else: | |
print('no spikes') | |
# (9) Plot the recorded voltages over time. | |
import plotly.graph_objs as go # You may have to pip install these. | |
go.Figure( | |
[ | |
go.Scatter(x=data[:, 0], y=data[:, 1], name="arbor"), | |
go.Scatter(x=list(neuron_time), y=list(neuron_cell.Vm), name="neuron"), | |
] | |
).show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment