-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnrnoc.hoc
371 lines (289 loc) · 8.63 KB
/
nrnoc.hoc
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
// $Id: nrnoc.hoc,v 1.26 2000/11/27 22:00:19 billl Exp $
proc nrnoc () {}
// Users should not edit nrnoc.hoc or default.hoc. Any local
// changes to these files should be made in local.hoc.
// key '*&*' is picked up by to indicate command for emacs
proc elisp () { printf("*&* %s\n",$s1) }
// if (not exists(simname)) { strdef simname, output_file, datestr, comment }
// Simctrl.hoc will automatically load stdgraph.hoc which automatically
// loads stdrun.hoc
strdef temp_string_, user_string_ // needed for simctrl
/* Global variable default values. NOTE that stdrun.hoc, stdgraph.hoc
and simctrl.hoc all contain variable definitions and thus default.hoc
should be loaded after these files */
load_file("default.hoc") /* Load default.hoc */
/* Allows arrays of strings */
objref hoc_obj_[2]
if (xwindows) {
load_file("stdgui.hoc") // don't want to encounter other String tempate defs
load_file("simctrl.hoc")
} else {
load_file("stdlib.hoc")
load_file("stdrunnoiv.hoc")
}
proc run () {
stdinit()
if (batch_flag == 1) {
sprint(output_file,"data/b%s.%02d", datestr, runnum)
batch_run(tstop, printStep, output_file)
finish()
} else {
continueRun(tstop)
}
}
proc continueRun() { local eventCount
// Although this works properly "the first time" it may not properly "continue" a simulation
eventCount=0
eventslow=1
stoprun = 0
while (t < $1 && stoprun == 0) {
for i = 1, nstep_steprun { fadvance() }
outputData()
eventCount = eventCount + 1
if (xwindows && eventCount%eventStep < 0.1) { doEvents() }
}
finish()
}
proc stdinit() {
realtime=0 startsw()
t = 0
stoprun = 0
if (batch_flag == 1) {
batch_save()
batchSave() // User defined program to set up stuff to save
}
init()
init()
if (graph_flag == 1) {
if (iv_flag == 1) {
initPlot()
} else {
initGraph()
}
}
if (print_flag == 1) { initPrint() }
}
proc init () {
initMech()
initMisc1()
/* Initialize state vars then calculate currents */
/* If user hand-set v in initMisc1() then v_init should be > 1000,
else all compartments will be set to v_init */
if (v_init < 1000) {
finitialize(v_init)
} else {
finitialize()
}
fcurrent()
/* Set ca pump and leak channel for steady state */
setMemb()
/* Recalculate currents with new pump and leak kinetics */
fcurrent()
fcurrent()
initMisc2()
if (cvode_active()) cvode.re_init()
}
proc initMech() { /* Initialization of mechanism variables */
/* NOTE: if any changes are made to the NEURON block of any local mod
file, the user must add the necessary inits to initMisc1() */
/** Range variables **/
forall {
if ((!ismembrane("pas")) && (!ismembrane("Passive"))) {
// Allow for either pas or Passive mod file usage
errorMsg("passive not inserted")
}
if (ismembrane("na_ion")) {
nai = na_init
nai0_na_ion = na_init
}
if (ismembrane("k_ion")) {
ki = k_init
ki0_k_ion = k_init
}
if (ismembrane("ca_ion")) {
cai = ca_init
cai0_ca_ion = ca_init
}
}
/** Global variables **/
}
proc setMemb () { local i_forward, i_back, iSum
/* Setup steady state voltage using leak channel */
forall {
if (ismembrane("pas")) {
iSum = 0.0
if (ismembrane("na_ion")) { iSum = iSum + ina }
if (ismembrane("k_ion")) { iSum = iSum + ik }
if (ismembrane("ca_ion")) { iSum = iSum + ica }
if (ismembrane("ns_ion")) { iSum = iSum + ins } // Non-specific
if (iSum == 0) { // Pas cmp so set e_pas = v
e_pas = v
} else {
if (g_pas > 0) { // Assume g set by user, calc e
e_pas = v + iSum/g_pas
} else { // Assume e set by user, calc g
if (e_pas != v) {
g_pas = iSum/(e_pas - v)
} else { // error: g_pas <= 0
errorMsg("bad g", g_pas)
}
}
if (e_pas < -100 || e_pas > 0) {
errorMsg("erev out of bounds", e_pas)
}
}
} else if (ismembrane("Passive")) {
iSum = 0.0
if (ismembrane("na_ion")) { iSum = iSum + ina }
if (ismembrane("k_ion")) { iSum = iSum + ik }
if (ismembrane("ca_ion")) { iSum = iSum + ica }
if (ismembrane("ns_ion")) { iSum = iSum + ins } // Non-specific
if (iSum == 0) { // Passive cmp so set erev_Passive = v
erev_Passive = v
} else {
if (g_Passive > 0) { // Assume g set by user, calc erev
erev_Passive = v + iSum/g_Passive
} else { // Assume erev set by user, calc g
if (erev_Passive != v) {
g_Passive = iSum/(erev_Passive - v)
} else { // error: g_Passive <= 0
errorMsg("bad g", g_Passive)
}
}
if (erev_Passive < -100 || erev_Passive > 0) {
errorMsg("erev out of bounds", erev_Passive)
}
}
}
}
}
proc finish() {
/* Called following completion of continueRun() */
finishMisc()
if (graph_flag == 1) {
if (iv_flag == 1) {
flushPlot()
} else {
graphmode(-1)
plt(-1)
}
}
if (print_flag == 1) {
wopen("")
}
}
/*------------------------------------------------------------
User definable GRAPHICS and PRINTING routines
------------------------------------------------------------*/
proc outputData() {
// Default procedure - if outputData() doesn't exist in the run file
if (graph_flag == 1) {
if (iv_flag == 1) {
Plot()
rt = stopsw()
if (rt > realtime) {
realtime = rt
fastflushPlot()
doNotify()
if (realtime == 2 && eventcount > 50) {
eventslow = int(eventcount/50) + 1
}
eventcount = 0
}else{
eventcount = eventcount + 1
if ((eventcount%eventslow) == 0) {
doEvents()
}
}
} else {
graph(t)
}
}
if (print_flag == 1) {
if (t%printStep <= printStep) { printOut() }
}
}
proc printOut() {
/* Default procedure - if printOut() doesn't exist in the run file */
}
proc initGraph() {
/* Default procedure - if initGraph() doesn't exist in the run file */
graph()
}
proc initPrint() {
/* Default procedure - if initPrint() doesn't exist in the run file */
wopen(output_file)
}
/*------------------------------------------------------------
User definable BATCH RUN routines
------------------------------------------------------------*/
proc batchSave() {
/* Default procedure - if batchSave() doesn't exist in the run file */
}
proc nextrun() {
// Called from finishmisc() following completion of batch in an autorun
wopen("")
runnum = runnum + 1
sprint(output_file,"data/b%s.%02d", datestr, runnum)
}
// commands for emacs
proc update_runnum() {
runnum = $1
sprint(output_file,"data/%s.%02d", datestr, runnum)
print "^&^ (progn (sim-index-revert)(setq sim-runnum ",runnum,"))" }
proc nrn_write_index() { printf("&INDEX& %s\n",$s1) }
proc nrn_update () { elisp("nrn-update") }
proc nrn_message () { printf("!&! %s\n",$s1) }
/*------------------------------------------------------------
User definable INITIALIZATION and FINISH routines
------------------------------------------------------------*/
// Default procedure - if initMisc1() doesn't exist in the run file
// Initializations performed prior to finitialize()
// This should contain point process inits and inits for any changes
// made to the NEURON block of any local mod file
proc initMisc1() { }
// Default procedure - if initMisc2() doesn't exist in the run file
// Initializations performed after finitialize()
proc initMisc2() { }
// Default procedure - if finishMisc() doesn't exist in the run file
proc finishMisc() { }
/*------------------------------------------------------------
Miscellaneous routines
------------------------------------------------------------*/
proc errorMsg() {
/* Print warning, assumes arg1 is string and arg2 if present is a
variable value */
sectionname(section)
if (numarg() == 0) {
printf("ERROR in errorMsg(): Needs at least 1 argument.\n")
} else if (numarg() == 1) {
printf("ERROR: %s in section %s.\n", $s1, section)
} else {
printf("ERROR: %s in section %s (var=%g).\n", $s1, section, $2)
}
}
proc clear() {
/* Clear non-interviews plot window */
plt(-3)
}
func mod() { local x, y
/* Mod function for non-integers */
x=$1
y=$2
return (x/y - int(x/y))
}
proc whatSection() {
/* Print name of section */
sectionname(section)
print section
}
proc print_pp_location() { local x //arg1 must be a point process
x = $o1.get_loc()
sectionname(temp_string_)
printf("%s located at %s(%g)\n", $o1, temp_string_, x)
pop_section()
}
//* Load local modifications to nrnoc.hoc and default.hoc
load_file("local.hoc")
if (xwindows && graph_flag) { nrnmainmenu() } // pwman_place(50,50)
print "Init complete.\n"