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 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
|
.. _topology:
Topology
--------
This document describes the construction and manipulation of a stylized topology, which may later be given a 3d shape. For more details and higher level functions, see:
.. toctree::
:maxdepth: 3
topology/geometry.rst
topology/secspec.rst
topology/seclist.rst
topology/secref.rst
----
.. class:: Section
Syntax:
.. code::
dend = h.Section()
dend = h.Section(name='dend')
dend = h.Section(cell=mycell)
dend = h.Section(name='dend', cell=mycell)
Description:
Creates a new section. If no cell argument is specified, the name argument (optional) will be returned via ``str(s)`` or ``s.hname()``; if no name is provided, one will be automatically generated.
If a cell argument is passed, its repr will be combined with the name to form ``str(s)``.
Example 1:
.. code::
soma = h.Section(name='soma')
axon = h.Section(name='axon')
dend = [h.Section(name='dend[%d]' % i) for i in range(3)]
for sec in h.allsec():
print(sec)
prints the names of all the sections which have been created:
.. code-block::
none
soma
axon
dend[0]
dend[1]
dend[2]
Example 2:
.. code::
import itertools
class MyCell:
_ids = itertools.count(0)
def __repr__(self):
return 'MyCell[%d]' % self.id
def __init__(self):
self.id = self._ids.next()
# create the morphology and connect it
self.soma = h.Section(name='soma', cell=self)
self.dend = h.Section(name='dend', cell=self)
self.dend.connect(self.soma(0.5))
# create two cells
my_cells = [MyCell(), MyCell()]
# print the topology
h.topology()
Displays:
.. code-block::
none
|-| MyCell[0].soma(0-1)
`| MyCell[0].dend(0-1)
|-| MyCell[1].soma(0-1)
`| MyCell[1].dend(0-1)
.. seealso::
:meth:`Section.connect`, :meth:`Section.insert`, :func:`allsec`
----
.. method:: Section.connect
Syntax:
``child.connect(parent, [0 or 1])``
``child.connect(parent(x), [0 or 1])``
Description:
The first form connects the child at end 0 or 1 to the parent
section at position x. By default the child end 0 connects to the parent end 1.
An alternative syntax is the second
form in which the location on the parent section is indicated. If a section
is connected twice a Notice is printed on the standard error device
saying that the section has been reconnected (the last connection takes
precedence). To avoid the notice, disconnect the section first with the
function :func:`disconnect`. If sections are inadvertently connected in a
loop, an error will be generated when the internal data structures are
created and the user will be required to disconnect one of the sections
forming the loop.
Example:
.. code::
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)]
for sec in dend:
sec.connect(soma(1), 0)
h.topology()
s = h.Shape()
.. image:: ../../images/section-connection.png
:align: center
----
.. method:: Section.disconnect
Syntax:
``section.disconnect()``
Description:
Disconnect the section. The section becomes the root of its subtree.
Example:
.. code::
from neuron import h
sl = [h.Section(name="s_%d" % i) for i in range(4)]
for i, sec in enumerate(sl[1:]):
sec.connect(sl[i](1))
h.topology()
sl[2].disconnect()
h.topology()
sl[2].connect(sl[0](.5), 1)
h.topology()
sl[2].disconnect()
h.topology()
sl[2].connect(sl[0](.5))
h.topology()
----
.. data:: Section.nseg
Syntax:
``section.nseg``
Description:
Number of segments (compartments) in ``section``.
When a section is created, nseg is 1.
In versions prior to 3.2, changing nseg throws away all
"inserted" mechanisms including diam
(if 3-d points do not exist). PointProcess, connectivity, L, and 3-d
point information remain unchanged.
Starting in version 3.2, a change to nseg re-uses information contained
in the old segments.
If nseg is increased, all old segments are
relocated to their nearest new locations (no instance variables are modified
and no pointers to data in those segments become invalid).
and new segments are allocated and given mechanisms and values that are
identical to the old segment in which the center of the new segment is
located. This means that increasing nseg by an odd factor preserves
the locations of all previous data (including all Point Processes)
and, if PARAMETER range variables are
constant, that all the new segments have the proper PARAMETER values.
(It generally doesn't matter that ASSIGNED and STATE values do not get
interpolated since those values are computed with :func:`fadvance`).
If range variables are not constant then the hoc expressions used to
set them should be re-executed.
If nseg is decreased then all the new segments are in fact those old
segments that were nearest the centers of the new segments. Unused old
segments are freed (and thus any existing pointers to variables in those
freed segments are invalid). This means that decreasing nseg by an odd
factor preserves the locations of all previous data.
POINT PROCESSes are preserved regardless of how nseg is changed.
However, any POINT PROCESS that was attached to a location other
than 0 or 1 will be moved to the center of the "new segment" that
is nearest to the "old segment" to which it was attached. The same
rule applies to child sections that had been attached to locations
other than 0 or 1.
The intention is to guarantee that the following sequence
.. code::
run() # sim1
for sec in h.allsec():
sec.nseg *= oddfactor
run() # sim2
for sec in h.allsec():
sec.nseg /= oddfactor
run() # sim3
will produce identical simulations for sim1 and sim3. And sim2 will be
oddfactor^2 more accurate with regard to spatial discretization error.
----
.. method:: Section.orientation
Syntax:
``y = section.orientation()``
Description:
Return the end (0 or 1) which connects to the parent. This is the
value, y, used in
.. code::
child.connect(parent(x), y)
----
.. method:: Section.parentseg
Syntax:
``seg = child.parentseg()``
Description:
Return the parent segment of the ``child`` section. This is ``parent(x)`` in:
.. code::
child.connect(parent(x), y)
To get the x value, use ``seg.x``.
----
.. method:: Section.cell
Syntax:
``section.cell()``
Description:
Returns the value of the cell keyword argument provided when the Section was created.
----
.. method:: Section.hname
Syntax:
``section.hname()``
Description:
Returns the value of the name keyword argument provided when the Section was created.
If no name was provided, the internally provided name is returned instead.
----
.. method:: Section.name
Syntax:
``section.name()``
Description:
Same as :meth:`Section.hname`
----
.. method:: Section.subtree()
Syntax:
``section.subtree()``
Description:
Returns a Python list of the sub-tree of the Section
Example:
.. code-block::
python
>>> from neuron import h
>>> soma = h.Section(name='soma')
>>> dend1 = h.Section(name='dend1')
>>> dend2 = h.Section(name='dend2')
>>> dend3 = h.Section(name='dend3')
>>> dend4 = h.Section(name='dend4')
>>> dend5 = h.Section(name='dend5')
>>> dend2.connect(soma)
dend2
>>> dend1.connect(soma)
dend1
>>> dend3.connect(dend2)
dend3
>>> dend4.connect(dend2)
dend4
>>> dend5.connect(dend4)
dend5
>>> h.topology()
|-| soma(0-1)
`| dend2(0-1)
`| dend3(0-1)
`| dend4(0-1)
`| dend5(0-1)
`| dend1(0-1)
1.0
>>> dend2.subtree()
[dend2, dend4, dend5, dend3]
>>> dend7 = h.Section(name='dend7')
>>> dend7.subtree()
[dend7]
>>> dend1.subtree()
[dend1]
>>> dend4.subtree()
[dend4, dend5]
>>> soma.subtree()
[soma, dend1, dend2, dend4, dend5, dend3]
----
.. method:: Section.wholetree()
Syntax:
``section.wholetree()``
Description:
Returns a Python list of the whole tree of the Section
Example:
.. code-block::
python
>>> from neuron import h
>>> soma = h.Section(name='soma')
>>> dend1 = h.Section(name='dend1')
>>> dend2 = h.Section(name='dend2')
>>> dend3 = h.Section(name='dend3')
>>> dend4 = h.Section(name='dend4')
>>> dend5 = h.Section(name='dend5')
>>> dend2.connect(soma)
dend2
>>> dend1.connect(soma)
dend1
>>> dend3.connect(dend2)
dend3
>>> dend4.connect(dend2)
dend4
>>> dend5.connect(dend4)
dend5
>>> h.topology()
|-| soma(0-1)
`| dend2(0-1)
`| dend3(0-1)
`| dend4(0-1)
`| dend5(0-1)
`| dend1(0-1)
1.0
>>> dend2.wholetree()
[soma, dend1, dend2, dend4, dend5, dend3]
>>> dend7 = h.Section(name='dend7')
>>> dend7.wholetree()
[dend7]
>>> soma.wholetree()
[soma, dend1, dend2, dend4, dend5, dend3]
>>> dend3.wholetree()
[soma, dend1, dend2, dend4, dend5, dend3]
----
.. function:: topology
Syntax:
``h.topology()``
Description:
Print the topology of how the sections are connected together.
----
.. function:: delete_section
Syntax:
``h.delete_section(sec=sec)``
Description:
Delete the specified section ``sec`` from the main section
list which is used in computation.
.. code::
for sec in h.allsec():
h.delete_section(sec=sec)
will remove all sections.
Note: deleted sections still exist (even though
:meth:`SectionRef.exists`
returns 0 and an error will result if one attempts to access
the section) so
that other objects (such as :class:`SectionList`\ s and :class:`Shape`\ s) which
hold pointers to these sections will still work. When the last
pointer to a section is destroyed, the section memory will be
freed.
.. warning::
If the ``sec`` argument is omitted, the currently accessed section is deleted instead.
----
.. function:: section_exists
Syntax:
``boolean = h.section_exists("name", [index], [object])``
Description:
Returns 1.0 if the section defined by the args exists and can be used
as a currently accessed section. Otherwise, returns 0.0.
The index is optional and if nonzero, can be incorporated into the name as
a literal value such as dend[25]. If the optional object arg is present, that
is the context, otherwise the context is the top level. "name" should
not contain the object prefix. Even if a section is multiply dimensioned, use
a single index value.
.. warning::
This function does not work with Sections created in Python.
----
.. function:: section_owner
Syntax:
``h.section_owner(sec=section)``
Description:
If ``section`` was created in Python, returns the ``cell`` keyword argument or
None. This is accessible directly from the Section object via :meth:`Section.cell`.
If the section was created in HOC, returns the object that created the section, or
None if created at the top level.
----
.. function:: disconnect
Syntax:
``h.disconnect(sec=section)``
Description:
Disconnect ``section`` from its parent. Such
a section can be reconnected with the connect method. The alternative
:meth:`Section.disconnect` is recommended.
.. warning::
If no section is specified, will disconnect the currently accessed section.
----
.. function:: issection
Syntax:
``h.issection("regular expression", sec=section)``
Description:
Return 1.0 if the name of ``section`` matches the regular expression.
Return 0.0 otherwise.
Regular expressions are like those of grep except {n1-n2} denotes
an integer range and [] is literal instead of denoting a character
range. For character ranges use <>. For example <a-z> or <abz45> denotes
any character from a to z or to any of the characters abz45.
Thus a[{8-15}] matches sections a[8] through a[15].
A match always begins from the beginning of a section name. If you
don't want to require a match at the beginning use the dot.
(Note,
that ``.`` matches any character and ``*`` matches 0 or more occurrences
of the previous character). The interpreter always closes each string with
an implicit ``$`` to require a match at the end of the string. If you
don't require a match at the end use "``.*``".
Example:
.. code::
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)]
for section in h.allsec():
if h.issection('s.*', sec=section):
print(section)
will print ``soma``
.. code::
for section in h.allsec():
if h.issection('d.*2]', sec=section):
print(section)
will print ``dend[2]``
.. code-block::
none
for section in h.allsec():
if h.issection(".*a.*", sec=section):
print(section)
will print all names which contain the letter "a"
.. code-block::
none
soma
axon
.. note::
This can also be done using Python's ``re`` module and testing ``str(sec)``
.. warning::
If the ``sec`` keyword argument is omitted, this will operate on the currently accessed section.
----
.. function:: ismembrane
Syntax:
``h.ismembrane("mechanism", sec=section)``
Description:
This function returns a 1.0 if the membrane of ``section`` contains this
(density) mechanism. This is not for point
processes.
Example:
.. code::
for sec in h.allsec():
if h.ismembrane('hh', sec=sec) and h.ismembrane('ca_ion', sec=sec):
print(sec)
will print the names of all the sections which contain both Hodgkin-Huxley and Calcium ions.
.. warning::
If the ``sec`` keyword argument is omitted, returns a result based on the currently accessed
section.
----
.. function:: sectionname
Syntax:
``h.sectionname(strvar, sec=section)``
Description:
The name of ``section`` is placed in *strvar*, a HOC string reference.
Such a string reference may be created by: ``strvar = h.ref('')``; it's value is ``strvar[0]``.
This function is superseded by the easier to use, ``str(section)``.
----
.. function:: secname
Syntax:
``h.secname(sec=section)``
Description:
This function is superseded by the easier to use, ``str(section)``. The below examples
can be more cleanly written as: ``s = str(soma)``, ``print(soma)``, and ``for sec in h.allsec(): for seg in sec: print(seg)``.
Returns the name of ``section``. Usage is
.. code::
s = h.secname(sec=soma)
or
.. code::
print(h.secname(sec=soma))
or
.. code::
for sec in h.allsec():
for seg in sec:
print('%s(%g)' % (h.secname(sec=sec), seg.x))
----
.. function:: psection
Syntax:
``h.psection(sec=section)``
Description:
Print info about ``section`` in a format which is executable in HOC.
(length, parent, diameter, membrane information)
.. note::
Beginning in NEURON 7.6, ``section.psection()`` returns a Python dictionary
with all the information displayed by h.psection and more (e.g.
sec.psection() returns information about reaction-diffusion kinetics).
----
.. function:: parent_section
Syntax:
``h.parent_section(x, sec=section)``
Description:
Return the pointer to the section parent of the segment ``section(x)``.
Because a 64 bit pointer cannot safely be represented as a
double this function is deprecated in favor of :meth:`SectionRef.parent`.
.. seealso::
:meth:`Section.parentseg`
----
.. function:: parent_node
Syntax:
``h.parent_node(x, sec=section)``
Description:
Return the pointer of the parent of the segment ``section(x)``.
.. warning::
This function is useless and currently returns an error.
----
.. function:: parent_connection
Syntax:
``y = h.parent_connection(sec=child)``
Description:
Return location on parent that ``child`` is
connected to. (0 <= x <= 1). This is the value, y, used in
.. code::
child.connect(parent(x), y)
This information is also available via: ``child.parentseg().x``
.. seealso::
:meth:`Section.parentseg`
----
.. function:: section_orientation
Syntax:
``y = h.section_orientation(sec=child)``
Description:
Return the end (0 or 1) which connects to the parent. This is the
value, y, used in
.. code::
child.connect(parent(x), y)
.. note::
It is cleaner to use the equivalent section method: :meth:`Section.orientation`.
|