brainx-skill 1.0.3 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +29 -64
- package/adapters/gemini.js +7 -0
- package/adapters/opencode.js +7 -0
- package/adapters/windsurf.js +7 -0
- package/{lib → installation/lib}/installer.js +8 -5
- package/manifest.json +7 -1
- package/package.json +25 -10
- package/skills/braincell/SKILL.md +182 -0
- package/skills/braincell/references/area-scaled-hh-pattern.md +54 -0
- package/skills/braincell/references/braincell-custom-ion-channel-authoring.md +210 -0
- package/skills/braincell/references/channel-library.md +170 -0
- package/skills/braincell/references/ion-library.md +154 -0
- package/skills/braincell/references/mixions-for-adaptation.md +81 -0
- package/skills/braincell/references/multicompartment/braincell-manual-morphology-construction.md +180 -0
- package/skills/braincell/references/multicompartment/cv-policy-reference.md +133 -0
- package/skills/braincell/references/multicompartment/filter-function-library.md +162 -0
- package/skills/braincell/references/multicompartment/morphology-io-loading-validation.md +135 -0
- package/skills/braincell/references/multicompartment/multicompartment-cell-workflow.md +391 -0
- package/skills/braincell/references/multicompartment/probe-reference.md +128 -0
- package/skills/braincell/references/multicompartment/topology-building-and-visualization.md +121 -0
- package/skills/braincell/references/scripts/calcium_channel_gating.py +66 -0
- package/skills/braincell/references/scripts/cell_multicompartment_reference.py +221 -0
- package/skills/braincell/references/scripts/channel_ablation.py +61 -0
- package/skills/braincell/references/scripts/fi_curve.py +68 -0
- package/skills/braincell/references/scripts/hh_neuron_basics.py +59 -0
- package/skills/braincell/references/scripts/spike_frequency_adaptation.py +75 -0
- package/skills/braincell/references/scripts/t_current_rebound.py +72 -0
- package/skills/braincell/references/scripts/thalamic_neurons.py +228 -0
- package/skills/braincell/references/solver-library-with-effects.md +188 -0
- package/skills/brainevent/SKILL.md +268 -0
- package/skills/brainevent/references/connectivity-variants.md +312 -0
- package/skills/brainevent/references/custom-operators-cpu.md +304 -0
- package/skills/brainevent/references/custom-operators-gpu.md +468 -0
- package/skills/brainevent/references/scripts/102_EI_net_1996.py +107 -0
- package/skills/brainevent/references/scripts/204_joglekar_2018_propagation.py +168 -0
- package/skills/brainevent/references/scripts/coba_ei_teaching.py +356 -0
- package/skills/brainevent/references/sparse-formats.md +182 -0
- package/skills/brainevent/references/synaptic-plasticity.md +285 -0
- package/skills/brainpy-state/SKILL.md +232 -0
- package/skills/brainpy-state/references/array-creation.md +158 -0
- package/skills/brainpy-state/references/brain-dynamics-delay-protocol.md +96 -0
- package/skills/brainpy-state/references/braintools/brainstate-control-flow-patterns.md +334 -0
- package/skills/brainpy-state/references/braintools/data-preprocessing.md +79 -0
- package/skills/brainpy-state/references/braintools/metric.md +152 -0
- package/skills/brainpy-state/references/braintools/optimizer.md +179 -0
- package/skills/brainpy-state/references/braintools/parameter-initializer.md +183 -0
- package/skills/brainpy-state/references/braintools/surrogate.md +147 -0
- package/skills/brainpy-state/references/component-selection.md +273 -0
- package/skills/brainpy-state/references/nest-compatible/devices.md +157 -0
- package/skills/brainpy-state/references/nest-compatible/divergence-and-parity.md +114 -0
- package/skills/brainpy-state/references/nest-compatible/integration-categories.md +41 -0
- package/skills/brainpy-state/references/nest-compatible/model-library.md +200 -0
- package/skills/brainpy-state/references/nest-compatible/nest-workflow.md +156 -0
- package/skills/brainpy-state/references/nest-compatible/network-building.md +264 -0
- package/skills/brainpy-state/references/nest-compatible/scripts/brette_et_al_2007.py +320 -0
- package/skills/brainpy-state/references/nest-compatible/scripts/brunel_alpha.py +108 -0
- package/skills/brainpy-state/references/nest-compatible/scripts/brunel_delta.py +93 -0
- package/skills/brainpy-state/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +171 -0
- package/skills/brainpy-state/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +147 -0
- package/skills/brainpy-state/references/nest-compatible/scripts/spatial_gaussex.py +112 -0
- package/skills/brainpy-state/references/nest-compatible/scripts/synapsecollection.py +198 -0
- package/skills/brainpy-state/references/nest-compatible/synapse-and-connectivity.md +153 -0
- package/skills/brainpy-state/references/projection-patterns.md +125 -0
- package/skills/brainpy-state/references/scripts/103_COBA_2005.py +86 -0
- package/skills/brainpy-state/references/scripts/106_COBA_HH_2007.py +181 -0
- package/skills/brainpy-state/references/scripts/107_gamma_oscillation_1996.py +156 -0
- package/skills/brainpy-state/references/scripts/109_fast_global_oscillation.py +111 -0
- package/skills/brainpy-state/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +221 -0
- package/skills/brainpy-state/references/scripts/training-snn.py +119 -0
- package/skills/brainstate/SKILL.md +399 -0
- package/skills/brainstate/agents/openai.yaml +4 -0
- package/skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +334 -0
- package/skills/brainstate/references/brainstate/brainstate-transformed-diagnostics.md +180 -0
- package/skills/brainstate/references/brainstate/parameter-constraints-regularization.md +213 -0
- package/skills/brainstate/references/brainstate/parameter-transforms-regularizers-catalog.md +171 -0
- package/skills/brainstate/references/brainstate/randomness-and-reproducibility.md +131 -0
- package/skills/brainstate/references/brainstate/transformation-grad-expansion.md +462 -0
- package/skills/brainstate/references/brainstate/transformation-jit-expansion.md +167 -0
- package/skills/brainstate/references/brainstate/transformation-vmap-expansion.md +314 -0
- package/skills/brainstate/references/collective_model_operations.md +195 -0
- package/skills/brainstate/references/extension_mechanisms.md +293 -0
- package/skills/brainstate/references/libraries/prebuilt-activation-library.md +115 -0
- package/skills/brainstate/references/libraries/prebuilt-layer-library.md +143 -0
- package/skills/brainstate/references/model-interop-and-migration.md +305 -0
- package/skills/brainstate/references/simulation-environment.md +117 -0
- package/skills/brainstate/references/size-inference-variations.md +279 -0
- package/skills/brainstate/references/state-graph-operations.md +216 -0
- package/skills/brainstate/references/state_collections_and_utilities.md +235 -0
- package/skills/brainstate/scripts/integrator_rnn.py +359 -0
- package/skills/brainstate/scripts/lif_neuron_model.py +52 -0
- package/skills/brainstate/scripts/modern_cnn.py +73 -0
- package/skills/brainstate/scripts/resnet.py +130 -0
- package/skills/brainunit/SKILL.md +287 -0
- package/skills/brainunit/references/array-creation.md +158 -0
- package/skills/brainunit/references/array-mechanics/functional-structural-api.md +90 -0
- package/skills/brainunit/references/array-mechanics.md +165 -0
- package/skills/brainunit/references/math-function-library.md +433 -0
- package/skills/brainunit/references/physical-constant-library.md +58 -0
- package/skills/brainunit/references/prefix-library.md +116 -0
- package/skills/brainunit/references/quantity-inspection-and-conversion.md +104 -0
- package/skills/brainunit/references/typing-and-runtime-validation.md +203 -0
- package/skills/brainunit/references/unit-structure-and-definition.md +140 -0
- package/skills/brainx-general-guard/SKILL.md +153 -0
- package/skills/brainx-general-guard/references/brainstate-randomness-reproducibility/advanced-randomness.md +303 -0
- package/skills/brainx-general-guard/references/brainstate-randomness-reproducibility/randomness-and-reproducibility.md +62 -0
- package/skills/brainx-install/SKILL.md +2 -2
- package/skills/brainx-install/references/compatibility-and-release-matching.md +3 -3
- /package/{bin → installation/bin}/brainx.js +0 -0
- /package/{lib → installation/lib}/adapter-transaction.js +0 -0
- /package/{lib → installation/lib}/bundle.js +0 -0
- /package/{lib → installation/lib}/cli.js +0 -0
- /package/{lib → installation/lib}/constants.js +0 -0
- /package/{lib → installation/lib}/hash.js +0 -0
- /package/{lib → installation/lib}/paths.js +0 -0
- /package/{lib → installation/lib}/prompts.js +0 -0
- /package/{lib → installation/lib}/receipt.js +0 -0
package/skills/braincell/references/multicompartment/braincell-manual-morphology-construction.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# BrainCell manual morphology construction
|
|
2
|
+
|
|
3
|
+
Use this reference after opening `references/multicompartment/multicompartment-cell-workflow.md` when no existing reconstruction should be loaded and the task requires explicit branch geometry, anatomical types, or parent-child topology. Return to the workflow before choosing CVs, mechanisms, probes, or a solver.
|
|
4
|
+
|
|
5
|
+
## Mental model
|
|
6
|
+
|
|
7
|
+
A `Branch` is one immutable, unbranched cable geometry; a `Morphology` is the mutable tree that names and attaches those branches. Neither object is a list of simulation compartments.
|
|
8
|
+
|
|
9
|
+
Typed branch constructors preserve anatomical meaning for later region selectors. `Cell` creates control volumes only after the morphology is complete.
|
|
10
|
+
|
|
11
|
+
## Workflow
|
|
12
|
+
|
|
13
|
+
| Step | Action | Important result |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| Choose geometry form | Use segment lengths when coordinates are unavailable; use 3-D points when physical coordinates matter. | One unit-aware immutable branch per unbranched cable. |
|
|
16
|
+
| Type branches | Construct soma, dendrite, and axon branches with typed classes. | Later selectors can target anatomical `type` reliably. |
|
|
17
|
+
| Build the tree | Create one root and attach every child with explicit names and endpoints. | One connected, acyclic morphology with reviewable topology. |
|
|
18
|
+
| Inspect | Check topology, branch order, metrics, coordinates, radii, and types. | Geometry errors are found before discretization and mechanism placement. |
|
|
19
|
+
| Return to the parent | Pass the trusted `Morphology` into the multicompartment workflow. | CV policy, `Cell`, `paint()`, `place()`, and simulation remain outside this leaf. |
|
|
20
|
+
|
|
21
|
+
## Construct branches
|
|
22
|
+
|
|
23
|
+
Choose one geometric representation per branch.
|
|
24
|
+
|
|
25
|
+
| API | Description |
|
|
26
|
+
|---|---|
|
|
27
|
+
| `braincell.Branch.from_lengths(lengths=..., radii=..., type=...)` | Use when segment lengths and shared boundary radii are known but 3-D coordinates are not; `radii` has one more value than `lengths`. |
|
|
28
|
+
| `braincell.Branch.from_lengths(lengths=..., radii_proximal=..., radii_distal=..., type=...)` | Use when every segment needs an explicit proximal/distal radius pair, including a radius jump. |
|
|
29
|
+
| `braincell.Branch.from_points(points=..., radii=..., type=...)` | Use when ordered 3-D coordinates are known; it computes lengths from consecutive points and requires one shared radius per point. |
|
|
30
|
+
| `braincell.Soma.from_points(...)` | Use for a point-defined soma without passing `type`; the typed constructor assigns `soma`. |
|
|
31
|
+
| `braincell.BasalDendrite.from_points(...)` | Use for a point-defined basal dendrite without passing `type`. |
|
|
32
|
+
| `braincell.ApicalDendrite.from_points(...)` | Use for a point-defined apical dendrite without passing `type`. |
|
|
33
|
+
| `braincell.Axon.from_points(...)` | Use for a point-defined axon without passing `type`. |
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import brainunit as u
|
|
37
|
+
from braincell import Branch
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
schematic_dendrite = Branch.from_lengths(
|
|
41
|
+
lengths=[12.0, 18.0, 10.0] * u.um,
|
|
42
|
+
radii=[3.0, 2.4, 1.8, 1.2] * u.um,
|
|
43
|
+
type="dendrite",
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
point_dendrite = Branch.from_points(
|
|
47
|
+
points=[
|
|
48
|
+
(0.0, 0.0, 0.0),
|
|
49
|
+
(12.0, 0.0, 0.0),
|
|
50
|
+
(12.0, 18.0, 0.0),
|
|
51
|
+
(16.0, 34.0, 6.0),
|
|
52
|
+
] * u.um,
|
|
53
|
+
radii=[3.0, 2.4, 1.8, 1.2] * u.um,
|
|
54
|
+
type="dendrite",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
assert schematic_dendrite.n_segments == 3
|
|
58
|
+
assert point_dendrite.points.shape == (4, 3)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
All geometry must carry BrainUnit length units. Constructors reject bare values, inconsistent shapes, missing radii, invalid branch types, and zero total length. Consecutive equal points produce a zero-length-segment warning.
|
|
62
|
+
|
|
63
|
+
Use `from_lengths()` for schematic cable and `from_points()` when projected views, Euclidean measurements, or 3-D rendering matter. Do not invent coordinates only to satisfy `from_points()`.
|
|
64
|
+
|
|
65
|
+
## Build a typed tree
|
|
66
|
+
|
|
67
|
+
Create one root with `Morphology.from_root()`, then attach each branch exactly once.
|
|
68
|
+
|
|
69
|
+
| API | Description |
|
|
70
|
+
|---|---|
|
|
71
|
+
| `braincell.Morphology.from_root(branch, name=...)` | Use to create a mutable tree around the root branch; prefer an explicit, selector-safe root name such as `soma`. |
|
|
72
|
+
| `morphology.attach(parent=..., child_branch=..., child_name=..., parent_x=..., child_x=...)` | Use for explicit attachment; it returns the newly attached `MorphoBranch` and raises for an unknown parent or invalid endpoint. |
|
|
73
|
+
| `morphology.soma.dendrite = branch` | Use only as concise syntax when the parent and default endpoints are obvious. |
|
|
74
|
+
| `morphology.soma[parent_x, child_x].axon = branch` | Use as concise syntax when the attachment endpoints must remain visible. |
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
import brainunit as u
|
|
78
|
+
from braincell import Axon, BasalDendrite, Morphology, Soma
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
soma = Soma.from_points(
|
|
82
|
+
points=[(0.0, 0.0, 0.0), (12.0, 0.0, 0.0)] * u.um,
|
|
83
|
+
radii=[6.0, 6.0] * u.um,
|
|
84
|
+
)
|
|
85
|
+
basal = BasalDendrite.from_points(
|
|
86
|
+
points=[
|
|
87
|
+
(12.0, 0.0, 0.0),
|
|
88
|
+
(26.0, 8.0, 0.0),
|
|
89
|
+
(40.0, 14.0, 0.0),
|
|
90
|
+
] * u.um,
|
|
91
|
+
radii=[2.6, 2.0, 1.4] * u.um,
|
|
92
|
+
)
|
|
93
|
+
axon = Axon.from_points(
|
|
94
|
+
points=[
|
|
95
|
+
(0.0, 0.0, 0.0),
|
|
96
|
+
(-12.0, -6.0, 0.0),
|
|
97
|
+
(-26.0, -14.0, -2.0),
|
|
98
|
+
] * u.um,
|
|
99
|
+
radii=[1.0, 0.8, 0.6] * u.um,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
morphology = Morphology.from_root(soma, name="soma")
|
|
103
|
+
morphology.attach(
|
|
104
|
+
parent="soma",
|
|
105
|
+
child_branch=basal,
|
|
106
|
+
child_name="basal",
|
|
107
|
+
parent_x=1.0,
|
|
108
|
+
child_x=0.0,
|
|
109
|
+
)
|
|
110
|
+
morphology.attach(
|
|
111
|
+
parent="soma",
|
|
112
|
+
child_branch=axon,
|
|
113
|
+
child_name="axon",
|
|
114
|
+
parent_x=0.0,
|
|
115
|
+
child_x=0.0,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
assert morphology.n_branches == 3
|
|
119
|
+
assert morphology.has_full_point_geometry
|
|
120
|
+
print(morphology.topo())
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`parent_x` may be `0`, `0.5`, or `1`; midpoint attachment is allowed only on a soma. `child_x` may currently be `0` or `1`. Keep branch names valid Python identifiers and avoid names reserved by morphology methods or metrics.
|
|
124
|
+
|
|
125
|
+
Coordinates at an attachment should describe the intended physical junction. The topology API records which endpoints connect, but it does not make inconsistent point coordinates scientifically valid.
|
|
126
|
+
|
|
127
|
+
## Inspect before simulation
|
|
128
|
+
|
|
129
|
+
Construction checks structural input constraints; inspection establishes that the resulting tree represents the intended neuron.
|
|
130
|
+
|
|
131
|
+
| API | Description |
|
|
132
|
+
|---|---|
|
|
133
|
+
| `morphology.topo()` | Use to review the named parent-child tree. |
|
|
134
|
+
| `morphology.branches` | Use to inspect every branch in default node order. |
|
|
135
|
+
| `morphology.branch(name=...)` | Use to inspect one named branch and its type. |
|
|
136
|
+
| `morphology.branch_by_order(order=...)` | Use to compare default, type, or depth ordering. |
|
|
137
|
+
| `morphology.metric` | Use to inspect branch counts, stems, bifurcations, path length, area, volume, and coordinate-dependent metrics. |
|
|
138
|
+
| `morphology.has_full_point_geometry` | Use before coordinate-dependent analysis or 3-D rendering. |
|
|
139
|
+
| `morphology.vis2d(...)` | Use for a topology or projected-geometry check without constructing a `Cell`. |
|
|
140
|
+
| `morphology.vis3d(...)` | Use only when every branch has complete 3-D point geometry. |
|
|
141
|
+
|
|
142
|
+
Verify at least:
|
|
143
|
+
|
|
144
|
+
- exactly one intended root;
|
|
145
|
+
- every expected branch appears once in `topo()`;
|
|
146
|
+
- soma, dendrite, and axon types match later selectors;
|
|
147
|
+
- all lengths and radii are positive and use the intended scale;
|
|
148
|
+
- branch attachment endpoints and coordinates agree;
|
|
149
|
+
- branch counts, path distances, surface area, and volume are plausible;
|
|
150
|
+
- `has_full_point_geometry` is true before relying on Euclidean metrics or 3-D views.
|
|
151
|
+
|
|
152
|
+
Open `references/multicompartment/topology-building-and-visualization.md` when branch, CV, or runtime-node visualization is required. Return to `references/multicompartment/multicompartment-cell-workflow.md` when the failure appears only after CV construction or runtime lowering.
|
|
153
|
+
|
|
154
|
+
## Return to the multicompartment workflow
|
|
155
|
+
|
|
156
|
+
After inspection, return to `references/multicompartment/multicompartment-cell-workflow.md` and continue with:
|
|
157
|
+
|
|
158
|
+
`trusted Morphology -> CV policy -> Cell -> paint -> place -> init_state -> inspect runtime -> run -> verify`
|
|
159
|
+
|
|
160
|
+
Do not choose a CV count from the number of source points or branches. The CV policy owns simulation resolution.
|
|
161
|
+
|
|
162
|
+
## Common failures
|
|
163
|
+
|
|
164
|
+
- Passing bare coordinates, lengths, or radii: attach BrainUnit length units to every geometric value.
|
|
165
|
+
- Passing `type=` to a typed constructor: use either `Branch(..., type=...)` or a typed subclass, not both.
|
|
166
|
+
- Mixing the two radius forms: provide `radii` or the complete proximal/distal pair.
|
|
167
|
+
- Creating a disconnected or multiply attached branch: attach every non-root branch exactly once.
|
|
168
|
+
- Using an invalid midpoint attachment: reserve `parent_x=0.5` for a soma.
|
|
169
|
+
- Losing anatomical types: construct typed branches before writing type-based filters.
|
|
170
|
+
- Treating successful construction as biological validation: inspect topology and morphology metrics before building a `Cell`.
|
|
171
|
+
- Treating branches or points as compartments: select and refine a CV policy in the parent workflow.
|
|
172
|
+
- Adding mechanisms before geometry is trusted: finish morphology inspection first.
|
|
173
|
+
|
|
174
|
+
## Sources
|
|
175
|
+
|
|
176
|
+
- Morphology concept: https://brainx.chaobrain.com/braincell/concepts/morphology.html
|
|
177
|
+
- Morphology tutorial: https://brainx.chaobrain.com/braincell/tutorials/morphology.html
|
|
178
|
+
- Cell tutorial: https://brainx.chaobrain.com/braincell/tutorials/cell.html
|
|
179
|
+
- `Branch` API: https://brainx.chaobrain.com/braincell/apis/generated/braincell.Branch.html
|
|
180
|
+
- `Morphology` API: https://brainx.chaobrain.com/braincell/apis/generated/braincell.Morphology.html
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# CV policy reference
|
|
2
|
+
|
|
3
|
+
Use this reference after opening `references/multicompartment/multicompartment-cell-workflow.md` when control-volume resolution must be chosen, varied by branch type, inspected, or checked for numerical convergence.
|
|
4
|
+
|
|
5
|
+
## Discretization model
|
|
6
|
+
|
|
7
|
+
A `CVPolicy` converts each continuous morphology branch into normalized `(prox, dist)` intervals that become isopotential control volumes; more and shorter CVs resolve spatial voltage gradients with more State and computation.
|
|
8
|
+
|
|
9
|
+
`Cell` treats the policy output as the source of truth for compartment splitting. Morphology sample points and branches do not determine the final compartment count.
|
|
10
|
+
|
|
11
|
+
## Choose a policy
|
|
12
|
+
|
|
13
|
+
| API | Use when | Important behavior and result |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| `Cell(morphology, cv_policy=None)` | Use the package default for a structural baseline. | `None` selects `CVPerBranch()` with one CV per branch. |
|
|
16
|
+
| `CVPerBranch(cv_per_branch=1)` | A fixed, predictable count per branch is required. | It splits every branch uniformly in normalized coordinates and returns the same count for short and long branches. |
|
|
17
|
+
| `MaxCVLen(max_cv_len, keep_odd=True)` | Physical branch length should cap CV size. | It computes a count independently for each branch, then splits that branch uniformly so CV lengths do not exceed the target up to tolerance. |
|
|
18
|
+
| `DLambda(d_lambda, frequency=..., keep_odd=True)` | Detailed cable modeling should follow electrical rather than only geometric length. | It computes electrotonic length from diameter, axial resistivity, membrane capacitance, and frequency, then sizes CVs as a fraction `d_lambda` of the AC length constant. |
|
|
19
|
+
| `CVPolicyByTypeRule(branch_types, policy)` | One or more morphology branch types need a distinct policy. | It pairs a tuple of type names with the policy applied to matching branches. |
|
|
20
|
+
| `CompositeByTypePolicy(rules, default_policy)` | Soma, dendrite, axon, or custom branches need different rules. | It checks rules in order and applies `default_policy` when no rule matches. |
|
|
21
|
+
| `policy.resolve_cv_bounds(morphology, paint_rules=...)` | Implementing or testing a policy directly. | It returns branch-wise tuples of normalized `(prox, dist)` intervals; normal modeling should let `Cell` call it. |
|
|
22
|
+
|
|
23
|
+
Use `CVPerBranch` for a reproducible baseline or deliberately uniform branch resolution. Use `MaxCVLen` when the modeling assumption is a physical maximum compartment length. Use `DLambda` as the detailed cable-model starting point when electrical length should control refinement.
|
|
24
|
+
|
|
25
|
+
## Inspect a policy before simulation
|
|
26
|
+
|
|
27
|
+
Construct cells with candidate policies and inspect the actual CV records; do not infer the result from morphology point count.
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
import braincell
|
|
31
|
+
import brainunit as u
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
morphology = braincell.Morphology.from_swc("neuron.swc")
|
|
35
|
+
|
|
36
|
+
baseline = braincell.Cell(
|
|
37
|
+
morphology,
|
|
38
|
+
cv_policy=braincell.CVPerBranch(cv_per_branch=1),
|
|
39
|
+
)
|
|
40
|
+
length_limited = braincell.Cell(
|
|
41
|
+
morphology,
|
|
42
|
+
cv_policy=braincell.MaxCVLen(max_cv_len=20.0 * u.um),
|
|
43
|
+
)
|
|
44
|
+
electrical = braincell.Cell(
|
|
45
|
+
morphology,
|
|
46
|
+
cv_policy=braincell.DLambda(
|
|
47
|
+
d_lambda=0.1,
|
|
48
|
+
frequency=100.0 * u.Hz,
|
|
49
|
+
),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
for name, cell in (
|
|
53
|
+
("baseline", baseline),
|
|
54
|
+
("length_limited", length_limited),
|
|
55
|
+
("electrical", electrical),
|
|
56
|
+
):
|
|
57
|
+
assert cell.n_cv == len(cell.cvs)
|
|
58
|
+
print(name, cell.n_cv)
|
|
59
|
+
print([(cv.branch_id, cv.prox, cv.dist) for cv in cell.cvs[:4]])
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Inspect `cv.branch_id`, `cv.branch_type`, `cv.prox`, `cv.dist`, `cv.length`, and `cv.area` when count alone cannot explain the spatial layout.
|
|
63
|
+
|
|
64
|
+
## Apply policies by branch type
|
|
65
|
+
|
|
66
|
+
Compose type rules when one global resolution rule would over-resolve some cables or under-resolve others.
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import braincell
|
|
70
|
+
import brainunit as u
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
policy = braincell.CompositeByTypePolicy(
|
|
74
|
+
rules=(
|
|
75
|
+
braincell.CVPolicyByTypeRule(
|
|
76
|
+
branch_types=("soma",),
|
|
77
|
+
policy=braincell.CVPerBranch(cv_per_branch=3),
|
|
78
|
+
),
|
|
79
|
+
braincell.CVPolicyByTypeRule(
|
|
80
|
+
branch_types=(
|
|
81
|
+
"dendrite",
|
|
82
|
+
"basal_dendrite",
|
|
83
|
+
"apical_dendrite",
|
|
84
|
+
),
|
|
85
|
+
policy=braincell.DLambda(
|
|
86
|
+
d_lambda=0.1,
|
|
87
|
+
frequency=100.0 * u.Hz,
|
|
88
|
+
),
|
|
89
|
+
),
|
|
90
|
+
),
|
|
91
|
+
default_policy=braincell.MaxCVLen(max_cv_len=40.0 * u.um),
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
cell = braincell.Cell(morphology, cv_policy=policy)
|
|
95
|
+
print("total CVs:", cell.n_cv)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Use the exact type strings present in the loaded morphology. Inspect branch types after import before relying on a by-type rule; unmatched or misspelled types silently take the default policy.
|
|
99
|
+
|
|
100
|
+
## Respect `DLambda` cable-property constraints
|
|
101
|
+
|
|
102
|
+
`DLambda` requires uniform axial resistivity (`ra`) and membrane capacitance (`cm`) within each branch because both enter the AC length constant. Painting a different `CableProperty` onto only a sub-interval of one branch raises `ValueError`.
|
|
103
|
+
|
|
104
|
+
Resting potential and temperature may vary within a branch without violating this specific `DLambda` constraint.
|
|
105
|
+
|
|
106
|
+
If sub-branch `ra` or `cm` variation is scientifically required, choose a compatible policy such as `MaxCVLen`, or split the geometry into branches whose cable properties are internally uniform.
|
|
107
|
+
|
|
108
|
+
Always pass `d_lambda` explicitly. Also pass `frequency` explicitly when reproducibility matters; do not copy the concept-page shorthand that omits the required `d_lambda` argument.
|
|
109
|
+
|
|
110
|
+
## Check spatial convergence
|
|
111
|
+
|
|
112
|
+
Treat CV policy as a numerical assumption, not a visualization preference.
|
|
113
|
+
|
|
114
|
+
1. Choose a policy from the spatial question and inspect `cell.n_cv` and `cell.cvs`.
|
|
115
|
+
2. Run the scientific protocol with fixed morphology, mechanisms, stimulus, solver, and `dt`.
|
|
116
|
+
3. Refine only the CV policy: increase `cv_per_branch`, reduce `max_cv_len`, or reduce `d_lambda`.
|
|
117
|
+
4. Compare the relevant traces, spike timing, peaks, attenuation, or other spatial observable at the same probe locations.
|
|
118
|
+
5. Accept the coarser policy only when the observable remains within the task's stated tolerance.
|
|
119
|
+
|
|
120
|
+
Do not change `dt`, solver, and CV policy in the same convergence comparison. A stable CV count does not establish time-step or solver convergence.
|
|
121
|
+
|
|
122
|
+
Open `references/multicompartment/topology-building-and-visualization.md` when CV coverage, locset ownership, or the runtime node mapping must be inspected. Return to `references/multicompartment/multicompartment-cell-workflow.md` for mechanism declaration and simulation.
|
|
123
|
+
|
|
124
|
+
## Sources
|
|
125
|
+
|
|
126
|
+
- [Discretization](https://brainx.chaobrain.com/braincell/concepts/discretization.html)
|
|
127
|
+
- [Cell in BrainCell](https://brainx.chaobrain.com/braincell/tutorials/cell.html)
|
|
128
|
+
- [CVPolicy API](https://brainx.chaobrain.com/braincell/apis/generated/braincell.CVPolicy.html)
|
|
129
|
+
- [CVPerBranch API](https://brainx.chaobrain.com/braincell/apis/generated/braincell.CVPerBranch.html)
|
|
130
|
+
- [MaxCVLen API](https://brainx.chaobrain.com/braincell/apis/generated/braincell.MaxCVLen.html)
|
|
131
|
+
- [DLambda API](https://brainx.chaobrain.com/braincell/apis/generated/braincell.DLambda.html)
|
|
132
|
+
- [CVPolicyByTypeRule API](https://brainx.chaobrain.com/braincell/apis/generated/braincell.CVPolicyByTypeRule.html)
|
|
133
|
+
- [CompositeByTypePolicy API](https://brainx.chaobrain.com/braincell/apis/generated/braincell.CompositeByTypePolicy.html)
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Filter function library
|
|
2
|
+
|
|
3
|
+
Use this reference after opening `references/multicompartment/multicompartment-cell-workflow.md` when `paint()` or `place()` needs explicit branches, anatomical types, metric ranges, set composition, structural points, or sampled locations.
|
|
4
|
+
|
|
5
|
+
## Selection model
|
|
6
|
+
|
|
7
|
+
A region selects continuous branch intervals for `cell.paint(...)`; a locset selects branch-local points for `cell.place(...)`. Keep selection expressions separate from the mechanisms attached to them.
|
|
8
|
+
|
|
9
|
+
| Selection | Materialized result | Attach with |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `RegionExpr` | `RegionMask.intervals`, containing `(branch_id, prox, dist)` tuples | `cell.paint(region, *density_declarations)` |
|
|
12
|
+
| `LocsetExpr` | `LocsetMask.points` and human-readable `display_names` | `cell.place(locset, *point_declarations)` |
|
|
13
|
+
|
|
14
|
+
Resolve either expression with `morphology.select(expression)` before declaration when imported branch types, names, or topology may differ from the intended target.
|
|
15
|
+
|
|
16
|
+
## Region selectors
|
|
17
|
+
|
|
18
|
+
Use regions for cable properties, ions, channels, and other density declarations.
|
|
19
|
+
|
|
20
|
+
| API | Use when | Important behavior and result |
|
|
21
|
+
|---|---|---|
|
|
22
|
+
| `AllRegion()` | A declaration applies to every branch interval. | It selects the entire morphology. |
|
|
23
|
+
| `EmptyRegion()` | A compositional identity or intentionally empty target is required. | It selects no intervals. |
|
|
24
|
+
| `BranchSlice(branch_index, prox, dist)` | Exact branch ids and normalized branch intervals are known. | Scalar or parallel sequence inputs materialize explicit `(branch_id, prox, dist)` intervals. |
|
|
25
|
+
| `branch_in(property, values)` | A branch property must equal one value or belong to a set or tuple. | It is the helper form of `BranchInFilter(property, values)` and selects whole matching branches. |
|
|
26
|
+
| `BranchInFilter(property, values)` | The explicit selector class is preferable to the helper. | It has the same equality or membership behavior as `branch_in(...)`. |
|
|
27
|
+
| `branch_range(property, bounds, closed="neither")` | A numeric or BrainUnit quantity-valued branch property must lie in a range. | It is the helper form of `BranchRangeFilter`; use `None` for an open lower or upper bound. |
|
|
28
|
+
| `BranchRangeFilter(property, bounds, closed="neither")` | The explicit range-selector class is preferable to the helper. | `closed` controls whether the left, right, both, or neither bound is included. |
|
|
29
|
+
|
|
30
|
+
Supported branch properties in the documented implementation are:
|
|
31
|
+
|
|
32
|
+
| Family | Properties |
|
|
33
|
+
|---|---|
|
|
34
|
+
| Metadata and topology | `branch_id`, `name`, `type`, `parent_id`, `n_children`, `branch_order`, `n_tapers` |
|
|
35
|
+
| Geometry | `length`, `mean_radius`, `area`, `volume` |
|
|
36
|
+
|
|
37
|
+
Use BrainUnit quantities for physical bounds:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import brainunit as u
|
|
41
|
+
from braincell.filter import branch_in, branch_range
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
dendrites = branch_in(
|
|
45
|
+
"type",
|
|
46
|
+
("dendrite", "basal_dendrite", "apical_dendrite"),
|
|
47
|
+
)
|
|
48
|
+
long_branches = branch_range(
|
|
49
|
+
"length",
|
|
50
|
+
(100.0 * u.um, None),
|
|
51
|
+
closed="left",
|
|
52
|
+
)
|
|
53
|
+
target = dendrites & long_branches
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Do not use `branch_range(...)` to select a partial interval within each branch. It filters whole branches by a property; use `BranchSlice(...)` for branch-local intervals.
|
|
57
|
+
|
|
58
|
+
## Region set algebra
|
|
59
|
+
|
|
60
|
+
Compose small selectors rather than duplicating mechanism declarations.
|
|
61
|
+
|
|
62
|
+
| Expression | Result |
|
|
63
|
+
|---|---|
|
|
64
|
+
| `left | right` | Union of both regions. |
|
|
65
|
+
| `left & right` | Intersection of both regions. |
|
|
66
|
+
| `left - right` | Parts of `left` not selected by `right`. |
|
|
67
|
+
| `region.complement()` | All morphology cable outside the region. |
|
|
68
|
+
|
|
69
|
+
Overlapping slices are normalized in the materialized mask. Inspect `morphology.select(region).intervals` when exact interval boundaries matter.
|
|
70
|
+
|
|
71
|
+
## Locset selectors
|
|
72
|
+
|
|
73
|
+
Use locsets for clamps, probes, synapses, junctions, and other point declarations.
|
|
74
|
+
|
|
75
|
+
| API | Use when | Important behavior and result |
|
|
76
|
+
|---|---|---|
|
|
77
|
+
| `RootLocation(x)` | Select one normalized position on the root branch. | `RootLocation(0.5)` selects the root midpoint. |
|
|
78
|
+
| `AtLocation(branch, x)` | Select a known branch name or id and normalized position. | It returns one explicit branch-local point. |
|
|
79
|
+
| `at(branch, x)` | Use the helper form of `AtLocation`. | It returns the same explicit point selector. |
|
|
80
|
+
| `BranchPoints()` | Select bifurcation sites. | It chooses branch-point locations on the parent side. |
|
|
81
|
+
| `Terminals()` | Select terminal tips. | It chooses the distal endpoint of every terminal branch. |
|
|
82
|
+
| `UniformSamples(region, count)` | Place a fixed number of evenly distributed samples within a region. | It returns `count` branch-local points. |
|
|
83
|
+
| `RandomSamples(region, count, seed)` | Place reproducible random samples within a region. | The same morphology, region, count, and seed resolve to the same points. |
|
|
84
|
+
|
|
85
|
+
Locsets support `|`, `&`, and `-` for union, intersection, and difference. A composed locset still materializes as concrete `(branch_id, x)` points, and a multi-point locset expands one placed declaration per point during lowering.
|
|
86
|
+
|
|
87
|
+
## Verify and apply selectors
|
|
88
|
+
|
|
89
|
+
Resolve semantic selectors before attaching mechanisms, then use the same expressions for declaration and topology inspection.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
import braincell
|
|
93
|
+
import braincell.mech as mech
|
|
94
|
+
import brainunit as u
|
|
95
|
+
from braincell.filter import Terminals, branch_in, branch_range
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
morphology = braincell.Morphology.from_swc("neuron.swc")
|
|
99
|
+
|
|
100
|
+
dendrites = branch_in(
|
|
101
|
+
"type",
|
|
102
|
+
("dendrite", "basal_dendrite", "apical_dendrite"),
|
|
103
|
+
)
|
|
104
|
+
long_dendrites = dendrites & branch_range(
|
|
105
|
+
"length",
|
|
106
|
+
(100.0 * u.um, None),
|
|
107
|
+
closed="left",
|
|
108
|
+
)
|
|
109
|
+
terminal_sites = Terminals()
|
|
110
|
+
|
|
111
|
+
region_mask = morphology.select(long_dendrites)
|
|
112
|
+
terminal_mask = morphology.select(terminal_sites)
|
|
113
|
+
|
|
114
|
+
assert region_mask.intervals, "no long dendrite matched the imported labels"
|
|
115
|
+
assert terminal_mask.points, "morphology has no terminal sites"
|
|
116
|
+
print(region_mask.intervals)
|
|
117
|
+
print(terminal_mask.display_names)
|
|
118
|
+
|
|
119
|
+
cell = braincell.Cell(morphology)
|
|
120
|
+
cell.paint(
|
|
121
|
+
long_dendrites,
|
|
122
|
+
mech.Channel(
|
|
123
|
+
"IL",
|
|
124
|
+
g_max=0.03 * u.mS / u.cm**2,
|
|
125
|
+
E=-65.0 * u.mV,
|
|
126
|
+
),
|
|
127
|
+
)
|
|
128
|
+
cell.place(terminal_sites, mech.StateProbe())
|
|
129
|
+
cell.init_state()
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Use a region only with `paint()` and a locset only with `place()`. A selector that resolves correctly against `Morphology` can still map unexpectedly after discretization; open `references/multicompartment/topology-building-and-visualization.md` to inspect CV ownership and runtime placement.
|
|
133
|
+
|
|
134
|
+
## Exported but unavailable selectors
|
|
135
|
+
|
|
136
|
+
The current filter API exports additional names, but the official filter tutorial marks these selectors as not implemented:
|
|
137
|
+
|
|
138
|
+
| Exported name | Intended family |
|
|
139
|
+
|---|---|
|
|
140
|
+
| `SubtreeRegion` | A branch and its distal subtree. |
|
|
141
|
+
| `RadiusRangeRegion` | Cable selected by local radius. |
|
|
142
|
+
| `TreeDistanceRegion` | Cable selected by along-tree distance. |
|
|
143
|
+
| `EuclideanDistanceRegion` | Cable selected by straight-line distance. |
|
|
144
|
+
| `RegionAnchors` | Region anchor construction. |
|
|
145
|
+
| `StepSamples` | Step-spaced locset sampling. |
|
|
146
|
+
|
|
147
|
+
Do not use an exported name as proof that the operation works. Prefer the implemented selectors above, construct equivalent explicit slices or points when practical, or inspect the installed BrainCell version before using a newly implemented surface.
|
|
148
|
+
|
|
149
|
+
## Common failures
|
|
150
|
+
|
|
151
|
+
- Do not pass a region to `place()` or a locset to `paint()`.
|
|
152
|
+
- Do not guess imported type strings; inspect `branch.type` values or materialize the selector first.
|
|
153
|
+
- Do not omit BrainUnit quantities from physical metric bounds.
|
|
154
|
+
- Do not confuse `branch_range(...)` property filtering with `BranchSlice(...)` interval selection.
|
|
155
|
+
- Do not use unseeded random placement when the model must be reproducible.
|
|
156
|
+
- Do not assume a nonempty morphology selector maps to the expected CV midpoint; inspect the topology after choosing the CV policy.
|
|
157
|
+
|
|
158
|
+
## Sources
|
|
159
|
+
|
|
160
|
+
- [Regions and locsets](https://brainx.chaobrain.com/braincell/concepts/regions_locsets.html)
|
|
161
|
+
- [Region and locset filters](https://brainx.chaobrain.com/braincell/tutorials/filter.html)
|
|
162
|
+
- [braincell.filter API](https://brainx.chaobrain.com/braincell/apis/filter.html)
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# BrainCell morphology IO, loading paths, and validation
|
|
2
|
+
|
|
3
|
+
Use this reference after opening `references/multicompartment/multicompartment-cell-workflow.md` when geometry must come from SWC, Neurolucida ASC, NeuroML2, NeuroMorpho.Org, or a BrainCell checkpoint. Keep manual branch construction in `references/multicompartment/braincell-manual-morphology-construction.md`.
|
|
4
|
+
|
|
5
|
+
## Choose a loading path
|
|
6
|
+
|
|
7
|
+
Each reader returns the same simulation-facing `Morphology`; choose the path from the source format and the validation evidence the task requires.
|
|
8
|
+
|
|
9
|
+
| API | Use when | Important behavior and result |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `Morphology.from_swc(path, options=..., mode=..., return_report=False)` | The reconstruction is an SWC point/parent table. | It maps SWC structure identifiers to typed branches, validates the tree, and returns a `Morphology`; with `return_report=True`, it returns `(morphology, SwcReport)`. |
|
|
12
|
+
| `Morphology.from_asc(path, return_report=False)` | The reconstruction is Neurolucida ASC and its spines, markers, contours, or metadata matter. | It parses the richer nested format and returns a `Morphology`; with `return_report=True`, it also returns an `AscReport`. |
|
|
13
|
+
| `NeuroMlReader().read(path)` | The source is NeuroML2. | It imports segment groups and cable geometry into a `Morphology`; it does not import channel or network definitions. |
|
|
14
|
+
| `Morphology.from_neuromorpho(neuron_id, ...)` | A known NeuroMorpho.Org integer neuron id should be downloaded, cached, parsed, and returned directly. | It reuses the cached download on later calls and returns a `Morphology`. |
|
|
15
|
+
| `braincell.io.load_neuromorpho(neuron_id, return_report=False)` | The NeuroMorpho path also needs the IO-module surface or a validation report. | It returns the same morphology path; with `return_report=True`, it returns `(morphology, report)`. |
|
|
16
|
+
| `braincell.io.load_morpho(path)` | A processed BrainCell morphology checkpoint should be reused without parsing the original reconstruction. | It returns the stored `Morphology` or raises a checkpoint compatibility error. |
|
|
17
|
+
|
|
18
|
+
Use SWC for the portable default interchange path. Use ASC when its additional annotations must survive import. Use a BrainCell checkpoint only after the source reconstruction has already been parsed, reviewed, and optionally edited.
|
|
19
|
+
|
|
20
|
+
## Load and validate SWC
|
|
21
|
+
|
|
22
|
+
An SWC load is a parse-and-validation operation; request the report whenever malformed geometry, automatic repairs, or structure-type mapping could change the model.
|
|
23
|
+
|
|
24
|
+
| API | Description |
|
|
25
|
+
|---|---|
|
|
26
|
+
| `SwcReadOptions(standardize_safe_fixes=..., unknown_type_as_custom=..., require_root_type_soma=...)` | Use to choose whether safe corrections are applied, unknown structure ids become `CustomBranch`, and the root must be a soma. |
|
|
27
|
+
| `Morphology.from_swc(path, options=options, return_report=True)` | Use for the normal load-and-review path; it returns the morphology and the findings or fixes in `SwcReport`. |
|
|
28
|
+
| `SwcReader().check(path)` | Use when the file must be validated without constructing a `Morphology`; it returns the report. |
|
|
29
|
+
| `SwcReader().read(path)` | Use only when the lower-level reader is needed directly; it parses and returns the morphology. |
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import braincell
|
|
33
|
+
from braincell.filter import branch_in
|
|
34
|
+
from braincell.io import SwcReadOptions
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
options = SwcReadOptions(
|
|
38
|
+
standardize_safe_fixes=True,
|
|
39
|
+
unknown_type_as_custom=True,
|
|
40
|
+
require_root_type_soma=True,
|
|
41
|
+
)
|
|
42
|
+
morphology, report = braincell.Morphology.from_swc(
|
|
43
|
+
"neuron.swc",
|
|
44
|
+
options=options,
|
|
45
|
+
return_report=True,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
print(report)
|
|
49
|
+
print(morphology.topo())
|
|
50
|
+
|
|
51
|
+
soma = morphology.select(branch_in("type", "soma"))
|
|
52
|
+
assert soma.intervals, "validated morphology has no branch typed as soma"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
SWC ids `1`, `2`, `3`, and `4` map to soma, axon, basal dendrite, and apical dendrite. Other ids become custom branches only when the chosen reader policy permits it. Inspect the report before accepting disconnected points, a missing soma, unknown types, or applied repairs.
|
|
56
|
+
|
|
57
|
+
## Handle format-specific behavior
|
|
58
|
+
|
|
59
|
+
### Neurolucida ASC
|
|
60
|
+
|
|
61
|
+
Use the high-level constructor unless lower-level ASC models are required.
|
|
62
|
+
|
|
63
|
+
| API | Description |
|
|
64
|
+
|---|---|
|
|
65
|
+
| `Morphology.from_asc(path, return_report=True)` | Load typed branches and return the morphology with an `AscReport` containing issues and metadata. |
|
|
66
|
+
| `AscReader().read(path)` | Parse ASC through the lower-level reader and return the morphology. |
|
|
67
|
+
| `AscSpineRecord` / `AscMetadata` | Inspect spine annotations or file-level metadata when those ASC-only details affect preprocessing. |
|
|
68
|
+
|
|
69
|
+
Do not assume a successful ASC parse makes coincident points, radii, branch labels, or imported annotations appropriate for the intended simulation.
|
|
70
|
+
|
|
71
|
+
### NeuroML2
|
|
72
|
+
|
|
73
|
+
Use `NeuroMlReader` only for morphology import:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from braincell.io import NeuroMlReader
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
morphology = NeuroMlReader().read("neuron.cell.nml")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Declare ions, channels, clamps, probes, and network structure separately. BrainCell does not import those NeuroML2 definitions automatically.
|
|
83
|
+
|
|
84
|
+
### NeuroMorpho.Org
|
|
85
|
+
|
|
86
|
+
Install the IO extra before using the repository client: `python -m pip install -U "braincell[io]"`.
|
|
87
|
+
|
|
88
|
+
| API | Description |
|
|
89
|
+
|---|---|
|
|
90
|
+
| `Morphology.from_neuromorpho(neuron_id, ...)` | Use the shortest path for a known integer neuron id; it downloads once, caches, parses, and returns the morphology. |
|
|
91
|
+
| `NeuroMorphoClient().iter_search(**criteria)` | Search by criteria such as species, brain region, or cell type; it yields typed neuron records. |
|
|
92
|
+
| `NeuroMorphoClient().get_neuron(neuron_id)` | Retrieve the detailed record for one integer neuron id. |
|
|
93
|
+
| `NeuroMorphoClient().download(neuron_id)` | Download a reconstruction and return its download record. |
|
|
94
|
+
| `braincell.io.fetch_neuromorpho(neuron_id, mode="standard")` | Fetch raw files without parsing; use `"standard"`, `"original"`, or `"both"` and receive a `NeuroMorphoDownloadRecord`. |
|
|
95
|
+
| `cache_dir=...` | Use on repository entry points when the default user cache must be replaced with an explicit location. |
|
|
96
|
+
|
|
97
|
+
Use the integer id from the neuron's NeuroMorpho.Org URL, not its display name. Treat cached content as an IO optimization, not as validation evidence.
|
|
98
|
+
|
|
99
|
+
## Save and reload processed geometry
|
|
100
|
+
|
|
101
|
+
Checkpoint a cleaned or edited BrainCell object when the exact processed geometry must be reused.
|
|
102
|
+
|
|
103
|
+
| API | Description |
|
|
104
|
+
|---|---|
|
|
105
|
+
| `braincell.io.save_morpho(morphology, path)` | Serialize a morphology and return the written `Path`. |
|
|
106
|
+
| `braincell.io.load_morpho(path)` | Reload a morphology checkpoint without reparsing its original source. |
|
|
107
|
+
| `braincell.io.save_branch(branch, path)` | Serialize one branch. |
|
|
108
|
+
| `braincell.io.load_branch(path)` | Reload one branch checkpoint. |
|
|
109
|
+
| `CheckpointError` | Catch when a checkpoint cannot be read. |
|
|
110
|
+
| `CheckpointVersionError` | Catch when the file format version is unsupported by the installed BrainCell. |
|
|
111
|
+
|
|
112
|
+
Do not use a checkpoint to hide the original validation record. Preserve the source identifier, reader options, report, BrainCell version, and any edits with the model provenance.
|
|
113
|
+
|
|
114
|
+
## Verify the loaded morphology
|
|
115
|
+
|
|
116
|
+
A successful load proves that the reader returned a `Morphology` under the chosen validation policy; it does not prove that the reconstruction is biologically or numerically suitable.
|
|
117
|
+
|
|
118
|
+
1. Read the validation report and distinguish detected issues from applied fixes.
|
|
119
|
+
2. Inspect `morphology.topo()` for the intended root, connectivity, names, and parent-child structure.
|
|
120
|
+
3. Select soma, axon, and dendrite types with `morphology.select(...)`; confirm that later region expressions will reach the intended branches.
|
|
121
|
+
4. Inspect coordinates, lengths, and radii for zero-length, disconnected, or implausible geometry.
|
|
122
|
+
5. Visualize the branch tree before choosing a CV policy or attaching mechanisms.
|
|
123
|
+
6. Record the reader options, input identity, and checkpoint version with the simulation.
|
|
124
|
+
|
|
125
|
+
Open `references/multicompartment/topology-building-and-visualization.md` when branch, CV, or runtime placement must be inspected visually. Return to `references/multicompartment/multicompartment-cell-workflow.md` after validation to choose a CV policy and declare the cell.
|
|
126
|
+
|
|
127
|
+
## Sources
|
|
128
|
+
|
|
129
|
+
- [IO overview](https://brainx.chaobrain.com/braincell/file_formats/overview.html)
|
|
130
|
+
- [SWC](https://brainx.chaobrain.com/braincell/file_formats/swc.html)
|
|
131
|
+
- [Neurolucida ASC](https://brainx.chaobrain.com/braincell/file_formats/asc.html)
|
|
132
|
+
- [NeuroML2](https://brainx.chaobrain.com/braincell/file_formats/neuroml2.html)
|
|
133
|
+
- [NeuroMorpho.Org](https://brainx.chaobrain.com/braincell/file_formats/neuromorpho.html)
|
|
134
|
+
- [Checkpointing](https://brainx.chaobrain.com/braincell/file_formats/checkpointing.html)
|
|
135
|
+
- [Morphology](https://brainx.chaobrain.com/braincell/concepts/morphology.html)
|