/* This is the primary file for creating the MSP cell - this file calls all
	of the hoc files necessary to build one cell and sets the default
	parameter values.
	
	Usually this file is called by a hoc file in /input_params/.
	
	Jason Moyer 2005 - jtmoyer@seas.upenn.edu
*/
	

//****************************************************************************
//Load all the baseline parameters to start with

sprint(dirstr, "%s/baseline_values.txt", preface)
//print dirstr
xopen(dirstr)
//load_file("../input_params/baseline_values.txt")
//****************************************************************************



//****************************************************************************
// all_tau_vecs.hoc loads the tables used to define the taus for many channels

sprint(dirstr, "%s/all_tau_vecs.hoc", preface)
//print dirstr
xopen(dirstr)
//load_file("all_tau_vecs.hoc")
//****************************************************************************



//****************************************************************************
//load the templates for the synapses - AMPA, GABA, and NMDA

sprint(dirstr, "%s/synapse_templates.hoc", preface)
xopen(dirstr)
//load_file("synapse_templates.hoc")
//****************************************************************************




//****************************************************************************
// load cell template - builds the cell topology, including inserting
// channels and synapses; dlambda code is in here (under geom()) along 
// with code to output the number of compartments in cell

sprint(dirstr, "%s/msp_template.hoc", preface)
xopen(dirstr)
//load_file ("msp_template.hoc")
//****************************************************************************



create acell_home_



//****************************************************************************
// load netstims template, sets default interval, number, noise

sprint(dirstr, "%s/netstims_template.hoc", preface)
xopen(dirstr)
//load_file("netstims_template.hoc")
//****************************************************************************



//****************************************************************************
// create msp cells using cell_append(), nc_append()
// set number of segments using geom_nseg() (in fixnseg.hoc)
// create shunt for sharp electrode

sprint(dirstr, "%s/create_mspcells.hoc", preface)
xopen(dirstr)
//load_file("create_mspcells.hoc")
//****************************************************************************





//**********************************************************************
// calculate membrane area, access soma by default
A1 = 0
Ad = 0

forsec "dendrite[1]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}

forsec "dendrite[14]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}

forsec "dendrite[26]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[27]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[29]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[32]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[35]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[42]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[52]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[53]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[54]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[2]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[9]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[15]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[18]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[23]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[30]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[31]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[36]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[39]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[43]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[44]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[3]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[8]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[10]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[11]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[16]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[17]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[19]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[20]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[37]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[38]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[40]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[41]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[45]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[50]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[4]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[7]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[12]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[13]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[21]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[22]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[46]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[47]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[5]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[6]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[48]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}
forsec "dendrite[49]" {
	for i = 1, nseg {
		Ad = Ad + area( i/(nseg+1) )
	}
}

forsec "MSP_Cell[0]"  {
	for i = 1, nseg {
		A1 = A1 + area( i/(nseg+1) )
	}
}

Ap = A1 - Ad

print "Total cell membrane area = ", A1		// equals whole cell membrane area
print "Mid + Dist mem area = ", Ad
print "Soma + Prox mem area = ", Ap 

//**********************************************************************
load_file("set_synapse.hoc")
//****************************************************************************
// specify cell's active properties using constants listed in
// input_params/baseline_values.txt
//

sprint(dirstr, "%s/basic_procs.hoc", preface)
xopen(dirstr)


set_pas(G_PAS)

set_naf(G_NAF)
set_nafd(G_NAFD)
set_nap(G_NAP)
set_napd(G_NAPD)

set_kir(G_KIR)
set_kas(G_KAS)
set_kasd(G_KASD)
set_kaf(G_KAF)
set_kafd(G_KAFD)
set_krp(G_KRP)
set_bkkca(G_BKKCA)
set_skkca(G_SKKCA)

set_caL(P_CAL)
set_caL13(P_CAL13)
set_can(P_CAN)
set_caq(P_CAQ)
set_car(P_CAR)
set_cat(P_CAT)

set_cainf(CAINF)
set_taur(TAUR)
set_cadrive(CA_DRIVE)
set_pump(CA_PUMP)

//set_mu()

set_ek(EK)
forsec "MSP_Cell" {Ra = RA    cm = CM}
//Mid 
F=1.3
//    forsec "Mid_Dend" {Ra = RA cm = CM*F}
forsec "dendrite[1]" {Ra = RA cm = CM*F}
forsec "dendrite[14]" {Ra = RA cm = CM*F}
forsec "dendrite[26]" {Ra = RA cm = CM*F}
forsec "dendrite[27]" {Ra = RA cm = CM*F}
forsec "dendrite[29]" {Ra = RA cm = CM*F}
forsec "dendrite[32]" {Ra = RA cm = CM*F}
forsec "dendrite[35]" {Ra = RA cm = CM*F}
forsec "dendrite[42]" {Ra = RA cm = CM*F}
forsec "dendrite[52]" {Ra = RA cm = CM*F}
forsec "dendrite[53]" {Ra = RA cm = CM*F}
forsec "dendrite[54]" {Ra = RA cm = CM*F}
//***
forsec "dendrite[2]" {Ra = RA cm = CM*F}
forsec "dendrite[9]" {Ra = RA cm = CM*F}
forsec "dendrite[15]" {Ra = RA cm = CM*F}
forsec "dendrite[18]" {Ra = RA cm = CM*F}
forsec "dendrite[23]" {Ra = RA cm = CM*F}
forsec "dendrite[30]" {Ra = RA cm = CM*F}
forsec "dendrite[31]" {Ra = RA cm = CM*F}
forsec "dendrite[36]" {Ra = RA cm = CM*F}
forsec "dendrite[39]" {Ra = RA cm = CM*F}
forsec "dendrite[43]" {Ra = RA cm = CM*F}
forsec "dendrite[44]" {Ra = RA cm = CM*F}

forsec "spine[0]" {Ra = RA cm = CM*F}

//Dist 
F=3
forsec "dendrite[3]" {Ra = RA cm = CM*F}
forsec "dendrite[8]" {Ra = RA cm = CM*F}
forsec "dendrite[10]" {Ra = RA cm = CM*F}
forsec "dendrite[11]" {Ra = RA cm = CM*F}
forsec "dendrite[16]" {Ra = RA cm = CM*F}
forsec "dendrite[17]" {Ra = RA cm = CM*F}
forsec "dendrite[19]" {Ra = RA cm = CM*F}
forsec "dendrite[20]" {Ra = RA cm = CM*F}
forsec "dendrite[37]" {Ra = RA cm = CM*F}
forsec "dendrite[38]" {Ra = RA cm = CM*F}
forsec "dendrite[40]" {Ra = RA cm = CM*F}
forsec "dendrite[41]" {Ra = RA cm = CM*F}
forsec "dendrite[45]" {Ra = RA cm = CM*F}
forsec "dendrite[50]" {Ra = RA cm = CM*F}
//***
forsec "dendrite[4]" {Ra = RA cm = CM*F}
forsec "dendrite[7]" {Ra = RA cm = CM*F}
forsec "dendrite[12]" {Ra = RA cm = CM*F}
forsec "dendrite[13]" {Ra = RA cm = CM*F}
forsec "dendrite[21]" {Ra = RA cm = CM*F}
forsec "dendrite[22]" {Ra = RA cm = CM*F}
forsec "dendrite[46]" {Ra = RA cm = CM*F}
forsec "dendrite[47]" {Ra = RA cm = CM*F}
//**
forsec "dendrite[5]" {Ra = RA cm = CM*F}
forsec "dendrite[6]" {Ra = RA cm = CM*F}
forsec "dendrite[48]" {Ra = RA cm = CM*F}
forsec "dendrite[49]" {Ra = RA cm = CM*F}


forsec "spine[1]" {Ra = RA cm = CM*F}


//****************************************************************************



//*************************************************************************
// create and set netstims using champawt(), chnmdawt(), chint()

sprint(dirstr, "%s/make_netstims.hoc", preface)
xopen(dirstr)

//*************************************************************************



access MSP_Cell[0].soma