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 
45 #define nt_t nrn_threads->_t
46 
47 /* impress the stimulus code to do synapses */
48 typedef struct Stimulus {
49  double loc; /* parameter location (0--1) */
50  double delay; /* value of t in msec for onset */
51  double duration;/* turns off at t = delay + duration */
52  double mag; /* conductance in microsiemens */
53  double erev;
54  double mag_seg; /* value added to rhs, depends on area of seg*/
55  double g; /* holds conductance when current calculated */
56  Node *pnd; /* segment location */
57  Section *sec;
58 } Stimulus;
59 
60 static int maxstim = 0; /* size of stimulus array */
61 static Stimulus *pstim; /* pointer to stimulus array */
62 static void free_syn(void);
63 
64 static void stim_record(int);
65 
66 void print_syn(void) {
67  int i;
68 
69  if (maxstim == 0) return;
70  /*SUPPRESS 440*/
71  Printf("fsyn(%d)\n/* section fsyn( #, loc, delay(ms), tau(ms), conduct(uS), erev(mV)) */\n", maxstim);
72  for (i = 0; i < maxstim; i++) {
73  Printf("%-15s fsyn(%2d,%4g,%10g,%8g,%14g,%9g)\n",
74  secname(pstim[i].sec), i,
75  pstim[i].loc, pstim[i].delay, pstim[i].duration, pstim[i].mag,
76  pstim[i].erev);
77  }
78 }
79 
80 static double alpha(double x) {
81 
82  if (x > 0.0 && x < 10.0) {
83  return x * exp(-x + 1.0);
84  }
85  return 0.0;
86 }
87 
88 
89 static double stimulus(int i) {
90  double x, g;
91 
92  if ((g = pstim[i].mag_seg) == 0.0) {
93  pstim[i].g = 0.0;
94  return 0.0;
95  }
96 #if CVODE
97  at_time(nrn_threads, pstim[i].delay);
98 #endif
99  x = (nt_t - pstim[i].delay) / pstim[i].duration;
100  pstim[i].g = g * alpha(x);
101  return pstim[i].g * (NODEV(pstim[i].pnd) - pstim[i].erev);
102 }
103 
104 void fsyni(void) {
105  int i;
106  double cur;
107 
108  i = chkarg(1, 0., (double) (maxstim - 1));
109  if ((cur = stimulus(i)) != 0.) {
110  cur *= pstim[i].mag / pstim[i].mag_seg;
111  }
112  hoc_retpushx(cur);
113 }
114 
115 void fsyng(void) {
116  int i;
117  double g = 0.0;
118 
119  i = chkarg(1, 0., (double) (maxstim - 1));
120  IGNORE(stimulus(i));
121  g = pstim[i].g;
122  if (g != 0.) {
123  g *= pstim[i].mag / pstim[i].mag_seg;
124  }
125  hoc_retpushx(g);
126 }
127 
128 void fsyn(void) {
129  int i;
130 
131  if (nrn_nthread > 1) {
132  hoc_execerror("fsyn does not allow threads", "");
133  }
134  i = chkarg(1, 0., 10000.);
135  if (ifarg(2)) {
136  if (i >= maxstim) {
137  hoc_execerror("index out of range", (char *) 0);
138  }
139  pstim[i].loc = chkarg(2, 0., 1.);
140  pstim[i].delay = chkarg(3, 0., 1e21);
141  pstim[i].duration = chkarg(4, 0., 1e21);
142  pstim[i].mag = *getarg(5);
143  pstim[i].erev = *getarg(6);
144  pstim[i].sec = chk_access();
145  section_ref(pstim[i].sec);
146  stim_record(i);
147  } else {
148  free_syn();
149  maxstim = i;
150  if (maxstim) {
151  pstim = (Stimulus *) emalloc((unsigned) (maxstim * sizeof(Stimulus)));
152  }
153  for (i = 0; i < maxstim; i++) {
154  pstim[i].loc = 0;
155  pstim[i].mag = 0.;
156  pstim[i].delay = 1e20;
157  pstim[i].duration = 0.;
158  pstim[i].erev = 0.;
159  pstim[i].sec = 0;
160  stim_record(i);
161  }
162  }
163  hoc_retpushx(0.);
164 }
165 
166 static void free_syn(void) {
167  int i;
168  if (maxstim) {
169  for (i = 0; i < maxstim; ++i) {
170  if (pstim[i].sec) {
171  section_unref(pstim[i].sec);
172  }
173  }
174  free((char *) pstim);
175  maxstim = 0;
176  }
177 }
178 
179 static void stim_record(int i) /*fill in the section info*/
180 {
181  double area;
182  Section *sec;
183 
184  sec = pstim[i].sec;
185  if (sec) {
186  if (sec->prop) {
187  pstim[i].pnd = node_ptr(sec, pstim[i].loc, &area);
188  pstim[i].mag_seg = 1.e2 * pstim[i].mag / area;
189  } else {
190  section_unref(sec);
191  pstim[i].sec = 0;
192  }
193  }
194 }
195 
196 void synapse_prepare(void) {
197  int i;
198 
199  for (i = 0; i < maxstim; i++) {
200  stim_record(i);
201  }
202 }
203 
204 void activsynapse_rhs(void) {
205 
206  int i;
207  for (i = 0; i < maxstim; i++) {
208  if (pstim[i].sec) {
209  NODERHS(pstim[i].pnd) -= stimulus(i);
210  }
211  }
212 }
213 
215 
216  int i;
217 
218  for (i = 0; i < maxstim; i++) {
219  if (pstim[i].sec) {
220  NODED(pstim[i].pnd) += pstim[i].g;
221  }
222  }
223 }
224 
void activsynapse_lhs()
Definition: synapse.cpp:214
#define area
Definition: md1redef.h:5
#define Printf
Definition: model.h:252
double duration
Definition: fstim.cpp:34
struct Prop * prop
Definition: section.h:62
static Stimulus * pstim
Definition: synapse.cpp:61
void print_syn(void)
Definition: synapse.cpp:66
#define NODEV(n)
Definition: section.h:114
#define NODED(n)
Definition: section.h:103
double delay
Definition: fstim.cpp:33
double mag_seg
Definition: fstim.cpp:36
void activsynapse_rhs(void)
Definition: synapse.cpp:204
double loc
Definition: fstim.cpp:32
#define cur
Definition: eion.cpp:338
#define IGNORE(arg)
Definition: model.h:262
int nrn_nthread
Definition: multicore.cpp:44
static double alpha(double x)
Definition: synapse.cpp:80
static void free_syn(void)
Definition: synapse.cpp:166
NrnThread * nrn_threads
Definition: multicore.cpp:45
const char * secname(Section *sec)
Definition: cabcode.cpp:1787
void fsyn(void)
Definition: synapse.cpp:128
Node * pnd
Definition: fstim.cpp:37
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:741
at_time
Definition: extargs.h:1
hoc_retpushx(1.0)
Section * sec
Definition: fstim.cpp:38
exp
Definition: extdef.h:3
#define nt_t
Definition: synapse.cpp:45
double mag
Definition: fstim.cpp:35
void fsyni(void)
Definition: synapse.cpp:104
char * emalloc(unsigned n)
Definition: list.cpp:189
double erev
Definition: synapse.cpp:53
int ifarg(int)
Definition: code.cpp:1562
double g
Definition: synapse.cpp:55
static double stimulus(int i)
Definition: synapse.cpp:89
void section_ref(Section *)
Definition: solve.cpp:563
#define NODERHS(n)
Definition: section.h:104
void fsyng(void)
Definition: synapse.cpp:115
#define getarg
Definition: hocdec.h:15
static int maxstim
Definition: synapse.cpp:60
#define i
Definition: md1redef.h:12
struct Stimulus Stimulus
void synapse_prepare(void)
Definition: synapse.cpp:196
Node * node_ptr(Section *sec, double x, double *parea)
Definition: cabcode.cpp:2003
void section_unref(Section *)
Definition: solve.cpp:552
Definition: section.h:132
Section * chk_access(void)
Definition: cabcode.cpp:437
double chkarg(int, double low, double high)
Definition: code2.cpp:608
static void stim_record(int)
Definition: synapse.cpp:179