Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def record(self, active):
if active:
rec = h.NetCon(self.source, None, sec=self)
rec.record(self.spike_times)
h('''create soma''')
h.load_file("stdrun.hoc")
h.soma.L = 5.6419
h.soma.diam = 5.6419
h.soma.insert("hh")
ic = h.IClamp(h.soma(0.5))
ic.delay = 0.5
ic.dur = 0.1
ic.amp = 0.3
v = h.Vector()
v.record(h.soma(0.5)._ref_v, sec=h.soma)
tv = h.Vector()
tv.record(h._ref_t, sec=h.soma)
nc = h.NetCon(h.soma(0.5)._ref_v, None, sec=h.soma)
spikestime = h.Vector()
nc.record(spikestime)
h.run()
simulation_spikes = spikestime.to_python()
assert np.allclose(simulation_spikes, ref_spikes)
#continue # go to next conn
try:
postTarget = synMech['hObj']
except:
print('\nError: no synMech available for conn: ', conn)
print(' cell tags: ',self.tags)
print(' cell synMechs: ',self.secs[conn['sec']]['synMechs'])
import sys
sys.exit()
# create NetCon
if conn['preGid'] == 'NetStim':
netstim = next((stim['hObj'] for stim in self.stims if stim['source']==conn['preLabel']), None)
if netstim:
netcon = h.NetCon(netstim, postTarget)
else: continue
else:
#cell = next((c for c in sim.net.cells if c.gid == conn['preGid']), None)
netcon = sim.pc.gid_connect(conn['preGid'], postTarget)
netcon.weight[0] = conn['weight']
netcon.delay = conn['delay']
#netcon.threshold = conn.get('threshold', sim.net.params.defaultThreshold)
conn['hObj'] = netcon
# Add plasticity
if conn.get('plast'):
self._addConnPlasticity(conn['plast'], self.secs[conn['sec']], netcon, 0)
sim.pc.set_gid2node(self.gid, sim.rank) # this is the key call that assigns cell gid to a particular node
sec = next((secParams for secName,secParams in self.secs.items() if 'spikeGenLoc' in secParams), None) # check if any section has been specified as spike generator
if sec:
loc = sec['spikeGenLoc'] # get location of spike generator within section
else:
#sec = self.secs['soma'] if 'soma' in self.secs else self.secs[self.secs.keys()[0]] # use soma if exists, otherwise 1st section
sec = next((sec for secName, sec in self.secs.items() if len(sec['topol']) == 0), self.secs[list(self.secs.keys())[0]]) # root sec (no parents)
loc = 0.5
nc = None
if 'pointps' in sec: # if no syns, check if point processes with 'vref' (artificial cell)
for pointpName, pointpParams in sec['pointps'].items():
if 'vref' in pointpParams:
nc = h.NetCon(getattr(sec['pointps'][pointpName]['hObj'], '_ref_'+pointpParams['vref']), None, sec=sec['hObj'])
break
if not nc: # if still haven't created netcon
nc = h.NetCon(sec['hObj'](loc)._ref_v, None, sec=sec['hObj'])
if 'threshold' in sec: threshold = sec['threshold']
threshold = threshold if threshold is not None else sim.net.params.defaultThreshold
nc.threshold = threshold
sim.pc.cell(self.gid, nc, 1) # associate a particular output stream of events
del nc # discard netcon
sim.net.gid2lid[self.gid] = len(sim.net.gid2lid)
def create_collector(self):
"""
Greates a pair of NetStim and NetCon which trigger an event to recursively collect the activity of the group
segments. This method does nothing if group.record_activity is False
"""
if self.record_activity:
collector_stim = h.NetStim(0.5)
collector_stim.start = self.recording_time_start
collector_stim.interval = self.recording_period
collector_stim.number = 1e9
collector_stim.noise = 0
collector_con = h.NetCon(collector_stim, None)
collector_con.record((self.collect))
self.collector_stim = collector_stim
self.collector_con = collector_con
def connect2target (self,targ):
return h.NetCon(self.ofths,targ)
self.secs[synMechSecs[i]]['hSec'].push()
sim.pc.source_var(sourceVar, connParams['preGapId'])
h.pop_section()
netcon = None
# connections using NetCons
else:
if pointp:
sec = self.secs[secLabels[0]]
postTarget = sec['pointps'][pointp]['hPointp'] # local point neuron
else:
sec = self.secs[synMechSecs[i]]
postTarget = synMechs[i]['hSyn'] # local synaptic mechanism
if netStimParams:
netcon = h.NetCon(netstim, postTarget) # create Netcon between netstim and target
else:
netcon = sim.pc.gid_connect(params['preGid'], postTarget) # create Netcon between global gid and target
netcon.weight[weightIndex] = weights[i] # set Netcon weight
netcon.delay = delays[i] # set Netcon delay
#netcon.threshold = threshold # set Netcon threshold
self.conns[-1]['hNetcon'] = netcon # add netcon object to dict in conns list
# Add time-dependent weight shaping
if 'shape' in params and params['shape']:
temptimevecs = []
tempweightvecs = []
# Default shape
self.secs[synMechSecs[i]]['hObj'].push()
sim.pc.source_var(sourceVar, connParams['preGapId'])
h.pop_section()
netcon = None
# connections using NetCons
else:
if pointp:
sec = self.secs[secLabels[0]]
postTarget = sec['pointps'][pointp]['hObj'] # local point neuron
else:
sec = self.secs[synMechSecs[i]]
postTarget = synMechs[i]['hObj'] # local synaptic mechanism
if netStimParams:
netcon = h.NetCon(netstim, postTarget) # create Netcon between netstim and target
else:
netcon = sim.pc.gid_connect(params['preGid'], postTarget) # create Netcon between global gid and target
netcon.weight[weightIndex] = weights[i] # set Netcon weight
netcon.delay = delays[i] # set Netcon delay
#netcon.threshold = threshold # set Netcon threshold
self.conns[-1]['hObj'] = netcon # add netcon object to dict in conns list
# Add time-dependent weight shaping
if 'shape' in params and params['shape']:
temptimevecs = []
tempweightvecs = []
# Default shape
def create_cells(self, numcells):
""" Create cells in the network """
self.cells = []
r = numcells*10 # Radius of cell locations from origin (0,0) in microns
for i in range(numcells): # for each cell
cell = HHCell(i) # create cell object
cell.set_recording() # set up voltage recording
cell.create_synapse(loc=0.5, tau=2, e=0) # create synapse object
xpos = sin(i * 2 * pi / numcells) * r # calculate x position
ypos = cos(i * 2 * pi / numcells) * r # calculate y position
cell.set_position(xpos, ypos) # set x,y position
nc = h.NetCon(cell.soma(0.5)._ref_v, None, sec=cell.soma) # create netcon to record spikes from cell
nc.record(self.spkt, self.spkid, i)
self.cells.append(cell) # add cell to list of cells in network
print('Created cell ' + str(i))