External Stimuli not working

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
gladonias
Posts: 6
Joined: Thu Feb 28, 2019 5:24 am
Location: Waterford Institute of Technology

External Stimuli not working

Post by gladonias »

Hi,

I'm trying to stimulate a cell using NetStim/ExpSyn (I also tried with IClamp) and there's no response on the membrane potential. I've double-checked with the NEURON+Python Tutorial and with some of my older scripts that are working fine and I can't see what I'm missing. Would any of you be able to spot if I'm missing something or if I'm doing anything wrong? Any help is very much appreciated. Please, see my files below.

I have a model of a neuron as Python class:

Code: Select all

import neuron

class L5PyrNeuron2(object):
    """
        Model 2 of a L5 pyramidal neuron with a myelinated main axon.
    """
    def __init__(self):
        self.create_sections()
        self.build_topology()
        self.build_subsets()
        self.define_geometry()
        self.define_biophysics()

    def create_sections(self):
        # Create the somato-dendritic sections.
        self.soma = []
        self.dend = []
        self.apic = []
        # This section is related to the Axon Hillock and the Axon Initial Segment (AIS)
        self.ais = []
        # Create the proximal collateral sections.
        self.axon = []
        # Create the internodes.
        self.mainaxon = []
        # Create the nodes of Ranvier.
        self.node = []
        # Create the distal collateral sections
        self.coll = []
        # Define the number of nodes and internodes
        self.n_nodes = 600
        # Define the number of myelin wraps fixed in this model.
        self.wraps_number = 15
        # Define the division factor applied to the lengths of the internodes compared to the standard model, this factor can assume the values of 2 or 4.
        self.internodes_length_division_factor = 2
        # If 1, the soma is hyperpolarized during 200 ms before spike initiation.
        self.hyperpol = 0
        # If 1, the soma is depolarized during 10 s before spike initiation.
        self.depol = 0
        self.v_init = -70

        self.soma.append(neuron.h.Section(name = 'soma[0]', cell = self))

        for i in range(83):
            self.dend.append(neuron.h.Section(name = 'dend[{}]'.format(i), cell = self))

        for i in range(133):
            self.apic.append(neuron.h.Section(name = 'apic[{}]'.format(i), cell = self))
        
        self.ais.append(neuron.h.Section(name = 'ais[0]', cell = self))

        for i in range(self.n_nodes):
            self.mainaxon.append(neuron.h.Section(name = 'mainaxon[{}]'.format(i), cell = self))
        
        for i in range(self.n_nodes):
            self.node.append(neuron.h.Section(name = 'node[{}]'.format(i), cell = self))

        for i in range(89):
            self.axon.append(neuron.h.Section(name = 'axon[{}]'.format(i), cell = self))
        
        for i in range(4):
            self.coll.append(neuron.h.Section(name = 'coll[{}]'.format(i), cell = self))
    
    def build_topology(self):
        # Connect nodes and internodes
        for i in range(self.n_nodes - 1):
            self.node[i].connect(self.mainaxon[i](1))
            self.mainaxon[i+1].connect(self.node[i](1))
            # self.mainaxon[i](1).connect(self.node[i](0))
            # self.node[i](1).connect(self.mainaxon[i+1](0))
        self.node[self.n_nodes-1].connect(self.mainaxon[self.n_nodes-1](1))
        # self.mainaxon[self.n_nodes-1](1).connect(self.node[self.n_nodes-1](0))

        # Connect the soma to the AIS and the AIS to the first internode
        self.ais[0].connect(self.soma[0](0.5))
        self.mainaxon[0].connect(self.ais[0](1))

        # First collateral
        self.axon[0].connect(self.node[1](0.7))
        self.axon[1].connect(self.axon[0](1))
        self.axon[2].connect(self.axon[1](1))
        self.axon[3].connect(self.axon[2](1))
        self.axon[4].connect(self.axon[2](1))
        self.axon[5].connect(self.axon[1](1))
        self.axon[6].connect(self.axon[0](1))
        self.axon[7].connect(self.axon[6](1))
        self.axon[8].connect(self.axon[7](1))
        self.axon[9].connect(self.axon[7](1))
        self.axon[10].connect(self.axon[6](1))
        self.axon[11].connect(self.axon[10](1))
        self.axon[12].connect(self.axon[11](1))
        self.axon[13].connect(self.axon[12](1))
        self.axon[14].connect(self.axon[12](1))
        self.axon[15].connect(self.axon[11](1))
        self.axon[16].connect(self.axon[15](1))
        self.axon[17].connect(self.axon[16](1))
        self.axon[18].connect(self.axon[16](1))
        self.axon[19].connect(self.axon[15](1))
        self.axon[20].connect(self.axon[19](1))
        self.axon[21].connect(self.axon[19](1))
        self.axon[22].connect(self.axon[10](1))

        # Second collateral
        self.axon[23].connect(self.node[3](0.3))
        self.axon[24].connect(self.axon[23](1))
        self.axon[25].connect(self.axon[23](1))
        self.axon[26].connect(self.axon[25](1))
        self.axon[27].connect(self.axon[26](1))
        self.axon[28].connect(self.axon[26](1))
        self.axon[29].connect(self.axon[28](1))
        self.axon[30].connect(self.axon[28](1))
        self.axon[31].connect(self.axon[25](1))
        self.axon[32].connect(self.node[3](0.7))

        # Third collateral
        self.axon[33].connect(self.axon[32](1))
        self.axon[34].connect(self.axon[33](1))
        self.axon[35].connect(self.axon[33](1))
        self.axon[36].connect(self.axon[35](1))
        self.axon[37].connect(self.axon[35](1))
        self.axon[38].connect(self.axon[32](1))
        self.axon[39].connect(self.axon[38](1))
        self.axon[40].connect(self.axon[39](1))
        self.axon[41].connect(self.axon[39](1))
        self.axon[42].connect(self.axon[41](1))
        self.axon[43].connect(self.axon[41](1))
        self.axon[44].connect(self.axon[38](1))

        # Fourth collateral
        self.axon[45].connect(self.node[11](0.5))

        # Fifth collateral
        self.axon[46].connect(self.node[13](0.3))
        
        # Sixth collateral
        self.axon[47].connect(self.node[13](0.7))
        
        # Seventh collateral
        self.axon[48].connect(self.node[1](0.3))
        self.axon[49].connect(self.axon[48](1))
        self.axon[50].connect(self.axon[49](1))
        self.axon[51].connect(self.axon[50](1))
        self.axon[52].connect(self.axon[51](1))
        self.axon[53].connect(self.axon[52](1))
        self.axon[54].connect(self.axon[53](1))
        self.axon[55].connect(self.axon[54](1))
        self.axon[56].connect(self.axon[54](1))
        self.axon[57].connect(self.axon[56](1))
        self.axon[58].connect(self.axon[56](1))
        self.axon[59].connect(self.axon[53](1))
        self.axon[60].connect(self.axon[59](1))
        self.axon[61].connect(self.axon[59](1))
        self.axon[62].connect(self.axon[61](1))
        self.axon[63].connect(self.axon[61](1))
        self.axon[64].connect(self.axon[63](1))
        self.axon[65].connect(self.axon[63](1))
        self.axon[66].connect(self.axon[52](1))
        self.axon[67].connect(self.axon[51](1))
        self.axon[68].connect(self.axon[50](1))
        self.axon[69].connect(self.axon[68](1))
        self.axon[70].connect(self.axon[68](1))
        self.axon[71].connect(self.axon[49](1))
        self.axon[72].connect(self.axon[48](1))
        self.axon[73].connect(self.axon[72](1))
        self.axon[74].connect(self.axon[73](1))
        self.axon[75].connect(self.axon[74](1))
        self.axon[76].connect(self.axon[74](1))
        self.axon[77].connect(self.axon[73](1))
        self.axon[78].connect(self.axon[77](1))
        self.axon[79].connect(self.axon[78](1))
        self.axon[80].connect(self.axon[78](1))
        self.axon[81].connect(self.axon[80](1))
        self.axon[82].connect(self.axon[80](1))
        self.axon[83].connect(self.axon[77](1))
        self.axon[84].connect(self.axon[83](1))
        self.axon[85].connect(self.axon[83](1))
        self.axon[86].connect(self.axon[72](1))
        self.axon[87].connect(self.axon[86](1))
        self.axon[88].connect(self.axon[86](1))

        # Eighth, Ninth, Tenth and Eleventh collaterals (distal collaterals)
        for i in range(4):
            self.coll[i].connect(self.node[20 * i + 31](0.5))

        # Connect the dendritic tree
        self.dend[0].connect(self.soma[0](0.5))
        for i in range(1, 3):
            self.dend[i].connect(self.dend[i-1](1))
        self.dend[3].connect(self.dend[1](1))
        for i in range(4, 6):
            self.dend[i].connect(self.dend[3](1))
        for i in range(6, 8):
            self.dend[i].connect(self.dend[5](1))
        self.dend[8].connect(self.dend[0](1))
        for i in range(9, 11):
            self.dend[i].connect(self.dend[8](1))
        self.dend[11].connect(self.soma[0](0.5))
        for i in range(12, 16):
            self.dend[i].connect(self.dend[i-1](1))
        self.dend[16].connect(self.dend[14](1))
        self.dend[17].connect(self.dend[13](1))
        for i in range(18, 20):
            self.dend[i].connect(self.dend[i-1](1))
        self.dend[20].connect(self.dend[18](1))
        self.dend[21].connect(self.dend[17](1))
        self.dend[22].connect(self.dend[12](1))
        for i in range(23, 25):
            self.dend[i].connect(self.dend[i-1](1))
        self.dend[25].connect(self.dend[23](1))
        self.dend[26].connect(self.dend[22](1))
        self.dend[27].connect(self.dend[11](1))
        for i in range(28, 30):
            self.dend[i].connect(self.dend[27](1))
        self.dend[30].connect(self.soma[0](0.5))
        for i in range(31, 34):
            self.dend[i].connect(self.dend[i-1](1))
        self.dend[34].connect(self.dend[32](1))
        self.dend[35].connect(self.dend[31](1))
        for i in range(36, 38):
            self.dend[i].connect(self.dend[35](1))
        self.dend[38].connect(self.dend[30](1))
        for i in range(39, 41):
            self.dend[i].connect(self.dend[i-1](1))
        self.dend[41].connect(self.dend[39](1))
        self.dend[42].connect(self.dend[38](1))
        for i in range(43, 46):
            self.dend[i].connect(self.dend[i-1](1))
        self.dend[46].connect(self.dend[44](1))
        self.dend[47].connect(self.dend[43](1))
        self.dend[48].connect(self.dend[42](1))
        for i in range(49, 51):
            self.dend[i].connect(self.dend[48](1))
        self.dend[51].connect(self.soma[0](0.5))
        for i in range(52, 54):
            self.dend[i].connect(self.dend[i-1](1))
        self.dend[54].connect(self.dend[52](1))
        for i in range(55, 57):
            self.dend[i].connect(self.dend[54](1))
        for i in range(57, 59):
            self.dend[i].connect(self.dend[56](1))
        self.dend[59].connect(self.dend[51](1))
        for i in range(60, 62):
            self.dend[i].connect(self.dend[i-1](1))
        self.dend[62].connect(self.dend[60](1))
        self.dend[63].connect(self.dend[59](1))
        self.dend[64].connect(self.soma[0](0.5))
        for i in range(65, 67):
            self.dend[i].connect(self.dend[i-1](1))
        self.dend[67].connect(self.dend[65](1))
        for i in range(68, 70):
            self.dend[i].connect(self.dend[67](1))
        for i in range(70, 72):
            self.dend[i].connect(self.dend[69](1))
        self.dend[72].connect(self.dend[64](1))
        for i in range(73, 76):
            self.dend[i].connect(self.dend[i-1](1))
        self.dend[76].connect(self.dend[74](1))
        self.dend[77].connect(self.dend[73](1))
        for i in range(78, 80):
            self.dend[i].connect(self.dend[77](1))
        self.dend[80].connect(self.dend[72](1))
        for i in range(81, 83):
            self.dend[i].connect(self.dend[80](1))
        self.apic[0].connect(self.soma[0](0.5))
        for i in range(1, 4):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[4].connect(self.apic[2](1))
        self.apic[5].connect(self.apic[1](1))
        self.apic[6].connect(self.apic[0](1))
        for i in range(7, 9):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[9].connect(self.apic[7](1))
        self.apic[10].connect(self.apic[6](1))
        for i in range(11, 13):
            self.apic[i].connect(self.apic[10](1))
        for i in range(13, 15):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[15].connect(self.apic[13](1))
        self.apic[16].connect(self.apic[12](1))
        for i in range(17, 19):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[19].connect(self.apic[17](1))
        self.apic[20].connect(self.apic[16](1))
        for i in range(21, 23):
            self.apic[i].connect(self.apic[20](1))
        for i in range(23, 26):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[26].connect(self.apic[24](1))
        self.apic[27].connect(self.apic[23](1))
        self.apic[28].connect(self.apic[22](1))
        for i in range(29, 31):
            self.apic[i].connect(self.apic[28](1))
        for i in range(31, 33):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[33].connect(self.apic[31](1))
        for i in range(34, 36):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[36].connect(self.apic[34](1))
        self.apic[37].connect(self.apic[33](1))
        for i in range(38, 40):
            self.apic[i].connect(self.apic[37](1))
        for i in range(40, 45):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[45].connect(self.apic[43](1))
        self.apic[46].connect(self.apic[42](1))
        self.apic[47].connect(self.apic[41](1))
        for i in range(48, 50):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[50].connect(self.apic[48](1))
        self.apic[51].connect(self.apic[47](1))
        self.apic[52].connect(self.apic[40](1))
        for i in range(53, 56):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[56].connect(self.apic[54](1))
        self.apic[57].connect(self.apic[53](1))
        self.apic[58].connect(self.apic[52](1))
        for i in range(59, 62):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[62].connect(self.apic[60](1))
        self.apic[63].connect(self.apic[59](1))
        for i in range(64, 66):
            self.apic[i].connect(self.apic[63](1))
        for i in range(66, 68):
            self.apic[i].connect(self.apic[65](1))
        self.apic[68].connect(self.apic[58](1))
        for i in range(69, 71):
            self.apic[i].connect(self.apic[68](1))
        self.apic[71].connect(self.apic[39](1))
        for i in range(72, 74):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[74].connect(self.apic[72](1))
        for i in range(75, 77):
            self.apic[i].connect(self.apic[74](1))
        self.apic[77].connect(self.apic[71](1))
        for i in range(78, 80):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[80].connect(self.apic[78](1))
        for i in range(81, 83):
            self.apic[i].connect(self.apic[80](1))
        self.apic[83].connect(self.apic[77](1))
        for i in range(84, 86):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[86].connect(self.apic[84](1))
        for i in range(87, 89):
            self.apic[i].connect(self.apic[86](1))
        self.apic[89].connect(self.apic[83](1))
        for i in range(90, 92):
            self.apic[i].connect(self.apic[89](1))
        self.apic[92].connect(self.apic[30](1))
        for i in range(93, 95):
            self.apic[i].connect(self.apic[92](1))
        for i in range(95, 97):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[97].connect(self.apic[95](1))
        self.apic[98].connect(self.apic[94](1))
        for i in range(99, 101):
            self.apic[i].connect(self.apic[98](1))
        for i in range(101, 103):
            self.apic[i].connect(self.apic[100](1))
        for i in range(103, 105):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[105].connect(self.apic[103](1))
        for i in range(106, 108):
            self.apic[i].connect(self.apic[105](1))
        for i in range(108, 110):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[110].connect(self.apic[108](1))
        self.apic[111].connect(self.apic[107](1))
        self.apic[112].connect(self.apic[102](1))
        for i in range(113, 115):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[115].connect(self.apic[113](1))
        self.apic[116].connect(self.apic[112](1))
        for i in range(117, 120):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[120].connect(self.apic[118](1))
        for i in range(121, 123):
            self.apic[i].connect(self.apic[120](1))
        self.apic[123].connect(self.apic[117](1))
        for i in range(124, 126):
            self.apic[i].connect(self.apic[i-1](1))
        self.apic[126].connect(self.apic[124](1))
        self.apic[127].connect(self.apic[123](1))
        for i in range(128, 130):
            self.apic[i].connect(self.apic[127](1))
        self.apic[130].connect(self.apic[116](1))
        for i in range(131, 133):
            self.apic[i].connect(self.apic[130](1))
    
    def build_subsets(self):
        self.all = neuron.h.SectionList()
        self.all.wholetree(sec = self.soma[0])

    def define_geometry(self):
        for i in range(14, self.n_nodes - 1):
            self.mainaxon[i].L = 50
            self.mainaxon[i].diam = 1.14
        
        for i in range(self.n_nodes - 1):
            self.node[i].L = 1.5
            self.node[i].diam = 1.14
        
        for i in range(4):
            self.coll[i].L = 1000
            self.coll[i].diam = 0.23

        # Define the number of segments for each section
        for sec in self.all:
            sec.nseg = int(sec.L / 10) + 1
    
    def define_biophysics(self):
        # Somato-dendritic compartments
        for i in range(133):
            self.apic[i].cm = 1
            self.apic[i].Ra = 150
            self.apic[i].insert('pas')
            self.apic[i].g_pas = 0.0000333
            self.apic[i].e_pas = -69.5
            self.apic[i].insert('na12')
            self.apic[i].gbar_na12 = 80
            self.apic[i].insert('na16')
            self.apic[i].gbar_na16 = 0
            self.apic[i].ena = 60
            self.apic[i].insert('kv')
            self.apic[i].gbar_kv = 10
            self.apic[i].ek = -90
        
        for i in range(83):
            self.dend[i].cm = 1
            self.dend[i].Ra = 150
            self.dend[i].insert('pas')
            self.dend[i].g_pas = 0.0000333
            self.dend[i].e_pas = -69.5
            self.dend[i].insert('na12')
            self.dend[i].gbar_na12 = 80
            self.dend[i].insert('na16')
            self.dend[i].gbar_na16 = 0
            self.dend[i].ena = 60
            self.dend[i].insert('kv')
            self.dend[i].gbar_kv = 10
            self.dend[i].ek = -90
        
        for i in range(1):
            self.soma[i].cm = 1
            self.soma[i].Ra = 150
            self.soma[i].insert('pas')
            self.soma[i].g_pas = 0.0000333
            self.soma[i].e_pas = -69.5
            self.soma[i].insert('na12')
            self.soma[i].gbar_na12 = 80
            self.soma[i].insert('na16')
            self.soma[i].gbar_na16 = 0
            self.soma[i].ena = 60
            self.soma[i].insert('kv')
            self.soma[i].gbar_kv = 20
            self.soma[i].ek = -90
        
        # Proximal collaterals
        for i in range(89):
            self.axon[i].cm = 1
            self.axon[i].Ra = 150
            self.axon[i].insert('pas')
            self.axon[i].g_pas = 0.0000333
            self.axon[i].e_pas = -38.3
            self.axon[i].insert('na16')
            self.axon[i].gbar_na16 = 370
            self.axon[i].ena = 60
            self.axon[i].insert('capq')
            self.axon[i].gbar_capq = 0.0001
            self.axon[i].eca = 140
            self.axon[i].insert('kd')
            self.axon[i].gbar_kd = 0.00268
            self.axon[i].ek = -90
        
        # Distal collaterals
        for i in range(4):
            self.coll[i].cm = 1
            self.coll[i].Ra = 150
            self.coll[i].insert('pas')
            self.coll[i].g_pas = 0.0000333
            self.coll[i].e_pas = -38.3
            self.coll[i].insert('na16')
            self.coll[i].gbar_na16 = 370
            self.coll[i].ena = 60
            self.coll[i].insert('capq')
            self.coll[i].gbar_capq = 0.0001
            self.coll[i].eca = 140
            self.coll[i].insert('kd')
            self.coll[i].gbar_kd = 0.00268
            self.coll[i].ek = -90

        # Axonal hill and AIS.
        # This section is ~ 60µm-long and connected to the first internode.
        for i in range(1):
            self.ais[i].cm = 1
            self.ais[i].Ra = 150
            self.ais[i].insert('pas')
            self.ais[i].insert('na12')
            self.ais[i].insert('na16')
            self.ais[i].ena = 60
            self.ais[i].insert('kv')
            self.ais[i].insert('kd')
            self.ais[i].ek = -90

            self.ais[i](0.168).g_pas = 0.0000333
            self.ais[i](0.168).e_pas = -69.5
            self.ais[i](0.168).gbar_na12 = 2560
            self.ais[i](0.168).gbar_na16 = 0
            self.ais[i](0.168).gbar_kv = 100
            self.ais[i](0.168).gbar_kd = 0

            self.ais[i](0.252).g_pas = 0.0000333
            self.ais[i](0.252).e_pas = -69.5
            self.ais[i](0.252).gbar_na12 = 3072
            self.ais[i](0.252).gbar_na16 = 128
            self.ais[i](0.252).gbar_kv = 100
            self.ais[i](0.252).gbar_kd = 0

            self.ais[i](0.336).g_pas = 0.0000333
            self.ais[i](0.336).e_pas = -69.5
            self.ais[i](0.336).gbar_na12 = 2880
            self.ais[i](0.336).gbar_na16 = 320
            self.ais[i](0.336).gbar_kv = 100
            self.ais[i](0.336).gbar_kd = 0

            self.ais[i](0.42).g_pas = 0.0000333
            self.ais[i](0.42).e_pas = -69.5
            self.ais[i](0.42).gbar_na12 = 2400
            self.ais[i](0.42).gbar_na16 = 800
            self.ais[i](0.42).gbar_kv = 100
            self.ais[i](0.42).gbar_kd = 0

            self.ais[i](0.504).g_pas = 0.0000333
            self.ais[i](0.504).e_pas = -69.5
            self.ais[i](0.504).gbar_na12 = 1672
            self.ais[i](0.504).gbar_na16 = 1368
            self.ais[i](0.504).gbar_kv = 100
            self.ais[i](0.504).gbar_kd = 0

            self.ais[i](0.588).g_pas = 0.0000333
            self.ais[i](0.588).e_pas = -69.5
            self.ais[i](0.588).gbar_na12 = 1033.6
            self.ais[i](0.588).gbar_na16 = 1782.9
            self.ais[i](0.588).gbar_kv = 100
            self.ais[i](0.588).gbar_kd = 0

            self.ais[i](0.672).g_pas = 0.0000333
            self.ais[i](0.672).e_pas = -69.5
            self.ais[i](0.672).gbar_na12 = 480
            self.ais[i](0.672).gbar_na16 = 1920
            self.ais[i](0.672).gbar_kv = 100
            self.ais[i](0.672).gbar_kd = 0

            self.ais[i](0.756).g_pas = 0.0000333
            self.ais[i](0.756).e_pas = -69.5
            self.ais[i](0.756).gbar_na12 = 208
            self.ais[i](0.756).gbar_na16 = 1865.1
            self.ais[i](0.756).gbar_kv = 100
            self.ais[i](0.756).gbar_kd = 0

            self.ais[i](0.84).g_pas = 0.0000333
            self.ais[i](0.84).e_pas = -69.5
            self.ais[i](0.84).gbar_na12 = 19.2
            self.ais[i](0.84).gbar_na16 = 1645.7
            self.ais[i](0.84).gbar_kv = 100
            self.ais[i](0.84).gbar_kd = 0

            self.ais[i](0.924).g_pas = 0.0000333
            self.ais[i](0.924).e_pas = -69.5
            self.ais[i](0.924).gbar_na12 = 0
            self.ais[i](0.924).gbar_na16 = 1371.4
            self.ais[i](0.924).gbar_kv = 100
            self.ais[i](0.924).gbar_kd = 0

            self.ais[i](1).g_pas = 0.0000333
            self.ais[i](1).e_pas = -69.5
            self.ais[i](1).gbar_na12 = 0
            self.ais[i](1).gbar_na16 = 1397.1
            self.ais[i](1).gbar_kv = 100
            self.ais[i](1).gbar_kd = 0

        # Biophysics of internodes and nodes with half length internodes.
        for i in range(1, self.n_nodes - 1):
            self.mainaxon[i].cm = 1
            self.mainaxon[i].Ra = 150
            self.mainaxon[i].insert('pas')
            self.mainaxon[i].g_pas = 0.0000333
            self.mainaxon[i].e_pas = -38.3
            self.mainaxon[i].insert('extracellular')
            self.mainaxon[i].xraxial[0] = 120663
            self.mainaxon[i].xraxial[1] = 10000000000
            self.mainaxon[i].xg[0] = 0.0000333 / (self.wraps_number * 2)
            self.mainaxon[i].xg[1] = 0.0000333
            self.mainaxon[i].xc[0] = 1 / (self.wraps_number * 2)
            self.mainaxon[i].xc[1] = 0.0000000001
            self.mainaxon[i].e_extracellular = 0

            self.node[i].cm = 1
            self.node[i].Ra = 150
            self.node[i].insert('pas')
            self.node[i].g_pas = 0.0000333
            self.node[i].e_pas = -38.3
            self.node[i].insert('na16')
            self.node[i].gbar_na16 = 757.92
            self.node[i].ena = 60
            self.node[i].insert('kd')
            self.node[i].gbar_kd = 0.00536
            self.node[i].ek = -90
...I also built a similar simrun.py as the one available in the NEURON+Python tutorial, see my simrun file below:

Code: Select all

import neuron
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

plt.style.use('seaborn-deep')
plt.rcParams.update({'font.size': 12})

def set_recording_vectors(cell):
    # Membrane potential vector at the soma
    soma_v = neuron.h.Vector()
    # Membrane potential vector at the axon
    axon_v = neuron.h.Vector()
    # Time stamp vector
    t_vec = neuron.h.Vector()

    soma_v.record(cell.soma[0](0.5)._ref_v)
    axon_v.record(cell.axon[28](0.5)._ref_v)
    t_vec.record(neuron.h._ref_t)

    return t_vec, axon_v, soma_v

def simulate(tstop=25):
    neuron.h.tstop = tstop
    neuron.h.run()

def export_output(t_vec, axon_v, soma_v, new_fig=True, file_format='pdf', res=75):
    soma_plot = plt.plot(t_vec, soma_v, color='black')
    axon_plot = plt.plot(t_vec, axon_v, color='red', linestyle=':')
    plt.legend(soma_plot + axon_plot, ['Soma', 'Axon'])
    plt.ylabel('Membrane Potential (mV)')
    plt.xlabel('Time (ms)')
    plt.ylim(-80, 40)
    plt.margins(0, 0)
    plt.grid(which='both', axis='both', alpha=0.75, linestyle=':')
    plt.tight_layout()
    plt.savefig('result.pdf', format=file_format, dpi=res)
    plt.close()
...and I have a main.py file to initialize the simulation parameters, instantiate a cell, run the simulation, and export the behavior of the membrane potential.

Code: Select all

import neuron
import simrun

def init_simulation():
    """
        Initialise simulation environment.
    """
    neuron.h.load_file('stdrun.hoc')
	
    # Set temperature to 37 C and simulation time step to 0.025 ms
    print('Loading constants.')
    neuron.h.load_file('constants.hoc')

init_simulation()
cell = L5PyrNeuron2()

# Make a new simulator
stim = neuron.h.NetStim()

# Attach it to a synapse in the middle of the soma.
syn_ = neuron.h.ExpSyn(0.5, sec=cell.soma[0])
stim.number = 1
stim.start = 9
stim.noise = 0
ncstim = neuron.h.NetCon(stim, syn_)
ncstim.delay = 1
ncstim.weight[0] = 0.04
syn_.tau = 2

t_v_vec, axon_v_vec, soma_v_vec = simrun.set_recording_vectors(cell)

simrun.simulate()

simrun.export_output(t_v_vec, axon_v_vec, soma_v_vec)
Last but not least, here's what I get after the simulation is done:

Image
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: External Stimuli not working

Post by ted »

1. Is the model cell excitable? Attach an IClamp to the soma and apply a 1 ms current pulse that starts at t = 1 ms. Record and plot the current generated by the IClamp and v at the point of attachment. Adjust amplitude of the current pulse until a spike is elicited. Can't elicit a spike? Verify that the anatomical and biophysical properties of the model cell are correct, and that spatial and temporal discretization are appropriate.

2. Does the spike propagate down the axon? Figure out how to demonstrate that it does.

3. Set the amplitude of the current delivered by the IClamp to 0. Re-enable synaptic input. Activate the synapse at t = 1 ms. Record and plot the current generated by the synapse and v at the point of attachment. Adjust the synaptic input until a spike is elicited.


General comments: the code is reasonably pythonic, but not very "neuronic", and organization could be better. Let's start with organization; we can get to making the code more "neuronic" later.

You'll save yourself a lot of time and effort, and your code will be much easier to write, read, debug, and maintain, if it is modular. The best strategy for achieving modularity is to group statements and procedures by function. The four key functions achieved by user-written code, listed in the sequence in which a program should be organized, are

Model specification
Instrumentation
User interface
Simulation flow control


Model specification code specifies what biological properties are represented in a model, and how they are represented. It serves the following purposes:
  • defines cell classes
  • creates instances of these classes
  • specifies how these instances interact (e.g. by synaptic connections)
Instrumentation code specifies how the model is to be stimulated, and how its responses are to be monitored. Exmples include code that sets up
  • vector recording
  • signal sources, e.g. IClamps, SEClamps, maybe artificial spiking cells that activate synapses
User interface code specifies how the user can interact with the model. This may include:
  • setting up graphs that plot results on the fly
  • GUI controls for changing parameters, launching simulations, etc,
  • reading command line switches that affect model or simulation parameters
Simulation flow control code accomplishes these important tasks:
  • specification of key simulation parameters, e.g. dt, duration of simulation, integration method
  • code that implements experimental protocols such as changing an ionic concentration at a particular time in the course of a simulation; this is likely to be implemented with one or more FInitializeHandlers
  • model and simulator initialization (including, but not limited to, ensuring that model state variables have the desired values at the start of a simulation)
  • simulation execution--this is where NEURON's computational engine generates numerical solutions to the equations that describe the model
  • postprocessing, plotting or writing results to output files

It is a mistake to mix different kinds of code. It is especially bad to embed instrumentation, user interface, or simulation flow control code in a cell class definition.
Post Reply