from netpyne import specs, sim

# Network parameters
netParams = specs.NetParams()  # object of class NetParams to store the network parameters

## Population parameters
netParams.popParams['Epop'] = {'cellType': 'E', 'numCells': 50, 'cellModel': 'HH', 'diversity': True}
netParams.popParams['Ipop'] = {'cellType': 'I', 'numCells': 40, 'cellModel': 'HH', 'diversity': True}


## Cell property rules
# E variant 1
cellRule = {'conds': {'cellType': 'E'}, 'diversityFraction': 0.1 , 'secs': {}}  # cell rule dict
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.cellParams['E1rule'] = cellRule                          # add dict to list of cell params

# E variant 2
cellRule = {'conds': {'cellType': 'E'}, 'diversityFraction': 0.5, 'secs': {}}  # cell rule dict
cellRule['secs']['soma'] = {'geom': {}, 'mechs': {}}                              # soma params dict
cellRule['secs']['soma']['geom'] = {'diam': 20, '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.cellParams['E2rule'] = cellRule                          # add dict to list of cell params

# E variant 3
cellRule = {'conds': {'cellType': 'E'}, 'diversityFraction': 0.4, 'secs': {}}  # cell rule dict
cellRule['secs']['soma'] = {'geom': {}, 'mechs': {}}                              # soma params dict
cellRule['secs']['soma']['geom'] = {'diam': 25, '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.cellParams['E3rule'] = cellRule                          # add dict to list of cell params

# I variant 1
cellRule = {'conds': {'cellType': 'I'}, 'diversityFraction': 0.8, 'secs': {}}  # cell rule dict
cellRule['secs']['soma'] = {'geom': {}, 'mechs': {}}                              # soma params dict
cellRule['secs']['soma']['geom'] = {'diam': 5.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.cellParams['I1rule'] = cellRule                          # add dict to list of cell params

# I variant 2
cellRule = {'conds': {'cellType': 'I'}, 'diversityFraction': 0.2, '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.cellParams['I2rule'] = cellRule


# Simulation options
simConfig = specs.SimConfig()        # object of class SimConfig to store simulation configuration

# Create network and run simulation
sim.create(netParams = netParams, simConfig = simConfig)
