Package: bmtool
bmtoolA collection of modules to make developingNeuronandBMTKmodels easier.Table of ContentsGetting StartedCLISingle CellConnectorsBmplotGetting StartedInstallationpipinstallbmtoolFor developers who will be pulling down additional updates to this repository regularly use the following instead.gitclonehttps://github.com/cyneuro/bmtool.gitcdbmtool
pythonsetup.pydevelopThen download updates (from this directory) withgitpullCLIMany of modules available can be accesed using the command line>cdyour_bmtk_model_directory
>bmtool
Usage:bmtool[OPTIONS]COMMAND[ARGS]...

Options:--verboseVerboseprinting--helpShowthismessageandexit.

Commands:debugplotutil

>>bmtoolplotUsage:bmtoolplot[OPTIONS]COMMAND[ARGS]...

Options:--configPATHConfigurationfiletouse,default:"simulation_config.json"--no-displayWhensettherewillbenoplotdisplayed,usefulforsavingplots--helpShowthismessageandexit.

Commands:connectionDisplayinformationrelatedtoneuronconnectionspositionsPlotcellpositionsforagivensetofpopulationsrasterPlotthespikerasterforagivenpopulationreportPlotthespecifiedreportusingBMTK'sdefaultreportplotter
>Single Cell ModulePassive propertiesCurrent injectionFI curveZAPTunerVHalf SegregationThe single cell module can take any neuron HOC object and calculate passive properties, run a current clamp, calculate FI curve, or run a ZAP. The module is designed to work with HOC template files and can also turn Allen database SWC and json files into HOC objects and use those. The examples below uses "Cell_Cf" which is the name of a HOC templated loaded by the profiler.First step is it initialize the profiler.frombmtool.singlecellimportProfilerprofiler=Profiler(template_dir='templates',mechanism_dir='mechanisms',dt=0.1)Can provide any single cell module with either name of Hoc template or a HOC object. If you are wanted to use Allen database SWC and json files you can use the following functionfrombmtool.singlecellimportload_allen_database_cellscell=load_allen_database_cells(path_to_SWC_file,path_to_json_file)Passive propertiesCalculates the passive properties(V-rest, Rin and tau) of a HOC objectfrombmtool.singlecellimportPassive,run_and_plotimportmatplotlib.pyplotaspltsim=Passive('Cell_Cf',inj_amp=-100.,inj_delay=1500.,inj_dur=1000.,tstop=2500.,method='exp2')title='Passive Cell Current Injection'xlabel='Time (ms)'ylabel='Membrane Potential (mV)'X,Y=run_and_plot(sim,title,xlabel,ylabel,plot_injection_only=True)plt.gca().plot(*sim.double_exponential_fit(),'r:',label='double exponential fit')plt.legend()plt.show()Injection location: Cell_Cf[0].soma[0](0.5)
Recording: Cell_Cf[0].soma[0](0.5)._ref_v
Running simulation for passive properties...

V Rest: -70.21 (mV)
Resistance: 128.67 (MOhms)
Membrane time constant: 55.29 (ms)

V_rest Calculation: Voltage taken at time 1500.0 (ms) is
-70.21 (mV)

R_in Calculation: dV/dI = (v_final-v_rest)/(i_final-i_start)
(-83.08 - (-70.21)) / (-0.1 - 0)
12.87 (mV) / 0.1 (nA) = 128.67 (MOhms)

Tau Calculation: Fit a double exponential curve to the membrane potential response
f(t) = a0 + a1*exp(-t/tau1) + a2*exp(-t/tau2)
Constained by initial value: f(0) = a0 + a1 + a2 = v_rest
Fit parameters: (a0, a1, a2, tau1, tau2) = (-83.06, -3306.48, 3319.33, 55.29, 55.15)
Membrane time constant is determined from the slowest exponential term: 55.29 (ms)

Sag potential: v_sag = v_peak - v_final = -0.66 (mV)
Normalized sag potential: v_sag / (v_peak - v_rest) = 0.049Current clampRuns a current clamp on a HOC objectfrombmtool.singlecellimportCurrentClampsim=CurrentClamp('Cell_Cf',inj_amp=350.,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()Injection location: Cell_Cf[1].soma[0](0.5)
Recording: Cell_Cf[1].soma[0](0.5)._ref_v
Current clamp simulation running...

Number of spikes: 19FI curveCalculates the frequency vs current injection plot for a HOC objectfrombmtool.singlecellimportFIsim=FI('Cell_Cf',i_start=0.,i_stop=1000.,i_increment=50.,tstart=1500.,threshold=-15.)X,Y=run_and_plot(sim,title='FI Curve',xlabel='Injection (nA)',ylabel='# Spikes')plt.show()Injection location: Cell_Cf[21].soma[0](0.5)
Recording: Cell_Cf[21].soma[0](0.5)._ref_v
Running simulations for FI curve...

Results
Injection (nA): 0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95
Number of spikes: 0, 1, 10, 12, 15, 16, 17, 19, 20, 20, 21, 21, 22, 23, 23, 24, 25, 25, 26, 27ZAPRuns a ZAP on a HOC objectfrombmtool.singlecellimportZAPsim=ZAP('Cell_Cf')X,Y=run_and_plot(sim)plt.show()Injection location: Cell_Cf[23].soma[0](0.5)
Recording: Cell_Cf[23].soma[0](0.5)._ref_v
ZAP current simulation running...

Chirp current injection with frequency changing from 0 to 15 Hz over 15 seconds
Impedance is calculated as the ratio of FFT amplitude of membrane voltage to FFT amplitude of chirp currentSingle Cell TuningFrom a BMTK Model directory containing asimulation_config.jsonfile:bmtoolutilcelltune--builderFor non-BMTK cell tuning:bmtoolutilcell--templateTemplateFile.hoc--mod-folder./tune--builderVHalf Segregation ModuleBased on the Alturki et al. (2016) paper.Segregate your channel activation for an easier time tuning your cells.>bmtoolutilcellvhseg--help

Usage:bmtoolutilcellvhseg[OPTIONS]Alturkietal.(2016)V1/2AutomatedSegregationInterface,simplifytuningbyseparatingchannelactivation

Options:--titleTEXT--tstopINTEGER--outhocTEXTSpecifythefileyouwantthemodifiedcelltemplatewrittento--outfolderTEXTSpecifythedirectoryyouwantthemodifiedcelltemplateandmodfileswrittento(default:_seg)--outappendAppendoutinsteadofoverwriting(default:False)--debugPrintalldebugstatements--fminpaINTEGERStartingFICurveamps(default:0)--fmaxpaINTEGEREndingFICurveamps(default:1000)--fincrementINTEGERIncrementtheFICurveampsbysuppliedpA(default:100)--infvarsTEXTSpecifytheinfvariablestoplot,skipsthewizard.(Commaseparated,eg:inf_mech,minf_mech2,ninf_mech2)--segvarsTEXTSpecifythesegregationvariablestogloballyset,skipsthewizard.(Commaseparated,eg:mseg_mech,nseg_mech2)--eleakTEXTSpecifytheeleakvarmanually--gleakTEXTSpecifythegleakvarmanually--othersecTEXTSpecifyothersectionsthatawindowshouldbegeneratedfor(Commaseparated,eg:dend[0],dend[1])--helpShowthismessageandexit.ExamplesWizard Mode (Interactive)>bmtoolutilcellvhseg

?Selectacell:CA3PyramidalCell
Usingsectiondend[0]?Showothersections?(default:No)Yes
?Selectothersections(spacebartoselect):done(2selections)?Selectinfvariablestoplot(spacebartoselect):done(5selections)?Selectsegregationvariables[ORVARIABLESYOUWANTTOCHANGEONALLSEGMENTSatthesametime](spacebartoselect):done(2selections)Command Mode (Non-interactive)bmtoolutilcell--templateCA3PyramidalCellvhseg--othersecdend[0],dend[1]--infvarsinf_im--segvarsgbar_im--gleakgl_ichan2CA3--eleakel_ichan2CA3Example:Simple models can utilizebmtoolutilcell--hoccell_template.hocvhsegbuild--build
bmtoolutilcell--hocsegmented_template.hocvhsegbuildex:https://github.com/tjbanks/two-cell-hcoConnectors ModuleUnidirectionConnectorReciprocalConnectorCorrelatedGapJunctionOneToOneSequentialConnectorThis module contains helper functions and classes that work with BMTK's NetworkBuilder module in building networks. It facilitates building reciprocal connections, distance dependent connections, afferent connections, etc. See documentation inside the scriptconnectors.pyfor more notes on usage.All connector example below use the following network node structurefrombmtk.builderimportNetworkBuildernet=NetworkBuilder('example_net')net.add_nodes(N=100,pop_name='PopA',model_type='biophysical')net.add_nodes(N=100,pop_name='PopB',model_type='biophysical')background=NetworkBuilder('background')background.add_nodes(N=300,pop_name='tON',potential='exc',model_type='virtual')Unidirectional connector - unidirectional connections in bmtk network model with given probability within a single population (or between two populations)frombmtool.connectorsimportUnidirectionConnectorconnector=UnidirectionConnector(p=0.15,n_syn=1)connector.setup_nodes(source=net.nodes(pop_name='PopA'),target=net.nodes(pop_name='PopB'))net.add_edges(**connector.edge_params())Recipical connector - buiilding connections in bmtk network model with reciprocal probability within a single population (or between two populationsfrombmtool.connectorsimportReciprocalConnectorconnector=ReciprocalConnector(p0=0.15,pr=0.06767705087,n_syn0=1,n_syn1=1,estimate_rho=False)connector.setup_nodes(source=net.nodes(pop_name='PopA'),target=net.nodes(pop_name='PopA'))net.add_edges(**connector.edge_params())CorrelatedGapJunctionfrombmtool.connectorsimportReciprocalConnector,CorrelatedGapJunctionconnector=ReciprocalConnector(p0=0.15,pr=0.06,n_syn0=1,n_syn1=1,estimate_rho=False)connector.setup_nodes(source=net.nodes(pop_name='PopA'),target=net.nodes(pop_name='PopA'))net.add_edges(**connector.edge_params())gap_junc=CorrelatedGapJunction(p_non=0.1228,p_uni=0.56,p_rec=1,connector=connector)gap_junc.setup_nodes(source=net.nodes(pop_name='PopA'),target=net.nodes(pop_name='PopA'))conn=net.add_edges(is_gap_junction=True,syn_weight=0.0000495,target_sections=None,afferent_section_id=0,afferent_section_pos=0.5,**gap_junc.edge_params())OneToOneSequentialConnectorfrombmtool.connectorsimportOneToOneSequentialConnectorconnector=OneToOneSequentialConnector()connector.setup_nodes(source=background.nodes(),target=net.nodes(pop_name='PopA'))net.add_edges(**connector.edge_params())connector.setup_nodes(target=net.nodes(pop_name='PopB'))net.add_edges(**connector.edge_params())Bmplot ModuleTotal connectionsPercent connectionsConvergence connnectionsDivergence connectionsconnection histogramprobability connection3D location3D rotationTotal connection plotGenerates a table of total number of connections each neuron population recievesfrombmtoolimportbmplotbmplot.total_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True)Percent connection plotGenerates a table of the percent connectivity of neuron populations.Method can change if you want the table to be total percent connectivity or only unidirectional connectivity or only bi directional connectvitybmplot.percent_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,method='total')Convergence plotGenerates a table of the mean convergence of neuron populations. Method can be changed to show max,and min convergence a cell recieves and also changed to show standard deviation of convergencebmplot.convergence_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True)Divergence plotGenerates a table of the mean divergence of neuron populations. Method can be changed to show max,and min divergence a cell recieves and also changed to show standard deviation of divergencebmplot.divergence_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name')![png]readme_figures/(output_25_0.png)Connection histogramGenerates a histogram of the distribution of connections a population of cells give to individual cells of another populationbmplot.connection_histogram(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',source_cell='PNa',target_cell='PV')probability of connection plotthis function needs some workbmplot.probability_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,line_plot=True)3D position plotGenerates a plot of cells positions in 3D spacebmplot.plot_3d_positions(config='config.json',populations_list='LA',group_by='pop_name',save_file=False)cell rotationsGenerates a plot of cells location in 3D plot and also the cells rotationbmplot.cell_rotation_3d(config='config2.json',populations_list='all',group_by='pop_name',save_file=False,quiver_length=20,arrow_length_ratio=0.25,max_cells=100)