Ejemplo n.º 1
0
    def __init__(self, pre_index, post_index, presynaptic_population,
                 postsynaptic_population, projection_nml, conn_id,
                 pre_pop_comp, post_pop_comp, **attributes):
        #logger.info("Creating Connection: %s -> %s (%s)" % (pre_index, post_index, projection_nml))

        self.presynaptic_index = pre_index
        self.postsynaptic_index = post_index

        nml_pre_index = pre_index
        nml_post_index = post_index

        pre_pop = presynaptic_population
        if isinstance(presynaptic_population, common.PopulationView):
            pre_pop = presynaptic_population.parent
            nml_pre_index = presynaptic_population.index_in_grandparent(
                [pre_index])[0]

        post_pop = postsynaptic_population
        if isinstance(postsynaptic_population, common.PopulationView):
            post_pop = postsynaptic_population.parent
            nml_post_index = postsynaptic_population.index_in_grandparent(
                [post_index])[0]

        projection_nml.connection_wds.append(
            neuroml.ConnectionWD(
                id=conn_id,
                pre_cell_id="../%s/%i/%s" %
                (pre_pop.label, nml_pre_index, pre_pop_comp),
                post_cell_id="../%s/%i/%s" %
                (post_pop.label, nml_post_index, post_pop_comp),
                weight=attributes['WEIGHT'],
                delay='%sms' % attributes['DELAY']))

        for name, value in attributes.items():
            setattr(self, name, value)
Ejemplo n.º 2
0
 def __init__(self, pre, post, projection, conn_id, pre_pop_comp, post_pop_comp, **attributes):
     #logger.debug("Creating Connection: %s -> %s" % (pre, post))
     
     self.presynaptic_index = pre
     self.postsynaptic_index = post
     projection.connection_wds.append(neuroml.ConnectionWD(id=conn_id,pre_cell_id="../%s/%i/%s"%(projection.presynaptic_population,pre,pre_pop_comp),
                post_cell_id="../%s/%i/%s"%(projection.postsynaptic_population,post,post_pop_comp), weight=attributes['WEIGHT'], delay='%sms'%attributes['DELAY']))
                
     for name, value in attributes.items():
         setattr(self, name, value)
Ejemplo n.º 3
0
    def handleConnection(self, proj_id, conn_id, prePop, postPop, synapseType, \
                                                    preCellId, \
                                                    postCellId, \
                                                    preSegId = 0, \
                                                    preFract = 0.5, \
                                                    postSegId = 0, \
                                                    postFract = 0.5, \
                                                    delay=0,
                                                    weight=1):

        #self.printConnectionInformation(proj_id, conn_id, prePop, postPop, synapseType, preCellId, postCellId, weight)

        if not self.weightDelays[proj_id] and delay == 0 and weight == 1:

            connection = neuroml.Connection(id=conn_id, \
                                pre_cell_id="../%s/%i/%s"%(prePop,preCellId,self.populations[prePop].component), \
                                pre_segment_id=preSegId, \
                                pre_fraction_along=preFract,
                                post_cell_id="../%s/%i/%s"%(postPop,postCellId,self.populations[postPop].component), \
                                post_segment_id=postSegId,
                                post_fraction_along=postFract)

            self.projections[proj_id].connections.append(connection)

        else:
            connection = neuroml.ConnectionWD(id=conn_id, \
                                pre_cell_id="../%s/%i/%s"%(prePop,preCellId,self.populations[prePop].component), \
                                pre_segment_id=preSegId, \
                                pre_fraction_along=preFract,
                                post_cell_id="../%s/%i/%s"%(postPop,postCellId,self.populations[postPop].component), \
                                post_segment_id=postSegId,
                                post_fraction_along=postFract,
                                weight=weight,
                                delay='%sms'%(delay*1000.0))

            self.projections[proj_id].connection_wds.append(connection)
Ejemplo n.º 4
0
def add_synapses(net,
                 conndata,
                 nrn_runname,
                 dCellIDs,
                 dNumCells,
                 write_synapse_file=False):
    '''
    Reads original data files: conndata_x.dat, connections.dat and synlist.dat (created by launch_synapse_printer.hoc)
    create synapse files (only .txt files TODO: automate to make .nml-files)
    calculates the place of synapses and connects the cells
    :param net: neuroml.Network() - to which the projections will be added
    :param conndata: string(int) - original connection data file (only for setting the weights of the synapses, other parameters are loaded from other files)
    :param nrn_runname: string - name of the directory where the saved data files are stored (synlist.dat, connections.dat) ! nrn_runname depends on conndata !
    :param dCellIDs - dictionary created by create_populations, which stroes the gid's
    :param dNumCells - dictionary created by create_populations, quick and dirty way to handle pyramidalcell -> [poolosyncell, cutsuridiscell] in conndata_x.dat and synlist.dat
    '''

    # read in synaptic weight (if weight is 0 don't create synapses)
    fConndata = "../../datasets/conndata_%s.dat" % conndata
    dSWeights = {}

    with open(fConndata) as file:
        next(file)  # skip header/first row: "99"
        for line in file:

            # handle pyramidalcell
            preCell = helper_pyramidalcell(line.split()[0], dNumCells)
            postCell = helper_pyramidalcell(line.split()[1], dNumCells)
            weight = float(line.split()[2]) * 1000  # nS

            if weight != 0.:
                id = "%s_to_%s" % (preCell, postCell)
                dSWeights[id] = weight

    file.close()

    # read in synapse types and IDs
    fSynapses = "../../results/%s/synlist.dat" % nrn_runname
    dSynapseIDs = {}

    # for automated synapse file generation ...
    # there will be a unique synapse for every poosible connection where the weight is not 0 (not all of them will be used in the network)
    exp2Synapses = ''
    customGABASynapses = ''
    synapse_types = []

    with open(fSynapses) as file:
        for line in file:

            # handle pyramidalcell
            preCell = helper_pyramidalcell(line.split()[1], dNumCells)
            postCell = helper_pyramidalcell(line.split()[0], dNumCells)
            tmp = "%s_to_%s" % (preCell, postCell)

            if tmp in dSWeights:  # only handle synapse if weight is != 0
                id = "syn_%s_to_%s" % (preCell, postCell)
                synapseID = "%s_%s" % (id, int(line.split()[2]))
                weight = dSWeights[tmp]

                tmp = line.split()[3]  # is like: cell_type[0].foo[x]
                postSegID = tmp[tmp.rfind('.') + 1:tmp.rfind('[')] + '_' + tmp[
                    tmp.rfind('[') + 1:tmp.rfind(']')]  # converts it to: foo_x

                if synapseID not in dSynapseIDs:
                    dSynapseIDs[synapseID] = postSegID

                    # write out synapses
                    tauRise = float(line.split()[5])
                    tauDecay = float(line.split()[6])
                    erev = float(line.split()[7])
                    syn = '\t<expTwoSynapse id="%s" gbase="%gnS" erev="%gmV" tauDecay="%gms" tauRise="%gms"/>\n\n' % (
                        id, weight, erev, tauDecay, tauRise)
                    if id not in synapse_types and line.split(
                    )[4] != "ExpGABAab":
                        exp2Synapses += syn
                        synapse_types.append(id)
                else:
                    tauRiseB = float(line.split()[5])
                    tauDecayB = float(line.split()[6])
                    erevB = float(line.split()[7])
                    synA = '\t<expTwoSynapse id="%s_A" gbase="%gnS" erev="%gmV" tauDecay="%gms" tauRise="%gms"/>\n' % (
                        id, weight, erev, tauDecay, tauRise)
                    synB = '\t<expTwoSynapse id="%s_B" gbase="%gnS" erev="%gmV" tauDecay="%gms" tauRise="%gms"/>\n\n' % (
                        id, weight / 3.37, erevB, tauDecayB, tauRiseB)
                    if id not in synapse_types:
                        customGABASynapses += (synA + synB)
                        synapse_types.append(id)

        if write_synapse_file:
            fExp2Synapses = open("../synapses/exp2Synapses.txt", 'w')
            fExp2Synapses.write(exp2Synapses)
            fExp2Synapses.close()
            fCustomGABASynapses = open("../synapses/customGABASynapses.txt",
                                       'w')
            fCustomGABASynapses.write(customGABASynapses)
            fCustomGABASynapses.close()

    file.close()

    # read in connections
    """
    Note: if you run the model (the NEURON one) on multiple processors with CatFlag==0,
    then the connections will be dispersed in one file per processor, named subconns_[processorID].dat.
    SimTracker can then merge the files together, but if you don't use SimTracker and are using multiple processors,
    try setting CatFlag==1 to have NEURON concatenate all the data into one connections.dat file)
    This code was based on test runs wth a single processor, so we are using subconns_0.dat
    """
    fConnections = "../../results/%s/subconns_0.dat" % nrn_runname  # TODO: fix this...(see above in docstring)
    dProjections = {}

    with open(fConnections) as file:
        # next(file)  # skip header: "source, target, synapse" <- only if useing connections.dat, created by SimTracker
        for line in file:

            preCellID = int(line.split()[0])
            preCell_type = dCellIDs[preCellID][0]
            preCellIDPop = dCellIDs[preCellID][1]
            postCellID = int(line.split()[1])
            postCell_type = dCellIDs[postCellID][0]
            postCellIDPop = dCellIDs[postCellID][1]
            synapseID = int(line.split()[2])
            postSegID = dSynapseIDs["syn_%s_to_%s_%g" %
                                    (preCell_type, postCell_type, synapseID)]

            connection = [preCellIDPop, postCellIDPop, postSegID]
            projID = "proj_%spop_to_%spop" % (preCell_type, postCell_type)

            if projID not in dProjections:
                dProjections[projID] = []
                dProjections[projID].append(connection)
            else:
                dProjections[projID].append(connection)

    file.close()

    # load cell morphologies (for segment and fractionAlong calculation for neuroml.Connections) - see morphology_helper.py
    cell_types = dNumCells.keys()
    dMorphs = {}
    for cell in cell_types:
        dMorphs[cell] = helper_morphology(
            "../cells/%s.cell.nml" % cell
        )  # will be a dictionary of dictionaries d[cell][segGroupID] = [[segIDs], [lSegs]]

    #####  add projections and connections to nml file #####

    for projID, connection_list in dProjections.iteritems():

        presynaptic = projID.split('_')[1][:-3]
        postsynaptic = projID.split('_')[-1][:-3]

        if presynaptic != "ngf":  # ngf cells are useing the boundled GABA_A, GABA_B syapse (ExpGABAab.mod)...
            proj = neuroml.Projection(
                id=projID,
                presynaptic_population="pop_%s" % presynaptic,
                postsynaptic_population="pop_%s" % postsynaptic,
                synapse="syn_%s_to_%s" % (presynaptic, postsynaptic))

            for i, sublist in enumerate(connection_list):

                preCellID = sublist[0]
                postCellID = sublist[1]
                postSegmentGroupID = sublist[2]
                if presynaptic not in ["ca3", "ec"]:
                    presynapticComp = "%scell" % presynaptic
                    preSegID, preFracAlong = calc_seg_fracalong(
                        dMorphs[presynaptic], "soma_0",
                        0.5)  # see morphology_helper.
                else:
                    presynapticComp = "spikeGenPoisson"  # TODO: implement other stimulations ...
                    preSegID = 0
                    preFracAlong = 0.5
                postSegID, postFracAlong = calc_seg_fracalong(
                    dMorphs[postsynaptic], postSegmentGroupID,
                    0.5)  # see morphology_helper.py

                conn = neuroml.ConnectionWD(
                    id=i,
                    pre_cell_id="../pop_%s/%g/%s" %
                    (presynaptic, preCellID, presynapticComp),
                    pre_segment_id=preSegID,
                    pre_fraction_along=preFracAlong,
                    post_cell_id="../pop_%s/%g/%scell" %
                    (postsynaptic, postCellID, postsynaptic),
                    post_segment_id=postSegID,
                    post_fraction_along=postFracAlong,
                    weight=
                    1,  # synaptic weights are specified at the synapse component level and are not scaled in the network
                    delay="3ms")
                proj.connection_wds.append(conn)

            net.projections.append(proj)

        else:  # TODO: check if only ngf is using ExpGABAab (with other ConnDat, SynData spec.)
            for sType in ['A', 'B']:
                proj = neuroml.Projection(
                    id="%s_%s" % (projID, sType),
                    presynaptic_population="pop_%s" % presynaptic,
                    postsynaptic_population="pop_%s" % postsynaptic,
                    synapse="syn_%s_to_%s_%s" %
                    (presynaptic, postsynaptic, sType))

                for i, sublist in enumerate(connection_list):

                    preCellID = sublist[0]
                    postCellID = sublist[1]
                    postSegmentGroupID = sublist[2]
                    presynapticComp = "ngfcell"
                    preSegID, preFracAlong = calc_seg_fracalong(
                        dMorphs["ngf"], "soma_0",
                        0.5)  # see morphology_helper.
                    postSegID, postFracAlong = calc_seg_fracalong(
                        dMorphs[postsynaptic], postSegmentGroupID,
                        0.5)  # see morphology_helper.py

                    conn = neuroml.ConnectionWD(
                        id=i,
                        pre_cell_id="../pop_ngf/%g/%s" %
                        (preCellID, presynapticComp),
                        pre_segment_id=preSegID,
                        pre_fraction_along=preFracAlong,
                        post_cell_id="../pop_%s/%g/%scell" %
                        (postsynaptic, postCellID, postsynaptic),
                        post_segment_id=postSegID,
                        post_fraction_along=postFracAlong,
                        weight=
                        1,  # synaptic weights are specified at the synapse component level and are not scaled in the network
                        delay="3ms")
                    proj.connection_wds.append(conn)

                net.projections.append(proj)
Ejemplo n.º 5
0
    def handle_connection(self, proj_id, conn_id, prePop, postPop, synapseType, \
                                                    preCellId, \
                                                    postCellId, \
                                                    preSegId = 0, \
                                                    preFract = 0.5, \
                                                    postSegId = 0, \
                                                    postFract = 0.5, \
                                                    delay=0,
                                                    weight=1):

        #self.printConnectionInformation(proj_id, conn_id, prePop, postPop, synapseType, preCellId, postCellId, weight)

        pre_cell_path = "../%s/%i/%s" % (prePop, preCellId,
                                         self.populations[prePop].component)
        if self.populations[prePop].type == None:
            pre_cell_path = "../%s[%i]" % (prePop, preCellId)

        post_cell_path = "../%s/%i/%s" % (postPop, postCellId,
                                          self.populations[postPop].component)
        if self.populations[postPop].type == None:
            post_cell_path = "../%s[%i]" % (postPop, postCellId)

        if isinstance(self.projections[proj_id], neuroml.ElectricalProjection):

            instances = False
            if len(self.populations[prePop].instances) > 0 or len(
                    self.populations[postPop].instances) > 0:
                instances = True

            if not instances:
                conn = neuroml.ElectricalConnection(id=conn_id, \
                                    pre_cell="%s"%(preCellId), \
                                    pre_segment=preSegId, \
                                    pre_fraction_along=preFract,
                                    post_cell="%s"%(postCellId), \
                                    post_segment=postSegId,
                                    post_fraction_along=postFract,
                                    synapse=self.projection_syns[proj_id])

                self.projections[proj_id].electrical_connections.append(conn)

            else:
                if weight == 1:
                    conn = neuroml.ElectricalConnectionInstance(id=conn_id, \
                                        pre_cell=pre_cell_path, \
                                        pre_segment=preSegId, \
                                        pre_fraction_along=preFract,
                                        post_cell=post_cell_path, \
                                        post_segment=postSegId,
                                        post_fraction_along=postFract,
                                        synapse=self.projection_syns[proj_id])

                    self.projections[
                        proj_id].electrical_connection_instances.append(conn)
                else:
                    conn = neuroml.ElectricalConnectionInstanceW(id=conn_id, \
                                        pre_cell=pre_cell_path, \
                                        pre_segment=preSegId, \
                                        pre_fraction_along=preFract,
                                        post_cell=post_cell_path, \
                                        post_segment=postSegId,
                                        post_fraction_along=postFract,
                                        synapse=self.projection_syns[proj_id],
                                        weight=weight)

                    self.projections[
                        proj_id].electrical_connection_instance_ws.append(conn)

        elif isinstance(self.projections[proj_id],
                        neuroml.ContinuousProjection):

            instances = False
            if len(self.populations[prePop].instances) > 0 or len(
                    self.populations[postPop].instances) > 0:
                instances = True

            if not instances:
                if weight != 1:
                    raise Exception(
                        "Case not (yet) supported: weight!=1 when not an instance based population..."
                    )

                conn = neuroml.ContinuousConnection(id=conn_id, \
                                    pre_cell="%s"%(preCellId), \
                                    pre_segment=preSegId, \
                                    pre_fraction_along=preFract,
                                    post_cell="%s"%(postCellId), \
                                    post_segment=postSegId,
                                    post_fraction_along=postFract,
                                    pre_component=self.projection_syns_pre[proj_id],
                                    post_component=self.projection_syns[proj_id])

                self.projections[proj_id].continuous_connections.append(conn)

            else:
                if weight == 1:
                    conn = neuroml.ContinuousConnectionInstance(id=conn_id, \
                                        pre_cell=pre_cell_path, \
                                        pre_segment=preSegId, \
                                        pre_fraction_along=preFract,
                                        post_cell=post_cell_path, \
                                        post_segment=postSegId,
                                        post_fraction_along=postFract,
                                        pre_component=self.projection_syns_pre[proj_id],
                                        post_component=self.projection_syns[proj_id])

                    self.projections[
                        proj_id].continuous_connection_instances.append(conn)
                else:
                    conn = neuroml.ContinuousConnectionInstanceW(id=conn_id, \
                                        pre_cell=pre_cell_path, \
                                        pre_segment=preSegId, \
                                        pre_fraction_along=preFract,
                                        post_cell=post_cell_path, \
                                        post_segment=postSegId,
                                        post_fraction_along=postFract,
                                        pre_component=self.projection_syns_pre[proj_id],
                                        post_component=self.projection_syns[proj_id],
                                        weight=weight)

                    self.projections[
                        proj_id].continuous_connection_instance_ws.append(conn)

        else:

            if not self.weightDelays[proj_id] and delay == 0 and weight == 1:

                connection = neuroml.Connection(id=conn_id, \
                                    pre_cell_id=pre_cell_path, \
                                    pre_segment_id=preSegId, \
                                    pre_fraction_along=preFract,
                                    post_cell_id=post_cell_path, \
                                    post_segment_id=postSegId,
                                    post_fraction_along=postFract)

                self.projections[proj_id].connections.append(connection)

            else:
                connection = neuroml.ConnectionWD(id=conn_id, \
                                    pre_cell_id=pre_cell_path, \
                                    pre_segment_id=preSegId, \
                                    pre_fraction_along=preFract,
                                    post_cell_id=post_cell_path, \
                                    post_segment_id=postSegId,
                                    post_fraction_along=postFract,
                                    weight=weight,
                                    delay='%sms'%(delay))

                self.projections[proj_id].connection_wds.append(connection)