File: initbatser.ho.txt

package info (click to toggle)
neuron 8.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,760 kB
  • sloc: cpp: 149,571; python: 58,465; ansic: 50,329; sh: 3,510; xml: 213; pascal: 51; makefile: 35; sed: 5
file content (120 lines) | stat: -rw-r--r-- 2,639 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// $Id: initbatser.hoc,v 1.9 2011/06/15 05:10:48 ted Exp ted $

// Serial batch implementation
// for stimulus current i iterating over a range of values
//   run a simulation and report spike frequency
// save i & corresponding f to a file
// optionally plot fi curve

load_file("stdgui.hoc") // load standard library but don't open NMM toolbar

///// Simulation parameters

PLOTRESULTS = 1 // if 1, generates a graph that shows f-i curve
TSTOP = 500 // ms, more than long enough for 15 spikes at ISI = 25 ms
AMP0 = 0.1 // nA--minimum stimulus
D_AMP = 0.02 // nA--stim increment between runs
NRUNS = 30

///// Model specification

load_file("cell.hoc")

///// Instrumentation

// experimental manipulations

objref stim
soma stim = new IClamp(0.5)
stim.del = 1 // ms
stim.dur = 1e9
stim.amp = 0.1 // nA

// $1 is run #
// returns corresponding stimulus amplitude

func fstimamp() {
  return AMP0 + $1*D_AMP
}

// sets stimulus amplitude to appropriate value for this run

proc setparams() {
  stim.amp = fstimamp($1)
}

// data recording and analysis

objref nc, spvec, nil // to record spike times
// count only those spikes that get to distal end of dend
dend nc = new NetCon(&v(1), nil)
nc.threshold = -10 // mV
spvec = new Vector()
nc.record(spvec)

NSETTLE = 5 // ignore the first NSETTLE ISI (allow freq to stablize)
NINVL = 10 // # ISI from which frequency will be calculated
NMIN = NSETTLE + NINVL // ignore recordings with fewer than this # of ISIs

freq = 0

proc postproc() { local nspikes, t1, t2
  freq = 0
  nspikes = spvec.size()
  if (nspikes > NMIN) {
    t2 = spvec.x(nspikes-1) // last spike
    t1 = spvec.x(nspikes-1-NINVL) // NINVL prior to last spike
    freq = NINVL*1e3/(t2-t1) // t1 and t2 are separated by NINVL ISIs
  }
}

///// Simulation control

tstop = TSTOP

// batch control

trun = startsw() // keep track of execution time past this point

objref svec, fvec

proc batchrun() { local ii
  svec = new Vector()
  fvec = new Vector()
  for ii=0,$1-1 {
    setparams(ii) // set parameters for this run
    run()
    postproc() // analyze the data
    svec.append(stim.amp)
    fvec.append(freq)
    printf(".") // indicate progress
  }
}

batchrun(NRUNS)

///// Reporting of results

proc saveresults() { local ii  localobj file
  file = new File($s1)
  file.wopen()
  file.printf("label:%s\n%d\n", "f", fvec.size)
  for ii=0, fvec.size-1 {
    file.printf("%g\t%g\n", svec.x[ii], fvec.x[ii])
  }
  file.close()
}

saveresults("fi.dat")

print " "
print startsw() - trun, "seconds" // report run time

objref fig
load_file("plotfi.hoc")

if (PLOTRESULTS==1) {
  fig = plotfi(fvec, svec)
} else {
  quit()
}