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  at_time(nrn_threads, pstim[i].delay);
101  x = (nt_t - pstim[i].delay) / pstim[i].duration;
102  pstim[i].g = g * alpha(x);
103  return pstim[i].g * (NODEV(pstim[i].pnd) - pstim[i].erev);
104 }
105 
106 void fsyni(void) {
107  int i;
108  double cur;
109 
110  i = chkarg(1, 0., (double) (maxstim - 1));
111  if ((cur = stimulus(i)) != 0.) {
112  cur *= pstim[i].mag / pstim[i].mag_seg;
113  }
114  hoc_retpushx(cur);
115 }
116 
117 void fsyng(void) {
118  int i;
119  double g = 0.0;
120 
121  i = chkarg(1, 0., (double) (maxstim - 1));
122  IGNORE(stimulus(i));
123  g = pstim[i].g;
124  if (g != 0.) {
125  g *= pstim[i].mag / pstim[i].mag_seg;
126  }
127  hoc_retpushx(g);
128 }
129 
130 void fsyn(void) {
131  int i;
132 
133  if (nrn_nthread > 1) {
134  hoc_execerror("fsyn does not allow threads", "");
135  }
136  i = chkarg(1, 0., 10000.);
137  if (ifarg(2)) {
138  if (i >= maxstim) {
139  hoc_execerror("index out of range", (char*) 0);
140  }
141  pstim[i].loc = chkarg(2, 0., 1.);
142  pstim[i].delay = chkarg(3, 0., 1e21);
143  pstim[i].duration = chkarg(4, 0., 1e21);
144  pstim[i].mag = *getarg(5);
145  pstim[i].erev = *getarg(6);
146  pstim[i].sec = chk_access();
148  stim_record(i);
149  } else {
150  free_syn();
151  maxstim = i;
152  if (maxstim) {
153  pstim = (Stimulus*) emalloc((unsigned) (maxstim * sizeof(Stimulus)));
154  }
155  for (i = 0; i < maxstim; i++) {
156  pstim[i].loc = 0;
157  pstim[i].mag = 0.;
158  pstim[i].delay = 1e20;
159  pstim[i].duration = 0.;
160  pstim[i].erev = 0.;
161  pstim[i].sec = 0;
162  stim_record(i);
163  }
164  }
165  hoc_retpushx(0.);
166 }
167 
168 static void free_syn(void) {
169  int i;
170  if (maxstim) {
171  for (i = 0; i < maxstim; ++i) {
172  if (pstim[i].sec) {
174  }
175  }
176  free((char*) pstim);
177  maxstim = 0;
178  }
179 }
180 
181 static void stim_record(int i) /*fill in the section info*/
182 {
183  double area;
184  Section* sec;
185 
186  sec = pstim[i].sec;
187  if (sec) {
188  if (sec->prop) {
189  pstim[i].pnd = node_ptr(sec, pstim[i].loc, &area);
190  pstim[i].mag_seg = 1.e2 * pstim[i].mag / area;
191  } else {
193  pstim[i].sec = 0;
194  }
195  }
196 }
197 
198 void synapse_prepare(void) {
199  int i;
200 
201  for (i = 0; i < maxstim; i++) {
202  stim_record(i);
203  }
204 }
205 
206 void activsynapse_rhs(void) {
207  int i;
208  for (i = 0; i < maxstim; i++) {
209  if (pstim[i].sec) {
210  NODERHS(pstim[i].pnd) -= stimulus(i);
211  }
212  }
213 }
214 
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 }
Section * chk_access()
Definition: cabcode.cpp:449
const char * secname(Section *sec)
name of section (for use in error messages)
Definition: cabcode.cpp:1674
Node * node_ptr(Section *sec, double x, double *parea)
Definition: cabcode.cpp:1828
static double * duration
Definition: clamp.cpp:37
static Node * pnd
Definition: clamp.cpp:33
#define area
Definition: md1redef.h:12
#define sec
Definition: md1redef.h:20
#define i
Definition: md1redef.h:19
at_time
Definition: extargs.h:1
double chkarg(int, double low, double high)
Definition: code2.cpp:626
void hoc_retpushx(double x)
Definition: hocusr.cpp:154
#define getarg
Definition: hocdec.h:17
#define IGNORE(arg)
Definition: model.h:224
exp
Definition: extdef.h:5
NrnThread * nrn_threads
Definition: multicore.cpp:56
int nrn_nthread
Definition: multicore.cpp:55
void hoc_execerror(const char *s1, const char *s2)
Definition: nrnoc_aux.cpp:39
static void * emalloc(size_t size)
Definition: mpispike.cpp:30
void section_ref(Section *)
Definition: solve.cpp:520
void section_unref(Section *)
Definition: solve.cpp:509
int ifarg(int)
Definition: code.cpp:1607
#define loc(x, y, z)
#define NODEV(n)
Definition: section_fwd.hpp:60
#define NODERHS(n)
Definition: section_fwd.hpp:55
#define NODED(n)
Definition: section_fwd.hpp:54
Definition: section.h:105
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:206
static void stim_record(int)
Definition: synapse.cpp:181
void fsyni(void)
Definition: synapse.cpp:106
struct Stimulus Stimulus
static double alpha(double x)
Definition: synapse.cpp:85
static void free_syn(void)
Definition: synapse.cpp:168
void synapse_prepare(void)
Definition: synapse.cpp:198
void print_syn(void)
Definition: synapse.cpp:65
void activsynapse_lhs()
Definition: synapse.cpp:215
void fsyn(void)
Definition: synapse.cpp:130
static int maxstim
Definition: synapse.cpp:59
void fsyng(void)
Definition: synapse.cpp:117
static Stimulus * pstim
Definition: synapse.cpp:60
#define nt_t
Definition: synapse.cpp:44
static double stimulus(int i)
Definition: synapse.cpp:93
int Printf(const char *fmt, Args... args)
Definition: logger.hpp:18