Skip to content

Commit

Permalink
cfg.connRandomSecFromList and cfg.distributeSynsUniformly can now be …
Browse files Browse the repository at this point in the history
…overriden in individual conn rule
  • Loading branch information
vvbragin committed Apr 5, 2024
1 parent 9e34541 commit f4d5e1c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

**New features**

- cfg.connRandomSecFromList and cfg.distributeSynsUniformly can now be overriden in individual conn rule

**Bug fixes**

- Better handling of exceptions in `importCellParams()` (incl. issue 782)
Expand Down
22 changes: 10 additions & 12 deletions netpyne/cell/compartCell.py
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,9 @@ def _setConnPointP(self, params, secLabels, weightIndex):
def _setConnSynMechs(self, params, secLabels):
from .. import sim

distributeSynsUniformly = params.get('distributeSynsUniformly', sim.cfg.distributeSynsUniformly)
connRandomSecFromList = params.get('connRandomSecFromList', sim.cfg.connRandomSecFromList)

synsPerConn = params['synsPerConn']
if not params.get('synMech'):
if sim.net.params.synMechParams: # if no synMech specified, but some synMech params defined
Expand Down Expand Up @@ -1515,20 +1518,17 @@ def _setConnSynMechs(self, params, secLabels):
synMechLocs = [i * (1.0 / synsPerConn) + 1.0 / synsPerConn / 2 for i in range(synsPerConn)]
else:
# if multiple sections, distribute syns uniformly
if sim.cfg.distributeSynsUniformly:
if distributeSynsUniformly:
synMechSecs, synMechLocs = self._distributeSynsUniformly(secList=secLabels, numSyns=synsPerConn)
else:
if not sim.cfg.connRandomSecFromList and synsPerConn == len(
secLabels
): # have list of secs that matches num syns
# have list of secs that matches num syns
if not connRandomSecFromList and synsPerConn == len(secLabels):
synMechSecs = secLabels
if isinstance(params['loc'], list):
if len(params['loc']) == synsPerConn: # list of locs matches num syns
synMechLocs = params['loc']
else: # list of locs does not match num syns
print(
"Error: The length of the list of locations does not match synsPerConn (with cfg.distributeSynsUniformly = False"
)
print("Error: The length of the list of locations does not match synsPerConn (with distributeSynsUniformly = False)")
return
else: # single loc
synMechLocs = [params['loc']] * synsPerConn
Expand All @@ -1537,7 +1537,7 @@ def _setConnSynMechs(self, params, secLabels):
synMechLocs = params['loc'] if isinstance(params['loc'], list) else [params['loc']]

# randomize the section to connect to and move it to beginning of list
if sim.cfg.connRandomSecFromList and len(synMechSecs) >= synsPerConn:
if connRandomSecFromList and len(synMechSecs) >= synsPerConn:
if len(synMechLocs) == 1:
synMechLocs = [params['loc']] * synsPerConn
rand = h.Random()
Expand All @@ -1554,9 +1554,7 @@ def _setConnSynMechs(self, params, secLabels):
rand.uniform(0, 1)
synMechLocs = [rand.repick() for i in range(synsPerConn)]
else:
print(
"\nError: The length of the list of sections needs to be greater or equal to the synsPerConn (with cfg.connRandomSecFromList = True"
)
print("\nError: The length of the list of sections needs to be greater or equal to the synsPerConn (with connRandomSecFromList = True)")
return

else: # if 1 synapse
Expand All @@ -1565,7 +1563,7 @@ def _setConnSynMechs(self, params, secLabels):
synMechLocs = params['loc'] if isinstance(params['loc'], list) else [params['loc']]

# randomize the section to connect to and move it to beginning of list
if sim.cfg.connRandomSecFromList and len(synMechSecs) > 1:
if connRandomSecFromList and len(synMechSecs) > 1:
rand = h.Random()
preGid = params['preGid'] if isinstance(params['preGid'], int) else 0
rand.Random123(sim.hashStr('connSynMechsSecs'), self.gid, preGid) # initialize randomizer
Expand Down
5 changes: 5 additions & 0 deletions netpyne/network/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,11 @@ def _addCellConn(self, connParam, preCellGid, postCellGid, preCellsTags={}):
if 'weightIndex' in connParam:
params['weightIndex'] = connParam.get('weightIndex')

if 'distributeSynsUniformly' in connParam:
params['distributeSynsUniformly'] = connParam['distributeSynsUniformly']
if 'connRandomSecFromList' in connParam:
params['connRandomSecFromList'] = connParam['connRandomSecFromList']

isGapJunction = 'gapJunction' in connParam # deprecated way of defining gap junction
if self.params.synMechParams.isPointerConn(params['synMech']) or isGapJunction:
params['preLoc'] = connParam.get('preLoc')
Expand Down

0 comments on commit f4d5e1c

Please sign in to comment.