Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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['hNetStim'] 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['hNetcon'] = netcon
# Add plasticity
if conn.get('plast'):
self._addConnPlasticity(conn['plast'], self.secs[conn['sec']], netcon, 0)
def _addConnPlasticity (self, params, sec, netcon, weightIndex):
from .. import sim
plasticity = params.get('plast')
if plasticity and sim.cfg.createNEURONObj:
try:
plastMech = getattr(h, plasticity['mech'], None)(0, sec=sec['hSec']) # create plasticity mechanism (eg. h.STDP)
for plastParamName,plastParamValue in plasticity['params'].items(): # add params of the plasticity mechanism
setattr(plastMech, plastParamName, plastParamValue)
if plasticity['mech'] == 'STDP': # specific implementation steps required for the STDP mech
precon = sim.pc.gid_connect(params['preGid'], plastMech); precon.weight[0] = 1 # Send presynaptic spikes to the STDP adjuster
pstcon = sim.pc.gid_connect(self.gid, plastMech); pstcon.weight[0] = -1 # Send postsynaptic spikes to the STDP adjuster
h.setpointer(netcon._ref_weight[weightIndex], 'synweight', plastMech) # Associate the STDP adjuster with this weight
#self.conns[-1]['hPlastSection'] = plastSection
self.conns[-1]['hSTDP'] = plastMech
self.conns[-1]['hSTDPprecon'] = precon
self.conns[-1]['hSTDPpstcon'] = pstcon
self.conns[-1]['STDPdata'] = {'preGid':params['preGid'], 'postGid': self.gid, 'receptor': weightIndex} # Not used; FYI only; store here just so it's all in one place
if sim.cfg.verbose: print(' Added STDP plasticity to synaptic mechanism')
except:
print('Error: exception when adding plasticity using %s mechanism' % (plasticity['mech']))
def _addConnPlasticity (self, params, sec, netcon, weightIndex):
from .. import sim
plasticity = params.get('plast')
if plasticity and sim.cfg.createNEURONObj:
try:
plastMech = getattr(h, plasticity['mech'], None)(0, sec=sec['hObj']) # create plasticity mechanism (eg. h.STDP)
for plastParamName,plastParamValue in plasticity['params'].items(): # add params of the plasticity mechanism
setattr(plastMech, plastParamName, plastParamValue)
if plasticity['mech'] == 'STDP': # specific implementation steps required for the STDP mech
precon = sim.pc.gid_connect(params['preGid'], plastMech); precon.weight[0] = 1 # Send presynaptic spikes to the STDP adjuster
pstcon = sim.pc.gid_connect(self.gid, plastMech); pstcon.weight[0] = -1 # Send postsynaptic spikes to the STDP adjuster
h.setpointer(netcon._ref_weight[weightIndex], 'synweight', plastMech) # Associate the STDP adjuster with this weight
#self.conns[-1]['hPlastSection'] = plastSection
self.conns[-1]['hSTDP'] = plastMech
self.conns[-1]['hSTDPprecon'] = precon
self.conns[-1]['hSTDPpstcon'] = pstcon
self.conns[-1]['STDPdata'] = {'preGid':params['preGid'], 'postGid': self.gid, 'receptor': weightIndex} # Not used; FYI only; store here just so it's all in one place
if sim.cfg.verbose: print(' Added STDP plasticity to synaptic mechanism')
except:
print('Error: exception when adding plasticity using %s mechanism' % (plasticity['mech']))
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
pulsetype = params['shape']['pulseType'] if 'pulseType' in params['shape'] else 'square'
pulsewidth = params['shape']['pulseWidth'] if 'pulseWidth' in params['shape'] else 100.0
connParams['preLabel'] = netStimParams['source']
self.conns.append(Dict(connParams))
else: # do not fill in python structure (just empty dict for NEURON obj)
self.conns.append(Dict())
# NEURON objects
if sim.cfg.createNEURONObj:
if 'vref' in self.tags:
postTarget = getattr(self.hPointp, '_ref_'+self.tags['vref']) # local point neuron
else:
postTarget = self.hPointp
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
pulsetype = params['shape']['pulseType'] if 'pulseType' in params['shape'] else 'square'
pulsewidth = params['shape']['pulseWidth'] if 'pulseWidth' in params['shape'] else 100.0
pulseperiod = params['shape']['pulsePeriod'] if 'pulsePeriod' in params['shape'] else 100.0
def _addConnPlasticity (self, params, sec, netcon, weightIndex):
from .. import sim
plasticity = params.get('plast')
if plasticity and sim.cfg.createNEURONObj:
try:
plastMech = getattr(h, plasticity['mech'], None)(0, sec=sec['hSec']) # create plasticity mechanism (eg. h.STDP)
for plastParamName,plastParamValue in plasticity['params'].items(): # add params of the plasticity mechanism
setattr(plastMech, plastParamName, plastParamValue)
if plasticity['mech'] == 'STDP': # specific implementation steps required for the STDP mech
precon = sim.pc.gid_connect(params['preGid'], plastMech); precon.weight[0] = 1 # Send presynaptic spikes to the STDP adjuster
pstcon = sim.pc.gid_connect(self.gid, plastMech); pstcon.weight[0] = -1 # Send postsynaptic spikes to the STDP adjuster
h.setpointer(netcon._ref_weight[weightIndex], 'synweight', plastMech) # Associate the STDP adjuster with this weight
#self.conns[-1]['hPlastSection'] = plastSection
self.conns[-1]['hSTDP'] = plastMech
self.conns[-1]['hSTDPprecon'] = precon
self.conns[-1]['hSTDPpstcon'] = pstcon
self.conns[-1]['STDPdata'] = {'preGid':params['preGid'], 'postGid': self.gid, 'receptor': weightIndex} # Not used; FYI only; store here just so it's all in one place
if sim.cfg.verbose: print(' Added STDP plasticity to synaptic mechanism')
except:
print('Error: exception when adding plasticity using %s mechanism' % (plasticity['mech']))
def _addConnPlasticity (self, params, sec, netcon, weightIndex):
from .. import sim
plasticity = params.get('plast')
if plasticity and sim.cfg.createNEURONObj:
try:
plastMech = getattr(h, plasticity['mech'], None)(0, sec=sec['hObj']) # create plasticity mechanism (eg. h.STDP)
for plastParamName,plastParamValue in plasticity['params'].items(): # add params of the plasticity mechanism
setattr(plastMech, plastParamName, plastParamValue)
if plasticity['mech'] == 'STDP': # specific implementation steps required for the STDP mech
precon = sim.pc.gid_connect(params['preGid'], plastMech); precon.weight[0] = 1 # Send presynaptic spikes to the STDP adjuster
pstcon = sim.pc.gid_connect(self.gid, plastMech); pstcon.weight[0] = -1 # Send postsynaptic spikes to the STDP adjuster
h.setpointer(netcon._ref_weight[weightIndex], 'synweight', plastMech) # Associate the STDP adjuster with this weight
#self.conns[-1]['hPlastSection'] = plastSection
self.conns[-1]['hSTDP'] = plastMech
self.conns[-1]['hSTDPprecon'] = precon
self.conns[-1]['hSTDPpstcon'] = pstcon
self.conns[-1]['STDPdata'] = {'preGid':params['preGid'], 'postGid': self.gid, 'receptor': weightIndex} # Not used; FYI only; store here just so it's all in one place
if sim.cfg.verbose: print(' Added STDP plasticity to synaptic mechanism')
except:
print('Error: exception when adding plasticity using %s mechanism' % (plasticity['mech']))