How to use the netpyne.sim.net function in netpyne

To help you get started, we’ve selected a few netpyne examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Neurosim-lab / netpyne / netpyne / sim / wrappers.py View on Github external
def create (netParams=None, simConfig=None, output=False):
    ''' Sequence of commands to create network '''
    from .. import sim
    import __main__ as top
    if not netParams: netParams = top.netParams
    if not simConfig: simConfig = top.simConfig

    sim.initialize(netParams, simConfig)  # create network object and set cfg and net params
    pops = sim.net.createPops()                  # instantiate network populations
    cells = sim.net.createCells()                 # instantiate network cells based on defined populations
    conns = sim.net.connectCells()                # create connections between cells based on params
    stims = sim.net.addStims()                    # add external stimulation to cells (IClamps etc)
    rxd = sim.net.addRxD()                    # add reaction-diffusion (RxD)
    simData = sim.setupRecording()             # setup variables to record for each cell (spikes, V traces, etc)

    if output: return (pops, cells, conns, rxd, stims, simData)
github Neurosim-lab / netpyne / netpyne / cell / cell.py View on Github external
def calculateCorrectBorderDist (self):
        from .. import sim

        pop = self.tags['pop']
        popParams = sim.net.params.popParams
        coords = ['x', 'y', 'z']
        borderCorrect = [0,0,0]
        for icoord,coord in enumerate(coords):
            # calculate borders
            size = getattr(sim.net.params, 'size'+coord.upper())
            borders = [0, size]
            if coord+'borders' in sim.net.params.correctBorder:
                borders = [b*size for b in sim.net.params.correctBorder[coord+'borders']]
            elif coord+'Range' in popParams[pop]:
                borders = popParams[pop][coord+'Range']
            elif coord+'normRange' in popParams[pop]:
                borders = [popParams[pop][coord+'normRange'][0] * size,
                        popParams[pop][coord+'normRange'][1] * size]
            
            # calcualte distance to border
            borderDist = min([abs(self.tags[coord] - border) for border in borders])
            borderThreshold = sim.net.params.correctBorder['threshold'][icoord]
            borderCorrect[icoord] = max(0, borderThreshold - borderDist)
        self.tags['borderCorrect'] = borderCorrect
github Neurosim-lab / netpyne / examples / rxd_net / init.py View on Github external
MPI usage:
    mpiexec -n 4 nrniv -python -mpi init.py

Contributors: salvadordura@gmail.com
"""

from netpyne import sim
from netParams import netParams
from cfg import cfg

# --------------------------------
# Instantiate network 
# --------------------------------
sim.initialize(netParams, cfg)  # create network object and set cfg and net params
sim.net.createPops()                  # instantiate network populations
sim.net.createCells()                 # instantiate network cells based on defined populations
sim.net.connectCells()                # create connections between cells based on params
sim.net.addStims()                    # add external stimulation to cells (IClamps etc)
sim.net.addRxD()                      # add reaction-diffusion (RxD)
sim.setupRecording()             # setup variables to record for each cell (spikes, V traces, etc)
sim.simulate()
sim.analyze()      
github Neurosim-lab / netpyne / netpyne / cell / compartCell.py View on Github external
def _setConnSynMechs (self, params, secLabels):
        from .. import sim

        synsPerConn = params['synsPerConn']
        if not params.get('synMech'):
            if sim.net.params.synMechParams:  # if no synMech specified, but some synMech params defined
                synLabel = list(sim.net.params.synMechParams.keys())[0]  # select first synMech from net params and add syn
                params['synMech'] = synLabel
                if sim.cfg.verbose: print('  Warning: no synaptic mechanisms specified for connection to cell gid=%d so using %s '%(self.gid, synLabel))
            else: # if no synaptic mechanism specified and no synMech params available 
                if sim.cfg.verbose: print('  Error: no synaptic mechanisms available to add conn on cell gid=%d '%(self.gid))
                return -1  # if no Synapse available print error and exit

        # if desired synaptic mechanism specified in conn params
        if synsPerConn > 1:  # if more than 1 synapse
            if len(secLabels) == 1:  # if single section, create all syns there
                synMechSecs = [secLabels[0]] * synsPerConn  # same section for all 
                if isinstance(params['loc'], list):
                    if len(params['loc']) == synsPerConn: 
                        synMechLocs = params['loc']
                    else:
                        print("Error: The length of the list of locations does not match synsPerConn (distributing uniformly)")
                        synMechSecs, synMechLocs = self._distributeSynsUniformly(secList=secLabels, numSyns=synsPerConn)
github Neurosim-lab / netpyne / netpyne / network / stim.py View on Github external
# subset of cells from selected pops (by relative indices)                     
            if 'cellList' in target['conds']:
                orderedPostGids = sorted(postCellsTags.keys())
                gidList = [orderedPostGids[i] for i in target['conds']['cellList']]
                postCellsTags = {gid: tags for (gid,tags) in postCellsTags.items() if gid in gidList}

            # initialize randomizer in case used in string-based function (see issue #89 for more details)
            self.rand.Random123(sim.id32('stim_'+source['type']), sim.id32('%d%d'%(len(postCellsTags), sum(postCellsTags))), sim.cfg.seeds['stim'])

            # calculate params if string-based funcs
            strParams = self._stimStrToFunc(postCellsTags, source, target)

            # loop over postCells and add stim target
            for postCellGid in postCellsTags:  # for each postsyn cell
                if postCellGid in self.gid2lid:  # check if postsyn is in this node's list of gids
                    postCell = self.cells[sim.net.gid2lid[postCellGid]]  # get Cell object 

                    # stim target params
                    params = {}
                    params['label'] = targetLabel
                    params['source'] = target['source']
                    params['sec'] = strParams['secList'][postCellGid] if 'secList' in strParams else target['sec']
                    params['loc'] = strParams['locList'][postCellGid] if 'locList' in strParams else target['loc']
                     
                    if source['type'] == 'NetStim': # for NetStims add weight+delay or default values
                        params['weight'] = strParams['weightList'][postCellGid] if 'weightList' in strParams else target.get('weight', 1.0)
                        params['delay'] = strParams['delayList'][postCellGid] if 'delayList' in strParams else target.get('delay', 1.0)
                        params['synsPerConn'] = strParams['synsPerConnList'][postCellGid] if 'synsPerConnList' in strParams else target.get('synsPerConn', 1)
                        params['synMech'] = target.get('synMech', None)
                        for p in ['Weight', 'Delay', 'loc']:
                            if 'synMech'+p+'Factor' in target:
                                params['synMech'+p+'Factor'] = target.get('synMech'+p+'Factor')
github Neurosim-lab / netpyne / netpyne / network / pop.py View on Github external
if coord+'normRange' in self.tags:  # if normalized range, rescale random locations
                minv = self.tags[coord+'normRange'][0] 
                maxv = self.tags[coord+'normRange'][1] 
                randLocs[:,icoord] = randLocs[:,icoord] * (maxv-minv) + minv

        for i in self._distributeCells(int(sim.net.params.scale * self.tags['numCells']))[sim.rank]:
            gid = sim.net.lastGid+i
            self.cellGids.append(gid)  # add gid list of cells belonging to this population - not needed?
            cellTags = {k: v for (k, v) in self.tags.items() if k in sim.net.params.popTagsCopiedToCells}  # copy all pop tags to cell tags, except those that are pop-specific
            cellTags['pop'] = self.tags['pop']
            cellTags['xnorm'] = randLocs[i,0] # set x location (um)
            cellTags['ynorm'] = randLocs[i,1] # set y location (um)
            cellTags['znorm'] = randLocs[i,2] # set z location (um)
            cellTags['x'] = sim.net.params.sizeX * randLocs[i,0] # set x location (um)
            cellTags['y'] = sim.net.params.sizeY * randLocs[i,1] # set y location (um)
            cellTags['z'] = sim.net.params.sizeZ * randLocs[i,2] # set z location (um)            
            if 'spkTimes' in self.tags:  # if VecStim, copy spike times to params
                if isinstance(self.tags['spkTimes'][0], list):
                    try:
                        cellTags['params']['spkTimes'] = self.tags['spkTimes'][i] # 2D list
                    except:
                        pass
                else:
                    cellTags['params']['spkTimes'] = self.tags['spkTimes'] # 1D list (same for all)
            cells.append(self.cellModelClass(gid, cellTags)) # instantiate Cell object

            if sim.cfg.verbose: print(('Cell %d/%d (gid=%d) of pop %s, on node %d, '%(i, sim.net.params.scale * self.tags['numCells']-1, gid, self.tags['pop'], sim.rank)))
        sim.net.lastGid = sim.net.lastGid + self.tags['numCells'] 
        return cells