source: project/release/4/nemo/trunk/examples/Granule/Granule_DeSouza10.nemo @ 31318

Last change on this file since 31318 was 31318, checked in by Ivan Raikov, 6 years ago

nemo: fixes to granule cell build scripts

File size: 58.4 KB
Line 
1
2;; Reference: Cerebellar cortex oscillatory robustness from Golgi cell gap jncs (Simoes de Souza and De Schutter 2011)
3
4(nemo-model Granule
5
6  (
7   (input (v (unit mV))
8          (celsius (unit degC)))
9
10   (component (type defaults)
11      (const V_t = -35 (unit mV))
12      (const Ra = 0.01 (unit ohm.cm))
13      (const celsius = 30 (unit degC))
14      (output celsius V_t)
15      )
16
17   (component (type membrane-capacitance)
18         (const C_m  = 1 (unit uf/cm2))
19         (output C_m  ))
20
21
22   (component (type geometry) (name soma)
23         (const L = 11.8 (unit um))
24         (const diam = 11.8 (unit um))
25         (output L diam ))
26
27
28   (component (type post-synaptic-conductance) (name AMPA)
29
30        (input (w from event (unit uS)))
31
32        (const tauA = 0.03 (unit ms)) ;; rise time
33        (const tauB = 0.5 (unit ms)) ;; decay time
34
35        (const  e = 0 )
36
37        (const tau1 = (if ((tauA / tauB) > .9999) then (0.9999 * tauB) else tauA))
38        (const tau2 = tauB)
39
40        (const tp = ((tau1 * tau2) / (tau2 - tau1) * ln (tau2 / tau1)))
41        (const scale_factor  = (1 / (neg (exp(neg (tp) / tau1)) + exp (neg (tp) / tau2))))
42
43        (transient (A) = (neg (A) / tau1) (onevent (A + (w * scale_factor))) (initial 0))
44        (transient (B) = (neg (B) / tau2) (onevent (B + (w * scale_factor))) (initial 0))
45
46        (g =  (B - A))
47
48        (output g e scale_factor)
49
50      )
51
52
53   (component (type post-synaptic-conductance) (name GABA)
54
55        (input (w from event))
56
57        (const tauA = 0.31) ;; rise time
58        (const tauB = 8.8) ;; decay time
59
60        (const  e = -75)
61
62        (const tau1 = (if ((tauA / tauB) > .9999) then (0.9999 * tauB) else tauA))
63        (const tau2 = tauB)
64
65        (const tp = ((tau1 * tau2) / (tau2 - tau1) * ln (tau2 / tau1)))
66        (const scale_factor  = (1 / (neg (exp(neg (tp) / tau1)) + exp (neg (tp) / tau2))))
67
68        (transient (A) = (neg (A) / tau1) (onevent (A + (w * scale_factor))) (initial 0))
69        (transient (B) = (neg (B) / tau2) (onevent (B + (w * scale_factor))) (initial 0))
70
71        (g =  (B - A))
72
73        (output g e scale_factor)
74
75      )
76
77
78   (component (type post-synaptic-conductance) (name NMDA)
79
80        (input (w from event))
81
82        (const tauA = 1) ;; rise time
83        (const tauB = 13.3) ;; decay time
84
85        (const  e = 0)
86
87        (const tau1 = (if ((tauA / tauB) > .9999) then (0.9999 * tauB) else tauA))
88        (const tau2 = tauB)
89
90        (const tp = ((tau1 * tau2) / (tau2 - tau1) * ln (tau2 / tau1)))
91        (const scale_factor  = (1 / (neg (exp(neg (tp) / tau1)) + exp (neg (tp) / tau2))))
92
93        (transient (A) = (neg (A) / tau1) (onevent (A + (w * scale_factor))) (initial 0))
94        (transient (B) = (neg (B) / tau2) (onevent (B + (w * scale_factor))) (initial 0))
95
96        (g =  (B - A))
97
98        (output g e scale_factor)
99
100      )
101
102   (component (type decaying-pool) (name ca)
103
104      (input
105       (cai from ion-pools)
106       (ica from ion-currents))
107
108      (const  F       = 96485.3)
109      (const  d       = .2)
110      (const  cao     = 2.)
111      (const  cai0    = 1e-4)
112      (const  beta    = 1.5)
113     
114      (d (ca) =  ((neg (ica) / (2 * F * d)) * 1e4 -
115                  (beta * ((if (ca < cai0) then cai0 else ca) - cai0)))
116         (initial cai0))
117     
118      (output ca cao)
119      )
120
121   
122   (component (type ionic-current) (name CaHVA )
123             
124      (input
125       (cai from ion-pools)
126       (cao from ion-pools))
127             
128      (component (type gate)
129
130                 ;; rate constants
131                 
132                 (Q10 = (pow (3 ((celsius - 20) / 10))))
133                 
134                 (const Aalpha_s  = 0.04944)
135                 (const Kalpha_s  =  15.87301587302)
136                 (const V0alpha_s = -29.06)
137                 
138                 (const Abeta_s  = 0.08298)
139                 (const Kbeta_s  =  -25.641)
140                 (const V0beta_s = -18.66)
141                 
142                 (const Aalpha_u  = 0.0013)
143                 (const Kalpha_u  =  -18.183)
144                 (const V0alpha_u = -48)
145                         
146                 (const Abeta_u = 0.0013)
147                 (const Kbeta_u = 83.33)
148                 (const V0beta_u = -48)
149                 
150                 ;; rate functions
151                 
152                 (defun alpha_s (v Q10)
153                   (Q10 * Aalpha_s * exp((v - V0alpha_s) / Kalpha_s)))
154                 
155                 (defun beta_s (v Q10)
156                   (Q10 * Abeta_s * exp((v - V0beta_s) / Kbeta_s)))
157                 
158                 (defun alpha_u (v Q10)
159                   (Q10 * Aalpha_u * exp((v - V0alpha_u) / Kalpha_u)))
160                 
161                 (defun beta_u (v Q10)
162                   (Q10 * Abeta_u * exp((v - V0beta_u) / Kbeta_u)))
163
164                 (s_inf = ((alpha_s (v Q10))/(alpha_s (v Q10) + beta_s (v Q10))))
165                 (tau_s = (1 / (alpha_s (v Q10) + beta_s (v Q10)) ))
166
167                 (u_inf = ((alpha_u (v Q10))/(alpha_u (v Q10) + beta_u (v Q10)) ))
168                 (tau_u = (1 / (alpha_u (v Q10) + beta_u (v Q10)) ))
169
170                 (hh-ionic-gate
171                  (CaHVA  ;; ion name: exported variables will be of the form {ion}_{id}
172                   (initial-m  s_inf)
173                   (initial-h  u_inf)
174                   (m-power    2)
175                   (h-power    1)
176                   (m-inf      s_inf)
177                   (m-tau      tau_s)
178                   (h-inf      u_inf)
179                   (h-tau      tau_u)
180                   ))
181                 )
182     
183      (component (type pore)
184                 (const  gbar  = 0.00046)
185                 (output gbar ))
186     
187      (component (type permeating-ion) (name ca)
188                 (const F = 96485.3)
189                 (const R = 8.31342)
190                 (e = ((1e3) * (R * (celsius + 273.15)) / (2 * F) * ln (cao / cai)))
191                 (output e)
192                 )
193     
194      ) ;; end CaHVA current
195
196   (component (type voltage-clamp) (name CaHVA)
197             
198              (const vchold   = -71)
199              (const vcbase   = -69)
200              (const vcinc    = 10)
201              (const vcsteps  = 8)
202              (const vchdur   = 30)
203              (const vcbdur   = 100)
204
205              (component (type default-concentration) (name ca)
206                      (const cn       = 5e-5)
207                      (const cnout    = 2)
208                      (output cn cnout))
209             
210              (output vchold vcbase vcinc vcsteps vchdur vcbdur )
211
212              )
213
214
215
216   (component (type ionic-current) (name KA )
217
218              (defun sigm (x y) (1 / (exp (x / y) + 1)))
219             
220              (component (type gate)
221
222                         ;; rate constants
223
224                         (Q10 = (pow (3 ((celsius - 25.5) / 10))))
225
226                         (const Aalpha_a  = 0.8147)
227                         (const Kalpha_a  = -23.32708)
228                         (const V0alpha_a = -9.17203)
229                         (const Abeta_a   = 0.1655)
230                         (const Kbeta_a   = 19.47175)
231                         (const V0beta_a  = -18.27914)
232
233                         (const Aalpha_b  = 0.0368)
234                         (const Kalpha_b  = 12.8433)
235                         (const V0alpha_b = -111.33209)
236                         (const Abeta_b   = 0.0345)
237                         (const Kbeta_b   = -8.90123)
238                         (const V0beta_b  = -49.9537)
239
240                         (const V0_ainf = -38)
241                         (const  K_ainf = -17)
242
243                         (const V0_binf   = -78.8)
244                         (const K_binf    = 8.4)
245
246                         
247                         ;; rate functions
248
249                         (defun alpha_a (v Q10)
250                           (Q10 * Aalpha_a * sigm((v - V0alpha_a) Kalpha_a)))
251
252                         (defun beta_a (v Q10)
253                           (Q10 * (Abeta_a / exp((v - V0beta_a) / Kbeta_a))))
254
255                         (defun alpha_b (v Q10)
256                           (Q10 * Aalpha_b * sigm((v - V0alpha_b) Kalpha_b)))
257
258                         (defun beta_b (v Q10)
259                           (Q10 * Abeta_b * sigm((v - V0beta_b) Kbeta_b)))
260
261                         (a_inf = (1 / (1 + exp ((v - V0_ainf) / K_ainf))))
262                         (tau_a = (1 / (alpha_a (v Q10) + beta_a (v Q10)) ))
263                         (b_inf = (1 / (1 + exp ((v - V0_binf) / K_binf))))
264                         (tau_b = (1 / (alpha_b (v Q10) + beta_b (v Q10)) ))
265
266                         (hh-ionic-gate
267                          (KA  ;; ion name: exported variables will be of the form {ion}_{id}
268                           (initial-m  (1 / (1 + exp ((v - V0_ainf) / K_ainf))) )
269                           (initial-h  (1 / (1 + exp ((v - V0_binf) / K_binf))) )
270                           (m-power    3)
271                           (h-power    1)
272                           (m-inf      a_inf)
273                           (m-tau      tau_a)
274                           (h-inf      b_inf)
275                           (h-tau      tau_b)
276                           ))
277
278                         )
279
280                     
281              (component (type pore)
282                         (const  gbar  = 0.0032)
283                         (output gbar ))
284
285             
286              (component (type permeating-ion) (name k)
287                         (const e = -84.69)
288                         (output e ))
289             
290              ) ;; end KA current
291             
292
293              (component (type voltage-clamp) (name KA)
294           
295                         (const vchold   = -71)
296                         (const vcbase   = -69)
297                         (const vcinc    = 10)
298                         (const vcsteps  = 8)
299                         (const vchdur   = 30)
300                         (const vcbdur   = 100)
301           
302                         (output vchold vcbase vcinc vcsteps vchdur vcbdur)
303                         )
304   
305
306   (component (type ionic-current) (name KCa )
307
308
309      (input
310       (cai from ion-pools))
311
312             
313      (component (type gate)
314                 
315                 ;; rate constants
316                 (Q10 = (pow (3 ((celsius - 30) / 10))))
317                 
318                 (const Aalpha_c = 2.5)
319                 (const Balpha_c = 1.5e-3)
320                 
321                 (const Kalpha_c =  -11.765)
322                 
323                 (const Abeta_c = 1.5)
324                 (const Bbeta_c = 0.15e-3)
325
326                 (const Kbeta_c = -11.765)
327
328                 (cai1 = (if (cai < 1e-4) then 1e-4 else cai))
329
330                 ;; rate functions
331                 (defun alpha_c (v cai Q10)
332                   (Q10 * Aalpha_c / (1 + (Balpha_c * exp(v / Kalpha_c) / cai ))))
333                 
334                 (defun beta_c (v cai Q10)
335                   (Q10 * Abeta_c / (1 + (cai / (Bbeta_c * exp (v / Kbeta_c))) )))
336
337                 (c_inf = ((alpha_c (v cai Q10)) / (alpha_c (v cai Q10) + beta_c (v cai Q10)) ))
338                 (tau_c = (1 / (alpha_c (v cai Q10) + beta_c (v cai Q10)) ))
339
340                 (hh-ionic-gate
341                  (KCa  ;; ion name: exported variables will be of the form {ion}_{id}
342                   (initial-m  c_inf)
343                   (m-power    1)
344                   (h-power    0)
345                   (m-inf      c_inf)
346                   (m-tau      tau_c)
347                   ))
348                 
349                 )
350     
351      (component (type pore)
352                 (const  gbar  = 0.04)
353                 (output gbar ))
354     
355     
356      (component (type permeating-ion) (name k)
357                 (const e = -84.69)
358                 (output e ))
359     
360      (component (type modulating-ion) (name ca)
361                 )
362             
363      ) ;; end KCa current
364
365   (component (type voltage-clamp) (name KCa)
366             
367              (const vchold   = -71)
368              (const vcbase   = -69)
369              (const vcinc    = 10)
370              (const vcsteps  = 8)
371              (const vchdur   = 30)
372              (const vcbdur   = 100)
373
374              (const cnhold   = 1e-4)
375              (const cnbase   = 1e-4)
376              (const cninc    = 1e3)
377              (const cnsteps  = 1)
378              (const cnout    = 2)
379             
380              (output vchold vcbase vcinc vcsteps vchdur vcbdur
381                      cnhold cnbase cninc cnsteps cnout)
382              )
383
384
385
386   (component (type ionic-current) (name Kir )
387             
388              (component (type gate)
389
390                         ;; rate constants
391                         (Q10 = (pow (3 ((celsius - 20) / 10))))
392
393                         (const Aalpha_d = 0.13289)
394                         (const Kalpha_d = -24.3902)
395
396                         (const V0alpha_d = -83.94)
397                         (const Abeta_d   = 0.16994)
398
399                         (const Kbeta_d = 35.714)
400                         (const V0beta_d = -83.94)
401   
402                         ;; rate functions
403                         (defun alpha_d (v Q10)
404                           (Q10 * Aalpha_d * exp((v - V0alpha_d) / Kalpha_d)))
405                         
406                         (defun beta_d (v Q10)
407                           (Q10 * Abeta_d * exp((v - V0beta_d) / Kbeta_d) ))
408
409                         (d_inf = ((alpha_d (v Q10)) / (alpha_d (v Q10) + beta_d (v Q10)) ))
410                         (tau_d = (1 / (alpha_d (v Q10) + beta_d (v Q10)) ))
411
412                         (hh-ionic-gate
413                          (Kir  ;; ion name: exported variables will be of the form {ion}_{id}
414                           (initial-m  d_inf)
415                           (m-power    1)
416                           (h-power    0)
417                           (m-inf      (d_inf))
418                           (m-tau      (tau_d))
419                           ))
420                         
421                         )
422
423
424              (component (type pore)
425                         (const  gbar  = 0.0009)
426                         (output gbar ))
427
428             
429              (component (type permeating-ion) (name k)
430                         (const e = -84.69)
431                         (output e ))
432             
433              ) ;; end Kir current
434
435                     
436
437   (component (type voltage-clamp) (name Kir)
438             
439              (const vchold   = -71)
440              (const vcbase   = -69)
441              (const vcinc    = 10)
442              (const vcsteps  = 8)
443              (const vchdur   = 30)
444              (const vcbdur   = 100)
445             
446              (output vchold vcbase vcinc vcsteps vchdur vcbdur)
447              )
448
449
450   (component (type ionic-current) (name KM )
451             
452              (component (type gate)
453
454                         ;; rate constants
455                         (const Aalpha_n = 0.0033)
456
457                         (const Kalpha_n  = 40)
458                         (const V0alpha_n = -30)
459                         (const Abeta_n   = 0.0033)
460
461                         (const Kbeta_n  = -20)
462                         (const V0beta_n = -30)
463                         (const V0_ninf  = -35)
464                         (const   B_ninf = 6)
465                         
466                         (Q10 = (pow (3 ((celsius - 22) / 10))))
467                         
468                         ;; rate equations
469                         (defun alpha_n (v Q10)
470                           (Q10 * Aalpha_n * exp((v - V0alpha_n) / Kalpha_n) ))
471
472                         (defun beta_n (v Q10)
473                           (Q10 * Abeta_n * exp((v - V0beta_n) / Kbeta_n) ))
474
475                         (hh-ionic-gate
476                          (KM  ;; ion name: exported variables will be of the form {ion}_{id}
477                           (initial-m  (1 / (1 + exp((neg (v - V0_ninf)) / B_ninf))))
478                           (m-power    1)
479                           (h-power    0)
480                           (m-tau      (1 / (alpha_n(v Q10) + beta_n (v Q10)) ))
481                           (m-inf      (1 / (1 + exp((neg (v - V0_ninf)) / B_ninf))))
482                           ))
483                         )
484             
485              (component (type pore)
486                         (const  gbar  = 0.00025)
487                         (output gbar ))
488             
489              (component (type permeating-ion) (name k)
490                         (const e = -84.69)
491                         (output e ))
492             
493              ) ;; end KM current
494
495
496   (component (type voltage-clamp) (name KM)
497             
498              (const vchold   = -71)
499              (const vcbase   = -69)
500              (const vcinc    = 10)
501              (const vcsteps  = 8)
502              (const vchdur   = 30)
503              (const vcbdur   = 100)
504             
505              (output vchold vcbase vcinc vcsteps vchdur vcbdur)
506              )
507
508   (component (type ionic-current) (name KV )
509
510              (defun linoid (x y)
511                (if ((abs (x / y)) < 1e-6)
512                    then (y * (1 - ((x / y) / 2)))
513                    else (x / (exp (x / y) - 1))
514                    ))
515             
516              (component (type gate)
517
518                         ;; rate constants
519                         (Q10 = (pow (3 ((celsius - 6.3) / 10))))
520
521                         (const Aalpha_n = -0.01)
522                         (const Kalpha_n = -10)
523                         (const V0alpha_n = -25)
524                         (const Abeta_n = 0.125)
525       
526                         (const Kbeta_n = -80)
527                         (const V0beta_n = -35)
528
529                         ;; rate functions
530                         (defun alpha_n (v Q10)
531                           (Q10 * Aalpha_n * linoid ((v - V0alpha_n) Kalpha_n)))
532
533                         (defun beta_n (v Q10)
534                           (Q10 * Abeta_n * exp((v - V0beta_n) / Kbeta_n) ))
535
536
537                         (n_inf = ((alpha_n (v Q10)) / (alpha_n (v Q10) + beta_n (v Q10)) ))
538                         (tau_n = (1 / (alpha_n (v Q10) + beta_n (v Q10)) ))
539
540                         (hh-ionic-gate
541                          (KV  ;; ion name: exported variables will be of the form {ion}_{id}
542                           (initial-m  n_inf)
543                           (m-power    4)
544                           (h-power    0)
545                           (m-inf     (n_inf))
546                           (m-tau     (tau_n))
547                           ))
548                         )
549
550
551              (component (type pore)
552                         (const  gbar  = 0.003)
553                         (output gbar ))
554             
555              (component (type permeating-ion) (name k)
556                         (const e = -84.69)
557                         (output e ))
558             
559              ) ;; end KV current
560             
561
562   (component (type voltage-clamp) (name KV)
563             
564              (const vchold   = -71)
565              (const vcbase   = -69)
566              (const vcinc    = 10)
567              (const vcsteps  = 8)
568              (const vchdur   = 30)
569              (const vcbdur   = 100)
570             
571              (output vchold vcbase vcinc vcsteps vchdur vcbdur)
572              )
573             
574   
575   (component (type ionic-current) (name Lkg1)
576             
577              (component (type pore)
578                         (const  gbar  = (5.68e-5))
579                         (output gbar))
580             
581              (component (type permeating-ion) (name non-specific)
582                         (const e = -16.5)
583                         (output e ))
584             
585              ) ;; end leak current
586
587
588   (component (type ionic-current) (name Lkg2)
589             
590              (component (type pore)
591                         (const  ggaba  = (3e-5))
592                         (output ggaba))
593             
594              (component (type permeating-ion) (name non-specific)
595                         (const egaba = -65)
596                         (output egaba ))
597             
598              ) ;; end leak current
599
600
601   (component (type ionic-current) (name Na )
602             
603              (component (type gate)
604
605                         ;; rate constants
606                         (Q10 = (pow (3 ((celsius - 20) / 10))))
607
608                         (const Aalfa = 353.91)
609                         (const Valfa = 13.99)
610                         (const Abeta = 1.272)
611                         (const Vbeta = 13.99)
612                         (const Agamma = 150)
613                         (const Adelta = 40)
614                         (const Aepsilon = 1.75)
615                         (const Ateta = 0.0201)
616                         (const Vteta = 25)
617                         (const ACon = 0.005)
618                         (const ACoff = 0.5)
619                         (const AOon = 0.75)
620                         (const AOoff = 0.005)
621                         (const n1 = 5.422)
622                         (const n2 = 3.279)
623                         (const n3 = 1.83)
624                         (const n4 = 0.738)
625       
626                         (gamma = (Q10 * Agamma))
627                         (delta = (Q10 * Adelta))
628                         (epsilon = (Q10 * Aepsilon))
629                         (Con = (Q10 * ACon))
630                         (Coff = (Q10 * ACoff))
631                         (Oon = (Q10 * AOon))
632                         (Ooff = (Q10 * AOoff))
633                         (a = (pow ((Oon / Con) (1.0 / 4.0))))
634                         (b = (pow ((Ooff / Coff) (1.0 / 4.0))))
635
636                         ;; rate functions
637                         (defun alfa (v Q10)   
638                           (Q10 * Aalfa * exp (v / Valfa)))
639
640                         (defun beta (v Q10)
641                           (Q10 * Abeta * exp (neg (v) / Vbeta)))
642
643                         (defun teta (v Q10)
644                           (Q10 * Ateta * exp (neg (v) / Vteta)))
645                               
646
647                         (reaction
648                          (Na_z
649                           (transitions
650                            (<-> C1 C2 (n1 * alfa (v Q10)) (n4 * beta (v Q10)))
651                            (<-> C2 C3 (n2 * alfa (v Q10)) (n3 * beta (v Q10)))
652                            (<-> C3 C4 (n3 * alfa (v Q10)) (n2 * beta (v Q10)))
653                            (<-> C4 C5 (n4 * alfa (v Q10)) (n1 * beta (v Q10)))
654                            (<-> C5 O  gamma delta)
655                            (<-> O  B  epsilon (teta (v Q10)))
656
657                            (<-> I1 I2 (n1 * alfa (v Q10) * a) (n4 * beta (v Q10) * b))
658                            (<-> I2 I3 (n2 * alfa (v Q10) * a) (n3 * beta (v Q10) * b))
659                            (<-> I3 I4 (n3 * alfa (v Q10) * a) (n2 * beta (v Q10) * b))
660                            (<-> I4 I5 (n4 * alfa (v Q10) * a) (n1 * beta (v Q10) * b))
661                            (<-> I5 I6 gamma delta)
662
663                            (<-> C1 I1 Con Coff)
664                            (<-> C2 I2 (Con * a) (Coff * b))
665                            (<-> C3 I3 (Con * pow (a 2)) (Coff * pow (b 2)))
666                            (<-> C4 I4 (Con * pow (a 3)) (Coff * pow (b 3)))
667                            (<-> C5 I5 (Con * pow (a 4)) (Coff * pow (b 4)))
668
669                            (O <-> I6 Oon Ooff))
670                           
671                           (conserve ((1 = (C1 + C2 + C3 + C4 + C5 + O + B + I1 + I2 + I3 + I4 + I5 + I6))))
672                     
673                           (open O)   (power 1)))
674
675                         (output Na_z ) 
676
677                         )
678             
679              (component (type pore)
680                         (const  gbar  = 0.013)
681                         (output gbar ))
682
683             
684              (component (type permeating-ion) (name na)
685                         (const e = 87.39)
686                         (output e ))
687             
688              ) ;; end Na current
689
690   (component (type voltage-clamp) (name Na)
691
692              (const vchold   = -71)
693              (const vcbase   = -60)
694              (const vcinc    = 10)
695              (const vcsteps  = 9)
696              (const vchdur   = 30)
697              (const vcbdur   = 100)
698           
699              (output vchold vcbase vcinc vcsteps vchdur vcbdur))
700
701      )
702
703;; Following are templates for various driver scripts used to run this model
704   (
705    (".hoc" () 
706#<<EOF
707
708create soma
709access soma
710
711insert {{model_name}}
712
713soma {
714        nseg = 1
715
716{% with diam = default(diam, 11.8), L = default(L, 11.8) %}
717        diam = {{diam}}
718        L = {{L}}
719{% endwith %}
720
721        cm = 1
722
723        Ra = 100
724    }
725EOF
726)
727
728    ("template.hoc" () 
729#<<EOF
730
731begintemplate GC
732public soma
733
734create soma
735
736proc init() {
737
738  soma {
739     
740    nseg=1
741
742{% with diam = default(diam, 11.8), L = default(L, 11.8) %}
743    diam = {{diam}}
744    L = {{L}}
745{% endwith %}
746
747    Ra=100
748    cm=1
749    celsius = 30
750
751    insert {{model_name}}_CaHVA
752    insert {{model_name}}_ca
753    insert {{model_name}}_KA
754    insert {{model_name}}_KCa
755    insert {{model_name}}_Kir   
756    insert {{model_name}}_KM
757    insert {{model_name}}_KV
758    insert {{model_name}}_Lkg1
759    insert {{model_name}}_Lkg2
760    insert {{model_name}}_Na
761
762   }
763}
764
765endtemplate GC
766
767
768EOF
769)
770
771    ("syn_template.hoc" () 
772#<<EOF
773
774begintemplate GC
775
776public soma, syn, nclist
777
778objref syn[5]
779objref nclist
780
781create soma
782
783proc init() {
784
785nclist = new List()
786   
787
788soma {
789     
790    nseg=1
791
792{% with diam = default(diam, 11.8), L = default(L, 11.8) %}
793    diam = {{diam}}
794    L = {{L}}
795{% endwith %}
796
797    Ra=100
798    cm=1
799    celsius = 30
800
801    insert {{model_name}}_CaHVA
802    insert {{model_name}}_ca
803    insert {{model_name}}_KA
804    insert {{model_name}}_KCa
805    insert {{model_name}}_Kir   
806    insert {{model_name}}_KM
807    insert {{model_name}}_KV
808    insert {{model_name}}_Lkg1
809    insert {{model_name}}_Lkg2
810    insert {{model_name}}_Na
811   
812}
813
814for i=0,4 {
815    syn[i] = new Granule_AMPA(0)
816}
817
818}
819
820endtemplate GC
821
822EOF
823)
824
825
826    ("protocol.hoc" () 
827
828#<<EOF
829
830// Load the Granule cell template
831
832xopen("{{model_name}}_template.hoc")
833
834objref gc
835gc = new GC()
836
837v_init = -70
838
839celsius = 30
840
841{% with tstop = default(tstop, 1000) %}
842tstop = {{tstop}} // for IClamp
843{% endwith %}
844
845dt = 0.025
846
847stim_amp=0.01875
848
849objectvar stim
850gc.soma stim = new IClamp(0.5)
851stim.del = 1000
852stim.dur = 1850
853stim.amp = stim_amp
854 
855objref rec_v
856rec_v = new Vector()
857rec_v.record (&gc.soma.v(0.5))
858
859objref rec_t
860rec_t = new Vector()
861rec_t.record (&t)
862
863dt = 0.025
864tstop = 3000
865run()
866
867objref output_file
868output_file = new File()
869output_file.wopen("{{model_name}}.dat")
870
871for (i=0; i < rec_v.size(); i=i+1) {
872  output_file.printf("%g %g\n", rec_t.x[i], rec_v.x[i])
873}
874
875output_file.close()
876quit()
877       
878
879EOF
880)
881
882    ("netstim_protocol.hoc" () 
883#<<EOF
884load_file("nrngui.hoc")
885
886load_file( "{{model_name}}_syn_template.hoc" )
887
888objref gc
889gc = new GC()
890
891prelength = 1000
892mainlength = 6000
893
894
895//**********************************************************************
896proc simulate() { local preDT, mainDT, logsize  localobj logfile, tlog, Vlog, iklog, inalog, icalog, ica2log
897   
898    mainDT = 0.025
899    preDT = 0.025
900   
901    dt = preDT
902    tstop = prelength
903    run()
904   
905   
906    if ( stoprun == 1) return
907   
908    dt = mainDT
909    continuerun(prelength + mainlength)
910    if ( stoprun == 1) return
911   
912    logfile=$o1
913    tlog=$o2
914    Vlog=$o3
915    iklog=$o4
916    inalog=$o5
917    icalog=$o6
918   
919    logsize = tlog.size()
920   
921    for i=0,tlog.size()-1 {
922        logfile.printf("%g %g %g %g %g\n", tlog.x[i], Vlog.x[i], iklog.x[i], inalog.x[i], icalog.x[i])
923    }
924
925}
926
927
928//*************User-Interface*******************************************
929
930nrnsecmenu(0.5, 1)
931
932xpanel("Spontaneous firing")
933xvalue("Time for Initialization", "prelength")
934xvalue("Main duration", "mainlength")
935
936xvalue("dt", "dt")
937xvalue("t", "t")
938xlabel("")
939xbutton("Start", "simulate()")
940xbutton("Stop", "stoprun = 1")
941xpanel()
942
943vec_sizes = (prelength+mainlength)/dt + 1       // recorded traces are all this size
944
945strdef logfn
946objref ns, iklog, inalog, icalog, Vlog, tlog, logfile
947
948objref stim_rates // input stimulus rates
949
950nrates = 5
951stim_rates = new Vector (nrates)
952stim_rates.x[0] = 1
953stim_rates.x[1] = 20
954stim_rates.x[2] = 50
955stim_rates.x[3] = 100
956stim_rates.x[4] = 200
957
958for (k=0; k < nrates; k = k + 1) {
959
960  ns = new NetStim()
961  ns.start    = 1000
962  ns.number   = 100000
963  ns.noise    = 1
964  ns.interval = (1 / stim_rates.x[k]) * 1000
965
966  gc.nclist.append (new NetCon(ns,gc.syn[0],-20,1,0.1))
967  gc.nclist.append (new NetCon(ns,gc.syn[1],-20,12,0.1))
968  gc.nclist.append (new NetCon(ns,gc.syn[2],-20,15,0.1))
969  gc.nclist.append (new NetCon(ns,gc.syn[3],-20,17,0.1))
970  gc.nclist.append (new NetCon(ns,gc.syn[4],-20,19,0.1))
971
972  iklog = new Vector(vec_sizes)
973  iklog.record (&gc.soma.ik(0.5))
974
975  inalog = new Vector(vec_sizes)
976  inalog.record (&gc.soma.ina(0.5))
977
978  icalog = new Vector(vec_sizes)
979  icalog.record (&gc.soma.ica(0.5))
980
981  Vlog = new Vector(vec_sizes)
982  Vlog.record (&gc.soma.v(0.5))
983
984  tlog = new Vector(vec_sizes,0)
985  tlog.record (&t)
986
987  sprint (logfn, "Granule_netstim_protocol_%d_Hz.dat", stim_rates.x[k] )
988
989  logfile = new File()
990  logfile.wopen ( logfn  )
991
992  simulate(logfile,tlog,Vlog,iklog,inalog,icalog)
993  logfile.close()
994}
995
996quit()
997EOF
998)
999
1000
1001
1002    ("octave_odepkg_run.m" () 
1003
1004#<<EOF
1005
1006## {{model_name}} model driver for Octave/odepkg
1007
1008{{model_name}}_defs = "{{model_name}}.m";
1009
1010autoload ("{{model_name}}", {{model_name}}_defs );
1011autoload ("{{model_name}}_init", {{model_name}}_defs );
1012
1013{{model_name}}_init;
1014
1015global celsius cai
1016
1017
1018{% with cai = default(cai, 1e-4), celsius = default(celsius, 30) %}
1019cai = {{cai}} ;
1020celsius = {{celsius}} ;
1021{% endwith %}
1022
1023y0 = {{model_name}}_init(-70)
1024
1025{% with tstop = default(tstop, 300) %}
1026tstop = {{tstop}} ;
1027{% endwith %}
1028
1029t0 = 0.0;
1030t1 = tstop;
1031
1032dt = 1e-3;
1033
1034reltol=1e-2;
1035abstol=1e-2;
1036
1037function y = step (x, k)
1038  y = 1 ./ (1 + exp(-2 * k * x));
1039end
1040
1041function y = stepp (x, k)
1042  y = 2 ./ (1 + exp(2 * k * x));
1043end
1044
1045function i = ifn(t,k,hc,cc,t1,t2)
1046  i = hc + (cc - hc) .* step(t - t1,k) .* step(t2 - t,k);
1047endfunction
1048
1049function [dy] = my{{model_name}}(t, y)
1050
1051  [dy] = {{model_name}}(t, y);
1052
1053  i_stim = ifn(t,3,0,0.01875,10,290);
1054 
1055  dy(1) = dy(1) + i_stim;
1056
1057endfunction
1058
1059
1060P = odeset ('RelTol', reltol, 'AbsTol', abstol, 'MaxStep', 1e-1, 'InitialStep', dt,
1061           "OutputFcn", @odeplot);
1062sol = ode2r (@my{{model_name}}, [t0 t1], y0, P);
1063
1064ys = [sol.x sol.y];
1065
1066N = size(ys)(1);
1067{{model_name}}_v = [ys(:,1) ys(:,2)];
1068save -ascii "{{model_name}}_v.dat" {{model_name}}_v;
1069
1070EOF
1071)
1072
1073
1074    ("nestmodule_bootstrap.sh" () 
1075#<<EOF
1076#!/bin/sh
1077
1078echo "Bootstrapping Granule module..."
1079
1080if test -d autom4te.cache ; then
1081# we must remove this cache, because it
1082# may screw up things if configure is run for
1083# different platforms.
1084  echo "  -> Removing old automake cache ..."
1085  rm -rf autom4te.cache
1086fi
1087
1088echo "  -> Running aclocal ..."
1089aclocal
1090
1091echo "  -> Running libtoolize ..."
1092if [ `uname -s` = Darwin ] ; then
1093# libtoolize is glibtoolize on OSX
1094  LIBTOOLIZE=glibtoolize
1095else 
1096  LIBTOOLIZE=libtoolize
1097fi
1098
1099libtool_major=`$LIBTOOLIZE --version | head -n1 | cut -d\) -f2 | cut -d\. -f1`
1100$LIBTOOLIZE --force --copy --ltdl
1101
1102echo "  -> Re-running aclocal ..."
1103if test $libtool_major -le 2; then
1104  aclocal --force
1105else
1106  aclocal --force -I $(pwd)/libltdl/m4
1107fi
1108
1109echo "  -> Running autoconf ..."
1110autoconf
1111
1112# autoheader must run before automake
1113echo "  -> Running autoheader ..."
1114autoheader
1115
1116echo "  -> Running automake ..."
1117automake --foreign --add-missing --force-missing --copy
1118
1119echo "Done."
1120
1121EOF
1122)
1123
1124    ("nestmodule_configure_gsl.ac" () 
1125#<<EOF
1126AC_PREREQ(2.52)
1127
1128AC_INIT(granulemodule, 1.0, raikov@oist.jp)
1129
1130# These variables are exported to include/config.h
1131GRANULEMODULE_MAJOR=1
1132GRANULEMODULE_MINOR=0
1133GRANULEMODULE_PATCHLEVEL=0
1134
1135# Exporting source and build directories requires full path names.
1136# Thus we have to expand.
1137# Here, we are in top build dir, since source dir must exist, we can just
1138# move there and call pwd
1139if test "x$srcdir" = x ; then
1140  PKGSRCDIR=`pwd`
1141else
1142  PKGSRCDIR=`cd $srcdir && pwd`
1143fi
1144PKGBUILDDIR=`pwd`
1145
1146# If this is not called, install-sh will be put into .. by bootstrap.sh
1147# moritz, 06-26-06
1148AC_CONFIG_AUX_DIR(.)
1149
1150AM_INIT_AUTOMAKE(nest, $GRANULEMODULE_VERSION)
1151
1152# obtain host system type; HEP 2004-12-20
1153AC_CANONICAL_HOST
1154
1155# ------------------------------------------------------------------------
1156# Handle options
1157#
1158# NOTE: No programs/compilations must be run in this section;
1159#       otherwise CFLAGS and CXXFLAGS may take on funny default
1160#       values.
1161#       HEP 2004-12-20
1162# ------------------------------------------------------------------------
1163
1164# nest-config
1165NEST_CONFIG=`which nest-config`
1166AC_ARG_WITH(nest,[  --with-nest=script  nest-config script including path],
1167[
1168  if test "$withval" != yes; then
1169    NEST_CONFIG=$withval
1170  else
1171    AC_MSG_ERROR([--with-nest-config expects the nest-config script as argument. See README for details.])
1172  fi
1173])
1174
1175# -------------------------------------------
1176# END Handle options
1177# -------------------------------------------
1178
1179
1180# does nest-config work
1181AC_MSG_CHECKING([for nest-config ])
1182AC_CHECK_FILE($NEST_CONFIG, HAVE_NEST=yes,
1183              AC_MSG_ERROR([No usable nest-config was found. You may want to use --with-nest-config.]))
1184AC_MSG_RESULT(found)
1185
1186# the following will crash if nest-config does not run
1187# careful, lines below must not break
1188AC_MSG_CHECKING([for NEST directory information ])
1189NEST_PREFIX=`$NEST_CONFIG --prefix`
1190NEST_CPPFLAGS=`$NEST_CONFIG --cflags`
1191NEST_COMPILER=`$NEST_CONFIG --compiler`
1192if test $prefix = NONE; then prefix=`$NEST_CONFIG --prefix`; fi
1193AC_MSG_RESULT($NEST_CPPFLAGS)
1194
1195
1196# Set the platform-dependent compiler flags based on the canonical
1197# host string.  These flags are placed in AM_{C,CXX}FLAGS.  If
1198# {C,CXX}FLAGS are given as environment variables, then they are
1199# appended to the set of automatically chosen flags.  After
1200# {C,CXX}FLAGS have been read out, they must be cleared, since
1201# system-dependent defaults will otherwise be placed into the
1202# Makefiles.  HEP 2004-12-20.
1203
1204# Before we can determine the proper compiler flags, we must know
1205# which compiler we are using.  Since the pertaining AC macros run the
1206# compiler and set CFLAGS, CXXFLAGS to system-dependent values, we
1207# need to save command line/enviroment settings of these variables
1208# first. AC_AIX must run before the compiler is run, so we must run it
1209# here.
1210# HEP 2004-12-21
1211
1212GRANULEMODULE_SAVE_CXXFLAGS=$CXXFLAGS
1213
1214# Must first check if we are on AIX
1215AC_AIX
1216
1217# Check for C++ compiler, looking for the same compiler
1218# used with NEST
1219AC_PROG_CXX([ $NEST_COMPILER ])
1220
1221# the following is makeshift, should have the macro set proper
1222# GRANULEMODULE_SET_CXXFLAGS
1223AM_CXXFLAGS=$GRANULEMODULE_SAVE_CXXFLAGS
1224CXXFLAGS=
1225
1226## Configure C environment
1227
1228AC_PROG_LD
1229AC_PROG_INSTALL
1230
1231AC_LIBLTDL_CONVENIENCE     ## put libltdl into a convenience library
1232AC_PROG_LIBTOOL            ## use libtool
1233AC_CONFIG_SUBDIRS(libltdl) ## also configure subdir containing libltdl
1234
1235#-- Set the language to C++
1236AC_LANG_CPLUSPLUS
1237
1238#-- Look for programs needed in the Makefile
1239AC_PROG_CXXCPP
1240AM_PROG_LIBTOOL
1241AC_PATH_PROGS([MAKE],[gmake make],[make])
1242
1243# ---------------------------------------------------------------
1244# Configure directories to be built
1245# ---------------------------------------------------------------
1246
1247PKGDATADIR=$datadir/$PACKAGE
1248PKGDOCDIR=$datadir/doc/$PACKAGE
1249
1250# set up directories from which to build help
1251# second line replaces space with colon as separator
1252HELPDIRS="$PKGSRCDIR $PKGSRCDIR/sli"
1253HELPDIRS=`echo $HELPDIRS | tr " " ":"`
1254
1255#-- Replace these variables in *.in
1256AC_SUBST(HAVE_NEST)
1257AC_SUBST(NEST_CONFIG)
1258AC_SUBST(NEST_CPPFLAGS)
1259AC_SUBST(NEST_COMPILER)
1260AC_SUBST(NEST_PREFIX)
1261AC_SUBST(HELPDIRS)
1262AC_SUBST(PKGSRCDIR)
1263AC_SUBST(PKGBUILDDIR)
1264AC_SUBST(PKGDATADIR)
1265AC_SUBST(PKGDOCDIR)
1266AC_SUBST(KERNEL)
1267AC_SUBST(HOST)
1268AC_SUBST(SED)
1269AC_SUBST(LD)
1270AC_SUBST(host_os)
1271AC_SUBST(host_cpu)
1272AC_SUBST(host_vendor)
1273AC_SUBST(AS)
1274AC_SUBST(CXX)
1275AC_SUBST(AR)
1276AC_SUBST(ARFLAGS)
1277AC_SUBST(CXX_AR)
1278AC_SUBST(AM_CXXFLAGS)
1279AC_SUBST(AM_CFLAGS)
1280AC_SUBST(MAKE)
1281AC_SUBST(MAKE_FLAGS)
1282AC_SUBST(INCLTDL)
1283AC_SUBST(LIBLTDL)
1284
1285AM_CONFIG_HEADER(granulemodule_config.h:granulemodule_config.h.in)
1286AC_CONFIG_FILES(Makefile)
1287
1288# -----------------------------------------------
1289# Create output
1290# -----------------------------------------------
1291AC_OUTPUT
1292
1293
1294# -----------------------------------------------
1295# Report, after output at end of configure run
1296# Must come after AC_OUTPUT, so that it is
1297# displayed after libltdl has been configured
1298# -----------------------------------------------
1299
1300echo
1301echo "-------------------------------------------------------"
1302echo "Granule module Configuration Summary"
1303echo "-------------------------------------------------------"
1304echo
1305echo "C++ compiler        : $CXX"
1306echo "C++ compiler flags  : $AM_CXXFLAGS"
1307echo "NEST compiler flags : $NEST_CPPFLAGS"
1308
1309# these variables will still contain '${prefix}'
1310# we want to have the versions where this is resolved, too:
1311eval eval eval  PKGDOCDIR_AS_CONFIGURED=$PKGDOCDIR
1312eval eval eval  PKGDATADIR_AS_CONFIGURED=$PKGDATADIR
1313
1314echo
1315echo "-------------------------------------------------------"
1316echo
1317echo "You can build and install Granule module now, using"
1318echo "  make"
1319echo "  make install"
1320echo
1321echo "Granule module will be installed to:"
1322echo -n "  "; eval eval echo "$libdir"
1323echo
1324
1325EOF
1326)
1327
1328    ("nestmodule_configure_cvode.ac" () 
1329#<<EOF
1330AC_PREREQ(2.52)
1331
1332AC_INIT(granulemodule, 1.0, raikov@oist.jp)
1333
1334# These variables are exported to include/config.h
1335GRANULEMODULE_MAJOR=1
1336GRANULEMODULE_MINOR=0
1337GRANULEMODULE_PATCHLEVEL=0
1338
1339# Exporting source and build directories requires full path names.
1340# Thus we have to expand.
1341# Here, we are in top build dir, since source dir must exist, we can just
1342# move there and call pwd
1343if test "x$srcdir" = x ; then
1344  PKGSRCDIR=`pwd`
1345else
1346  PKGSRCDIR=`cd $srcdir && pwd`
1347fi
1348PKGBUILDDIR=`pwd`
1349
1350# If this is not called, install-sh will be put into .. by bootstrap.sh
1351# moritz, 06-26-06
1352AC_CONFIG_AUX_DIR(.)
1353
1354AM_INIT_AUTOMAKE(nest, $GRANULEMODULE_VERSION)
1355
1356# obtain host system type; HEP 2004-12-20
1357AC_CANONICAL_HOST
1358
1359# ------------------------------------------------------------------------
1360# Handle options
1361#
1362# NOTE: No programs/compilations must be run in this section;
1363#       otherwise CFLAGS and CXXFLAGS may take on funny default
1364#       values.
1365#       HEP 2004-12-20
1366# ------------------------------------------------------------------------
1367
1368# nest-config
1369NEST_CONFIG=`which nest-config`
1370AC_ARG_WITH(nest,[  --with-nest=script  nest-config script including path],
1371[
1372  if test "$withval" != yes; then
1373    NEST_CONFIG=$withval
1374  else
1375    AC_MSG_ERROR([--with-nest-config expects the nest-config script as argument. See README for details.])
1376  fi
1377])
1378
1379# -------------------------------------------
1380# END Handle options
1381# -------------------------------------------
1382
1383# sundials-config
1384SUNDIALS_CONFIG=`which sundials-config`
1385AC_ARG_WITH(sundials,[  --with-sundials=script  sundials-config script including path],
1386[
1387  if test "$withval" != yes; then
1388    SUNDIALS_CONFIG=$withval
1389#  else
1390#    AC_MSG_ERROR([--with-sundials-config expects the sundials-config script as argument. See README for details.])
1391  fi
1392])
1393
1394
1395# does nest-config work
1396AC_MSG_CHECKING([for nest-config ])
1397AC_CHECK_FILE($NEST_CONFIG, HAVE_NEST=yes,
1398              AC_MSG_ERROR([No usable nest-config was found. You may want to use --with-nest-config.]))
1399AC_MSG_RESULT(found)
1400
1401AC_MSG_CHECKING([for sundials-config ])
1402AC_CHECK_FILE($SUNDIALS_CONFIG, HAVE_SUNDIALS=yes,
1403              AC_MSG_WARN([No usable sundials-config was found. You may want to use --with-sundials-config.]))
1404AC_MSG_RESULT(found)
1405
1406# the following will crash if nest-config does not run
1407# careful, lines below must not break
1408AC_MSG_CHECKING([for NEST directory information ])
1409NEST_PREFIX=`$NEST_CONFIG --prefix`
1410NEST_CPPFLAGS=`$NEST_CONFIG --cflags`
1411NEST_COMPILER=`$NEST_CONFIG --compiler`
1412if test $prefix = NONE; then prefix=`$NEST_CONFIG --prefix`; fi
1413AC_MSG_RESULT($NEST_CPPFLAGS)
1414
1415
1416AC_MSG_CHECKING([for SUNDIALS preprocessor flags ])
1417SUNDIALS_CPPFLAGS="`$SUNDIALS_CONFIG -m cvode -t s -l c -s cppflags`"
1418AC_MSG_RESULT($SUNDIALS_CPPFLAGS)
1419
1420AC_MSG_CHECKING([for SUNDIALS linker options ])
1421SUNDIALS_LDFLAGS="`$SUNDIALS_CONFIG -m cvode -t s -l c -s libs` -lblas -llapack"
1422AC_MSG_RESULT($SUNDIALS_LDFLAGS)
1423
1424# Set the platform-dependent compiler flags based on the canonical
1425# host string.  These flags are placed in AM_{C,CXX}FLAGS.  If
1426# {C,CXX}FLAGS are given as environment variables, then they are
1427# appended to the set of automatically chosen flags.  After
1428# {C,CXX}FLAGS have been read out, they must be cleared, since
1429# system-dependent defaults will otherwise be placed into the
1430# Makefiles.  HEP 2004-12-20.
1431
1432# Before we can determine the proper compiler flags, we must know
1433# which compiler we are using.  Since the pertaining AC macros run the
1434# compiler and set CFLAGS, CXXFLAGS to system-dependent values, we
1435# need to save command line/enviroment settings of these variables
1436# first. AC_AIX must run before the compiler is run, so we must run it
1437# here.
1438# HEP 2004-12-21
1439
1440GRANULEMODULE_SAVE_CXXFLAGS=$CXXFLAGS
1441
1442# Must first check if we are on AIX
1443AC_AIX
1444
1445# Check for C++ compiler, looking for the same compiler
1446# used with NEST
1447AC_PROG_CXX([ $NEST_COMPILER ])
1448
1449# the following is makeshift, should have the macro set proper
1450# GRANULEMODULE_SET_CXXFLAGS
1451AM_CXXFLAGS=$GRANULEMODULE_SAVE_CXXFLAGS
1452CXXFLAGS=
1453
1454## Configure C environment
1455
1456AC_PROG_LD
1457AC_PROG_INSTALL
1458
1459AC_LIBLTDL_CONVENIENCE     ## put libltdl into a convenience library
1460AC_PROG_LIBTOOL            ## use libtool
1461AC_CONFIG_SUBDIRS(libltdl) ## also configure subdir containing libltdl
1462
1463#-- Set the language to C++
1464AC_LANG_CPLUSPLUS
1465
1466#-- Look for programs needed in the Makefile
1467AC_PROG_CXXCPP
1468AM_PROG_LIBTOOL
1469AC_PATH_PROGS([MAKE],[gmake make],[make])
1470
1471# ---------------------------------------------------------------
1472# Configure directories to be built
1473# ---------------------------------------------------------------
1474
1475PKGDATADIR=$datadir/$PACKAGE
1476PKGDOCDIR=$datadir/doc/$PACKAGE
1477
1478# set up directories from which to build help
1479# second line replaces space with colon as separator
1480HELPDIRS="$PKGSRCDIR $PKGSRCDIR/sli"
1481HELPDIRS=`echo $HELPDIRS | tr " " ":"`
1482
1483#-- Replace these variables in *.in
1484AC_SUBST(HAVE_NEST)
1485AC_SUBST(NEST_CONFIG)
1486AC_SUBST(NEST_CPPFLAGS)
1487AC_SUBST(NEST_COMPILER)
1488AC_SUBST(NEST_PREFIX)
1489AC_SUBST(HELPDIRS)
1490AC_SUBST(PKGSRCDIR)
1491AC_SUBST(PKGBUILDDIR)
1492AC_SUBST(PKGDATADIR)
1493AC_SUBST(PKGDOCDIR)
1494AC_SUBST(KERNEL)
1495AC_SUBST(HOST)
1496AC_SUBST(SED)
1497AC_SUBST(LD)
1498AC_SUBST(host_os)
1499AC_SUBST(host_cpu)
1500AC_SUBST(host_vendor)
1501AC_SUBST(AS)
1502AC_SUBST(CXX)
1503AC_SUBST(AR)
1504AC_SUBST(ARFLAGS)
1505AC_SUBST(CXX_AR)
1506AC_SUBST(AM_CXXFLAGS)
1507AC_SUBST(AM_CFLAGS)
1508AC_SUBST(MAKE)
1509AC_SUBST(MAKE_FLAGS)
1510AC_SUBST(INCLTDL)
1511AC_SUBST(LIBLTDL)
1512AC_SUBST(SUNDIALS_CONFIG)
1513AC_SUBST(SUNDIALS_CPPFLAGS)
1514AC_SUBST(SUNDIALS_LDFLAGS)
1515
1516AM_CONFIG_HEADER(granulemodule_config.h:granulemodule_config.h.in)
1517AC_CONFIG_FILES(Makefile)
1518
1519# -----------------------------------------------
1520# Create output
1521# -----------------------------------------------
1522AC_OUTPUT
1523
1524
1525# -----------------------------------------------
1526# Report, after output at end of configure run
1527# Must come after AC_OUTPUT, so that it is
1528# displayed after libltdl has been configured
1529# -----------------------------------------------
1530
1531echo
1532echo "-------------------------------------------------------"
1533echo "Granule module Configuration Summary"
1534echo "-------------------------------------------------------"
1535echo
1536echo "C++ compiler        : $CXX"
1537echo "C++ compiler flags  : $AM_CXXFLAGS"
1538echo "NEST compiler flags : $NEST_CPPFLAGS"
1539echo "SUNDIALS compiler flags : $SUNDIALS_CPPFLAGS"
1540echo "SUNDIALS linker flags : $SUNDIALS_LDFLAGS"
1541
1542# these variables will still contain '${prefix}'
1543# we want to have the versions where this is resolved, too:
1544eval eval eval  PKGDOCDIR_AS_CONFIGURED=$PKGDOCDIR
1545eval eval eval  PKGDATADIR_AS_CONFIGURED=$PKGDATADIR
1546
1547echo
1548echo "-------------------------------------------------------"
1549echo
1550echo "You can build and install Granule module now, using"
1551echo "  make"
1552echo "  make install"
1553echo
1554echo "Granule module will be installed to:"
1555echo -n "  "; eval eval echo "$libdir"
1556echo
1557
1558EOF
1559)
1560
1561    ("nestmodule_configure_ida.ac" () 
1562#<<EOF
1563AC_PREREQ(2.52)
1564
1565AC_INIT(granulemodule, 1.0, raikov@oist.jp)
1566
1567# These variables are exported to include/config.h
1568GRANULEMODULE_MAJOR=1
1569GRANULEMODULE_MINOR=0
1570GRANULEMODULE_PATCHLEVEL=0
1571
1572# Exporting source and build directories requires full path names.
1573# Thus we have to expand.
1574# Here, we are in top build dir, since source dir must exist, we can just
1575# move there and call pwd
1576if test "x$srcdir" = x ; then
1577  PKGSRCDIR=`pwd`
1578else
1579  PKGSRCDIR=`cd $srcdir && pwd`
1580fi
1581PKGBUILDDIR=`pwd`
1582
1583# If this is not called, install-sh will be put into .. by bootstrap.sh
1584# moritz, 06-26-06
1585AC_CONFIG_AUX_DIR(.)
1586
1587AM_INIT_AUTOMAKE(nest, $GRANULEMODULE_VERSION)
1588
1589# obtain host system type; HEP 2004-12-20
1590AC_CANONICAL_HOST
1591
1592# ------------------------------------------------------------------------
1593# Handle options
1594#
1595# NOTE: No programs/compilations must be run in this section;
1596#       otherwise CFLAGS and CXXFLAGS may take on funny default
1597#       values.
1598#       HEP 2004-12-20
1599# ------------------------------------------------------------------------
1600
1601# nest-config
1602NEST_CONFIG=`which nest-config`
1603AC_ARG_WITH(nest,[  --with-nest=script  nest-config script including path],
1604[
1605  if test "$withval" != yes; then
1606    NEST_CONFIG=$withval
1607  else
1608    AC_MSG_ERROR([--with-nest-config expects the nest-config script as argument. See README for details.])
1609  fi
1610])
1611
1612# -------------------------------------------
1613# END Handle options
1614# -------------------------------------------
1615
1616# sundials-config
1617SUNDIALS_CONFIG=`which sundials-config`
1618AC_ARG_WITH(sundials,[  --with-sundials=script  sundials-config script including path],
1619[
1620  if test "$withval" != yes; then
1621    SUNDIALS_CONFIG=$withval
1622#  else
1623#    AC_MSG_ERROR([--with-sundials-config expects the sundials-config script as argument. See README for details.])
1624  fi
1625])
1626
1627
1628# does nest-config work
1629AC_MSG_CHECKING([for nest-config ])
1630AC_CHECK_FILE($NEST_CONFIG, HAVE_NEST=yes,
1631              AC_MSG_ERROR([No usable nest-config was found. You may want to use --with-nest-config.]))
1632AC_MSG_RESULT(found)
1633
1634AC_MSG_CHECKING([for sundials-config ])
1635AC_CHECK_FILE($SUNDIALS_CONFIG, HAVE_SUNDIALS=yes,
1636              AC_MSG_WARN([No usable sundials-config was found. You may want to use --with-sundials-config.]))
1637AC_MSG_RESULT(found)
1638
1639# the following will crash if nest-config does not run
1640# careful, lines below must not break
1641AC_MSG_CHECKING([for NEST directory information ])
1642NEST_PREFIX=`$NEST_CONFIG --prefix`
1643NEST_CPPFLAGS=`$NEST_CONFIG --cflags`
1644NEST_COMPILER=`$NEST_CONFIG --compiler`
1645if test $prefix = NONE; then prefix=`$NEST_CONFIG --prefix`; fi
1646AC_MSG_RESULT($NEST_CPPFLAGS)
1647
1648
1649AC_MSG_CHECKING([for SUNDIALS preprocessor flags ])
1650SUNDIALS_CPPFLAGS="`$SUNDIALS_CONFIG -m ida -t s -l c -s cppflags`"
1651AC_MSG_RESULT($SUNDIALS_CPPFLAGS)
1652
1653AC_MSG_CHECKING([for SUNDIALS linker options ])
1654SUNDIALS_LDFLAGS="`$SUNDIALS_CONFIG -m ida -t s -l c -s libs` -lblas -llapack"
1655AC_MSG_RESULT($SUNDIALS_LDFLAGS)
1656
1657# Set the platform-dependent compiler flags based on the canonical
1658# host string.  These flags are placed in AM_{C,CXX}FLAGS.  If
1659# {C,CXX}FLAGS are given as environment variables, then they are
1660# appended to the set of automatically chosen flags.  After
1661# {C,CXX}FLAGS have been read out, they must be cleared, since
1662# system-dependent defaults will otherwise be placed into the
1663# Makefiles.  HEP 2004-12-20.
1664
1665# Before we can determine the proper compiler flags, we must know
1666# which compiler we are using.  Since the pertaining AC macros run the
1667# compiler and set CFLAGS, CXXFLAGS to system-dependent values, we
1668# need to save command line/enviroment settings of these variables
1669# first. AC_AIX must run before the compiler is run, so we must run it
1670# here.
1671# HEP 2004-12-21
1672
1673GRANULEMODULE_SAVE_CXXFLAGS=$CXXFLAGS
1674
1675# Must first check if we are on AIX
1676AC_AIX
1677
1678# Check for C++ compiler, looking for the same compiler
1679# used with NEST
1680AC_PROG_CXX([ $NEST_COMPILER ])
1681
1682# the following is makeshift, should have the macro set proper
1683# GRANULEMODULE_SET_CXXFLAGS
1684AM_CXXFLAGS=$GRANULEMODULE_SAVE_CXXFLAGS
1685CXXFLAGS=
1686
1687## Configure C environment
1688
1689AC_PROG_LD
1690AC_PROG_INSTALL
1691
1692AC_LIBLTDL_CONVENIENCE     ## put libltdl into a convenience library
1693AC_PROG_LIBTOOL            ## use libtool
1694AC_CONFIG_SUBDIRS(libltdl) ## also configure subdir containing libltdl
1695
1696#-- Set the language to C++
1697AC_LANG_CPLUSPLUS
1698
1699#-- Look for programs needed in the Makefile
1700AC_PROG_CXXCPP
1701AM_PROG_LIBTOOL
1702AC_PATH_PROGS([MAKE],[gmake make],[make])
1703
1704# ---------------------------------------------------------------
1705# Configure directories to be built
1706# ---------------------------------------------------------------
1707
1708PKGDATADIR=$datadir/$PACKAGE
1709PKGDOCDIR=$datadir/doc/$PACKAGE
1710
1711# set up directories from which to build help
1712# second line replaces space with colon as separator
1713HELPDIRS="$PKGSRCDIR $PKGSRCDIR/sli"
1714HELPDIRS=`echo $HELPDIRS | tr " " ":"`
1715
1716#-- Replace these variables in *.in
1717AC_SUBST(HAVE_NEST)
1718AC_SUBST(NEST_CONFIG)
1719AC_SUBST(NEST_CPPFLAGS)
1720AC_SUBST(NEST_COMPILER)
1721AC_SUBST(NEST_PREFIX)
1722AC_SUBST(HELPDIRS)
1723AC_SUBST(PKGSRCDIR)
1724AC_SUBST(PKGBUILDDIR)
1725AC_SUBST(PKGDATADIR)
1726AC_SUBST(PKGDOCDIR)
1727AC_SUBST(KERNEL)
1728AC_SUBST(HOST)
1729AC_SUBST(SED)
1730AC_SUBST(LD)
1731AC_SUBST(host_os)
1732AC_SUBST(host_cpu)
1733AC_SUBST(host_vendor)
1734AC_SUBST(AS)
1735AC_SUBST(CXX)
1736AC_SUBST(AR)
1737AC_SUBST(ARFLAGS)
1738AC_SUBST(CXX_AR)
1739AC_SUBST(AM_CXXFLAGS)
1740AC_SUBST(AM_CFLAGS)
1741AC_SUBST(MAKE)
1742AC_SUBST(MAKE_FLAGS)
1743AC_SUBST(INCLTDL)
1744AC_SUBST(LIBLTDL)
1745AC_SUBST(SUNDIALS_CONFIG)
1746AC_SUBST(SUNDIALS_CPPFLAGS)
1747AC_SUBST(SUNDIALS_LDFLAGS)
1748
1749AM_CONFIG_HEADER(granulemodule_config.h:granulemodule_config.h.in)
1750AC_CONFIG_FILES(Makefile)
1751
1752# -----------------------------------------------
1753# Create output
1754# -----------------------------------------------
1755AC_OUTPUT
1756
1757
1758# -----------------------------------------------
1759# Report, after output at end of configure run
1760# Must come after AC_OUTPUT, so that it is
1761# displayed after libltdl has been configured
1762# -----------------------------------------------
1763
1764echo
1765echo "-------------------------------------------------------"
1766echo "Granule module Configuration Summary"
1767echo "-------------------------------------------------------"
1768echo
1769echo "C++ compiler        : $CXX"
1770echo "C++ compiler flags  : $AM_CXXFLAGS"
1771echo "NEST compiler flags : $NEST_CPPFLAGS"
1772echo "SUNDIALS compiler flags : $SUNDIALS_CPPFLAGS"
1773echo "SUNDIALS linker flags : $SUNDIALS_LDFLAGS"
1774
1775# these variables will still contain '${prefix}'
1776# we want to have the versions where this is resolved, too:
1777eval eval eval  PKGDOCDIR_AS_CONFIGURED=$PKGDOCDIR
1778eval eval eval  PKGDATADIR_AS_CONFIGURED=$PKGDATADIR
1779
1780echo
1781echo "-------------------------------------------------------"
1782echo
1783echo "You can build and install Granule module now, using"
1784echo "  make"
1785echo "  make install"
1786echo
1787echo "Granule module will be installed to:"
1788echo -n "  "; eval eval echo "$libdir"
1789echo
1790
1791EOF
1792)
1793
1794    ("nestmodule_makefile_gsl.am" () 
1795#<<EOF
1796
1797# Automake file for external dynamic modules for NEST
1798#
1799# Hans Ekkehard Plesser, April 2008
1800# Automake file for the Developer Module
1801#
1802# libgranulemodule is built as a normal, installable library.
1803# It will be installed to $prefix/lib by make install.
1804#
1805# Headers from this directory are not to be installed upon
1806# make install. They are therefore included in _SOURCES.
1807
1808
1809libdir= @libdir@/nest
1810
1811lib_LTLIBRARIES=      granulemodule.la libgranulemodule.la
1812
1813granulemodule_la_CXXFLAGS= @AM_CXXFLAGS@
1814granulemodule_la_SOURCES=  granulemodule.cpp      granulemodule.h      \
1815                      Granule.cpp Granule.h
1816granulemodule_la_LDFLAGS=  -module
1817
1818libgranulemodule_la_CXXFLAGS= $(granulemodule_la_CXXFLAGS) -DLINKED_MODULE
1819libgranulemodule_la_SOURCES=  $(granulemodule_la_SOURCES)
1820
1821MAKEFLAGS= @MAKE_FLAGS@
1822
1823AM_CPPFLAGS= @NEST_CPPFLAGS@ \
1824             @INCLTDL@     
1825
1826AM_LDFLAGS =
1827
1828.PHONY: install-slidoc
1829
1830nobase_pkgdata_DATA=\
1831        granulemodule.sli
1832
1833install-slidoc:
1834        NESTRCFILENAME=/dev/null $(DESTDIR)$(NEST_PREFIX)/bin/sli --userargs="@HELPDIRS@" $(NEST_PREFIX)/share/nest/sli/install-help.sli
1835
1836install-data-hook: install-exec install-slidoc
1837
1838EXTRA_DIST= sli
1839
1840EOF
1841)
1842
1843    ("nestmodule_makefile_sundials.am" () 
1844#<<EOF
1845
1846# Automake file for external dynamic modules for NEST
1847#
1848# Hans Ekkehard Plesser, April 2008
1849# Automake file for the Developer Module
1850#
1851# libgranulemodule is built as a normal, installable library.
1852# It will be installed to $prefix/lib by make install.
1853#
1854# Headers from this directory are not to be installed upon
1855# make install. They are therefore included in _SOURCES.
1856
1857
1858libdir= @libdir@/nest
1859
1860lib_LTLIBRARIES=      granulemodule.la libgranulemodule.la
1861
1862granulemodule_la_CXXFLAGS= @AM_CXXFLAGS@
1863granulemodule_la_SOURCES=  granulemodule.cpp      granulemodule.h      \
1864                      Granule.cpp Granule.h
1865granulemodule_la_LDFLAGS=  -module
1866
1867libgranulemodule_la_CXXFLAGS= $(granulemodule_la_CXXFLAGS) -DLINKED_MODULE
1868libgranulemodule_la_SOURCES=  $(granulemodule_la_SOURCES)
1869
1870MAKEFLAGS= @MAKE_FLAGS@
1871
1872AM_CPPFLAGS= @NEST_CPPFLAGS@ \
1873             @SUNDIALS_CPPFLAGS@ \
1874             @INCLTDL@     
1875
1876AM_LDFLAGS = @SUNDIALS_LDFLAGS@
1877
1878.PHONY: install-slidoc
1879
1880nobase_pkgdata_DATA=\
1881        granulemodule.sli
1882
1883install-slidoc:
1884        NESTRCFILENAME=/dev/null $(DESTDIR)$(NEST_PREFIX)/bin/sli --userargs="@HELPDIRS@" $(NEST_PREFIX)/share/nest/sli/install-help.sli
1885
1886install-data-hook: install-exec install-slidoc
1887
1888EXTRA_DIST= sli
1889
1890EOF
1891)
1892
1893    ("nestmodule.cpp" () 
1894#<<EOF
1895/*
1896 *  granulemodule.cpp
1897 *  This file is part of NEST.
1898 *
1899 *  Copyright (C) 2008 by
1900 *  The NEST Initiative
1901 *
1902 *  See the file AUTHORS for details.
1903 *
1904 *  Permission is granted to compile and modify
1905 *  this file for non-commercial use.
1906 *  See the file LICENSE for details.
1907 *
1908 */
1909
1910// include necessary NEST headers
1911//#include "config.h"
1912#include "network.h"
1913#include "model.h"
1914#include "dynamicloader.h"
1915#include "genericmodel.h"
1916#include "generic_connector.h"
1917#include "booldatum.h"
1918#include "integerdatum.h"
1919#include "tokenarray.h"
1920#include "exceptions.h"
1921#include "sliexceptions.h"
1922#include "nestmodule.h"
1923
1924// include headers with your own stuff
1925#include "granulemodule.h"
1926#include "Granule.h"
1927
1928// -- Interface to dynamic module loader ---------------------------------------
1929
1930/*
1931 * The dynamic module loader must be able to find your module.
1932 * You make the module known to the loader by defining an instance of your
1933 * module class in global scope. This instance must have the name
1934 *
1935 * <modulename>_LTX_mod
1936 *
1937 * The dynamicloader can then load modulename and search for symbol "mod" in it.
1938 */
1939 
1940granulenest::GranuleModule granulemodule_LTX_mod;
1941
1942// -- DynModule functions ------------------------------------------------------
1943
1944granulenest::GranuleModule::GranuleModule()
1945  {
1946#ifdef LINKED_MODULE
1947     // register this module at the dynamic loader
1948     // this is needed to allow for linking in this module at compile time
1949     // all registered modules will be initialized by the main app's dynamic loader
1950     nest::DynamicLoaderModule::registerLinkedModule(this);
1951#endif     
1952   }
1953
1954granulenest::GranuleModule::~GranuleModule()
1955   {
1956   }
1957
1958   const std::string granulenest::GranuleModule::name(void) const
1959   {
1960     return std::string("Granule Module"); // Return name of the module
1961   }
1962
1963   const std::string granulenest::GranuleModule::commandstring(void) const
1964   {
1965     /* 1. Tell interpreter that we provide the C++ part of GranuleModule with the
1966           current revision number.
1967        2. Instruct the interpreter to check that granulemodule-init.sli exists,
1968           provides at least version 1.0 of the SLI interface to GranuleModule, and
1969           to load it.
1970      */
1971     return std::string("");
1972   }
1973
1974   /* BeginDocumentation
1975      Name: StepPatternConnect - Connect sources and targets with a stepping pattern
1976     
1977      Synopsis:
1978      [sources] source_step [targets] target_step synmod StepPatternConnect -> n_connections
1979     
1980      Parameters:
1981      [sources]     - Array containing GIDs of potential source neurons
1982      source_step   - Make connection from every source_step'th neuron
1983      [targets]     - Array containing GIDs of potential target neurons
1984      target_step   - Make connection to every target_step'th neuron
1985      synmod        - The synapse model to use (literal, must be key in synapsedict)
1986      n_connections - Number of connections made
1987     
1988      Description:
1989      This function subsamples the source and target arrays given with steps
1990      source_step and target_step, beginning with the first element in each array,
1991      and connects the selected nodes.
1992     
1993      Example:
1994      /first_src 0 /network_size get def
1995      /last_src /iaf_neuron 20 Create def  % nodes  1 .. 20
1996      /src [first_src last_src] Range def
1997      /last_tgt /iaf_neuron 10 Create def  % nodes 21 .. 30
1998      /tgt [last_src 1 add last_tgt] Range def
1999     
2000      src 6 tgt 4 /drop_odd_spike StepPatternConnect
2001 
2002      This connects nodes [1, 7, 13, 19] as sources to nodes [21, 25,
2003      29] as targets using synapses of type drop_odd_spike, and
2004      returning 12 as the number of connections.  The following
2005      command will print the connections (you must paste the SLI
2006      command as one long line):
2007
2008      src { /s Set << /source s /synapse_type /static_synapse >> FindConnections { GetStatus /target get } Map dup length 0 gt { cout s <- ( -> ) <- exch <-- endl } if ; } forall
2009      1 -> [21 25 29]
2010      7 -> [21 25 29]
2011      13 -> [21 25 29]
2012      19 -> [21 25 29]
2013     
2014      Remark:
2015      This function is only provided as an example for how to write your own
2016      interface function.
2017     
2018      Author:
2019      Hans Ekkehard Plesser
2020     
2021      SeeAlso:
2022      Connect, ConvergentConnect, DivergentConnect
2023   */
2024   void granulenest::GranuleModule::StepPatternConnect_Vi_i_Vi_i_lFunction::execute(SLIInterpreter *i) const
2025   {
2026     // Check if we have (at least) five arguments on the stack.
2027     i->assert_stack_load(5);
2028
2029     // Retrieve source, source step, target, target step from the stack
2030     const TokenArray sources = getValue<TokenArray> (i->OStack.pick(4)); // bottom
2031     const long src_step      = getValue<long>       (i->OStack.pick(3));
2032     const TokenArray targets = getValue<TokenArray> (i->OStack.pick(2));
2033     const long tgt_step      = getValue<long>       (i->OStack.pick(1)); 
2034     const Name synmodel_name = getValue<std::string>(i->OStack.pick(0)); // top
2035     
2036     // Obtain synapse model index
2037     const Token synmodel
2038       = nest::NestModule::get_network().get_synapsedict().lookup(synmodel_name);
2039     if ( synmodel.empty() )
2040       throw nest::UnknownSynapseType(synmodel_name.toString());
2041     const nest::index synmodel_id = static_cast<nest::index>(synmodel);
2042
2043     // Build a list of targets with the given step
2044     TokenArray selected_targets;
2045     for ( size_t t = 0 ; t < targets.size() ; t += tgt_step )
2046       selected_targets.push_back(targets[t]);
2047     
2048     // Now connect all appropriate sources to this list of targets
2049     size_t Nconn = 0;  // counts connections
2050     for ( size_t s = 0 ; s < sources.size() ; s += src_step )
2051     {
2052       // We must first obtain the GID of the source as integer
2053       const nest::long_t sgid = getValue<nest::long_t>(sources[s]);
2054
2055       // nest::network::divergent_connect() requires weight and delay arrays. We want to use
2056       // default values from the synapse model, so we pass empty arrays.
2057       nest::NestModule::get_network().divergent_connect(sgid, selected_targets,
2058                                                         TokenArray(), TokenArray(),
2059                                                         synmodel_id);
2060       Nconn += selected_targets.size();
2061     }
2062
2063     // We get here only if none of the operations above throws and exception.
2064     // Now we can safely remove the arguments from the stack and push Nconn
2065     // as our result.
2066     i->OStack.pop(5);
2067     i->OStack.push(Nconn);
2068     
2069     // Finally, we pop the call to this functions from the execution stack.
2070     i->EStack.pop();
2071   }
2072
2073  //-------------------------------------------------------------------------------------
2074
2075  void granulenest::GranuleModule::init(SLIInterpreter *i, nest::Network*)
2076  {
2077    /* Register a neuron or device model.
2078       Give node type as template argument and the name as second argument.
2079       The first argument is always a reference to the network.
2080       Return value is a handle for later unregistration.
2081    */
2082       nest::register_model<nest::Granule>(nest::NestModule::get_network(),
2083                                            "Granule");
2084
2085
2086    /* Register a SLI function.
2087       The first argument is the function name for SLI, the second a pointer to
2088       the function object. If you do not want to overload the function in SLI,
2089       you do not need to give the mangled name. If you give a mangled name, you
2090       should define a type trie in the granulemodule-init.sli file.
2091    */
2092    i->createcommand("StepPatternConnect_Vi_i_Vi_i_l",
2093                     &stepPatternConnect_Vi_i_Vi_i_lFunction);
2094
2095  }  // GranuleModule::init()
2096
2097 
2098
2099EOF
2100)
2101
2102    ("nestmodule.h" () 
2103#<<EOF
2104/*
2105 *  granulemodule.h
2106 *
2107 *  This file is part of NEST.
2108 *
2109 *  Copyright (C) 2008 by
2110 *  The NEST Initiative
2111 *
2112 *  See the file AUTHORS for details.
2113 *
2114 *  Permission is granted to compile and modify
2115 *  this file for non-commercial use.
2116 *  See the file LICENSE for details.
2117 *
2118 */
2119
2120#ifndef GRANULEMODULE_H
2121#define GranuleMODULE_H
2122
2123#include "dynmodule.h"
2124#include "slifunction.h"
2125
2126namespace nest
2127{
2128  class Network;
2129}
2130
2131// Put your stuff into your own namespace.
2132namespace granulenest {
2133 
2134/**
2135 * Class defining your model.
2136 * @note For each model, you must define one such class, with a unique name.
2137 */
2138class GranuleModule : public DynModule
2139{
2140public:
2141
2142  // Interface functions ------------------------------------------
2143 
2144  /**
2145   * @note The constructor registers the module with the dynamic loader.
2146   *       Initialization proper is performed by the init() method.
2147   */
2148  GranuleModule();
2149 
2150  /**
2151   * @note The destructor does not do much in modules. Proper "downrigging"
2152   *       is the responsibility of the unregister() method.
2153   */
2154  ~GranuleModule();
2155
2156  /**
2157   * Initialize module by registering models with the network.
2158   * @param SLIInterpreter* SLI interpreter
2159   * @param nest::Network*  Network with which to register models
2160   * @note  Parameter Network is needed for historical compatibility
2161   *        only.
2162   */
2163  void init(SLIInterpreter*, nest::Network*);
2164
2165  /**
2166   * Return the name of your model.
2167   */
2168  const std::string name(void) const;
2169 
2170  /**
2171   * Return the name of a sli file to execute when granulemodule is loaded.
2172   * This mechanism can be used to define SLI commands associated with your
2173   * module, in particular, set up type tries for functions you have defined.
2174   */
2175  const std::string commandstring(void) const;
2176     
2177public:
2178 
2179  // Classes implementing your functions -----------------------------
2180 
2181  /**
2182   * Implement a function for a step-pattern-based connection.
2183   * @note What this function does is described in the SLI documentation
2184   *       in the cpp file.
2185   * @note The mangled name indicates this function expects the following
2186   *       arguments on the stack (bottom first): vector of int, int,
2187   *       vector of int, int.
2188   * @note You must define a member object in your module class
2189   *       of the function class. execute() is later invoked on this
2190   *       member.
2191   */
2192  class StepPatternConnect_Vi_i_Vi_i_lFunction: public SLIFunction
2193     {
2194     public:
2195       void execute(SLIInterpreter *) const;
2196     };
2197
2198     StepPatternConnect_Vi_i_Vi_i_lFunction stepPatternConnect_Vi_i_Vi_i_lFunction;
2199  };
2200} // namespace granulenest
2201
2202#endif
2203
2204EOF
2205)
2206
2207    ("granulemodule.sli" () 
2208#<<EOF
2209/*
2210 * Initialization file for GranuleModule.
2211 * Run automatically when GranuleModule is loaded.
2212 */
2213
2214M_DEBUG (granulemodule.sli) (Initializing SLI support for GranuleModule.) message
2215
2216/StepPatternConnect [ /arraytype /integertype /arraytype /integertype /literaltype ]
2217{
2218  StepPatternConnect_Vi_i_Vi_i_l
2219} def
2220
2221EOF
2222)
2223
2224    ("testrun.sli" () 
2225#<<EOF
2226/dt 0.025 def
2227
2228ResetKernel
22290
2230 <<
2231   /resolution  dt
2232 >> SetStatus
2233
2234(granulemodule) Install
2235/neuron /Granule Create def
2236/stepinput /step_current_generator Create def
2237/vlog /voltmeter Create def
2238/vlog_parameters << /interval dt /to_file true /to_memory false >> def
2239vlog vlog_parameters SetStatus
2240
2241/evlog /spike_detector Create def
2242/evlog_parameters << /withtime true /precise_times true /to_file true >> def
2243evlog evlog_parameters SetStatus
2244
2245stepinput neuron Connect
2246vlog neuron Connect
2247neuron evlog Connect
2248
2249/step_current_parameters << /amplitude_times [0.0 1000.0 2850.0] /amplitude_values [0.0 18.75 0.0 ] >> def
2250stepinput step_current_parameters SetStatus
2251
22523000.0 Simulate
2253
2254EOF
2255)
2256
2257
2258    ("netstim.sli" () 
2259#<<EOF
2260
2261(granulemodule) Install
2262
2263[ 1.0 20.0 50.0 100.0 200.0 ]
2264
2265{
2266
2267/i exch def
2268
2269(Granule_netstim_) i cvs (_Hz) join join /label exch def
2270
2271/dt 0.025 def
2272
2273/seeds 0 /total_num_virtual_procs get array 1 add def
2274
2275ResetKernel
22760
2277 <<
2278   /resolution  dt
2279   /rng_seeds seeds
2280 >> SetStatus
2281
2282/neuron /Granule Create def
2283/neuron_params << /V_m -65.0 >> def
2284neuron neuron_params SetStatus
2285
2286/input1 /poisson_generator Create def
2287/input2 /poisson_generator Create def
2288/input3 /poisson_generator Create def
2289/input4 /poisson_generator Create def
2290/input5 /poisson_generator Create def
2291
2292/vlog /voltmeter Create def
2293
2294/poisson_parameters1 << /rate i Hz /start 1000.0 >> def
2295input1 poisson_parameters1 SetStatus
2296
2297/poisson_parameters2 << /rate i Hz /start 1000.0 >> def
2298input2 poisson_parameters2 SetStatus
2299
2300/poisson_parameters3 << /rate i Hz /start 1000.0 >> def
2301input3 poisson_parameters3 SetStatus
2302
2303/poisson_parameters4 << /rate i Hz /start 1000.0 >> def
2304input4 poisson_parameters4 SetStatus
2305
2306/poisson_parameters5 << /rate i Hz /start 1000.0 >> def
2307input5 poisson_parameters5 SetStatus
2308
2309/vlog_parameters << /interval dt /label label /to_file true  /to_memory false >> def
2310vlog vlog_parameters SetStatus
2311
2312/ampa_receptor neuron GetStatus /receptor_types get /AMPA get def
2313
2314/conn_parameters1 << /receptor_type ampa_receptor /weight 0.1 /delay 1.0 >> def
2315input1 neuron conn_parameters1 Connect
2316
2317/conn_parameters2 << /receptor_type ampa_receptor /weight 0.1 /delay 12.0 >> def
2318input2 neuron conn_parameters2 Connect
2319
2320/conn_parameters3 << /receptor_type ampa_receptor /weight 0.1 /delay 15.0 >> def
2321input3 neuron conn_parameters3 Connect
2322
2323/conn_parameters4 << /receptor_type ampa_receptor /weight 0.1 /delay 17.0 >> def
2324input4 neuron conn_parameters4 Connect
2325
2326/conn_parameters5 << /receptor_type ampa_receptor /weight 0.1 /delay 19.0 >> def
2327input5 neuron conn_parameters5 Connect
2328       
2329vlog neuron Connect
2330
23316000.0 Simulate
2332
2333i
2334}
2335Map
2336EOF
2337)
2338
2339
2340) ;; end template declarations
2341     
2342)
Note: See TracBrowser for help on using the repository browser.