Ejemplo n.º 1
0
	def make_fF_Curve(self,
                          projFile,
                          simulator,
                          simConfig,
                          nTrains,
                          simDuration,
                          analyseStartTime, analyseStopTime,
                          analyseThreshold,
                          maxNumSimultaneousSims = 4):

			# Load neuroConstruct project

			print "Loading project from file: " + projFile.getAbsolutePath()+", exists: "+ str(projFile.exists())

			pm = ProjectManager()
			self.myProject = pm.loadProject(projFile)
			self.simulator = simulator

			simConfig = self.myProject.simConfigInfo.getSimConfig(simConfig)

			simConfig.setSimDuration(simDuration)

			pm.doGenerate(simConfig.getName(), self.neuroConstructSeed)

			while pm.isGenerating():
					print "Waiting for the project to be generated with Simulation Configuration: "+str(simConfig)
					time.sleep(2)

			numGenerated = self.myProject.generatedCellPositions.getNumberInAllCellGroups()

			print "Number of cells generated: " + str(numGenerated)

			simReferences = {}


			if numGenerated > 0:

					print "Generating scripts for simulator: %s..."%simulator

					if simulator == 'NEURON':
						self.myProject.neuronFileManager.setQuitAfterRun(1) # Remove this line to leave the NEURON sim windows open after finishing
						self.myProject.neuronSettings.setCopySimFiles(1) # 1 copies hoc/mod files to PySim_0 etc. and will allow multiple sims to run at once
						self.myProject.neuronSettings.setGraphicsMode(0) # 0 hides graphs during execution
                        
					if simulator == 'GENESIS':
						self.myProject.genesisFileManager.setQuitAfterRun(1) # Remove this line to leave the NEURON sim windows open after finishing
						self.myProject.genesisSettings.setCopySimFiles(1) # 1 copies hoc/mod files to PySim_0 etc. and will allow multiple sims to run at once
						self.myProject.genesisSettings.setGraphicsMode(0) # 0 hides graphs during execution


					currentTrain = 0

					ADD_TO_START_FINITIALIZE = self.myProject.neuronSettings.getNativeBlock(NativeCodeLocation.START_FINITIALIZE)
					ADD_TO_RECORD_I = self.myProject.neuronSettings.getNativeBlock(NativeCodeLocation.AFTER_SIMULATION)

					while currentTrain <= nTrains:

							while (len(self.simsRunning)>=maxNumSimultaneousSims):
									print "Sims currently running: "+str(self.simsRunning)
									print "Waiting..."
									time.sleep(3) # wait a while...
									self.updateSimsRunning()


							simRef = "PySim_"+str(currentTrain)

							print "Going to run simulation: "+simRef

							########  Adjusting the amplitude of the Voltage clamp ###############

                                                        TEXT_BEFORE_CREATION = """objref vector, gTrainFile\n""" + "objectvar clamp\n"

                                                        ### TEXT_BEFORE_INIT = "GranuleCell_mod_tonic[0].Soma {\n" + "clampobj = new VClamp(0.5)\n" + "clampobj.dur[0] = " + str(stimDur) + "\n" + "clampobj.amp[0] = " + str(stimAmp) + "\n" +  "}\n" # This should do the trick

                                                        TEXT_START_FINITIALIZE = "\n" + "gTrainFile = new File() \n" + "vector = new Vector(100000) \n" + "access GranuleCell_mod_tonic[0].Soma \n" + "clamp = new SEClamp(0.5) \n" + "clamp.amp1 = 0 \n" + "clamp.dur1 = 1e9 \n" + """gTrainFile.ropen("E:/neuroConstruct/models/Dan_GranCell/gTrains_nS/gAMPA_""" + str(currentTrain) + """.txt") \n""" + "vector.scanf(gTrainFile) \n" + "gTrainFile.close \n" + "for i = 0, vector.size() -1 { \n" + "     if (vector.x[i] <= 0) { \n" + "          vector.x[i] = 1e-20 \n" + "              } \n" + "        } \n" + "for i = 0, vector.size() -1 { \n" + "    vector.x[i] = ( 1 / vector.x[i] ) * 1000 \n" + "    } \n" + "vector.play(&clamp.rs, 0.03) \n" # This

                                                        TEXT_START_FINITIALIZE = TEXT_START_FINITIALIZE + ADD_TO_START_FINITIALIZE

                                                        TEXT_TO_RECORD_I = """// currently not used \n"""

                                                        TEXT_TO_RECORD_I = TEXT_TO_RECORD_I + ADD_TO_RECORD_I

                                                        self.myProject.neuronSettings.setNativeBlock(NativeCodeLocation.BEFORE_CELL_CREATION, TEXT_BEFORE_CREATION)
                                                        self.myProject.neuronSettings.setNativeBlock(NativeCodeLocation.START_FINITIALIZE, TEXT_START_FINITIALIZE)
                                                        self.myProject.neuronSettings.setNativeBlock(NativeCodeLocation.AFTER_SIMULATION, TEXT_TO_RECORD_I)

					
							print "Next Train: "+ str(currentTrain)

							self.myProject.simulationParameters.setReference(simRef)

							if simulator == "NEURON":
									self.myProject.neuronFileManager.generateTheNeuronFiles(simConfig,
																							None,
																							NeuronFileManager.RUN_HOC,
																							self.simulatorSeed)

									print "Generated NEURON files for: "+simRef

									compileProcess = ProcessManager(self.myProject.neuronFileManager.getMainHocFile())

									compileSuccess = compileProcess.compileFileWithNeuron(0,0)

									print "Compiled NEURON files for: "+simRef

									if compileSuccess:
													pm.doRunNeuron(simConfig)
													print "Set running simulation: "+simRef
													self.simsRunning.append(simRef)

							if simulator == "GENESIS":
									compartmentalisation = GenesisCompartmentalisation()

									self.myProject.genesisFileManager.generateTheGenesisFiles(simConfig,
																							None,
																							compartmentalisation,
																							self.simulatorSeed)
									print "Generated GENESIS files for: "+simRef

									pm.doRunGenesis(simConfig)
									print "Set running simulation: "+simRef
									self.simsRunning.append(simRef)

							time.sleep(1) # Wait for sim to be kicked off
							simReferences[simRef] = currentTrain
							currentTrain = currentTrain + 1

					print
					print "Finished running "+str(len(simReferences))+" simulations for project "+ projFile.getAbsolutePath()
					print "These can be loaded and replayed in the previous simulation browser in the GUI"
					print

			while (len(self.simsRunning)>0):
					print "Sims currently running: "+str(self.simsRunning)
					print "Waiting..."
					time.sleep(4) # wait a while...
					self.updateSimsRunning()

			#simReferences = {'PySim_0.3':0.3,'PySim_0.4':0.4,'PySim_0.5':0.5}

			plotFrameFf = PlotManager.getPlotterFrame("F-f curve from project: "+str(self.myProject.getProjectFile())+" on "+simulator , 1, 1)

			plotFrameVolts = PlotManager.getPlotterFrame("VoltageTraces from project: "+str(self.myProject.getProjectFile())+" on "+simulator , 1, 1)

			plotFrameFf.setViewMode(PlotCanvas.INCLUDE_ORIGIN_VIEW)

			info = "F-f curve for Simulation Configuration: "+str(simConfig)

			dataSet = DataSet(info, info, "Hz", "Hz", "Input_Freq", "Output_Freq")
			dataSet.setGraphFormat(PlotCanvas.USE_CIRCLES_FOR_PLOT)

			simList = simReferences.keys()
			simList.sort()
			
		        traininfos = open("E:/neuroConstruct/models/Dan_GranCell/gAMPA_traininfo.txt")
			train_info_list = traininfos.readlines()
			currentTrain = 0

			for sim in simList:

					simDir = File(projFile.getParentFile(), "E:/neuroConstruct/models/Dan_GranCell/simulations/"+sim)
					print
					print "--- Reloading data from simulation in directory: %s"%simDir.getCanonicalPath()
					try:
							simData = SimulationData(simDir)
							simData.initialise()
							print "Data loaded: "
							print simData.getAllLoadedDataStores()
							times = simData.getAllTimes()
							cellSegmentRef = simConfig.getCellGroups().get(0)+"_0"
							volts = simData.getVoltageAtAllTimes(cellSegmentRef)

							time.sleep(2)

							traceInfo = "Voltage at: %s in simulation: %s"%(cellSegmentRef, sim)

							dataSetV = DataSet(traceInfo, traceInfo, "ms", "mV", "Time", "Membrane Potential")

                                                        
                                                        Spike_List = []

                                                        Spike_List.append(0.00)

							for i in range(len(times)):
								dataSetV.addPoint(times[i], volts[i])

							for i in range(len(times)):
								if (volts[i] > 0.0):
                                                                        if (times[i] - Spike_List[len(Spike_List)-1] > 0.50):
                                                                                Spike_List.append(times[i])

                                                                                
                                                        Spike_List.remove(0.00)
        

							plotFrameVolts.addDataSet(dataSetV)

							spikeTimes = SpikeAnalyser.getSpikeTimes(volts, times, analyseThreshold, analyseStartTime, analyseStopTime)

							currentTrain_Freq = float(train_info_list[currentTrain-1])

							
							print "Number of spikes in sim %s: %i"%(sim, len(spikeTimes))
							avgFreq = 0
							if len(Spike_List)>0:
									avgFreq = 1000.0 / ((Spike_List[len(Spike_List)-1] - Spike_List[0]) / (len(Spike_List) -1))
									dataSet.addPoint(currentTrain_Freq,avgFreq)
							currentTrain = currentTrain + 1

							
					except:
							print "Error analysing simulation data from: %s"%simDir.getCanonicalPath()
							print sys.exc_info()[0]


			plotFrameFf.addDataSet(dataSet)
Ejemplo n.º 2
0
def testAll(argv=None):
    if argv is None:
        argv = sys.argv

    print "Loading project from "+ projFile.getCanonicalPath()


    simManager = nc.SimulationManager(projFile,
                                      numConcurrentSims = numConcurrentSims,
                                      verbose = verbose)

    ### Change num in each cell group

    simManager.project.cellGroupsInfo.getCellPackingAdapter("lg1").setMaxNumberCells(numCells1)
    simManager.project.cellGroupsInfo.getCellPackingAdapter("lg2").setMaxNumberCells(numCells2)


    allSims = simManager.runMultipleSims(simConfigs =             simConfigs,
                               simDt =                   simDt,
                               simDuration =             simDuration,
                               simulators =              simulators,
                               runInBackground =         runInBackground,
                               varTimestepNeuron =       varTimestepNeuron,
                               mpiConfigs =              mpiConfigs,
                               suggestedRemoteRunTime =  suggestedRemoteRunTime,
                               simRefGlobalPrefix =      simAllPrefix,
                               runSims =                 runSims,
                               maxElecLens =             multipleRuns,
                               saveAsHdf5 =              saveAsHdf5,
                               saveOnlySpikes =          saveOnlySpikes,
                               runMode =                 runMode)

    while (len(simManager.allRunningSims)>0):
        print "Waiting for the following sims to finish: "+str(simManager.allRunningSims)
        time.sleep(5) # wait a while...
        simManager.updateSimsRunning()

    times = []
    procNums = []
    for sim in allSims:
        simDir = File(projFile.getParentFile(), "/simulations/"+sim)
        try:
            simData = SimulationData(simDir)
            simData.initialise()
            simTime = simData.getSimulationProperties().getProperty("RealSimulationTime")
            print "Simulation: %s took %s seconds"%(sim, simTime)
            times.append(float(simTime))
            paraConfig = simData.getSimulationProperties().getProperty("Parallel configuration")
            print paraConfig
            numProc = int(paraConfig[max(paraConfig.find(" host, ")+7, paraConfig.find(" hosts, ")+8):paraConfig.find(" processor")])
            procNums.append(numProc)

        except:
            print "Error analysing simulation data from: %s"%simDir.getCanonicalPath()
            print sys.exc_info()




    print times
    print procNums

    '''
    import matplotlib.pyplot as plt
    lines = plt.loglog(times, procNums, 'r:')

    plt.ylabel('Simulation time')
    plt.xlabel('Number of processors')
    plt.show()'''

    from ucl.physiol.neuroconstruct.gui.plotter import PlotManager
    from ucl.physiol.neuroconstruct.gui.plotter import PlotCanvas

    from ucl.physiol.neuroconstruct.dataset import DataSet

    plotFrame = PlotManager.getPlotterFrame("Time for simulation run on different numbers of processors", 0, 1)

    plotFrame.setViewMode(PlotCanvas.INCLUDE_ORIGIN_VIEW)

    info = "Simulation times for: "+str(procNums)

    dataSet = DataSet(info, info, "#", "s", "Number of processors", "Simulation time")
    dataSet.setGraphFormat(PlotCanvas.USE_CIRCLES_FOR_PLOT)

    for i in range(len(times)):
        #dataSet.addPoint(procNums[i],times[i]*procNums[i])
        dataSet.addPoint(procNums[i],times[i])

    plotFrame.addDataSet(dataSet)
Ejemplo n.º 3
0
analyseStopTime = 600
analyseThreshold = -20 # mV

spikeTimes_nC = SpikeAnalyser.getSpikeTimes(voltages_nC, times_nC, analyseThreshold, analyseStartTime, analyseStopTime)
print "neuroConcsturct spike times:"
print spikeTimes_nC

spikeTimes_original = SpikeAnalyser.getSpikeTimes(voltages_original, times_original, analyseThreshold, analyseStartTime, analyseStopTime)
print "modelDB spike times:"
print spikeTimes_original

plotFrame = PlotManager.getPlotterFrame("test model: "+str(myProject.getProjectFile()) , 1, 1)
plotFrame.setViewMode(PlotCanvas.INCLUDE_ORIGIN_VIEW)
info = "modelDB vs nC: "+str(simConfig)

dataSet_nC = DataSet(info, info, "ms", "nC", "time", "nC")
dataSet_nC.setGraphFormat(PlotCanvas.USE_CIRCLES_FOR_PLOT)   
for t1 in spikeTimes_nC:
   dataSet_nC.addPoint(t1,1)
 
dataSet_original = DataSet(info, info, "ms", "modelDB", "time", "modelDB")
dataSet_original.setGraphFormat(PlotCanvas.USE_CIRCLES_FOR_PLOT)   
for t2 in spikeTimes_original:
   dataSet_original.addPoint(t2,1)
   
plotFrame.addDataSet(dataSet_nC)
plotFrame.addDataSet(dataSet_original)

test = 0
if len(spikeTimes_nC) == len(spikeTimes_original):
   test = 1
Ejemplo n.º 4
0
def testAll(argv=None):
    if argv is None:
        argv = sys.argv

    print "Loading project from "+ projFile.getCanonicalPath()


    simManager = nc.SimulationManager(projFile,
                                      numConcurrentSims = numConcurrentSims,
                                      verbose = verbose)

    ### Change num in each cell group

    densityGrC = 1.90e6
    densityMF = 6.6e5
    densityGoC = 4607

    totDens = densityGrC + densityMF + densityGoC

    numMF = int(targetNum * densityMF/totDens)
    numGoC = int(targetNum * densityGoC/totDens)
    numGrC = targetNum - numMF - numGoC

    vol = targetNum/(totDens*1e-9)
    height = 150
    side = math.sqrt(vol/height)

    
    info = "Number in %fx%fx%i box (vol: %f mm^3): GrC: %i, MF: %i, GoC: %i, Total: %i"%(side, side, height, vol*1e-9,numGrC, numMF,numGoC, (numGrC +numMF +numGoC))
    print info

    SimulationsInfo.addExtraSimProperty("summary", info)

    region3D = simManager.project.regionsInfo.getRegionObject("TestGranCellVolume")
    region3D.setParameter(region3D.WIDTH_PARAM, side)
    region3D.setParameter(region3D.HEIGHT_PARAM, height)
    region3D.setParameter(region3D.DEPTH_PARAM, side)

    simManager.project.cellGroupsInfo.getCellPackingAdapter("TestScalingGrC").setMaxNumberCells(numGrC)
    simManager.project.cellGroupsInfo.getCellPackingAdapter("TestScalingGoC").setMaxNumberCells(numGoC)
    simManager.project.cellGroupsInfo.getCellPackingAdapter("TestScalingMF").setMaxNumberCells(numMF)
    ######simManager.project.cellGroupsInfo.getCellPackingAdapter("lg2").setMaxNumberCells(numCells2)


    allSims = simManager.runMultipleSims(simConfigs =             simConfigs,
                               simDt =                   simDt,
                               simDuration =             simDuration,
                               simulators =              simulators,
                               runInBackground =         runInBackground,
                               varTimestepNeuron =       varTimestepNeuron,
                               mpiConfigs =              mpiConfigs,
                               suggestedRemoteRunTime =  suggestedRemoteRunTime,
                               simRefGlobalPrefix =      simAllPrefix,
                               runSims =                 runSims,
                               maxElecLens =             multipleRuns,
                               saveAsHdf5 =              saveAsHdf5,
                               saveOnlySpikes =          saveOnlySpikes,
                               runMode =                 runMode)

    while (len(simManager.allRunningSims)>0):
        print "Waiting for the following sims to finish: "+str(simManager.allRunningSims)
        time.sleep(5) # wait a while...
        simManager.updateSimsRunning()

    times = []
    procNums = []
    for sim in allSims:
        simDir = File(projFile.getParentFile(), "/simulations/"+sim)
        try:
            simData = SimulationData(simDir)
            simData.initialise()
            simTime = simData.getSimulationProperties().getProperty("RealSimulationTime")
            print "Simulation: %s took %s seconds"%(sim, simTime)
            times.append(float(simTime))
            paraConfig = simData.getSimulationProperties().getProperty("Parallel configuration")
            print paraConfig
            numProc = int(paraConfig[max(paraConfig.find(" host, ")+7, paraConfig.find(" hosts, ")+8):paraConfig.find(" processor")])
            procNums.append(numProc)

        except:
            print "Error analysing simulation data from: %s"%simDir.getCanonicalPath()
            print sys.exc_info()




    print times
    print procNums

    '''
    import matplotlib.pyplot as plt
    lines = plt.loglog(times, procNums, 'r:')

    plt.ylabel('Simulation time')
    plt.xlabel('Number of processors')
    plt.show()'''

    from ucl.physiol.neuroconstruct.gui.plotter import PlotManager
    from ucl.physiol.neuroconstruct.gui.plotter import PlotCanvas

    from ucl.physiol.neuroconstruct.dataset import DataSet

    plotFrame = PlotManager.getPlotterFrame("Time for simulation run on different numbers of processors", 0, 1)

    plotFrame.setViewMode(PlotCanvas.INCLUDE_ORIGIN_VIEW)

    info = "Simulation times for: "+str(procNums)

    dataSet = DataSet(info, info, "#", "s", "Number of processors", "Simulation time")
    dataSet.setGraphFormat(PlotCanvas.USE_CIRCLES_FOR_PLOT)

    for i in range(len(times)):
        dataSet.addPoint(procNums[i],times[i]*procNums[i])
        #dataSet.addPoint(procNums[i],times[i])

    plotFrame.addDataSet(dataSet)
Ejemplo n.º 5
0
                        volts, times, analyseThreshold, analyseStartTime,
                        analyseStopTime)

                    #print "Spike times in %s for sim %s: %s"%(cellSegmentRef, simRef, str(spikeTimes))

                    if totNumSpikes < 0: totNumSpikes = len(spikeTimes)

                    for spikeIndex in range(max(totNumSpikes - numSpikes, 0),
                                            totNumSpikes):

                        spikeTimeTrace = "Times_" + sim + "_" + simConfigName + "_" + str(
                            spikeIndex)

                        if not allSpikeTimeDataSets.has_key(spikeTimeTrace):
                            ds = DataSet(spikeTimeTrace, spikeTimeTrace, "",
                                         "ms", "Number of compartments",
                                         "Spike time")
                            allSpikeTimeDataSets[spikeTimeTrace] = ds

                        spikeTrace = allSpikeTimeDataSets[spikeTimeTrace]
                        print "Adding point to " + spikeTimeTrace
                        #pointNum = spikeTrace.addPoint(1/maxElecLen, spikeTimes[-1])
                        ##pointNum = spikeTrace.addPoint(1/maxElecLen, spikeTimes[spikeIndex])
                        morphProp = simData.getSimulationProperties(
                        ).getProperty("Morph summary nRT")
                        comps = morphProp.split(":")[-1]

                        pointNum = spikeTrace.addPoint(float(comps),
                                                       spikeTimes[spikeIndex])

                        #spikeTrace.setCommentOnPoint(pointNum, "Point for electrotonic len: "+str(maxElecLen))
Ejemplo n.º 6
0
	def generateF_ICurve(self,
                         projFile,
                         simulator,
                         simConfig,
                         preStimAmp, preStimDel, preStimDur,
                         stimAmpLow, stimAmpInc, stimAmpHigh,
                         stimDel, stimDur,
                         simDuration,
                         analyseStartTime, analyseStopTime,
                         analyseThreshold,
                         maxNumSimultaneousSims = 4):

			# Load neuroConstruct project

			print "Loading project from file: " + projFile.getAbsolutePath()+", exists: "+ str(projFile.exists())

			pm = ProjectManager()
			self.myProject = pm.loadProject(projFile)
			self.simulator = simulator

			simConfig = self.myProject.simConfigInfo.getSimConfig(simConfig)

			simConfig.setSimDuration(simDuration)

			pm.doGenerate(simConfig.getName(), self.neuroConstructSeed)

			while pm.isGenerating():
					print "Waiting for the project to be generated with Simulation Configuration: "+str(simConfig)
					time.sleep(2)

			numGenerated = self.myProject.generatedCellPositions.getNumberInAllCellGroups()

			print "Number of cells generated: " + str(numGenerated)

			simReferences = {}


			if numGenerated > 0:

					print "Generating scripts for simulator: %s..."%simulator

					if simulator == 'NEURON':
						self.myProject.neuronFileManager.setQuitAfterRun(1) # Remove this line to leave the NEURON sim windows open after finishing
						self.myProject.neuronSettings.setCopySimFiles(1) # 1 copies hoc/mod files to PySim_0 etc. and will allow multiple sims to run at once
						self.myProject.neuronSettings.setGraphicsMode(0) # 0 hides graphs during execution
                        
					if simulator == 'GENESIS':
						self.myProject.genesisFileManager.setQuitAfterRun(1) # Remove this line to leave the NEURON sim windows open after finishing
						self.myProject.genesisSettings.setCopySimFiles(1) # 1 copies hoc/mod files to PySim_0 etc. and will allow multiple sims to run at once
						self.myProject.genesisSettings.setGraphicsMode(0) # 0 hides graphs during execution


					stimAmp = stimAmpLow

					while stimAmp <= stimAmpHigh:

							while (len(self.simsRunning)>=maxNumSimultaneousSims):
									print "Sims currently running: "+str(self.simsRunning)
									print "Waiting..."
									time.sleep(3) # wait a while...
									self.updateSimsRunning()


							simRef = "PySim_"+str(float(stimAmp))

							print "Going to run simulation: "+simRef

							########  Adjusting the amplitude of the current clamp ###############

                                                        # preStim = self.myProject.elecInputInfo.getStim(simConfig.getInputs().get(0))
							preStim = self.myProject.elecInputInfo.getStim("Input_3")

							preStim.setAmp(NumberGenerator(preStimAmp))
							preStim.setDel(NumberGenerator(preStimDel))
							preStim.setDur(NumberGenerator(preStimDur))
							self.myProject.elecInputInfo.updateStim(preStim)


							# stim = self.myProject.elecInputInfo.getStim(simConfig.getInputs().get(1))
							stim = self.myProject.elecInputInfo.getStim("Input_4")
							

							stim.setAmp(NumberGenerator(stimAmp))
							stim.setDel(NumberGenerator(stimDel))
							stim.setDur(NumberGenerator(stimDur))
							self.myProject.elecInputInfo.updateStim(stim)

							print "Next stim: "+ str(stim)

							self.myProject.simulationParameters.setReference(simRef)

							if simulator == "NEURON":
									self.myProject.neuronFileManager.generateTheNeuronFiles(simConfig,
																							None,
																							NeuronFileManager.RUN_HOC,
																							self.simulatorSeed)

									print "Generated NEURON files for: "+simRef

									compileProcess = ProcessManager(self.myProject.neuronFileManager.getMainHocFile())

									compileSuccess = compileProcess.compileFileWithNeuron(0,0)

									print "Compiled NEURON files for: "+simRef

									if compileSuccess:
													pm.doRunNeuron(simConfig)
													print "Set running simulation: "+simRef
													self.simsRunning.append(simRef)

							if simulator == "GENESIS":
									compartmentalisation = GenesisCompartmentalisation()

									self.myProject.genesisFileManager.generateTheGenesisFiles(simConfig,
																							None,
																							compartmentalisation,
																							self.simulatorSeed)
									print "Generated GENESIS files for: "+simRef

									pm.doRunGenesis(simConfig)
									print "Set running simulation: "+simRef
									self.simsRunning.append(simRef)

							time.sleep(1) # Wait for sim to be kicked off
							simReferences[simRef] = stimAmp
							stimAmp = stimAmp +stimAmpInc

					print
					print "Finished running "+str(len(simReferences))+" simulations for project "+ projFile.getAbsolutePath()
					print "These can be loaded and replayed in the previous simulation browser in the GUI"
					print

			while (len(self.simsRunning)>0):
					print "Sims currently running: "+str(self.simsRunning)
					print "Waiting..."
					time.sleep(4) # wait a while...
					self.updateSimsRunning()

			#simReferences = {'PySim_0.3':0.3,'PySim_0.4':0.4,'PySim_0.5':0.5}

			plotFrameFI = PlotManager.getPlotterFrame("F-I curve from project: "+str(self.myProject.getProjectFile())+" on "+simulator , 1, 1)
			plotFrameVolts = PlotManager.getPlotterFrame("VoltageTraces from project: "+str(self.myProject.getProjectFile())+" on "+simulator , 1, 1)

			plotFrameFI.setViewMode(PlotCanvas.INCLUDE_ORIGIN_VIEW)

			info = "F-I curve for Simulation Configuration: "+str(simConfig)

			dataSet = DataSet(info, info, "nA", "Hz", "Current injected", "Firing frequency")
			dataSet.setGraphFormat(PlotCanvas.USE_CIRCLES_FOR_PLOT)

			simList = simReferences.keys()
			simList.sort()

			for sim in simList:

					simDir = File(projFile.getParentFile(), "/neuroConstruct/models/Dan_GranCell/simulations/"+sim)
					print
					print "--- Reloading data from simulation in directory: %s"%simDir.getCanonicalPath()
					try:
							simData = SimulationData(simDir)
							simData.initialise()
							print "Data loaded: "
							print simData.getAllLoadedDataStores()
							times = simData.getAllTimes()
							cellSegmentRef = simConfig.getCellGroups().get(0)+"_0"
							volts = simData.getVoltageAtAllTimes(cellSegmentRef)

							traceInfo = "Voltage at: %s in simulation: %s"%(cellSegmentRef, sim)

							dataSetV = DataSet(traceInfo, traceInfo, "mV", "ms", "Membrane potential", "Time")
							for i in range(len(times)):
									dataSetV.addPoint(times[i], volts[i])

							plotFrameVolts.addDataSet(dataSetV)

							spikeTimes = SpikeAnalyser.getSpikeTimes(volts, times, analyseThreshold, analyseStartTime, analyseStopTime)
							stimAmp = simReferences[sim]
							print "Number of spikes at %f nA in sim %s: %i"%(stimAmp, sim, len(spikeTimes))
							avgFreq = 0
							if len(spikeTimes)>1:
									avgFreq = len(spikeTimes)/ ((analyseStopTime - analyseStartTime)/1000.0)
									dataSet.addPoint(stimAmp,avgFreq)
					except:
							print "Error analysing simulation data from: %s"%simDir.getCanonicalPath()
							print sys.exc_info()[0]


			plotFrameFI.addDataSet(dataSet)
                analyseStartTime = 0
                analyseStopTime = 2000
                analyseThreshold = -20 # mV

                spikeTimes = SpikeAnalyser.getSpikeTimes(volts, times, analyseThreshold, analyseStartTime, analyseStopTime)

                #print "Spike times in %s for sim %s: %s"%(cellSegmentRef, simRef, str(spikeTimes))
                
                if totNumSpikes <0: totNumSpikes = len(spikeTimes)
                
                for spikeIndex in range(max(totNumSpikes-numSpikes, 0), totNumSpikes):
                        
                    spikeTimeTrace = "Times_"+sim+"_"+simConfigName+"_"+str(spikeIndex)
        
                    if not allSpikeTimeDataSets.has_key(spikeTimeTrace):
                        ds = DataSet(spikeTimeTrace, spikeTimeTrace, "", "ms", "Number of compartments", "Spike time")
                        allSpikeTimeDataSets[spikeTimeTrace] = ds
                    
                    
                    spikeTrace = allSpikeTimeDataSets[spikeTimeTrace]
                    print "Adding point to "+spikeTimeTrace
                    #pointNum = spikeTrace.addPoint(1/maxElecLen, spikeTimes[-1])
                    ##pointNum = spikeTrace.addPoint(1/maxElecLen, spikeTimes[spikeIndex])
                    morphProp = simData.getSimulationProperties().getProperty("Morph summary nRT")
                    comps = morphProp.split(":")[-1]

                    pointNum = spikeTrace.addPoint(float(comps), spikeTimes[spikeIndex])

                    #spikeTrace.setCommentOnPoint(pointNum, "Point for electrotonic len: "+str(maxElecLen))
                    spikeTrace.setCommentOnPoint(pointNum, morphProp)
    
Ejemplo n.º 8
0
    try:
        simData = SimulationData(simDir)
        simData.initialise()
        print("Data loaded: ")
        print(simData.getAllLoadedDataStores())

        times = simData.getAllTimes()
        # simConfig was just grabbed for use here, it was CGspinstell_0
        cellSegmentRef = simConfig.getCellGroups().get(0)+"_0"

        volts = simData.getVoltageAtAllTimes(cellSegmentRef)

        traceInfo = "Voltage at: %s in simulation: %s"%(cellSegmentRef, sim)

        dataSetV = DataSet(traceInfo, traceInfo, "ms", "mV", "Time", "Membrane potential")
        for i in range(len(times)):
            dataSetV.addPoint(times[i], volts[i])

        if plotAllTraces:
            plotFrameAlltraces.addDataSet(dataSetV)
            # needs adjusting for a comprehensive maxx maxy minx miny
            plotFrameAlltraces.setMaxMinScaleValues(dataSetV.getMaxX()[0],dataSetV.getMinX()[0],dataSetV.getMaxY()[1],dataSetV.getMinY()[1])

        if (curveType == "F-I") :
            print "F-I analisys..."
            # initialize the dataSet for the graph
            if (dataSet == "") :
                dataSet = DataSet("info 1", "info 2", "nA", "Hz", "Current injected", "Firing frequency")
                dataSet.setGraphFormat(PlotCanvas.USE_CIRCLES_FOR_PLOT)
            spikeTimes = SpikeAnalyser.getSpikeTimes(volts, times, analyseThreshold, analyseStartTime, analyseStopTime)
Ejemplo n.º 9
0
    
    
        except:
            print "Error analysing simulation data from: %s"%simRef
            print exc_info()
    
    num_peaks = 1e9
    
    for ds in peaks_wave.values():
        if ds.getNumberPoints() < num_peaks:
            num_peaks = ds.getNumberPoints()
    
    
    info = "Averaged peak trace"
    
    avg = DataSet(info, info, "Time", "Peak", "ms", "")
    avg.setGraphFormat(PlotCanvas.USE_THICK_LINES_FOR_PLOT)
    
    for i in xrange(num_peaks):
        tot_val = 0
        for ds in peaks_wave.values():
            tot_val += ds.getPoint(i)[1]
        avg.addPoint(i, tot_val/len(peaks_wave))
    
    plotFrame2.addDataSet(avg)
    
    
    plotFrame.setVisible(True)
    plotFrame2.setVisible(True)

    innerRadius = outerRadius
Ejemplo n.º 10
0
	def generateV_ICurve(self,
                         projFile,
                         simulator,
                         simConfig,
                         stimAmpLow, stimAmpInc, stimAmpHigh,
                         stimDur,
                         simDuration,
                         maxNumSimultaneousSims = 4):

			# Load neuroConstruct project

			print "Loading project from file: " + projFile.getAbsolutePath()+", exists: "+ str(projFile.exists())

			pm = ProjectManager()
			self.myProject = pm.loadProject(projFile)
			self.simulator = simulator

			simConfig = self.myProject.simConfigInfo.getSimConfig(simConfig)

			simConfig.setSimDuration(simDuration)

			pm.doGenerate(simConfig.getName(), self.neuroConstructSeed)

			while pm.isGenerating():
					print "Waiting for the project to be generated with Simulation Configuration: "+str(simConfig)
					time.sleep(2)

			numGenerated = self.myProject.generatedCellPositions.getNumberInAllCellGroups()

			print "Number of cells generated: " + str(numGenerated)

			simReferences = {}


			if numGenerated > 0:

					print "Generating scripts for simulator: %s..."%simulator

					if simulator == 'NEURON':
						self.myProject.neuronFileManager.setQuitAfterRun(1) # Remove this line to leave the NEURON sim windows open after finishing
						self.myProject.neuronSettings.setCopySimFiles(1) # 1 copies hoc/mod files to PySim_0 etc. and will allow multiple sims to run at once
						self.myProject.neuronSettings.setGraphicsMode(0) # 0 hides graphs during execution
                        
					if simulator == 'GENESIS':
						self.myProject.genesisFileManager.setQuitAfterRun(1) # Remove this line to leave the NEURON sim windows open after finishing
						self.myProject.genesisSettings.setCopySimFiles(1) # 1 copies hoc/mod files to PySim_0 etc. and will allow multiple sims to run at once
						self.myProject.genesisSettings.setGraphicsMode(0) # 0 hides graphs during execution


					stimAmp = stimAmpLow

					ADD_TO_BEFORE_INIT = self.myProject.neuronSettings.getNativeBlock(NativeCodeLocation.BEFORE_INITIAL)
					ADD_TO_RECORD_I = self.myProject.neuronSettings.getNativeBlock(NativeCodeLocation.AFTER_SIMULATION)
					ADD_TO_START_FINITIALIZE = self.myProject.neuronSettings.getNativeBlock(NativeCodeLocation.START_FINITIALIZE)

					while stimAmp <= stimAmpHigh:

							while (len(self.simsRunning)>=maxNumSimultaneousSims):
									print "Sims currently running: "+str(self.simsRunning)
									print "Waiting..."
									time.sleep(3) # wait a while...
									self.updateSimsRunning()


							simRef = "PySim_"+str(float(stimAmp))

							print "Going to run simulation: "+simRef

							########  Adjusting the amplitude of the Voltage clamp ###############

                                                        TEXT_BEFORE_CREATION = "objref clampobj" + "\n" + "objref record_current" + "\n" + "objref data_save" + "\n"

                                                        # TEXT_BEFORE_INIT = "GranuleCell_mod_tonic[0].Soma {\n" + "clampobj = new SEClamp(0.5)\n" + "clampobj.dur1 = 150.0" + "\n" + "clampobj.amp1 = -100.0" + "\n" + "clampobj.dur2 = " + str(stimDur) + "\n" + "clampobj.amp2 = " + str(stimAmp) + "\n" + "clampobj.dur3 = 150.0" + "\n" + "clampobj.amp3 = -100.0" + "\n" + "clampobj.rs = 0.00001\n " + "}\n" # This should do the trick

                                                        # TEXT_BEFORE_INIT = TEXT_BEFORE_INIT + ADD_TO_BEFORE_INIT

                                                        TEXT_START_FINITIALIZE = "GranuleCell_mod_tonic[0].Soma {\n" + "clampobj = new SEClamp(0.5)\n" + "clampobj.dur1 = 150.0" + "\n" + "clampobj.amp1 = -100.0" + "\n" + "clampobj.dur2 = " + str(stimDur) + "\n" + "clampobj.amp2 = " + str(stimAmp) + "\n" + "clampobj.dur3 = 150.0" + "\n" + "clampobj.amp3 = -40.0" + "\n" + "clampobj.rs = 0.00001\n" + "record_current = new Vector()" + "\n" + "record_current.record(&clampobj.i)" + "\n" + "}\n" #This should do the trick

                                                        TEXT_START_FINITIALIZE = TEXT_START_FINITIALIZE + ADD_TO_START_FINITIALIZE

                                                        TEXT_TO_RECORD_I = """data_save = new File() \n""" + """strdef filename \n""" + """sprint(filename, """" + self.myProject.getProjectMainDirectory().getAbsolutePath() + """/simulations/current%.3f.txt", clampobj.amp2) \n""" + """data_save.wopen(filename) \n""" + """record_current.printf(data_save) \n""" + """data_save.close() \n"""

                                                        TEXT_TO_RECORD_I = TEXT_TO_RECORD_I + ADD_TO_RECORD_I

                                                        self.myProject.neuronSettings.setNativeBlock(NativeCodeLocation.BEFORE_CELL_CREATION, TEXT_BEFORE_CREATION)
                                                        # self.myProject.neuronSettings.setNativeBlock(NativeCodeLocation.BEFORE_INITIAL, TEXT_BEFORE_INIT)
                                                        self.myProject.neuronSettings.setNativeBlock(NativeCodeLocation.START_FINITIALIZE, TEXT_START_FINITIALIZE)
                                                        self.myProject.neuronSettings.setNativeBlock(NativeCodeLocation.AFTER_SIMULATION, TEXT_TO_RECORD_I)

					
							print "Next stim: "+ str(stimAmp)

							self.myProject.simulationParameters.setReference(simRef)

							if simulator == "NEURON":
									self.myProject.neuronFileManager.generateTheNeuronFiles(simConfig,
																							None,
																							NeuronFileManager.RUN_HOC,
																							self.simulatorSeed)

									print "Generated NEURON files for: "+simRef

									compileProcess = ProcessManager(self.myProject.neuronFileManager.getMainHocFile())

									compileSuccess = compileProcess.compileFileWithNeuron(0,0)

									print "Compiled NEURON files for: "+simRef

									if compileSuccess:
													pm.doRunNeuron(simConfig)
													print "Set running simulation: "+simRef
													self.simsRunning.append(simRef)

							if simulator == "GENESIS":
									compartmentalisation = GenesisCompartmentalisation()

									self.myProject.genesisFileManager.generateTheGenesisFiles(simConfig,
																							None,
																							compartmentalisation,
																							self.simulatorSeed)
									print "Generated GENESIS files for: "+simRef

									pm.doRunGenesis(simConfig)
									print "Set running simulation: "+simRef
									self.simsRunning.append(simRef)

							time.sleep(1) # Wait for sim to be kicked off
							simReferences[simRef] = stimAmp
							stimAmp = stimAmp +stimAmpInc

					print
					print "Finished running "+str(len(simReferences))+" simulations for project "+ projFile.getAbsolutePath()
					print "These can be loaded and replayed in the previous simulation browser in the GUI"
					print

			while (len(self.simsRunning)>0):
					print "Sims currently running: "+str(self.simsRunning)
					print "Waiting..."
					time.sleep(4) # wait a while...
					self.updateSimsRunning()

			#simReferences = {'PySim_0.3':0.3,'PySim_0.4':0.4,'PySim_0.5':0.5}

			plotFrameVI = PlotManager.getPlotterFrame("V-I curve from project: "+str(self.myProject.getProjectFile())+" on "+simulator , 1, 1)


			plotFrameVI.setViewMode(PlotCanvas.INCLUDE_ORIGIN_VIEW)

			info = "V-I curve for Simulation Configuration: "+str(simConfig)

			dataSet = DataSet(info, info, "mV", "nA", "Voltage", "Current")
			dataSet.setGraphFormat(PlotCanvas.USE_CIRCLES_FOR_PLOT)

			simList = simReferences.keys()
			simList.sort()

			for sim in simList:

					simDir = File(projFile.getParentFile(), "/neuroConstruct/models/Dan_GranCell/simulations/"+sim)
					print
					print "--- Reloading data from simulation in directory: %s"%simDir.getCanonicalPath()
					try:
							simData = SimulationData(simDir)
							simData.initialise()
							print "Data loaded: "
							print simData.getAllLoadedDataStores()
							times = simData.getAllTimes()
							cellSegmentRef = simConfig.getCellGroups().get(0)+"_0"

							cfilename = "E:/neuroConstruct/models/Dan_GranCell/simulations/" + sim + "/current.txt"
							trace = "E:/neuroConstruct/models/Dan_GranCell/simulations/" + sim + ".txt"
							# cFILE = open(cfilename, "r")
							
							
							strom = 0.0
							
							volts = simData.getVoltageAtAllTimes(cellSegmentRef)
							

							traceInfo = "Voltage at: %s in simulation: %s"%(cellSegmentRef, sim)

							stimAmp = simReferences[sim]
							print "Current at %f mV in sim %s: %f"%(stimAmp, sim, float(strom))
							
							dataSet.addPoint(stimAmp,float(strom))
					except:
							print "Error analysing simulation data from: %s"%simDir.getCanonicalPath()
							print sys.exc_info()[0]


			plotFrameVI.addDataSet(dataSet)
Ejemplo n.º 11
0
def testAll(argv=None):
    if argv is None:
        argv = sys.argv

    print "Loading project from " + projFile.getCanonicalPath()

    simManager = nc.SimulationManager(projFile,
                                      numConcurrentSims=numConcurrentSims,
                                      verbose=verbose)

    allSims = simManager.runMultipleSims(
        simConfigs=simConfigs,
        simDt=simDt,
        simDuration=simDuration,
        simulators=simulators,
        runInBackground=runInBackground,
        varTimestepNeuron=varTimestepNeuron,
        mpiConfigs=mpiConfigs,
        suggestedRemoteRunTime=suggestedRemoteRunTime,
        simRefGlobalPrefix=simAllPrefix,
        runSims=runSims,
        maxElecLens=multipleRuns,
        saveAsHdf5=saveAsHdf5,
        saveOnlySpikes=saveOnlySpikes)

    while (len(simManager.allRunningSims) > 0):
        print "Waiting for the following sims to finish: " + str(
            simManager.allRunningSims)
        time.sleep(5)  # wait a while...
        simManager.updateSimsRunning()

    times = []
    procNums = []
    for sim in allSims:
        simDir = File(projFile.getParentFile(), "/simulations/" + sim)
        try:
            simData = SimulationData(simDir)
            simData.initialise()
            simTime = simData.getSimulationProperties().getProperty(
                "RealSimulationTime")
            print "Simulation: %s took %s seconds" % (sim, simTime)
            times.append(float(simTime))
            paraConfig = simData.getSimulationProperties().getProperty(
                "Parallel configuration")
            print paraConfig
            numProc = int(paraConfig[max(
                paraConfig.find(" host, ") + 7,
                paraConfig.find(" hosts, ") +
                8):paraConfig.find(" processor")])
            procNums.append(numProc)

        except:
            print "Error analysing simulation data from: %s" % simDir.getCanonicalPath(
            )
            print sys.exc_info()

    print times
    print procNums
    '''
    import matplotlib.pyplot as plt
    lines = plt.loglog(times, procNums, 'r:')

    plt.ylabel('Simulation time')
    plt.xlabel('Number of processors')
    plt.show()'''

    from ucl.physiol.neuroconstruct.gui.plotter import PlotManager
    from ucl.physiol.neuroconstruct.gui.plotter import PlotCanvas

    from ucl.physiol.neuroconstruct.dataset import DataSet

    plotFrame = PlotManager.getPlotterFrame(
        "Time for simulation run on different numbers of processors", 0, 1)

    plotFrame.setViewMode(PlotCanvas.INCLUDE_ORIGIN_VIEW)

    info = "Simulation times for: " + str(procNums)

    dataSet = DataSet(info, info, "#", "s", "Number of processors",
                      "Simulation time")
    dataSet.setGraphFormat(PlotCanvas.USE_CIRCLES_FOR_PLOT)

    for i in range(len(times)):
        dataSet.addPoint(procNums[i], times[i] * procNums[i])

    plotFrame.addDataSet(dataSet)
Ejemplo n.º 12
0
    try:
        simData = SimulationData(simDir)
        simData.initialise()
        print("Data loaded: ")
        print(simData.getAllLoadedDataStores())

        times = simData.getAllTimes()
        # simConfig was just grabbed for use here, it was CGspinstell_0
        cellSegmentRef = simConfig.getCellGroups().get(0) + "_0"

        volts = simData.getVoltageAtAllTimes(cellSegmentRef)

        traceInfo = "Voltage at: %s in simulation: %s" % (cellSegmentRef, sim)

        dataSetV = DataSet(traceInfo, traceInfo, "ms", "mV", "Time",
                           "Membrane potential")
        for i in range(len(times)):
            dataSetV.addPoint(times[i], volts[i])

        if plotAllTraces:
            plotFrameAlltraces.addDataSet(dataSetV)
            # needs adjusting for a comprehensive maxx maxy minx miny
            plotFrameAlltraces.setMaxMinScaleValues(dataSetV.getMaxX()[0],
                                                    dataSetV.getMinX()[0],
                                                    dataSetV.getMaxY()[1],
                                                    dataSetV.getMinY()[1])

        if (curveType == "F-I"):
            print "F-I analisys..."
            # initialize the dataSet for the graph
            if (dataSet == ""):
        time.sleep(1) # Wait for sim to be kicked off
    
    print
    print "Finished running "+str(numSimulationsToRun)+" simulations for project "+ projFile.getAbsolutePath()
    print "These can be loaded and replayed in the previous simulation browser in the GUI"
    print

    ########  Generating a current versus firing rate plot  #######
    
    plotFrameFI = PlotManager.getPlotterFrame("F-I curve from project: "+str(myProject.getProjectFile()) , 1, 1)

    plotFrameFI.setViewMode(PlotCanvas.INCLUDE_ORIGIN_VIEW)

    info = "F-I curve for Simulation Configuration: "+str(simConfig)

    dataSet = DataSet(info, info, "nA", "Hz", "Current injected", "Firing frequency")
    dataSet.setGraphFormat(PlotCanvas.USE_CIRCLES_FOR_PLOT)

    simList = simReferences.keys()
    simList.sort()

    for sim in simList:

        simDir = File(projFile.getParentFile(), "/simulations/"+sim)
        print
        print "--- Reloading data from simulation in directory: %s"%simDir.getCanonicalPath()
        try:
            simData = SimulationData(simDir)
            simData.initialise()
            print "Data loaded: "
            print simData.getAllLoadedDataStores()
Ejemplo n.º 14
0
    print "Finished running " + str(
        numSimulationsToRun
    ) + " simulations for project " + projFile.getAbsolutePath()
    print "These can be loaded and replayed in the previous simulation browser in the GUI"
    print

    ########  Generating a current versus firing rate plot  #######

    plotFrameFI = PlotManager.getPlotterFrame(
        "F-I curve from project: " + str(myProject.getProjectFile()), 1, 1)

    plotFrameFI.setViewMode(PlotCanvas.INCLUDE_ORIGIN_VIEW)

    info = "F-I curve for Simulation Configuration: " + str(simConfig)

    dataSet = DataSet(info, info, "nA", "Hz", "Current injected",
                      "Firing frequency")
    dataSet.setGraphFormat(PlotCanvas.USE_CIRCLES_FOR_PLOT)

    simList = simReferences.keys()
    simList.sort()

    for sim in simList:

        simDir = File(projFile.getParentFile(), "/simulations/" + sim)
        print
        print "--- Reloading data from simulation in directory: %s" % simDir.getCanonicalPath(
        )
        try:
            simData = SimulationData(simDir)
            simData.initialise()
            print "Data loaded: "