NEURON
synapse.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 /* /local/src/master/nrn/src/nrnoc/synapse.cpp,v 1.2 1997/08/15 13:04:13 hines Exp */
3 /* modified from fstim.cpp */
4 
5 /*
6 fsyn(maxnum)
7  allocates space for maxnum synapses. Space for
8  previously existing synapses is released. All synapses initialized to
9  0 maximum conductance.
10 
11 fsyn(i, loc, delay, tau, gmax, erev)
12  The ith synapse is injected at parameter `loc'
13  different synapses do not concatenate but can ride on top of
14  each other. delay refers to onset of synapse relative to t=0
15  delay and duration are in msec.
16  stim in namps.
17 
18  a synaptic current defined by
19  i = g * (v - erev) i(nanoamps), g(microsiemens);
20  where
21  g = 0 for t < delay and
22  g = gmax * (t - delay)/tau * exp(-(t - delay - tau)/tau)
23  for t > onset
24  this has the property that the maximum value is gmax and occurs at
25  t = delay + tau.
26 
27 fsyni(i)
28  returns synaptic current for ith synapse at the value of the
29  global time t in units of nanoamps.
30 
31 fsyng(i)
32  returns synaptic conductance for ith synapse at the value of the
33  global time t.
34 
35 */
36 
37 #include <stdlib.h>
38 #include "neuron.h"
39 #include "section.h"
40 #include "nrniv_mf.h"
41 #include <math.h>
42 
43 
44 #define nt_t nrn_threads->_t
45 
46 /* impress the stimulus code to do synapses */
47 typedef struct Stimulus {
48  double loc; /* parameter location (0--1) */
49  double delay; /* value of t in msec for onset */
50  double duration; /* turns off at t = delay + duration */
51  double mag; /* conductance in microsiemens */
52  double erev;
53  double mag_seg; /* value added to rhs, depends on area of seg*/
54  double g; /* holds conductance when current calculated */
55  Node* pnd; /* segment location */
56  Section* sec;
58 
59 static int maxstim = 0; /* size of stimulus array */
60 static Stimulus* pstim; /* pointer to stimulus array */
61 static void free_syn(void);
62 
63 static void stim_record(int);
64 
65 void print_syn(void) {
66  int i;
67 
68  if (maxstim == 0)
69  return;
70  /*SUPPRESS 440*/
71  Printf("fsyn(%d)\n/* section fsyn( #, loc, delay(ms), tau(ms), conduct(uS), erev(mV)) */\n",
72  maxstim);
73  for (i = 0; i < maxstim; i++) {
74  Printf("%-15s fsyn(%2d,%4g,%10g,%8g,%14g,%9g)\n",
75  secname(pstim[i].sec),
76  i,
77  pstim[i].loc,
78  pstim[i].delay,
79  pstim[i].duration,
80  pstim[i].mag,
81  pstim[i].erev);
82  }
83 }
84 
85 static double alpha(double x) {
86  if (x > 0.0 && x < 10.0) {
87  return x * exp(-x + 1.0);
88  }
89  return 0.0;
90 }
91 
92 
93 static double stimulus(int i) {
94  double x, g;
95 
96  if ((g = pstim[i].mag_seg) == 0.0) {
97  pstim[i].g = 0.0;
98  return 0.0;
99  }
100 #if CVODE
101  at_time(nrn_threads, pstim[i].delay);
102 #endif
103  x = (nt_t - pstim[i].delay) / pstim[i].duration;
104  pstim[i].g = g * alpha(x);
105  return pstim[i].g * (NODEV(pstim[i].pnd) - pstim[i].erev);
106 }
107 
108 void fsyni(void) {
109  int i;
110  double cur;
111 
112  i = chkarg(1, 0., (double) (maxstim - 1));
113  if ((cur = stimulus(i)) != 0.) {
114  cur *= pstim[i].mag / pstim[i].mag_seg;
115  }
116  hoc_retpushx(cur);
117 }
118 
119 void fsyng(void) {
120  int i;
121  double g = 0.0;
122 
123  i = chkarg(1, 0., (double) (maxstim - 1));
124  IGNORE(stimulus(i));
125  g = pstim[i].g;
126  if (g != 0.) {
127  g *= pstim[i].mag / pstim[i].mag_seg;
128  }
129  hoc_retpushx(g);
130 }
131 
132 void fsyn(void) {
133  int i;
134 
135  if (nrn_nthread > 1) {
136  hoc_execerror("fsyn does not allow threads", "");
137  }
138  i = chkarg(1, 0., 10000.);
139  if (ifarg(2)) {
140  if (i >= maxstim) {
141  hoc_execerror("index out of range", (char*) 0);
142  }
143  pstim[i].loc = chkarg(2, 0., 1.);
144  pstim[i].delay = chkarg(3, 0., 1e21);
145  pstim[i].duration = chkarg(4, 0., 1e21);
146  pstim[i].mag = *getarg(5);
147  pstim[i].erev = *getarg(6);
148  pstim[i].sec = chk_access();
150  stim_record(i);
151  } else {
152  free_syn();
153  maxstim = i;
154  if (maxstim) {
155  pstim = (Stimulus*) emalloc((unsigned) (maxstim * sizeof(Stimulus)));
156  }
157  for (i = 0; i < maxstim; i++) {
158  pstim[i].loc = 0;
159  pstim[i].mag = 0.;
160  pstim[i].delay = 1e20;
161  pstim[i].duration = 0.;
162  pstim[i].erev = 0.;
163  pstim[i].sec = 0;
164  stim_record(i);
165  }
166  }
167  hoc_retpushx(0.);
168 }
169 
170 static void free_syn(void) {
171  int i;
172  if (maxstim) {
173  for (i = 0; i < maxstim; ++i) {
174  if (pstim[i].sec) {
176  }
177  }
178  free((char*) pstim);
179  maxstim = 0;
180  }
181 }
182 
183 static void stim_record(int i) /*fill in the section info*/
184 {
185  double area;
186  Section* sec;
187 
188  sec = pstim[i].sec;
189  if (sec) {
190  if (sec->prop) {
191  pstim[i].pnd = node_ptr(sec, pstim[i].loc, &area);
192  pstim[i].mag_seg = 1.e2 * pstim[i].mag / area;
193  } else {
195  pstim[i].sec = 0;
196  }
197  }
198 }
199 
200 void synapse_prepare(void) {
201  int i;
202 
203  for (i = 0; i < maxstim; i++) {
204  stim_record(i);
205  }
206 }
207 
208 void activsynapse_rhs(void) {
209  int i;
210  for (i = 0; i < maxstim; i++) {
211  if (pstim[i].sec) {
212  NODERHS(pstim[i].pnd) -= stimulus(i);
213  }
214  }
215 }
216 
218  int i;
219 
220  for (i = 0; i < maxstim; i++) {
221  if (pstim[i].sec) {
222  NODED(pstim[i].pnd) += pstim[i].g;
223  }
224  }
225 }
const char * secname(Section *sec)
Definition: cabcode.cpp:1776
Node * node_ptr(Section *sec, double x, double *parea)
Definition: cabcode.cpp:1986
Section * chk_access(void)
Definition: cabcode.cpp:444
static double * duration
Definition: clamp.cpp:37
static Node * pnd
Definition: clamp.cpp:33
double chkarg(int, double low, double high)
Definition: code2.cpp:638
#define cur
Definition: eion.cpp:364
#define erev
Definition: eion.cpp:361
at_time
Definition: extargs.h:1
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:754
void hoc_retpushx(double x)
Definition: hocusr.cpp:154
#define getarg
Definition: hocdec.h:15
int ifarg(int)
Definition: code.cpp:1581
#define area
Definition: md1redef.h:5
#define sec
Definition: md1redef.h:13
#define i
Definition: md1redef.h:12
#define IGNORE(arg)
Definition: model.h:247
#define Printf
Definition: model.h:237
exp
Definition: extdef.h:5
char * emalloc(unsigned n)
Definition: list.cpp:166
int nrn_nthread
Definition: multicore.cpp:46
NrnThread * nrn_threads
Definition: multicore.cpp:47
void section_ref(Section *)
Definition: solve.cpp:575
void section_unref(Section *)
Definition: solve.cpp:565
#define g
Definition: passive0.cpp:21
#define loc(x, y, z)
#define NODEV(n)
Definition: section.h:115
#define NODERHS(n)
Definition: section.h:105
#define NODED(n)
Definition: section.h:104
Definition: section.h:133
double erev
Definition: synapse.cpp:52
double loc
Definition: fstim.cpp:32
double delay
Definition: fstim.cpp:33
double mag
Definition: fstim.cpp:35
double g
Definition: synapse.cpp:54
double mag_seg
Definition: fstim.cpp:36
Section * sec
Definition: fstim.cpp:38
double duration
Definition: fstim.cpp:34
Node * pnd
Definition: fstim.cpp:37
void activsynapse_rhs(void)
Definition: synapse.cpp:208
static void stim_record(int)
Definition: synapse.cpp:183
void fsyni(void)
Definition: synapse.cpp:108
struct Stimulus Stimulus
static double alpha(double x)
Definition: synapse.cpp:85
static void free_syn(void)
Definition: synapse.cpp:170
void synapse_prepare(void)
Definition: synapse.cpp:200
void print_syn(void)
Definition: synapse.cpp:65
void activsynapse_lhs()
Definition: synapse.cpp:217
void fsyn(void)
Definition: synapse.cpp:132
static int maxstim
Definition: synapse.cpp:59
void fsyng(void)
Definition: synapse.cpp:119
static Stimulus * pstim
Definition: synapse.cpp:60
#define nt_t
Definition: synapse.cpp:44
static double stimulus(int i)
Definition: synapse.cpp:93