Example #1
0
def exportToNML(cells):

    nml_net_file = "../NeuroML2/GranuleCells/Exported/GCnet%iG.net.nml" % len(cells)
    export_to_neuroml2(None,
                       nml_net_file,
                       includeBiophysicalProperties=False,
                       separateCellFiles=True)

    # Rename files so their cell GIDs are preserved
    for gcid in cells.keys():
        fileId = cells[gcid]['index']
        oldFile = '../NeuroML2/GranuleCells/Exported/Granule_0_%i.cell.nml' % fileId
        newFile = '../NeuroML2/GranuleCells/Exported/Granule_0_%i.cell.nml_TEMP' % gcid

        # Using TEMP files to avoid naming conflicts
        os.rename(oldFile, newFile)

    # Remove temp files after all have been renamed
    for gcid in cells.keys():
        oldFile = '../NeuroML2/GranuleCells/Exported/Granule_0_%i.cell.nml_TEMP' % gcid
        newFile = '../NeuroML2/GranuleCells/Exported/Granule_0_%i.cell.nml' % gcid
        os.rename(oldFile, newFile)


    for gcid in cells.keys():

        cell, nml_doc, nml_cell_file = readGCnml(gcid)
        
        print("Loaded GC cell %i with %i segments"%(gcid, len(cell.morphology.segments)))

        # Change cell ID to preserve GCID
        cell.id = "Granule_0_%i" % gcid

        # Change segment ids to start at 0 and increment
        exportHelper.resetRoot(cell)

        # Replace ModelViewParmSubset_N groups with all, axon, soma, dendrite groups
        buildStandardSegmentGroups(cell)

        # Add channel placeholders
        nml_doc.includes.append(neuroml.IncludeType(href="channelIncludesPLACEHOLDER"))
        cell.biophysical_properties = neuroml.BiophysicalProperties(id="biophysPLACEHOLDER")
        cell.morphology.segments.append(neuroml.Segment(id="spinePLACEHOLDER"))

        # Save the new NML
        pynml.write_neuroml2_file(nml_doc, nml_cell_file)


        # Replace placeholders with contents from GranuleCell...xml files
        replaceChannelPlaceholders(nml_cell_file)

        cell, nml_doc, nml_cell_file = readGCnml(gcid)

        # Fix the fractionAlong parent segment bug ( https://github.com/NeuroML/org.neuroml.export/issues/46 )
        exportHelper.splitSegmentAlongFraction(cell, "Seg0_priden", "priden", 0.8, "Seg0_priden2_0")

        # Orient cell along the versor
        versor = granules.granule_position_orientation(gcid)[1]

        for seg in cell.morphology.segments:
            segLength = seg.length

            if seg.parent is not None:
                parentDistal = [parent for parent in cell.morphology.segments if parent.id == seg.parent.segments][0].distal
                seg.proximal.x = parentDistal.x
                seg.proximal.y = parentDistal.y
                seg.proximal.z = parentDistal.z

            seg.distal = setAlongVersor(seg.distal, versor, seg.proximal, segLength)

        # Make sure spine is in the all group
        [group for group in cell.morphology.segment_groups if group.id == 'all'][0]\
            .includes\
            .append(neuroml.Include(segment_groups='spine_group'))\

        # and Dendrite group
        [group for group in cell.morphology.segment_groups if group.id == 'dendrite_group'][0]\
            .includes\
            .append(neuroml.Include(segment_groups='spine_group'))

        # Save orientation
        pynml.write_neuroml2_file(nml_doc, nml_cell_file)

        print(nml_cell_file)
Example #2
0
def export(num_cells_to_export=5):
    cells = []

    for mgid in range(num_cells_to_export):
        print mgid
        cells.append(mkmitral(mgid))

    nml_net_file = "../NeuroML2/MitralCells/Exported/PartialBulb_%iMTCells.net.nml" % num_cells_to_export
    export_to_neuroml2(None,
                       nml_net_file,
                       includeBiophysicalProperties=False,
                       separateCellFiles=True)

    for i in range(num_cells_to_export):
        print("Processing cell %i out of %i" % (i, num_cells_to_export))
        nml_cell_file = "../NeuroML2/MitralCells/Exported/Mitral_0_%i.cell.nml" % i
        nml_doc = pynml.read_neuroml2_file(nml_cell_file)
        cell = nml_doc.cells[0]

        soma_seg = next(seg for seg in cell.morphology.segments
                        if seg.name == "Seg0_soma")
        initial_seg = next(seg for seg in cell.morphology.segments
                           if seg.name == "Seg0_initialseg")
        hillock_seg = next(seg for seg in cell.morphology.segments
                           if seg.name == "Seg0_hillock")

        # Ensure hillock parent is soma
        hillock_seg.parent.segments = soma_seg.id

        # Fix initial and hillock segs by moving them to the soma
        hillock_seg.proximal = pointMovedByOffset(hillock_seg.proximal,
                                                  soma_seg.distal)
        hillock_seg.distal = pointMovedByOffset(hillock_seg.distal,
                                                soma_seg.distal)
        initial_seg.proximal = pointMovedByOffset(initial_seg.proximal,
                                                  soma_seg.distal)
        initial_seg.distal = pointMovedByOffset(initial_seg.distal,
                                                soma_seg.distal)

        # Set root to id=0 and increment others
        exportHelper.resetRoot(cell)

        # TODO: cell.position(x,y,z) used for cell positioning in networks does not work as expected
        # See: https://github.com/NeuroML/jNeuroML/issues/55
        # Skipping the translation for now
        # # Move everything back to the origin
        # originOffset = type("", (), dict(x = -soma_seg.proximal.x, y = -soma_seg.proximal.y, z = -soma_seg.proximal.z ))()
        #
        # for seg in cell.morphology.segments:
        #     seg.proximal = pointMovedByOffset(seg.proximal, originOffset)
        #     seg.distal =   pointMovedByOffset(seg.distal, originOffset)

        # Replace ModelViewParmSubset_N groups with all, axon, soma, dendrite groups
        buildStandardSegmentGroups(cell)

        # Add channel placeholders
        nml_doc.includes.append(
            neuroml.IncludeType(href="channelIncludesPLACEHOLDER"))
        cell.biophysical_properties = neuroml.BiophysicalProperties(
            id="biophysPLACEHOLDER")

        # Save the new NML
        pynml.write_neuroml2_file(nml_doc, nml_cell_file)

        # Replace placeholders with contents from MitralCell...xml files
        replaceChannelPlaceholders(nml_cell_file)

        print("COMPLETED: " + nml_cell_file)

    print("DONE")
Example #3
0
def __main__():
    num_cells_to_export = 1

    cells = []
    for mgid in range(num_cells_to_export):
      print mgid
      cells.append(mkmitral(mgid))

    nml_net_file = "../NeuroML2/MitralCells/Exported/PartialBulb_%iMTCells.net.nml" % num_cells_to_export
    export_to_neuroml2(None, 
                       nml_net_file,
                       includeBiophysicalProperties=False,
                       separateCellFiles=True)

    for i in range(num_cells_to_export):

        print("Processing cell %i out of %i"%(i, num_cells_to_export))

        nml_cell_file = "../NeuroML2/MitralCells/Exported/Mitral_0_%i.cell.nml" % i

        nml_doc = pynml.read_neuroml2_file(nml_cell_file)

        cell = nml_doc.cells[0]

        import pydevd
        pydevd.settrace('10.211.55.3', port=4200, stdoutToServer=True, stderrToServer=True, suspend=True)
        
        # Set root to id=0 and increment others
        exportHelper.resetRoot(cell)

        somaSeg = [seg for seg in cell.morphology.segments if seg.name == "Seg0_soma"][0]
        initialSeg = [seg for seg in cell.morphology.segments if seg.name == "Seg0_initialseg"][0]
        hillockSeg = [seg for seg in cell.morphology.segments if seg.name == "Seg0_hillock"][0]

        # Fix initial and hillock segs by moving them to the soma
        hillockSeg.proximal = pointMovedByOffset(hillockSeg.proximal, somaSeg.distal)
        hillockSeg.distal = pointMovedByOffset(hillockSeg.distal, somaSeg.distal)
        initialSeg.proximal = pointMovedByOffset(initialSeg.proximal, somaSeg.distal)
        initialSeg.distal = pointMovedByOffset(initialSeg.distal, somaSeg.distal)

        # Move everything back to the origin
        originOffset = type("", (), dict(x = -somaSeg.proximal.x, y = -somaSeg.proximal.y, z = -somaSeg.proximal.z ))()

        for seg in cell.morphology.segments:
            seg.proximal = pointMovedByOffset(seg.proximal, originOffset)
            seg.distal =   pointMovedByOffset(seg.distal, originOffset)

        # Replace ModelViewParmSubset_N groups with all, axon, soma, dendrite groups
        buildStandardSegmentGroups(cell)

        # Add channel placeholders
        nml_doc.includes.append(neuroml.IncludeType(href="channelIncludesPLACEHOLDER"))
        cell.biophysical_properties = neuroml.BiophysicalProperties(id="biophysPLACEHOLDER")

        # Save the new NML
        pynml.write_neuroml2_file(nml_doc, nml_cell_file)

        # Replace placeholders with contents from MitralCell...xml files
        replaceChannelPlaceholders(nml_cell_file)

        print("COMPLETED: " + nml_cell_file)

    print("DONE")