% # iGABAA_IN_IN_JB12:
%
% Normalized synaptic GABA-Aergic inhibitory current, with synaptic
% depression and minis, FROM the interneuron axo-soma TO pyramidal
% dendrite PYdr<-IN connection used in the DynaSim
% implementation of (Benita et al., 2012).
%
% - Dependencies:
%     - netconNearestNeighbors.m
%
% - References:
%     - Benita, J. M., Guillamon, A., Deco, G., & Sanchez-Vives, M.
%     V. (2012). Synaptic depression and slow oscillatory activity
%     in a biophysical network model of the cerebral cortex.
%     Frontiers in Computational Neuroscience, 6.
%     https://doi.org/10.3389/fncom.2012.00064
%
% - Tags: synapse, connection, inhibition, gabaa
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameters
% For DynaSim, we need to convert synaptic maximal conductance from
% absolute to area-relative terms, while also converting the units to
% mS/cm^2 to keep pace with the rest of the equations:
%
% 0.165 nS (gGABAA II) / 0.02 mm^2 (interneuron area) * ...
% 1 mS / 1000000 nS * 100 mm^2 / 1 cm^2 = ...
% 0.000825 mS/cm^2
%
gGABAA = 0.000825 % mS/cm^2
EGABAA = -70    % mV

alpha = 1
tauGABAA = 5 % ms
deprFactor = 0.9
tauRes = 400 % ms

% Initial conditions
sGABAAIC = 0.0
sGABAANoiseIC = 0.1
resIC = 0.8
resNoiseIC = 0.1

% Propofol-modifying parameters
propoCondMult = 1
propoTauMult = 1

% Connectivity
% Connective radius, aka how many target cells each source cell connects
% to, from the source's perspective.
radius = 10

% Remove autapses to the dendrite corresponding to this soma
removeRecurrentBool = 1
% We also need to normalize the conductance in mS/cm^2 by the number
% of connections each target cell is receiving on average, so that
% the TOTAL sum of their conductive inputs adds to our overall
% maximal conductance above.
normalizingFactor = min(((2*radius + (1-removeRecurrentBool)) / (N_post/N_pre)), N_pre)

% Note that what is passed is 2x the radius
netcon = netconNearestNeighbors(2*radius, N_pre, N_post, removeRecurrentBool)


% Functions
IGABAA_IN_IN_JB12(X,sGABAA,rec) = -propoCondMult.*gGABAA/normalizingFactor.*((res.*sGABAA)*netcon).*(X-EGABAA)

monitor IGABAA_IN_IN_JB12

% This is the synaptic activity state variable
sGABAA' = alpha./(1 + exp(-(X_pre - 20)./2)) - sGABAA./(tauGABAA*propoTauMult)
sGABAA(0) = sGABAAIC+sGABAANoiseIC.*rand(1,N_pre)

% This is the 'resources' state variable
res' = (1 - res)./tauRes + max((t-tspike_pre)<=(2*dt)).*(-(1 - res)./tauRes + (deprFactor.*res - res)./dt)
res(0) = resIC-resNoiseIC.*rand(1,N_pre)

% Linker
@current += IGABAA_IN_IN_JB12(X_post,sGABAA,res)