/*
 *  tsodyks_facilitating.sli
 *
 *  This file is part of NEST.
 *
 *  Copyright (C) 2004 The NEST Initiative
 *
 *  NEST is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  NEST is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with NEST.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

 /* BeginDocumentation
Name: test_iaf - sli script for overall test of iaf_neuron model

Synopsis: (test_iaf) run -> compare cout with comments in file


Description:
Script to test Tsodyks short term plasticity depressing synapses according to
'Neural Networks with Dynamic Synapses'
Misha Tsodyks, Klaus Pawelzik, Henry Markram
Neural computation 10, 821--853 (1998)

reproduces figure 1 B,(C)


author:  Markus Diesmann, Moritz Helias
date:    March 2006

*/


ResetKernel      % clear all existing network elements


userdict begin

      1 /local_num_threads Set
      8 /total_num_virtual_procs Set
      0.1 /h Set

      /Tau 60.0 def          % membrane time constant
      /Theta 15.0 def        % threshold
      /U0 0.0 def            % reset potential of Vm
      /R 1.0 def             % mambrane resistance in GOhm
      /C Tau R div def       % Tau [ms] / 1.0 GOhm in NEST units
      /TauR 2.0 def          % refractory time
      /Tau_psc 1.5 def       % time constant of PSC (=Tau_inact)
      /Tau_rec 130.0 def     % recovery time
      /Tau_fac 530.0 def     % facilitation time
      /U 0.03 def            % facilitation parameter U
      /A 1540.0 def          % PSC weight in pA
      /f 20.0 1000.0 div def % frequency in Hz given converted to 1/ms

      /Tend 1200.0 def       % simulation time
      /TIstart 50.0 def      % start of current
      /TIend 1050.0 def      % end of current


      % set resolution and limits on delays
      % limits must be set BEFORE connecting any elements
      [0]
      <<
        /resolution h
        /local_num_threads local_num_threads
        /overwrite_files true
%       /total_num_virtual_procs total_num_virtual_procs
      >> SetStatus

      cout 15 setprecision

      % create specific synapse type

      /tsodyks_synapse
      << /tau_psc Tau_psc
         /tau_rec Tau_rec
         /tau_fac Tau_fac
         /U U
         /delay 0.1
         /weight A
         /u 0.0
         /x 1.0
      >> SetDefaults

      /iaf_psc_exp Create /neuron1 Set

      neuron1 << /tau_m Tau
                 /t_ref TauR
                 /tau_syn_ex Tau_psc
                 /tau_syn_in Tau_psc
                 /C_m C
                 /V_reset U0
                 /E_L U0
                 /V_m U0
                 /V_th Theta
      >> SetStatus

      % neuron1 GetStatus info

      /iaf_psc_exp Create /neuron2 Set

      neuron2 << /tau_m Tau
                 /t_ref TauR
                 /tau_syn_ex Tau_psc
                 /tau_syn_in Tau_psc
                 /C_m C
                 /V_reset U0
                 /E_L U0
                 /V_m U0
                 /V_th Theta
      >> SetStatus

      % neuron2 GetStatus info

      /I0 Theta C mul Tau div 1.0 1.0 f div TauR sub Tau div neg exp sub div def
      cout (I0= ) <- I0 <- endl ;


      /dc_generator Create /dc_gen Set
      dc_gen << /amplitude I0 /start TIstart /stop TIend >> SetStatus

      /voltmeter Create /vm Set
      vm << /withtime true
            /to_file true
         >> SetStatus

      /spike_detector Create /sp_det Set
      sp_det << /withtime true /withgid true >> SetStatus

      dc_gen neuron1 Connect
      vm neuron2 Connect

      neuron1 neuron2 /tsodyks_synapse Connect

      Tend Simulate
end