Beispiel #1
0
# soma
compartment_lengths[structure == 4] = diameter_soma / nof_segments_soma
# postsomatic region
compartment_lengths[structure == 5] = length_postsomatic_region
# total length neuron
length_neuron = sum(compartment_lengths)

##### compartment diameters
# initialize
compartment_diameters = np.zeros(nof_comps + 1) * um
# dendrite
compartment_diameters[0:start_index_soma] = diameter_dendrite
dendrite_outer_diameter = diameter_dendrite + nof_myelin_layers_dendrite * thicknes_myelin_layer * 2
# soma
soma_comp_diameters = calc.get_soma_diameters(nof_segments_soma,
                                              diameter_dendrite, diameter_soma,
                                              diameter_axon)
compartment_diameters[start_index_soma:end_index_soma +
                      2] = soma_comp_diameters
# axon
compartment_diameters[end_index_soma + 2:] = diameter_axon
axon_outer_diameter = diameter_axon + nof_myelin_layers_axon * thicknes_myelin_layer * 2

#####  Compartment middle point distances (needed for plots)
distance_comps_middle = np.zeros_like(compartment_lengths)
distance_comps_middle[0] = 0.5 * compartment_lengths[0]
for ii in range(0, nof_comps - 1):
    distance_comps_middle[
        ii +
        1] = 0.5 * compartment_lengths[ii] + 0.5 * compartment_lengths[ii + 1]
Beispiel #2
0
def set_up_model(dt, model, update=False):
    """This function calculates the stimulus current at the current source for
    a single monophasic pulse stimulus at each point of time

    Parameters
    ----------
    dt : time
        Sets the defaultclock.
    model : module
        Contains all morphologic and physiologic data of a model
                
    Returns
    -------
    neuron
        Gives back a brian2 neuron
    model
        Gives back the whole module
    """

    start_scope()

    ##### Update model parameters (should be done, if original parameters have been changed)
    if update:
        ##### rates for resting potential
        alpha_m_0 = 0.1 * 25 / (np.exp(25 / 10) - 1)
        beta_m_0 = 4
        alpha_h_0 = 0.07
        beta_h_0 = 1 / (np.exp(3) + 1)
        alpha_n_0 = 0.01 * 10 / (np.exp(1) - 1)
        beta_n_0 = 0.125

        ##### initial values for gating variables
        model.m_init = alpha_m_0 / (alpha_m_0 + beta_m_0)
        model.n_init = alpha_n_0 / (alpha_n_0 + beta_n_0)
        model.h_init = alpha_h_0 / (alpha_h_0 + beta_h_0)
        model.w_init = 1 / (np.exp(13 / 5) + 1)**(1 / 4)
        model.z_init = 1 / (2 * (np.exp(0.74) + 1)) + 0.5
        model.r_init = 1 / (np.exp(+62 / 35) + 1)

        ##### calculate Nerst potential for leakage current
        model.E_L = -(1 / model.g_L) * (
            model.g_Na * model.m_init**3 * model.h_init * model.E_Na +
            model.g_K * model.n_init**4 * model.E_K +
            model.g_KLT * model.w_init**4 * model.z_init * model.E_K +
            model.g_HCN * model.r_init * model.E_HCN)
        model.E_L_presomatic_region = -(1 / model.g_L) * (
            model.g_Na * model.m_init**3 * model.h_init * model.E_Na +
            model.g_K * model.n_init**4 * model.E_K +
            model.g_KLT_soma * model.w_init**4 * model.z_init * model.E_K +
            model.g_HCN_soma * model.r_init * model.E_HCN)
        model.E_L_soma = -(1 / model.g_L_soma) * (
            model.g_Na_soma * model.m_init**3 * model.h_init * model.E_Na +
            model.g_K_soma * model.n_init**4 * model.E_K +
            model.g_KLT_soma * model.w_init**4 * model.z_init * model.E_K +
            model.g_HCN_soma * model.r_init * model.E_HCN)

        ##### structure of ANF
        # terminal = 0
        # internode = 1
        # node = 2
        # presomatic region = 3
        # Soma = 4
        # postsomatic region = 5)
        model.structure = np.array([0] + list(np.tile([1,2],5)) + [1] + list(np.tile([3],model.nof_segments_presomatic_region)) + \
                             list(np.tile([4],model.nof_segments_soma)) + [5] + list(np.tile([1,2],model.nof_axonal_internodes-1)) + [1])
        ##### indexes presomatic region
        model.index_presomatic_region = np.argwhere(model.structure == 3)
        model.start_index_presomatic_region = int(
            model.index_presomatic_region[0])
        ##### indexes of soma
        model.index_soma = np.argwhere(model.structure == 4)
        model.start_index_soma = int(model.index_soma[0])
        model.end_index_soma = int(model.index_soma[-1])
        ##### further structural data
        model.nof_comps = len(model.structure)
        model.nof_comps_dendrite = len(
            model.structure[:model.start_index_soma])
        model.nof_comps_axon = len(model.structure[model.end_index_soma + 1:])

        ##### compartment lengths
        # initialize
        model.compartment_lengths = np.zeros_like(model.structure) * um
        # peripheral terminal
        model.compartment_lengths[np.where(
            model.structure == 0)] = model.length_peripheral_terminal
        # internodes dendrite
        model.compartment_lengths[0:model.start_index_soma][
            model.structure[0:model.start_index_soma] ==
            1] = model.length_internodes_dendrite
        # internodes axon
        model.compartment_lengths[model.end_index_soma + 1:][
            model.structure[model.end_index_soma +
                            1:] == 1] = model.length_internodes_axon
        # nodes dendrite
        model.compartment_lengths[0:model.start_index_soma][
            model.structure[0:model.start_index_soma] ==
            2] = model.length_nodes_dendrite
        # nodes axon
        model.compartment_lengths[model.end_index_soma + 1:][
            model.structure[model.end_index_soma +
                            1:] == 2] = model.length_nodes_axon
        # presomatic region
        model.compartment_lengths[
            model.structure ==
            3] = model.length_presomatic_region / model.nof_segments_presomatic_region
        # soma
        model.compartment_lengths[
            model.structure ==
            4] = model.diameter_soma / model.nof_segments_soma
        # postsomatic region
        model.compartment_lengths[model.structure ==
                                  5] = model.length_postsomatic_region
        # total length neuron
        model.length_neuron = sum(model.compartment_lengths)

        ##### compartment diameters
        # initialize
        model.compartment_diameters = np.zeros(model.nof_comps + 1) * um
        # dendrite
        model.compartment_diameters[0:model.
                                    start_index_soma] = model.diameter_dendrite
        # soma
        soma_comp_diameters = calc.get_soma_diameters(model.nof_segments_soma,
                                                      model.diameter_dendrite,
                                                      model.diameter_soma,
                                                      model.diameter_axon)
        model.compartment_diameters[model.
                                    start_index_soma:model.end_index_soma +
                                    2] = soma_comp_diameters
        # axon
        model.compartment_diameters[model.end_index_soma +
                                    2:] = model.diameter_axon

        #####  Compartment middle point distances (needed for plots)
        model.distance_comps_middle = np.zeros_like(model.compartment_lengths)
        model.distance_comps_middle[0] = 0.5 * model.compartment_lengths[0]
        for ii in range(0, model.nof_comps - 1):
            model.distance_comps_middle[
                ii + 1] = 0.5 * model.compartment_lengths[
                    ii] + 0.5 * model.compartment_lengths[ii + 1]

        ##### Capacities
        # initialize
        model.c_m = np.zeros_like(model.structure) * uF / cm**2
        # all but internodes
        model.c_m[np.where(model.structure != 1)] = model.c_m_layer
        # dendrite internodes
        model.c_m[0:model.start_index_soma][
            model.structure[0:model.start_index_soma] ==
            1] = model.c_m_layer / (1 + model.nof_myelin_layers_dendrite)
        # soma
        model.c_m[np.where(model.structure == 4)] = model.c_m_layer / (
            1 + model.nof_myelin_layers_soma)
        # axon internodes
        model.c_m[model.end_index_soma +
                  1:][model.structure[model.end_index_soma + 1:] ==
                      1] = model.c_m_layer / (1 + model.nof_myelin_layers_axon)

        ##### Condactivities internodes
        # initialize
        model.g_m = np.zeros_like(model.structure) * msiemens / cm**2
        # dendritic internodes
        model.g_m[0:model.start_index_soma][
            model.structure[0:model.start_index_soma] ==
            1] = model.g_m_layer / (1 + model.nof_myelin_layers_dendrite)
        # axonal internodes
        model.g_m[model.end_index_soma +
                  1:][model.structure[model.end_index_soma + 1:] ==
                      1] = model.g_m_layer / (1 + model.nof_myelin_layers_axon)

        ##### Axoplasmatic resistances
        model.compartment_center_diameters = np.zeros(model.nof_comps) * um
        model.compartment_center_diameters = (
            model.compartment_diameters[0:-1] +
            model.compartment_diameters[1:]) / 2
        model.R_a = (model.compartment_lengths * model.rho_in) / (
            (model.compartment_center_diameters * 0.5)**2 * np.pi)

        ##### Surface arias
        # lateral surfaces
        m = [
            np.sqrt(
                abs(model.compartment_diameters[i + 1] -
                    model.compartment_diameters[i])**2 +
                model.compartment_lengths[i]**2)
            for i in range(0, model.nof_comps)
        ]
        # total surfaces
        model.A_surface = [
            (model.compartment_diameters[i + 1] +
             model.compartment_diameters[i]) * np.pi * m[i] * 0.5
            for i in range(0, model.nof_comps)
        ]

        ##### Noise term
        model.g_Na_vector = np.zeros(model.nof_comps) * msiemens / cm**2
        model.g_Na_vector[:] = model.g_Na
        model.g_Na_vector[model.structure == 1] = 0 * msiemens / cm**2
        model.g_Na_vector[model.structure == 4] = model.g_Na_soma
        model.noise_term = np.sqrt(model.A_surface * model.g_Na_vector)

        ##### Compartments to plot
        # get indexes of all compartments that are not segmented
        model.indexes_comps = np.where(
            np.logical_or(
                np.logical_or(
                    np.logical_or(model.structure == 0, model.structure == 1),
                    model.structure == 2), model.structure == 5))
        # calculate middle compartments of presomatic region and soma
        model.middle_comp_presomatic_region = int(
            model.start_index_presomatic_region +
            np.floor((model.nof_segments_presomatic_region) / 2))
        model.middle_comp_soma = int(model.start_index_soma +
                                     np.floor((model.nof_segments_soma) / 2))
        # create array with all compartments to plot
        model.comps_to_plot = np.sort(
            np.append(
                model.indexes_comps,
                [model.middle_comp_presomatic_region, model.middle_comp_soma]))

    ##### initialize defaultclock
    defaultclock.dt = dt

    ##### define morphology
    morpho = Section(n=model.nof_comps,
                     length=model.compartment_lengths,
                     diameter=model.compartment_diameters)

    ##### define neuron
    neuron = SpatialNeuron(morphology=morpho,
                           model=model.eqs,
                           Cm=model.c_m,
                           Ri=model.rho_in,
                           method="exponential_euler")

    ##### initial values
    neuron.v = model.V_res
    neuron.m = model.m_init
    neuron.n = model.n_init
    neuron.h = model.h_init
    neuron.w = model.w_init
    neuron.z = model.z_init
    neuron.r = model.r_init

    ##### Set parameter values of differential equations
    # conductances active compartments
    neuron.g_Na = model.g_Na
    neuron.g_K = model.g_K
    neuron.g_KLT = model.g_KLT
    neuron.g_HCN = model.g_HCN
    neuron.g_L = model.g_L

    # conductances soma
    neuron.g_Na[model.index_soma] = model.g_Na_soma
    neuron.g_K[model.index_soma] = model.g_K_soma
    neuron.g_KLT[model.index_soma] = model.g_KLT_soma
    neuron.g_HCN[model.index_soma] = model.g_HCN_soma
    neuron.g_L[model.index_soma] = model.g_L_soma

    # conductances presomatic region
    neuron.g_KLT[model.index_presomatic_region] = model.g_KLT_somatic_region
    neuron.g_HCN[model.index_presomatic_region] = model.g_HCN_somatic_region

    # conductances internodes
    neuron.g_myelin = model.g_m
    neuron.g_Na[np.asarray(
        np.where(model.structure == 1))] = 0 * msiemens / cm**2
    neuron.g_K[np.asarray(
        np.where(model.structure == 1))] = 0 * msiemens / cm**2
    neuron.g_KLT[np.asarray(
        np.where(model.structure == 1))] = 0 * msiemens / cm**2
    neuron.g_HCN[np.asarray(
        np.where(model.structure == 1))] = 0 * msiemens / cm**2
    neuron.g_L[np.asarray(
        np.where(model.structure == 1))] = 0 * msiemens / cm**2

    # Nernst potential for leakage current
    neuron.E_Leak = model.E_L
    neuron.E_Leak[index_presomatic_region] = E_L_presomatic_region
    neuron.E_Leak[model.index_soma] = E_L_soma

    # other parameters
    neuron.T_celsius = model.T_celsius
    neuron.V_res = model.V_res
    neuron.E_Na = model.E_Na
    neuron.E_K = model.E_K
    neuron.E_HCN = model.E_HCN

    return neuron, model
Beispiel #3
0
def set_up_model(dt, model, update=False):
    """This function calculates the stimulus current at the current source for
    a single monophasic pulse stimulus at each point of time

    Parameters
    ----------
    dt : time
        Sets the defaultclock.
    model : module
        Contains all morphologic and physiologic data of a model
                
    Returns
    -------
    neuron
        Gives back a brian2 neuron
    model
        Gives back the whole module
    """

    start_scope()

    ##### Update model parameters (should be done, if original parameters have been changed)
    if update:
        ##### Temperature
        model.T_kelvin = model.zero_celsius + model.T_celsius * kelvin

        ##### Nernst potentials Smit
        # Nernst potential sodium
        model.E_Na_Smit = model.R * model.T_kelvin / model.F * np.log(
            model.Na_ratio) - model.V_res
        # Nernst potential potassium
        model.E_K_Smit = model.R * model.T_kelvin / model.F * np.log(
            model.K_ratio) - model.V_res

        ##### rates for resting potential
        alpha_m_Rat_0 = 0.1 * 25 / (np.exp(25 / 10) - 1)
        beta_m_Rat_0 = 4
        alpha_h_Rat_0 = 0.07
        beta_h_Rat_0 = 1 / (np.exp(3) + 1)
        alpha_n_Rat_0 = 0.01 * 10 / (np.exp(1) - 1)
        beta_n_Rat_0 = 0.125
        alpha_m_t_Smit_0 = 4.42 * 2.5 / (np.exp(2.5) -
                                         1) * 2.23**(0.1 *
                                                     (model.T_celsius - 20))
        alpha_m_p_Smit_0 = 2.06 * (2.5 - 0.1 * (-20)) / (
            1 * (np.exp(2.5 - 0.1 *
                        (-20))) - 1) * 1.99**(0.1 * (model.T_celsius - 20))
        alpha_n_Smit_0 = 0.2 * 1.0 / (10 * (np.exp(1) - 1)) * 1.5**(
            0.1 * (model.T_celsius - 20))
        alpha_h_Smit_0 = 1.47 * 0.07 * 1.5**(0.1 * (model.T_celsius - 20))
        beta_m_t_Smit_0 = 4.42 * 4.0 * 2.23**(0.1 * (model.T_celsius - 20))
        beta_m_p_Smit_0 = 2.06 * 4.0 * np.exp(
            20 / 18) * 1.99**(0.1 * (model.T_celsius - 20))
        beta_n_Smit_0 = 0.2 * 0.125 * 1 * 1.5**(0.1 * (model.T_celsius - 20))
        beta_h_Smit_0 = 1.47 / (1 +
                                np.exp(3.0)) * 1.5**(0.1 *
                                                     (model.T_celsius - 20))

        ##### initial values for gating variables
        model.m_init_Rat = alpha_m_Rat_0 / (alpha_m_Rat_0 + beta_m_Rat_0)
        model.n_init_Rat = alpha_n_Rat_0 / (alpha_n_Rat_0 + beta_n_Rat_0)
        model.h_init_Rat = alpha_h_Rat_0 / (alpha_h_Rat_0 + beta_h_Rat_0)
        model.m_t_init_Smit = alpha_m_t_Smit_0 / (alpha_m_t_Smit_0 +
                                                  beta_m_t_Smit_0)
        model.m_p_init_Smit = alpha_m_p_Smit_0 / (alpha_m_p_Smit_0 +
                                                  beta_m_p_Smit_0)
        model.n_init_Smit = alpha_n_Smit_0 / (alpha_n_Smit_0 + beta_n_Smit_0)
        model.h_init_Smit = alpha_h_Smit_0 / (alpha_h_Smit_0 + beta_h_Smit_0)

        ##### calculate Nerst potential for leakage current
        model.E_L_Rat = -(1 / model.g_L_Rat) * (
            model.g_Na_Rat * model.m_init_Rat**3 * model.h_init_Rat *
            model.E_Na_Rat +
            model.g_K_Rat * model.n_init_Rat**4 * model.E_K_Rat)
        model.E_L_Smit = -(1 / model.g_L_Smit) * (
            0.975 * model.g_Na_Smit * model.m_t_init_Smit**3 *
            model.h_init_Smit * model.E_Na_Smit + 0.025 * model.g_Na_Smit *
            model.m_p_init_Smit**3 * model.h_init_Smit * model.E_Na_Smit +
            model.g_K_Smit * model.n_init_Smit**4 * model.E_K_Smit)

        ##### structure of ANF
        # terminal = 0
        # internode = 1
        # node = 2
        # presomatic region = 3
        # Soma = 4
        # postsomatic region = 5)
        model.structure = np.array([0] + list(np.tile([1,2],4)) + [1] + list(np.tile([3],model.nof_segments_presomatic_region)) +\
                             list(np.tile([4],model.nof_segments_soma)) + [5] + list(np.tile([1,2],model.nof_axonal_internodes)) + [1])
        # indexes presomatic region
        model.index_presomatic_region = np.argwhere(model.structure == 3)
        model.start_index_presomatic_region = int(
            model.index_presomatic_region[0])
        # indexes of soma
        model.index_soma = np.argwhere(model.structure == 4)
        model.start_index_soma = int(model.index_soma[0])
        model.end_index_soma = int(model.index_soma[-1])
        # further structural data
        model.nof_comps = len(model.structure)
        model.nof_comps_dendrite = len(
            model.structure[:model.start_index_soma])
        model.nof_comps_axon = len(model.structure[model.end_index_soma + 1:])

        #####  Compartment lengths
        # initialize
        model.compartment_lengths = np.zeros_like(model.structure) * um
        # peripheral terminal
        model.compartment_lengths[np.where(
            model.structure == 0)] = model.length_peripheral_terminal
        # internodes dendrite
        model.compartment_lengths[0:model.start_index_soma][
            model.structure[0:model.start_index_soma] ==
            1] = model.length_internodes_dendrite
        # internodes axon
        model.compartment_lengths[model.end_index_soma + 1:][
            model.structure[model.end_index_soma +
                            1:] == 1] = model.length_internodes_axon
        # nodes dendrite
        model.compartment_lengths[0:model.start_index_soma][
            model.structure[0:model.start_index_soma] ==
            2] = model.length_nodes_dendrite
        # nodes axon
        model.compartment_lengths[model.end_index_soma + 1:][
            model.structure[model.end_index_soma +
                            1:] == 2] = model.length_nodes_axon
        # presomatic region
        model.compartment_lengths[np.where(
            model.structure == 3
        )] = model.length_presomatic_region / model.nof_segments_presomatic_region
        # soma
        model.compartment_lengths[np.where(
            model.structure ==
            4)] = model.diameter_soma / model.nof_segments_soma
        # postsomatic region
        model.compartment_lengths[np.where(
            model.structure == 5)] = model.length_postsomatic_region
        # total length neuron
        model.length_neuron = sum(model.compartment_lengths)

        ##### Compartment diameters
        # initialize
        model.compartment_diameters = np.zeros(model.nof_comps + 1) * um
        # dendrite
        model.compartment_diameters[0:model.
                                    start_index_soma] = model.diameter_dendrite
        # soma
        model.soma_comp_diameters = calc.get_soma_diameters(
            model.nof_segments_soma, model.diameter_dendrite,
            model.diameter_soma, model.diameter_axon)
        model.compartment_diameters[model.
                                    start_index_soma:model.end_index_soma +
                                    2] = model.soma_comp_diameters
        # axon
        model.compartment_diameters[model.end_index_soma +
                                    2:] = model.diameter_axon

        ##### number of axonal myelin layers
        model.nof_myelin_layers_axon = np.floor(
            0.5 * (model.axon_outer_diameter - model.diameter_axon) /
            model.myelin_layer_thicknes_axon)

        #####  Compartment middle point distances (needed for plots)
        model.distance_comps_middle = np.zeros_like(model.compartment_lengths)
        model.distance_comps_middle[0] = 0.5 * model.compartment_lengths[0]
        for ii in range(0, model.nof_comps - 1):
            model.distance_comps_middle[
                ii + 1] = 0.5 * model.compartment_lengths[
                    ii] + 0.5 * model.compartment_lengths[ii + 1]

        ##### Capacities
        # initialize
        model.c_m = np.zeros_like(model.structure) * uF / cm**2
        # all but internodes dendrite
        model.c_m[0:model.start_index_soma][
            model.structure[0:model.start_index_soma] != 1] = model.c_m_layer
        # dendritic internodes
        model.c_m[0:model.start_index_soma][
            model.structure[0:model.start_index_soma] ==
            1] = model.c_m_layer / (1 + model.nof_myelin_layers_dendrite)
        # soma
        model.c_m[np.where(model.structure == 4)] = model.c_m_layer / (
            1 + model.nof_myelin_layers_soma)
        # all but internodes axon
        model.c_m[model.end_index_soma +
                  1:][model.structure[model.end_index_soma +
                                      1:] != 1] = model.c_mem
        # axonal internodes
        model.c_m[model.end_index_soma +
                  1:][model.structure[model.end_index_soma + 1:] ==
                      1] = 1 / (1 / model.c_mem +
                                model.nof_myelin_layers_axon / model.c_my)

        ##### Condactivities internodes
        # initialize
        model.g_m = np.zeros_like(model.structure) * msiemens / cm**2
        # dendritic internodes
        model.g_m[0:model.start_index_soma][
            model.structure[0:model.start_index_soma] ==
            1] = model.g_m_layer / (1 + model.nof_myelin_layers_dendrite)
        # axonal internodes
        model.g_m[model.end_index_soma +
                  1:][model.structure[model.end_index_soma + 1:] == 1] = 1 / (
                      model.r_mem + model.nof_myelin_layers_axon * model.r_my)

        ##### Axoplasmatic resistances
        model.compartment_center_diameters = np.zeros(model.nof_comps) * um
        model.compartment_center_diameters = (
            model.compartment_diameters[0:-1] +
            model.compartment_diameters[1:]) / 2
        model.R_a = (model.compartment_lengths * model.rho_in) / (
            (model.compartment_center_diameters * 0.5)**2 * np.pi)

        ##### Surface arias
        # lateral surfaces
        m = [
            np.sqrt(
                abs(model.compartment_diameters[i + 1] -
                    model.compartment_diameters[i])**2 +
                model.compartment_lengths[i]**2)
            for i in range(0, model.nof_comps)
        ]
        # total surfaces
        model.A_surface = [
            (model.compartment_diameters[i + 1] +
             model.compartment_diameters[i]) * np.pi * m[i] * 0.5
            for i in range(0, model.nof_comps)
        ]

        ##### Noise term
        model.g_Na_vector = np.zeros(model.nof_comps) * msiemens / cm**2
        model.g_Na_vector[0:model.start_index_soma][
            model.structure[0:model.start_index_soma] != 1] = model.g_Na_Rat
        model.g_Na_vector[np.where(model.structure == 4)] = model.g_Na_soma
        model.g_Na_vector[model.end_index_soma +
                          1:][model.structure[model.end_index_soma +
                                              1:] != 1] = model.g_Na_Smit
        model.noise_term = np.sqrt(model.A_surface * model.g_Na_vector)

        ##### Compartments to plot
        # get indexes of all compartments that are not segmented
        model.indexes_comps = np.where(
            np.logical_or(
                np.logical_or(
                    np.logical_or(model.structure == 0, model.structure == 1),
                    model.structure == 2), model.structure == 5))
        # calculate middle compartments of presomatic region and soma
        model.middle_comp_presomatic_region = int(
            model.start_index_presomatic_region +
            np.floor((model.nof_segments_presomatic_region) / 2))
        model.middle_comp_soma = int(model.start_index_soma +
                                     np.floor((model.nof_segments_soma) / 2))
        # create array with all compartments to plot
        model.comps_to_plot = np.sort(
            np.append(
                model.indexes_comps,
                [model.middle_comp_presomatic_region, model.middle_comp_soma]))

    ##### initialize defaultclock
    defaultclock.dt = dt

    ##### define morphology
    morpho = Section(n=model.nof_comps,
                     length=model.compartment_lengths,
                     diameter=model.compartment_diameters)

    ##### define neuron
    neuron = SpatialNeuron(morphology=morpho,
                           model=model.eqs,
                           Cm=model.c_m,
                           Ri=model.rho_in,
                           method="exponential_euler")

    ##### initial values
    neuron.v = V_res
    neuron.m_t_Smit = model.m_t_init_Smit
    neuron.m_p_Smit = model.m_p_init_Smit
    neuron.n_Smit = model.n_init_Smit
    neuron.h_Smit = model.h_init_Smit
    neuron.m_Rat = model.m_init_Rat
    neuron.n_Rat = model.n_init_Rat
    neuron.h_Rat = model.h_init_Rat

    ##### Set parameter values of differential equations
    # conductances dentritic nodes and peripheral terminal
    neuron.g_Na_Rat[0:model.start_index_soma] = model.g_Na_Rat
    neuron.g_K_Rat[0:model.start_index_soma] = model.g_K_Rat
    neuron.g_L_Rat[0:model.start_index_soma] = model.g_L_Rat

    neuron.g_Na_Smit[0:model.start_index_soma] = 0 * msiemens / cm**2
    neuron.g_K_Smit[0:model.start_index_soma] = 0 * msiemens / cm**2
    neuron.g_L_Smit[0:model.start_index_soma] = 0 * msiemens / cm**2

    # conductances axonal nodes
    neuron.g_Na_Smit[model.end_index_soma + 1:] = model.g_Na_Smit
    neuron.g_K_Smit[model.end_index_soma + 1:] = model.g_K_Smit
    neuron.g_L_Smit[model.end_index_soma + 1:] = model.g_L_Smit

    neuron.g_Na_Rat[model.end_index_soma + 1:] = 0 * msiemens / cm**2
    neuron.g_K_Rat[model.end_index_soma + 1:] = 0 * msiemens / cm**2
    neuron.g_L_Rat[model.end_index_soma + 1:] = 0 * msiemens / cm**2

    # conductances soma
    neuron.g_Na_Rat[model.index_soma] = model.g_Na_soma
    neuron.g_K_Rat[model.index_soma] = model.g_K_soma
    neuron.g_L_Rat[model.index_soma] = model.g_L_soma

    neuron.g_Na_Smit[model.index_soma] = 0 * msiemens / cm**2
    neuron.g_K_Smit[model.index_soma] = 0 * msiemens / cm**2
    neuron.g_L_Smit[model.index_soma] = 0 * msiemens / cm**2

    # conductances internodes
    neuron.g_myelin = model.g_m

    neuron.g_Na_Rat[np.asarray(
        np.where(model.structure == 1))] = 0 * msiemens / cm**2
    neuron.g_K_Rat[np.asarray(
        np.where(model.structure == 1))] = 0 * msiemens / cm**2
    neuron.g_L_Rat[np.asarray(
        np.where(model.structure == 1))] = 0 * msiemens / cm**2

    neuron.g_Na_Smit[np.asarray(
        np.where(model.structure == 1))] = 0 * msiemens / cm**2
    neuron.g_K_Smit[np.asarray(
        np.where(model.structure == 1))] = 0 * msiemens / cm**2
    neuron.g_L_Smit[np.asarray(
        np.where(model.structure == 1))] = 0 * msiemens / cm**2

    # other parameters
    neuron.V_res = model.V_res
    neuron.E_Na_Smit = model.E_Na_Smit
    neuron.E_K_Smit = model.E_K_Smit
    neuron.E_L_Smit = model.E_L_Smit
    neuron.E_Na_Rat = model.E_Na_Rat
    neuron.E_K_Rat = model.E_K_Rat
    neuron.E_L_Rat = model.E_L_Rat
    neuron.T_celsius = model.T_celsius

    return neuron, model