-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from Neurosim-lab/development
PR from development to master - VERSION 0.6.7
- Loading branch information
Showing
31 changed files
with
1,223 additions
and
290 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Running batch simulations using NetPyNE | ||
|
||
Includes two toy examples using the 6-compartment M1 Corticospinal cell. | ||
1) f-I curve as a function of the amplitude of an IClamp and dendritic Na conductance. | ||
2) EPSP amplitude as a function of the weight of aNetStim and the rise time of an NMDA synapse. | ||
|
||
The code runs the required batch simulations in parallel using MPI and plots the corresponding figures. | ||
|
||
## Requirements | ||
- NEURON with MPI support | ||
- NetPyNE | ||
|
||
## Quick steps to run batch sims and plot results | ||
|
||
1) Compile mod files: | ||
cd mod | ||
mkmod | ||
|
||
2) Run batch simulations: | ||
./runbatch [num_cores] | ||
|
||
3) Plot results: | ||
ipython -i analysis.py | ||
|
||
|
||
## Code structure: | ||
|
||
* netParams.py: Defines the network model. Includes "fixed" parameter values of cells, synapses, connections, stimulation, etc. Changes to this file should only be made for relatively stable improvements of the model. Parameter values that will be varied systematically to explore or tune the model should be included here by referencing the appropiate variable in the simulation configuration (cfg) module. Only a single netParams file is required for each batch of simulations. | ||
|
||
* cfg.py: Simulation configuration module. Includes parameter values for each simulation run such as duration, dt, recording parameters etc. Also includes the model parameters that are being varied to explore or tune the network. When running a batch, NetPyNE will create one cfg file for each parameter configuration. | ||
|
||
* init.py: Sequence of commands to run a single simulation. Can be executed via 'ipython init.py'. When running a batch, NetPyNE will call init.py multiple times, pass a different cfg file for each of the parameter configurations explored. | ||
|
||
* batch.py: Defines the parameters and parameter values explored in the batch, as well as the run configuration (e.g. using MPI in a multicore machine or PBS Torque for HPCs). Includes examples of how to create 2 different batch simulations: | ||
1) batchNa(): explore the effect of changing the amplitude of an IClamp and the dendritic Na conductance. | ||
2) batchNMDA(): explore the effect of changing the weight of NetStim and the rise time of an NMDA synapse. | ||
|
||
To run, add a call to either of these functions in __main__(), or import the batch module and run interactively. | ||
|
||
To add new batch explorations, follow the format of the above example, making sure that the parameters being explored are included in cfg.py and referenced appropiately in netParams.py | ||
|
||
* runbatch: Shell script to run the batch simulation using mpi. Alternatively, can run "manually" using: | ||
mpiexec -np [num_cores] nrniv -python -mpi batch.py | ||
|
||
* analysis.py: Functions to read and plot figures from the batch simulation results. Can call readPlotNa() or readPlotNMDA() from __main__() or import analysis and call interactively. | ||
|
||
* utils.py: Support functions to read output data from batch simulations, and others. Eventually, some of these functions will be moved to NetPyNE. | ||
|
||
* /cells: Folder containing cell model. In this case only includes SPI6.py. NetPyNE will import the cell specifications from this file. | ||
|
||
* /data: Folder to store output of simulations. | ||
|
||
* /mod: Folder containing mod files (need to clean up to keep just mod files required for this model) | ||
|
||
|
||
For further information please contact: [email protected] | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
""" | ||
analysis.py | ||
Functions to read and plot figures from the batch simulation results. | ||
Can call readPlotNa() or readPlotNMDA() from __main__() or import analysis and call interactively. | ||
Contributors: [email protected] | ||
""" | ||
|
||
import utils | ||
import json | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
def plotfINa(dataFolder, batchLabel, params, data): | ||
utils.setPlotFormat(numColors = 8) | ||
|
||
Pvals = params[0]['values'] | ||
Ivals = params[1]['values'] | ||
Pvalsdic = {val: i for i,val in enumerate(Pvals)} | ||
Ivalsdic = {val: i for i,val in enumerate(Ivals)} | ||
|
||
rates = [[0 for x in range(len(Pvals))] for y in range(len(Ivals))] | ||
for key, d in data.iteritems(): | ||
rate = len(d['simData']['spkt']) | ||
Pindex = Pvalsdic[d['paramValues'][0]] | ||
Iindex = Ivalsdic[d['paramValues'][1]] | ||
rates[Iindex][Pindex] = rate | ||
print d['paramValues'] | ||
print rate | ||
|
||
filename = '%s/%s/%s_fIcurve.json' % (dataFolder, batchLabel, batchLabel) | ||
with open(filename, 'w') as fileObj: | ||
json.dump(rates, fileObj) | ||
|
||
plt.figure() | ||
|
||
handles = plt.plot(rates, marker='o', markersize=10) | ||
plt.xlabel('Somatic current injection (nA)') | ||
plt.xticks(range(len(Ivals))[::2], Ivals[::2]) | ||
plt.ylabel('Frequency (Hz)') | ||
plt.legend(handles, params[0]['values'], title = 'dend Na', loc=2) | ||
plt.savefig('%s/%s/%s_fIcurve.png' % (dataFolder, batchLabel, batchLabel)) | ||
plt.show() | ||
|
||
|
||
def plotNMDA(dataFolder, batchLabel, params, data, somaLabel='soma', stimRange=[5000,10000]): | ||
utils.setPlotFormat(numColors = 8) | ||
|
||
Pvals = params[0]['values'] | ||
Wvals = params[1]['values'] | ||
Pvalsdic = {val: i for i,val in enumerate(Pvals)} | ||
Wvalsdic = {val: i for i,val in enumerate(Wvals)} | ||
|
||
epsps = [[0 for x in range(len(Pvals))] for y in range(len(Wvals))] | ||
for key, d in data.iteritems(): | ||
cellLabel = d['simData']['V_soma'].keys()[0] | ||
vsoma = d['simData']['V_'+somaLabel][cellLabel] | ||
epsp = max(vsoma[stimRange[0]:stimRange[1]]) - vsoma[stimRange[0]-1] | ||
|
||
Pindex = Pvalsdic[d['paramValues'][0]] | ||
Windex = Wvalsdic[d['paramValues'][1]] | ||
epsps[Windex][Pindex] = epsp | ||
print d['paramValues'] | ||
print epsp | ||
|
||
filename = '%s/%s/%s_epsp.json' % (dataFolder, batchLabel, batchLabel) | ||
with open(filename, 'w') as fileObj: | ||
json.dump(epsps, fileObj) | ||
|
||
plt.figure() | ||
|
||
handles = plt.plot(epsps, marker='o', markersize=10) | ||
plt.xlabel('Weight (of NetStim connection)') | ||
plt.ylabel('Somatic EPSP amplitude (mV) in response to 1 NetStim spike') | ||
plt.xticks(range(len(Wvals))[::2], Wvals[::2]) | ||
plt.legend(handles, params[0]['values'], title = 'NMDA tau1 (ms)', loc=2) | ||
plt.savefig('%s/%s/%s_epsp.png' % (dataFolder, batchLabel, batchLabel)) | ||
plt.show() | ||
|
||
|
||
def readPlotNa(): | ||
dataFolder = 'data/' | ||
batchLabel = 'batchNa' | ||
|
||
params, data = utils.readBatchData(dataFolder, batchLabel, loadAll=0, saveAll=1, vars=None, maxCombs=None) | ||
plotfINa(dataFolder, batchLabel, params, data) | ||
|
||
|
||
def readPlotNMDA(): | ||
dataFolder = 'data/' | ||
batchLabel = 'batchNMDA' | ||
|
||
params, data = utils.readBatchData(dataFolder, batchLabel, loadAll=0, saveAll=1, vars=None, maxCombs=None) | ||
plotNMDA(dataFolder, batchLabel, params, data) | ||
|
||
|
||
# Main code | ||
if __name__ == '__main__': | ||
readPlotNa() | ||
# readPlotNMDA() | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
batch.py | ||
Batch simulation for M1 model using NetPyNE | ||
Contributors: [email protected] | ||
""" | ||
|
||
from netpyne.batch import Batch | ||
import numpy as np | ||
|
||
|
||
def createBatch(params): | ||
# Create Batch object | ||
b = Batch() | ||
for k,v in params.iteritems(): | ||
b.params.append({'label': k, 'values': v}) | ||
return b | ||
|
||
|
||
def runBatch(b, label): | ||
b.batchLabel = label | ||
b.saveFolder = 'data/'+b.batchLabel | ||
b.method = 'grid' | ||
b.runCfg = {'type': 'mpi', | ||
'script': 'init.py', | ||
'skip': True} | ||
|
||
b.run() # run batch | ||
|
||
|
||
def batchNa(): | ||
b = createBatch({'dendNa': [0.025, 0.03, 0.035, 0.4], | ||
('IClamp1', 'amp'): list(np.arange(-2.0, 8.0, 0.5)/10.0)}) | ||
runBatch(b, 'batchNa') | ||
|
||
|
||
def batchNMDA(): | ||
b = createBatch({'tau1NMDA': [10, 15, 20, 25], | ||
('NetStim1', 'weight'): list(np.arange(1.0, 10.0, 1.0)/1e4)}) | ||
runBatch(b, 'batchNMDA') | ||
|
||
|
||
# Main code | ||
if __name__ == '__main__': | ||
batchNa() | ||
# batchNMDA() | ||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/usr/site/nrniv/local/python/SPI6.py |
Oops, something went wrong.