from netpyne import specs, sim
import os

# Information
hoc_file = 'ECtemplate.hoc'
cell_name = 'ECcell'

cell_label = 'Pyr_EC'
cell_type = 'PYR'
cell_model = 'PYR'

output_dir = 'output'
if not os.path.exists(output_dir):
    os.mkdir(output_dir)

###############################################################################
# NetPyNE network specifications
netParams = specs.NetParams()

# Create population
pop_label = cell_label+'_pop'
netParams.popParams[pop_label] = {'cellType': cell_type, 
                                  'cellModel': cell_model,
                                  'numCells': 1}

# Import cell into cellParams
importedCellParams = netParams.importCellParams(label=cell_label,
                                                conds={'cellType': cell_type, 'cellModel': cell_model},
                                                fileName=hoc_file,
                                                cellName=cell_name
                                                )

###############################################################################
# NetPyNE config
simConfig = specs.SimConfig()					            # object of class SimConfig to store simulation configuration
simConfig.duration = 200 						            # Duration of the simulation, in ms
simConfig.dt = 0.01								                # Internal integration timestep to use
simConfig.verbose = True							                # Show detailed messages
simConfig.recordTraces = {'V_soma':{'sec':'soma','loc':0.5,'var':'v'}}  # Dict with traces to record
simConfig.recordStep = 0.01
simConfig.filename = os.path.join(output_dir,cell_name) 			# Set file output name
simConfig.saveJson = False
simConfig.analysis['plotTraces'] = {'include': ['all'], 'saveFig': True} # Plot recorded traces for this list of cells
simConfig.hParams['v_init'] = -70

### Run simulation ###
sim.createSimulateAnalyze(netParams = netParams, simConfig = simConfig)

### Plot morphology ###
sim.analysis.plotShape(showSyns=True, dist=0.6, saveFig=True)