/*----------------------------------------------------------------------------

	Detailed kinetic synapse mechanism
	----------------------------------

	Demo file to show the behavior of a synaptic currents mediated by
	glutamate NMDA receptors, using a detailed kinetic model of these
	receptors and a kinetic model for the release of transmitter.

	Kinetic model from Clements & Westbrook, Neuron 7: 605, 1991.


  See details in:

  Destexhe, A., Mainen, Z.F. and Sejnowski, T.J.  Kinetic models of 
  synaptic transmission.  In: Methods in Neuronal Modeling (2nd edition; 
  edited by Koch, C. and Segev, I.), MIT press, Cambridge, 1996.


  Written by Alain Destexhe, Laval University, 1995

----------------------------------------------------------------------------*/



//----------------------------------------------------------------------------
//  load and define general graphical procedures
//----------------------------------------------------------------------------

//xopen("$(NEURONHOME)/lib/hoc/stdrun.hoc")
load_file("nrngui.hoc")

objectvar g[20]			// max 20 graphs
ngraph = 0

proc addgraph() { local ii	// define subroutine to add a new graph
				// addgraph("variable", minvalue, maxvalue)
	ngraph = ngraph+1
	ii = ngraph-1
	g[ii] = new Graph()
	g[ii].size(0,tstop,$2,$3)
	g[ii].xaxis()
	g[ii].yaxis()
	g[ii].addvar($s1,1,0)
	g[ii].save_name("graphList[0].")
	graphList[0].append(g[ii])
}

if(ismenu==0) {
  nrnmainmenu()			// create main menu
  nrncontrolmenu()		// crate control menu
  ismenu=1
}



//----------------------------------------------------------------------------
//  general parameters
//----------------------------------------------------------------------------

dt=0.025
tstop = 2500
runStopAt = tstop
steps_per_ms = 1/dt
celsius = 36
v_init = -70



//----------------------------------------------------------------------------
//  create compartments and insert passive properties
//----------------------------------------------------------------------------

create PRE,POST
forall {
  diam=10
  L=10
  insert pas
  g_pas=1/5000
  e_pas=v_init
}



//----------------------------------------------------------------------------
//  insert presynaptic mechanisms
//----------------------------------------------------------------------------

access PRE		// insert Hodgk-Hux. Na+ and K+ currents for spikes


insert glurel		// transmitter release


//----------------------------------------------------------------------------
//  insert postsynaptic mechansisms
//----------------------------------------------------------------------------

objectvar c
c = new NMDA5()			// create synapse
POST c.loc(0.5)				// assign postsynaptic compartment
setpointer c.C, PRE.T_glurel(0.5)		// assign presynaptic compartment

Erev_NMDA5	= 0	//	(mV)	reversal potential (E_K)
mg_NMDA5	= 0	//	put in zero magnesium for the demo

// parameters from Hessler Shirke & Malinow 1993
Rb_NMDA5	= 2e-3    //	(/uM /ms)	: binding 		
Ru_NMDA5	= 0.005  //	(/ms)	: unbinding		
Rd_NMDA5	= 0.004   //	(/ms)	: desensitization
Rr_NMDA5	= 0.006   //	(/ms)	: resensitization 
Ro_NMDA5	= 0.10   //	(/ms)	: opening
Rc_NMDA5	= 0.04   //	(/ms)	: closing
c.gmax 		= 50	//	(pS)	maximum conductance




//----------------------------------------------------------------------------
//  add graphs
//----------------------------------------------------------------------------


if (name_declared("mosinit") == 0) {
addgraph("PRE.T_glurel(0.5)",0,1.5)
addgraph("c.inmda",-0.001, 0.0001)
}