コード例 #1
0
	def _connect(self,targetsId,cellType,netconList):
		""" Connect this object to target cells.

		Keyword arguments:
		targetsId -- List with the id of the target cells.
		cellType -- String defining the cell type.
		netconList -- List in which we append the created netCon Neuron objects.
		"""

		delay=1 # delay of the connection
		if cellType in self._nn.get_afferents_names(): weight = AfferentFiber.get_ees_weight()
		elif cellType in self._nn.get_real_motoneurons_names(): weight = Motoneuron.get_ees_weight()
		elif cellType in self._nn.get_intf_motoneurons_names(): weight = IntFireMn.get_ees_weight()
		else: raise Exception("undefined celltype for EES...intfireMn still to be implemented")

		for targetId in targetsId:
			# check whether this id is associated with a cell in this host.
			if not self._pc.gid_exists(targetId): continue

			if cellType in self._nn.get_real_motoneurons_names():
				cell = self._pc.gid2cell(targetId)
				target = cell.create_synapse('ees')
			else: target = self._pc.gid2cell(targetId)

			# create the connections
			nc = self._pc.gid_connect(self._eesId,target)
			nc.weight[0] = weight
			nc.delay = delay
			nc.active(False)
			netconList.append(nc)
コード例 #2
0
	def __init__(self,parallelContext,neuralNetwork,amplitude,frequency,pulsesNumber=100000,species="rat",stim_start=5):
		""" Object initialization.

		Keyword arguments:
		parallelContext -- Neuron parallelContext object.
		neuralNetwork -- NeuralNetwork instance to connect to this object.
		amplitude -- Aplitude of stimulation. It could either be an integer
		value between _minCur and _maxCur or a list containing the percentages
		of recruited primary afferents, secondary afferents and motoneurons.
		frequency -- Stimulation frequency in Hz; it has to be lower than the
		maximum stimulation frequency imposed by the AfferentFiber model.
		pulsesNumber -- number of pulses to send (default 100000).
		species -- rat or human (it loads different recruitment curves)
		"""
		self._pc = parallelContext
		self._nn = neuralNetwork
		self._species = species
		# Lets assign an Id to the stim object (high value to be sure is not already take from some cell)
		self._eesId = 1000000
		# Initialize a dictionary to contain all the connections between this object and the stimulated cells
		self._connections = {}

		self._maxFrequency = AfferentFiber.get_max_ees_frequency()
		self._current = None
		self._percIf= None
		self._percIIf= None
		self._percMn = None

		# Create the netStim Object in the first process
		if rank==0:
			# Tell this host it has this cellId
			self._pc.set_gid2node(self._eesId, rank)

			# Create the stim objetc
			self._stim = h.NetStim()
			self._stim.number = pulsesNumber
			self._stim.start = stim_start #lets give few ms for init purposes
			self._stim.noise = 0

			self._pulses = h.Vector()
			# Associate the cell with this host and id
			# the nc is also necessary to use this cell as a source for all other hosts
			nc = h.NetCon(self._stim,None)
			self._pc.cell(self._eesId, nc)
			# Record the stimulation pulses
			nc.record(self._pulses)

			# Load the recruitment data
			self._load_rec_data()

		# lets define which type of cells are recruited by the stimulation
		self._recruitedCells = sum([self._nn.get_afferents_names(),self._nn.get_motoneurons_names()],[])

		# Connect the stimulation to all muscles of the neural network
		self._connect_to_network()
		# Set stimulation parameters
		self.set_amplitude(amplitude)
		self.set_frequency(frequency)
コード例 #3
0
 def _connect_ees_to_fibers(self):
     """ Connect fibers ojects to ees objects to make the stimulation activate these fibers. """
     for i in range(len(self._eesFrequencies)):
         for j in range(len(self._fiberDelays)):
             for k in range(len(self._fiberFiringRates)):
                 self._netconList[i][j].append(
                     h.NetCon(self._eesList[i],
                              self._fiberList[i][j][k].cell))
                 self._netconList[i][j][k].delay = 1
                 self._netconList[i][j][k].weight[
                     0] = AfferentFiber.get_ees_weight()
コード例 #4
0
 def _create_fibers(self):
     """ Create the fibers with the defined different delays. """
     for i in range(len(self._eesFrequencies)):
         for j in range(len(self._fiberDelays)):
             for k in range(len(self._fiberFiringRates)):
                 self._fiberList[i][j].append(
                     AfferentFiber(self._fiberDelays[j]))
                 if self._segmentToRecord is None:
                     self._fiberList[i][j][k].set_firing_rate(
                         self._fiberFiringRates[k])
                 if self._segmentToRecord is not None:
                     self._fiberList[i][j][k].set_firing_rate(
                         self._fiberFiringRates[k], False)
                     self._fiberList[i][j][k].set_recording(
                         True, self._segmentToRecord)
コード例 #5
0
    def __init__(self,
                 parallelContext,
                 eesFrequencies,
                 fiberDelays,
                 fiberFiringRates,
                 segmentToRecord=None,
                 tstop=5000):
        """ Object initialization.

		Keyword arguments:
		parallelContext -- Neuron parallelContext object.
		eesFrequencies -- List of stimulation frequencies to test.
		fiberDelays -- List of fiber delays to test.
		fiberFiringRates -- List of fiber firing rates to test.
		segmentToRecord -- Segment to record in case of a real afferent fiber model (default = None).
		tstop -- Time in ms at wich the simulation will stop (default = 500).
		"""

        Simulation.__init__(self, parallelContext)

        if rank == 1:
            print "\nMPI execution: the different processes have different stimulation starting time."
            print "The final result is the mean results between each process\n"

        # Variables initializations
        self._eesFrequencies = eesFrequencies
        self._fiberDelays = fiberDelays
        self._fiberFiringRates = fiberFiringRates
        self._segmentToRecord = segmentToRecord

        self._init_lists()
        self._results = np.zeros([
            len(self._eesFrequencies),
            len(self._fiberDelays),
            len(self._fiberFiringRates)
        ])

        self._create_fibers()
        self._create_ees_objects()
        self._connect_ees_to_fibers()

        self._set_tstop(tstop)
        self._set_integration_step(AfferentFiber.get_update_period())
コード例 #6
0
    def __init__(self,
                 parallelContext,
                 neuralNetwork,
                 afferentInput=None,
                 eesObject=None,
                 eesModulation=None,
                 tStop=100):
        """ Object initialization.

		Keyword arguments:
		parallelContext -- Neuron parallelContext object.
		neuralNetwork -- NeuralNetwork object.
		afferentInput -- Dictionary of lists for each type of fiber containing the
			fibers firing rate over time and the dt at wich the firing rate is updated.
			If no afferent input is desired, use None (default = None).
		eesObject -- EES object connected to the NeuralNetwork,
			mandatory for eesModulation (Default = None).
		eesModulation -- possible dictionary with the following strucuture: {'modulation':
			dictionary containing a	signal of 0 and 1s used to activate/inactivate
			the stimulation for every muscle that we want to modulate (the dictionary
			keys have to be the muscle names used in the neural network structure), 'dt':
			modulation dt}. If no modulation of the EES is intended use None (default = None).
		tStop -- Time in ms at wich the simulation will stop (default = 100). In case
			the time is set to -1 the neuralNetwork will be integrated for all the duration
			of the afferentInput.
		"""

        Simulation.__init__(self, parallelContext)

        if rank == 1:
            print "\nMPI execution: the cells are divided in the different hosts\n"

        self._nn = neuralNetwork
        self._Iaf = self._nn.get_primary_afferents_names(
        )[0] if self._nn.get_primary_afferents_names() else []
        self._IIf = self._nn.get_secondary_afferents_names(
        )[0] if self._nn.get_secondary_afferents_names() else []
        self._Mn = self._nn.get_motoneurons_names(
        ) if self._nn.get_motoneurons_names() else []

        self._set_integration_step(AfferentFiber.get_update_period())

        # Initialization of the afferent modulation
        if afferentInput == None:
            self._afferentModulation = False
            self._afferentInput = None
            if tStop > 0: self._set_tstop(tStop)
            else:
                raise (Exception(
                    "If no afferents input are provided tStop has to be greater than 0."
                ))
        else:
            self._afferentModulation = True
            self._afferentInput = afferentInput[0]
            self._dtUpdateAfferent = afferentInput[1]
            self._init_afferents_fr()
            key = []
            key.append(self._afferentInput.keys()[0])
            key.append(self._afferentInput[key[0]].keys()[0])
            self._inputDuration = len(
                self._afferentInput[key[0]][key[1]]) * self._dtUpdateAfferent
            if tStop == -1 or tStop >= self._inputDuration:
                self._set_tstop(self._inputDuration - self._dtUpdateAfferent)
            else:
                self._set_tstop(tStop)

        self._ees = eesObject
        # Initialization of the binary stim modulation
        if eesModulation == None or eesObject == None:
            self._eesBinaryModulation = False
            self._eesProportionalModulation = False
            self._eesParam = {
                'state': None,
                'amp': None,
                'modulation': None,
                'dt': None
            }
        elif eesModulation['type'] == "binary":
            self._eesBinaryModulation = True
            self._eesProportionalModulation = False
            current, percIf, percIIf, percMn = self._ees.get_amplitude()
            self._eesParam = {
                'state': {},
                'modulation': eesModulation['modulation'],
                'dt': eesModulation['dt']
            }
            self._eesParam['amp'] = [percIf, percIIf, percMn]
            for muscle in eesModulation['modulation']:
                self._eesParam['state'][muscle] = 1
        elif eesModulation['type'] == "proportional":
            self._eesBinaryModulation = False
            self._eesProportionalModulation = True
            self._eesParam = {
                'modulation': eesModulation['modulation'],
                'dt': eesModulation['dt']
            }
            current, percIf, percIIf, percMn = self._ees.get_amplitude()
            self._eesParam['maxAmp'] = np.array([percIf, percIIf, percMn])

        #Initialization of the result dictionaries
        self._meanFr = None
        self._estimatedEMG = None
        self._nSpikes = None
        self._nActiveCells = None
コード例 #7
0
 def _create_cell_population(self,
                             cellId,
                             muscle,
                             muscAfferentDelay,
                             cellClass,
                             cellName,
                             cellNumber,
                             neuronParam=None):
     """ Create cells populations. """
     for n in range(int(cellNumber)):
         # Lets divide equally the cells between the different hosts
         if n % sizeComm == rank:
             # Assign a cellId to the new cell
             self.cellsId[muscle][cellName].append(cellId)
             # Tell this host it has this cellId
             self._pc.set_gid2node(cellId, rank)
             # Create the cell
             if cellClass == "IntFireMn":
                 #List containing all integrate and fire motoneurons names
                 if not cellName in self._intMotoneuronsNames:
                     self._intMotoneuronsNames.append(cellName)
                 self.cells[muscle][cellName].append(IntFireMn())
             elif cellClass == "Motoneuron":
                 #List containing all realistic motoneurons names
                 if not cellName in self._realMotoneuronsNames:
                     self._realMotoneuronsNames.append(cellName)
                 # durg - parameter specific to the Mn
                 drug = False
                 if neuronParam == "drug": drug = True
                 self.cells[muscle][cellName].append(Motoneuron(drug))
             elif cellClass == "AfferentFiber":
                 #Lists containing all primary or secondary afferent fibers names
                 if "II" in cellName:
                     if not cellName in self._secondaryAfferentsNames:
                         self._secondaryAfferentsNames.append(cellName)
                 else:
                     if not cellName in self._primaryAfferentsNames:
                         self._primaryAfferentsNames.append(cellName)
                 # delay - parameter specific for the Afferent fibers
                 if neuronParam is not None: delay = int(neuronParam)
                 elif muscAfferentDelay is not None:
                     delay = int(muscAfferentDelay)
                 else:
                     raise Exception(
                         "Please specify the afferent fiber delay")
                 self.cells[muscle][cellName].append(AfferentFiber(delay))
             elif cellClass == "IntFire":
                 #List containing all interneurons names
                 if not cellName in self._interNeuronsNames:
                     self._interNeuronsNames.append(cellName)
                 self.cells[muscle][cellName].append(IntFire())
             else:
                 raise Exception(
                     "Unkown cell in the netowrk instructions.... (" +
                     str(cellClass) + ")")
             # Associate the cell with this host and id, the nc is also necessary to use this cell as a source for all other hosts
             nc = self.cells[muscle][cellName][-1].connect_to_target(None)
             self._pc.cell(cellId, nc)
             # Record cells APs
             if (cellClass == "Motoneuron" or cellClass
                     == "IntFireMn") and self.recordMotoneurons:
                 self.actionPotentials[muscle][cellName].append(h.Vector())
                 nc.record(self.actionPotentials[muscle][cellName][-1])
             elif cellClass == "AfferentFiber" and self.recordAfferents:
                 self.actionPotentials[muscle][cellName].append(h.Vector())
                 nc.record(self.actionPotentials[muscle][cellName][-1])
             elif cellClass == "IntFire" and self.recordIntFire:
                 self.actionPotentials[muscle][cellName].append(h.Vector())
                 nc.record(self.actionPotentials[muscle][cellName][-1])
         cellId += 1
     return cellId