/*
============================================================================
Cavitational Capacitive Drive (CCD) Model Demonstration
Author: Mithun Padmakumar
Date: July 2026

Citation:
  Padmakumar, M., Rajan, D., & Steephen, J. E. (2026). Cavitational capacitive 
  drive: A computationally efficient model for ultrasonic neuromodulation. 
  Journal of Neural Engineering.

Description:
  Main execution script for demonstrating the application of the Cavitational 
  Capacitive Drive (CCD) model on a cortical Regular Spiking (RS) neuron.
============================================================================
*/

load_file("nrngui.hoc")
load_file("ccd_tables.hoc")

// Ensure output directory exists
system("mkdir -p Results")

// Set simulation stop time
tstop = 150

// Create standalone Cortical Regular Spiking (RS) neuron model
create soma
access soma

Ra = 100
nseg = 1
diam = 96
L = 96
cm = 1
celsius = 36

// Passive current
insert pas
e_pas = -70.3
g_pas = 2.05e-5

// Traub Hodgkin-Huxley channels (Na+, K+)
insert hh2
ek = -100
ena = 50
vtraub_hh2 = -56.2
gnabar_hh2 = 0.056
gkbar_hh2 = 0.006

// Cortical M-current
insert im
taumax_im = 608
gkbar_im = 7.5e-5

print " "
print "<< RS cell created >>"
print " "

v_init = -70

// Setup Action Potential counter
objref apc, ap_times
apc = new APCount(0.5)
apc.thresh = 0
ap_times = new Vector()
apc.record(ap_times)

// Record membrane potential and simulation timestamps
objref vsoma, ts
vsoma = new Vector()
vsoma.record(&soma.v(0.5))

ts = new Vector()
ts.record(&t)

// Record membrane capacitance
objref cm_vec
cm_vec = new Vector()
cm_vec.record(&soma.cm(0.5))

// Load GUI and process handlers
load_file("GUI.hoc")

// Launch standard NEURON RunControl panel
nrncontrolmenu()

// Create membrane potential visualization graph
objref g_v
g_v = new Graph()
g_v.size(0, tstop, -80, 40)
g_v.addvar("soma.v(0.5)", 1, 1)
graphList[0].append(g_v)

// Initialize simulation state
finitialize(v_init)

print "CCD Model Simulation Environment Initialized."