How to use netpyne - 10 common examples

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 / conversion / sonataImport.py View on Github external
self.parse_group(h5file.root.edges)
                h5file.close()
                self.edges_info[self.current_edge] = load_csv_props(edge_types_file)
                self.current_edge = None

        for conn in self.conn_info:
            
            pre_node = self.conn_info[conn]['pre_node']
            post_node = self.conn_info[conn]['post_node']
            
            print('   Adding projection %s: %s -> %s '%(conn, pre_node, post_node))

            # add all synMechs in this projection to netParams.synMechParams
            for type in self.edges_info[conn]:
                syn_label = self.edges_info[conn][type]['dynamics_params'].split('.')[0]
                if syn_label not in sim.net.params.synMechParams:
                    dynamics_params_file = self.subs(self.network_config['components']['synaptic_models_dir']) +'/'+self.edges_info[conn][type]['dynamics_params']        
                    syn_dyn_params = load_json(dynamics_params_file)
                    synMechParams = dict(syn_dyn_params)
                    for k in synMechParams:  # replace keys
                        if k in synMechSubs:
                            synMechParams[synMechSubs[k]] = synMechParams.pop(k) 
                    synMechParams['mod'] = self.edges_info[conn][type]['model_template']
                    sim.net.params.synMechParams[syn_label] = synMechParams
                    print('   Added synMech %s '%(syn_label))

            # add individual connections in this projection
            for i in range(len(self.conn_info[conn]['pre_id'])):
                pre_id = self.conn_info[conn]['pre_id'][i]
                post_id = self.conn_info[conn]['post_id'][i]
                pre_gid = self.cell_info[pre_node]['gid_from_id'][pre_id] 
                post_gid = self.cell_info[post_node]['gid_from_id'][post_id]
github Neurosim-lab / netpyne / netpyne / cell / compartCell.py View on Github external
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)
github Neurosim-lab / netpyne / netpyne / network / subconn.py View on Github external
# updade sec and loc
                        conn['sec'] = newSec
                        conn['loc'] = newLoc

                        # find grouped conns 
                        if subConnParam.get('groupSynMechs', None) and conn['synMech'] in subConnParam['groupSynMechs']:
                            connGroup = connsGroup[i]  # get grouped conn from previously stored dict 
                            connGroup['synMech'] = connGroup['synMech'].split('__grouped__')[1]  # remove '__grouped__' label

                            connGroup['sec'] = newSec
                            connGroup['loc'] = newLoc
                            if newWeightNorm: connGroup['weight'] = connGroup['weight'] / oldWeightNorm * newWeightNorm

                                
        sim.pc.barrier()
github Neurosim-lab / netpyne / netpyne / conversion / sonataImport.py View on Github external
for i in range(len(self.conn_info[conn]['pre_id'])):
                pre_id = self.conn_info[conn]['pre_id'][i]
                post_id = self.conn_info[conn]['post_id'][i]
                pre_gid = self.cell_info[pre_node]['gid_from_id'][pre_id] 
                post_gid = self.cell_info[post_node]['gid_from_id'][post_id]


                if post_gid in sim.net.gid2lid:

                    type = self.conn_info[conn]['edge_type_id'][i]

                    print('   Conn: type %s pop %s (id %s) -> pop %s (id %s) MAPPED TO: cell gid %s -> cell gid %s'%(type,pre_node,pre_id,post_node,post_id, pre_gid,post_gid))
                    #print(self.edges_info[conn][type])
                    
                    connParams = {}
                    postCell = sim.net.cells[sim.net.gid2lid[post_gid]]

                    # preGid
                    connParams['preGid'] = pre_gid

                    # synMech
                    connParams['synMech'] = self.edges_info[conn][type]['dynamics_params'].split('.')[0]                
                    
                    # weight
                    sign = syn_dyn_params['sign'] if 'sign' in syn_dyn_params else 1
                    try:
                        weight = self.conn_info[conn]['syn_weight'][i] 
                    except:
                        weight = self.edges_info[conn][type]['syn_weight'] if 'syn_weight' in self.edges_info[conn][type] else 1.0
                    connParams['weight'] = sign*weight
                    
                    # delay
github Neurosim-lab / netpyne / netpyne / sim / load.py View on Github external
def loadAll (filename, data=None, instantiate=True, createNEURONObj=True):
    from .. import sim 

    if not data: data = _loadFile(filename)
    loadSimCfg(filename, data=data)
    sim.cfg.createNEURONObj = createNEURONObj  # set based on argument
    loadNetParams(filename, data=data)
    if hasattr(sim.cfg, 'compactConnFormat'): 
        connFormat = sim.cfg.compactConnFormat
    else:
        print('Error: no connFormat provided in simConfig')
        sys.exit()
    loadNet(filename, data=data, instantiate=instantiate, compactConnFormat=connFormat)
    loadSimData(filename, data=data)
github Neurosim-lab / netpyne / netpyne / cell / compartCell.py View on Github external
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)
github MetaCell / NetPyNE-UI / netpyne_ui / netpyne_geppetto.py View on Github external
def instantiateNetPyNEModel(self):
        with redirect_stdout(sys.__stdout__):
            saveData = sim.allSimData if hasattr(sim, 'allSimData') and 'spkt' in sim.allSimData.keys() and len(sim.allSimData['spkt'])>0 else False
            sim.create(self.netParams, self.simConfig)
            sim.net.defineCellShapes()  # creates 3d pt for cells with stylized geometries
            sim.gatherData(gatherLFP=False)
            if saveData: sim.allSimData = saveData  # preserve data from previous simulation
        
        return sim
github Neurosim-lab / netpyne / examples / M1 / M1_export.py View on Github external
import M1  # import parameters file
from netpyne import sim  # import netpyne sim module

np = M1.netParams
print("********************\n*\n*  Note: setting noise to 1, since noise can only be 0 or 1 in NeuroML export currently!\n*\n********************")
np.stimSourceParams['background_E']['noise'] = 1
np.stimSourceParams['background_I']['noise'] = 1

sim.createExportNeuroML2(netParams = np, 
                       simConfig = M1.simConfig,
                       reference = 'M1',
                       connections=True,
                       stimulations=True)  # create and export network to NeuroML 2
github Neurosim-lab / netpyne / examples / HHTut / HHTut_export.py View on Github external
import HHTut  # import parameters file
from netpyne import sim  # import netpyne sim module

np = HHTut.netParams
print("********************\n*\n*  Note: setting noise to 1, since noise can only be 0 or 1 in NeuroML export currently!\n*\n********************")
np.stimSourceParams['bkg']['noise'] = 1

sim.createExportNeuroML2(netParams = np, 
                       simConfig = HHTut.simConfig,
                       reference = 'HHTut')  # create and export network to NeuroML 2
github Neurosim-lab / netpyne / examples / RL_arm / main.py View on Github external
sim.maxPrate = 100

# Motor encoding
sim.nMuscles = 4 # number of muscles
motorGids = [gid for gid,tags in allCellTags.iteritems() if tags['pop'] == 'EM']
cellsPerMuscle = len(motorGids) / sim.nMuscles
sim.motorCmdCellRange = [motorGids[i:i+cellsPerMuscle] for i in xrange(0, len(motorGids), cellsPerMuscle)]  # cell gids of motor output to each muscle
sim.cmdmaxrate = 120  # value to normalize motor command num spikes
sim.cmdtimewin = 50  # window to sum spikes of motor commands
sim.antagInh = 1  # inhibition from antagonic muscle

# RL
sim.useRL = 1
sim.timeoflastRL = -1
sim.RLinterval = 50
sim.minRLerror = 0.002 # minimum error change for RL (m)
sim.targetid = 1 # initial target 
sim.allWeights = [] # list to store weights
sim.weightsfilename = 'weights.txt'  # file to store weights
sim.plotWeights = 1  # plot weights

# Exploratory movements
sim.explorMovs = 1 # exploratory movements (noise to EM pop)
sim.explorMovsRate = 100 # stim max firing rate for motor neurons of specific muscle groups to enforce explor movs
sim.explorMovsDur = 500 # max duration of each excitation to each muscle during exploratory movments init = 1000
sim.timeoflastexplor = -inf # time when last exploratory movement was updated
sim.randseed = 5  # random seed

# reset arm every trial
sim.trialReset = True # whether to reset the arm after every trial time
sim.timeoflastreset = 0 # time when arm was last reseted