bmtool


Namebmtool JSON
Version 0.5.2 PyPI version JSON
download
home_pagehttps://github.com/cyneuro/bmtool
SummaryBMTool
upload_time2024-03-05 19:27:17
maintainer
docs_urlNone
authorTyler Banks
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # bmtool
A collection of modules to make developing [Neuron](https://www.neuron.yale.edu/neuron/) and [BMTK](https://alleninstitute.github.io/bmtk/) models easier.

[![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/cyneuro/bmtool/blob/master/LICENSE) 

## Table of Contents
- [Getting Started](#Getting-Started)
- [CLI](#CLI)
- [Single Cell](#Single-Cell-Module)
- [Connectors](#Connectors-Module)
- [Bmplot](#bmplot-Module)

## Getting Started

**Installation**
```bash
pip install bmtool
```
For developers who will be pulling down additional updates to this repository regularly use the following instead.
```bash
git clone https://github.com/cyneuro/bmtool.git
cd bmtool
python setup.py develop
```
Then download updates (from this directory) with
```bash
git pull
```

## CLI
#### Many of modules available can be accesed using the command line 
```bash
> cd your_bmtk_model_directory
> bmtool
Usage: bmtool [OPTIONS] COMMAND [ARGS]...

Options:
  --verbose  Verbose printing
  --help     Show this message and exit.

Commands:
  debug
  plot
  util

>  
> bmtool plot 
Usage: bmtool plot [OPTIONS] COMMAND [ARGS]...

Options:
  --config PATH  Configuration file to use, default: "simulation_config.json"
  --no-display   When set there will be no plot displayed, useful for saving
                 plots
  --help         Show this message and exit.

Commands:
  connection  Display information related to neuron connections
  positions   Plot cell positions for a given set of populations
  raster      Plot the spike raster for a given population
  report      Plot the specified report using BMTK's default report plotter
>
```

## Single Cell Module
- [Passive properties](#passive-properties)
- [Current injection](#current-clamp)
- [FI curve](#fi-curve)
- [ZAP](#zap)
- [Tuner](#single-cell-tuning)
- [VHalf Segregation](#vhalf-segregation-module)
#### The 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.


```python
from bmtool.singlecell import Profiler
profiler = 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 function


```python
from bmtool.singlecell import load_allen_database_cells
cell = load_allen_database_cells(path_to_SWC_file,path_to_json_file)
```

### Passive properties
#### Calculates the passive properties(V-rest, Rin and tau) of a HOC object


```python
from bmtool.singlecell import Passive,run_and_plot
import matplotlib.pyplot as plt
sim = 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.049
    



    
![png](readme_figures/output_8_1.png)
    


### Current clamp
#### Runs a current clamp on a HOC object


```python
from bmtool.singlecell import CurrentClamp
sim = 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: 19
    



    
![png](readme_figures/output_10_1.png)
    


### FI curve
#### Calculates the frequency vs current injection plot for a HOC object


```python
from bmtool.singlecell import FI
sim = 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, 27
    



    
![png](readme_figures/output_12_1.png)
    


### ZAP
#### Runs a ZAP on a HOC object


```python
from bmtool.singlecell import ZAP
sim = ZAP('Cell_Cf')
X, Y = run_and_plot(sim)
plt.show()
```

    Injection location: Cell_Cf[22].soma[0](0.5)
    Recording: Cell_Cf[22].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 current
    



    
![png](readme_figures/output_14_1.png)
    


### Single Cell Tuning

#### From a BMTK Model directory containing a `simulation_config.json` file:
```bash
bmtool util cell tune --builder
```

#### For non-BMTK cell tuning:
```bash
bmtool util cell --template TemplateFile.hoc --mod-folder ./ tune --builder
```
![bmtool](./figures/figure2.png "Tuning Figure")

### VHalf Segregation Module

#### Based on the Alturki et al. (2016) paper.

#### Segregate your channel activation for an easier time tuning your cells.


```bash
> bmtool util cell vhseg --help

Usage: bmtool util cell vhseg [OPTIONS]

  Alturki et al. (2016) V1/2 Automated Segregation Interface, simplify
  tuning by separating channel activation

Options:
  --title TEXT
  --tstop INTEGER
  --outhoc TEXT         Specify the file you want the modified cell template
                        written to
  --outfolder TEXT      Specify the directory you want the modified cell
                        template and mod files written to (default: _seg)
  --outappend           Append out instead of overwriting (default: False)
  --debug               Print all debug statements
  --fminpa INTEGER      Starting FI Curve amps (default: 0)
  --fmaxpa INTEGER      Ending FI Curve amps (default: 1000)
  --fincrement INTEGER  Increment the FI Curve amps by supplied pA (default:
                        100)
  --infvars TEXT        Specify the inf variables to plot, skips the wizard.
                        (Comma separated, eg: inf_mech,minf_mech2,ninf_mech2)
  --segvars TEXT        Specify the segregation variables to globally set,
                        skips the wizard. (Comma separated, eg:
                        mseg_mech,nseg_mech2)
  --eleak TEXT          Specify the eleak var manually
  --gleak TEXT          Specify the gleak var manually
  --othersec TEXT       Specify other sections that a window should be
                        generated for (Comma separated, eg: dend[0],dend[1])
  --help                Show this message and exit.

```

### Examples 

#### Wizard Mode (Interactive)

```bash
> bmtool util cell vhseg

? Select a cell:  CA3PyramidalCell
Using section dend[0]
? Show other sections? (default: No)  Yes
? Select other sections (space bar to select):  done (2 selections)
? Select inf variables to plot (space bar to select):   done (5 selections)
? Select segregation variables [OR VARIABLES YOU WANT TO CHANGE ON ALL SEGMENTS at the same time] (space bar to select):  done (2 selections)
```

#### Command Mode (Non-interactive)

```bash
bmtool util cell --template CA3PyramidalCell vhseg --othersec dend[0],dend[1] --infvars inf_im --segvars gbar_im --gleak gl_ichan2CA3 --eleak el_ichan2CA3
```

Example:

![bmtool](./figures/figure4.png "Seg Figure")

#### Simple models can utilize 
``` bash
bmtool util cell --hoc cell_template.hoc vhsegbuild --build
bmtool util cell --hoc segmented_template.hoc vhsegbuild
```
ex: [https://github.com/tjbanks/two-cell-hco](https://github.com/tjbanks/two-cell-hco)

### Connectors Module
- [UnidirectionConnector](#unidirectional-connector---unidirectional-connections-in-bmtk-network-model-with-given-probability-within-a-single-population-or-between-two-populations)
- [ReciprocalConnector](#recipical-connector---buiilding-connections-in-bmtk-network-model-with-reciprocal-probability-within-a-single-population-or-between-two-populations)
- [CorrelatedGapJunction](#correlatedgapjunction)
- [OneToOneSequentialConnector](#onetoonesequentialconnector)

#### This 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 script `connectors.py` for more notes on usage.

#### All connector example below use the following network node structure
```python
from bmtk.builder import NetworkBuilder
net = 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 - Object for building unidirectional connections in bmtk network model with given probability within a single population (or between two populations).
```python
from bmtool.connectors  import UnidirectionConnector
connector = 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 - Object for building connections in bmtk network model with reciprocal probability within a single population (or between two populations)
```python
from bmtool.connectors  import ReciprocalConnector
connector = 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())
```
#### CorrelatedGapJunction - Object for building gap junction connections in bmtk network model with given probabilities within a single population which could be correlated with the recurrent chemical synapses in this population.
```python
from bmtool.connectors import ReciprocalConnector, CorrelatedGapJunction
connector = 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())
```

#### OneToOneSequentialConnector - Object for building one to one correspondence connections in bmtk network model with between two populations. One of the population can consist of multiple sub-populations.
```python
from bmtool.connectors  import OneToOneSequentialConnector
connector = 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 Module
- [Total connections](#Total-connection-plot)
- [Percent connections](#Percent-connection-plot)
- [Convergence connnections](#convergence-plot)
- [Divergence connections](#divergence-plot)
- [connection histogram](#connection-histogram)
- [probability connection](#probability-of-connection-plot)
- [3D location](#3d-position-plot)
- [3D rotation](#cell-rotations)
- [Plot Connection Diagram](#plot-connection-diagram)

### Total connection plot
#### Generates a table of total number of connections each neuron population recieves


```python
from bmtool import bmplot
bmplot.total_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,include_gap=False)
```


    
![png](readme_figures/output_19_0.png)
    


### Percent connection plot
#### Generates a table of the percent connectivity of neuron populations.Method can change if you want the table to be total percent connectivity, only unidirectional connectivity or only bi directional connectvity 


```python
bmplot.percent_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,method='total',include_gap=False)
```


    
![png](readme_figures/output_21_0.png)
    


### Convergence plot
#### Generates a table of the mean convergence of neuron populations. Method can be changed to show max, min, mean, or std for convergence a cell recieves


```python
bmplot.convergence_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,include_gap=False,method='mean+std')
```


    
![png](readme_figures/output_23_0.png)
    


### Divergence plot
#### Generates a table of the mean divergence of neuron populations. Method can be changed to show max, min, mean or std divergence a cell recieves.


```python
bmplot.divergence_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,include_gap=False,method='mean+std')
```


    
![png](readme_figures/output_25_0.png)
    


### Connection histogram 
#### Generates a histogram of the distribution of connections a population of cells give to individual cells of another population 


```python
bmplot.connection_histogram(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',source_cell='PV',target_cell='PV',include_gap=False)
```


    
![png](readme_figures/output_27_0.png)
    


### probability of connection plot
#### this function needs some work


```python
bmplot.probability_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,line_plot=True)
```


    
![png](readme_figures/output_29_0.png)
    



    
![png](readme_figures/output_29_1.png)
    


### 3D position plot
#### Generates a plot of cells positions in 3D space 


```python
bmplot.plot_3d_positions(config='config.json',populations_list='LA',group_by='pop_name',save_file=False)
```


    
![png](readme_figures/output_31_0.png)
    


### cell rotations
#### Generates a plot of cells location in 3D plot and also the cells rotation


```python
bmplot.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)
```


    
![png](readme_figures/output_33_0.png)
    


### Plot Connection Diagram


```python
bmplot.plot_network_graph(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True)
```


    
![png](readme_figures/output_35_0.png)
    





```python
from bmtool import bmplot
bmplot.plot_basic_cell_info(config_file='config.json')
```

    Network and node info:
    LA:



<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>node_type</th>
      <th>pop_name</th>
      <th>model_type</th>
      <th>model_template</th>
      <th>morphology</th>
      <th>count</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>100</td>
      <td>PNa</td>
      <td>biophysical</td>
      <td>hoc:Cell_Af</td>
      <td>blank.swc</td>
      <td>800</td>
    </tr>
    <tr>
      <th>1</th>
      <td>101</td>
      <td>PNc</td>
      <td>biophysical</td>
      <td>hoc:Cell_Cf</td>
      <td>blank.swc</td>
      <td>800</td>
    </tr>
    <tr>
      <th>2</th>
      <td>102</td>
      <td>PV</td>
      <td>biophysical</td>
      <td>hoc:InterneuronCellf</td>
      <td>blank.swc</td>
      <td>240</td>
    </tr>
    <tr>
      <th>3</th>
      <td>103</td>
      <td>SOM</td>
      <td>biophysical</td>
      <td>hoc:LTS_Cell</td>
      <td>blank.swc</td>
      <td>160</td>
    </tr>
  </tbody>
</table>


    thalamus_pyr:



<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>node_type</th>
      <th>pop_name</th>
      <th>model_type</th>
      <th>count</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>100</td>
      <td>pyr_inp</td>
      <td>virtual</td>
      <td>1600</td>
    </tr>
  </tbody>
</table>


    thalamus_pv:



<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>node_type</th>
      <th>pop_name</th>
      <th>model_type</th>
      <th>count</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>100</td>
      <td>pv_inp</td>
      <td>virtual</td>
      <td>240</td>
    </tr>
  </tbody>
</table>


    thalamus_som:



<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>node_type</th>
      <th>pop_name</th>
      <th>model_type</th>
      <th>count</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>100</td>
      <td>som_inp</td>
      <td>virtual</td>
      <td>160</td>
    </tr>
  </tbody>
</table>


    tone:



<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>node_type</th>
      <th>pop_name</th>
      <th>model_type</th>
      <th>count</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>100</td>
      <td>tone</td>
      <td>virtual</td>
      <td>1840</td>
    </tr>
  </tbody>
</table>


    shock:



<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>node_type</th>
      <th>pop_name</th>
      <th>model_type</th>
      <th>count</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>100</td>
      <td>shock</td>
      <td>virtual</td>
      <td>400</td>
    </tr>
  </tbody>
</table>


    shell:



<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>node_type</th>
      <th>pop_name</th>
      <th>model_type</th>
      <th>count</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>100</td>
      <td>PNa</td>
      <td>virtual</td>
      <td>3975</td>
    </tr>
    <tr>
      <th>1</th>
      <td>101</td>
      <td>PNc</td>
      <td>virtual</td>
      <td>3975</td>
    </tr>
    <tr>
      <th>2</th>
      <td>102</td>
      <td>PV</td>
      <td>virtual</td>
      <td>1680</td>
    </tr>
    <tr>
      <th>3</th>
      <td>103</td>
      <td>SOM</td>
      <td>virtual</td>
      <td>1120</td>
    </tr>
  </tbody>
</table>





    'LA'



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cyneuro/bmtool",
    "name": "bmtool",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Tyler Banks",
    "author_email": "tbanks@mail.missouri.edu",
    "download_url": "https://files.pythonhosted.org/packages/3a/4c/a374e479b70d02c016dea58faf02a64bac793a3b427d974b9582d0b690fe/bmtool-0.5.2.tar.gz",
    "platform": null,
    "description": "# bmtool\nA collection of modules to make developing [Neuron](https://www.neuron.yale.edu/neuron/) and [BMTK](https://alleninstitute.github.io/bmtk/) models easier.\n\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/cyneuro/bmtool/blob/master/LICENSE) \n\n## Table of Contents\n- [Getting Started](#Getting-Started)\n- [CLI](#CLI)\n- [Single Cell](#Single-Cell-Module)\n- [Connectors](#Connectors-Module)\n- [Bmplot](#bmplot-Module)\n\n## Getting Started\n\n**Installation**\n```bash\npip install bmtool\n```\nFor developers who will be pulling down additional updates to this repository regularly use the following instead.\n```bash\ngit clone https://github.com/cyneuro/bmtool.git\ncd bmtool\npython setup.py develop\n```\nThen download updates (from this directory) with\n```bash\ngit pull\n```\n\n## CLI\n#### Many of modules available can be accesed using the command line \n```bash\n> cd your_bmtk_model_directory\n> bmtool\nUsage: bmtool [OPTIONS] COMMAND [ARGS]...\n\nOptions:\n  --verbose  Verbose printing\n  --help     Show this message and exit.\n\nCommands:\n  debug\n  plot\n  util\n\n>  \n> bmtool plot \nUsage: bmtool plot [OPTIONS] COMMAND [ARGS]...\n\nOptions:\n  --config PATH  Configuration file to use, default: \"simulation_config.json\"\n  --no-display   When set there will be no plot displayed, useful for saving\n                 plots\n  --help         Show this message and exit.\n\nCommands:\n  connection  Display information related to neuron connections\n  positions   Plot cell positions for a given set of populations\n  raster      Plot the spike raster for a given population\n  report      Plot the specified report using BMTK's default report plotter\n>\n```\n\n## Single Cell Module\n- [Passive properties](#passive-properties)\n- [Current injection](#current-clamp)\n- [FI curve](#fi-curve)\n- [ZAP](#zap)\n- [Tuner](#single-cell-tuning)\n- [VHalf Segregation](#vhalf-segregation-module)\n#### The 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.\n\n#### First step is it initialize the profiler.\n\n\n```python\nfrom bmtool.singlecell import Profiler\nprofiler = Profiler(template_dir='templates', mechanism_dir = 'mechanisms', dt=0.1)\n```\n\n#### 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 function\n\n\n```python\nfrom bmtool.singlecell import load_allen_database_cells\ncell = load_allen_database_cells(path_to_SWC_file,path_to_json_file)\n```\n\n### Passive properties\n#### Calculates the passive properties(V-rest, Rin and tau) of a HOC object\n\n\n```python\nfrom bmtool.singlecell import Passive,run_and_plot\nimport matplotlib.pyplot as plt\nsim = Passive('Cell_Cf', inj_amp=-100., inj_delay=1500., inj_dur=1000., tstop=2500., method='exp2')\ntitle = 'Passive Cell Current Injection'\nxlabel = 'Time (ms)'\nylabel = 'Membrane Potential (mV)'\nX, Y = run_and_plot(sim, title, xlabel, ylabel, plot_injection_only=True)\nplt.gca().plot(*sim.double_exponential_fit(), 'r:', label='double exponential fit')\nplt.legend()\nplt.show()\n```\n\n    Injection location: Cell_Cf[0].soma[0](0.5)\n    Recording: Cell_Cf[0].soma[0](0.5)._ref_v\n    Running simulation for passive properties...\n    \n    V Rest: -70.21 (mV)\n    Resistance: 128.67 (MOhms)\n    Membrane time constant: 55.29 (ms)\n    \n    V_rest Calculation: Voltage taken at time 1500.0 (ms) is\n    -70.21 (mV)\n    \n    R_in Calculation: dV/dI = (v_final-v_rest)/(i_final-i_start)\n    (-83.08 - (-70.21)) / (-0.1 - 0)\n    12.87 (mV) / 0.1 (nA) = 128.67 (MOhms)\n    \n    Tau Calculation: Fit a double exponential curve to the membrane potential response\n    f(t) = a0 + a1*exp(-t/tau1) + a2*exp(-t/tau2)\n    Constained by initial value: f(0) = a0 + a1 + a2 = v_rest\n    Fit parameters: (a0, a1, a2, tau1, tau2) = (-83.06, -3306.48, 3319.33, 55.29, 55.15)\n    Membrane time constant is determined from the slowest exponential term: 55.29 (ms)\n    \n    Sag potential: v_sag = v_peak - v_final = -0.66 (mV)\n    Normalized sag potential: v_sag / (v_peak - v_rest) = 0.049\n    \n\n\n\n    \n![png](readme_figures/output_8_1.png)\n    \n\n\n### Current clamp\n#### Runs a current clamp on a HOC object\n\n\n```python\nfrom bmtool.singlecell import CurrentClamp\nsim = CurrentClamp('Cell_Cf', inj_amp=350., inj_delay=1500., inj_dur=1000., tstop=3000., threshold=-15.)\nX, Y = run_and_plot(sim, title='Current Injection', xlabel='Time (ms)',\n                    ylabel='Membrane Potential (mV)', plot_injection_only=True)\nplt.show()\n```\n\n    Injection location: Cell_Cf[1].soma[0](0.5)\n    Recording: Cell_Cf[1].soma[0](0.5)._ref_v\n    Current clamp simulation running...\n    \n    Number of spikes: 19\n    \n\n\n\n    \n![png](readme_figures/output_10_1.png)\n    \n\n\n### FI curve\n#### Calculates the frequency vs current injection plot for a HOC object\n\n\n```python\nfrom bmtool.singlecell import FI\nsim = FI('Cell_Cf', i_start=0., i_stop=1000., i_increment=50., tstart=1500.,threshold=-15.)\nX, Y = run_and_plot(sim, title='FI Curve', xlabel='Injection (nA)', ylabel='# Spikes')\nplt.show()\n```\n\n    Injection location: Cell_Cf[21].soma[0](0.5)\n    Recording: Cell_Cf[21].soma[0](0.5)._ref_v\n    Running simulations for FI curve...\n    \n    Results\n    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\n    Number of spikes: 0, 1, 10, 12, 15, 16, 17, 19, 20, 20, 21, 21, 22, 23, 23, 24, 25, 25, 26, 27\n    \n\n\n\n    \n![png](readme_figures/output_12_1.png)\n    \n\n\n### ZAP\n#### Runs a ZAP on a HOC object\n\n\n```python\nfrom bmtool.singlecell import ZAP\nsim = ZAP('Cell_Cf')\nX, Y = run_and_plot(sim)\nplt.show()\n```\n\n    Injection location: Cell_Cf[22].soma[0](0.5)\n    Recording: Cell_Cf[22].soma[0](0.5)._ref_v\n    ZAP current simulation running...\n    \n    Chirp current injection with frequency changing from 0 to 15 Hz over 15 seconds\n    Impedance is calculated as the ratio of FFT amplitude of membrane voltage to FFT amplitude of chirp current\n    \n\n\n\n    \n![png](readme_figures/output_14_1.png)\n    \n\n\n### Single Cell Tuning\n\n#### From a BMTK Model directory containing a `simulation_config.json` file:\n```bash\nbmtool util cell tune --builder\n```\n\n#### For non-BMTK cell tuning:\n```bash\nbmtool util cell --template TemplateFile.hoc --mod-folder ./ tune --builder\n```\n![bmtool](./figures/figure2.png \"Tuning Figure\")\n\n### VHalf Segregation Module\n\n#### Based on the Alturki et al. (2016) paper.\n\n#### Segregate your channel activation for an easier time tuning your cells.\n\n\n```bash\n> bmtool util cell vhseg --help\n\nUsage: bmtool util cell vhseg [OPTIONS]\n\n  Alturki et al. (2016) V1/2 Automated Segregation Interface, simplify\n  tuning by separating channel activation\n\nOptions:\n  --title TEXT\n  --tstop INTEGER\n  --outhoc TEXT         Specify the file you want the modified cell template\n                        written to\n  --outfolder TEXT      Specify the directory you want the modified cell\n                        template and mod files written to (default: _seg)\n  --outappend           Append out instead of overwriting (default: False)\n  --debug               Print all debug statements\n  --fminpa INTEGER      Starting FI Curve amps (default: 0)\n  --fmaxpa INTEGER      Ending FI Curve amps (default: 1000)\n  --fincrement INTEGER  Increment the FI Curve amps by supplied pA (default:\n                        100)\n  --infvars TEXT        Specify the inf variables to plot, skips the wizard.\n                        (Comma separated, eg: inf_mech,minf_mech2,ninf_mech2)\n  --segvars TEXT        Specify the segregation variables to globally set,\n                        skips the wizard. (Comma separated, eg:\n                        mseg_mech,nseg_mech2)\n  --eleak TEXT          Specify the eleak var manually\n  --gleak TEXT          Specify the gleak var manually\n  --othersec TEXT       Specify other sections that a window should be\n                        generated for (Comma separated, eg: dend[0],dend[1])\n  --help                Show this message and exit.\n\n```\n\n### Examples \n\n#### Wizard Mode (Interactive)\n\n```bash\n> bmtool util cell vhseg\n\n? Select a cell:  CA3PyramidalCell\nUsing section dend[0]\n? Show other sections? (default: No)  Yes\n? Select other sections (space bar to select):  done (2 selections)\n? Select inf variables to plot (space bar to select):   done (5 selections)\n? Select segregation variables [OR VARIABLES YOU WANT TO CHANGE ON ALL SEGMENTS at the same time] (space bar to select):  done (2 selections)\n```\n\n#### Command Mode (Non-interactive)\n\n```bash\nbmtool util cell --template CA3PyramidalCell vhseg --othersec dend[0],dend[1] --infvars inf_im --segvars gbar_im --gleak gl_ichan2CA3 --eleak el_ichan2CA3\n```\n\nExample:\n\n![bmtool](./figures/figure4.png \"Seg Figure\")\n\n#### Simple models can utilize \n``` bash\nbmtool util cell --hoc cell_template.hoc vhsegbuild --build\nbmtool util cell --hoc segmented_template.hoc vhsegbuild\n```\nex: [https://github.com/tjbanks/two-cell-hco](https://github.com/tjbanks/two-cell-hco)\n\n### Connectors Module\n- [UnidirectionConnector](#unidirectional-connector---unidirectional-connections-in-bmtk-network-model-with-given-probability-within-a-single-population-or-between-two-populations)\n- [ReciprocalConnector](#recipical-connector---buiilding-connections-in-bmtk-network-model-with-reciprocal-probability-within-a-single-population-or-between-two-populations)\n- [CorrelatedGapJunction](#correlatedgapjunction)\n- [OneToOneSequentialConnector](#onetoonesequentialconnector)\n\n#### This 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 script `connectors.py` for more notes on usage.\n\n#### All connector example below use the following network node structure\n```python\nfrom bmtk.builder import NetworkBuilder\nnet = NetworkBuilder('example_net')\nnet.add_nodes(N=100, pop_name='PopA',model_type = 'biophysical')\nnet.add_nodes(N=100, pop_name='PopB',model_type = 'biophysical')\n\nbackground = NetworkBuilder('background')\nbackground.add_nodes(N=300,pop_name='tON',potential='exc',model_type='virtual')\n```\n\n#### Unidirectional connector - Object for building unidirectional connections in bmtk network model with given probability within a single population (or between two populations).\n```python\nfrom bmtool.connectors  import UnidirectionConnector\nconnector = UnidirectionConnector(p=0.15, n_syn=1)\nconnector.setup_nodes(source=net.nodes(pop_name = 'PopA'), target=net.nodes(pop_name = 'PopB'))\nnet.add_edges(**connector.edge_params())\n```\n#### Recipical connector - Object for building connections in bmtk network model with reciprocal probability within a single population (or between two populations)\n```python\nfrom bmtool.connectors  import ReciprocalConnector\nconnector = ReciprocalConnector(p0=0.15, pr=0.06767705087, n_syn0=1, n_syn1=1,estimate_rho=False)\nconnector.setup_nodes(source=net.nodes(pop_name = 'PopA'), target=net.nodes(pop_name = 'PopA'))\nnet.add_edges(**connector.edge_params())\n```\n#### CorrelatedGapJunction - Object for building gap junction connections in bmtk network model with given probabilities within a single population which could be correlated with the recurrent chemical synapses in this population.\n```python\nfrom bmtool.connectors import ReciprocalConnector, CorrelatedGapJunction\nconnector = ReciprocalConnector(p0=0.15, pr=0.06, n_syn0=1, n_syn1=1, estimate_rho=False)\nconnector.setup_nodes(source=net.nodes(pop_name='PopA'), target=net.nodes(pop_name='PopA'))\nnet.add_edges(**connector.edge_params())\ngap_junc = CorrelatedGapJunction(p_non=0.1228,p_uni=0.56,p_rec=1,connector=connector)\ngap_junc.setup_nodes(source=net.nodes(pop_name='PopA'), target=net.nodes(pop_name='PopA'))\nconn = net.add_edges(is_gap_junction=True, syn_weight=0.0000495, target_sections=None,afferent_section_id=0, afferent_section_pos=0.5,\n**gap_junc.edge_params())\n```\n\n#### OneToOneSequentialConnector - Object for building one to one correspondence connections in bmtk network model with between two populations. One of the population can consist of multiple sub-populations.\n```python\nfrom bmtool.connectors  import OneToOneSequentialConnector\nconnector = OneToOneSequentialConnector()\nconnector.setup_nodes(source=background.nodes(), target=net.nodes(pop_name = 'PopA'))\nnet.add_edges(**connector.edge_params())\nconnector.setup_nodes(target=net.nodes(pop_name = 'PopB'))\nnet.add_edges(**connector.edge_params())\n```\n\n## Bmplot Module\n- [Total connections](#Total-connection-plot)\n- [Percent connections](#Percent-connection-plot)\n- [Convergence connnections](#convergence-plot)\n- [Divergence connections](#divergence-plot)\n- [connection histogram](#connection-histogram)\n- [probability connection](#probability-of-connection-plot)\n- [3D location](#3d-position-plot)\n- [3D rotation](#cell-rotations)\n- [Plot Connection Diagram](#plot-connection-diagram)\n\n### Total connection plot\n#### Generates a table of total number of connections each neuron population recieves\n\n\n```python\nfrom bmtool import bmplot\nbmplot.total_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,include_gap=False)\n```\n\n\n    \n![png](readme_figures/output_19_0.png)\n    \n\n\n### Percent connection plot\n#### Generates a table of the percent connectivity of neuron populations.Method can change if you want the table to be total percent connectivity, only unidirectional connectivity or only bi directional connectvity \n\n\n```python\nbmplot.percent_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,method='total',include_gap=False)\n```\n\n\n    \n![png](readme_figures/output_21_0.png)\n    \n\n\n### Convergence plot\n#### Generates a table of the mean convergence of neuron populations. Method can be changed to show max, min, mean, or std for convergence a cell recieves\n\n\n```python\nbmplot.convergence_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,include_gap=False,method='mean+std')\n```\n\n\n    \n![png](readme_figures/output_23_0.png)\n    \n\n\n### Divergence plot\n#### Generates a table of the mean divergence of neuron populations. Method can be changed to show max, min, mean or std divergence a cell recieves.\n\n\n```python\nbmplot.divergence_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,include_gap=False,method='mean+std')\n```\n\n\n    \n![png](readme_figures/output_25_0.png)\n    \n\n\n### Connection histogram \n#### Generates a histogram of the distribution of connections a population of cells give to individual cells of another population \n\n\n```python\nbmplot.connection_histogram(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',source_cell='PV',target_cell='PV',include_gap=False)\n```\n\n\n    \n![png](readme_figures/output_27_0.png)\n    \n\n\n### probability of connection plot\n#### this function needs some work\n\n\n```python\nbmplot.probability_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,line_plot=True)\n```\n\n\n    \n![png](readme_figures/output_29_0.png)\n    \n\n\n\n    \n![png](readme_figures/output_29_1.png)\n    \n\n\n### 3D position plot\n#### Generates a plot of cells positions in 3D space \n\n\n```python\nbmplot.plot_3d_positions(config='config.json',populations_list='LA',group_by='pop_name',save_file=False)\n```\n\n\n    \n![png](readme_figures/output_31_0.png)\n    \n\n\n### cell rotations\n#### Generates a plot of cells location in 3D plot and also the cells rotation\n\n\n```python\nbmplot.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)\n```\n\n\n    \n![png](readme_figures/output_33_0.png)\n    \n\n\n### Plot Connection Diagram\n\n\n```python\nbmplot.plot_network_graph(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True)\n```\n\n\n    \n![png](readme_figures/output_35_0.png)\n    \n\n\n\n\n\n```python\nfrom bmtool import bmplot\nbmplot.plot_basic_cell_info(config_file='config.json')\n```\n\n    Network and node info:\n    LA:\n\n\n\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>node_type</th>\n      <th>pop_name</th>\n      <th>model_type</th>\n      <th>model_template</th>\n      <th>morphology</th>\n      <th>count</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>100</td>\n      <td>PNa</td>\n      <td>biophysical</td>\n      <td>hoc:Cell_Af</td>\n      <td>blank.swc</td>\n      <td>800</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>101</td>\n      <td>PNc</td>\n      <td>biophysical</td>\n      <td>hoc:Cell_Cf</td>\n      <td>blank.swc</td>\n      <td>800</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>102</td>\n      <td>PV</td>\n      <td>biophysical</td>\n      <td>hoc:InterneuronCellf</td>\n      <td>blank.swc</td>\n      <td>240</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>103</td>\n      <td>SOM</td>\n      <td>biophysical</td>\n      <td>hoc:LTS_Cell</td>\n      <td>blank.swc</td>\n      <td>160</td>\n    </tr>\n  </tbody>\n</table>\n\n\n    thalamus_pyr:\n\n\n\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>node_type</th>\n      <th>pop_name</th>\n      <th>model_type</th>\n      <th>count</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>100</td>\n      <td>pyr_inp</td>\n      <td>virtual</td>\n      <td>1600</td>\n    </tr>\n  </tbody>\n</table>\n\n\n    thalamus_pv:\n\n\n\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>node_type</th>\n      <th>pop_name</th>\n      <th>model_type</th>\n      <th>count</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>100</td>\n      <td>pv_inp</td>\n      <td>virtual</td>\n      <td>240</td>\n    </tr>\n  </tbody>\n</table>\n\n\n    thalamus_som:\n\n\n\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>node_type</th>\n      <th>pop_name</th>\n      <th>model_type</th>\n      <th>count</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>100</td>\n      <td>som_inp</td>\n      <td>virtual</td>\n      <td>160</td>\n    </tr>\n  </tbody>\n</table>\n\n\n    tone:\n\n\n\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>node_type</th>\n      <th>pop_name</th>\n      <th>model_type</th>\n      <th>count</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>100</td>\n      <td>tone</td>\n      <td>virtual</td>\n      <td>1840</td>\n    </tr>\n  </tbody>\n</table>\n\n\n    shock:\n\n\n\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>node_type</th>\n      <th>pop_name</th>\n      <th>model_type</th>\n      <th>count</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>100</td>\n      <td>shock</td>\n      <td>virtual</td>\n      <td>400</td>\n    </tr>\n  </tbody>\n</table>\n\n\n    shell:\n\n\n\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>node_type</th>\n      <th>pop_name</th>\n      <th>model_type</th>\n      <th>count</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>100</td>\n      <td>PNa</td>\n      <td>virtual</td>\n      <td>3975</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>101</td>\n      <td>PNc</td>\n      <td>virtual</td>\n      <td>3975</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>102</td>\n      <td>PV</td>\n      <td>virtual</td>\n      <td>1680</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>103</td>\n      <td>SOM</td>\n      <td>virtual</td>\n      <td>1120</td>\n    </tr>\n  </tbody>\n</table>\n\n\n\n\n\n    'LA'\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "BMTool",
    "version": "0.5.2",
    "project_urls": {
        "Homepage": "https://github.com/cyneuro/bmtool"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a7e794820a4e3a20063d8924ffee4b39426a0d3d519263a8245b72635cd3ed5f",
                "md5": "a63cbed643a3a3716ae6ef6d6aaf4d63",
                "sha256": "b428413821da04af7404bccdbae52fd7fe8303aa47e656bded1387b7553a0f28"
            },
            "downloads": -1,
            "filename": "bmtool-0.5.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a63cbed643a3a3716ae6ef6d6aaf4d63",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 84909,
            "upload_time": "2024-03-05T19:27:16",
            "upload_time_iso_8601": "2024-03-05T19:27:16.290103Z",
            "url": "https://files.pythonhosted.org/packages/a7/e7/94820a4e3a20063d8924ffee4b39426a0d3d519263a8245b72635cd3ed5f/bmtool-0.5.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3a4ca374e479b70d02c016dea58faf02a64bac793a3b427d974b9582d0b690fe",
                "md5": "23e8131b81447ebdce9b620e5f3b3edf",
                "sha256": "34edb388d3a6dbe03ae4ea4f75aecf727724fe46039c9fd2e64592a1b3a4e8d0"
            },
            "downloads": -1,
            "filename": "bmtool-0.5.2.tar.gz",
            "has_sig": false,
            "md5_digest": "23e8131b81447ebdce9b620e5f3b3edf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 87111,
            "upload_time": "2024-03-05T19:27:17",
            "upload_time_iso_8601": "2024-03-05T19:27:17.581038Z",
            "url": "https://files.pythonhosted.org/packages/3a/4c/a374e479b70d02c016dea58faf02a64bac793a3b427d974b9582d0b690fe/bmtool-0.5.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-05 19:27:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cyneuro",
    "github_project": "bmtool",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "bmtool"
}
        
Elapsed time: 0.22838s