File: mechstan.rst

package info (click to toggle)
neuron 8.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,760 kB
  • sloc: cpp: 149,571; python: 58,465; ansic: 50,329; sh: 3,510; xml: 213; pascal: 51; makefile: 35; sed: 5
file content (449 lines) | stat: -rwxr-xr-x 11,521 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
.. _mechstan:

         
MechanismStandard (Parameter Control)
-------------------------------------



.. class:: MechanismStandard


    Syntax:
    
        .. code-block::
            python
            
            ms = h.MechanismStandard(name_str)
            ms = h.MechanismStandard(name_str, vartype)


    Description:
        In Python, consider the use of 'sec.psection()' which encapsulates MechanismType and MechanismStandard so as to return a dictionary.

        With no vartype or vartype = 1, this provides 
        storage for parameter values of a membrane mechanism or point process. 
        This class is useful in maintaining a default set of parameters and can 
        be used to specify values for a set of sections. 
         
        *name_str* is a density mechanism such as ``hh`` or a point process 
        such as :class:`VClamp`. A ``MechanismStandard`` instance, when created, 
        contains default values for all parameters associated with the mechanism. 
         
        In combination with the 
        :class:`MechanismType` class it is possible to create generic graphical interface 
        widgets that are independent of the particular mechanism and parameter names. 
         
        If vartype = 1, 2, or 3, the storage is for PARAMETER, ASSIGNED, or STATE 
        variables respectively. If vartype = 0, the storage is for all three types. 
         
        If vartype = -1, the count and names (and array size) 
        of the GLOBAL variables are accessible, but any other method will 
        generate an error message. 
         

    Example:

        .. code-block::
            python
            
            from neuron import h, gui
            ms1 = h.MechanismStandard('hh')
            ms2 = h.MechanismStandard('AlphaSynapse')
            ms2.set('gmax', 0.3)
            ms1.panel()
            ms2.panel()

            ms1 = h.MechanismStandard("hh") 
            ms2 = h.MechanismStandard("AlphaSynapse") 
            ms2.set("gmax", .3) 
            ms1.panel() 
            ms2.panel() 

        .. image:: ../images/mechanismstandard.png
            :align: center

    Example:

        The following example prints all the names associated with POINT_PROCESS 
        and SUFFIX mechanisms. 

        .. code-block::
            python

            from neuron import h, gui

            soma = h.Section(name="soma")
            def pname(msname):
                s = h.ref('')
                for i in range(-1, 4):
                    ms = h.MechanismStandard(msname, i)
                    print('\n{}   vartype={}'.format(msname, i))
                    for j in range(ms.count()):
                        k = ms.name(s, j)
                        print('%-5d %-20s size=%d' % (j, s[0], k))

            def ptype():
                msname = h.ref('')
                for i in range(2):
                    mt = h.MechanismType(i)
                    for j in range(mt.count()):
                        mt.select(j)
                        mt.selected(msname)
                        print('\n\n{} mechanismtype={}'.format(msname[0], j))
                        pname(msname[0])


            ptype() 
             
    Example:

        The following example provides a function ``get_mech_globals`` that returns a
        list of all of a mechanism's global (or per-thread-global) variables. As running the
        code shows, there are six such variables (all per-thread-global) for the ``hh``
        mechanism. These are used to temporarily share limiting values and time constant information
        between functions in the NMODL file; their per-thread-global nature means that
        the memory is reused for subsequent locations within a given thread, but that different
        threads do not interfere with each other.

        .. code-block::
            python

            from neuron import h
             
            def get_mech_globals(mechname):
                ms = h.MechanismStandard(mechname, -1)
                name = h.ref('')
                mech_globals = []
                for j in range(ms.count()):
                    ms.name(name, j)
                    mech_globals.append(name[0])
                return mech_globals
             
            print(get_mech_globals('hh'))



    .. seealso::
        :class:`MechanismType`

         

----



.. method:: MechanismStandard.panel


    Syntax:
        .. code-block::
            python
            
            ms.panel()
            ms.panel("string")


    Description:
        Popup a panel of parameters for this mechanism. It's a good idea to 
        set the default values before generating the panel. 
         
        With no argument the first item in the panel will be the name of the 
        mechanism. Otherwise the string is used as the first item label. 

    .. seealso::
        :func:`nrnglobalmechmenu`, :func:`nrnmechmenu`, :func:`nrnpointmenu`

         

----



.. method:: MechanismStandard.action


    Syntax:
        .. code-block::
            python
            
            ms.action(py_callback)


    Description:
        `py_callback` is executed when any variable is changed in the panel.
        The callback is sent three parameters; in order: the MechanismStandard object,
        the index of the changed item in the object, and a third argument indicating
        position in an array (or 0 if the parameter is not an array; this is the usual
        case). The value is in `h.hoc_ac_` and this value may also be read via
        ``nameref = h.ref(""); ms.name(nameref, i);  value = ms.get(nameref[0], j)``

    Example:

        .. code-block::
            python

            from neuron import h, gui

            soma = h.Section(name='soma')
            axon = h.Section(name='axon')
            dend = [h.Section(name='dend[%d]' % i) for i in range(3)]

            axon.insert('hh')
            for sec in dend:
                sec.insert('pas')

            h.xpanel("Updated when MechanismStandard is changed")
            for i, sec in enumerate(dend):
                h.xvalue("dend[%d](0.5).pas.g" % i, sec(0.5).pas._ref_g)

            h.xpanel()

            def change_pas(ms, i, j):
                for sec in h.allsec():
                    if sec.has_membrane('pas'):
                        ms.out()

            ms = h.MechanismStandard('pas')
            ms.action(change_pas)
            ms.panel()


    .. note::

        Support for Python callbacks for this method was added in NEURON 7.5.

         

----



.. method:: MechanismStandard._in


    Syntax:
        .. code-block::
            python
            
            ms._in(sec=section)
            ms._in(x, sec=section)
            ms._in(pointprocess)
            ms._in(mechanismstandard)

    Description:
        copies parameter values into this mechanism standard from ... 


        ``ms._in(sec=section)`` 
            the mechanism located in first segment of ``section`` 

        ``ms._in(x, sec=section)``
            the mechanism located in the segment ``section(x)``. 
            (Note that x=0 and 1 are considered to lie in the 
            0+ and 1- segments respectively. 

        ``ms._in(pointprocess)`` 
            the point process object 

        ``ms._in(mechanismstandard)`` 
            another mechanism standard 

        If the source is not the same type as the standard then nothing happens. 

    Example:


        .. code-block::
            python

            from neuron import h

            s = h.Section(name='soma')
            s.insert('hh')
            s(.5).hh.gnabar = 0.5

            ms = h.MechanismStandard('hh')
            ms.set("gnabar_hh", 0.3)

            print(ms.get("gnabar_hh"))
            ms._in(sec=s)
            print(ms.get("gnabar_hh"))



    .. note::

        This is the same as the HOC method ``ms.in``, however the name had to be
        changed for Python due to ``in`` being a keyword in Python.

    .. note::

        Python support for this method was added in NEURON 7.5.

----



.. method:: MechanismStandard.out


    Syntax:
        .. code-block::
            python
            
            ms.out(sec=section)
            ms.out(x, sec=section)
            ms.out(pointprocess)
            ms.out(mechanismstandard)


    Description:
        copies parameter values from this mechanism standard to ... 


        ``ms.out(sec=section)`` 
            the mechanism located in ``section`` (all segments). 

        ``ms.out(x, sec=section)`` 
            the mechanism located in ``section`` in the segment 
            containing x.(Note that x=0 and 1 are considered to lie in the 
            0+ and 1- segments respectively) 

        ``ms.out(pointprocess)`` 
            the point process argument 

        ``ms.out(mechanismstandard)`` 
            another mechanism standard 

        If the target is not the same type as the standard then nothing happens. 

         

----



.. method:: MechanismStandard.set


    Syntax:
        .. code-block::
            python
            
            ms.set('varname', val [, arrayindex])


    Description:
        sets the parameter in the standard to *val*. If the variable is 
        an array, then the optional index can be specified. 

        ``varname`` follows the HOC form convention of ``name_mech``; e.g. ``gnabar_hh``.

        See :meth:`MechanismStandard.out` for an example.
         

----



.. method:: MechanismStandard.get


    Syntax:
        .. code-block::
            python
            
            val = ms.get('varname' [, arrayindex])


    Description:
        returns the value of the parameter. If the variable is actually 
        a POINTER and it is nil, then return -1e300. 

        ``varname`` follows the HOC form convention of ``name_mech``; e.g. ``gnabar_hh``.

        See :meth:`MechanismStandard._in` for an example.

----



.. method:: MechanismStandard.save


    Syntax:
        .. code-block::
            python
            
            ms.save('name')


    Description:
        For saving the state of a MechanismStandard to a session file. 
        The name will be the objectvar that the instance gets assigned to 
        when the session file is read. 
        See pointman.hoc for an example of usage. 

         

----



.. method:: MechanismStandard.count


    Syntax:
        .. code-block::
            python
            
            cnt = ms.count()


    Description:
        Returns the number of parameter names of the mechanism 
        represented by the MechanismStandard. 

         

----



.. method:: MechanismStandard.name


    Syntax:
        .. code-block::
            python
            
            ms.name(strref)
            size = ms.name(strref, i)


    Description:
        The single arg form assigns the name of the mechanism to the strref 
        variable. 
         
        When the i parameter is present (i ranges from 0 to ms.count()-1) the 
        strref parameter gets assigned the ith name of the mechanism represented 
        by the MechanismStandard. In addition the return value is the 
        array size of that parameter (1 for a scalar). 


    Example:
    
        .. code-block::
            python
            
            from neuron import h, gui

            ms = h.MechanismStandard('hh')
            name_strref = h.ref('')

            # read the name of the mechanism
            ms.name(name_strref)

            print(name_strref[0])    # displays: hh