% # iT_TC_AS17: T-type Low-threshold Calcium current, Hodgkin-Huxley-style,
%     for generic thalamocortical compartments, corresponding to CaV 3.1, used
%     in (Soplata et al., 2017).
%
% - References:
%     - Soplata AE, McCarthy MM, Sherfey J, Lee S, Purdon PL, Brown EN, et al.
%     Thalamocortical control of propofol phase-amplitude coupling. PLoS Comput
%     Biol. 2017;13: e1005879. doi:10.1371/journal.pcbi.1005879
%
% - Requires: @CaBuffer_TC_AS17 calcium concentration exposed by
%     "CaBuffer_TC_AS17" mechanism
%
% - Exposes: @iT_TC_AS17 calcium current as required by "CaBuffer_TC_AS17"
%
% - Tags: calcium, current, intrinsic, thalamocortical
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameters
gT = 2    % mS/cm^2
vShift = 2  % mV
phiH = 3.73 % unitless, based on Q10 of 3

% AES: set ICs too high and TC cells stay at mV=0 constantly???
hTIC = 0.01
hTNoiseIC = 0.005

% Functions
ET(CaBuffer_TC_AS17) = 1000.*8.31441.*(273.15+36)./(2.*96846).*log(2./@CaBuffer_TC_AS17) % mV
Minf(X)  = 1./(1+exp((-(X+vShift+57))./6.2))
Hinf(X)  = 1./(1+exp((X+vShift+81)./4))
tauH(X)  = (30.8+(211.4+exp((X+vShift+113.2)./5))./(1+exp((X+vShift+84)./3.2)))./phiH
iT_TC_AS17(X,hT) = -gT.*Minf(X).^2.*hT.*(X-ET(@CaBuffer_TC_AS17))

monitor iT_TC_AS17

% ODEs and ICs
hT' = (Hinf(X)-hT)./tauH(X)
hT(0)=hTIC+hTNoiseIC.*rand(1,Npop)

% Interface
@current += iT_TC_AS17(X,hT)
@iT_TC_AS17 += -iT_TC_AS17(X,hT)