InĀ [3]:
Copied!
import glob
import os
download_from_allen = True
if download_from_allen:
from allensdk.api.queries.biophysical_api import BiophysicalApi
bp = BiophysicalApi()
bp.cache_stimulus = False
neuronal_model_id = 472451419
bp.cache_data(neuronal_model_id)
working_dir = os.getcwd()
json_files = glob.glob(os.path.join(working_dir, "*fit*.json"))
swc_files = glob.glob(os.path.join(working_dir, "*.swc"))
dynamic_params = json_files[0]
morphology = swc_files[0]
print(dynamic_params)
print(morphology)
import glob
import os
download_from_allen = True
if download_from_allen:
from allensdk.api.queries.biophysical_api import BiophysicalApi
bp = BiophysicalApi()
bp.cache_stimulus = False
neuronal_model_id = 472451419
bp.cache_data(neuronal_model_id)
working_dir = os.getcwd()
json_files = glob.glob(os.path.join(working_dir, "*fit*.json"))
swc_files = glob.glob(os.path.join(working_dir, "*.swc"))
dynamic_params = json_files[0]
morphology = swc_files[0]
print(dynamic_params)
print(morphology)
2025-09-24 15:18:42,872 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/491459173 2025-09-24 15:18:47,032 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/496607103 2025-09-24 15:18:47,285 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/395337293 2025-09-24 15:18:47,474 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/395337054 2025-09-24 15:18:47,649 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/395337225 2025-09-24 15:18:47,783 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/395337019 2025-09-24 15:18:47,966 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/395337003 2025-09-24 15:18:48,186 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/395337050 2025-09-24 15:18:48,327 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/395337042 2025-09-24 15:18:48,508 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/395337011 2025-09-24 15:18:48,649 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/395337046 2025-09-24 15:18:48,788 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/395337015 2025-09-24 15:18:49,008 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/395337066 2025-09-24 15:18:49,206 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/464138096 2025-09-24 15:18:49,386 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/395337007 2025-09-24 15:18:49,566 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/395337062 2025-09-24 15:18:49,732 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/491113425 2025-09-24 15:18:49,866 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/395337070 2025-09-24 15:18:50,004 allensdk.api.api.retrieve_file_over_http INFO Downloading URL: http://api.brain-map.org/api/v2/well_known_file_download/497235805
/home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/386049446_fit.json /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/Nr5a1-Cre_Ai14-177334.05.01.01_491459171_m.swc
InĀ [4]:
Copied!
# if already compiled then lets delete the folder and force a recompile
if os.path.isdir('x86_64'):
os.system("rm -rf x86_64")
# compile the mod files
if not os.path.isdir("x86_64"):
os.system("nrnivmodl modfiles")
# if already compiled then lets delete the folder and force a recompile
if os.path.isdir('x86_64'):
os.system("rm -rf x86_64")
# compile the mod files
if not os.path.isdir("x86_64"):
os.system("nrnivmodl modfiles")
/home/gjgpb9/miniconda3/envs/bmtk/bin/nrnivmodl:10: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html from pkg_resources import working_set Translating CaDynamics.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/CaDynamics.c Translating Ca_HVA.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/Ca_HVA.c Translating Ca_LVA.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/Ca_LVA.c Thread Safe Thread Safe Thread Safe
/home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial Mod files: "modfiles/modfiles/CaDynamics.mod" "modfiles/modfiles/Ca_HVA.mod" "modfiles/modfiles/Ca_LVA.mod" "modfiles/modfiles/Ih.mod" "modfiles/modfiles/Im.mod" "modfiles/modfiles/Im_v2.mod" "modfiles/modfiles/Kd.mod" "modfiles/modfiles/K_P.mod" "modfiles/modfiles/K_T.mod" "modfiles/modfiles/Kv2like.mod" "modfiles/modfiles/Kv3_1.mod" "modfiles/modfiles/Nap.mod" "modfiles/modfiles/NaTa.mod" "modfiles/modfiles/NaTs.mod" "modfiles/modfiles/NaV.mod" "modfiles/modfiles/SK.mod" Creating 'x86_64' directory for .o files. -> Compiling mod_func.cpp -> NMODL ../modfiles/CaDynamics.mod -> NMODL ../modfiles/Ca_LVA.mod -> NMODL ../modfiles/Ca_HVA.mod -> NMODL ../modfiles/Ih.mod -> NMODL ../modfiles/Im.mod -> NMODL ../modfiles/Im_v2.mod -> NMODL ../modfiles/Kd.mod -> NMODL ../modfiles/K_P.mod -> NMODL ../modfiles/K_T.mod -> NMODL ../modfiles/Kv2like.mod -> NMODL ../modfiles/Kv3_1.mod -> NMODL ../modfiles/Nap.mod -> NMODL ../modfiles/NaTa.mod -> NMODL ../modfiles/NaTs.mod -> NMODL ../modfiles/NaV.mod -> NMODL ../modfiles/SK.mod -> Compiling CaDynamics.c -> Compiling Ca_HVA.c -> Compiling Ca_LVA.c -> Compiling Ih.c -> Compiling Im.c -> Compiling Im_v2.c -> Compiling Kd.c
Translating Ih.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/Ih.c Thread Safe Translating Im.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/Im.c Translating Im_v2.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/Im_v2.c Thread Safe Thread Safe Translating Kd.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/Kd.c Thread Safe Translating K_P.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/K_P.c Translating K_T.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/K_T.c Thread Safe Thread Safe Translating Kv2like.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/Kv2like.c Thread Safe Translating Kv3_1.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/Kv3_1.c Translating Nap.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/Nap.c Thread Safe Thread Safe Translating NaTa.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/NaTa.c Translating NaTs.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/NaTs.c Thread Safe Translating NaV.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/NaV.c Thread Safe NEURON's CVode method ignores conservation Notice: LINEAR is not thread safe. Translating SK.mod into /home/gjgpb9/cortex_modeling/bmtool/docs/examples/notebooks/single_cell/Allen_tutorial/x86_64/SK.c Thread Safe
-> Compiling K_P.c -> Compiling K_T.c -> Compiling Kv2like.c -> Compiling Kv3_1.c -> Compiling Nap.c -> Compiling NaTa.c -> Compiling NaTs.c -> Compiling NaV.c -> Compiling SK.c => LINKING shared library ./libnrnmech.so => LINKING executable ./special LDFLAGS are: -pthread Successfully created x86_64/special
There may be some warnings from the logger that I don't want to see so i will just turn them off. Comment this line out if you want to see the warnings
InĀ [5]:
Copied!
import logging
logging.disable(logging.WARNING)
import logging
logging.disable(logging.WARNING)
Load the Allen Database cell¶
To use the Allen cell with bmtool we need to use the load_allen_database_cells function. This will load the cell into a format that bmtool can use
InĀ [6]:
Copied!
import matplotlib.pyplot as plt
from bmtool.singlecell import CurrentClamp,run_and_plot,Profiler,load_allen_database_cells
cell_creater = load_allen_database_cells(morphology=morphology,
dynamic_params=dynamic_params,
model_processing='aibs_allactive')
import matplotlib.pyplot as plt
from bmtool.singlecell import CurrentClamp,run_and_plot,Profiler,load_allen_database_cells
cell_creater = load_allen_database_cells(morphology=morphology,
dynamic_params=dynamic_params,
model_processing='aibs_allactive')
Warning: no DISPLAY environment variable. --No graphics will be displayed.
Now we can use this cell_creater in a similar way to the cell template name in the Neuron_hoc tutorial.
InĀ [7]:
Copied!
profiler = Profiler(template_dir='.', mechanism_dir = 'modfiles', dt=0.1)
sim = CurrentClamp(cell_creater, inj_amp=500., inj_delay=1500., inj_dur=1000., tstop=3000., threshold=-15.)
X, Y = run_and_plot(sim, title='Current Injection', xlabel='Time (ms)',
ylabel='Membrane Potential (mV)', plot_injection_only=True)
plt.show()
profiler = Profiler(template_dir='.', mechanism_dir = 'modfiles', dt=0.1)
sim = CurrentClamp(cell_creater, inj_amp=500., inj_delay=1500., inj_dur=1000., tstop=3000., threshold=-15.)
X, Y = run_and_plot(sim, title='Current Injection', xlabel='Time (ms)',
ylabel='Membrane Potential (mV)', plot_injection_only=True)
plt.show()
NEURON mechanisms not found in modfiles. Injection location: Biophys1[0].soma[0](0.5) Recording: Biophys1[0].soma[0](0.5)._ref_v Current clamp simulation running... Number of spikes: 15
InĀ [8]:
Copied!
from bmtool.singlecell import FI
sim = FI(cell_creater,tdur=1000,i_increment=50)
X, Y = run_and_plot(sim,xlabel='Current',ylabel="Spikes")
plt.show()
from bmtool.singlecell import FI
sim = FI(cell_creater,tdur=1000,i_increment=50)
X, Y = run_and_plot(sim,xlabel='Current',ylabel="Spikes")
plt.show()
Injection location: Biophys1[21].soma[0](0.5) Recording: Biophys1[21].soma[0](0.5)._ref_v Running simulations for FI curve... Results Injection (nA): number of spikes 0 0.00 0 1 0.05 0 2 0.10 2 3 0.15 6 4 0.20 9 5 0.25 11 6 0.30 12 7 0.35 13 8 0.40 14 9 0.45 14 10 0.50 15 11 0.55 15 12 0.60 15 13 0.65 15 14 0.70 5 15 0.75 4 16 0.80 3 17 0.85 3 18 0.90 2 19 0.95 2 20 1.00 2