<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Importing Cells in NetPyNE
(1) Clone repository and compile mod files
Determine your location in the directory structure
Step1:  Move to (or stay in) the '/content' directory
Step2:  Ensure you are in the correct directory --> Expected output
Step3:  Install NEURON and NetPyNE, and import matplotlib
Step4:  This next line will detect if the directory already exists (i.e. you are re-running this code), and will delete it to prevent future errors.
Step5:  Clone repository with the necessary cell and mod files
Step6:  Move into the repository with all the necessary files
Step7:  Ensure you are in the repository with the 'pwd' command --> Expected output
Step8:  Compile the mod files --> Expected output
Step9:  (2) Importing cells from different file formats
Set up netParams object
Step10:  2a. Import cell from .json format
Step11:  2b. Import a detailed morphology from a .swc file
Step12:  2c. Import a cell from a .hoc (NEURON) file
Step13:  2d. Import a cell from a .py (python) file
Step14:  EXERCISE
Step15:  (3) Explore and manipulate cell parameters
Explore the cell types located in the netParams.cellParams dictionary
Step16:  EXERCISE
Step17:  EXERCISE
Step18:  Now we want to explore (and change) the values of a channel parameter in a given cell model
Step19:  EXERCISE
Step20:  EXERCISE
Step21:  Now let's see how these changes affect the cell behavior by plotting cell's response to current input before and after param changes!
EXERCISE
Step22:  EXERCISE
Step23:  Add cfg params
Step24:  Create network and run simulation
Step25:  EXERCISE
Step26:  Run the sim
Step27:  (4) Plotting Morphology
Step28:  EXERCISE
Step29:  Now let's set the propagation velocity and length constant
Step30:  EXERCISE
Step31:  Add some network stimulation parameters
Step32:  EXERCISE
Step33:  Add cell connectivity rules
EXERCISE
Step34:  EXERCISE
<ASSISTANT_TASK:>
Python Code:
!pwd
Explanation: Importing Cells in NetPyNE
(1) Clone repository and compile mod files
Determine your location in the directory structure
End of explanation
%cd /content/
Explanation: Move to (or stay in) the '/content' directory
End of explanation
!pwd
Explanation: Ensure you are in the correct directory --> Expected output: "/content"
End of explanation
!pip install neuron
!pip install netpyne 
import matplotlib
import os
import json
%matplotlib inline
Explanation: Install NEURON and NetPyNE, and import matplotlib
End of explanation
if os.path.isdir('/content/cells_netpyne2021'):
  !rm -r /content/cells_netpyne2021
Explanation: This next line will detect if the directory already exists (i.e. you are re-running this code), and will delete it to prevent future errors.
End of explanation
!git clone https://github.com/ericaygriffith/cells_netpyne2021.git
Explanation: Clone repository with the necessary cell and mod files
End of explanation
cd cells_netpyne2021/
Explanation: Move into the repository with all the necessary files
End of explanation
!pwd
Explanation: Ensure you are in the repository with the 'pwd' command --> Expected output: '/content/cells_netpyne2021'
End of explanation
!nrnivmodl
Explanation: Compile the mod files --> Expected output: creation of an 'x86_64' directory
End of explanation
from netpyne import specs, sim   
# Network parameters
netParams = specs.NetParams()  # object of class NetParams to store the network parameters
Explanation: (2) Importing cells from different file formats
Set up netParams object
End of explanation
netParams.loadCellParamsRule(label='TC_reduced', fileName = 'TC_reduced_cellParams.json')
netParams.cellParams['TC_reduced']
Explanation: 2a. Import cell from .json format
End of explanation
netParams.importCellParams(
        label='PYR_HH3D_swc',
        conds={'cellType': 'PYR', 'cellModel': 'HH3D_swc'},
        fileName='BS0284.swc',
        cellName='swc_cell')
netParams.cellParams.keys()
Explanation: 2b. Import a detailed morphology from a .swc file
End of explanation
netParams.importCellParams(
        label='PYR_HH3D_hoc',
        conds={'cellType': 'PYR', 'cellModel': 'HH3D_hoc'},
        fileName='geom.hoc',
        cellName='E21',
        importSynMechs=False)
netParams.cellParams.keys()
Explanation: 2c. Import a cell from a .hoc (NEURON) file
End of explanation
netParams.importCellParams(
        label='sRE_py',
        conds={'cellType': 'sRE', 'cellModel': 'HH'},
        fileName='sRE.py',
        cellName='sRE',
        importSynMechs=False)
netParams.cellParams.keys()
Explanation: 2d. Import a cell from a .py (python) file
End of explanation
netParams.importCellParams(
    label='mouse_hipp_swc',
    conds={'cellType': 'hipp','cellModel': 'HH3D'},
    fileName='mouseGABA_hipp.swc',
    cellName='swc_hippCell'
)
netParams.cellParams.keys()
Explanation: EXERCISE: import the other swc file contained in the cells_netpyne2021 directory
End of explanation
netParams.cellParams.keys()
Explanation: (3) Explore and manipulate cell parameters
Explore the cell types located in the netParams.cellParams dictionary
End of explanation
netParams.cellParams['TC_reduced']['secs']['soma']['geom']['L']
geom_TC = netParams.cellParams['TC_reduced']['secs']['soma']['geom']
geom_TC['L']
Explanation: EXERCISE: Find the geometry (length & diameter) of the soma compartment for each of the above cells
End of explanation
netParams.cellParams['TC_reduced']['secs']['soma']['mechs'].keys()
Explanation: EXERCISE: List all of the channel mechanisms in the soma compartment of the thalamocortical cell model (TC_reduced)
End of explanation
netParams.cellParams['TC_reduced']['secs']['soma']['mechs'].keys()
netParams.cellParams['TC_reduced']['secs']['soma']['mechs']['pas'].keys()
netParams.cellParams['TC_reduced']['secs']['soma']['mechs']['pas']['g'] = 5.0e05
netParams.cellParams['TC_reduced']['secs']['soma']['mechs']['pas']['g']
Explanation: Now we want to explore (and change) the values of a channel parameter in a given cell model
End of explanation
netParams.cellParams['mouse_hipp_swc']['secs']['soma_0']['mechs']['pas'] = {'g': 0.0000357, 'e': -70}
Explanation: EXERCISE: Change the conductance of the leak channel in the soma compartment of the reticular cell model (sRE.py)
EXERCISE: Insert a passive leak channel ('pas') into the soma compartment of the mouseGABA_hipp.swc cell model
End of explanation
for sec in netParams.cellParams['PYR_HH3D_swc']['secs'].keys():
  netParams.cellParams['PYR_HH3D_swc']['secs'][sec]['geom']['cm'] = 1
Explanation: EXERCISE: Change the capacitance of all compartments in the model defined by BS0284.swc (PYR_HH3D_swc)
End of explanation
netParams.popParams['TC_pop'] = {'cellType': 'TC', 'numCells': 1, 'cellModel': 'HH_reduced'}
Explanation: Now let's see how these changes affect the cell behavior by plotting cell's response to current input before and after param changes!
EXERCISE: First create a population of thalamocortical cells
End of explanation
netParams.stimTargetParams['Input->TC_pop'] = {'source': 'Input', 'sec':'soma', 'loc': 0.5, 'conds': {'pop':'TC_pop'}}
Explanation: EXERCISE: Add hyperpolarizing current clamp stimulation of -0.1 nA to thalamocortical cell pop
End of explanation
## cfg  
cfg = specs.SimConfig()					            # object of class SimConfig to store simulation configuration
cfg.duration = 2*1e3 						            # Duration of the simulation, in ms
cfg.dt = 0.01								                # Internal integration timestep to use
cfg.verbose = 1							                # Show detailed messages 
cfg.recordTraces = {'V_soma':{'sec':'soma','loc':0.5,'var':'v'}}  # Dict with traces to record
cfg.recordStep = 0.01 			
cfg.filename = 'model_output'  			# Set file output name
cfg.saveJson = False
cfg.analysis['plotTraces'] = {'include': [0], 'saveFig': True} # Plot recorded traces for this list of cells
cfg.hParams['celsius'] = 36
Explanation: Add cfg params
End of explanation
sim.createSimulateAnalyze(netParams = netParams, simConfig = cfg)
Explanation: Create network and run simulation
End of explanation
## cfg  
cfg = specs.SimConfig()					            # object of class SimConfig to store simulation configuration
cfg.duration = 2*1e3 						            # Duration of the simulation, in ms
cfg.dt = 0.01								                # Internal integration timestep to use
cfg.verbose = 1							                # Show detailed messages 
cfg.recordTraces = {'V_soma':{'sec':'soma','loc':0.5,'var':'v'}}  # Dict with traces to record
cfg.recordStep = 0.01 			
cfg.filename = 'model_output'  			# Set file output name
cfg.saveJson = False
cfg.analysis['plotTraces'] = {'include': [0], 'saveFig': True} # Plot recorded traces for this list of cells
cfg.hParams['celsius'] = 36
Explanation: EXERCISE: We see a rebound burst! T-type calcium channels are normally considered responsible for this behavior. What happens if we set the conductance of this channel to 0?
cfg params
End of explanation
sim.createSimulateAnalyze(netParams = netParams, simConfig = cfg)
Explanation: Run the sim
End of explanation
netParams.popParams['HH3D_pop_hoc'] = {'cellType': 'PYR', 'numCells': 1, 'cellModel': 'HH3D_hoc'}
sim.createSimulateAnalyze(netParams = netParams, simConfig = cfg)
%matplotlib inline
sim.analysis.plotShape(includePre = [], includePost=['HH3D_pop_hoc'], showSyns=False, figSize=(4,9), dist=0.8, saveFig=True)
Explanation: (4) Plotting Morphology
End of explanation
netParams.sizeX = 200
Explanation: EXERCISE: Try plotting the morphology of other cell models
(5) Making a Network
EXERCISE: To begin creating a network, specify the geometry of the area you would like to model.
End of explanation
netParams.propVelocity = 100.0 # propagation velocity (um/ms)
netParams.probLengthConst = 150.0 # length constant for conn probability (um)
Explanation: Now let's set the propagation velocity and length constant:
End of explanation
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
Explanation: EXERCISE: Now establish a few populations of cells
Now we need some synaptic mechanism parameters
End of explanation
netParams.stimSourceParams['bkg'] = {'type': 'NetStim', 'rate': 40, 'noise': 0.3}
Explanation: Add some network stimulation parameters
End of explanation
netParams.stimTargetParams['bkg->all'] = {'source': 'bkg',
                                          'conds': {'cellType': ['E','I']}, 
                                          'weight': 10.0, 'sec': 'soma', 
                                          'delay': 'max(1, normal(5,2))', 
                                          'synMech': 'exc'}
Explanation: EXERCISE: modify the line below such that your stim object can target the populations in your network
End of explanation
netParams.connParams['E->all'] = {
  'preConds': {'cellType': 'E'}, 'postConds': {'y': [100,1000]},  #  E -> all (100-1000 um)
  'probability': 0.1 ,                  # probability of connection
  'weight': '5.0*post_ynorm',         # synaptic weight
  'delay': 'dist_3D/propVelocity',      # transmission delay (ms)
  'synMech': 'exc'}                     # synaptic mechanism
Explanation: Add cell connectivity rules
EXERCISE: modify the lines below to fit your network
End of explanation
cfg.analysis['plot2Dnet'] = {'saveFig': True}                                                # plot 2D cell positions and connections
cfg.analysis['plotConn'] = {'saveFig': True}                                                 # plot connectivity matrix
Explanation: EXERCISE: Add the appropriate line(s) to run the network and plot a 2D representation of your network w/ connectivity between cells
End of explanation
<END_TASK>