def generateRandomMorphology():

    morphology = Morphology()


    p = Point3DWithDiam(x=0,y=0,z=0,diameter=soma_diam)
    d = Point3DWithDiam(x=soma_len,y=0,z=0,diameter=soma_diam)
    soma = Segment(proximal=p, distal=d, name = 'Soma', id = 0)

    morphology.segments.append(soma)
    parent_seg = soma

    for dend_id in range(0,dend_num):

        p = Point3DWithDiam(x=d.x,y=d.y,z=d.z,diameter=dend_diam)
        d = Point3DWithDiam(x=p.x,y=p.y+dend_len,z=p.z,diameter=dend_diam)
        dend = Segment(proximal=p, distal=d, name = 'Dend_%i'%dend_id, id = 1+dend_id)
        dend.parent = SegmentParent(segments=parent_seg.id)
        parent_seg = dend

        morphology.segments.append(dend)

    morphology.id = "TestMorphology"

    return morphology
Exemple #2
0
def generateRandomMorphology():

    morphology = Morphology()

    p = Point3DWithDiam(x=0, y=0, z=0, diameter=soma_diam)
    d = Point3DWithDiam(x=soma_len, y=0, z=0, diameter=soma_diam)
    soma = Segment(proximal=p, distal=d, name='Soma', id=0)

    morphology.segments.append(soma)
    parent_seg = soma

    for dend_id in range(0, dend_num):

        p = Point3DWithDiam(x=d.x, y=d.y, z=d.z, diameter=dend_diam)
        d = Point3DWithDiam(x=p.x, y=p.y + dend_len, z=p.z, diameter=dend_diam)
        dend = Segment(proximal=p,
                       distal=d,
                       name='Dend_%i' % dend_id,
                       id=1 + dend_id)
        dend.parent = SegmentParent(segments=parent_seg.id)
        parent_seg = dend

        morphology.segments.append(dend)

    morphology.id = "TestMorphology"

    return morphology
Exemple #3
0
    def test_proximal_coordinates(self):
        proximal_point = Point3DWithDiam(x=0.1, y=0.2, z=0.3)
        seg = Segment(proximal=proximal_point)

        self.assertEqual(seg.proximal.x, 0.1)
        self.assertEqual(seg.proximal.y, 0.2)
        self.assertEqual(seg.proximal.z, 0.3)
Exemple #4
0
    def test_length(self):
        d = Point3DWithDiam(x=0.2, y=2.4, z=3.5, diameter=0.6)
        p = Point3DWithDiam(x=0.5, y=2.0, z=1.8, diameter=0.9)

        seg = Segment(proximal=p, distal=d)

        self.assertAlmostEqual(seg.length, 1.772004514, places=7)
Exemple #5
0
    def test_area(self):
        d = Point3DWithDiam(x=0.2, y=2.4, z=3.5, diameter=0.6)
        p = Point3DWithDiam(x=0.5, y=2.0, z=1.8, diameter=0.9)

        seg = Segment(proximal=p, distal=d)

        self.assertAlmostEqual(seg.surface_area, 4.19011944, places=7)
Exemple #6
0
    def test_distal_coordinates(self):
        distal_point = Point3DWithDiam(x=0.1, y=0.2, z=0.3)
        seg = Segment(distal=distal_point)

        self.assertEqual(seg.distal.x, 0.1)
        self.assertEqual(seg.distal.y, 0.2)
        self.assertEqual(seg.distal.z, 0.3)
Exemple #7
0
    def test_area1(self):
        diam = 1.
        len = 1.
        d = Point3DWithDiam(x=0, y=0, z=0, diameter=diam)
        p = Point3DWithDiam(x=0, y=len, z=0, diameter=diam * 1.01)

        seg = Segment(proximal=p, distal=d)

        self.assertAlmostEqual(seg.surface_area, 3.15734008, places=7)
Exemple #8
0
    def test_volume1(self):

        diam = 1.
        len = 1.
        d = Point3DWithDiam(x=0, y=0, z=0, diameter=diam)
        p = Point3DWithDiam(x=0, y=len, z=0, diameter=diam * 1.01)
        seg = Segment(proximal=p, distal=d)

        self.assertAlmostEqual(seg.volume, 0.793278324, places=7)
def add_segment(obj, p0, p1, name=None):

    p = Point3DWithDiam(x=p0[0], y=p0[1], z=p0[2], diameter=p0[3])
    d = Point3DWithDiam(x=p1[0], y=p1[1], z=p1[2], diameter=p1[3])

    segid = len(obj.morphology.segments)

    parent = None if segid == 0 else SegmentParent(segments=segid - 1)

    segment = Segment(id=segid, proximal=p, distal=d, parent=parent)
    if name:
        segment.name = name

    obj.morphology.segment_groups[0].members.append(Member(segments=segid))

    obj.morphology.segments.append(segment)

    return segment
Exemple #10
0
    def test_length0(self):
        diam = 1.
        len = 1.
        d = Point3DWithDiam(x=0, y=0, z=0, diameter=diam)
        p = Point3DWithDiam(x=0, y=len, z=0, diameter=diam)

        seg = Segment(proximal=p, distal=d)

        self.assertAlmostEqual(seg.length, 1, places=7)
def createMorphoMlFile(fileName, cell):
    '''
    Convert to new neuroml structures and write
    '''

    if not muscle_dict.has_key(cell.name):
        neuroMlwriter = NeuroMlWriter(fileName, cell.name)
        neuroMlwriter.addCell(cell)
        neuroMlwriter.writeDocumentToFile()
        return

    #
    # Incomplete code to use the neuroml interface to write the file,
    # used for muscles, doesn't produce good enough result on neurons yet.
    #

    seg0 = cell.segments[0].position
    soma = Segment(proximal=cvt_pt(seg0.proximal_point),
                   distal=cvt_pt(seg0.distal_point))
    soma.name = 'Soma'
    soma.id = 0

    axon_segments = []
    for seg1 in cell.segments[1:]:

        parent = SegmentParent(segments=seg1.parent)
        if seg1.position.proximal_point is None:
            p = None
        else:
            p = cvt_pt(seg1.position.proximal_point)

        axon_segment = Segment(proximal=p,
                               distal=cvt_pt(seg1.position.distal_point),
                               parent=parent)
        axon_segment.id = seg1.id
        axon_segment.name = seg1.name
        axon_segments.append(axon_segment)

    morphology = Morphology()
    morphology.segments.append(soma)
    morphology.segments += axon_segments
    morphology.id = 'morphology_' + cell.name

    nml_cell = neuroml_Cell()
    nml_cell.id = cell.name
    nml_cell.morphology = morphology

    doc = NeuroMLDocument()
    doc.cells.append(nml_cell)
    #addCell(doc, cell)
    doc.id = "TestNeuroMLDocument"
    writers.NeuroMLWriter.write(doc, "Output/%s.nml" % fileName)
Exemple #12
0
    def test_area0(self):
        diam = 1.
        len = 1.
        d = Point3DWithDiam(x=0, y=0, z=0, diameter=diam)
        p = Point3DWithDiam(x=0, y=len, z=0, diameter=diam)

        seg = Segment(proximal=p, distal=d)

        self.assertAlmostEqual(seg.surface_area,
                               math.pi * diam * len,
                               places=7)
Exemple #13
0
    def test_volume0(self):

        diam = 1.
        len = 1.
        d = Point3DWithDiam(x=0, y=0, z=0, diameter=diam)
        p = Point3DWithDiam(x=0, y=len, z=0, diameter=diam)
        seg = Segment(proximal=p, distal=d)

        self.assertAlmostEqual(seg.volume,
                               math.pi * (diam / 2)**2 * len,
                               places=7)
def createMorphoMlFile(fileName, cell):
    '''
    Convert to new neuroml structures and write
    '''

    if not muscle_dict.has_key(cell.name):
        neuroMlwriter = NeuroMlWriter(fileName, cell.name)
        neuroMlwriter.addCell(cell)
        neuroMlwriter.writeDocumentToFile()
        return

    #
    # Incomplete code to use the neuroml interface to write the file,
    # used for muscles, doesn't produce good enough result on neurons yet.
    #

    seg0 = cell.segments[0].position
    soma = Segment(proximal=cvt_pt(seg0.proximal_point),
                   distal=cvt_pt(seg0.distal_point))
    soma.name = 'Soma'
    soma.id = 0


    axon_segments = []
    for seg1 in cell.segments[1:]:

        parent = SegmentParent(segments=seg1.parent)
        if seg1.position.proximal_point is None:
            p = None
        else:
            p = cvt_pt(seg1.position.proximal_point)

        axon_segment = Segment(proximal = p,
                               distal = cvt_pt(seg1.position.distal_point),
                               parent = parent)
        axon_segment.id = seg1.id
        axon_segment.name = seg1.name
        axon_segments.append(axon_segment)

    morphology = Morphology()
    morphology.segments.append(soma)
    morphology.segments += axon_segments
    morphology.id = 'morphology_' + cell.name

    nml_cell = neuroml_Cell()
    nml_cell.id = cell.name
    nml_cell.morphology = morphology

    doc = NeuroMLDocument()
    doc.cells.append(nml_cell)
    #addCell(doc, cell)
    doc.id = "TestNeuroMLDocument"
    writers.NeuroMLWriter.write(doc, "Output/%s.nml" % fileName)
def createMorphoMlFile(fileName, cell):
    '''
    Convert to new neuroml structures and write
    '''

    seg0 = cell.segments[0].position
    soma = Segment(proximal=cvt_pt(seg0.proximal_point),
                   distal=cvt_pt(seg0.distal_point))
    soma.name = 'Soma'
    soma.id = 0

    axon_segments = []
    for seg1 in cell.segments[1:]:

        parent = SegmentParent(segments=seg1.parent)
        if seg1.position.distal_point is None:
            p = None
        else:
            p = cvt_pt(seg1.position.distal_point)
        axon_segment = Segment(proximal=p,
                               distal=cvt_pt(seg1.position.distal_point),
                               parent=parent)
        axon_segment.id = seg1.id
        axon_segment.name = seg1.name
        axon_segments.append(axon_segment)

    morphology = Morphology()
    morphology.segments.append(soma)
    morphology.segments += axon_segments
    morphology.id = 'morphology_' + cell.name

    nml_cell = neuroml_Cell()
    nml_cell.id = cell.name
    nml_cell.morphology = morphology

    doc = NeuroMLDocument()
    #doc.name = "Test neuroML document"
    doc.cells.append(nml_cell)
    doc.id = fileName
    writers.NeuroMLWriter.write(doc, "Output/%s.nml" % fileName)
def createMorphoMlFile(fileName, cell):
    '''
    Convert to new neuroml structures and write
    '''

    seg0 = cell.segments[0].position
    soma = Segment(proximal=cvt_pt(seg0.proximal_point),
                   distal=cvt_pt(seg0.distal_point))
    soma.name = 'Soma'
    soma.id = 0

    axon_segments = []
    for seg1 in cell.segments[1:]:

        parent = SegmentParent(segments=seg1.parent)
        if seg1.position.distal_point is None:
            p = None
        else:
            p = cvt_pt(seg1.position.distal_point)
        axon_segment = Segment(proximal = p,
                               distal = cvt_pt(seg1.position.distal_point),
                               parent = parent)
        axon_segment.id = seg1.id
        axon_segment.name = seg1.name
        axon_segments.append(axon_segment)

    morphology = Morphology()
    morphology.segments.append(soma)
    morphology.segments += axon_segments
    morphology.id = 'morphology_' + cell.name

    nml_cell = neuroml_Cell()
    nml_cell.id = cell.name
    nml_cell.morphology = morphology

    doc = NeuroMLDocument()
    #doc.name = "Test neuroML document"
    doc.cells.append(nml_cell)
    doc.id = fileName
    writers.NeuroMLWriter.write(doc, "Output/%s.nml" % fileName)
Exemple #17
0
    def create_generic_neuron_cell(self):

        self.generic_neuron_cell = Cell(id="GenericNeuronCell")

        morphology = Morphology()
        morphology.id = "morphology_" + self.generic_neuron_cell.id

        self.generic_neuron_cell.morphology = morphology

        prox_point = Point3DWithDiam(
            x="0",
            y="0",
            z="0",
            diameter=self.get_bioparameter("cell_diameter").value)
        dist_point = Point3DWithDiam(
            x="0",
            y="0",
            z="0",
            diameter=self.get_bioparameter("cell_diameter").value)

        segment = Segment(id="0",
                          name="soma",
                          proximal=prox_point,
                          distal=dist_point)

        morphology.segments.append(segment)

        self.generic_neuron_cell.biophysical_properties = BiophysicalProperties(
            id="biophys_" + self.generic_neuron_cell.id)

        mp = MembraneProperties()
        self.generic_neuron_cell.biophysical_properties.membrane_properties = mp

        mp.init_memb_potentials.append(
            InitMembPotential(
                value=self.get_bioparameter("initial_memb_pot").value))

        mp.specific_capacitances.append(
            SpecificCapacitance(value=self.get_bioparameter(
                "neuron_specific_capacitance").value))

        mp.spike_threshes.append(
            SpikeThresh(
                value=self.get_bioparameter("neuron_spike_thresh").value))

        mp.channel_densities.append(
            ChannelDensity(cond_density=self.get_bioparameter(
                "neuron_leak_cond_density").value,
                           id="Leak_all",
                           ion_channel="Leak",
                           erev=self.get_bioparameter("leak_erev").value,
                           ion="non_specific"))

        mp.channel_densities.append(
            ChannelDensity(cond_density=self.get_bioparameter(
                "neuron_k_slow_cond_density").value,
                           id="k_slow_all",
                           ion_channel="k_slow",
                           erev=self.get_bioparameter("k_slow_erev").value,
                           ion="k"))
        '''
        mp.channel_densities.append(ChannelDensity(cond_density=self.get_bioparameter("neuron_k_fast_cond_density").value, 
                                                   id="k_fast_all", 
                                                   ion_channel="k_fast", 
                                                   erev=self.get_bioparameter("k_fast_erev").value,
                                                   ion="k"))'''

        mp.channel_densities.append(
            ChannelDensity(cond_density=self.get_bioparameter(
                "neuron_ca_simple_cond_density").value,
                           id="ca_simple_all",
                           ion_channel="ca_simple",
                           erev=self.get_bioparameter("ca_simple_erev").value,
                           ion="ca"))

        ip = IntracellularProperties()
        self.generic_neuron_cell.biophysical_properties.intracellular_properties = ip

        # NOTE: resistivity/axial resistance not used for single compartment cell models, so value irrelevant!
        ip.resistivities.append(Resistivity(value="0.1 kohm_cm"))

        # NOTE: Ca reversal potential not calculated by Nernst, so initial_ext_concentration value irrelevant!
        species = Species(id="ca",
                          ion="ca",
                          concentration_model="CaPool",
                          initial_concentration="0 mM",
                          initial_ext_concentration="2E-6 mol_per_cm3")

        ip.species.append(species)
    def create_models(self):

        self.generic_cell = Cell(id = "GenericCell")

        morphology = Morphology()
        morphology.id = "morphology_"+self.generic_cell.id

        self.generic_cell.morphology = morphology

        prox_point = Point3DWithDiam(x="0", y="0", z="0", diameter=self.get_bioparameter("cell_diameter").value)
        dist_point = Point3DWithDiam(x="0", y="0", z=self.get_bioparameter("cell_length").value, diameter=self.get_bioparameter("cell_diameter").value)

        segment = Segment(id="0",
                          name="soma",
                          proximal = prox_point, 
                          distal = dist_point)

        morphology.segments.append(segment)

        self.generic_cell.biophysical_properties = BiophysicalProperties(id="biophys_"+self.generic_cell.id)

        mp = MembraneProperties()
        self.generic_cell.biophysical_properties.membrane_properties = mp

        mp.init_memb_potentials.append(InitMembPotential(value=self.get_bioparameter("initial_memb_pot").value))

        mp.specific_capacitances.append(SpecificCapacitance(value=self.get_bioparameter("specific_capacitance").value))

        mp.spike_threshes.append(SpikeThresh(value=self.get_bioparameter("spike_thresh").value))

        mp.channel_densities.append(ChannelDensity(cond_density=self.get_bioparameter("leak_cond_density").value, 
                                                   id="Leak_all", 
                                                   ion_channel="Leak", 
                                                   erev=self.get_bioparameter("leak_erev").value,
                                                   ion="non_specific"))

        mp.channel_densities.append(ChannelDensity(cond_density=self.get_bioparameter("k_slow_cond_density").value, 
                                                   id="k_slow_all", 
                                                   ion_channel="k_slow", 
                                                   erev=self.get_bioparameter("k_slow_erev").value,
                                                   ion="k"))

        mp.channel_densities.append(ChannelDensity(cond_density=self.get_bioparameter("k_fast_cond_density").value, 
                                                   id="k_fast_all", 
                                                   ion_channel="k_fast", 
                                                   erev=self.get_bioparameter("k_fast_erev").value,
                                                   ion="k"))

        mp.channel_densities.append(ChannelDensity(cond_density=self.get_bioparameter("ca_boyle_cond_density").value, 
                                                   id="ca_boyle_all", 
                                                   ion_channel="ca_boyle", 
                                                   erev=self.get_bioparameter("ca_boyle_erev").value,
                                                   ion="ca"))

        ip = IntracellularProperties()
        self.generic_cell.biophysical_properties.intracellular_properties = ip

        # NOTE: resistivity/axial resistance not used for single compartment cell models, so value irrelevant!
        ip.resistivities.append(Resistivity(value="0.1 kohm_cm"))


        # NOTE: Ca reversal potential not calculated by Nernst, so initial_ext_concentration value irrelevant!
        species = Species(id="ca", 
                          ion="ca",
                          concentration_model="CaPool",
                          initial_concentration="0 mM",
                          initial_ext_concentration="2E-6 mol_per_cm3")

        ip.species.append(species)


        self.exc_syn = GradedSynapse(id="exc_syn",
                                conductance =        self.get_bioparameter("exc_syn_conductance").value,
                                delta =              self.get_bioparameter("exc_syn_delta").value,
                                Vth =                self.get_bioparameter("exc_syn_vth").value,
                                erev =               self.get_bioparameter("exc_syn_erev").value,
                                k =                  self.get_bioparameter("exc_syn_k").value)


        self.inh_syn = GradedSynapse(id="inh_syn",
                                conductance =        self.get_bioparameter("inh_syn_conductance").value,
                                delta =              self.get_bioparameter("inh_syn_delta").value,
                                Vth =                self.get_bioparameter("inh_syn_vth").value,
                                erev =               self.get_bioparameter("inh_syn_erev").value,
                                k =                  self.get_bioparameter("inh_syn_k").value)

        self.elec_syn = GapJunction(id="elec_syn",
                               conductance =    self.get_bioparameter("elec_syn_gbase").value)


        self.offset_current = PulseGenerator(id="offset_current",
                                delay=self.get_bioparameter("unphysiological_offset_current_del").value,
                                duration=self.get_bioparameter("unphysiological_offset_current_dur").value,
                                amplitude=self.get_bioparameter("unphysiological_offset_current").value)
Exemple #19
0
def neuroml_single_cell(skeleton_id, nodes, pre, post):
    """ Encapsulate a single skeleton into a NeuroML Cell instance.
        
        skeleton_id: the ID of the skeleton to which all nodes belong.
        nodes: a dictionary of node ID vs tuple of node parent ID, location as a tuple of 3 floats, and radius. In nanometers.
        pre: a dictionary of node ID vs list of connector ID
        post: a dictionary of node ID vs list of connector ID

        Returns a Cell with id=skeleton_id.
    """

    # Collect the children of every node
    successors = defaultdict(list) # parent node ID vs list of children node IDs
    rootID = None
    for nodeID, props in nodes.iteritems():
        parentID = props[0]
        if not parentID:
            rootID = nodeID
            continue
        successors[parentID].append(nodeID) 

    # Cache of Point3DWithDiam
    points = {}

    def asPoint(nodeID):
        """ Return the node as a Point3DWithDiam, in micrometers. """
        p = points.get(nodeID)
        if not p:
            props = nodes[nodeID]
            radius = props[2]
            if radius < 0:
                radius = 0.1 # FUTURE Will have to change
            loc = props[1]
            # Point in micrometers
            p = Point3DWithDiam(loc[0] / 1000.0, loc[1] / 1000.0, loc[2] / 1000.0, radius)
            points[nodeID] = p
        return p

    
    # Starting from the root node, iterate towards the end nodes, adding a segment
    # for each parent-child pair.

    segments = []
    segment_id = 1
    todo = [rootID]

    # VERY CONFUSINGLY, the Segment.parent is a SegmentParent with the same id as the parent Segment. An unseemly overheady way to reference the parent Segment.

    while todo:
        nodeID = todo.pop()
        children = successors[nodeID]
        if not children:
            continue
        p1 = asPoint(nodeID)
        parent = segments[-1] if segments else None
        segment_parent = SegmentParent(segments=parent.id) if parent else None
        for childID in children:
            p2 = asPoint(childID)
            segment_id += 1
            segment = Segment(proximal=p1, distal=p2, parent=segment_parent)
            segment.id = segment_id
            segment.name = "%s-%s" % (nodeID, childID)
            segments.append(segment)
            todo.append(childID)

    # Pack the segments into a Cell
    morphology = Morphology()
    morphology.segments.extend(segments)
    morphology.id = "Skeleton #%s" % skeleton_id

    # Synapses: TODO requires input from Padraig Gleeson

    cell = Cell()
    cell.name = 'Cell'
    cell.id = skeleton_id
    cell.morphology = morphology

    return cell
Exemple #20
0
def neuroml_single_cell(skeleton_id, nodes, pre, post):
    """ Encapsulate a single skeleton into a NeuroML Cell instance.
        
        skeleton_id: the ID of the skeleton to which all nodes belong.
        nodes: a dictionary of node ID vs tuple of node parent ID, location as a tuple of 3 floats, and radius. In nanometers.
        pre: a dictionary of node ID vs list of connector ID
        post: a dictionary of node ID vs list of connector ID

        Returns a Cell with id=skeleton_id.
    """

    # Collect the children of every node
    successors = defaultdict(
        list)  # parent node ID vs list of children node IDs
    rootID = None
    for nodeID, props in nodes.iteritems():
        parentID = props[0]
        if not parentID:
            rootID = nodeID
            continue
        successors[parentID].append(nodeID)

    # Cache of Point3DWithDiam
    points = {}

    def asPoint(nodeID):
        """ Return the node as a Point3DWithDiam, in micrometers. """
        p = points.get(nodeID)
        if not p:
            props = nodes[nodeID]
            radius = props[2]
            if radius < 0:
                radius = 0.1  # FUTURE Will have to change
            loc = props[1]
            # Point in micrometers
            p = Point3DWithDiam(loc[0] / 1000.0, loc[1] / 1000.0,
                                loc[2] / 1000.0, radius)
            points[nodeID] = p
        return p

    # Starting from the root node, iterate towards the end nodes, adding a segment
    # for each parent-child pair.

    segments = []
    segment_id = 1
    todo = [rootID]

    # VERY CONFUSINGLY, the Segment.parent is a SegmentParent with the same id as the parent Segment. An unseemly overheady way to reference the parent Segment.

    while todo:
        nodeID = todo.pop()
        children = successors[nodeID]
        if not children:
            continue
        p1 = asPoint(nodeID)
        parent = segments[-1] if segments else None
        segment_parent = SegmentParent(segments=parent.id) if parent else None
        for childID in children:
            p2 = asPoint(childID)
            segment_id += 1
            segment = Segment(proximal=p1, distal=p2, parent=segment_parent)
            segment.id = segment_id
            segment.name = "%s-%s" % (nodeID, childID)
            segments.append(segment)
            todo.append(childID)

    # Pack the segments into a Cell
    morphology = Morphology()
    morphology.segments.extend(segments)
    morphology.id = "Skeleton #%s" % skeleton_id

    # Synapses: TODO requires input from Padraig Gleeson

    cell = Cell()
    cell.name = 'Cell'
    cell.id = skeleton_id
    cell.morphology = morphology

    return cell
Exemple #21
0
def add_segment(cell,
                prox,
                dist,
                name=None,
                parent=None,
                fraction_along=1.0,
                group=None):
    # type: (Cell, List[float], List[float], str, SegmentParent, float, SegmentGroup) -> Segment
    """Add a segment to the cell.

    Convention: use axon_, soma_, dend_ prefixes for axon, soma, and dendrite
    segments respectivey. This will allow this function to add the correct
    neurolex IDs to the group.

    The created segment is also added to the default segment groups that were
    created by the `create_cell` function: "all", "dendrite_group",
    "soma_group", "axon_group" if the convention is followed.

    :param cell: cell to add segment to
    :type cell: Cell
    :param prox: proximal segment information
    :type prox: list with 4 float entries: [x, y, z, diameter]
    :param dist: dist segment information
    :type dist: list with 4 float entries: [x, y, z, diameter]
    :param name: name of segment
    :type name: str
    :param parent: parent segment
    :type parent: SegmentParent
    :param fraction_along: where the new segment is connected to the parent (0: distal point, 1: proximal point)
    :type fraction_along: float
    :param group: segment group to add the segment to
    :type group: SegmentGroup
    :returns: the created segment

    """
    try:
        if prox:
            p = Point3DWithDiam(x=prox[0],
                                y=prox[1],
                                z=prox[2],
                                diameter=prox[3])
        else:
            p = None
    except IndexError as e:
        print_function("{}: prox must be a list of 4 elements".format(e))
    try:
        d = Point3DWithDiam(x=dist[0], y=dist[1], z=dist[2], diameter=dist[3])
    except IndexError as e:
        print_function("{}: dist must be a list of 4 elements".format(e))

    segid = len(cell.morphology.segments)

    sp = SegmentParent(segments=parent.id,
                       fraction_along=fraction_along) if parent else None
    segment = Segment(id=segid, proximal=p, distal=d, parent=sp)

    if name:
        segment.name = name

    if group:
        seg_group = None
        seg_group = get_seg_group_by_id(group, cell)
        seg_group_all = get_seg_group_by_id("all", cell)
        seg_group_default = None
        neuro_lex_id = None

        if "axon_" in group:
            neuro_lex_id = neuro_lex_ids[
                "axon"]  # See http://amigo.geneontology.org/amigo/term/GO:0030424
            seg_group_default = get_seg_group_by_id("axon_group", cell)
        if "soma_" in group:
            neuro_lex_id = neuro_lex_ids["soma"]
            seg_group_default = get_seg_group_by_id("soma_group", cell)
        if "dend_" in group:
            neuro_lex_id = neuro_lex_ids["dend"]
            seg_group_default = get_seg_group_by_id("dendrite_group", cell)

        if seg_group is None:
            seg_group = SegmentGroup(id=group, neuro_lex_id=neuro_lex_id)
            cell.morphology.segment_groups.append(seg_group)

        seg_group.members.append(Member(segments=segment.id))
        # Ideally, these higher level segment groups should just include other
        # segment groups using Include, which would result in smaller NML
        # files. However, because these default segment groups are defined
        # first, they are printed in the NML file before the new segments and their
        # groups. The jnml validator does not like this.
        # TODO: clarify if the order of definition is important, or if the jnml
        # validator needs to be updated to manage this use case.
        if seg_group_default:
            seg_group_default.members.append(Member(segments=segment.id))

    seg_group_all.members.append(Member(segments=segment.id))

    cell.morphology.segments.append(segment)
    return segment
Exemple #22
0
def create_cell():
    """Create the cell.

    :returns: name of the cell nml file
    """
    # Create the nml file and add the ion channels
    hh_cell_doc = NeuroMLDocument(id="cell", notes="HH cell")
    hh_cell_fn = "HH_example_cell.nml"
    hh_cell_doc.includes.append(IncludeType(href=create_na_channel()))
    hh_cell_doc.includes.append(IncludeType(href=create_k_channel()))
    hh_cell_doc.includes.append(IncludeType(href=create_leak_channel()))

    # Define a cell
    hh_cell = Cell(id="hh_cell", notes="A single compartment HH cell")

    # Define its biophysical properties
    bio_prop = BiophysicalProperties(id="hh_b_prop")
    #  notes="Biophysical properties for HH cell")

    # Membrane properties are a type of biophysical properties
    mem_prop = MembraneProperties()
    # Add membrane properties to the biophysical properties
    bio_prop.membrane_properties = mem_prop

    # Append to cell
    hh_cell.biophysical_properties = bio_prop

    # Channel density for Na channel
    na_channel_density = ChannelDensity(id="na_channels", cond_density="120.0 mS_per_cm2", erev="50.0 mV", ion="na", ion_channel="na_channel")
    mem_prop.channel_densities.append(na_channel_density)

    # Channel density for k channel
    k_channel_density = ChannelDensity(id="k_channels", cond_density="360 S_per_m2", erev="-77mV", ion="k", ion_channel="k_channel")
    mem_prop.channel_densities.append(k_channel_density)

    # Leak channel
    leak_channel_density = ChannelDensity(id="leak_channels", cond_density="3.0 S_per_m2", erev="-54.3mV", ion="non_specific", ion_channel="leak_channel")
    mem_prop.channel_densities.append(leak_channel_density)

    # Other membrane properties
    mem_prop.spike_threshes.append(SpikeThresh(value="-20mV"))
    mem_prop.specific_capacitances.append(SpecificCapacitance(value="1.0 uF_per_cm2"))
    mem_prop.init_memb_potentials.append(InitMembPotential(value="-65mV"))

    intra_prop = IntracellularProperties()
    intra_prop.resistivities.append(Resistivity(value="0.03 kohm_cm"))

    # Add to biological properties
    bio_prop.intracellular_properties = intra_prop

    # Morphology
    morph = Morphology(id="hh_cell_morph")
    #  notes="Simple morphology for the HH cell")
    seg = Segment(id="0", name="soma", notes="Soma segment")
    # We want a diameter such that area is 1000 micro meter^2
    # surface area of a sphere is 4pi r^2 = 4pi diam^2
    diam = math.sqrt(1000 / math.pi)
    proximal = distal = Point3DWithDiam(x="0", y="0", z="0", diameter=str(diam))
    seg.proximal = proximal
    seg.distal = distal
    morph.segments.append(seg)
    hh_cell.morphology = morph

    hh_cell_doc.cells.append(hh_cell)
    pynml.write_neuroml2_file(nml2_doc=hh_cell_doc, nml2_file_name=hh_cell_fn, validate=True)
    return hh_cell_fn
Exemple #23
0
    def test_volume(self):
        d = Point3DWithDiam(x=0.2, y=2.4, z=3.5, diameter=0.6)
        p = Point3DWithDiam(x=0.5, y=2.0, z=1.8, diameter=0.9)
        seg = Segment(proximal=p, distal=d)

        self.assertAlmostEqual(seg.volume, 0.7932855820702964, places=7)
Exemple #24
0
    def test_proximal_diameter(self):
        proximal_point = Point3DWithDiam(diameter=3.21)
        seg = Segment(proximal=proximal_point)

        self.assertEqual(seg.proximal.diameter, 3.21)
Exemple #25
0
    def test_distal_diameter(self):
        distal_point = Point3DWithDiam(diameter=3.21)
        seg = Segment(distal=distal_point)

        self.assertEqual(seg.distal.diameter, 3.21)
Exemple #26
0
from collections import defaultdict
from neuron import h  # for debugging
import numpy as np
from neuroml import Morphology, Segment, Point3DWithDiam as P
from pyNN.morphology import NeuroMLMorphology, uniform, with_label, any
from pyNN.parameters import IonicSpecies
import pyNN.neuron as sim
from pyNN.neuron.nmodl import NMODLChannel

from PC_param import pc_param
from ion_channel_params import ion_channel_parameters

use_arraymorph = False

soma = Segment(proximal=P(x=0, y=0, z=0, diameter=29.8),
               distal=P(x=0, y=29.8, z=0, diameter=29.8),
               name="soma")

dendrites = []
with open("PC_dendnames.dlist") as fp:
    dendrite_section_names = [line.strip() for line in fp if len(line) > 1]
section_coordinates = np.genfromtxt("coordinate.csv")
section_connections = np.genfromtxt("connections.csv")
assert len(dendrite_section_names) == section_coordinates.shape[0]

if use_arraymorph:
    raise NotImplementedError("to do")
else:
    for dend_name, C in zip(dendrite_section_names, section_coordinates):
        dendrites.append(
            Segment(proximal=P(x=C[1], y=C[2], z=C[3], diameter=C[4]),