.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/mc_neuron.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_mc_neuron.py: Multi-compartment neuron example -------------------------------- .. only:: html ---- Run this example as a Jupyter notebook: .. card:: :width: 25% :margin: 2 :text-align: center :link: https://lab.ebrains.eu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fnest%2Fnest-simulator-examples&urlpath=lab%2Ftree%2Fnest-simulator-examples%2Fnotebooks%2Fnotebooks%2Fmc_neuron.ipynb&branch=main :link-alt: JupyterHub service .. image:: https://nest-simulator.org/TryItOnEBRAINS.png .. grid:: 1 1 1 1 :padding: 0 0 2 0 .. grid-item:: :class: sd-text-muted :margin: 0 0 3 0 :padding: 0 0 3 0 :columns: 4 See :ref:`our guide ` for more information and troubleshooting. ---- Simple example of how to use the three-compartment ``iaf_cond_alpha_mc`` neuron model. Three stimulation paradigms are illustrated: - externally applied current, one compartment at a time - spikes impinging on each compartment, one at a time - rheobase current injected to soma causing output spikes Voltage and synaptic conductance traces are shown for all compartments. .. GENERATED FROM PYTHON SOURCE LINES 40-42 First, we import all necessary modules to simulate, analyze and plot this example. .. GENERATED FROM PYTHON SOURCE LINES 42-49 .. code-block:: Python import matplotlib.pyplot as plt import nest nest.ResetKernel() .. GENERATED FROM PYTHON SOURCE LINES 50-54 We then extract the receptor types and the list of recordable quantities from the neuron model. Receptor types and recordable quantities uniquely define the receptor type and the compartment while establishing synaptic connections or assigning multimeters. .. GENERATED FROM PYTHON SOURCE LINES 54-62 .. code-block:: Python syns = nest.GetDefaults("iaf_cond_alpha_mc")["receptor_types"] print(f"iaf_cond_alpha_mc receptor_types: {syns}") rqs = nest.GetDefaults("iaf_cond_alpha_mc")["recordables"] print(f"iaf_cond_alpha_mc recordables : {rqs}") .. GENERATED FROM PYTHON SOURCE LINES 63-64 The simulation parameters are assigned to variables. .. GENERATED FROM PYTHON SOURCE LINES 64-76 .. code-block:: Python params = { "V_th": -60.0, # threshold potential "V_reset": -65.0, # reset potential "t_ref": 10.0, # refractory period "g_sp": 5.0, # somato-proximal coupling conductance "soma": {"g_L": 12.0}, # somatic leak conductance # proximal excitatory and inhibitory synaptic time constants "proximal": {"tau_syn_ex": 1.0, "tau_syn_in": 5.0}, "distal": {"C_m": 90.0}, # distal capacitance } .. GENERATED FROM PYTHON SOURCE LINES 77-79 The nodes are created using ``Create``. We store the returned handles in variables for later reference. .. GENERATED FROM PYTHON SOURCE LINES 79-82 .. code-block:: Python n = nest.Create("iaf_cond_alpha_mc", params=params) .. GENERATED FROM PYTHON SOURCE LINES 83-86 A ``multimeter`` is created and connected to the neurons. The parameters specified for the multimeter include the list of quantities that should be recorded and the time interval at which quantities are measured. .. GENERATED FROM PYTHON SOURCE LINES 86-90 .. code-block:: Python mm = nest.Create("multimeter", params={"record_from": rqs, "interval": 0.1}) nest.Connect(mm, n) .. GENERATED FROM PYTHON SOURCE LINES 91-95 We create one current generator per compartment and configure a stimulus regime that drives distal, proximal and soma dendrites, in that order. Configuration of the current generator includes the definition of the start and stop times and the amplitude of the injected current. .. GENERATED FROM PYTHON SOURCE LINES 95-101 .. code-block:: Python cgs = nest.Create("dc_generator", 3) cgs[0].set(start=250.0, stop=300.0, amplitude=50.0) # soma cgs[1].set(start=150.0, stop=200.0, amplitude=-50.0) # proxim. cgs[2].set(start=50.0, stop=100.0, amplitude=100.0) # distal .. GENERATED FROM PYTHON SOURCE LINES 102-104 Generators are then connected to the correct compartments. Specification of the ``receptor_type`` uniquely defines the target compartment and receptor. .. GENERATED FROM PYTHON SOURCE LINES 104-109 .. code-block:: Python nest.Connect(cgs[0], n, syn_spec={"receptor_type": syns["soma_curr"]}) nest.Connect(cgs[1], n, syn_spec={"receptor_type": syns["proximal_curr"]}) nest.Connect(cgs[2], n, syn_spec={"receptor_type": syns["distal_curr"]}) .. GENERATED FROM PYTHON SOURCE LINES 110-113 We create one excitatory and one inhibitory spike generator per compartment and configure a regime that drives distal, proximal and soma dendrites, in that order, alternating the excitatory and inhibitory spike generators. .. GENERATED FROM PYTHON SOURCE LINES 113-122 .. code-block:: Python sgs = nest.Create("spike_generator", 6) sgs[0].spike_times = [600.0, 620.0] # soma excitatory sgs[1].spike_times = [610.0, 630.0] # soma inhibitory sgs[2].spike_times = [500.0, 520.0] # proximal excitatory sgs[3].spike_times = [510.0, 530.0] # proximal inhibitory sgs[4].spike_times = [400.0, 420.0] # distal excitatory sgs[5].spike_times = [410.0, 430.0] # distal inhibitory .. GENERATED FROM PYTHON SOURCE LINES 123-125 Connect generators to correct compartments in the same way as in case of current generator .. GENERATED FROM PYTHON SOURCE LINES 125-133 .. code-block:: Python nest.Connect(sgs[0], n, syn_spec={"receptor_type": syns["soma_exc"]}) nest.Connect(sgs[1], n, syn_spec={"receptor_type": syns["soma_inh"]}) nest.Connect(sgs[2], n, syn_spec={"receptor_type": syns["proximal_exc"]}) nest.Connect(sgs[3], n, syn_spec={"receptor_type": syns["proximal_inh"]}) nest.Connect(sgs[4], n, syn_spec={"receptor_type": syns["distal_exc"]}) nest.Connect(sgs[5], n, syn_spec={"receptor_type": syns["distal_inh"]}) .. GENERATED FROM PYTHON SOURCE LINES 134-135 Run the simulation for 700 ms. .. GENERATED FROM PYTHON SOURCE LINES 135-138 .. code-block:: Python nest.Simulate(700) .. GENERATED FROM PYTHON SOURCE LINES 139-140 Now we set the intrinsic current of soma to 150 pA to make the neuron spike. .. GENERATED FROM PYTHON SOURCE LINES 140-143 .. code-block:: Python n.soma = {"I_e": 150.0} .. GENERATED FROM PYTHON SOURCE LINES 144-146 We simulate the network for another 300 ms and retrieve recorded data from the multimeter .. GENERATED FROM PYTHON SOURCE LINES 146-150 .. code-block:: Python nest.Simulate(300) rec = mm.events .. GENERATED FROM PYTHON SOURCE LINES 151-153 We create an array with the time points when the quantities were actually recorded .. GENERATED FROM PYTHON SOURCE LINES 153-156 .. code-block:: Python t = rec["times"] .. GENERATED FROM PYTHON SOURCE LINES 157-160 We plot the time traces of the membrane potential and the state of each membrane potential for soma, proximal, and distal dendrites (`V_m.s`, `V_m.p` and `V_m.d`). .. GENERATED FROM PYTHON SOURCE LINES 160-169 .. code-block:: Python plt.figure() plt.subplot(211) plt.plot(t, rec["V_m.s"], t, rec["V_m.p"], t, rec["V_m.d"]) plt.legend(("Soma", "Proximal dendrite", "Distal dendrite"), loc="lower right") plt.axis([0, 1000, -76, -59]) plt.ylabel("Membrane potential [mV]") plt.title("Responses of iaf_cond_alpha_mc neuron") .. GENERATED FROM PYTHON SOURCE LINES 170-172 Finally, we plot the time traces of the synaptic conductance measured in each compartment. .. GENERATED FROM PYTHON SOURCE LINES 172-181 .. code-block:: Python plt.subplot(212) plt.plot(t, rec["g_ex.s"], "b-", t, rec["g_ex.p"], "g-", t, rec["g_ex.d"], "r-") plt.plot(t, rec["g_in.s"], "b--", t, rec["g_in.p"], "g--", t, rec["g_in.d"], "r--") plt.legend(("g_ex.s", "g_ex.p", "g_in.d", "g_in.s", "g_in.p", "g_in.d")) plt.axis([350, 700, 0, 1.15]) plt.xlabel("Time [ms]") plt.ylabel("Synaptic conductance [nS]") plt.show() .. _sphx_glr_download_auto_examples_mc_neuron.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: mc_neuron.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: mc_neuron.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_