diff --git a/CHANGES.md b/CHANGES.md index 1f3e61579..418efe75c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,19 @@ +# Version 0.6.0 + +- Added option to shape conn weights dynamically to create temporal patterns (issue #33) + +- Store all params of synMechs exhaustively instead of by reference (issue #139) + +- Added netParams.importCellParamsFromNet() to import parameters of multiple cells from existing network (issue #154) + +- Added modifySynMechs function + +- Added option to record from all synMechs of a type (eg. 'AMPA') + +- Fixed bugs and improved efficiency of modify, modifyConns and modifyStims function + +- Fixed bug plotting traces + # Version 0.5.9 - Improved NeuroML2 import functions (issue #12) diff --git a/doc/source/code/tut2.py b/doc/source/code/tut2.py index 09fa46932..99b3d9510 100644 --- a/doc/source/code/tut2.py +++ b/doc/source/code/tut2.py @@ -4,35 +4,35 @@ netParams = specs.NetParams() # object of class NetParams to store the network parameters ## Population parameters -netParams.addPopParams('S', {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'}) -netParams.addPopParams('M', {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'}) -netParams.addPopParams('background', {'rate': 10, 'noise': 0.5, 'cellModel': 'NetStim'}) +netParams.popParams['S'] = {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'} +netParams.popParams['M'] = {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'} +netParams.popParams['background'] = {'rate': 10, 'noise': 0.5, 'cellModel': 'NetStim'} ## Cell property rules cellRule = {'conds': {'cellType': 'PYR'}, 'secs': {}} # cell rule dict cellRule['secs']['soma'] = {'geom': {}, 'mechs': {}} # soma params dict cellRule['secs']['soma']['geom'] = {'diam': 18.8, 'L': 18.8, 'Ra': 123.0} # soma geometry cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} # soma hh mechanism -netParams.addCellParams('PYRrule', cellRule) # add dict to list of cell params +netParams.cellParams['PYRrule'] = cellRule # add dict to list of cell params ## Synaptic mechanism parameters -netParams.addSynMechParams('exc', {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 5.0, 'e': 0}) # excitatory synaptic mechanism +netParams.synMechParams['exc'] = {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 5.0, 'e': 0} # excitatory synaptic mechanism ## Cell connectivity rules -netParams.addConnParams('S->M', # S -> M label - {'preConds': {'popLabel': 'S'}, # conditions of presyn cells +netParams.connParams['S->M'] = { # S -> M label + 'preConds': {'popLabel': 'S'}, # conditions of presyn cells 'postConds': {'popLabel': 'M'}, # conditions of postsyn cells - 'probability': 0.5, # probability of connection - 'weight': 0.01, # synaptic weight - 'delay': 5, # transmission delay (ms) - 'synMech': 'exc'}) # synaptic mechanism + 'probability': 0.5, # probability of connection + 'weight': 0.01, # synaptic weight + 'delay': 5, # transmission delay (ms) + 'synMech': 'exc'} # synaptic mechanism -netParams.addConnParams('bg->PYR', # background -> PYR label - {'preConds': {'popLabel': 'background'}, +netParams.connParams['bg->PYR'] = { # background -> PYR label + 'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': 'PYR'}, 'weight': 0.01, # synaptic weight 'delay': 5, # transmission delay (ms) - 'synMech': 'exc'}) # synaptic mechanism + 'synMech': 'exc'} # synaptic mechanism # Simulation options @@ -46,9 +46,9 @@ simConfig.filename = 'model_output' # Set file output name simConfig.savePickle = False # Save params, network and sim output to pickle file -simConfig.addAnalysis('plotRaster', True) # Plot a raster -simConfig.addAnalysis('plotTraces', {'include': [1]}) # Plot recorded traces for this list of cells -simConfig.addAnalysis('plot2Dnet', True) # plot 2D visualization of cell positions and connections +simConfig.analysis['plotRaster'] = True # Plot a raster +simConfig.analysis['plotTraces'] = {'include': [1]} # Plot recorded traces for this list of cells +simConfig.analysis['plot2Dnet'] = True # plot 2D visualization of cell positions and connections # Create network and run simulation diff --git a/doc/source/code/tut3.py b/doc/source/code/tut3.py index 133247b99..8975832a3 100644 --- a/doc/source/code/tut3.py +++ b/doc/source/code/tut3.py @@ -4,9 +4,9 @@ netParams = specs.NetParams() # object of class NetParams to store the network parameters ## Population parameters -netParams.addPopParams('S', {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'}) -netParams.addPopParams('M', {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'}) -netParams.addPopParams('background', {'rate': 10, 'noise': 0.5, 'cellModel': 'NetStim'}) +netParams.popParams['S'] = {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'} +netParams.popParams['M'] = {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'} +netParams.popParams['background'] = {'rate': 10, 'noise': 0.5, 'cellModel': 'NetStim'} ## Cell property rules cellRule = {'conds': {'cellType': 'PYR'}, 'secs': {}} # cell rule dict @@ -17,7 +17,7 @@ cellRule['secs']['dend']['geom'] = {'diam': 5.0, 'L': 150.0, 'Ra': 150.0, 'cm': 1} # dend geometry cellRule['secs']['dend']['topol'] = {'parentSec': 'soma', 'parentX': 1.0, 'childX': 0} # dend topology cellRule['secs']['dend']['mechs']['pas'] = {'g': 0.0000357, 'e': -70} # dend mechanisms -netParams.addCellParams('PYRrule', cellRule) # add dict to list of cell parameters +netParams.cellParams['PYRrule'] = cellRule # add dict to list of cell parameters ## Synaptic mechanism parameters @@ -25,19 +25,19 @@ ## Cell connectivity rules -netParams.addConnParams('S->M', {'preConds': {'popLabel': 'S'}, 'postConds': {'popLabel': 'M'}, # S -> M +netParams.connParams['S->M'] = {'preConds': {'popLabel': 'S'}, 'postConds': {'popLabel': 'M'}, # S -> M 'probability': 0.5, # probability of connection 'weight': 0.01, # synaptic weight 'delay': 5, # transmission delay (ms) 'sec': 'dend', # section to connect to - 'loc': 1.0, # location of synapse - 'synMech': 'exc'}) # target synaptic mechanism + 'loc': 1.0, # location of synapse + 'synMech': 'exc'} # target synaptic mechanism -netParams.addConnParams('bg->PYR', {'preConds': {'popLabel': 'background'}, +netParams.connParams['bg->PYR'] = {'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': 'PYR'}, # background -> PYR 'weight': 0.01, # synaptic weight 'delay': 5, # transmission delay (ms) - 'synMech': 'exc'}) # target synapse + 'synMech': 'exc'} # target synapse # Simulation options @@ -51,9 +51,9 @@ simConfig.filename = 'model_output' # Set file output name simConfig.savePickle = False # Save params, network and sim output to pickle file -simConfig.addAnalysis('plotRaster', True) # Plot a raster -simConfig.addAnalysis('plotTraces', {'include': [1]}) # Plot recorded traces for this list of cells -simConfig.addAnalysis('plot2Dnet', True) # plot 2D visualization of cell positions and connections +simConfig.analysis['plotRaster'] = True # Plot a raster +simConfig.analysis['plotTraces'] = {'include': [1]} # Plot recorded traces for this list of cells +simConfig.analysis['plot2Dnet'] = True # plot 2D visualization of cell positions and connections # Create network and run simulation diff --git a/doc/source/code/tut4.py b/doc/source/code/tut4.py index 7f8fa2b8a..a858773fe 100644 --- a/doc/source/code/tut4.py +++ b/doc/source/code/tut4.py @@ -4,48 +4,48 @@ netParams = specs.NetParams() # object of class NetParams to store the network parameters ## Population parameters -netParams.addPopParams('S', {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'Izhi2007b'}) -netParams.addPopParams('M', {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'}) -netParams.addPopParams('background', {'rate': 100, 'noise': 0.5, 'cellModel': 'NetStim'}) +netParams.popParams['S'] = {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'Izhi2007b'} +netParams.popParams['M'] = {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'} +netParams.popParams['background'] = {'rate': 100, 'noise': 0.5, 'cellModel': 'NetStim'} ## Cell property rules cellRule = {'conds': {'cellType': 'PYR', 'cellModel': 'HH'}, 'secs': {}} # cell rule dict -cellRule['secs']['soma'] = {'geom': {}, 'mechs': {}} # soma params dict -cellRule['secs']['soma']['geom'] = {'diam': 18.8, 'L': 18.8, 'Ra': 123.0} # soma geometry -cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} # soma hh mechanisms -cellRule['secs']['dend'] = {'geom': {}, 'topol': {}, 'mechs': {}} # dend params dict -cellRule['secs']['dend']['geom'] = {'diam': 5.0, 'L': 150.0, 'Ra': 150.0, 'cm': 1} # dend geometry -cellRule['secs']['dend']['topol'] = {'parentSec': 'soma', 'parentX': 1.0, 'childX': 0} # dend topology -cellRule['secs']['dend']['mechs']['pas'] = {'g': 0.0000357, 'e': -70} # dend mechanisms -netParams.addCellParams('PYR_HH_rule', cellRule) # add dict to list of cell parameters +cellRule['secs']['soma'] = {'geom': {}, 'mechs': {}} # soma params dict +cellRule['secs']['soma']['geom'] = {'diam': 18.8, 'L': 18.8, 'Ra': 123.0} # soma geometry +cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} # soma hh mechanisms +cellRule['secs']['dend'] = {'geom': {}, 'topol': {}, 'mechs': {}} # dend params dict +cellRule['secs']['dend']['geom'] = {'diam': 5.0, 'L': 150.0, 'Ra': 150.0, 'cm': 1} # dend geometry +cellRule['secs']['dend']['topol'] = {'parentSec': 'soma', 'parentX': 1.0, 'childX': 0} # dend topology +cellRule['secs']['dend']['mechs']['pas'] = {'g': 0.0000357, 'e': -70} # dend mechanisms +netParams.cellParams['PYR_HH_rule'] = cellRule # add dict to list of cell parameters -cellRule = {'conds': {'cellType': 'PYR', 'cellModel': 'Izhi2007b'}, 'secs': {}} # cell rule dict -cellRule['secs']['soma'] = {'geom': {}, 'pointps': {}} # soma params dict -cellRule['secs']['soma']['geom'] = {'diam': 10.0, 'L': 10.0, 'cm': 31.831} # soma geometry +cellRule = {'conds': {'cellType': 'PYR', 'cellModel': 'Izhi2007b'}, 'secs': {}} # cell rule dict +cellRule['secs']['soma'] = {'geom': {}, 'pointps': {}} # soma params dict +cellRule['secs']['soma']['geom'] = {'diam': 10.0, 'L': 10.0, 'cm': 31.831} # soma geometry cellRule['secs']['soma']['pointps']['Izhi'] = {'mod':'Izhi2007b', 'C':1, 'k':0.7, - 'vr':-60, 'vt':-40, 'vpeak':35, 'a':0.03, 'b':-2, 'c':-50, 'd':100, 'celltype':1} # soma hh mechanisms -netParams.addCellParams('PYR_Izhi_rule', cellRule) # add dict to list of cell parameters + 'vr':-60, 'vt':-40, 'vpeak':35, 'a':0.03, 'b':-2, 'c':-50, 'd':100, 'celltype':1} # soma hh mechanisms +netParams.cellParams['PYR_Izhi_rule'] = cellRule # add dict to list of cell parameters ## Synaptic mechanism parameters -netParams.addSynMechParams('exc', {'mod': 'Exp2Syn', 'tau1': 1.0, 'tau2': 5.0, 'e': 0}) # excitatory synapse +netParams.synMechParams['exc'] = {'mod': 'Exp2Syn', 'tau1': 1.0, 'tau2': 5.0, 'e': 0} # excitatory synapse ## Cell connectivity rules -netParams.addConnParams('S->M', - {'preConds': {'popLabel': 'S'}, 'postConds': {'popLabel': 'M'}, # S -> M +netParams.connParams['S->M'] = { + 'preConds': {'popLabel': 'S'}, 'postConds': {'popLabel': 'M'}, # S -> M 'probability': 0.1, # probability of connection 'weight': 0.005, # synaptic weight 'delay': 5, # transmission delay (ms) 'sec': 'dend', # section to connect to 'loc': 1.0, - 'synMech': 'exc'}) # target synapse + 'synMech': 'exc'} # target synapse -netParams.addConnParams('bg->PYR', - {'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': 'PYR'}, # background -> PYR +netParams.connParams['bg->PYR'] = { + 'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': 'PYR'}, # background -> PYR 'weight': 0.01, # synaptic weight 'delay': 5, # transmission delay (ms) - 'synMech': 'exc'}) # target synapse + 'synMech': 'exc'} # target synapse # Simulation options @@ -58,9 +58,9 @@ simConfig.filename = 'model_output' # Set file output name simConfig.savePickle = False # Save params, network and sim output to pickle file -simConfig.addAnalysis('plotRaster', True) # Plot a raster -simConfig.addAnalysis('plotTraces', {'include': [1]}) # Plot recorded traces for this list of cells -simConfig.addAnalysis('plot2Dnet', True) # plot 2D visualization of cell positions and connections +simConfig.analysis['plotRaster'] = True # Plot a raster +simConfig.analysis['plotTraces'] = {'include': [1]} # Plot recorded traces for this list of cells +simConfig.analysis['plot2Dnet'] = True # plot 2D visualization of cell positions and connections # Create network and run simulation diff --git a/doc/source/code/tut5.py b/doc/source/code/tut5.py index 3e3cd6daf..aa1654355 100644 --- a/doc/source/code/tut5.py +++ b/doc/source/code/tut5.py @@ -11,13 +11,13 @@ ## Population parameters -netParams.addPopParams('E2', {'cellType': 'E', 'numCells': 50, 'yRange': [100,300], 'cellModel': 'HH'}) -netParams.addPopParams('I2', {'cellType': 'I', 'numCells': 50, 'yRange': [100,300], 'cellModel': 'HH'}) -netParams.addPopParams('E4', {'cellType': 'E', 'numCells': 50, 'yRange': [300,600], 'cellModel': 'HH'}) -netParams.addPopParams('I4', {'cellType': 'I', 'numCells': 50, 'yRange': [300,600], 'cellModel': 'HH'}) -netParams.addPopParams('E5', {'cellType': 'E', 'numCells': 50, 'ynormRange': [0.6,1.0], 'cellModel': 'HH'}) -netParams.addPopParams('I5', {'cellType': 'I', 'numCells': 50, 'ynormRange': [0.6,1.0], 'cellModel': 'HH'}) -netParams.addPopParams('background', {'rate': 20, 'noise': 0.3, 'cellModel': 'NetStim'}) +netParams.popParams['E2'] = {'cellType': 'E', 'numCells': 50, 'yRange': [100,300], 'cellModel': 'HH'} +netParams.popParams['I2'] = {'cellType': 'I', 'numCells': 50, 'yRange': [100,300], 'cellModel': 'HH'} +netParams.popParams['E4'] = {'cellType': 'E', 'numCells': 50, 'yRange': [300,600], 'cellModel': 'HH'} +netParams.popParams['I4'] = {'cellType': 'I', 'numCells': 50, 'yRange': [300,600], 'cellModel': 'HH'} +netParams.popParams['E5'] = {'cellType': 'E', 'numCells': 50, 'ynormRange': [0.6,1.0], 'cellModel': 'HH'} +netParams.popParams['I5'] = {'cellType': 'I', 'numCells': 50, 'ynormRange': [0.6,1.0], 'cellModel': 'HH'} +netParams.popParams['background'] = {'rate': 20, 'noise': 0.3, 'cellModel': 'NetStim'} ## Cell property rules @@ -25,56 +25,56 @@ cellRule['secs']['soma'] = {'geom': {}, 'mechs': {}} # soma params dict cellRule['secs']['soma']['geom'] = {'diam': 15, 'L': 14, 'Ra': 120.0} # soma geometry cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.13, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} # soma hh mechanism -netParams.addCellParams('Erule', cellRule) # add dict to list of cell params +netParams.cellParams['Erule'] = cellRule # add dict to list of cell params cellRule = {'conds': {'cellType': 'I'}, 'secs': {}} # cell rule dict cellRule['secs']['soma'] = {'geom': {}, 'mechs': {}} # soma params dict cellRule['secs']['soma']['geom'] = {'diam': 10.0, 'L': 9.0, 'Ra': 110.0} # soma geometry cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.11, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} # soma hh mechanism -netParams.addCellParams('Irule', cellRule) # add dict to list of cell params +netParams.cellParams['Irule'] = cellRule # add dict to list of cell params ## Synaptic mechanism parameters -netParams.addSynMechParams('exc', {'mod': 'Exp2Syn', 'tau1': 0.8, 'tau2': 5.3, 'e': 0}) # NMDA synaptic mechanism -netParams.addSynMechParams('inh', {'mod': 'Exp2Syn', 'tau1': 0.6, 'tau2': 8.5, 'e': -75}) # GABA synaptic mechanism +netParams.synMechParams['exc'] = {'mod': 'Exp2Syn', 'tau1': 0.8, 'tau2': 5.3, 'e': 0} # NMDA synaptic mechanism +netParams.synMechParams['inh'] = {'mod': 'Exp2Syn', 'tau1': 0.6, 'tau2': 8.5, 'e': -75} # GABA synaptic mechanism ## Cell connectivity rules -netParams.addConnParams('bg->all', -{'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': ['E', 'I']}, # background -> all +netParams.connParams['bg->all'] = { + 'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': ['E', 'I']}, # background -> all 'weight': 0.01, # synaptic weight 'delay': 'max(1, gauss(5,2))', # transmission delay (ms) - 'synMech': 'exc'}) # synaptic mechanism + 'synMech': 'exc'} # synaptic mechanism -netParams.addConnParams('E->all', -{'preConds': {'cellType': 'E'}, 'postConds': {'y': [100,1000]}, # E -> all (100-1000 um) +netParams.connParams['E->all'] = { + 'preConds': {'cellType': 'E'}, 'postConds': {'y': [100,1000]}, # E -> all (100-1000 um) 'probability': 0.1 , # probability of connection 'weight': '0.005*post_ynorm', # synaptic weight 'delay': 'dist_3D/propVelocity', # transmission delay (ms) - 'synMech': 'exc'}) # synaptic mechanism + 'synMech': 'exc'} # synaptic mechanism -netParams.addConnParams('I->E', -{'preConds': {'cellType': 'I'}, 'postConds': {'popLabel': ['E2','E4','E5']}, # I -> E +netParams.connParams['I->E'] = { + 'preConds': {'cellType': 'I'}, 'postConds': {'popLabel': ['E2','E4','E5']}, # I -> E 'probability': '0.4*exp(-dist_3D/probLengthConst)', # probability of connection - 'weight': 0.001, # synaptic weight - 'delay': 'dist_3D/propVelocity', # transmission delay (ms) - 'synMech': 'inh'}) # synaptic mechanism + 'weight': 0.001, # synaptic weight + 'delay': 'dist_3D/propVelocity', # transmission delay (ms) + 'synMech': 'inh'} # synaptic mechanism # Simulation options simConfig = specs.SimConfig() # object of class SimConfig to store simulation configuration simConfig.duration = 1*1e3 # Duration of the simulation, in ms -simConfig.dt = 0.05 # Internal integration timestep to use +simConfig.dt = 0.05 # Internal integration timestep to use simConfig.verbose = False # Show detailed messages simConfig.recordTraces = {'V_soma':{'sec':'soma','loc':0.5,'var':'v'}} # Dict with traces to record simConfig.recordStep = 1 # Step size in ms to save data (eg. V traces, LFP, etc) simConfig.filename = 'model_output' # Set file output name simConfig.savePickle = False # Save params, network and sim output to pickle file -simConfig.addAnalysis('plotRaster', {'orderBy': 'y', 'orderInverse': True}) # Plot a raster -simConfig.addAnalysis('plotTraces', {'include': [('E2',0), ('E4', 0), ('E5', 5)]}) # Plot recorded traces for this list of cells -simConfig.addAnalysis('plot2Dnet', True) # plot 2D visualization of cell positions and connections -simConfig.addAnalysis('plotConn', True) # plot connectivity matrix +simConfig.analysis['plotRaster'] = {'orderBy': 'y', 'orderInverse': True} # Plot a raster +simConfig.analysis['plotTraces'] = {'include': [('E2',0), ('E4', 0), ('E5', 5)]} # Plot recorded traces for this list of cells +simConfig.analysis['plot2Dnet'] = True # plot 2D visualization of cell positions and connections +simConfig.analysis['plotConn'] = True # plot connectivity matrix # Create network and run simulation sim.createSimulateAnalyze(netParams = netParams, simConfig = simConfig) diff --git a/doc/source/code/tut6.py b/doc/source/code/tut6.py index a3d518651..7f42e3ada 100644 --- a/doc/source/code/tut6.py +++ b/doc/source/code/tut6.py @@ -4,31 +4,31 @@ netParams = specs.NetParams() # object of class NetParams to store the network parameters ## Population parameters -netParams.addPopParams('S', {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'}) -netParams.addPopParams('M', {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'}) -netParams.addPopParams('background', {'rate': 10, 'noise': 0.5, 'cellModel': 'NetStim'}) +netParams.popParams['S'] = {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'} +netParams.popParams['M'] = {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'} +netParams.popParams['background'] = {'rate': 10, 'noise': 0.5, 'cellModel': 'NetStim'} ## Cell property rules -cellRule = {'conds': {'cellType': 'PYR'}, 'secs': {}} # cell rule dict -cellRule['secs']['soma'] = {'geom': {}, 'mechs': {}} # soma params dict -cellRule['secs']['soma']['geom'] = {'diam': 18.8, 'L': 18.8} # soma geometry -cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} # soma hh mechanism -netParams.addCellParams('PYRrule', cellRule) # add dict to list of cell params +cellRule = {'conds': {'cellType': 'PYR'}, 'secs': {}} # cell rule dict +cellRule['secs']['soma'] = {'geom': {}, 'mechs': {}} # soma params dict +cellRule['secs']['soma']['geom'] = {'diam': 18.8, 'L': 18.8} # soma geometry +cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} # soma hh mechanism +netParams.cellParams['PYRrule'] = cellRule # add dict to list of cell params ## Synaptic mechanism parameters -netParams.addSynMechParams('exc', {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 5.0, 'e': 0}) # excitatory synaptic mechanism +netParams.synMechParams['exc'] = {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 5.0, 'e': 0} # excitatory synaptic mechanism ## Stimulation parameters -netParams.addStimSourceParams('Input_1', {'type': 'IClamp', 'delay': 300, 'dur': 100, 'amp': 'uniform(0.4,0.5)'}) -netParams.addStimSourceParams('Input_2', {'type': 'VClamp', 'dur': [0,50,200], 'amp': [-60,-30,40], 'gain': 1e5, 'rstim': 1, 'tau1': 0.1, 'tau2': 0}) -netParams.addStimSourceParams('Input_3', {'type': 'AlphaSynapse', 'onset': 'uniform(300,600)', 'tau': 5, 'gmax': 'post_ynorm', 'e': 0}) -netParams.addStimSourceParams('Input_4', {'type': 'NetStim', 'interval': 'uniform(20,100)', 'start': 600, 'noise': 0.1}) +netParams.stimSourceParams['Input_1'] = {'type': 'IClamp', 'delay': 300, 'dur': 100, 'amp': 'uniform(0.4,0.5)'} +netParams.stimSourceParams['Input_2'] = {'type': 'VClamp', 'dur': [0,50,200], 'amp': [-60,-30,40], 'gain': 1e5, 'rstim': 1, 'tau1': 0.1, 'tau2': 0} +netParams.stimSourceParams['Input_3'] = {'type': 'AlphaSynapse', 'onset': 'uniform(300,600)', 'tau': 5, 'gmax': 'post_ynorm', 'e': 0} +netParams.stimSourceParams['Input_4'] = {'type': 'NetStim', 'interval': 'uniform(20,100)', 'start': 600, 'noise': 0.1} -netParams.addStimTargetParams('Input_1->S', {'source': 'Input_1', 'sec':'soma', 'loc': 0.8, 'conds': {'popLabel':'S', 'cellList': range(15)}}) -netParams.addStimTargetParams('Input_2->S', {'source': 'Input_2', 'sec':'soma', 'loc': 0.5, 'conds': {'popLabel':'S', 'ynorm': [0,0.5]}}) -netParams.addStimTargetParams('Input_3->M1', {'source': 'Input_3', 'sec':'soma', 'loc': 0.2, 'conds': {'popLabel':'M', 'cellList': [2,4,5,8,10,15,19]}}) -netParams.addStimTargetParams('Input_4->PYR', {'source': 'Input_4', 'sec':'soma', 'loc': 0.5, 'weight': '0.1+gauss(0.2,0.05)','delay': 1, - 'conds': {'cellType':'PYR', 'ynorm': [0.6,1.0]}}) +netParams.stimTargetParams['Input_1->S'] = {'source': 'Input_1', 'sec':'soma', 'loc': 0.8, 'conds': {'popLabel':'S', 'cellList': range(15)}} +netParams.stimTargetParams['Input_2->S'] = {'source': 'Input_2', 'sec':'soma', 'loc': 0.5, 'conds': {'popLabel':'S', 'ynorm': [0,0.5]}} +netParams.stimTargetParams['Input_3->M1'] = {'source': 'Input_3', 'sec':'soma', 'loc': 0.2, 'conds': {'popLabel':'M', 'cellList': [2,4,5,8,10,15,19]}} +netParams.stimTargetParams['Input_4->PYR'] = {'source': 'Input_4', 'sec':'soma', 'loc': 0.5, 'weight': '0.1+gauss(0.2,0.05)','delay': 1, + 'conds': {'cellType':'PYR', 'ynorm': [0.6,1.0]}} # Simulation options @@ -42,8 +42,8 @@ simConfig.filename = 'model_output' # Set file output name simConfig.savePickle = False # Save params, network and sim output to pickle file -simConfig.addAnalysis('plotRaster', True) # Plot a raster -simConfig.addAnalysis('plotTraces', {'include': [('S',0), ('M',0)]}) # Plot recorded traces for this list of cells +simConfig.analysis['plotRaster'] = True # Plot a raster +simConfig.analysis['plotTraces'] = {'include': [('S',0), ('M',0)]} # Plot recorded traces for this list of cells # Create network and run simulation diff --git a/doc/source/code/tut7.py b/doc/source/code/tut7.py index 3907ddefc..88374241d 100644 --- a/doc/source/code/tut7.py +++ b/doc/source/code/tut7.py @@ -17,8 +17,8 @@ netParams = specs.NetParams() # object of class NetParams to store the network parameters # Population parameters -netParams.addPopParams('hop', {'cellType': 'PYR', 'cellModel': 'HH', 'numCells': 50}) # add dict with params for this pop -netParams.addPopParams('background', {'cellModel': 'NetStim', 'rate': 50, 'noise': 0.5}) # background inputs +netParams.popParams['hop'] = {'cellType': 'PYR', 'cellModel': 'HH', 'numCells': 50} # add dict with params for this pop +netParams.popParams['background'] = {'cellModel': 'NetStim', 'rate': 50, 'noise': 0.5} # background inputs # Cell parameters @@ -27,25 +27,25 @@ cellRule['secs']['soma'] = {'geom': {}, 'topol': {}, 'mechs': {}} # soma properties cellRule['secs']['soma']['geom'] = {'diam': 18.8, 'L': 18.8} cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} -netParams.addCellParams('PYR', cellRule) # add dict to list of cell properties +netParams.cellParams['PYR'] = cellRule # add dict to list of cell properties # Synaptic mechanism parameters -netParams.addSynMechParams('exc', {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 1.0, 'e': 0}) -netParams.addSynMechParams('inh', {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 1.0, 'e': -80}) +netParams.synMechParams['exc'] = {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 1.0, 'e': 0} +netParams.synMechParams['inh'] = {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 1.0, 'e': -80} # Connectivity parameters -netParams.addConnParams('bg->hop', - {'preConds': {'popLabel': 'background'}, 'postConds': {'popLabel': 'hop'}, # background -> PYR +netParams.connParams['bg->hop'] = { + 'preConds': {'popLabel': 'background'}, 'postConds': {'popLabel': 'hop'}, # background -> PYR 'weight': 0.1, # fixed weight of 0.1 'synMech': 'exc', # target exc synapse - 'delay': 1}) # uniformly distributed delays between 1-5ms + 'delay': 1} # uniformly distributed delays between 1-5ms -netParams.addConnParams('hop->hop', - {'preConds': {'popLabel': 'hop'}, 'postConds': {'popLabel': 'hop'}, +netParams.connParams['hop->hop'] = { + 'preConds': {'popLabel': 'hop'}, 'postConds': {'popLabel': 'hop'}, 'weight': 0.0, # weight of each connection 'synMech': 'inh', # target inh synapse - 'delay': 5}) # delay + 'delay': 5} # delay ############################################################################### @@ -59,12 +59,12 @@ simConfig.verbose = False # Show detailed messages simConfig.recordTraces = {'V_soma':{'sec':'soma','loc':0.5,'var':'v'}} # Dict with traces to record simConfig.recordStep = 1 # Step size in ms to save data (eg. V traces, LFP, etc) -simConfig.filename = 'model_output' # Set file output name +simConfig.filename = 'model_output' # Set file output name simConfig.savePickle = False # Save params, network and sim output to pickle file -simConfig.addAnalysis('plotRaster', {'syncLines': True}) # Plot a raster -simConfig.addAnalysis('plotTraces', {'include': [1]}) # Plot recorded traces for this list of cells -simConfig.addAnalysis('plot2Dnet', True) # plot 2D visualization of cell positions and connections +simConfig.analysis['plotRaster'] = {'syncLines': True} # Plot a raster +simConfig.analysis['plotTraces'] = {'include': [1]} # Plot recorded traces for this list of cells +simConfig.analysis['plot2Dnet'] = True # plot 2D visualization of cell positions and connections ############################################################################### @@ -73,17 +73,17 @@ from netpyne import sim # Create network and run simulation -sim.initialize( # create network object and set cfg and net params - simConfig = simConfig, # pass simulation config and network params as arguments +sim.initialize( # create network object and set cfg and net params + simConfig = simConfig, # pass simulation config and network params as arguments netParams = netParams) -sim.net.createPops() # instantiate network populations -sim.net.createCells() # instantiate network cells based on defined populations -sim.net.connectCells() # create connections between cells based on params -sim.setupRecording() # setup variables to record for each cell (spikes, V traces, etc) -sim.runSim() # run parallel Neuron simulation -sim.gatherData() # gather spiking data and cell info from each node -sim.saveData() # save params, cell info and sim output to file (pickle,mat,txt,etc) -sim.analysis.plotData() # plot spike raster +sim.net.createPops() # instantiate network populations +sim.net.createCells() # instantiate network cells based on defined populations +sim.net.connectCells() # create connections between cells based on params +sim.setupRecording() # setup variables to record for each cell (spikes, V traces, etc) +sim.runSim() # run parallel Neuron simulation +sim.gatherData() # gather spiking data and cell info from each node +sim.saveData() # save params, cell info and sim output to file (pickle,mat,txt,etc) +sim.analysis.plotData() # plot spike raster # ############################################################################### diff --git a/doc/source/code/tut_import.py b/doc/source/code/tut_import.py index d4bc655c4..f05309514 100644 --- a/doc/source/code/tut_import.py +++ b/doc/source/code/tut_import.py @@ -4,16 +4,16 @@ netParams = specs.NetParams() # object of class NetParams to store the network parameters ## Population parameters -netParams.addPopParams('HH_pop', {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'HH'}) -netParams.addPopParams('HH3D_pop', {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'HH3D'}) -netParams.addPopParams('Traub_pop', {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'Traub'}) -netParams.addPopParams('Mainen_pop', {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'Mainen'}) -netParams.addPopParams('Friesen_pop', {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'Friesen'}) -netParams.addPopParams('Izhi03a_pop', {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'Izhi2003a'}) -netParams.addPopParams('Izhi03b_pop', {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'Izhi2003b'}) -netParams.addPopParams('Izhi07a_pop', {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'Izhi2007a'}) -netParams.addPopParams('Izhi07b_pop', {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'Izhi2007b'}) -netParams.addPopParams('background', {'rate': 50, 'noise': 0.5, 'cellModel': 'NetStim'}) +netParams.popParams['HH_pop'] = {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'HH'} +netParams.popParams['HH3D_pop'] = {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'HH3D'} +netParams.popParams['Traub_pop'] = {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'Traub'} +netParams.popParams['Mainen_pop'] = {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'Mainen'} +netParams.popParams['Friesen_pop'] = {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'Friesen'} +netParams.popParams['Izhi03a_pop'] = {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'Izhi2003a'} +netParams.popParams['Izhi03b_pop'] = {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'Izhi2003b'} +netParams.popParams['Izhi07a_pop'] = {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'Izhi2007a'} +netParams.popParams['Izhi07b_pop'] = {'cellType': 'PYR', 'numCells': 5, 'cellModel': 'Izhi2007b'} +netParams.popParams['background'] = {'rate': 50, 'noise': 0.5, 'cellModel': 'NetStim'} ### HH @@ -64,32 +64,32 @@ ## Synaptic mechanism parameters -netParams.addSynMechParams('AMPA', {'mod': 'Exp2Syn', 'tau1': 1.0, 'tau2': 5.0, 'e': 0}) # soma NMDA synapse +netParams.synMechParams['AMPA'] = {'mod': 'Exp2Syn', 'tau1': 1.0, 'tau2': 5.0, 'e': 0} # soma NMDA synapse ## Connectivity params -netParams.addConnParams('bg1', - {'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': 'PYR', 'cellModel': ['Traub', 'HH', 'HH3D', 'Mainen', 'Izhi2003b', 'Izhi2007b']}, # background -> PYR (weight=0.1) +netParams.connParams['bg1'] = { + 'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': 'PYR', 'cellModel': ['Traub', 'HH', 'HH3D', 'Mainen', 'Izhi2003b', 'Izhi2007b']}, # background -> PYR (weight=0.1) 'connFunc': 'fullConn', # connectivity function (all-to-all) 'weight': 0.1, # synaptic weight 'delay': 5, # transmission delay (ms) - 'sec': 'soma'}) + 'sec': 'soma'} -netParams.addConnParams('bg2', - {'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': 'PYR', 'cellModel': ['Friesen','Izhi2003a', 'Izhi2007a']}, # background -> PYR (weight = 10) +netParams.connParams['bg2'] = { + 'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': 'PYR', 'cellModel': ['Friesen','Izhi2003a', 'Izhi2007a']}, # background -> PYR (weight = 10) 'connFunc': 'fullConn', # connectivity function (all-to-all) 'weight': 5, # synaptic weight 'delay': 5, # transmission delay (ms) 'synMech':'AMPA', - 'sec': 'soma'}) + 'sec': 'soma'} -netParams.addConnParams('recurrent', - {'preConds': {'cellType': 'PYR'}, 'postConds': {'cellType': 'PYR'}, # PYR -> PYR random +netParams.connParams['recurrent'] = { + 'preConds': {'cellType': 'PYR'}, 'postConds': {'cellType': 'PYR'}, # PYR -> PYR random 'connFunc': 'convConn', # connectivity function (random) 'convergence': 'uniform(0,10)', # max number of incoming conns to cell 'weight': 0.001, # synaptic weight 'delay': 5, # transmission delay (ms) - 'sec': 'soma'}) # section to connect to + 'sec': 'soma'} # section to connect to # Simulation options @@ -102,8 +102,8 @@ simConfig.filename = 'model_output' # Set file output name simConfig.savePickle = False # Save params, network and sim output to pickle file -simConfig.addAnalysis('plotRaster', {'orderInverse': True}) # Plot a raster -simConfig.addAnalysis('plotTraces', {'include': [0]}) # Plot recorded traces for this list of cells +simConfig.analysis['plotRaster'] = {'orderInverse': True} # Plot a raster +simConfig.analysis['plotTraces'] = {'include': [0]} # Plot recorded traces for this list of cells # Create network and run simulation diff --git a/doc/source/reference.rst b/doc/source/reference.rst index 6cf48ce4f..209b34910 100644 --- a/doc/source/reference.rst +++ b/doc/source/reference.rst @@ -128,10 +128,12 @@ The value consists in turn of a dictionary with the parameters of the population ``zRange`` for absolute value in um (e.g. [100,200]), or ``znormRange`` for normalized value between 0 and 1 as fraction of ``sizeZ`` (e.g. [0.1,0.2]). -The ``addPopParams(label, params)`` method of the class ``netParams`` can be used to add an item to ``popParams``. This has the advantage of checking the syntax of the parameters added. - Examples of standard population:: + netParams.popParams['Sensory'] = {'cellType': 'PYR', 'cellModel': 'HH', 'ynormRange':[0.2, 0.5], 'density': 50000} + +The ``addPopParams(label, params)`` method of the class ``netParams`` can be used to add an item to ``popParams``. If working interactively, this has the advantage of checking the syntax of the parameters added:: + netParams.addPopParams('Sensory', {'cellType': 'PYR', 'cellModel': 'HH', 'ynormRange':[0.2, 0.5], 'density': 50000}) @@ -152,13 +154,13 @@ It is also possible to create a special type of population consisting of NetStim Example of NetStim population:: - netParams.addPopParams('background', {'cellModel': 'NetStim', 'rate': 100, 'noise': 0.5}) # background inputs + netParams.popParams['background'] = {'cellModel': 'NetStim', 'rate': 100, 'noise': 0.5} # background inputs Finally, it is possible to define a population composed of individually-defined cells by including the list of cells in the ``cellsList`` dictionary field. Each element of the list of cells will in turn be a dictionary containing any set of cell properties such as ``cellLabel`` or location (e.g. ``x`` or ``ynorm``). An example is shown below:: cellsList.append({'cellLabel':'gs15', 'x': 1, 'ynorm': 0.4 , 'z': 2}) cellsList.append({'cellLabel':'gs21', 'x': 2, 'ynorm': 0.5 , 'z': 3}) - netParams.addPopParams('IT_cells', {'cellModel':'Izhi2007b', 'cellType':'IT', 'cellsList': cellsList}) # IT individual cells + netParams.popParams['IT_cells'] = {'cellModel':'Izhi2007b', 'cellType':'IT', 'cellsList': cellsList} # IT individual cells .. _cell_property_rules: @@ -232,14 +234,14 @@ Example of two cell property rules added using different valid approaches:: cellRule['secs']['soma']['geom'] = {'diam': 18.8, 'L': 18.8, 'Ra': 123.0} cellRule['secs']['soma']['pointps']['Izhi'] = {'mod':'Izhi2007a', 'vref':'V', 'a':0.03, 'b':-2, 'c':-50, 'd':100, 'celltype':1} - netParams.addCellParams('PYR_Izhi', cellRule) # add rule to list of cell property rules + netParams.cellParams['PYR_Izhi'] = cellRule # add rule to list of cell property rules .. note:: As in the examples above, you can use temporary variables/structures (e.g. ``soma`` or ``cellRule``) to facilitate the creation of the final dictionary ``netParams.cellParams``. .. ​note:: Several cell properties may be applied to the same cell if the conditions match. The latest cell properties will overwrite previous ones if there is an overlap. -.. note:: You can directly create or modify the cell parameters via ``netParams.cellParams``, e.g. ``netParams.cellParams['PYR_HH']['secs']['soma']['geom']['L']=16``. The only reason for using the ``addCellParams()`` method is that it checks that all required parameters are included and the syntax is right. +.. note:: You can directly create or modify the cell parameters via ``netParams.cellParams``, e.g. ``netParams.cellParams['PYR_HH']['secs']['soma']['geom']['L']=16``. .. seealso:: Cell properties can be imported from an external file. See :ref:`importing_cells` for details and examples. @@ -253,6 +255,8 @@ To define the parameteres of a synaptic mechanism, add items to the ``synMechPar * mechanism parameters (e.g. ``tau`` or ``e``) - these will depend on the specific NMODL mechanism. +* ``selfNetCon`` (optional) - Dict with parameters of NetCon between the cell voltage and the synapse, required by some synaptic mechanisms such as the homeostatic synapse (hsyn). e.g. ``'selfNetCon': {'sec': 'soma' , threshold': -15, 'weight': -1, 'delay': 0}`` (by default the source section, 'sec' = 'soma') + Synaptic mechanisms will be added to cells as required during the connection phase. Each connectivity rule will specify which synaptic mechanism parameters to use by referencing the appropiate label. Example of synaptic mechanism parameters for a simple excitatory synaptic mechanism labeled ``NMDA``, implemented using the ``Exp2Syn`` model, with rise time (``tau1``) of 0.1 ms, decay time (``tau2``) of 5 ms, and equilibrium potential (``e``) of 0 mV: @@ -260,7 +264,7 @@ Example of synaptic mechanism parameters for a simple excitatory synaptic mechan .. code-block:: python ## Synaptic mechanism parameters - netParams.addSynMechParams('AMPA', {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 5.0, 'e': 0}) # NMDA synaptic mechanism + netParams.synMechParams['AMPA'] = {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 5.0, 'e': 0} # NMDA synaptic mechanism Connectivity rules @@ -377,35 +381,55 @@ Each item of the ``connParams`` ordered dictionary consists of a key and value. User-defined connectivity functions can be added. +* **shape** (optional) - Modifies the conn weight dynamically during the simulation based on the specified pattern. + Contains a dictionary with the following fields: + + ``'switchOnOff`` - times at which to switch on and off the weight + + ``'pulseType'`` - type of pulse to generate; either 'square' or 'gaussian' + + ``'pulsePeriod'`` - period (in ms) of the pulse + + ``'pulseWidth'`` - width (in ms) of the pulse + + Can be used to generate complex stimulation patterns, with oscillations or turning on and off at specific times. + + e.g. ``'shape': {'switchOnOff': [200, 800], 'pulseType': 'square', 'pulsePeriod': 100, 'pulseWidth': 50}`` + +* **plasticity** (optional) - Plasticity mechanism to use for this connections. + Requires 2 fields: ``mech`` to specifiy the name of the plasticity mechanism, and ``params`` containing a dictionary with the parameters of the mechanism + + e.g. ``{'mech': 'STDP', 'params': {'hebbwt': 0.01, 'antiwt':-0.01, 'wmax': 50, 'RLon': 1 'tauhebb': 10}}`` + Example of connectivity rules: .. code-block:: python ## Cell connectivity rules - netParams.addConnParams('S->M', + netParams.connParams['S->M'] = { 'preConds': {'popLabel': 'S'}, 'postConds': {'popLabel': 'M'}, # S -> M 'sec': 'dend', # target postsyn section 'synMech': 'AMPA', # target synaptic mechanism 'weight': 0.01, # synaptic weight 'delay': 5, # transmission delay (ms) - 'probability': 0.5}) # probability of connection + 'probability': 0.5} # probability of connection - netParams.addConnParams('bg->all', - {'preConds': {'popLabel': 'background'}, + netParams.connParams['bg->all'] = { + 'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': ['S','M'], 'ynorm': [0.1,0.6]}, # background -> S,M with ynrom in range 0.1 to 0.6 'synReceptor': 'AMPA', # target synaptic mechanism 'weight': 0.01, # synaptic weight 'delay': 5} # transmission delay (ms) - netParams.addConnParams('yrange->HH', + netParams.connParams['yrange->HH'] = { {'preConds': {'y': [100, 600]}, 'postConds': {'cellModel': 'HH'}, # cells with y in range 100 to 600 -> cells implemented using HH models 'synMech': ['AMPA', 'NMDA'], # target synaptic mechanisms 'synsPerConn': 3, # number of synapses per cell connection (per synMech, ie. total syns = 2 x 3) 'weight': 0.02, # single weight for all synapses 'delay': [5, 10], # different delays for each of 3 synapses per synMech - 'loc': [[0.1, 0.5, 0.7], [0.3, 0.4, 0.5]]}) # different locations for each of the 6 synapses + 'loc': [[0.1, 0.5, 0.7], [0.3, 0.4, 0.5]]} # different locations for each of the 6 synapses .. note:: NetStim populations can only serve as presynaptic source of a connection. Additionally, only the ``fullConn`` (default) and ``probConn`` (using ``probability`` parameter) connectivity functions can be used to connect NetStims. NetStims are created *on the fly* during the implementation of the connectivity rules, instantiating one NetStim per postsynaptic cell. @@ -458,7 +482,7 @@ String-based functions add great flexibility and power to NetPyNE connectivity r .. code-block:: python - netParams.addConnParams(... + netParams.connParams[...] = { 'convergence': 'uniform(1,15)', # ... @@ -466,7 +490,7 @@ String-based functions add great flexibility and power to NetPyNE connectivity r .. code-block:: python - netParams.addConnParams(... + netParams.connParams[...] = { 'delay': '0.2 + gauss(13.0,1.4)', # ... @@ -480,7 +504,7 @@ String-based functions add great flexibility and power to NetPyNE connectivity r # ... - netParams.addConnParams(... + netParams.connParams[...] = { 'delay': 'delayMin + gauss(delayMean, delayVar)', # ... @@ -488,7 +512,7 @@ String-based functions add great flexibility and power to NetPyNE connectivity r .. code-block:: python - netParams.addConnParams(... + netParams.connParams[...] = { 'delay': 'defaultDelay + dist_3D/propVelocity', # ... @@ -496,7 +520,7 @@ String-based functions add great flexibility and power to NetPyNE connectivity r .. code-block:: python - netParams.addConnParams(... + netParams.connParams[...] = { 'probability': '0.1+0.2*post_y', # ... @@ -508,7 +532,7 @@ String-based functions add great flexibility and power to NetPyNE connectivity r # ... - netParams.addConnParams(... + netParams.connParams[...] = { 'probability': 'exp(-dist_2D/lengthConst)', # ... @@ -562,38 +586,34 @@ The code below shows an example of how to create different types of stimulation # Stimulation parameters ## Stimulation sources parameters - netParams.addStimSourceParams('Input_1', - {'type': 'IClamp', 'delay': 10, 'dur': 800, 'amp': 'uniform(0.05,0.5)'}) + netParams.stimSourceParams['Input_1'] = {'type': 'IClamp', 'delay': 10, 'dur': 800, 'amp': 'uniform(0.05,0.5)'} - netParams.addStimSourceParams('Input_2', - {'type': 'VClamp', 'dur':[0,1,1], 'amp':[1,1,1],'gain':1, 'rstim':0, 'tau1':1, 'tau2':1, 'i':1}) + netParams.stimSourceParams['Input_2'] = {'type': 'VClamp', 'dur':[0,1,1], 'amp':[1,1,1],'gain':1, 'rstim':0, 'tau1':1, 'tau2':1, 'i':1} - netParams.addStimParams('Input_3', - {'type': 'AlphaSynapse', 'onset': 'uniform(1,500)', 'tau': 5, 'gmax': 'post_ynorm', 'e': 0}) + netParams.stimSourceParams(['Input_3'] = {'type': 'AlphaSynapse', 'onset': 'uniform(1,500)', 'tau': 5, 'gmax': 'post_ynorm', 'e': 0} - netParams.addStimParams('Input_4', - {'type': 'NetStim', 'interval': 'uniform(20,100)', 'number': 1000, 'start': 5, 'noise': 0.1}) + netParams.stimSourceParams['Input_4'] = {'type': 'NetStim', 'interval': 'uniform(20,100)', 'number': 1000, 'start': 5, 'noise': 0.1} ## Stimulation mapping parameters - netParams.addStimTargetParams('Input1->PYR', - {'source': 'Input_1', + netParams.stimTargetParams['Input1->PYR'] = { + 'source': 'Input_1', 'sec':'soma', 'loc': 0.5, 'conds': {'popLabel':'PYR', 'cellList': range(8)}}) - netParams.addStimTargetParams('Input3->Basket', - {'source': 'Input_3', + netParams.stimTargetParams['Input3->Basket'] = { + 'source': 'Input_3', 'sec':'soma', 'loc': 0.5, - 'conds': {'cellType':'Basket'}}) + 'conds': {'cellType':'Basket'}} - netParams.addStimTargetParams('Input4->PYR3', - {'source': 'Input_4', + netParams.stimTargetParams['Input4->PYR3'] = { + 'source': 'Input_4', 'sec':'soma', 'loc': 0.5, 'weight': '0.1+gauss(0.2,0.05)', 'delay': 1, - 'conds': {'popLabel':'PYR3', 'cellList': [0,1,2,5,10,14,15]}}) + 'conds': {'popLabel':'PYR3', 'cellList': [0,1,2,5,10,14,15]}} @@ -854,6 +874,20 @@ Methods to modify network e.g. ``{'soma': {'geom': {'L': 100}}}`` sets the soma length to 100 um. +* **net.modifySynMechs(params)** + + Modifies properties of synMechs in an instantiated network. The ``params`` argument is a dictionary with the following 3 items: + + - 'conds': dictionary of conditions to select synMechs that will be modified, with each item containing a synMech tag, and the desired value ([min, max] range format allowed). + + e.g. ``{'label': 'AMPA', 'sec': 'soma', 'loc': [0, 0.5]}`` targets synMechs with the label 'AMPA', at the soma section, with locations between 0 and 0.5. + + - 'cellConds': dictionary of conditions to select target cells that will contain the synMechs to be modified, with each item containing a cell tag (see list of tags available :ref:`cell_class_data_model`), and the desired value ([min, max] range format allowed). + + e.g. ``{'popLabel': 'PYR', 'ynorm': [0.1, 0.6]}`` targets connections of cells from the 'PYR' population with normalized depth within 0.1 and 0.6. + + - '[synMech property]' (e.g. 'tau1' or 'e'): New value for stim property (note that properties depend on the type of synMech). Can include several synMech properties to modify. + * **net.modifyConns(params)** @@ -868,7 +902,7 @@ Methods to modify network e.g. ``{'popLabel': 'PYR', 'ynorm': [0.1, 0.6]}`` targets connections of cells from the 'PYR' population with normalized depth within 0.1 and 0.6. - - 'weight' | 'threshold': New value for connection weight or threshold. + - 'weight' | 'threshold': New value for connection weight or threshold. Can include both. * **net.modifyStims(params)** @@ -878,13 +912,13 @@ Methods to modify network - 'conds': dictionary of conditions to select stims that will be modified, with each item containing a stim tag (see list of stim tags available :ref:`cell_class_data_model`), and the desired value ([min, max] range format allowed). e.g. ``{'label': 'VClamp1->S'}`` targets stims that were created using the stimTargetParms rule labeled 'VClamp1->S'. - e.g. ``{'source': 'IClamp2', 'dur': [100, 300]} targets stims that have as source 'Netstim2' (defined in stimSourceParams), with a duration between 100 and 300 ms. + e.g. ``{'source': 'IClamp2', 'dur': [100, 300]}`` targets stims that have as source 'Netstim2' (defined in stimSourceParams), with a duration between 100 and 300 ms. - 'cellConds': dictionary of conditions to select target cells that will contain the stims to be modified, with each item containing a cell tag (see list of tags available :ref:`cell_class_data_model`), and the desired value ([min, max] range format allowed). e.g. ``{'popLabel': 'PYR', 'ynorm': [0.1, 0.6]}`` targets connections of cells from the 'PYR' population with normalized depth within 0.1 and 0.6. - - '[stim property]' (e.g. 'dur', 'amp' or 'delay'): New value for stim property (note that properties depend on the type of stim). + - '[stim property]' (e.g. 'dur', 'amp' or 'delay'): New value for stim property (note that properties depend on the type of stim). Can include several stim properties to modify. Population class methods diff --git a/doc/source/tutorial.rst b/doc/source/tutorial.rst index c69eaebf4..c336c2146 100644 --- a/doc/source/tutorial.rst +++ b/doc/source/tutorial.rst @@ -120,7 +120,8 @@ We will now create a new model file (call it ``tut2.py``) where we will specify Populations ^^^^^^^^^^^^^^^^^^^^^^ -First, we need to create some populations for our network, by adding items to the ``popParams`` dictionary in ``netParams``. The ``netParams`` object provides a method ``addPopParams(label, params)`` to easily do this, where ``label`` is an arbitrary label for the population (can be used as reference later), and ``params`` is a dictionary with the following population parameters (see :ref:`pop_params` for more details): +First, we need to create some populations for our network, by adding items to the ``popParams`` dictionary in ``netParams``. Each ``popParams`` item includes a key (population label) and a value consisting of a dictionary with the following population parameters (see :ref:`pop_params` for more details): + * ``cellType`` - an attribute/tag assigned to cells in this population, can later be used to set certain cell properties to cells with this tag. @@ -131,21 +132,21 @@ First, we need to create some populations for our network, by adding items to th We will start by creating 2 populations labeled ``S`` (sensory) and ``M`` (motor), with ``20`` cells each, of type ``PYR`` (pyramidal), and using ``HH`` cell model (standard compartmental Hodgkin-Huxley type cell). ## Population parameters - netParams.addPopParams('S', {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'}) - netParams.addPopParams('M', {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'}) + netParams.popParams['S'] = {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'} + netParams.popParams['M'] = {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'HH'} During execution, this will tell NetPyNE to create 40 ``Cell`` objects, each of which will include the attributes or tags of its population, i.e. 'cellType': 'PYR', etc. These tags can later be used to define the properties of the cells, or connectivity rules. Lets now add a special type of population used to provide background driving inputs to the cells, labeled ``background``. In this case the cell model will be ``NetStim`` (NEURON's artificial spike generator), and we will specify we want a firing rate of ``100`` Hz and with a noise level of ``0.5``:: - netParams.addPopParams('background', {'rate': 10, 'noise': 0.5, 'cellModel': 'NetStim'}) + netParams.popParams['background'] = {'rate': 10, 'noise': 0.5, 'cellModel': 'NetStim'} To get a better intuition of the data structure, you can ``print netParams.popParams`` to see all the populations parameters, or print ``print netParams.popParams['M']`` to see the parameters of population 'M'. Cell property rules ^^^^^^^^^^^^^^^^^^^^^^^^^^ -Now we need to define the properties of each cell type, by adding items to the ``cellParams`` dictionary. We can use the ``netParams`` method ``addCellParams(label, params)``, where ``label`` is an arbitrary label for this rule (doesn't need to be same as cell type), and ``params`` is a dictionary with the following two fields: +Now we need to define the properties of each cell type, by adding items to the ``cellParams`` dictionary. Each ``cellParams`` item includes a key (cell rule label) and a value consisting of a dictionary with the following two fields: * ``conds`` - these arbitrary conditions need to be met by cells in order to apply them these cell properties. Usually defined specifying an attribute/tag of the cell and the required value e.g. 'cellType': 'PYR' @@ -159,13 +160,13 @@ In our example we create a cell property rule that applies to all cells where th cellRule['secs']['soma'] = {'geom': {}, 'mechs': {}} # soma params dict cellRule['secs']['soma']['geom'] = {'diam': 18.8, 'L': 18.8, 'Ra': 123.0} # soma geometry cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} # soma hh mechanism - netParams.addCellParams('PYRrule', cellRule) + netParams.cellParams['PYRrule'] = cellRule Take a moment to examine the nested dictionary structure used to define the cell property rule. Notice the use of empty dictionaries (``{}``) and intermediate dictionaries (eg. ``cellRule``) to facilitate filling in the parameters. There are other equivalent methods to add this rule, such as:: - netParams.addCellParams('PYRrule', # cell rule label - {'conds': {'cellType': 'PYR'}, # properties will be applied to cells that match these conditions + netParams.cellParams['PYRrule'] = { # cell rule label + 'conds': {'cellType': 'PYR'}, # properties will be applied to cells that match these conditions 'secs': {'soma': # sections {'geom': {'diam': 18.8, 'L': 18.8, 'Ra': 123.0}, # geometry 'mechs': {'hh': {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70}}}}}) # mechanisms @@ -182,7 +183,7 @@ All methods are equally valid as long as the resulting structure looks like this Synaptic mechanisms parameters ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Next we need to define the parameters of at least one synaptic mechanism, by adding items to the ``synMechParams`` dictionary via ``addSynMechParams(label, params)`` method; where ``label`` is an arbitrary label for this mechanism (used to reference it in the connectivity rules); and ``params`` is a dictionary with the following fields: +Next we need to define the parameters of at least one synaptic mechanism, by adding items to the ``synMechParams`` dictionary. Each ``synMechParams`` items includes a key (synMech label, used to reference it in the connectivity rules), and a value consisting of a dictionary with the following fields: * ``mod`` - the NMODL mechanism (eg. 'ExpSyn') @@ -191,13 +192,13 @@ Next we need to define the parameters of at least one synaptic mechanism, by add Synaptic mechanisms will be added to cells as required during the connection phase. Each connectivity rule will specify which synaptic mechanism parameters to use by referencing the appropiate label. In our network we will define the parameters of a simple excitatory synaptic mechanism labeled ``exc``, implemented using the ``Exp2Syn`` model, with rise time (``tau1``) of 0.1 ms, decay time (``tau2``) of 5 ms, and equilibrium potential (``e``) of 0 mV:: ## Synaptic mechanism parameters - netParams.addSynMechParams('exc', {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 5.0, 'e': 0}) # excitatory synaptic mechanism + netParams.synMechParams['exc'] = {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 5.0, 'e': 0} # excitatory synaptic mechanism Connectivity rules ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Finally, we need to specify how to connect the cells, by adding items (connectivity rules) to the ``connParams`` dictionary, using the ``addConnParams(label, params)`` method. The ``label`` is an arbitrary name for this conenction, and ``params`` consists of a dictionary with the following fields: +Finally, we need to specify how to connect the cells, by adding items (connectivity rules) to the ``connParams`` dictionary. Each ``connParams`` item includes a key (conn rule label), and a values consisting of a dictionary with the following fields: * ``preConds`` - specifies the conditions of the presynaptic cells @@ -214,8 +215,8 @@ Finally, we need to specify how to connect the cells, by adding items (connectiv We will first add a rule to randomly connect the sensory to the motor population with a 50% probability:: ## Cell connectivity rules - netParams.addConnParams('S->M', # S -> M label - {'preConds': {'popLabel': 'S'}, # conditions of presyn cells + netParams.connParams['S->M'] = { # S -> M label + 'preConds': {'popLabel': 'S'}, # conditions of presyn cells 'postConds': {'popLabel': 'M'}, # conditions of postsyn cells 'probability': 0.5, # probability of connection 'weight': 0.01, # synaptic weight @@ -224,8 +225,8 @@ We will first add a rule to randomly connect the sensory to the motor population Next we will connect background inputs (NetStims) to all cells of both populations:: - netParams.addConnParams('bg->PYR', # background -> PYR label - {'preConds': {'popLabel': 'background'}, + netParams.connParams['bg->PYR'] = { # background -> PYR label + 'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': 'PYR'}, 'weight': 0.01, # synaptic weight 'delay': 5, # transmission delay (ms) @@ -252,9 +253,9 @@ Below we include the options required to run a simulation of 1 second, with intg simConfig.filename = 'model_output' # Set file output name simConfig.savePickle = False # Save params, network and sim output to pickle file - simConfig.addAnalysis('plotRaster', True) # Plot a raster - simConfig.addAnalysis('plotTraces', {'include': [1]}) # Plot recorded traces for this list of cells - simConfig.addAnalysis('plot2Dnet', True) # plot 2D visualization of cell positions and connections + simConfig.analysis['plotRaster'] = True # Plot a raster + simConfig.analysis['plotTraces'] = {'include': [1]} # Plot recorded traces for this list of cells + simConfig.analysis['plot2Dnet'] = True # plot 2D visualization of cell positions and connections The complete list of simulation configuration options is available here: :ref:`sim_config`. @@ -308,18 +309,18 @@ Here we extend the pyramidal cell type by adding a dendritic section with a pass cellRule['secs']['dend']['geom'] = {'diam': 5.0, 'L': 150.0, 'Ra': 150.0, 'cm': 1} # dend geometry cellRule['secs']['dend']['topol'] = {'parentSec': 'soma', 'parentX': 1.0, 'childX': 0} # dend topology cellRule['secs']['dend']['mechs']['pas'] = {'g': 0.0000357, 'e': -70} # dend mechanisms - netParams.addCellParams('PYRrule', cellRule) # add dict to list of cell parameters + netParams.cellParams['PYRrule'] = cellRule # add dict to list of cell parameters We can also update the connectivity rule to specify that the ``S`` cells should connect to the dendrite of ``M`` cells, by adding the dict entry ``'sec': 'dend'`` as follows:: - netParams.addConnParams('S->M', {'preConds': {'popLabel': 'S'}, 'postConds': {'popLabel': 'M'}, # S -> M + netParams.connParams['S->M'] = {'preConds': {'popLabel': 'S'}, 'postConds': {'popLabel': 'M'}, # S -> M 'probability': 0.5, # probability of connection 'weight': 0.01, # synaptic weight 'delay': 5, # transmission delay (ms) 'sec': 'dend', # section to connect to 'loc': 1.0, # location of synapse - 'synMech': 'exc'}) # target synaptic mechanism + 'synMech': 'exc'} # target synaptic mechanism The full tutorial code for this example is available here: :download:`tut3.py `. @@ -339,7 +340,7 @@ Next we need to compile this .mod file so its ready to use by NEURON:: Now we need to specify that we want to use the ``Izhi2007b`` ``cellModel`` for the ``S`` population:: - netParams.addPopParams('S', {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'Izhi2007b'}) + netParams.popParams['S'] = {'cellType': 'PYR', 'numCells': 20, 'cellModel': 'Izhi2007b'} And we need to create a new cell rule for the Izhikevich cell. But first we need to specify that the existing rule needs to apply only to 'HH' cell models:: @@ -352,7 +353,7 @@ Finally we can create the new rule for the Izhikevich cell model:: cellRule['secs']['soma']['geom'] = {'diam': 10.0, 'L': 10.0, 'cm': 31.831} # soma geometry cellRule['secs']['soma']['pointps']['Izhi'] = {'mod':'Izhi2007b', 'C':1, 'k':0.7, 'vr':-60, 'vt':-40, 'vpeak':35, 'a':0.03, 'b':-2, 'c':-50, 'd':100, 'celltype':1} # soma hh mechanisms - netParams.addCellParams('PYR_Izhi_rule', cellRule) # add dict to list of cell parameters + netParams.cellParams['PYR_Izhi_rule'] = cellRule # add dict to list of cell parameters Notice we have added a new field inside the ``soma`` called ``pointps``, which will include the point process mechanisms in the section. In this case we added the ``Izhi2007b`` point process and provided a dict with the Izhikevich cell parameters corresponding to the pyramidal regular spiking cell. Further details and other parameters for the Izhikevich cell model can be found here: https://senselab.med.yale.edu/modeldb/showModel.cshtml?model=39948 @@ -386,13 +387,13 @@ Note that we also added two parameters (``propVelocity`` and ``probLengthConst`` Next we can create our background input popualtion and the 6 cortical populations labeled according to the cell type and layer eg. 'E2' for excitatory cells in layer 2. We can define the cortical depth range of each population by using the ``yRange`` parameter, eg. to place layer 2 cells between 100 and 300 um depth: ``'yRange': [100,300]``. This range can also be specified using normalized values, eg. ``'yRange': [0.1,0.3]``. In the code below we provide examples of both methods for illustration:: ## Population parameters - netParams.addPopParams('E2', {'cellType': 'E', 'numCells': 50, 'yRange': [100,300], 'cellModel': 'HH'}) - netParams.addPopParams('I2', {'cellType': 'I', 'numCells': 50, 'yRange': [100,300], 'cellModel': 'HH'}) - netParams.addPopParams('E4', {'cellType': 'E', 'numCells': 50, 'yRange': [300,600], 'cellModel': 'HH'}) - netParams.addPopParams('I4', {'cellType': 'I', 'numCells': 50, 'yRange': [300,600], 'cellModel': 'HH'}) - netParams.addPopParams('E5', {'cellType': 'E', 'numCells': 50, 'ynormRange': [0.6,1.0], 'cellModel': 'HH'}) - netParams.addPopParams('I5', {'cellType': 'I', 'numCells': 50, 'ynormRange': [0.6,1.0], 'cellModel': 'HH'}) - netParams.addPopParams('background', {'rate': 20, 'noise': 0.3, 'cellModel': 'NetStim'}) + netParams.popParams['E2'] = {'cellType': 'E', 'numCells': 50, 'yRange': [100,300], 'cellModel': 'HH'} + netParams.popParams['I2'] = {'cellType': 'I', 'numCells': 50, 'yRange': [100,300], 'cellModel': 'HH'} + netParams.popParams['E4'] = {'cellType': 'E', 'numCells': 50, 'yRange': [300,600], 'cellModel': 'HH'} + netParams.popParams['I4'] = {'cellType': 'I', 'numCells': 50, 'yRange': [300,600], 'cellModel': 'HH'} + netParams.popParams['E5'] = {'cellType': 'E', 'numCells': 50, 'ynormRange': [0.6,1.0], 'cellModel': 'HH'} + netParams.popParams['I5'] = {'cellType': 'I', 'numCells': 50, 'ynormRange': [0.6,1.0], 'cellModel': 'HH'} + netParams.popParams['background'] = {'rate': 20, 'noise': 0.3, 'cellModel': 'NetStim'} Next we define the cell properties of each type of cell ('E' for excitatory and 'I' for inhibitory). We have made minor random modifications of some cell parameters just to illustrate that different cell types can have different properties:: @@ -402,30 +403,30 @@ Next we define the cell properties of each type of cell ('E' for excitatory and cellRule['secs']['soma'] = {'geom': {}, 'mechs': {}} # soma params dict cellRule['secs']['soma']['geom'] = {'diam': 15, 'L': 14, 'Ra': 120.0} # soma geometry cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.13, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} # soma hh mechanism - netParams.addCellParams('Erule', cellRule) # add dict to list of cell params + netParams.cellParams['Erule'] = cellRule # add dict to list of cell params cellRule = {'conds': {'cellType': 'I'}, 'secs': {}} # cell rule dict cellRule['secs']['soma'] = {'geom': {}, 'mechs': {}} # soma params dict cellRule['secs']['soma']['geom'] = {'diam': 10.0, 'L': 9.0, 'Ra': 110.0} # soma geometry cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.11, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} # soma hh mechanism - netParams.addCellParams('Irule', cellRule) # add dict to list of cell params + netParams.cellParams['Irule'] = cellRule # add dict to list of cell params As in previous examples we also add the parameters of the excitatory and inhibitory synaptic mechanisms, which will be added to cells when the connections are created:: ## Synaptic mechanism parameters - netParams.addSynMechParams('exc', {'mod': 'Exp2Syn', 'tau1': 0.8, 'tau2': 5.3, 'e': 0}) # NMDA synaptic mechanism - netParams.addSynMechParams('inh', {'mod': 'Exp2Syn', 'tau1': 0.6, 'tau2': 8.5, 'e': -75}) # GABA synaptic mechanism + netParams.synMechParams['exc'] = {'mod': 'Exp2Syn', 'tau1': 0.8, 'tau2': 5.3, 'e': 0} # NMDA synaptic mechanism + netParams.synMechParams['inh'] = {'mod': 'Exp2Syn', 'tau1': 0.6, 'tau2': 8.5, 'e': -75} # GABA synaptic mechanism In terms of connectivity, we'll start by adding background inputs to all cell in the network. The weight will be fixed to 0.01, but we'll make the delay come from a gaussian distribution with mean 5 ms and standard deviation 2, and have a minimum value of 1 ms. We can do this using string-based functions: ``'max(1, gauss(5,2)'``. As detailed in section :ref:`function_string`, string-based functions allow you to define connectivity params using many Python mathematical operators and functions. The full code to add background inputs looks like this:: ## Cell connectivity rules - netParams.addConnParams('bg->all', - {'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': ['E', 'I']}, # background -> all + netParams.connParams['bg->all'] = { + 'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': ['E', 'I']}, # background -> all 'weight': 0.01, # synaptic weight 'delay': 'max(1, gauss(5,2))', # transmission delay (ms) - 'synMech': 'exc'}) # synaptic mechanism + 'synMech': 'exc'} # synaptic mechanism We can now add the standard simulation configuration options and the code to create and run the network. Notice that we have chosen to record and plot voltage traces of one cell in each of the excitatory populations (``{'include': [('E2',0), ('E4', 0), ('E5', 5)]})``), plot the raster ordered based on cell cortical depth (``{'orderBy': 'y', 'orderInverse': True})``), show a 2D visualization of cell positions and connections, and plot the connectivity matrix:: @@ -440,10 +441,10 @@ We can now add the standard simulation configuration options and the code to cre simConfig.filename = 'model_output' # Set file output name simConfig.savePickle = False # Save params, network and sim output to pickle file - simConfig.addAnalysis('plotRaster', {'orderBy': 'y', 'orderInverse': True}) # Plot a raster - simConfig.addAnalysis('plotTraces', {'include': [('E2',0), ('E4', 0), ('E5', 5)]}) # Plot recorded traces for this list of cells - simConfig.addAnalysis('plot2Dnet', True) # plot 2D visualization of cell positions and connections - simConfig.addAnalysis('plotConn', True) # plot connectivity matrix + simConfig.analysis['plotRaster'] = {'orderBy': 'y', 'orderInverse': True} # Plot a raster + simConfig.analysis['plotTraces'] = {'include': [('E2',0), ('E4', 0), ('E5', 5)]} # Plot recorded traces for this list of cells + simConfig.analysis['plot2Dnet'] = True # plot 2D visualization of cell positions and connections + simConfig.analysis['plotConn'] = True # plot connectivity matrix # Create network and run simulation sim.createSimulateAnalyze(netParams = netParams, simConfig = simConfig) @@ -461,12 +462,12 @@ Second, lets make the the connection weight be proportional to the cortical dept Finally, we can specify the delay based on the distance between the cells (``dist_3D``) and the propagation velocity (given as a parameter at the beginning of the code), as follows: ``'delay': 'dist_3D/propVelocity'``. The full code for this connectivity rules is:: - netParams.addConnParams('E->all', - {'preConds': {'cellType': 'E'}, 'postConds': {'y': [100,1000]}, # E -> all (100-1000 um) + netParams.connParams['E->all'] = { + 'preConds': {'cellType': 'E'}, 'postConds': {'y': [100,1000]}, # E -> all (100-1000 um) 'probability': 0.1 , # probability of connection 'weight': '0.005*post_ynorm', # synaptic weight 'delay': 'dist_3D/propVelocity', # transmission delay (ms) - 'synMech': 'exc'}) # synaptic mechanism + 'synMech': 'exc'} # synaptic mechanism Running the model now shows excitatory connections in red, and how cells in the deeper layers (higher y values) exhibit lower rates and higher synchronization, due to increased weights leading to depolarization blockade. This difference is also visible in the voltage traces of layer 2 vs layer 5 cells: @@ -480,12 +481,12 @@ Finally, we add inhibitory connections which will project only onto excitatory c To make the probability of connection decay exponentiall as a function of distance with a given length constant (``probLengthConst``), we can use the following distance-based expression: ``'probability': '0.4*exp(-dist_3D/probLengthConst)'``. The code for the inhibitory connectivity rule is therefore:: - netParams.addConnParams('I->E', - {'preConds': {'cellType': 'I'}, 'postConds': {'popLabel': ['E2','E4','E5']}, # I -> E + netParams.connParams['I->E'] = { + 'preConds': {'cellType': 'I'}, 'postConds': {'popLabel': ['E2','E4','E5']}, # I -> E 'probability': '0.4*exp(-dist_3D/probLengthConst)', # probability of connection 'weight': 0.001, # synaptic weight 'delay': 'dist_3D/propVelocity', # transmission delay (ms) - 'synMech': 'inh'}) # synaptic mechanism + 'synMech': 'inh'} # synaptic mechanism Notice that the 2D network diagram now shows inhibitory connections in blue, and these are mostly local/lateral within layers, due to the distance-related probability restriction. These local inhibitory connections reduce the overall synchrony, introducing some richness into the temporal firing patterns of the network. @@ -501,24 +502,24 @@ The full tutorial code for this example is available here: :download:`tut5.py `, remove all connection parameters, and add external stimulation instead. -Below we use the ``netParams.addStimSourceParams()`` method to easily add four typical NEURON sources of stimulation, each of a different type: IClamp, VClamp, AlphaSynapse, NetStim. Note that parameters values can also include string-based functions (:ref:`function_string`), for example to set a uniform distribution of onset values (``'onset': 'uniform(600,800)'``), or maximum conductance dependent on the target cell normalized depth (``'gmax': 'post_ynorm'``):: +Below we add four typical NEURON sources of stimulation, each of a different type: IClamp, VClamp, AlphaSynapse, NetStim. Note that parameters values can also include string-based functions (:ref:`function_string`), for example to set a uniform distribution of onset values (``'onset': 'uniform(600,800)'``), or maximum conductance dependent on the target cell normalized depth (``'gmax': 'post_ynorm'``):: - netParams.addStimSourceParams('Input_1', {'type': 'IClamp', 'delay': 300, 'dur': 100, 'amp': 'uniform(0.4,0.5)'}) - netParams.addStimSourceParams('Input_2', {'type': 'VClamp', 'dur': [0,50,200], 'amp': [-60,-30,40], 'gain': 1e5, 'rstim': 1, 'tau1': 0.1, 'tau2': 0}) - netParams.addStimSourceParams('Input_3', {'type': 'AlphaSynapse', 'onset': 'uniform(300,600)', 'tau': 5, 'gmax': 'post_ynorm', 'e': 0}) - netParams.addStimSourceParams('Input_4', {'type': 'NetStim', 'interval': 'uniform(20,100)', 'number': 1000, 'start': 600, 'noise': 0.1}) + netParams.stimSourceParams['Input_1'] = {'type': 'IClamp', 'delay': 300, 'dur': 100, 'amp': 'uniform(0.4,0.5)'} + netParams.stimSourceParams['Input_2'] = {'type': 'VClamp', 'dur': [0,50,200], 'amp': [-60,-30,40], 'gain': 1e5, 'rstim': 1, 'tau1': 0.1, 'tau2': 0} + netParams.stimSourceParams['Input_3'] = {'type': 'AlphaSynapse', 'onset': 'uniform(300,600)', 'tau': 5, 'gmax': 'post_ynorm', 'e': 0} + netParams.stimSourceParams['Input_4'] = {'type': 'NetStim', 'interval': 'uniform(20,100)', 'number': 1000, 'start': 600, 'noise': 0.1} -Now we can map or apply any of the above stimulation sources to any subset of cells in the network, using the ``netParams.addStimTargetParams()``. Note that we can use any of the cell tags (e.g. 'popLabel', 'cellType' or 'ynorm') to select what cells will be stimulated. Additionally, using the 'cellList' option, we can target a specific list of cells (using relative cell ids) within the subset of cells selected (e.g. first 15 cells of the 'S' population):: +Now we can map or apply any of the above stimulation sources to any subset of cells in the networkby adding items to the ``stimTargetParams`` dict. Note that we can use any of the cell tags (e.g. 'popLabel', 'cellType' or 'ynorm') to select what cells will be stimulated. Additionally, using the 'cellList' option, we can target a specific list of cells (using relative cell ids) within the subset of cells selected (e.g. first 15 cells of the 'S' population):: - netParams.addStimTargetParams('Input_1->S', {'source': 'Input_1', 'sec':'soma', 'loc': 0.8, 'conds': {'popLabel':'S', 'cellList': range(15)}}) - netParams.addStimTargetParams('Input_2->S', {'source': 'Input_2', 'sec':'soma', 'loc': 0.5, 'conds': {'popLabel':'S', 'ynorm': [0,0.5]}}) - netParams.addStimTargetParams('Input_3->M1', {'source': 'Input_3', 'sec':'soma', 'loc': 0.2, 'conds': {'popLabel':'M', 'cellList': [2,4,5,8,10,15,19]}}) - netParams.addStimTargetParams('Input_4->PYR', {'source': 'Input_4', 'sec':'soma', 'loc': 0.5, 'weight': '0.1+gauss(0.2,0.05)','delay': 1, 'conds': {'cellType':'PYR', 'ynorm': [0.6,1.0]}}) + netParams.stimTargetParams['Input_1->S'] = {'source': 'Input_1', 'sec':'soma', 'loc': 0.8, 'conds': {'popLabel':'S', 'cellList': range(15)}} + netParams.stimTargetParams['Input_2->S'] = {'source': 'Input_2', 'sec':'soma', 'loc': 0.5, 'conds': {'popLabel':'S', 'ynorm': [0,0.5]}} + netParams.stimTargetParams['Input_3->M1'] = {'source': 'Input_3', 'sec':'soma', 'loc': 0.2, 'conds': {'popLabel':'M', 'cellList': [2,4,5,8,10,15,19]}} + netParams.stimTargetParams['Input_4->PYR'] = {'source': 'Input_4', 'sec':'soma', 'loc': 0.5, 'weight': '0.1+gauss(0.2,0.05)','delay': 1, 'conds': {'cellType':'PYR', 'ynorm': [0.6,1.0]}} .. note:: The stimTargetParams of NetStims require connection parameters (e.g. weight and delay), since a new connection will be created to map/apply the NetStim to each target cell. @@ -551,8 +552,8 @@ We begin by creating a new file (``net6.py``) describing a simple network with o netParams = specs.NetParams() # object of class NetParams to store the network parameters # Population parameters - netParams.addPopParams('hop', {'cellType': 'PYR', 'cellModel': 'HH', 'numCells': 50}) # add dict with params for this pop - netParams.addPopParams('background', {'cellModel': 'NetStim', 'rate': 50, 'noise': 0.5}) # background inputs + netParams.popParams['hop'] = {'cellType': 'PYR', 'cellModel': 'HH', 'numCells': 50} # add dict with params for this pop + netParams.popParams['background'] = {'cellModel': 'NetStim', 'rate': 50, 'noise': 0.5} # background inputs # Cell parameters @@ -561,25 +562,25 @@ We begin by creating a new file (``net6.py``) describing a simple network with o cellRule['secs']['soma'] = {'geom': {}, 'topol': {}, 'mechs': {}} # soma properties cellRule['secs']['soma']['geom'] = {'diam': 18.8, 'L': 18.8} cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} - netParams.addCellParams('PYR', cellRule) # add dict to list of cell properties + netParams.cellParams['PYR'] = cellRule # add dict to list of cell properties # Synaptic mechanism parameters - netParams.addSynMechParams('exc', {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 1.0, 'e': 0}) - netParams.addSynMechParams('inh', {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 1.0, 'e': -80}) + netParams.synMechParams['exc'] = {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 1.0, 'e': 0} + netParams.synMechParams['inh'] = {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 1.0, 'e': -80} # Connectivity parameters - netParams.addConnParams('bg->hop', - {'preConds': {'popLabel': 'background'}, 'postConds': {'popLabel': 'hop'}, # background -> PYR + netParams.connParams['bg->hop'] = { + 'preConds': {'popLabel': 'background'}, 'postConds': {'popLabel': 'hop'}, # background -> PYR 'weight': 0.1, # fixed weight of 0.1 'synMech': 'exc', # target exc synapse 'delay': 1}) # uniformly distributed delays between 1-5ms - netParams.addConnParams('hop->hop', - {'preConds': {'popLabel': 'hop'}, 'postConds': {'popLabel': 'hop'}, + netParams.connParams['hop->hop'] = { + 'preConds': {'popLabel': 'hop'}, 'postConds': {'popLabel': 'hop'}, 'weight': 0.0, # weight of each connection 'synMech': 'inh', # target inh synapse - 'delay': 5}) # delay + 'delay': 5} # delay We now add the standard simulation configuration options, and include the ``syncLines`` option so that raster plots shown vertical lines at for each spike as an indication of synchrony:: @@ -598,9 +599,9 @@ We now add the standard simulation configuration options, and include the ``sync simConfig.filename = 'model_output' # Set file output name simConfig.savePickle = False # Save params, network and sim output to pickle file - simConfig.addAnalysis('plotRaster', {'syncLines': True}) # Plot a raster - simConfig.addAnalysis('plotTraces', {'include': [1]}) # Plot recorded traces for this list of cells - simConfig.addAnalysis('plot2Dnet', True) # plot 2D visualization of cell positions and connections + simConfig.analysis['plotRaster'] = {'syncLines': True} # Plot a raster + simConfig.analysis['plotTraces'] = {'include': [1]} # Plot recorded traces for this list of cells + simConfig.analysis['plot2Dnet'] = True # plot 2D visualization of cell positions and connections Finally, we add the code to create the network and run the simulation, but for illustration purposes, we use the individual function calls for each step of the process (instead of the all-encompassing ``sim.createAndSimulate()`` function used before):: diff --git a/examples/HHTut/HHTut.py b/examples/HHTut/HHTut.py index ddce03837..c9e237561 100644 --- a/examples/HHTut/HHTut.py +++ b/examples/HHTut/HHTut.py @@ -25,8 +25,8 @@ ############################################################################### # Population parameters -netParams.addPopParams('PYR', {'cellModel': 'HH', 'cellType': 'PYR', 'numCells': 200}) # add dict with params for this pop -netParams.addPopParams('background', {'cellModel': 'NetStim', 'rate': 10, 'noise': 0.5, 'start': 1}) # background inputs +netParams.popParams['PYR'] = {'cellModel': 'HH', 'cellType': 'PYR', 'numCells': 200} # add dict with params for this pop +netParams.popParams['background'] = {'cellModel': 'NetStim', 'rate': 10, 'noise': 0.5, 'start': 1} # background inputs # Cell parameters @@ -36,27 +36,27 @@ cellRule['secs']['soma']['geom'] = {'diam': 18.8, 'L': 18.8, 'Ra': 123.0} # soma geometry cellRule['secs']['soma']['mechs']['hh'] = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} # soma hh mechanism cellRule['secs']['soma']['vinit'] = -71 -netParams.addCellParams('PYR', cellRule) # add dict to list of cell params +netParams.cellParams['PYR'] = cellRule # add dict to list of cell params # Synaptic mechanism parameters -netParams.addSynMechParams('AMPA', {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 1.0, 'e': 0}) +netParams.synMechParams['AMPA'] = {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 1.0, 'e': 0} # Connectivity parameters -netParams.addConnParams('PYR->PYR', - {'preConds': {'popLabel': 'PYR'}, 'postConds': {'popLabel': 'PYR'}, +netParams.connParams['PYR->PYR'] = { + 'preConds': {'popLabel': 'PYR'}, 'postConds': {'popLabel': 'PYR'}, 'weight': 0.002, # weight of each connection 'delay': '0.2+gauss(13.0,1.4)', # delay min=0.2, mean=13.0, var = 1.4 'threshold': 10, # threshold - 'convergence': 'uniform(1,15)'}) # convergence (num presyn targeting postsyn) is uniformly distributed between 1 and 15 + 'convergence': 'uniform(1,15)'} # convergence (num presyn targeting postsyn) is uniformly distributed between 1 and 15 -netParams.addConnParams('bg->PYR', - {'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': 'PYR'}, # background -> PYR +netParams.connParams['bg->PYR'] = { + 'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': 'PYR'}, # background -> PYR 'weight': 0.1, # fixed weight of 0.08 'synMech': 'AMPA', # target NMDA synapse - 'delay': 'uniform(1,5)'}) # uniformly distributed delays between 1-5ms + 'delay': 'uniform(1,5)'} # uniformly distributed delays between 1-5ms ############################################################################### @@ -84,9 +84,9 @@ # Analysis and plotting -simConfig.addAnalysis('plotRaster', True) # Plot raster -simConfig.addAnalysis('plotTraces', {'include': [2]}) # Plot raster -simConfig.addAnalysis('plot2Dnet', True) # Plot 2D net cells and connections +simConfig.analysis['plotRaster'] = True # Plot raster +simConfig.analysis['plotTraces'] = {'include': [2]} # Plot raster +simConfig.analysis['plot2Dnet'] = True # Plot 2D net cells and connections diff --git a/examples/HybridTut/HybridTut.py b/examples/HybridTut/HybridTut.py index ad5f0a53d..9ad1bf953 100644 --- a/examples/HybridTut/HybridTut.py +++ b/examples/HybridTut/HybridTut.py @@ -24,9 +24,9 @@ ############################################################################### # Population parameters -netParams.addPopParams('PYR_HH', {'cellModel': 'HH', 'cellType': 'PYR', 'numCells': 50}) # add dict with params for this pop -netParams.addPopParams('PYR_Izhi', {'cellModel': 'Izhi2007b', 'cellType': 'PYR', 'numCells': 50}) # add dict with params for this pop -netParams.addPopParams('background', {'cellModel': 'NetStim', 'rate': 10, 'noise': 0.5}) # background inputs +netParams.popParams['PYR_HH'] = {'cellModel': 'HH', 'cellType': 'PYR', 'numCells': 50} # add dict with params for this pop +netParams.popParams['PYR_Izhi'] = {'cellModel': 'Izhi2007b', 'cellType': 'PYR', 'numCells': 50} # add dict with params for this pop +netParams.popParams['background'] = {'cellModel': 'NetStim', 'rate': 10, 'noise': 0.5} # background inputs # Cell parameters list @@ -43,7 +43,7 @@ cellRule['secs']['dend']['topol'] = {'parentSec': 'soma', 'parentX': 1.0, 'childX': 0} cellRule['secs']['dend']['mechs']['pas'] = {'g': 0.0000357, 'e': -70} -netParams.addCellParams('PYR_HH', cellRule) # add dict to list of cell properties +netParams.cellParams['PYR_HH'] = cellRule # add dict to list of cell properties ## PYR cell properties (Izhi) cellRule = {'conds': {'cellType': 'PYR', 'cellModel': 'Izhi2007b'}, 'secs': {}} @@ -51,39 +51,39 @@ cellRule['secs']['soma']['geom'] = {'diam': 10, 'L': 10, 'cm': 31.831} cellRule['secs']['soma']['pointps']['Izhi'] = {'mod':'Izhi2007b', 'C':1, 'k':0.7, 'vr':-60, 'vt':-40, 'vpeak':35, 'a':0.03, 'b':-2, 'c':-50, 'd':100, 'celltype':1} -netParams.addCellParams('PYR_Izhi', cellRule) # add dict to list of cell properties +netParams.cellParams['PYR_Izhi'] = cellRule # add dict to list of cell properties # Synaptic mechanism parameters -netParams.addSynMechParams('AMPA', {'mod': 'ExpSyn', 'tau': 0.1, 'e': 0}) +netParams.synMechParams['AMPA'] = {'mod': 'ExpSyn', 'tau': 0.1, 'e': 0} # Connectivity parameters -netParams.addConnParams('PYR->PYR', - {'preConds': {'cellType': 'PYR'}, 'postConds': {'cellType': 'PYR'}, +netParams.connParams['PYR->PYR'] = { + 'preConds': {'cellType': 'PYR'}, 'postConds': {'cellType': 'PYR'}, 'weight': 0.2, # weight of each connection 'delay': '0.2+gauss(13.0,1.4)', # delay min=0.2, mean=13.0, var = 1.4 'threshold': 10, # threshold 'convergence': 'uniform(0,5)', # convergence (num presyn targeting postsyn) is uniformly distributed between 1 and 10 - 'synMech': 'AMPA'}) + 'synMech': 'AMPA'} -netParams.addConnParams('bg->PYR_Izhi', - {'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': 'PYR','cellModel': 'Izhi2007b'}, # background -> PYR (Izhi2007b) +netParams.connParams['bg->PYR_Izhi'] = { + 'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': 'PYR','cellModel': 'Izhi2007b'}, # background -> PYR (Izhi2007b) 'connFunc': 'fullConn', 'weight': 1, 'delay': 'uniform(1,5)', - 'synMech': 'AMPA'}) + 'synMech': 'AMPA'} -netParams.addConnParams('bg->PYR_HH', - {'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': 'PYR', 'cellModel': 'HH'}, # background -> PYR (HH) +netParams.connParams['bg->PYR_HH'] = { + 'preConds': {'popLabel': 'background'}, 'postConds': {'cellType': 'PYR', 'cellModel': 'HH'}, # background -> PYR (HH) 'connFunc': 'fullConn', 'weight': 1, 'synMech': 'AMPA', 'sec': 'dend', 'loc': 1.0, - 'delay': 'uniform(1,5)'}) + 'delay': 'uniform(1,5)'} @@ -122,6 +122,6 @@ # Analysis and plotting -simConfig.addAnalysis('plotRaster', True) # Whether or not to plot a raster -simConfig.addAnalysis('plotTraces', {'include': [1,51]}) # plot recorded traces for this list of cells +simConfig.analysis['plotRaster'] = True # Whether or not to plot a raster +simConfig.analysis['plotTraces'] = {'include': [1,51]} # plot recorded traces for this list of cells diff --git a/examples/M1/M1.py b/examples/M1/M1.py index 99fe45792..b5e76c252 100644 --- a/examples/M1/M1.py +++ b/examples/M1/M1.py @@ -78,21 +78,21 @@ netParams.probLambda = 100.0 # length constant (lambda) for connection probability decay (um) ## create list of populations, where each item contains a dict with the pop params -netParams.addPopParams('IT_L23', {'cellModel': 'Izhi2007b', 'cellType': 'IT', 'ynormRange': [0.12, 0.31], 'density': 80e3}) # L2/3 IT -netParams.addPopParams('IT_L4', {'cellModel': 'Izhi2007b', 'cellType': 'IT', 'ynormRange': [0.31, 0.41], 'density': 80e3}) # L4 IT -netParams.addPopParams('IT_L5A', {'cellModel': 'Izhi2007b', 'cellType': 'IT', 'ynormRange': [0.41, 0.52], 'density': 80e3}) # L5A IT -netParams.addPopParams('IT_L5B', {'cellModel': 'Izhi2007b', 'cellType': 'IT', 'ynormRange': [0.52, 0.77], 'density': 40e3}) # L5B IT -netParams.addPopParams('PT_L5B', {'cellModel': 'Izhi2007b', 'cellType': 'PT', 'ynormRange': [0.52, 0.77], 'density': 40e3}) # L5B PT -netParams.addPopParams('IT_L6', {'cellModel': 'Izhi2007b', 'cellType': 'IT', 'ynormRange': [0.77, 1.0], 'density': 40e3}) # L6 IT -netParams.addPopParams('CT_L6', {'cellModel': 'Izhi2007b', 'cellType': 'CT', 'ynormRange': [0.77, 1.0], 'density': 40e3}) # L6 CT -netParams.addPopParams('PV_L23', {'cellModel': 'Izhi2007b', 'cellType': 'PV', 'ynormRange': [0.1, 0.31], 'density': 10e3}) # L2/3 PV (FS) -netParams.addPopParams('SOM_L23',{'cellModel': 'Izhi2007b', 'cellType': 'SOM', 'ynormRange': [0.1, 0.31], 'density': 10e3}) # L2/3 SOM (LTS) -netParams.addPopParams('PV_L5', {'cellModel': 'Izhi2007b', 'cellType': 'PV', 'ynormRange': [0.31, 0.77], 'density': 10e3}) # L5 PV (FS) -netParams.addPopParams('SOM_L5', {'cellModel': 'Izhi2007b', 'cellType': 'SOM', 'ynormRange': [0.31, 0.77], 'density': 10e3}) # L5 SOM (LTS) -netParams.addPopParams('PV_L6', {'cellModel': 'Izhi2007b', 'cellType': 'PV', 'ynormRange': [0.77, 1.0], 'density': 10e3}) # L6 PV (FS) -netParams.addPopParams('SOM_L6', {'cellModel': 'Izhi2007b', 'cellType': 'SOM', 'ynormRange': [0.77, 1.0], 'density': 10e3}) # L6 SOM (LTS) -netParams.addPopParams('background_E', {'cellModel': 'NetStim', 'rate': 20, 'noise': 0.5}) # background inputs to Exc -netParams.addPopParams('background_I', {'cellModel': 'NetStim', 'rate': 20, 'noise': 0.5}) # background inputs to Inh +netParams.popParams['IT_L23'] = {'cellModel': 'Izhi2007b', 'cellType': 'IT', 'ynormRange': [0.12, 0.31], 'density': 80e3} # L2/3 IT +netParams.popParams['IT_L4'] = {'cellModel': 'Izhi2007b', 'cellType': 'IT', 'ynormRange': [0.31, 0.41], 'density': 80e3} # L4 IT +netParams.popParams['IT_L5A'] = {'cellModel': 'Izhi2007b', 'cellType': 'IT', 'ynormRange': [0.41, 0.52], 'density': 80e3} # L5A IT +netParams.popParams['IT_L5B'] = {'cellModel': 'Izhi2007b', 'cellType': 'IT', 'ynormRange': [0.52, 0.77], 'density': 40e3} # L5B IT +netParams.popParams['PT_L5B'] = {'cellModel': 'Izhi2007b', 'cellType': 'PT', 'ynormRange': [0.52, 0.77], 'density': 40e3} # L5B PT +netParams.popParams['IT_L6'] = {'cellModel': 'Izhi2007b', 'cellType': 'IT', 'ynormRange': [0.77, 1.0], 'density': 40e3} # L6 IT +netParams.popParams['CT_L6'] = {'cellModel': 'Izhi2007b', 'cellType': 'CT', 'ynormRange': [0.77, 1.0], 'density': 40e3} # L6 CT +netParams.popParams['PV_L23'] = {'cellModel': 'Izhi2007b', 'cellType': 'PV', 'ynormRange': [0.1, 0.31], 'density': 10e3} # L2/3 PV (FS) +netParams.popParams['SOM_L23'] ={'cellModel': 'Izhi2007b', 'cellType': 'SOM', 'ynormRange': [0.1, 0.31], 'density': 10e3} # L2/3 SOM (LTS) +netParams.popParams['PV_L5'] = {'cellModel': 'Izhi2007b', 'cellType': 'PV', 'ynormRange': [0.31, 0.77], 'density': 10e3} # L5 PV (FS) +netParams.popParams['SOM_L5'] = {'cellModel': 'Izhi2007b', 'cellType': 'SOM', 'ynormRange': [0.31, 0.77], 'density': 10e3} # L5 SOM (LTS) +netParams.popParams['PV_L6'] = {'cellModel': 'Izhi2007b', 'cellType': 'PV', 'ynormRange': [0.77, 1.0], 'density': 10e3} # L6 PV (FS) +netParams.popParams['SOM_L6'] = {'cellModel': 'Izhi2007b', 'cellType': 'SOM', 'ynormRange': [0.77, 1.0], 'density': 10e3} # L6 SOM (LTS) +netParams.popParams['background_E'] = {'cellModel': 'NetStim', 'rate': 20, 'noise': 0.5} # background inputs to Exc +netParams.popParams['background_I'] = {'cellModel': 'NetStim', 'rate': 20, 'noise': 0.5} # background inputs to Inh ## Izhi cell params (used in cell properties) @@ -107,41 +107,41 @@ cellRule['secs']['soma'] = {'geom': {}, 'pointps':{}} # soma cellRule['secs']['soma']['geom'] = {'diam': 10, 'L': 10, 'cm': 31.831} cellRule['secs']['soma']['pointps']['Izhi'] = izhiParams['RS'] -netParams.addCellParams('IT', cellRule) # add dict to list of cell properties +netParams.cellParams['IT'] = cellRule # add dict to list of cell properties ## PT cell params cellRule = {'conds': {'cellType': 'PT'}, 'secs': {}} cellRule['secs']['soma'] = {'geom': {}, 'pointps':{}} # soma cellRule['secs']['soma']['geom'] = {'diam': 10, 'L': 10, 'cm': 31.831} cellRule['secs']['soma']['pointps']['Izhi'] = izhiParams['IB'] -netParams.addCellParams('PT', cellRule) # add dict to list of cell properties +netParams.cellParams['PT'] = cellRule # add dict to list of cell properties ## CT cell params cellRule = {'conds': {'cellType': 'CT'}, 'secs': {}} cellRule['secs']['soma'] = {'geom': {}, 'pointps':{}} # soma cellRule['secs']['soma']['geom'] = {'diam': 10, 'L': 10, 'cm': 31.831} cellRule['secs']['soma']['pointps']['Izhi'] = izhiParams['RS'] -netParams.addCellParams('CT', cellRule) # add dict to list of cell properties +netParams.cellParams['CT'] = cellRule # add dict to list of cell properties ## SOM cell params cellRule = { 'conds': {'cellType': 'SOM'}, 'secs': {}} cellRule['secs']['soma'] = {'geom': {}, 'pointps':{}} # soma cellRule['secs']['soma']['geom'] = {'diam': 10, 'L': 10, 'cm': 31.831} cellRule['secs']['soma']['pointps']['Izhi'] = izhiParams['LTS'] -netParams.addCellParams('SOM', cellRule) # add dict to list of cell properties +netParams.cellParams['SOM'] = cellRule # add dict to list of cell properties ## PV cell params cellRule = {'conds': {'cellType': 'PV'}, 'secs': {}} cellRule['secs']['soma'] = {'geom': {}, 'pointps':{}} # soma cellRule['secs']['soma']['geom'] = {'diam': 10, 'L': 10, 'cm': 31.831} cellRule['secs']['soma']['pointps']['Izhi'] = izhiParams['FS'] -netParams.addCellParams('PV', cellRule) # add dict to list of cell properties +netParams.cellParams['PV'] = cellRule # add dict to list of cell properties # Synaptic mechanism parameters -netParams.addSynMechParams('AMPA', {'mod': 'Exp2Syn', 'tau1': 0.05, 'tau2': 5.3, 'e': 0}) # AMPA -netParams.addSynMechParams('NMDA', {'mod': 'Exp2Syn', 'tau1': 0.15, 'tau2': 15, 'e': 0}) # NMDA -netParams.addSynMechParams('GABAA', {'mod': 'Exp2Syn', 'tau1': 0.07, 'tau2': 9.1, 'e': -80}) # GABAA -netParams.addSynMechParams('GABAB', {'mod': 'Exp2Syn', 'tau1': 0.07, 'tau2': 9.1, 'e': -80}) # GABAB +netParams.synMechParams['AMPA'] = {'mod': 'Exp2Syn', 'tau1': 0.05, 'tau2': 5.3, 'e': 0} # AMPA +netParams.synMechParams['NMDA'] = {'mod': 'Exp2Syn', 'tau1': 0.15, 'tau2': 15, 'e': 0} # NMDA +netParams.synMechParams['GABAA'] = {'mod': 'Exp2Syn', 'tau1': 0.07, 'tau2': 9.1, 'e': -80} # GABAA +netParams.synMechParams['GABAB'] = {'mod': 'Exp2Syn', 'tau1': 0.07, 'tau2': 9.1, 'e': -80} # GABAB # List of connectivity rules/params diff --git a/examples/RL_arm/params.py b/examples/RL_arm/params.py index 1da7ce9a3..0e950aa1a 100644 --- a/examples/RL_arm/params.py +++ b/examples/RL_arm/params.py @@ -26,20 +26,20 @@ netParams.scaleConnWeight = 0.001 # Connection weight scale factor # Population parameters -netParams.addPopParams('Psh', {'cellModel': 'Izhi2007b', 'cellType': 'RS', 'numCells': 40}) # add dict with params for this pop -netParams.addPopParams('Pel', {'cellModel': 'Izhi2007b', 'cellType': 'RS', 'numCells': 40}) # add dict with params for this pop -netParams.addPopParams('ES', {'cellModel': 'Izhi2007b', 'cellType': 'RS', 'numCells': 80}) # add dict with params for this pop -netParams.addPopParams('ISL', {'cellModel': 'Izhi2007b', 'cellType': 'LTS', 'numCells': 10}) # add dict with params for this pop -netParams.addPopParams('IS', {'cellModel': 'Izhi2007b', 'cellType': 'FS', 'numCells': 10}) # add dict with params for this pop -netParams.addPopParams('EM', {'cellModel': 'Izhi2007b', 'cellType': 'RS', 'numCells': 80}) # add dict with params for this pop -netParams.addPopParams('IML', {'cellModel': 'Izhi2007b', 'cellType': 'LTS', 'numCells': 10}) # add dict with params for this pop -netParams.addPopParams('IM', {'cellModel': 'Izhi2007b', 'cellType': 'FS', 'numCells': 10}) # add dict with params for this pop - -netParams.addPopParams('backgroundE', {'cellModel': 'NetStim', 'rate': 10, 'noise': 0.5}) # background inputs -netParams.addPopParams('backgroundI', {'cellModel': 'NetStim', 'rate': 10, 'noise': 0.5}) # background inputs -netParams.addPopParams('stimPsh', {'cellModel': 'NetStim', 'rate': 'variable', 'noise': 0}) # stim inputs for P_sh -netParams.addPopParams('stimPel', {'cellModel': 'NetStim', 'rate': 'variable', 'noise': 0}) # stim inputs for P_el -netParams.addPopParams('stimEM', {'cellModel': 'NetStim', 'rate': 'variable', 'noise': 0}) # stim inputs for EM (explor movs) +netParams.popParams['Psh'] = {'cellModel': 'Izhi2007b', 'cellType': 'RS', 'numCells': 40} # add dict with params for this pop +netParams.popParams['Pel'] = {'cellModel': 'Izhi2007b', 'cellType': 'RS', 'numCells': 40} # add dict with params for this pop +netParams.popParams['ES'] = {'cellModel': 'Izhi2007b', 'cellType': 'RS', 'numCells': 80} # add dict with params for this pop +netParams.popParams['ISL'] = {'cellModel': 'Izhi2007b', 'cellType': 'LTS', 'numCells': 10} # add dict with params for this pop +netParams.popParams['IS'] = {'cellModel': 'Izhi2007b', 'cellType': 'FS', 'numCells': 10} # add dict with params for this pop +netParams.popParams['EM'] = {'cellModel': 'Izhi2007b', 'cellType': 'RS', 'numCells': 80} # add dict with params for this pop +netParams.popParams['IML'] = {'cellModel': 'Izhi2007b', 'cellType': 'LTS', 'numCells': 10} # add dict with params for this pop +netParams.popParams['IM'] = {'cellModel': 'Izhi2007b', 'cellType': 'FS', 'numCells': 10} # add dict with params for this pop + +netParams.popParams['backgroundE'] = {'cellModel': 'NetStim', 'rate': 10, 'noise': 0.5} # background inputs +netParams.popParams['backgroundI'] = {'cellModel': 'NetStim', 'rate': 10, 'noise': 0.5} # background inputs +netParams.popParams['stimPsh'] = {'cellModel': 'NetStim', 'rate': 'variable', 'noise': 0} # stim inputs for P_sh +netParams.popParams['stimPel'] = {'cellModel': 'NetStim', 'rate': 'variable', 'noise': 0} # stim inputs for P_el +netParams.popParams['stimEM'] = {'cellModel': 'NetStim', 'rate': 'variable', 'noise': 0} # stim inputs for EM (explor movs) # Izhi cell params (used in cell properties) @@ -55,27 +55,27 @@ cellRule['secs']['soma'] = {'geom': {}, 'pointps':{}} # soma cellRule['secs']['soma']['geom'] = {'diam': 10, 'L': 10, 'cm': 31.831} cellRule['secs']['soma']['pointps']['Izhi'] = izhiParams['RS'] -netParams.addCellParams('RS_Izhi', cellRule) # add dict to list of cell properties +netParams.cellParams['RS_Izhi'] = cellRule # add dict to list of cell properties ## LTS Izhi cell params cellRule = {'conds': {'cellType': 'LTS', 'cellModel': 'Izhi2007b'}, 'secs': {}} cellRule['secs']['soma'] = {'geom': {}, 'pointps':{}} # soma cellRule['secs']['soma']['geom'] = {'diam': 10, 'L': 10, 'cm': 31.831} cellRule['secs']['soma']['pointps']['Izhi'] = izhiParams['LTS'] -netParams.addCellParams('LTS_Izhi', cellRule) # add dict to list of cell properties +netParams.cellParams['LTS_Izhi'] = cellRule # add dict to list of cell properties ## FS Izhi cell params cellRule = {'conds': {'cellType': 'FS', 'cellModel': 'Izhi2007b'}, 'secs': {}} cellRule['secs']['soma'] = {'geom': {}, 'pointps':{}} # soma cellRule['secs']['soma']['geom'] = {'diam': 10, 'L': 10, 'cm': 31.831} cellRule['secs']['soma']['pointps']['Izhi'] = izhiParams['FS'] -netParams.addCellParams('FS_Izhi', cellRule) # add dict to list of cell properties +netParams.cellParams['FS_Izhi'] = cellRule # add dict to list of cell properties # Synaptic mechanism parameters -netParams.addSynMechParams('AMPA', {'mod': 'Exp2Syn', 'tau1': 0.05, 'tau2': 5.3, 'e': 0}) # AMPA -netParams.addSynMechParams('NMDA', {'mod': 'Exp2Syn', 'tau1': 0.15, 'tau2': 1.50, 'e': 0}) # NMDA -netParams.addSynMechParams('GABA', {'mod': 'Exp2Syn', 'tau1': 0.07, 'tau2': 9.1, 'e': -80}) # GABAA +netParams.synMechParams['AMPA'] = {'mod': 'Exp2Syn', 'tau1': 0.05, 'tau2': 5.3, 'e': 0} # AMPA +netParams.synMechParams['NMDA'] = {'mod': 'Exp2Syn', 'tau1': 0.15, 'tau2': 1.50, 'e': 0} # NMDA +netParams.synMechParams['GABA'] = {'mod': 'Exp2Syn', 'tau1': 0.07, 'tau2': 9.1, 'e': -80} # GABAA # Connectivity parameters @@ -318,6 +318,6 @@ # Analysis and plotting -simConfig.addAnalysis('plotRaster', True) # Whether or not to plot a raster +simConfig.analysis['plotRaster'] = True # Whether or not to plot a raster diff --git a/examples/sandbox/sandbox.py b/examples/sandbox/sandbox.py index 73be70f31..688134718 100644 --- a/examples/sandbox/sandbox.py +++ b/examples/sandbox/sandbox.py @@ -14,7 +14,7 @@ # ############################################################################### -from netpyne import specs,sim +from netpyne import specs, sim from netpyne.specs import Dict netParams = specs.NetParams() # object of class NetParams to store the network parameters @@ -28,27 +28,27 @@ netParams.scaleConnWeightModels = {'HH': 1.0} # Population parameters -netParams.addPopParams('PYR', {'cellModel': 'HH', 'cellType': 'PYR2sec', 'ynormRange': [0,0.5], 'numCells': 10}) # add dict with params for this pop -netParams.addPopParams('PYR2', {'cellModel': 'HH', 'cellType': 'PYR2sec', 'ynormRange': [0.3,0.6], 'numCells': 20}) # add dict with params for this pop -netParams.addPopParams('PYR3', {'cellModel': 'HH', 'cellType': 'PYR2sec', 'ynormRange': [0.2,1.0],'numCells': 20}) # add dict with params for this pop +netParams.addPopParams('PYR', {'cellModel': 'HH', 'cellType': 'PYR', 'ynormRange': [0,0.5], 'numCells': 10}) # add dict with params for this pop +netParams.addPopParams('PYR2', {'cellModel': 'HH', 'cellType': 'PYR', 'ynormRange': [0.3,0.6], 'numCells': 20}) # add dict with params for this pop +netParams.addPopParams('PYR3', {'cellModel': 'HH', 'cellType': 'PYR', 'ynormRange': [0.2,1.0],'numCells': 20}) # add dict with params for this pop netParams.addPopParams('background', {'cellModel': 'NetStim', 'rate': 100, 'noise': 0.5, 'start': 1, 'seed': 2}) # background inputs netParams.addPopParams('background2', {'cellModel': 'NetStim', 'rate': 20, 'noise': 0.5, 'start': 1, 'seed': 2}) # background inputs - +netParams.addPopParams('microstim', {'rate': 50, 'noise': 0, 'cellModel': 'NetStim'}) # Synaptic mechanism parameters netParams.addSynMechParams('AMPA', {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 1.0, 'e': 0}) netParams.addSynMechParams('NMDA', {'mod': 'Exp2Syn', 'tau1': 0.1, 'tau2': 5.0, 'e': 0}) -netParams.addSynMechParams('homSyn', {'mod':'hsyn','tau1':0.05,'tau2':5.3,'e':0, 'selfNetCon': {'threshold': -15, 'weight': -1, 'delay': 0}}) +netParams.addSynMechParams('homSyn', {'mod':'hsyn','tau1':0.05,'tau2':5.3,'e':0, 'selfNetCon': {'threshold': -15, 'weight': -1, 'delay': 0, 'sec': 'soma', 'loc': 0.5}}) # Cell parameters ## PYR cell properties -# cellParams = Dict() -# cellParams.secs.soma.geom = {'diam': 18.8, 'L': 18.8, 'Ra': 123.0} -# cellParams.secs.soma.mechs.hh = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} -# cellParams.conds = {'cellType': 'PYR'} -# netParams.addCellParams('PYR', cellParams) +cellParams = Dict() +cellParams.secs.soma.geom = {'diam': 18.8, 'L': 18.8, 'Ra': 123.0} +cellParams.secs.soma.mechs.hh = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} +cellParams.conds = {'cellType': 'PYR'} +netParams.addCellParams('PYR2sec', cellParams) ## PYR2sec cell properties @@ -65,20 +65,20 @@ # netParams.addCellParams('PYR2sec', cellParams) # add dict to list of cell properties ## -cellRule = Dict(conds={'cellType': 'PYR2sec', 'cellModel': 'HH'}, secs=Dict(), secLists=Dict()) -cellRule.secs.soma.geom = Dict({'diam': 6.3, 'L': 5, 'Ra': 123.0, 'pt3d':[]}) -cellRule.secs.soma.geom.pt3d.append((0, 0, 0, 20)) -cellRule.secs.soma.geom.pt3d.append((0, 0, 20, 20)) -cellRule.secs.soma.mechs.hh = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} +# cellRule = Dict(conds={'cellType': 'PYR2sec', 'cellModel': 'HH'}, secs=Dict(), secLists=Dict()) +# cellRule.secs.soma.geom = Dict({'diam': 6.3, 'L': 5, 'Ra': 123.0, 'pt3d':[]}) +# cellRule.secs.soma.geom.pt3d.append((0, 0, 0, 20)) +# cellRule.secs.soma.geom.pt3d.append((0, 0, 20, 20)) +# cellRule.secs.soma.mechs.hh = {'gnabar': 0.12, 'gkbar': 0.036, 'gl': 0.003, 'el': -70} -cellRule.secs.dend.geom = Dict({'diam': 5.0, 'L': 150.0, 'Ra': 150.0, 'cm': 1, 'pt3d': []}) -cellRule.secs.dend.geom.pt3d.append((0, 0, 0, 40)) -cellRule.secs.dend.geom.pt3d.append((0, 0, 50, 40)) -cellRule.secs.dend.topol = {'parentSec': 'soma', 'parentX': 1.0, 'childX': 0} -cellRule.secs.dend.mechs.pas = {'g': 0.0000357, 'e': -70} +# cellRule.secs.dend.geom = Dict({'diam': 5.0, 'L': 150.0, 'Ra': 150.0, 'cm': 1, 'pt3d': []}) +# cellRule.secs.dend.geom.pt3d.append((0, 0, 0, 40)) +# cellRule.secs.dend.geom.pt3d.append((0, 0, 50, 40)) +# cellRule.secs.dend.topol = {'parentSec': 'soma', 'parentX': 1.0, 'childX': 0} +# cellRule.secs.dend.mechs.pas = {'g': 0.0000357, 'e': -70} -cellRule.secLists.all = ['soma', 'dend'] -netParams.addCellParams('PYR2sec', cellRule) # add dict to list of cell properties +# cellRule.secLists.all = ['soma', 'dend'] +# netParams.addCellParams('PYR2sec', cellRule) # add dict to list of cell properties ### HH # cellRule = {'label': 'PYR_HH_rule', 'conds': {'cellType': 'PYR', 'cellModel': 'HH'}} # cell rule dict @@ -86,6 +86,15 @@ # utils.importCell(cellRule=cellRule, synMechParams=netParams['synMechParams'], fileName='HHCellFile.py', cellName='HHCellClass') # netParams['cellParams'].append(cellRule) # add dict to list of cell parameters +### Import from net + +# netParams.importCellParamsFromNet( +# labelList = ['PYR', 'BAS'], +# condsList = [{'cellType': 'PYR'}, {'cellType': 'BAS'}], +# fileName = '/u/salvadord/Models/ca3ihdemo/simcells.py', +# cellNameList = ['net.bas.cell[0]', 'net.bas.cell[0]'], +# importSynMechs = True) + #Stimulation parameters # netParams.addStimSourceParams('Input_1', {'type': 'IClamp', 'delay': 10, 'dur': 800, 'amp': 'uniform(0.05,0.5)'}) @@ -125,15 +134,27 @@ # 'synMech': ['AMPA', 'NMDA'], # 'threshold': 10}) # threshold -netParams.addConnParams('PYRconn2', - {'preConds': {'popLabel': 'PYR'}, 'postConds': {'popLabel': 'PYR'}, - 'weight': 0.005, # weight of each connection - 'delay': '0.2+gauss(13.0,1.4)', # delay min=0.2, mean=13.0, var = 1.4 - 'threshold': 10, # threshold - 'convergence': 'uniform(1,15)', - 'synMech': 'homSyn', - 'sec': 'all', - 'synsPerConn': 2}) # convergence (num presyn targeting postsyn) is uniformly distributed between 1 and 15 +duration = 1*1e3 +netParams.connParams['mist->PYR'] = { + 'preConds': {'popLabel': 'microstim'}, + 'postConds': {'cellType': 'PYR'}, + 'weight': 0.1, + 'shape': {'switchOnOff': [200,400, 600, 800], + 'pulseType': 'gaussian', + 'pulsePeriod': 100, + 'pulseWidth': 60}, + 'synMech':'AMPA'} + + +# netParams.addConnParams('PYRconn2', +# {'preConds': {'popLabel': 'PYR'}, 'postConds': {'popLabel': 'PYR'}, +# 'weight': 0.005, # weight of each connection +# 'delay': '0.2+gauss(13.0,1.4)', # delay min=0.2, mean=13.0, var = 1.4 +# 'threshold': 10, # threshold +# 'convergence': 'uniform(1,15)', +# 'synMech': 'homSyn', +# 'sec': 'all', +# 'synsPerConn': 2}) # convergence (num presyn targeting postsyn) is uniformly distributed between 1 and 15 # netParams.addConnParams('PYR->PYR', # {'preConds': {'popLabel': 'PYR'}, 'postConds': {'popLabel': ['PYR','PYR2', 'PYR3']}, @@ -192,12 +213,12 @@ # 'delay': 'uniform(1,5)'} # uniformly distributed delays between 1-5ms -netParams.addSubConnParams('PYRsub1', - {'preConds': {'cellType': ['PYR2sec']}, # 'cellType': ['IT', 'PT', 'CT'] - 'postConds': {'popLabel': 'PYR'}, # 'popLabel': 'L5_PT' - 'sec': 'all', - 'ynormRange': [0, 1.0], - 'density': [0.2, 0.1, 0.0, 0.0, 0.2, 0.5] }) # subcellulalr distribution +# netParams.addSubConnParams('PYRsub1', +# {'preConds': {'cellType': ['PYR2sec']}, # 'cellType': ['IT', 'PT', 'CT'] +# 'postConds': {'popLabel': 'PYR'}, # 'popLabel': 'L5_PT' +# 'sec': 'all', +# 'ynormRange': [0, 1.0], +# 'density': [0.2, 0.1, 0.0, 0.0, 0.2, 0.5] }) # subcellulalr distribution @@ -214,9 +235,11 @@ simConfig.verbose = 1 #False # show detailed messages # Recording -simConfig.recordCells = [1,2] # which cells to record from +simConfig.recordCells = []# [1,2] # which cells to record from simConfig.recordTraces = {'Vsoma':{'sec':'soma','loc':0.5,'var':'v'}} -#'AMPA_i': {'sec':'soma', 'loc':0.5, 'synMech':'AMPA', 'var':'i'}} +#'AMPA_i': {'synMech':'homSyn', 'var':'i'}} +#'AMPA_i': {'synMech':'homSyn', 'sec': 'dend', 'loc': 0.775, 'var':'i'}} + simConfig.recordStim = True # record spikes of cell stims simConfig.recordStep = 0.1 # Step size in ms to save data (eg. V traces, LFP, etc) @@ -232,7 +255,7 @@ # # Analysis and plotting simConfig.addAnalysis('plotRaster', True) -#simConfig.addAnalysis('plotTraces', {'include': [1, ('PYR2',1)], 'oneFigPer':'trace'}) +simConfig.addAnalysis('plotTraces', {'include': [0], 'oneFigPer':'cell'}) # simConfig.addAnalysis('plotSpikeHist', {'include': ['PYR', 'allNetStims', 'background2', ('PYR',[5,6,7,8])], # 'timeRange': [400,600], 'binSize': 10, 'overlay':True, 'graphType': 'line', 'yaxis': 'count', 'saveData': True, 'saveFig': True, 'showFig': True}) # simConfig.addAnalysis('plot2Dnet', {'include': ['allCells']}) @@ -243,14 +266,21 @@ # RUN SIM ############################################################################### -sim.createSimulateAnalyze(netParams = netParams, simConfig = simConfig) # create and simulate network +#sim.createSimulateAnalyze(netParams = netParams, simConfig = simConfig) # create and simulate network # sim.createSimulate(netParams = netParams, simConfig = simConfig) # create and simulate network # sim.saveData() # sim.loadSimulateAnalyze('mpiHHTut.pkl') # sim.analysis.plotData() -# sim.initialize(netParams = netParams, simConfig = simConfig) -# sim.net.createPops() -# sim.net.createCells() +sim.initialize(netParams = netParams, simConfig = simConfig) +sim.net.createPops() +sim.net.createCells() +sim.net.connectCells() +sim.net.addStims() +sim.setupRecording() + +sim.simulate() + +sim.analyze() # ############################################################################### # # MODIFY and RUN SIM @@ -267,6 +297,17 @@ # 'cellConds': {'popLabel': 'PYR', 'ynorm': [0.0,0.5]}, # 'delay': 300}) +# sim.net.modifySynMechs({'conds': {'label':'homSyn', 'sec': 'soma', 'loc': [0,1]}, +# 'cellConds': {'cellType': 'PYR2sec'}, +# 'targetrate': 0.6}) + + +# for c in sim.net.cells: +# if c.tags['cellType'] == 'PYR': +# for sec in c.secs: +# for synMech in sec.synMechs: +# if synMech.label == 'homSyn': +# synMech.hSyn.targetrate = 0.6 # sim.simulate() # create and simulate network diff --git a/netpyne/__init__.py b/netpyne/__init__.py index 94c5a7daa..1f199f195 100644 --- a/netpyne/__init__.py +++ b/netpyne/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.5.9' +__version__ = '0.6.0' diff --git a/netpyne/analysis.py b/netpyne/analysis.py index be71b9cd3..e2b2022ab 100644 --- a/netpyne/analysis.py +++ b/netpyne/analysis.py @@ -6,7 +6,7 @@ Contributors: salvadordura@gmail.com """ -from matplotlib.pylab import nanmax, nanmin, errstate, bar, histogram, floor, ceil, yticks, arange, gca, scatter, figure, hold, subplot, axes, shape, imshow, \ +from matplotlib.pylab import transpose, nanmax, nanmin, errstate, bar, histogram, floor, ceil, yticks, arange, gca, scatter, figure, hold, subplot, axes, shape, imshow, \ colorbar, plot, xlabel, ylabel, title, xlim, ylim, clim, show, zeros, legend, savefig, psd, ion, subplots_adjust, subplots, tight_layout from matplotlib import gridspec from scipy import size, array, linspace, ceil @@ -528,14 +528,21 @@ def plotTraces (include = None, timeRange = None, overlay = False, oneFigPer = ' fontsiz = 12 for itrace, trace in enumerate(tracesList): if 'cell_'+str(gid) in sim.allSimData[trace]: - data = sim.allSimData[trace]['cell_'+str(gid)][int(timeRange[0]/recordStep):int(timeRange[1]/recordStep)] + fullTrace = sim.allSimData[trace]['cell_'+str(gid)] + if isinstance(fullTrace, dict): + data = [fullTrace[key][int(timeRange[0]/recordStep):int(timeRange[1]/recordStep)] for key in fullTrace.keys()] + lenData = len(data[0]) + data = transpose(array(data)) + else: + data = fullTrace[int(timeRange[0]/recordStep):int(timeRange[1]/recordStep)] + lenData = len(data) t = arange(timeRange[0], timeRange[1]+recordStep, recordStep) tracesData.append({'t': t, 'cell_'+str(gid)+'_'+trace: data}) color = colorList[itrace] if not overlay: subplot(len(tracesList),1,itrace+1) color = 'blue' - plot(t[:len(data)], data, linewidth=1.5, color=color, label=trace) + plot(t[:lenData], data, linewidth=1.5, color=color, label=trace) xlabel('Time (ms)', fontsize=fontsiz) ylabel(trace, fontsize=fontsiz) xlim(timeRange) diff --git a/netpyne/cell.py b/netpyne/cell.py index 9ee4f49a6..597f6d4c2 100644 --- a/netpyne/cell.py +++ b/netpyne/cell.py @@ -7,6 +7,7 @@ """ from numbers import Number +from copy import deepcopy from neuron import h # Import NEURON from specs import Dict import sim @@ -104,6 +105,13 @@ def createPyStruct (self, prop): for ionParamName,ionParamValue in ionParams.iteritems(): # add params of the ion sec['ions'][ionName][ionParamName] = ionParamValue + + # add synMechs + if 'synMechs' in sectParams: + for synMech in sectParams['synMechs']: + if 'label' in synMech and 'loc' in synMech: + self.addSynMech(synLabel=synMech['label'], secLabel=sectName, loc=synMech['loc']) + # add point processes if 'pointps' in sectParams: for pointpName,pointpParams in sectParams['pointps'].iteritems(): @@ -339,6 +347,8 @@ def addSynMech (self, synLabel, secLabel, loc): synMech = next((synMech for synMech in sec['synMechs'] if synMech['label']==synLabel and synMech['loc']==loc), None) if not synMech: # if synMech not in section, then create synMech = Dict({'label': synLabel, 'loc': loc}) + for paramName, paramValue in synMechParams.iteritems(): + synMech[paramName] = paramValue sec['synMechs'].append(synMech) if sim.cfg.createNEURONObj: @@ -357,15 +367,112 @@ def addSynMech (self, synLabel, secLabel, loc): if synParamName not in ['label', 'mod', 'selfNetCon', 'loc']: setattr(synMech['hSyn'], synParamName, synParamValue) elif synParamName == 'selfNetCon': # create self netcon required for some synapses (eg. homeostatic) - synMech['hNetCon'] = h.NetCon(sec['hSec'](loc)._ref_v, synMech['hSyn'], sec=sec['hSec']) + secLabelNetCon = synParamValue.get('sec', 'soma') + locNetCon = synParamValue.get('loc', 0.5) + secNetCon = self.secs.get(secLabelNetCon, None) + synMech['hNetCon'] = h.NetCon(secNetCon['hSec'](locNetCon)._ref_v, synMech['hSyn'], sec=secNetCon['hSec']) for paramName,paramValue in synParamValue.iteritems(): if paramName == 'weight': synMech['hNetCon'].weight[0] = paramValue - else: + elif paramName not in ['sec', 'loc']: setattr(synMech['hNetCon'], paramName, paramValue) return synMech + def modifySynMechs (self, params): + conditionsMet = 1 + if 'cellConds' in params: + if conditionsMet: + for (condKey,condVal) in params['cellConds'].iteritems(): # check if all conditions are met + # check if conditions met + if isinstance(condVal, list): + if self.tags.get(condKey) < condVal[0] or self.tags.get(condKey) > condVal[1]: + conditionsMet = 0 + break + elif self.tags.get(condKey) != condVal: + conditionsMet = 0 + break + + if conditionsMet: + for secLabel,sec in self.secs.iteritems(): + for synMech in sec['synMechs']: + conditionsMet = 1 + if 'conds' in params: + for (condKey,condVal) in params['conds'].iteritems(): # check if all conditions are met + # check if conditions met + if condKey == 'sec': + if condVal != secLabel: + conditionsMet = 0 + break + elif isinstance(condVal, list) and isinstance(condVal[0], Number): + if synMech.get(condKey) < condVal[0] or synMech.get(condKey) > condVal[1]: + conditionsMet = 0 + break + elif isinstance(condVal, list) and isinstance(condVal[0], str): + if synMech.get(condKey) not in condVal: + conditionsMet = 0 + break + elif synMech.get(condKey) != condVal: + conditionsMet = 0 + break + + if conditionsMet: # if all conditions are met, set values for this cell + exclude = ['conds', 'cellConds', 'label', 'mod', 'selfNetCon', 'loc'] + for synParamName,synParamValue in {k: v for k,v in params.iteritems() if k not in exclude}.iteritems(): + if sim.cfg.createPyStruct: + synMech[synParamName] = synParamValue + if sim.cfg.createNEURONObj: + try: + setattr(synMech['hSyn'], synParamName, synParamValue) + except: + print 'Error setting %s=%s on synMech' % (synParamName, str(synParamValue)) + + + + + # Custom code for time-dependently shaping the weight of a NetCon corresponding to a NetStim. + def _shapeStim(self, isi=1, variation=0, width=0.05, weight=10, start=0, finish=1, stimshape='gaussian'): + from pylab import r_, convolve, shape, exp, zeros, hstack, array, rand + + # Create event times + timeres = 0.001 # Time resolution = 1 ms = 500 Hz (DJK to CK: 500...?) + pulselength = 10 # Length of pulse in units of width + currenttime = 0 + timewindow = finish-start + allpts = int(timewindow/timeres) + output = [] + while currenttime=0 and currenttime condVal[1]: + if isinstance(condVal, list): + if self.tags.get(condKey) < condVal[0] or self.tags.get(condKey) > condVal[1]: conditionsMet = 0 break - elif isinstance(condVal, list) and isinstance(condVal[0], str): - if self.tags[condKey] not in condVal: - conditionsMet = 0 - break - elif stim[condKey] != condVal: + elif self.tags.get(condKey) != condVal: conditionsMet = 0 break - if conditionsMet and 'cellConds' in params: - if conditionsMet: - for (condKey,condVal) in params['cellConds'].iteritems(): # check if all conditions are met + if conditionsMet == 1: + for stim in self.stims: + conditionsMet = 1 + + if 'conds' in params: + for (condKey,condVal) in params['conds'].iteritems(): # check if all conditions are met # check if conditions met - if isinstance(condVal, list): - if self.tags.get(condKey) < condVal[0] or self.tags.get(condKey) > condVal[1]: + if isinstance(condVal, list) and isinstance(condVal[0], Number): + if stim.get(condKey) < condVal[0] or stim.get(condKey) > condVal[1]: conditionsMet = 0 break - elif self.tags.get(condKey) != condVal: + elif isinstance(condVal, list) and isinstance(condVal[0], str): + if stim.get(condKey) not in condVal: + conditionsMet = 0 + break + elif stim.get(condKey) != condVal: conditionsMet = 0 break - if conditionsMet: # if all conditions are met, set values for this cell - if stim['type'] == 'NetStim': # for netstims, find associated netcon - conn = next((conn for conn in self.conns if conn['source'] == stim['source']), None) - if sim.cfg.createPyStruct: - for paramName, paramValue in {k: v for k,v in params.iteritems() if k not in ['conds','cellConds']}.iteritems(): - if stim['type'] == 'NetStim' and paramName in ['weight', 'delay', 'threshold']: - conn[paramName] = paramValue - else: - stim[paramName] = paramValue - if sim.cfg.createNEURONObj: - for paramName, paramValue in {k: v for k,v in params.iteritems() if k not in ['conds','cellConds']}.iteritems(): - try: - if stim['type'] == 'NetStim': - if paramName == 'weight': - conn['hNetcon'].weight[0] = paramValue - elif paramName in ['delay', 'threshold']: - setattr(conn['hNetcon'], paramName, paramValue) + if conditionsMet: # if all conditions are met, set values for this cell + if stim['type'] == 'NetStim': # for netstims, find associated netcon + conn = next((conn for conn in self.conns if conn['source'] == stim['source']), None) + if sim.cfg.createPyStruct: + for paramName, paramValue in {k: v for k,v in params.iteritems() if k not in ['conds','cellConds']}.iteritems(): + if stim['type'] == 'NetStim' and paramName in ['weight', 'delay', 'threshold']: + conn[paramName] = paramValue else: - setattr(stim['h'+stim['type']], paramName, paramValue) - except: - print 'Error setting %s=%s on stim' % (paramName, str(paramValue)) + stim[paramName] = paramValue + if sim.cfg.createNEURONObj: + for paramName, paramValue in {k: v for k,v in params.iteritems() if k not in ['conds','cellConds']}.iteritems(): + try: + if stim['type'] == 'NetStim': + if paramName == 'weight': + conn['hNetcon'].weight[0] = paramValue + elif paramName in ['delay', 'threshold']: + setattr(conn['hNetcon'], paramName, paramValue) + else: + setattr(stim['h'+stim['type']], paramName, paramValue) + except: + print 'Error setting %s=%s on stim' % (paramName, str(paramValue)) def addNetStim (self, params, stimContainer=None): @@ -627,6 +770,7 @@ def addStim (self, params): 'delay': params.get('delay'), 'threshold': params.get('threshold'), 'synsPerConn': params.get('synsPerConn'), + 'shape': params.get('shape'), 'plast': params.get('plast')} netStimParams = {'source': params['source'], @@ -851,14 +995,34 @@ def recordTraces (self): ptr = synMech['hSyn'].__getattribute__('_ref_'+params['var']) else: # eg. soma(0.5)._ref_v ptr = self.secs[params['sec']]['hSec'](params['loc']).__getattribute__('_ref_'+params['var']) + elif 'synMech' in params: # special case where want to record from multiple synMechs + if 'sec' in params: + sec = self.secs[params['sec']] + synMechs = [synMech for synMech in sec['synMechs'] if synMech['label']==params['synMech']] + ptr = [synMech['hSyn'].__getattribute__('_ref_'+params['var']) for synMech in synMechs] + secLocs = [params.sec+str(synMech['loc']) for synMech in synMechs] + else: + ptr = [] + secLocs = [] + for secName,sec in self.secs.iteritems(): + synMechs = [synMech for synMech in sec['synMechs'] if synMech['label']==params['synMech']] + ptr.extend([synMech['hSyn'].__getattribute__('_ref_'+params['var']) for synMech in synMechs]) + secLocs.extend([secName+'_'+str(synMech['loc']) for synMech in synMechs]) + else: if 'pointp' in params: # eg. soma.izh._ref_u if params['pointp'] in self.secs[params['sec']]['pointps']: ptr = self.secs[params['sec']]['pointps'][params['pointp']]['hPointp'].__getattribute__('_ref_'+params['var']) if ptr: # if pointer has been created, then setup recording - sim.simData[key]['cell_'+str(self.gid)] = h.Vector(sim.cfg.duration/sim.cfg.recordStep+1).resize(0) - sim.simData[key]['cell_'+str(self.gid)].record(ptr, sim.cfg.recordStep) + if isinstance(ptr, list): + sim.simData[key]['cell_'+str(self.gid)] = {} + for ptrItem,secLoc in zip(ptr, secLocs): + sim.simData[key]['cell_'+str(self.gid)][secLoc] = h.Vector(sim.cfg.duration/sim.cfg.recordStep+1).resize(0) + sim.simData[key]['cell_'+str(self.gid)][secLoc].record(ptrItem, sim.cfg.recordStep) + else: + sim.simData[key]['cell_'+str(self.gid)] = h.Vector(sim.cfg.duration/sim.cfg.recordStep+1).resize(0) + sim.simData[key]['cell_'+str(self.gid)].record(ptr, sim.cfg.recordStep) if sim.cfg.verbose: print ' Recording ', key, 'from cell ', self.gid, ' with parameters: ',str(params) except: if sim.cfg.verbose: print ' Cannot record ', key, 'from cell ', self.gid diff --git a/netpyne/network.py b/netpyne/network.py index ed919388a..f438d635a 100644 --- a/netpyne/network.py +++ b/netpyne/network.py @@ -687,6 +687,7 @@ def _addCellConn (self, connParam, preCellGid, postCellGid): 'delay': finalParam['delaySynMech'], 'threshold': connParam.get('threshold'), 'synsPerConn': finalParam['synsPerConn'], + 'shape': connParam.get('shape'), 'plast': connParam.get('plast')} if sim.cfg.includeParamsLabel: params['label'] = connParam.get('label') @@ -713,6 +714,25 @@ def modifyCells (self, params): if sim.rank == 0 and sim.cfg.timing: print(' Done; cells modification time = %0.2f s.' % sim.timingData['modifyCellsTime']) + ############################################################################### + ### Modify synMech params + ############################################################################### + def modifySynMechs (self, params): + # Instantiate network connections based on the connectivity rules defined in params + sim.timing('start', 'modifySynMechsTime') + if sim.rank==0: + print('Modfying synaptic mech parameters...') + + for cell in self.cells: + cell.modifySynMechs(params) + + if hasattr(sim.net, 'allCells'): + sim._gatherCells() # update allCells + + sim.timing('stop', 'modifySynMechsTime') + if sim.rank == 0 and sim.cfg.timing: print(' Done; syn mechs modification time = %0.2f s.' % sim.timingData['modifySynMechsTime']) + + ############################################################################### ### Modify conn params diff --git a/netpyne/specs.py b/netpyne/specs.py index d46a65bce..7ef12d313 100644 --- a/netpyne/specs.py +++ b/netpyne/specs.py @@ -312,6 +312,10 @@ def importCellParams(self, label, conds, fileName, cellName, cellArgs=None, impo return self.cellParams[label] + def importCellParamsFromNet(self, labelList, condsList, fileName, cellNameList, importSynMechs=False): + utils.importCellsFromNet(self, fileName, labelList, condsList, cellNameList, importSynMechs) + return self.cellParams + def todict(self): from sim import replaceDictODict return replaceDictODict(self.__dict__) diff --git a/netpyne/utils.py b/netpyne/utils.py index 51fd78f50..ef65c827e 100644 --- a/netpyne/utils.py +++ b/netpyne/utils.py @@ -3,7 +3,7 @@ Useful functions related to the parameters file, eg. create params file from excel table -Contributors: salvadordura@gmail.com +Contributors: salvador dura@gmail.com """ import os, sys from neuron import h @@ -79,6 +79,7 @@ def _equal_dicts (d1, d2, ignore_keys): return False return True + def importCell (fileName, cellName, cellArgs = None): h.initnrn() @@ -91,8 +92,6 @@ def importCell (fileName, cellName, cellArgs = None): cell = getattr(h, cellName)(**cellArgs) # create cell using template, passing dict with args else: cell = getattr(h, cellName)(*cellArgs) # create cell using template, passing list with args - secs = list(cell.allsec()) - dirCell = dir(cell) elif fileName.endswith('.py'): filePath,fileNameOnly = os.path.split(fileName) # split path from filename if filePath not in sys.path: # add to path if not there (need to import module) @@ -104,24 +103,71 @@ def importCell (fileName, cellName, cellArgs = None): cell = getattr(modulePointer, cellName)(**cellArgs) # create cell using template, passing dict with args else: cell = getattr(modulePointer, cellName)(*cellArgs) # create cell using template, passing list with args - - dirCell = dir(cell) - - if 'all_sec' in dirCell: - secs = cell.all_sec - elif 'sec' in dirCell: - secs = [cell.sec] - elif 'allsec' in dir(h): - secs = [sec for sec in h.allsec()] - elif 'soma' in dirCell: - secs = [cell.soma] - else: - secs = [] sys.path.remove(filePath) else: print "File name should be either .hoc or .py file" return + secDic, secListDic, synMechs = getCellParams(cell) + return secDic, secListDic, synMechs + + +def importCellsFromNet (netParams, fileName, labelList, condsList, cellNamesList, importSynMechs): + h.initnrn() + + ''' Import cell from HOC template or python file into framework format (dict of sections, with geom, topol, mechs, syns)''' + if fileName.endswith('.hoc'): + print 'Importing from .hoc network not yet supported' + return + # h.load_file(fileName) + # for cellName in cellNames: + # cell = getattr(h, cellName) # create cell using template, passing dict with args + # secDic, secListDic, synMechs = getCellParams(cell) + + elif fileName.endswith('.py'): + origDir = os.getcwd() + filePath,fileNameOnly = os.path.split(fileName) # split path from filename + if filePath not in sys.path: # add to path if not there (need to import module) + sys.path.insert(0, filePath) + moduleName = fileNameOnly.split('.py')[0] # remove .py to obtain module name + os.chdir(filePath) + print '\nRunning network in %s to import cells into NetPyNE ...\n'%(fileName) + print h.name_declared('hcurrent') + from neuron import load_mechanisms + load_mechanisms(filePath) + exec('import ' + moduleName + ' as tempModule') in globals(), locals() # import module dynamically + modulePointer = tempModule + sys.path.remove(filePath) + else: + print "File name should be either .hoc or .py file" + return + + for label, conds, cellName in zip(labelList, condsList, cellNamesList): + print '\nImporting %s from %s ...'%(cellName, fileName) + exec('cell = tempModule' + '.' + cellName) + #cell = getattr(modulePointer, cellName) # get cell object + secs, secLists, synMechs = getCellParams(cell) + cellRule = {'conds': conds, 'secs': secs, 'secLists': secLists} + netParams.addCellParams(label, cellRule) + if importSynMechs: + for synMech in synMechs: netParams.addSynMechParams(synMech.pop('label'), synMech) + + +def getCellParams(cell): + dirCell = dir(cell) + + if 'all_sec' in dirCell: + secs = cell.all_sec + elif 'sec' in dirCell: + secs = [cell.sec] + elif 'allsec' in dir(h): + secs = [sec for sec in h.allsec()] + elif 'soma' in dirCell: + secs = [cell.soma] + else: + secs = [] + + # create dict with hname of each element in dir(cell) dirCellHnames = {} for dirCellName in dirCell: @@ -256,7 +302,7 @@ def importCell (fileName, cellName, cellArgs = None): # celsius warning if hasattr(h, 'celsius'): if h.celsius != 6.3: # if not default value - print "Warning: h.celsius=%.4g in imported file %s -- you can set this value in simConfig['hParams']['celsius']"%(h.celsius, fileName) + print "Warning: h.celsius=%.4g in imported file -- you can set this value in simConfig['hParams']['celsius']"%(h.celsius) # clean h.initnrn()