create cell_a_40, cell_b_40

forall {
	L = 200
	diam = 6

	Ra = 183
	cm = 1

	insert pas
	g_pas = 1 / 132500
	e_pas = -50

	nseg = 1	//for G-V plots; not using 51
}
v_init = e_pas

//------------------------------------------------------

objref g40[2]
for i = 0, 1 {
	g40[i] = new Gap40(0.5)	//Dummy Location
}

cell_a_40 g40[0].loc(0.9999) // just inside "distal" end of cell_a
cell_b_40 g40[1].loc(0.0001) // just inside "proximal" end of cell_b

objref pc
pc = new ParallelContext()

access cell_a_40
pc.source_var(&cell_a_40.v(0.9999), pctr)
pc.target_var(g40[1], &g40[1].vgap, pctr)
pctr = pctr + 1

access cell_b_40
pc.source_var(&cell_b_40.v(0.0001), pctr)
pc.target_var(g40[0], &g40[0].vgap, pctr)
pctr = pctr + 1

{ pc.setup_transfer() }
ParallelComputeTool[0].nthread(1)
cvode.cache_efficient(1)

//------------------------------------------------------

objref vbox_40, hbox1_40, hbox2_40
objref graph_v_40, graph_i_40, g_iv_40, g_gv_40

graph_v_40 = new Graph(0)
graph_v_40.exec_menu("Keep Lines")
addplot(graph_v_40,0)
graph_v_40.addexpr("cell_a_40.v(0.5)", 1, 2, 100, 100)

graph_i_40 = new Graph(0)
graph_i_40.exec_menu("Keep Lines")
addplot(graph_i_40,0)
graph_i_40.addexpr("g40[0].i", 5, 2, 100, 100)
//graph_i_40.addexpr("g40[1].i", 5, 2)

g_iv_40 = new Graph(0)
g_gv_40 = new Graph(0)

vbox_40 = new VBox()	//***** VBox
vbox_40.intercept(1)

hbox1_40 = new HBox()	//----- HBox1
hbox1_40.intercept(1)

graph_v_40.view(0, -170, 16000, 200, 600, 40, 600, 400)
graph_i_40.view(0, -6, 16000, 12, 1200, 40, 600, 400)

hbox1_40.intercept(0)
hbox1_40.map()			//----- HBox1

hbox2_40 = new HBox()	//----- HBox2
hbox2_40.intercept(1)

g_iv_40.view(-100, -6, 200, 12, 600, 40, 600, 400)
g_gv_40.view(-100, 0, 200, 180, 1200, 40, 600, 400)

hbox2_40.intercept(0)
hbox2_40.map()			//----- HBox2

vbox_40.intercept(0)
vbox_40.map()			//***** VBox
//------------------------------------------------------

objref stim_a_40
cell_a_40 stim_a_40 = new VClamp(0.5)
stim_a_40.amp[0] = -50

stim_a_40.amp[2] = -50
stim_a_40.dur[0] = 50
stim_a_40.dur[1] = 15000
stim_a_40.dur[2] = 500

//Stimulation stops before return to rest level
tstop= stim_a_40.dur[0]+stim_a_40.dur[1]

objref stim_b_40
cell_b_40 stim_b_40 = new VClamp (0.5)
stim_b_40.amp[0] = -50
stim_b_40.amp[1] = -50
stim_b_40.amp[2] = -50
stim_b_40.dur[0] = 50
stim_b_40.dur[1] = 15000
stim_b_40.dur[2] = 500

//------------------------------------------------------

objref rec_i_40, rec_g_40, vec_i_40, vec_g_40, vec_g_40_inst, vec_v_40

rec_i_40 = new Vector()
rec_g_40 = new Vector()
rec_i_40.record(&g40[0].i)
rec_g_40.record (&g40[0].g)

vec_i_40 = new Vector()
vec_g_40 = new Vector()
vec_g_40_inst = new Vector()
vec_v_40 = new Vector()

//------------------------------------------------------

for(i=-152.5; i<=52.5; i=i+5) {
	stim_a_40.amp[1] = i
	print "Clamp Level= ", i
	run()

	vec_g_40.append(rec_g_40.min())
	vec_i_40.append(rec_i_40.x(rec_i_40.size()-1))
	vec_v_40.append ((stim_a_40.amp[1]- stim_b_40.amp[1]))

	//Evaluate Instantaneous Conductance
	if ( (stim_a_40.amp[1]-stim_b_40.amp[1]) < 0 ) {
		vec_g_40_inst.append( 1000 * rec_i_40.min() / (stim_a_40.amp[1]- stim_b_40.amp[1]))
	} else {
		vec_g_40_inst.append( 1000 * rec_i_40.max() / (stim_a_40.amp[1]- stim_b_40.amp[1]))
	}
}

//------------------------------------------------------

vec_i_40.line(g_iv_40, vec_v_40, 2,2)
g_iv_40.exec_menu("View = plot")

vec_g_40.line(g_gv_40, vec_v_40, 3, 2)
vec_g_40_inst.line(g_gv_40, vec_v_40, 2, 2)
g_gv_40.mark(0,0,"O",1)
g_gv_40.exec_menu("View = plot")

graph_v_40.exec_menu("View = plot")
graph_i_40.exec_menu("View = plot")