% # CaBuffer_PYdr_JB12:
%
% Calcium buffer concentration dynamics, for generic pyramidal dendrite
% compartments used in the DynaSim implementation of (Benita et al., 2012).
%
% - Note: This CaBuffer produces calcium in concentations of uM, not mM
%
% - Requires:
%     - "@IHVA_PYdr_JB12" exposed by "IHVA_PYdr_JB12" mechanism
%
% - Exposes:
%     - calcium concentration "@CaBuffer_PYdr_JB12" required for "iKCa_PYdr_JB12"
%     mechanism
%
% - 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: calcium, intrinsic, pyramidal, dendrite
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameters
tauCa = 150 % ms
% We must multiply by 1000 to convert 1/nA to 1/uA, since all the rest of our
% equations use uA:
alphaCa = 0.005*1000 % uM/(uA ms) drive conversion of Ca-modifying currents
% AES actually maybe the nA in the paper was a typo and doesn't need conversion?
% alphaCa = 0.005 % uM/(uA ms) drive conversion of Ca-modifying currents
areaDR = 0.00035 % Area of dendrite, 0.035 mm^2 = 0.00035 cm^2

CaBufferIC = 0.001
CaBufferNoiseIC = 0.01

% ODEs
% CaBuffer requires input from IHVA, but CaBuffer is only used by IKCa
% AES, negative typo? (was not a typo, was simply using it for weird negative situation with ihva)
% CaBuffer_PYdr_JB12' = max(-alphaCa.*areaDR.*@IHVA_PYdr_JB12, 0) - CaBuffer_PYdr_JB12./tauCa
% CaBuffer_PYdr_JB12' = max(alphaCa.*areaDR.*@IHVA_PYdr_JB12, 0) - CaBuffer_PYdr_JB12./tauCa
% AES debug
CaBuffer_PYdr_JB12' = alphaCa.*areaDR.*@IHVA_PYdr_JB12 - CaBuffer_PYdr_JB12./tauCa


posCaBufferDebug(X) = alphaCa.*areaDR.*@IHVA_PYdr_JB12 + 0.*X
monitor posCaBufferDebug

CaBuffer_PYdr_JB12(0) = CaBufferIC+CaBufferNoiseIC.*rand(1,Npop)

% Interface
@CaBuffer_PYdr_JB12 += CaBuffer_PYdr_JB12