// Documentation: https://github.com/fietkiewicz/PointerBuilder
// Description: Muscle with calcium dynamics and neural activation.
// Notes:
//   The muscle model is adapted from the following paper:
//   Kim H. Linking Motoneuron PIC Location to Motor Function in Closed-Loop Motor Unit System Including Afferent
//   Feedback: A Computational Investigation. eNeuro. 2020 Apr 27;7(2)
//   On ModelDB: https://modeldb.science/266732

// Create neuron model
load_file("nrngui.hoc")
create cell
cell {
  insert hh
}

// Create stimulus for neuron
objref ns, syn, nc
ns = new NetStim()
ns.interval = 100
syn = new ExpSyn(0.5)
nc = new NetCon(ns, syn)
nc.delay = 0
nc.weight = 2

// Create muscle model
objref calciumObject, forceObject
create muscle
muscle {
    calciumObject = new calcium(0.5)
    forceObject = new force(0.5)
}

// connect neuron to muscle
objref neuromuscularJunction
neuromuscularJunction = new NetCon(&cell.v(0.5), calciumObject)
neuromuscularJunction.threshold = -40

// Set pointers
setpointer forceObject.aPointer, calciumObject.A
setpointer forceObject.xmPointer, calciumObject.xm

// Load run controls and graph window
xopen("graph.ses")