//genesis - Purkinje cell M9 genesis2 script
/* Copyright E. De Schutter (Caltech and BBF-UIA) */

/**********************************************************************
** Set of currents developed for rat cerebellum Purkinje neuron by
**  and dendritic spine prototypes.
** This version actually computes all the tables and saves it to files
** E. De Schutter, Caltech, 1991-1992
**********************************************************************/

/* Reference:
** E. De Schutter and J.M. Bower: An active membrane model of the
** cerebellar Purkinje cell. I. Simulation of current clamps in slice.
** Journal of Neurophysiology  71: 375-400 (1994).
** http://www.bbf.uia.ac.be/TNB/TNB_pub8.html
** Consult this reference for sources of equations and experimental data.
*/


/* The data on which these currents are based were collected at room
**   temperature (anything in the range 20 to 25C).  All rate factors were
**   adapted for body temperature (37C), assuming a Q10 of about 3;
**   in practice all rate factors were multiplied by a factor of 5 */

// CONSTANTS
/* should be defined by calling routine (all correctly scaled):
**	ENa, GNa
**	ECa, GCa
**	EK, GK 
**  	Eh, Gh */

int include_Purk_chansave

if ( {include_Purk_chansave} == 0 )

	include_Purk_chansave = 1

include  defaults.g
include  Purk_const.g


/*********************************************************************
**                  Central channel creation routine
*********************************************************************/

/* Make tabchannels */
function make_chan(chan, Ec, Gc, Xp, XAA, XAB, XAC, XAD, XAF, XBA, XBB,  \
    XBC, XBD, XBF, Yp, YAA, YAB, YAC, YAD, YAF, YBA, YBB, YBC, YBD, YBF \
    , Zp, ZAA, ZAB, ZAC, ZAD, ZAF, ZBA, ZBB, ZBC, ZBD, ZBF)
    str chan
    int Xp, Yp, Zp
    float Ec, Gc
    float XAA, XAB, XAC, XAD, XAF, XBA, XBB, XBC, XBD, XBF
    float YAA, YAB, YAC, YAD, YAF, YBA, YBB, YBC, YBD, YBF
    float ZAA, ZAB, ZAC, ZAD, ZAF, ZBA, ZBB, ZBC, ZBD, ZBF

    if ({exists {chan}})
        return
    end

    create tabchannel {chan}
    setfield {chan} Ek {Ec} Gbar {Gc} Ik 0 Gk 0 Xpower {Xp} Ypower {Yp}  \
        Zpower {Zp}
    if (Xp > 0)
        setupalpha {chan} X {XAA} {XAB} {XAC} {XAD} {XAF} {XBA} {XBB} {XBC} \
			{XBD} {XBF} -size {tab_xfills+1} -range {tab_xmin} {tab_xmax}
    end
    if (Yp > 0)
        setupalpha {chan} Y {YAA} {YAB} {YAC} {YAD} {YAF} {YBA} {YBB} {YBC} \
			{YBD} {YBF} -size {tab_xfills+1} -range {tab_xmin} {tab_xmax}
	end
    if (Zp != 0)
        setupalpha {chan} Z {ZAA} {ZAB} {ZAC} {ZAD} {ZAF} {ZBA} {ZBB} {ZBC} \
			{ZBD} {ZBF} -size {(tab_xfills+1)*20} -range {tab_xmin} {tab_xmax}
    end

end


/******************************************************************* \
**
**               The current equations themselves 
*********************************************************************/

function make_Purkinje_chans_KC_K2
    int i, cdivs
    float zinf, ztau, c, dc, cmin, cmax
    float x, dx, y
    float a, b

echo making and saving Purkinje channel library....

/*  10-fold precision  */

//    tab_xfills = 29999


    /* non-inactivating BK-type Ca-dependent K current eq 3 (Gruol K1)
    /* scaled for units: V, sec, mM */
    make_chan Purk_KC {EK} {GK} 1 7.5e3 0.0 0.0 0.0 1.0e12 0.110e3 0.0  \
        0.0 -0.035 14.9e-3 0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0  \
        0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

    /* Z: Ca-activation, tabchannel specific implementation */
    cmin = ({CCaI}) // will create a z-range from 0.0021 to 0.9727
    cmax = ({Ca_tab_max})
    cdivs = {(tab_xfills+1)*20}
    c = cmin
    dc = cdivs
    dc = (cmax - cmin)/cdivs
    //slow (Gola, Ikemoto:50-280ms delay)
    ztau = 0.010
    call Purk_KC TABCREATE Z {cdivs} {cmin} {cmax}
    for (i = 0; i <= (cdivs); i = i + 1)
	    zinf = 1/(1 + (4.0e-3/c))
	    setfield Purk_KC Z_A->table[{i}] {zinf/ztau}
	    setfield Purk_KC Z_B->table[{i}] {1/ztau}
	    c = c + dc
    end
    setfield Purk_KC Zpower 2
    setfield Purk_KC Z_A->calc_mode 0
    setfield Purk_KC Z_B->calc_mode 0
    call Purk_KC TABSAVE Purk_KCx20.tab

    /* non-inactivating Ca-dependent K current eq 1 (Gruol K2) */
    /* scaled for units: V, sec, mM */
    make_chan Purk_K2 {EK} {GK} 1 25.0e3 0.0 0.0 0.0 1.0e12 0.075e3 0.0  \
        0.0 0.025 6.0e-3 0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0.0 \
         0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
    /* Z: Ca-activation, tabchannel specific implementation */
    cmin = ({CCaI}) // will create a z-range from 0.0021 to 0.9727
    cmax = ({Ca_tab_max})
    cdivs = {(tab_xfills+1)*20}
    c = cmin
    dc = cdivs
    dc = (cmax - cmin)/cdivs
    ztau = 0.010
    call Purk_K2 TABCREATE Z {cdivs} {cmin} {cmax}
    for (i = 0; i <= (cdivs); i = i + 1)
	    zinf = 1/(1 + (0.2e-3/c))
	    setfield Purk_K2 Z_A->table[{i}] {zinf/ztau}
	    setfield Purk_K2 Z_B->table[{i}] {1/ztau}
	    c = c + dc
    end
    setfield Purk_K2 Zpower 2
    setfield Purk_K2 Z_A->calc_mode 0
    setfield Purk_K2 Z_B->calc_mode 0
    call Purk_K2 TABSAVE Purk_K2x20.tab

end
/*********************************************************************/


end