strdef base
base = "BOTH_85"	// Modify the name to include conductance type and RMP
v_init = -85		// choose an RMP (typically -55 to -85, in 5 mV steps)
AMPAmax=0.0005		// choose an AMPA conductance (typically 0 or 500 pS)
NMDAmax=0.001		// choose an NMDA conductance (typically 0 or 1 nS)

dt = 0.01
steps_per_ms = 100
tstop = 200

	create soma
	create dend
	create spine_head[1000]
	create spine_neck[1000]
	create iseg[40]
	create axon


//	v_init = -85		// resting membrane potential

	celsius=37			// nominal temperature of simulation
	Ri=100    			// internal resistivity in ohm-cm
	Cm=1.0	      		// specific membrane capacitance in uF/cm^2
	Rm=15000      		// specific membrane resistivity in ohm/cm^2

//edited on August 2, 2020 to remove all "insert" conductances [na, k] everywhere

	soma {
		nseg = 3
		diam = 10
		L = 20
		connect iseg[0](0), 0
	}

	for i = 0, 39 {
		iseg[i] {
			nseg = 1
			diam = 2 - (1.5*(i/40))
			L = 1

			if (i<39) connect iseg[i+1](0), 1
			if (i==39) connect axon(0),1
		}
	}


	
	axon {
		nseg = 201
		L = 2000
		diam = .5
	}


	dend {
		nseg = 1001
		diam(0:1) = 5:1
		L = 1000
		connect soma(1), 0
	     }

		access soma
		distance()

		
	for i = 0, 999 {
			//Adding spines for every micron
			g = (i+1)/1000
			dend connect spine_neck[i](0), g
			spine_neck[i] connect spine_head[i](0),1
			spine_neck[i] {nseg=1 L=1 diam=0.0504573} 
			spine_head[i] {nseg=1 L=0.5 diam=0.5}
	}

	forall {
		insert pas
		g_pas = 1/Rm
		cm = Cm
		Ra = Ri
		e_pas = v_init
	}

access soma

objref somavec, dendvec, Acondvec, Ncondvec, savsoma, savdend, savAcond, savNcond, somamatrix, dendmatrix, Acondmatrix, Ncondmatrix

somavec = new Vector()
dendvec = new Vector()
Acondvec = new Vector()
Ncondvec = new Vector()
savsoma = new File()
savdend = new File()
savAcond = new File()
savNcond = new File()
somamatrix = new Matrix(2000,101)
dendmatrix = new Matrix(2000,101)
Acondmatrix = new Matrix(2000,101)
Ncondmatrix = new Matrix(2000,101)

strdef fName
sprint(fName, "Soma_%s.dat", base) 
savsoma.wopen(fName)
sprint(fName, "Dend_%s.dat", base) 
savdend.wopen(fName)
sprint(fName, "AMPAcond_%s.dat", base) 
savAcond.wopen(fName)
sprint(fName, "NMDAcond_%s.dat", base) 
savNcond.wopen(fName)


objref AMPA, NMDA


for i = 0,100 {
	
	if (i==0) { 
		q = 1
	 } else { 
		q = ((i*10)-1) 
		}

	spine_head[q]	AMPA = new syn_g(1)
	spine_head[q]	NMDA = new nmda(1)
	AMPA.onset = 2
	AMPA.gmax = AMPAmax
	NMDA.onset = 2
	NMDA.gmax = NMDAmax
	p = q/999
	

somavec.record(&soma.v(0.5),0.1)
dendvec.record(&dend.v(p),0.1)
Acondvec.record(&AMPA.g, 0.1)
Ncondvec.record(&NMDA.g, 0.1)

init()
	
	while (t<tstop-dt) {
		fadvance()
	}

somamatrix.setcol(i, somavec)  
dendmatrix.setcol(i, dendvec) 
Acondmatrix.setcol(i, Acondvec) 
Ncondmatrix.setcol(i, Ncondvec) 

print i

}

somamatrix.fprint(savsoma, " %g")
dendmatrix.fprint(savdend, " %g")
Acondmatrix.fprint(savAcond, " %g")
Ncondmatrix.fprint(savNcond, " %g")

savsoma.close()
savdend.close()
savAcond.close()
savNcond.close()