MorphoBranch#

class braincell.morph.MorphoBranch(owner, node_id, *, name, branch, parent_id, parent_x, child_x)[source]#

A tree-local branch node bound to exactly one Morpho owner.

MorphoBranch provides transparent access to branch geometry (via delegation to Branch) and tree navigation (parent, children). It also supports syntax sugar for attaching children:

  • Attribute assignment: parent.dend = Branch(...)

  • Subscript syntax: parent[0.5].dend = Branch(...)

MorphoBranch instances are created internally by Morpho and should not be constructed directly.

Parameters:
  • owner (Morphology) – The morphology tree that owns this node.

  • node_id (int) – Unique node identifier within the tree.

  • name (str) – Branch name.

  • branch (Branch) – Underlying geometry object.

  • parent_id (int | None) – Node ID of the parent (None for the root).

  • parent_x (float) – Attachment point on the parent branch.

  • child_x (float) – Attachment point on the child branch.

See also

Morpho

The tree container that owns MorphoBranch nodes.

Branch

The immutable geometry wrapped by this node.

Notes

MorphoBranch delegates attribute access to the underlying Branch via __getattr__, so all geometry properties

(length, area, n_segments, type, etc.) are accessible directly on the node. Child branches can also be retrieved by name (e.g., morph.soma.dend).

Examples

>>> import brainunit as u
>>> from braincell import Branch, Morphology
>>> soma = Branch.from_lengths(
...     lengths=[20.0] * u.um,
...     radii=[10.0, 10.0] * u.um,
...     type="soma",
... )
>>> dend = Branch.from_lengths(
...     lengths=[50.0] * u.um,
...     radii=[2.0, 1.0] * u.um,
...     type="dendrite",
... )
>>> morph = Morphology.from_root(soma, name="soma")
>>> morph.soma.dend = dend
>>> morph.soma.n_children
1
>>> morph.soma.dend.length
50.0 * umetre
attach(branch, name=None, *, parent_x=1.0, child_x=0.0)[source]#

Attach a child branch to this branch.

Parameters:
  • branch (Branch) – Geometry of the child branch to attach.

  • name (str | None) – Name for the child branch. If None, auto-generated from the branch type.

  • parent_x (float) – Attachment point on this branch: 0 (proximal), 0.5 (midpoint, soma only), or 1 (distal, default).

  • child_x (float) – Attachment point on the child branch: 0 (proximal, default) or 1 (distal).

Returns:

The newly attached child branch node.

Return type:

MorphoBranch

Raises:

ValueError – If parent_x or child_x is invalid.

Notes

parent_x=0 attaches to the proximal end of this branch. This is typically used when this branch is itself a child and you want to attach at its connection point rather than its distal end.

Examples

>>> child = morph.soma.attach(dend_branch, name="apical")
>>> child.name
'apical'
property children: tuple[MorphoBranch, ...]#

All direct children of this branch.

Returns:

Child branch nodes.

Return type:

tuple of MorphoBranch

property index: int#

Index of this branch in the default ordering.

Returns:

Position in the default (by node ID) ordering.

Return type:

int

See also

index_by

Index in a specific ordering.

index_by(*, order='default')[source]#

Index of this branch in a specific ordering.

Parameters:

order (str) – Ordering strategy: "default" (by node ID), "type" (by SWC type rank then name), or "depth" (by depth then index).

Returns:

Position in the requested ordering.

Return type:

int

property n_children: int#

Number of direct children.

Returns:

Child count.

Return type:

int

property parent: MorphoBranch | None#

Parent branch node, or None for the root.

Returns:

Parent node.

Return type:

MorphoBranch or None