1# -*- coding: utf-8 -*-
2#
3# gap_junctions_two_neurons.py
4#
5# This file is part of NEST.
6#
7# Copyright (C) 2004 The NEST Initiative
8#
9# NEST is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 2 of the License, or
12# (at your option) any later version.
13#
14# NEST is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with NEST.  If not, see <http://www.gnu.org/licenses/>.
21
22"""
23Gap Junctions: Two neuron example
24---------------------------------
25
26This script simulates two Hodgkin-Huxley neurons of type ``hh_psc_alpha_gap``
27connected by a gap junction. Both neurons receive a constant current of
28100.0 pA. The neurons are initialized with different membrane potentials and
29synchronize over time due to the gap-junction connection.
30
31"""
32
33import nest
34import matplotlib.pyplot as plt
35import numpy
36
37nest.ResetKernel()
38
39###############################################################################
40# First we set the resolution of the simulation, create two neurons and
41# create a ``voltmeter`` for recording.
42
43nest.resolution = 0.05
44
45neuron = nest.Create('hh_psc_alpha_gap', 2)
46
47vm = nest.Create('voltmeter', params={'interval': 0.1})
48
49###############################################################################
50# Then we set the constant current input, modify the inital membrane
51# potential of one of the neurons and connect the neurons to the ``voltmeter``.
52
53neuron.I_e = 100.
54neuron[0].V_m = -10.
55
56nest.Connect(vm, neuron, 'all_to_all')
57
58###############################################################################
59# In order to create the ``gap_junction`` connection we employ the
60# ``all_to_all`` connection rule: Gap junctions are bidirectional connections,
61# therefore we need to connect `neuron[0]` to `neuron[1]` and `neuron[1]` to
62# `neuron[0]`:
63
64nest.Connect(neuron, neuron,
65             {'rule': 'all_to_all', 'allow_autapses': False},
66             {'synapse_model': 'gap_junction', 'weight': 0.5})
67
68###############################################################################
69# Finally we start the simulation and plot the membrane potentials of both
70# neurons.
71
72nest.Simulate(351.)
73
74senders = vm.events['senders']
75times = vm.events['times']
76v_m_values = vm.events['V_m']
77
78plt.figure(1)
79plt.plot(times[numpy.where(senders == 1)], v_m_values[numpy.where(senders == 1)], 'r-')
80plt.plot(times[numpy.where(senders == 2)], v_m_values[numpy.where(senders == 2)], 'g-')
81plt.xlabel('time (ms)')
82plt.ylabel('membrane potential (mV)')
83plt.show()
84