// Brill, Waxman, Moore, and Joyner (1977) Conduction velocity and spike
// configuration in myelinated fibres: Computed dependence on internode distance
// J. Neurology, Neurosurgery, and Psychiatry. 40: 769-774

create node[1], myelin[1]

// topol(nnode) connects an alternating sequence of node/myelin pairs.
// For internode lengths < 1000 microns more than 12 nodes were used
// to eliminate end and stimulation effects. Dynamically re-constructing
// the topology is easy but the stimulator and GUI depend on sections they
// reference staying in existence. It's especially bad for a PointProcessManager
// when it's entire cell disappears. Therefore, we use 50 nodes
// throughout which, although overkill for long myelin lengths, is approprieate
// for the shortest 25 um lengths used in fig 1.

proc topol() {local i
	nnode = $1
	create node[nnode], myelin[nnode-1]
	access node[0]
	for i=0, nnode-2 {
		connect myelin[i](0), node[i](1)
		connect node[i+1](0), myelin[i](1)
	}
	forsec "myelin" { nseg = 10 }
}

proc geom() {
	forsec "node" { // area = 100 um2
		L = 3.183
		diam = 10
	}
	forsec "myelin" {
		L = $1
		diam = 10
	}
}

func l2a() { // convert per length (/cm) to per area (/cm2) based on diameter
	return 1/(PI*diam) * 1e4
}

proc biophys() {local fac
	// ohm/cm must be converted to ohm-cm by multiplying by
	// cross sectional area
	fac = PI*diam^2/4 * 1e-8
	forall {
		Ra = 1.26e8 * fac
	}
	// paper relative to rest=0 but following values relative to -65
	forsec "node" {
		insert hh
		gnabar_hh = 1.2
		gkbar_hh = .09
		gl_hh = .02
		ena = 115 - 65
		ek = -12 - 65
		el_hh = -.05 - 65
		cm = 3.14e-9*l2a()*1e6 // end up as uF/cm2
	}
	forsec "myelin" {
		insert pas
		e_pas = -65
		g_pas = 5.60e-9*l2a() // end up as S/cm2
		cm = 1.87e-11*l2a()*1e6 // end up as uF/cm2
	}
}

celsius = 20

proc make() {
	topol($1)
	geom($2)
	biophys()
}

make(50, 1000) // appropriate down to 25um internode length