001: //
002: // Heccer : a compartmental solver that implements efficient Crank-Nicolson
003: // integration for neuronal models.
004: //
005: 
006: //////////////////////////////////////////////////////////////////////////////
007: //'
008: //' Heccer : testbed C implementation
009: //'
010: //' Copyright (C) 2006-2008 Hugo Cornelis
011: //'
012: //' functional ideas ..   Hugo Cornelis, hugo.cornelis@gmail.com
013: //'
014: //' coding ............   Hugo Cornelis, hugo.cornelis@gmail.com
015: //'
016: //////////////////////////////////////////////////////////////////////////////
017: 
018: 
019: #include <stdlib.h>
020: 
021: #include "../../heccer/compartment.h"
022: #include "../../heccer/heccer.h"
023: #include "../../heccer/mathcomponent.h"
024: 
025: 
026: #define HECCER_TEST_REPORTING_GRANULARITY 100000
027: #define HECCER_TEST_STEPS 1000000
028: #define HECCER_TEST_TESTED_THINGS ( HECCER_DUMP_VM_COMPARTMENT_MATRIX \
029:                                     | HECCER_DUMP_VM_COMPARTMENT_MATRIX_DIAGONALS \
030:                                     | HECCER_DUMP_VM_COMPARTMENT_OPERATIONS \
031:                                     | HECCER_DUMP_VM_CHANNEL_POOL_FLUXES \
032:                                     | HECCER_DUMP_VM_MECHANISM_DATA \
033:                                     | HECCER_DUMP_VM_MECHANISM_OPERATIONS \
034:                                     | HECCER_DUMP_VM_SUMMARY \
035:         )
036: #define HECCER_TEST_TIME_GRANULARITY (1e-14)
037: #define HECCER_TEST_TIME_STEP (1e-11)
038: 
039: 
040: struct Compartment comp =
041: {
042:     //m administrative overhead
043: 
044:     {
045:         //m type of structure
046: 
047:         MATH_TYPE_Compartment,
048:     },
049: 
050:     //m index of parent compartment, -1 for none
051: 
052:     -1,
053: 
054: /* 	//m first mechanism */
055: 
056: /* 	NULL, */
057: 
058: /* 	//m number of mechanisms */
059: 
060: /* 	0, */
061: 
062:     //m descriptive values, alphabetical order
063: 
064: /*     double dCm; */
065: 
066:     5.755329373e-12, // unscaled 0.0164,
067: 
068: /*     double dEm; */
069: 
070:     -0.08,
071: 
072: /*     double dInitVm; */
073: 
074:     -0.068,
075: 
076: /*     double dInject;		 */
077: 
078:     1e-9,
079: 
080: /*     double dRa; */
081: 
082:     772813.4375, // unscaled 2.5,
083: 
084: /*     double dRm; */
085: 
086:     8.548598272e9, // unscaled 3
087: };
088: 
089: 
090: //v a simple fast calcium channel
091: 
092: struct ChannelActInact caiCaT =
093: {
094:     //m administrative overhead
095: 
096:     {
097:         //m type of structure
098: 
099:         MATH_TYPE_ChannelActInact,
100:     },
101: 
102:     //m first set of descriptive values, alphabetical order
103: 
104:     //m initial reversal potential
105: 
106:     0.1470214874,
107: 
108:     //m get reversal potential from this intermediary, -1 for none
109: 
110:     1,
111: 
112:     //m maximal conductance when all channels are permissive
113: 
114:     1.754672296e-09,
115: 
116:     //m contributes to this concentration pool, -1 for none, boolean indicator only.
117: 
118:     1,
119: 
120:     //m activation description
121: 
122:     {
123:         //m power, for a standard heccer, something between 1 and 4 or so.
124: 
125:         1,
126: 
127:         //m gate definition
128: 
129:         {
130:             //m initial value, commonly forward over backward steady states
131: 
132:             0.038918706451336625,
133: 
134:             //m corresponding index in tables, set to -1 for initialization.
135: 
136:             -1,
137: 
138:             {
139:                 //m forward kinetiks, commonly denoted with alpha or non-perm to perm rate
140: 
141:                 {
142:                     //m multiplier
143: 
144:                     2.6e3,
145: 
146:                     //m multiplier membrane dependence, 0.0 for no dependence
147: 
148:                     0.0,
149: 
150:                     //m 2b: multiplier membrane dependence offset, 0.0 for no dependence
151: 
152:                     0.0,
153: 
154:                     //m choose between nominator or denominator, 1 means nominator, -1
155:                     //m means denominator
156: 
157:                     -1.0,
158: 
159:                     //m nominator or denominator offset
160: 
161:                     1.0,
162: 
163:                     //m membrane offset
164: 
165:                     0.021,
166: 
167:                     //m denormalized time constant
168: 
169:                     -8e-3,
170:                 },
171: 
172:                 //m backward kinetiks, commonly denoted with beta or perm to non-perm rate
173: 
174:                 {
175:                     //m multiplier
176: 
177:                     0.18e3,
178: 
179:                     //m multiplier membrane dependence, 0.0 for no dependence
180: 
181:                     0.0,
182: 
183:                     //m 2b: multiplier membrane dependence offset, 0.0 for no dependence
184: 
185:                     0.0,
186: 
187:                     //m choose between nominator or denominator, 1 means nominator, -1
188:                     //m means denominator
189: 
190:                     -1.0,
191: 
192:                     //m nominator or denominator offset
193: 
194:                     1.0,
195: 
196:                     //m membrane offset
197: 
198:                     0.04,
199: 
200:                     //m denormalized time constant
201: 
202:                     4e-3,
203:                 },
204:             },
205:         },
206:     },
207: 
208:     //m inactivation description
209: 
210:     {
211:         //m power, for a standard heccer, something between 1 and 4 or so.
212: 
213:         1,
214: 
215:         //m gate definition
216: 
217:         {
218:             //m initial value, commonly forward over backward steady states
219: 
220:             0.082602128127539254,
221: 
222:             //m corresponding index in tables, set to -1 for initialization.
223: 
224:             -1,
225: 
226:             {
227:                 //m forward kinetiks, commonly denoted with alpha or non-perm to perm rate
228: 
229:                 {
230:                     //m multiplier
231: 
232:                     0.0025e3,
233: 
234:                     //m multiplier membrane dependence, 0.0 for no dependence
235: 
236:                     0.0,
237: 
238:                     //m 2b: multiplier membrane dependence offset, 0.0 for no dependence
239: 
240:                     0.0,
241: 
242:                     //m choose between nominator or denominator, 1 means nominator, -1
243:                     //m means denominator
244: 
245:                     -1.0,
246: 
247:                     //m nominator or denominator offset
248: 
249:                     1.0,
250: 
251:                     //m membrane offset
252: 
253:                     0.04,
254: 
255:                     //m denormalized time constant
256: 
257:                     8e-3,
258:                 },
259: 
260:                 //m backward kinetiks, commonly denoted with beta or perm to non-perm rate
261: 
262:                 {
263:                     //m multiplier
264: 
265:                     0.19e3,
266: 
267:                     //m multiplier membrane dependence, 0.0 for no dependence
268: 
269:                     0.0,
270: 
271:                     //m 2b: multiplier membrane dependence offset, 0.0 for no dependence
272: 
273:                     0.0,
274: 
275:                     //m choose between nominator or denominator, 1 means nominator, -1
276:                     //m means denominator
277: 
278:                     -1.0,
279: 
280:                     //m nominator or denominator offset
281: 
282:                     1.0,
283: 
284:                     //m membrane offset
285: 
286:                     0.05,
287: 
288:                     //m denormalized time constant
289: 
290:                     -10.0e-3,
291:                 },
292:             },
293:         },
294:     },
295: };
296: 
297: 
298: struct InternalNernst inCa =
299: {
300:     //m administrative overhead
301: 
302:     {
303:         //m type of structure
304: 
305:         MATH_TYPE_InternalNernst,
306:     },
307: 
308:     //m nernst constant
309: 
310:     0.013363,
311: 
312:     //m link to internal concentration
313: 
314:     2,
315: 
316:     //m constant external concentration
317: 
318:     2.4000,
319: 
320:     //m initial nernst potential
321: 
322:     0.1470214874,
323: };
324: 
325: 
326: struct ExponentialDecay exdecCa =
327: {
328:     //m administrative overhead
329: 
330:     {
331:         //m type of structure
332: 
333:         MATH_TYPE_ExponentialDecay,
334:     },
335: 
336:     //m initial value
337: 
338:     4e-5,
339: 
340:     //m beta
341: 
342:     7.579027046e+10,
343: 
344:     //m steady state
345: 
346:     4e-05,
347: 
348:     //m tau
349: 
350:     0.00010,
351: 
352:     //m external contribution delivered by these intermediaries
353: 
354:     {
355:         0,
356:         -1,
357:         -1,
358:         -1,
359:     },
360: };
361: 
362: 
363: int piC2m[] =
364: {
365:     3,
366:     -1,
367: };
368: 
369: 
370: struct MathComponentArray mca =
371: {
372:     //m number of math components
373: 
374:     3,
375: 
376:     //m math component data
377: 
378:     NULL,
379: 
380:     //m math component index, initialize to NULL
381: 
382:     NULL,
383: 
384: };
385: 
386: 
387: struct Intermediary inter =
388: {
389:     //m compartment array
390: 
391:     1,
392: 
393:     &comp,
394: 
395:     //m all other mathematical components
396: 
397:     &mca,
398: 
399:     //m compartment 2 first mechanism number
400: 
401:     piC2m,
402: };
403: 
404: 
405: int main(int argc, char *argv[])
406: {
407:     //- determine intermediary size, and allocate
408: 
409:     struct MathComponentInfo *pmciCaT = MathComponentInfoLookup(caiCaT.mc.iType);
410: 
411:     struct MathComponentInfo *pmciCa = MathComponentInfoLookup(exdecCa.mc.iType);
412: 
413:     struct MathComponentInfo *pmciNernst = MathComponentInfoLookup(inCa.mc.iType);
414: 
415:     int iChars = pmciCaT->iChars + pmciCa->iChars + pmciNernst->iChars;
416: 
417:     void *pmc = calloc(sizeof(char), iChars);
418: 
419:     //- prepare the mechanism intermediary
420: 
421:     struct ChannelActInact *pcai = (struct ChannelActInact *)pmc;
422: 
423:     *pcai = caiCaT;
424: 
425:     struct InternalNernst *pin = (struct InternalNernst *)&((char *)pcai)[pmciCaT->iChars];
426: 
427:     *pin = inCa;
428: 
429:     struct ExponentialDecay *pexdec = (struct ExponentialDecay *)&((char *)pin)[pmciNernst->iChars];
430: 
431:     *pexdec = exdecCa;
432: 
433:     //! other order:
434: 
435: /*     struct ExponentialDecay *pexdec = (struct ExponentialDecay *)&((char *)pcai)[pmciCaT->iChars]; */
436: 
437: /*     *pexdec = exdecCa; */
438: 
439: /*     struct InternalNernst *pin = (struct InternalNernst *)&((char *)pexdec)[pmciCa->iChars]; */
440: 
441: /*     *pin = inCa; */
442: 
443:     //- link the intermediary
444: 
445:     mca.pmc = pmc;
446: 
447:     //- do the simulation
448: 
449:     simulate(argc,argv);
450: }
451: 
452: 
453: #define main(argc,argv) simulate(argc,argv)
454: 
455: //t this prototype can give warning and perhaps errors.
456: 
457: int main(int argc, char *argv[]);
458: 
459: 
460: #include "main.c"
461: 
462: