示例#1
0
def runColumnSimulation(simConfig="TempSimConfig",
                        simDuration=100,
                        simDt=0.025,
                        neuroConstructSeed=1234,
                        simulatorSeed=1234,
                        simulators=["NEURON"],
                        simRefPrefix="Net_",
                        suggestedRemoteRunTime=120,
                        defaultSynapticDelay=0.05,
                        mpiConf=MpiSettings.LOCAL_SERIAL,
                        scaleCortex=0.1,
                        scaleThalamus=0,
                        gabaScaling=1,
                        l4ssAmpaScaling=1,
                        l5PyrGapScaling=1,
                        inNrtTcrNmdaScaling=1,
                        pyrSsNmdaScaling=1,
                        deepBiasCurrent=-1,
                        maxElecLenFRB=0.01,
                        maxElecLenRS=0.01,
                        maxElecLenIN=0.01,
                        maxElecLenSS=0.01,
                        somaNseg=-1,
                        varTimestepNeuron=False,
                        verbose=True,
                        runInBackground=False):

    print "Running new column simulation..."

    ############################################

    # Full column populations

    numFRB = 50  #   full model: 50
    numRS = 1000  #   full model: 1000
    numSupBask = 90  #   full model: 90
    numSupAxAx = 90  #   full model: 90
    numSupLTS = 90  #   full model: 90
    numL4SpinStell = 240  #   full model: 240
    numL5TuftIB = 800  #   full model: 800
    numL5TuftRS = 200  #   full model: 200
    numDeepBask = 100  #   full model: 100
    numDeepAxAx = 100  #   full model: 100
    numDeepLTS = 100  #   full model: 100
    numL6NonTuftRS = 500  #   full model: 500

    numTCR = 100  #   full model: 100
    numnRT = 100  #   full model: 100

    #######################################

    ### Load neuroConstruct project

    import datetime

    start = datetime.datetime.now()

    print "Loading project %s from at %s " % (projFile.getCanonicalPath(),
                                              start.strftime("%Y-%m-%d %H:%M"))

    pm = ProjectManager()
    project = pm.loadProject(projFile)

    ### Set duration & timestep & simulation configuration

    project.simulationParameters.setDt(simDt)
    simConfig = project.simConfigInfo.getSimConfig(simConfig)
    simConfig.setSimDuration(simDuration)

    ### Set simulation reference

    index = 0
    simRef = "%s%i" % (simRefPrefix, index)

    while File("%s/simulations/%s_N" %
               (project.getProjectMainDirectory().getCanonicalPath(),
                simRef)).exists():
        simRef = "%s%i" % (simRefPrefix, index)
        index = index + 1

    project.simulationParameters.setReference(simRef)

    ### Change num in each cell group

    numFRB = int(scaleCortex * numFRB)
    numRS = int(scaleCortex * numRS)
    numSupBask = int(scaleCortex * numSupBask)
    numSupAxAx = int(scaleCortex * numSupAxAx)
    numSupLTS = int(scaleCortex * numSupLTS)
    numL4SpinStell = int(scaleCortex * numL4SpinStell)
    numL5TuftIB = int(scaleCortex * numL5TuftIB)
    numL5TuftRS = int(scaleCortex * numL5TuftRS)
    numDeepBask = int(scaleCortex * numDeepBask)
    numDeepAxAx = int(scaleCortex * numDeepAxAx)
    numDeepLTS = int(scaleCortex * numDeepLTS)
    numL6NonTuftRS = int(scaleCortex * numL6NonTuftRS)

    numTCR = int(scaleThalamus * numTCR)
    numnRT = int(scaleThalamus * numnRT)

    project.cellGroupsInfo.getCellPackingAdapter(
        "CG3D_L23PyrFRB").setMaxNumberCells(
            numFRB)  # Note only works if RandomCellPackingAdapter
    project.cellGroupsInfo.getCellPackingAdapter(
        "CG3D_L23PyrRS").setMaxNumberCells(numRS)
    project.cellGroupsInfo.getCellPackingAdapter(
        "CG3D_SupBask").setMaxNumberCells(numSupBask)
    project.cellGroupsInfo.getCellPackingAdapter(
        "CG3D_SupAxAx").setMaxNumberCells(numSupAxAx)
    project.cellGroupsInfo.getCellPackingAdapter(
        "CG3D_SupLTS").setMaxNumberCells(numSupLTS)
    project.cellGroupsInfo.getCellPackingAdapter(
        "CG3D_L4SpinStell").setMaxNumberCells(numL4SpinStell)
    project.cellGroupsInfo.getCellPackingAdapter(
        "CG3D_L5TuftIB").setMaxNumberCells(numL5TuftIB)
    project.cellGroupsInfo.getCellPackingAdapter(
        "CG3D_L5TuftRS").setMaxNumberCells(numL5TuftRS)
    project.cellGroupsInfo.getCellPackingAdapter(
        "CG3D_DeepBask").setMaxNumberCells(numDeepBask)
    project.cellGroupsInfo.getCellPackingAdapter(
        "CG3D_DeepAxAx").setMaxNumberCells(numDeepAxAx)
    project.cellGroupsInfo.getCellPackingAdapter(
        "CG3D_DeepLTS").setMaxNumberCells(numDeepLTS)
    project.cellGroupsInfo.getCellPackingAdapter(
        "CG3D_L6NonTuftRS").setMaxNumberCells(numL6NonTuftRS)
    project.cellGroupsInfo.getCellPackingAdapter("CG3D_TCR").setMaxNumberCells(
        numTCR)
    project.cellGroupsInfo.getCellPackingAdapter("CG3D_nRT").setMaxNumberCells(
        numnRT)

    ### Change weights in synapses/gap junctions

    for netConnName in simConfig.getNetConns():

        if gabaScaling != 1:

            SimulationsInfo.addExtraSimProperty("gabaWeightScaling",
                                                str(gabaScaling))
            synList = project.morphNetworkConnectionsInfo.getSynapseList(
                netConnName)

            for index in range(0, len(synList)):
                synName = project.morphNetworkConnectionsInfo.getSynapseList(
                    netConnName).get(index).getSynapseType()
                if synName.count("GABAA") > 0:
                    print "Changing synaptic weight for syn %s in net conn %s by factor %f" % (
                        synName, netConnName, gabaScaling)

                    project.morphNetworkConnectionsInfo.getSynapseList(
                        netConnName).get(index).setWeightsGenerator(
                            NumberGenerator(gabaScaling))

        if l4ssAmpaScaling != 1:

            SimulationsInfo.addExtraSimProperty("l4ssAmpaScaling",
                                                str(l4ssAmpaScaling))
            synList = project.morphNetworkConnectionsInfo.getSynapseList(
                netConnName)

            for index in range(0, len(synList)):
                synName = project.morphNetworkConnectionsInfo.getSynapseList(
                    netConnName).get(index).getSynapseType()
                if synName.count("Syn_AMPA_L4SS_L4SS") > 0:
                    print "Changing synaptic weight for syn %s in net conn %s by factor %f" % (
                        synName, netConnName, l4ssAmpaScaling)

                    project.morphNetworkConnectionsInfo.getSynapseList(
                        netConnName).get(index).setWeightsGenerator(
                            NumberGenerator(l4ssAmpaScaling))

        if l5PyrGapScaling != 1:

            SimulationsInfo.addExtraSimProperty("l5PyrGapScaling",
                                                str(l5PyrGapScaling))
            synList = project.morphNetworkConnectionsInfo.getSynapseList(
                netConnName)

            for index in range(0, len(synList)):
                synName = project.morphNetworkConnectionsInfo.getSynapseList(
                    netConnName).get(index).getSynapseType()
                tgtCG = project.morphNetworkConnectionsInfo.getTargetCellGroup(
                    netConnName)
                if synName.count("Syn_Elect_DeepPyr_DeepPyr"
                                 ) > 0 and tgtCG.count("CG3D_L5") > 0:
                    print "Changing synaptic weight for syn %s in net conn %s by factor %f" % (
                        synName, netConnName, l5PyrGapScaling)

                    project.morphNetworkConnectionsInfo.getSynapseList(
                        netConnName).get(index).setWeightsGenerator(
                            NumberGenerator(l5PyrGapScaling))

        if inNrtTcrNmdaScaling != 1:

            SimulationsInfo.addExtraSimProperty("inNrtTcrNmdaScaling",
                                                str(inNrtTcrNmdaScaling))
            synList = project.morphNetworkConnectionsInfo.getSynapseList(
                netConnName)

            for index in range(0, len(synList)):
                synName = project.morphNetworkConnectionsInfo.getSynapseList(
                    netConnName).get(index).getSynapseType()
                if synName.count("NMDA") > 0 and (
                        synName.endswith("_IN") > 0
                        or synName.endswith("_DeepIN") > 0
                        or synName.endswith("_SupIN") > 0
                        or synName.endswith("_SupFS") > 0
                        or synName.endswith("_DeepFS") > 0
                        or synName.endswith("_SupLTS") > 0
                        or synName.endswith("_DeepLTS") > 0
                        or synName.endswith("_nRT") > 0
                        or synName.endswith("_TCR") > 0):

                    print "Changing synaptic weight for syn %s in net conn %s by factor %f" % (
                        synName, netConnName, inNrtTcrNmdaScaling)

                    project.morphNetworkConnectionsInfo.getSynapseList(
                        netConnName).get(index).setWeightsGenerator(
                            NumberGenerator(inNrtTcrNmdaScaling))

        if pyrSsNmdaScaling != 1:

            SimulationsInfo.addExtraSimProperty("pyrSsNmdaScaling",
                                                str(pyrSsNmdaScaling))
            synList = project.morphNetworkConnectionsInfo.getSynapseList(
                netConnName)

            for index in range(0, len(synList)):
                synName = project.morphNetworkConnectionsInfo.getSynapseList(
                    netConnName).get(index).getSynapseType()
                if synName.count("NMDA") > 0 and (
                        synName.endswith("_SupPyr") > 0
                        or synName.endswith("_DeepPyr") > 0
                        or synName.endswith("_L4SS") > 0
                        or synName.endswith("_L5Pyr") > 0
                        or synName.endswith("_L5RS") > 0
                        or synName.endswith("_L5IB") > 0
                        or synName.endswith("_L6NT") > 0
                        or synName.endswith("_Pyr") > 0):

                    print "Changing synaptic weight for syn %s in net conn %s by factor %f" % (
                        synName, netConnName, pyrSsNmdaScaling)

                    project.morphNetworkConnectionsInfo.getSynapseList(
                        netConnName).get(index).setWeightsGenerator(
                            NumberGenerator(pyrSsNmdaScaling))

    ### Change bias currents

    for inputName in simConfig.getInputs():

        stim = project.elecInputInfo.getStim(inputName)

        if deepBiasCurrent >= 0:

            if stim.getElectricalInput().TYPE == "IClamp" and (
                    stim.getCellGroup() == "CG3D_L5TuftIB"
                    or stim.getCellGroup() == "CG3D_L5TuftRS"
                    or stim.getCellGroup() == "CG3D_L6NonTuftRS"):

                print "Changing offset current in %s to %f" % (
                    stim.getCellGroup(), deepBiasCurrent)

                stim.setAmp(NumberGenerator(deepBiasCurrent))
                project.elecInputInfo.updateStim(stim)

    ### Change spatial discretisation of some cells. This will impact accuracy & simulation speed

    if maxElecLenFRB > 0:
        frbCell = project.cellManager.getCell("L23PyrFRB_varInit")
        info = CellTopologyHelper.recompartmentaliseCell(
            frbCell, maxElecLenFRB, project)
        print "Recompartmentalised FRB cell: " + info
        if somaNseg > 0:
            frbCell.getSegmentWithId(
                0).getSection().setNumberInternalDivisions(somaNseg)

    if maxElecLenRS > 0:
        rsCell = project.cellManager.getCell("L23PyrRS")
        info = CellTopologyHelper.recompartmentaliseCell(
            rsCell, maxElecLenRS, project)
        print "Recompartmentalised RS cell: " + info
        if somaNseg > 0:
            rsCell.getSegmentWithId(0).getSection().setNumberInternalDivisions(
                somaNseg)

    if maxElecLenIN > 0:
        inCells = [
            "SupBasket", "SupAxAx", "SupLTSInter", "DeepBasket", "DeepAxAx",
            "DeepLTSInter"
        ]

        for inCellName in inCells:
            inCell = project.cellManager.getCell(inCellName)
            info = CellTopologyHelper.recompartmentaliseCell(
                inCell, maxElecLenIN, project)
            print "Recompartmentalised " + inCellName + " cell: " + info
            if somaNseg > 0:
                inCell.getSegmentWithId(
                    0).getSection().setNumberInternalDivisions(somaNseg)

    ### Change parallel configuration

    mpiSettings = MpiSettings()
    simConfig.setMpiConf(mpiSettings.getMpiConfiguration(mpiConf))
    print "Parallel configuration: " + str(simConfig.getMpiConf())

    if suggestedRemoteRunTime > 0:
        project.neuronFileManager.setSuggestedRemoteRunTime(
            suggestedRemoteRunTime)
        project.genesisFileManager.setSuggestedRemoteRunTime(
            suggestedRemoteRunTime)

    ### Change synaptic delay associated with each net conn

    for netConnName in simConfig.getNetConns():
        if netConnName.count("gap") == 0:
            print "Changing synaptic delay in %s to %f" % (
                netConnName, defaultSynapticDelay)
            delayGen = NumberGenerator(defaultSynapticDelay)
            for synProps in project.morphNetworkConnectionsInfo.getSynapseList(
                    netConnName):
                synProps.setDelayGenerator(delayGen)

    # defaultSynapticDelay will be recorded in simulation.props and listed in SimulationBrowser GUI
    SimulationsInfo.addExtraSimProperty("defaultSynapticDelay",
                                        str(defaultSynapticDelay))

    ### Generate network structure in neuroConstruct

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

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

    print "Generated %i cells in %i cell groups" % (
        project.generatedCellPositions.getNumberInAllCellGroups(),
        project.generatedCellPositions.getNumberNonEmptyCellGroups())
    print "Generated %i instances in %i network connections" % (
        project.generatedNetworkConnections.getNumAllSynConns(),
        project.generatedNetworkConnections.getNumNonEmptyNetConns())
    print "Generated %i instances in %i elect inputs" % (
        project.generatedElecInputs.getNumberSingleInputs(),
        project.generatedElecInputs.getNonEmptyInputRefs().size())

    if simulators.count("NEURON") > 0:

        simRefN = simRef + "_N"
        project.simulationParameters.setReference(simRefN)

        nc.generateAndRunNeuron(project,
                                pm,
                                simConfig,
                                simRefN,
                                simulatorSeed,
                                verbose=verbose,
                                runInBackground=runInBackground,
                                varTimestep=varTimestepNeuron)

        sleep(2)  # wait a while before running GENESIS...

    if simulators.count("GENESIS") > 0:

        simRefG = simRef + "_G"
        project.simulationParameters.setReference(simRefG)

        nc.generateAndRunGenesis(project,
                                 pm,
                                 simConfig,
                                 simRefG,
                                 simulatorSeed,
                                 verbose=verbose,
                                 runInBackground=runInBackground)

        sleep(2)  # wait a while before running MOOSE...

    if simulators.count("MOOSE") > 0:

        simRefM = simRef + "_M"
        project.simulationParameters.setReference(simRefM)

        nc.generateAndRunMoose(project,
                               pm,
                               simConfig,
                               simRefM,
                               simulatorSeed,
                               verbose=verbose,
                               runInBackground=runInBackground)

        sleep(2)  # wait a while before running GENESIS...

    print "Finished running all sims, shutting down..."

    stop = datetime.datetime.now()
    print
    print "Started: %s, finished: %s" % (start.strftime("%Y-%m-%d %H:%M"),
                                         stop.strftime("%Y-%m-%d %H:%M"))
    print
for chan in reduced_cell_type.getChanMechsForGroup('soma_group'):
    if chan.getName() in ['NaP_CML', 'NaR_CML', 'NaT_CML']:
	chan.setDensity(0)
	reduced_cell_type.associateGroupWithChanMech('soma_group', chan)
for chan in vervaeke_cell_type.getChanMechsForGroup('soma_group'):
    if chan.getName() in ['NaP', 'NaR', 'NaT']:
	chan.setDensity(0)
	vervaeke_cell_type.associateGroupWithChanMech('soma_group', chan)

# generate
pm.doGenerate(sim_config_name, 1234)
while pm.isGenerating():
    time.sleep(0.02)

# pick a segment to stimulate on the detailed cell
cth = CellTopologyHelper()
distances_dict = dict(cth.getSegmentDistancesFromRoot(vervaeke_cell_type, dendritic_group))
stim_seg_detailed = random.choice([seg_id for seg_id,dist in distances_dict.items() if 200. < dist < 220.])

# pick a segment to stimulate on the reduced cell
stim_seg_reduced = 6

# map distances of all ancestors of stimulation segment
ancestor_dists = dict(cth.getDistancesFromAncestorSegments(vervaeke_cell_type, stim_seg_detailed))

source_segment_index = 0
source_fraction_along = 0.5
delay = 0.

locs = []
detailed_seg_ids = []
示例#3
0
    if deepBiasCurrent >= 0:
	
        if stim.getCellGroup()=="CG3D_L5TuftIB" or stim.getCellGroup()=="CG3D_L5TuftRS" or stim.getCellGroup()=="CG3D_L6NonTuftRS":
        
	  print "Changing offset current in %s to %f"%(stim.getCellGroup(), deepBiasCurrent)
	  
	  stim.setAmp(NumberGenerator(deepBiasCurrent))
	  project.elecInputInfo.updateStim(stim)'''
       


### Change spatial discretisation of some cells. This will impact accuracy & simulation speed

if maxElecLenFRB > 0:
    frbCell = project.cellManager.getCell("L23PyrFRB_varInit")
    info = CellTopologyHelper.recompartmentaliseCell(frbCell, maxElecLenFRB, project)
    print "Recompartmentalised FRB cell: "+info
    if somaNseg > 0:
        frbCell.getSegmentWithId(0).getSection().setNumberInternalDivisions(somaNseg)

if maxElecLenRS > 0:
    rsCell = project.cellManager.getCell("L23PyrRS")
    info = CellTopologyHelper.recompartmentaliseCell(rsCell, maxElecLenRS, project)
    print "Recompartmentalised RS cell: "+info
    if somaNseg > 0:
        rsCell.getSegmentWithId(0).getSection().setNumberInternalDivisions(somaNseg)

if maxElecLenIN > 0:
    inCells = ["SupBasket", "SupAxAx","SupLTSInter","DeepBasket", "DeepAxAx","DeepLTSInter"]

    for inCellName in inCells:
def runColumnSimulation(simConfig=    			"TempSimConfig",
		        simDuration = 			100,
			simDt = 			0.025, 
			neuroConstructSeed = 		1234,
			simulatorSeed = 		1234,
			simulators = 			["NEURON"],
			simRefPrefix =          	"Net_",
			suggestedRemoteRunTime = 	120,
			defaultSynapticDelay =  	0.05,
			mpiConf = 			MpiSettings.LOCAL_SERIAL,
			scaleCortex = 			0.1,
			scaleThalamus = 		0,
			gabaScaling = 			1,
			l4ssAmpaScaling = 		1,
			l5PyrGapScaling = 		1,
			inNrtTcrNmdaScaling = 		1,
			pyrSsNmdaScaling = 		1,
			deepBiasCurrent = 		-1,
			maxElecLenFRB = 		0.01,
			maxElecLenRS =          	0.01,
			maxElecLenIN =         		0.01,
			maxElecLenSS =         		0.01,
			somaNseg =              	-1,
			varTimestepNeuron =     	False,
			verbose =               	True,
			runInBackground = 		False):
			  
    print "Running new column simulation..."

    ############################################

    # Full column populations

    numFRB =                50       #   full model: 50
    numRS =                 1000     #   full model: 1000
    numSupBask =            90       #   full model: 90
    numSupAxAx =            90       #   full model: 90
    numSupLTS =             90       #   full model: 90
    numL4SpinStell =        240      #   full model: 240
    numL5TuftIB =           800      #   full model: 800
    numL5TuftRS =           200      #   full model: 200
    numDeepBask =           100      #   full model: 100
    numDeepAxAx =           100      #   full model: 100
    numDeepLTS =            100      #   full model: 100
    numL6NonTuftRS =        500      #   full model: 500


    numTCR =                100      #   full model: 100
    numnRT =                100      #   full model: 100


    #######################################


    ### Load neuroConstruct project


    import datetime

    start = datetime.datetime.now()

    print "Loading project %s from at %s " % (projFile.getCanonicalPath(),start.strftime("%Y-%m-%d %H:%M"))

    pm = ProjectManager()
    project = pm.loadProject(projFile)


    ### Set duration & timestep & simulation configuration

    project.simulationParameters.setDt(simDt)
    simConfig = project.simConfigInfo.getSimConfig(simConfig)
    simConfig.setSimDuration(simDuration)


    ### Set simulation reference

    index = 0
    simRef = "%s%i"%(simRefPrefix,index)


    while File( "%s/simulations/%s_N"%(project.getProjectMainDirectory().getCanonicalPath(), simRef)).exists():
	simRef = "%s%i"%(simRefPrefix,index)
	index = index+1

    project.simulationParameters.setReference(simRef)


    ### Change num in each cell group

    numFRB = int(scaleCortex * numFRB)
    numRS = int(scaleCortex * numRS)
    numSupBask = int(scaleCortex * numSupBask)
    numSupAxAx = int(scaleCortex * numSupAxAx)
    numSupLTS = int(scaleCortex * numSupLTS)
    numL4SpinStell = int(scaleCortex * numL4SpinStell)
    numL5TuftIB = int(scaleCortex * numL5TuftIB)
    numL5TuftRS = int(scaleCortex * numL5TuftRS)
    numDeepBask = int(scaleCortex * numDeepBask)
    numDeepAxAx = int(scaleCortex * numDeepAxAx)
    numDeepLTS = int(scaleCortex * numDeepLTS)
    numL6NonTuftRS = int(scaleCortex * numL6NonTuftRS)

    numTCR = int(scaleThalamus * numTCR)
    numnRT = int(scaleThalamus * numnRT)

    project.cellGroupsInfo.getCellPackingAdapter("CG3D_L23PyrFRB").setMaxNumberCells(numFRB) # Note only works if RandomCellPackingAdapter
    project.cellGroupsInfo.getCellPackingAdapter("CG3D_L23PyrRS").setMaxNumberCells(numRS)
    project.cellGroupsInfo.getCellPackingAdapter("CG3D_SupBask").setMaxNumberCells(numSupBask)
    project.cellGroupsInfo.getCellPackingAdapter("CG3D_SupAxAx").setMaxNumberCells(numSupAxAx)
    project.cellGroupsInfo.getCellPackingAdapter("CG3D_SupLTS").setMaxNumberCells(numSupLTS)
    project.cellGroupsInfo.getCellPackingAdapter("CG3D_L4SpinStell").setMaxNumberCells(numL4SpinStell)
    project.cellGroupsInfo.getCellPackingAdapter("CG3D_L5TuftIB").setMaxNumberCells(numL5TuftIB)
    project.cellGroupsInfo.getCellPackingAdapter("CG3D_L5TuftRS").setMaxNumberCells(numL5TuftRS)
    project.cellGroupsInfo.getCellPackingAdapter("CG3D_DeepBask").setMaxNumberCells(numDeepBask)
    project.cellGroupsInfo.getCellPackingAdapter("CG3D_DeepAxAx").setMaxNumberCells(numDeepAxAx)
    project.cellGroupsInfo.getCellPackingAdapter("CG3D_DeepLTS").setMaxNumberCells(numDeepLTS)
    project.cellGroupsInfo.getCellPackingAdapter("CG3D_L6NonTuftRS").setMaxNumberCells(numL6NonTuftRS)
    project.cellGroupsInfo.getCellPackingAdapter("CG3D_TCR").setMaxNumberCells(numTCR)
    project.cellGroupsInfo.getCellPackingAdapter("CG3D_nRT").setMaxNumberCells(numnRT)



    ### Change weights in synapses/gap junctions

    for netConnName in simConfig.getNetConns():

	if gabaScaling != 1:

	    SimulationsInfo.addExtraSimProperty("gabaWeightScaling", str(gabaScaling))
	    synList = project.morphNetworkConnectionsInfo.getSynapseList(netConnName)
	    
	    for index in range(0, len(synList)):
		synName = project.morphNetworkConnectionsInfo.getSynapseList(netConnName).get(index).getSynapseType()
		if synName.count("GABAA")>0:
		    print "Changing synaptic weight for syn %s in net conn %s by factor %f"%(synName, netConnName, gabaScaling)
		
		    project.morphNetworkConnectionsInfo.getSynapseList(netConnName).get(index).setWeightsGenerator(NumberGenerator(gabaScaling))
		    
	if l4ssAmpaScaling !=1:
	  
	    SimulationsInfo.addExtraSimProperty("l4ssAmpaScaling", str(l4ssAmpaScaling))
	    synList = project.morphNetworkConnectionsInfo.getSynapseList(netConnName)
	    
	    for index in range(0, len(synList)):
		synName = project.morphNetworkConnectionsInfo.getSynapseList(netConnName).get(index).getSynapseType()
		if synName.count("Syn_AMPA_L4SS_L4SS")>0:
		    print "Changing synaptic weight for syn %s in net conn %s by factor %f"%(synName, netConnName, l4ssAmpaScaling)
		
		    project.morphNetworkConnectionsInfo.getSynapseList(netConnName).get(index).setWeightsGenerator(NumberGenerator(l4ssAmpaScaling))
		    
	if l5PyrGapScaling !=1:
	  
	    SimulationsInfo.addExtraSimProperty("l5PyrGapScaling", str(l5PyrGapScaling))
	    synList = project.morphNetworkConnectionsInfo.getSynapseList(netConnName)
	    
	    for index in range(0, len(synList)):
		synName = project.morphNetworkConnectionsInfo.getSynapseList(netConnName).get(index).getSynapseType()
		tgtCG = project.morphNetworkConnectionsInfo.getTargetCellGroup(netConnName)
		if synName.count("Syn_Elect_DeepPyr_DeepPyr")>0 and tgtCG.count("CG3D_L5")>0:
		    print "Changing synaptic weight for syn %s in net conn %s by factor %f"%(synName, netConnName, l5PyrGapScaling)
		
		    project.morphNetworkConnectionsInfo.getSynapseList(netConnName).get(index).setWeightsGenerator(NumberGenerator(l5PyrGapScaling))
		    
	if inNrtTcrNmdaScaling !=1:
	  
	    SimulationsInfo.addExtraSimProperty("inNrtTcrNmdaScaling", str(inNrtTcrNmdaScaling))
	    synList = project.morphNetworkConnectionsInfo.getSynapseList(netConnName)
	    
	    for index in range(0, len(synList)):
		synName = project.morphNetworkConnectionsInfo.getSynapseList(netConnName).get(index).getSynapseType()
		if synName.count("NMDA")>0 and (synName.endswith("_IN")>0 or 
						synName.endswith("_DeepIN")>0 or 
						synName.endswith("_SupIN")>0 or 
						synName.endswith("_SupFS")>0 or 
						synName.endswith("_DeepFS")>0 or 
						synName.endswith("_SupLTS")>0 or 
						synName.endswith("_DeepLTS")>0 or 
						synName.endswith("_nRT")>0 or 
						synName.endswith("_TCR")>0):
						  
		    print "Changing synaptic weight for syn %s in net conn %s by factor %f"%(synName, netConnName, inNrtTcrNmdaScaling)
		
		    project.morphNetworkConnectionsInfo.getSynapseList(netConnName).get(index).setWeightsGenerator(NumberGenerator(inNrtTcrNmdaScaling))
	  
	if pyrSsNmdaScaling !=1:
	  
	    SimulationsInfo.addExtraSimProperty("pyrSsNmdaScaling", str(pyrSsNmdaScaling))
	    synList = project.morphNetworkConnectionsInfo.getSynapseList(netConnName)
	    
	    for index in range(0, len(synList)):
		synName = project.morphNetworkConnectionsInfo.getSynapseList(netConnName).get(index).getSynapseType()
		if synName.count("NMDA")>0 and (synName.endswith("_SupPyr")>0 or
						synName.endswith("_DeepPyr")>0 or
						synName.endswith("_L4SS")>0 or
						synName.endswith("_L5Pyr")>0 or
						synName.endswith("_L5RS")>0 or
						synName.endswith("_L5IB")>0 or
						synName.endswith("_L6NT")>0 or
						synName.endswith("_Pyr")>0):
						  
		    print "Changing synaptic weight for syn %s in net conn %s by factor %f"%(synName, netConnName, pyrSsNmdaScaling)
		
		    project.morphNetworkConnectionsInfo.getSynapseList(netConnName).get(index).setWeightsGenerator(NumberGenerator(pyrSsNmdaScaling))


    ### Change bias currents

    for inputName in simConfig.getInputs():
      
	stim = project.elecInputInfo.getStim(inputName)
      
	if deepBiasCurrent >= 0:
	    
	    if stim.getElectricalInput().TYPE == "IClamp" and (stim.getCellGroup()=="CG3D_L5TuftIB" or stim.getCellGroup()=="CG3D_L5TuftRS" or stim.getCellGroup()=="CG3D_L6NonTuftRS"):
	    
	      print "Changing offset current in %s to %f"%(stim.getCellGroup(), deepBiasCurrent)
	      
	      stim.setAmp(NumberGenerator(deepBiasCurrent))
	      project.elecInputInfo.updateStim(stim)
	  


    ### Change spatial discretisation of some cells. This will impact accuracy & simulation speed

    if maxElecLenFRB > 0:
	frbCell = project.cellManager.getCell("L23PyrFRB_varInit")
	info = CellTopologyHelper.recompartmentaliseCell(frbCell, maxElecLenFRB, project)
	print "Recompartmentalised FRB cell: "+info
	if somaNseg > 0:
	    frbCell.getSegmentWithId(0).getSection().setNumberInternalDivisions(somaNseg)

    if maxElecLenRS > 0:
	rsCell = project.cellManager.getCell("L23PyrRS")
	info = CellTopologyHelper.recompartmentaliseCell(rsCell, maxElecLenRS, project)
	print "Recompartmentalised RS cell: "+info
	if somaNseg > 0:
	    rsCell.getSegmentWithId(0).getSection().setNumberInternalDivisions(somaNseg)

    if maxElecLenIN > 0:
	inCells = ["SupBasket", "SupAxAx","SupLTSInter","DeepBasket", "DeepAxAx","DeepLTSInter"]

	for inCellName in inCells:
	    inCell = project.cellManager.getCell(inCellName)
	    info = CellTopologyHelper.recompartmentaliseCell(inCell, maxElecLenIN, project)
	    print "Recompartmentalised "+inCellName+" cell: "+info
	    if somaNseg > 0:
		inCell.getSegmentWithId(0).getSection().setNumberInternalDivisions(somaNseg)


    ### Change parallel configuration

    mpiSettings = MpiSettings()
    simConfig.setMpiConf(mpiSettings.getMpiConfiguration(mpiConf))
    print "Parallel configuration: "+ str(simConfig.getMpiConf())

    if suggestedRemoteRunTime > 0:
	project.neuronFileManager.setSuggestedRemoteRunTime(suggestedRemoteRunTime)
	project.genesisFileManager.setSuggestedRemoteRunTime(suggestedRemoteRunTime)


    ### Change synaptic delay associated with each net conn

    for netConnName in simConfig.getNetConns():
	if netConnName.count("gap")==0:
	    print "Changing synaptic delay in %s to %f"%(netConnName, defaultSynapticDelay)
	    delayGen = NumberGenerator(defaultSynapticDelay)
	    for synProps in project.morphNetworkConnectionsInfo.getSynapseList(netConnName):
		synProps.setDelayGenerator(delayGen)

    # defaultSynapticDelay will be recorded in simulation.props and listed in SimulationBrowser GUI
    SimulationsInfo.addExtraSimProperty("defaultSynapticDelay", str(defaultSynapticDelay))


    ### Generate network structure in neuroConstruct

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

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


    print "Generated %i cells in %i cell groups" % (project.generatedCellPositions.getNumberInAllCellGroups(), project.generatedCellPositions.getNumberNonEmptyCellGroups())
    print "Generated %i instances in %i network connections" % (project.generatedNetworkConnections.getNumAllSynConns(), project.generatedNetworkConnections.getNumNonEmptyNetConns())
    print "Generated %i instances in %i elect inputs" % (project.generatedElecInputs.getNumberSingleInputs(), project.generatedElecInputs.getNonEmptyInputRefs().size())


    if simulators.count("NEURON")>0:
	
	simRefN = simRef+"_N"
	project.simulationParameters.setReference(simRefN)

	nc.generateAndRunNeuron(project,
				pm,
				simConfig,
				simRefN,
				simulatorSeed,
				verbose=verbose,
				runInBackground=runInBackground,
				varTimestep=varTimestepNeuron)
	    
	sleep(2) # wait a while before running GENESIS...
	
    if simulators.count("GENESIS")>0:
	
	simRefG = simRef+"_G"
	project.simulationParameters.setReference(simRefG)

	nc.generateAndRunGenesis(project,
				pm,
				simConfig,
				simRefG,
				simulatorSeed,
				verbose=verbose,
				runInBackground=runInBackground)
				
	sleep(2) # wait a while before running MOOSE...


    if simulators.count("MOOSE")>0:

	simRefM = simRef+"_M"
	project.simulationParameters.setReference(simRefM)

	nc.generateAndRunMoose(project,
				pm,
				simConfig,
				simRefM,
				simulatorSeed,
				verbose=verbose,
				runInBackground=runInBackground)
				
	sleep(2) # wait a while before running GENESIS...


    print "Finished running all sims, shutting down..."


    stop = datetime.datetime.now()
    print
    print "Started: %s, finished: %s" % (start.strftime("%Y-%m-%d %H:%M"),stop.strftime("%Y-%m-%d %H:%M"))
    print
def SingleCellNML2generator(projString=" ",
                            ConfigDict={},
                            ElecLenList=[],
                            somaNseg=None,
                            savingDir=None):

    projFile = File(os.getcwd(), projString)
    pm = ProjectManager()
    compSummary = {}
    for config in ConfigDict.keys():

        project = pm.loadProject(projFile)

        nmlfm = NeuroMLFileManager(project)

        compSummary[config] = {}
        if " " in config:
            configPath = config.replace(" ", "_")
        else:
            configPath = config

        for maxElecLen in ElecLenList:
            compSummary[config][str(maxElecLen)] = {}
            cell = project.cellManager.getCell(ConfigDict[config])

            if maxElecLen > 0:

                info = CellTopologyHelper.recompartmentaliseCell(
                    cell, maxElecLen, project)
                print "Recompartmentalising cell %s" % ConfigDict[config]
                if somaNseg != None:
                    cell.getSegmentWithId(
                        0).getSection().setNumberInternalDivisions(somaNseg)
                if savingDir != None:
                    cellpath = r'../../NeuroML2/%s/%s/%s_%f' % (
                        savingDir, configPath, configPath, maxElecLen)
                else:
                    cellpath = r'../../NeuroML2/%s/%s_%f' % (
                        configPath, configPath, maxElecLen)

            else:
                if savingDir != None:
                    cellpath = r'../../NeuroML2/%s/%s/%s_default' % (
                        savingDir, configPath, configPath)
                else:
                    cellpath = r'../../NeuroML2/%s/%s_default' % (configPath,
                                                                  configPath)

            summary = str(cell.getMorphSummary())
            summary_string = summary.split("_")
            for feature in summary_string:
                feature_split = feature.split(":")
                compSummary[config][str(maxElecLen)][
                    feature_split[0]] = feature_split[1]

# the format of summary :  Segs:122_Secs:61_IntDivs:1458
            print("Will be printing a cell morphology summary")
            print compSummary[config][str(maxElecLen)]
            ######### it turns out that this does not save recompartmentalized cells - all saved cells have identical spatial discretization;
            ##### generateNeuroML2 receives the parent projFile but not the loaded project which is  modified by the CellTopologyHelper.recompartmentaliseCell()

            ##################### neuroConstruct block #############################################################################

            neuroConstructSeed = 1234
            verbose = True
            pm.doGenerate(config, neuroConstructSeed)

            while pm.isGenerating():
                if verbose:
                    print(
                        "Waiting for the project to be generated with Simulation Configuration: "
                        + config)
                    time.sleep(5)

            simConfig = project.simConfigInfo.getSimConfig(config)

            seed = 1234
            genDir = File(projFile.getParentFile(), "generatedNeuroML2")
            nmlfm.generateNeuroMLFiles(
                simConfig, NeuroMLConstants.NeuroMLVersion.getLatestVersion(),
                LemsConstants.LemsOption.LEMS_WITHOUT_EXECUTE_MODEL,
                OriginalCompartmentalisation(), seed, False, True, genDir,
                "GENESIS Physiological Units", False)

            ########################################################################################################################

            if not os.path.exists(cellpath):
                print("Creating a new directory %s" % cellpath)
                os.makedirs(cellpath)
            else:
                print("A directory %s already exists" % cellpath)

            src_files = os.listdir("../generatedNeuroML2/")

            for file_name in src_files:
                full_file_name = os.path.join("../generatedNeuroML2/",
                                              file_name)
                if (os.path.isfile(full_file_name)):
                    print("Moving generated NeuroML2 to files to %s" %
                          cellpath)
                    shutil.copy(full_file_name, cellpath)

    #with open("compSummary.json",'w') as fout:
    #json.dump(compSummary, fout)

    subprocess.call(["~/neuroConstruct/nC.sh -python RegenerateNml2.py -f"],
                    shell=True)

    #subprocess.call(["cp compSummary.json ~/Thalamocortical/NeuroML2/"],shell=True)

    quit()
示例#6
0
for simConfigName in simConfigs:

  for maxElecLen in maxElecLens:

    project.simulationParameters.setDt(simDt)

    simConfig = project.simConfigInfo.getSimConfig(simConfigName)

    recompSuffix = ""
    
    if maxElecLen > 0:
        cellGroup = simConfig.getCellGroups().get(0)
        cell = project.cellManager.getCell(project.cellGroupsInfo.getCellType(cellGroup))
        print "Recomp cell in: "+cellGroup+" which is: "+str(cell)
        info = CellTopologyHelper.recompartmentaliseCell(cell, maxElecLen, project)
        print "*** Recompartmentalised cell: "+info
        recompSuffix = "_"+str(maxElecLen)

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

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


    print "Generated network with %i cell(s)" % project.generatedCellPositions.getNumberInAllCellGroups()


    simRefPrefix = (simConfigName+"_").replace(' ', '')
def SingleCellNML2generator(projString=" ",ConfigDict={},ElecLenList=[],somaNseg=None,savingDir=None,shell=None):
    
    projFile=File(os.getcwd(),projString)
    
    pm=ProjectManager()
    
    for config in ConfigDict.keys():
    
        project=pm.loadProject(projFile)
        
        nmlfm = NeuroMLFileManager(project)
        
        compSummary={}
       
        compSummary[config]={}
        
        if " " in config:
           configPath=config.replace(" ","_")
        else:
           configPath=config
           
        if savingDir !=None:
        
           full_path_to_config=r'../%s/%s'%(savingDir,configPath)
           
        else:
        
           full_path_to_config=r'../%s'%(configPath)
        
        for maxElecLen in ElecLenList:
            compSummary[config][str(maxElecLen)]={}
            cell=project.cellManager.getCell(ConfigDict[config])
            
            if maxElecLen > 0:

	       info = CellTopologyHelper.recompartmentaliseCell(cell, maxElecLen, project)
	       print "Recompartmentalising cell %s"%ConfigDict[config]
	       if somaNseg != None:
	          cell.getSegmentWithId(0).getSection().setNumberInternalDivisions(somaNseg)
	       if savingDir !=None: 
	          cellpath = r'../%s/%s/%s_%f'%(savingDir,configPath,configPath,maxElecLen)
	       else:
	          cellpath = r'../%s/%s_%f'%(configPath,configPath,maxElecLen)
	       
	    else:
	       if savingDir !=None:
	          cellpath = r'../%s/%s/%s_default'%(savingDir,configPath,configPath)
	       else:
	          cellpath = r'../%s/%s_default'%(configPath,configPath)
	       
	    summary=str(cell.getMorphSummary()) 
	    summary_string=summary.split("_")
	    for feature in summary_string:
	        feature_split=feature.split(":")
	        compSummary[config][str(maxElecLen)][feature_split[0]]=feature_split[1]
	    # the format of summary :  Segs:122_Secs:61_IntDivs:1458
	    print("Will be printing a cell morphology summary")
	    print compSummary[config][str(maxElecLen)]
	    ######### it turns out that this does not save recompartmentalized cells - all saved cells have identical spatial discretization; 
	    ##### generateNeuroML2 receives the parent projFile but not the loaded project which is  modified by the CellTopologyHelper.recompartmentaliseCell()
	    
	    ##################### neuroConstruct block #############################################################################
	    
	    neuroConstructSeed=1234
	    verbose=True
	    pm.doGenerate(config, neuroConstructSeed)

            while pm.isGenerating():
                  if verbose: 
                     print("Waiting for the project to be generated with Simulation Configuration: "+config)
                     time.sleep(5)
                     
	    simConfig = project.simConfigInfo.getSimConfig(config)
	    
	    seed=1234
	    genDir = File(projFile.getParentFile(), "generatedNeuroML2")
            nmlfm.generateNeuroMLFiles(simConfig,
                                       NeuroMLConstants.NeuroMLVersion.getLatestVersion(),
                                       LemsConstants.LemsOption.LEMS_WITHOUT_EXECUTE_MODEL,
                                       OriginalCompartmentalisation(),
                                       seed,
                                       False,
                                       True,
                                       genDir,
                                       "GENESIS Physiological Units",
                                       False)
            
            ########################################################################################################################
            
            if not os.path.exists(cellpath):
               print("Creating a new directory %s"%cellpath)
               os.makedirs(cellpath)
            else:
               print("A directory %s already exists"%cellpath)
              
               
            src_files = os.listdir("../../neuroConstruct/generatedNeuroML2/")
            for file_name in src_files:
                full_file_name = os.path.join("../../neuroConstruct/generatedNeuroML2/", file_name)
                if (os.path.isfile(full_file_name)):
                   print("Moving generated NeuroML2 to files to %s"%cellpath)
                   shutil.copy(full_file_name, cellpath)
                      
        with open(os.path.join(full_path_to_config,"compSummary.json"),'w') as fout:
             json.dump(compSummary, fout)          
      
    if shell ==None:
       extension='sh'
    else:
       extension=shell      
    
    os.chdir("../../neuroConstruct/pythonScripts")  
      
    subprocess.call("%s/nC.%s -python ../../neuroConstruct/pythonScripts/RegenerateNml2.py -f"%(os.environ["NC_HOME"],extension),shell=True)
    
    os.chdir("../../NeuroML2/pythonScripts")
示例#8
0
文件: Test.py 项目: pgleeson/TestArea
sp1 = Species("k")
sp1.setProperty("e", "-77.7")
grps1 = Vector()
grps1.add(Section.ALL)
spVg.put(sp1, grps1)

sp2 = Species("na")
sp2.setProperty("e", "55.5")
grps2 = Vector()
grps2.add(Section.ALL)
spVg.put(sp2, grps2)

print "Spec vs groups: " + str(spVg)

print CellTopologyHelper.printDetails(cell, myProject)

simConfig = myProject.simConfigInfo.getSimConfig(simConfig)

myProject.markProjectAsEdited()
print "Saving project..."
myProject.saveProject()
print "Project saved"

exit()
simConfig.setSimDuration(simDuration)

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

while pm.isGenerating():
    print "Waiting for the project to be generated with Simulation Configuration: " + str(simConfig)
示例#9
0
        if synScaling != 1:
            SimulationsInfo.addExtraSimProperty("synapticWeightScaling", str(synScaling))
            print "Changing synaptic weight in %s by factor %f"%(netConnName, synScaling)
            project.morphNetworkConnectionsInfo.getSynapseList(netConnName).get(0).setWeightsGenerator(NumberGenerator(synScaling))
    else:
        if gapScaling != 1:
            SimulationsInfo.addExtraSimProperty("gapJunctionWeightScaling", str(gapScaling))
            print "Changing gap junction weight in %s by factor %f"%(netConnName, gapScaling)
            project.morphNetworkConnectionsInfo.getSynapseList(netConnName).get(0).setWeightsGenerator(NumberGenerator(gapScaling))


### Change spatial discretisation of some cells. This will impact accuracy & simulation speed

if maxElecLenFRB > 0:
    frbCell = project.cellManager.getCell("L23PyrFRB_varInit")
    info = CellTopologyHelper.recompartmentaliseCell(frbCell, maxElecLenFRB, project)
    print "Recompartmentalised FRB cell: "+info
    if somaNseg > 0:
        frbCell.getSegmentWithId(0).getSection().setNumberInternalDivisions(somaNseg)

if maxElecLenRS > 0:
    rsCell = project.cellManager.getCell("L23PyrRS")
    info = CellTopologyHelper.recompartmentaliseCell(rsCell, maxElecLenRS, project)
    print "Recompartmentalised RS cell: "+info
    if somaNseg > 0:
        rsCell.getSegmentWithId(0).getSection().setNumberInternalDivisions(somaNseg)

if maxElecLenLTS > 0:
    ltsCell = project.cellManager.getCell("SupLTSInter")
    info = CellTopologyHelper.recompartmentaliseCell(ltsCell, maxElecLenLTS, project)
    print "Recompartmentalised LTS cell: "+info