brainx-skill 1.0.6 → 1.0.9

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.
Files changed (120) hide show
  1. package/README.md +10 -8
  2. package/adapters/gemini.js +7 -0
  3. package/adapters/opencode.js +7 -0
  4. package/adapters/windsurf.js +7 -0
  5. package/installation/lib/installer.js +4 -1
  6. package/manifest.json +6 -1
  7. package/package.json +8 -2
  8. package/skills/braincell/SKILL.md +182 -0
  9. package/skills/braincell/references/area-scaled-hh-pattern.md +54 -0
  10. package/skills/braincell/references/braincell-custom-ion-channel-authoring.md +273 -0
  11. package/skills/braincell/references/channel-library.md +85 -0
  12. package/skills/braincell/references/ion-library.md +87 -0
  13. package/skills/braincell/references/mixions-for-adaptation.md +81 -0
  14. package/skills/braincell/references/multicompartment/braincell-manual-morphology-construction.md +180 -0
  15. package/skills/braincell/references/multicompartment/cv-policy-reference.md +133 -0
  16. package/skills/braincell/references/multicompartment/filter-function-library.md +154 -0
  17. package/skills/braincell/references/multicompartment/morphology-io-loading-validation.md +135 -0
  18. package/skills/braincell/references/multicompartment/multicompartment-cell-workflow.md +391 -0
  19. package/skills/braincell/references/multicompartment/probe-reference.md +128 -0
  20. package/skills/braincell/references/multicompartment/topology-building-and-visualization.md +260 -0
  21. package/skills/braincell/references/scripts/calcium_channel_gating.py +66 -0
  22. package/skills/braincell/references/scripts/cell_multicompartment_reference.py +221 -0
  23. package/skills/braincell/references/scripts/channel_ablation.py +61 -0
  24. package/skills/braincell/references/scripts/fi_curve.py +68 -0
  25. package/skills/braincell/references/scripts/hh_neuron_basics.py +59 -0
  26. package/skills/braincell/references/scripts/spike_frequency_adaptation.py +75 -0
  27. package/skills/braincell/references/scripts/t_current_rebound.py +72 -0
  28. package/skills/braincell/references/scripts/thalamic_neurons.py +228 -0
  29. package/skills/braincell/references/solver-library-with-effects.md +188 -0
  30. package/skills/brainevent/SKILL.md +268 -0
  31. package/skills/brainevent/references/connectivity-variants.md +312 -0
  32. package/skills/brainevent/references/custom-operators-cpu.md +304 -0
  33. package/skills/brainevent/references/custom-operators-gpu.md +468 -0
  34. package/skills/brainevent/references/scripts/102_EI_net_1996.py +107 -0
  35. package/skills/brainevent/references/scripts/204_joglekar_2018_propagation.py +168 -0
  36. package/skills/brainevent/references/scripts/coba_ei_teaching.py +356 -0
  37. package/skills/brainevent/references/sparse-formats.md +182 -0
  38. package/skills/brainevent/references/synaptic-plasticity.md +285 -0
  39. package/skills/brainmass/SKILL.md +290 -0
  40. package/skills/brainmass/references/batch-transform-acceleration.md +136 -0
  41. package/skills/brainmass/references/brainstate/parameter-constraints-regularization.md +214 -0
  42. package/skills/brainmass/references/brainstate/parameter-transforms-regularizers-catalog.md +171 -0
  43. package/skills/brainmass/references/braintools/cogtask.md +190 -0
  44. package/skills/brainmass/references/braintools/data-preprocessing.md +83 -0
  45. package/skills/brainmass/references/braintools/metric.md +157 -0
  46. package/skills/brainmass/references/braintools/optimizer.md +187 -0
  47. package/skills/brainmass/references/braintools/parameter-initializer.md +187 -0
  48. package/skills/brainmass/references/braintools/surrogate.md +151 -0
  49. package/skills/brainmass/references/coupling-network-api.md +148 -0
  50. package/skills/brainmass/references/datasets-api.md +72 -0
  51. package/skills/brainmass/references/fitting-with-objectives-api.md +146 -0
  52. package/skills/brainmass/references/forward-observation-api.md +131 -0
  53. package/skills/brainmass/references/horn-task-training.md +199 -0
  54. package/skills/brainmass/references/modellibrary.md +104 -0
  55. package/skills/brainmass/references/noiseprocesses.md +121 -0
  56. package/skills/brainmass/references/parameter-sweeps-and-regime-analysis.md +130 -0
  57. package/skills/brainmass/references/scripts/eeg-fitting-with-gradients.py +230 -0
  58. package/skills/brainmass/references/scripts/gradient-free-fitting.py +106 -0
  59. package/skills/brainmass/references/scripts/hopf-bifurcation-single-node.py +78 -0
  60. package/skills/brainmass/references/scripts/horn-cognitive-task-training.py +211 -0
  61. package/skills/brainmass/references/scripts/jansen-rit-eeg-proxy.py +76 -0
  62. package/skills/brainmass/references/scripts/kuramoto-synchronization.py +81 -0
  63. package/skills/brainmass/references/scripts/linear-baseline-node.py +81 -0
  64. package/skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +249 -0
  65. package/skills/brainmass/references/scripts/seizure-epileptor-case-study.py +126 -0
  66. package/skills/brainmass/references/scripts/wilson-cowan-ei-dynamics.py +86 -0
  67. package/skills/brainmass/references/scripts/wong-wang-decision-making.py +167 -0
  68. package/skills/brainmass/references/scripts/wong-wang-dmf-resting-state.py +72 -0
  69. package/skills/brainmass/references/visualization-analysis-api.md +130 -0
  70. package/skills/brainpy-state/SKILL.md +232 -0
  71. package/skills/brainpy-state/references/array-creation.md +158 -0
  72. package/skills/brainpy-state/references/brain-dynamics-delay-protocol.md +96 -0
  73. package/skills/brainpy-state/references/braintools/brainstate-control-flow-patterns.md +334 -0
  74. package/skills/brainpy-state/references/braintools/data-preprocessing.md +79 -0
  75. package/skills/brainpy-state/references/braintools/metric.md +152 -0
  76. package/skills/brainpy-state/references/braintools/optimizer.md +179 -0
  77. package/skills/brainpy-state/references/braintools/parameter-initializer.md +183 -0
  78. package/skills/brainpy-state/references/braintools/surrogate.md +147 -0
  79. package/skills/brainpy-state/references/component-selection.md +273 -0
  80. package/skills/brainpy-state/references/nest-compatible/devices.md +157 -0
  81. package/skills/brainpy-state/references/nest-compatible/divergence-and-parity.md +114 -0
  82. package/skills/brainpy-state/references/nest-compatible/integration-categories.md +41 -0
  83. package/skills/brainpy-state/references/nest-compatible/model-library.md +200 -0
  84. package/skills/brainpy-state/references/nest-compatible/nest-workflow.md +156 -0
  85. package/skills/brainpy-state/references/nest-compatible/network-building.md +264 -0
  86. package/skills/brainpy-state/references/nest-compatible/scripts/brette_et_al_2007.py +320 -0
  87. package/skills/brainpy-state/references/nest-compatible/scripts/brunel_alpha.py +108 -0
  88. package/skills/brainpy-state/references/nest-compatible/scripts/brunel_delta.py +93 -0
  89. package/skills/brainpy-state/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +171 -0
  90. package/skills/brainpy-state/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +147 -0
  91. package/skills/brainpy-state/references/nest-compatible/scripts/spatial_gaussex.py +112 -0
  92. package/skills/brainpy-state/references/nest-compatible/scripts/synapsecollection.py +198 -0
  93. package/skills/brainpy-state/references/nest-compatible/synapse-and-connectivity.md +153 -0
  94. package/skills/brainpy-state/references/projection-patterns.md +125 -0
  95. package/skills/brainpy-state/references/scripts/103_COBA_2005.py +86 -0
  96. package/skills/brainpy-state/references/scripts/106_COBA_HH_2007.py +181 -0
  97. package/skills/brainpy-state/references/scripts/107_gamma_oscillation_1996.py +156 -0
  98. package/skills/brainpy-state/references/scripts/109_fast_global_oscillation.py +111 -0
  99. package/skills/brainpy-state/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +221 -0
  100. package/skills/brainpy-state/references/scripts/training-snn.py +119 -0
  101. package/skills/brainstate/SKILL.md +1 -1
  102. package/skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +250 -399
  103. package/skills/brainstate/references/brainstate/brainstate-transformed-diagnostics.md +6 -2
  104. package/skills/brainstate/references/brainstate/parameter-constraints-regularization.md +16 -2
  105. package/skills/brainstate/references/brainstate/parameter-transforms-regularizers-catalog.md +8 -3
  106. package/skills/brainstate/references/brainstate/randomness-and-reproducibility.md +64 -143
  107. package/skills/brainstate/references/brainstate/transformation-grad-expansion.md +13 -1
  108. package/skills/brainstate/references/brainstate/transformation-jit-expansion.md +11 -1
  109. package/skills/brainstate/references/brainstate/transformation-vmap-expansion.md +35 -7
  110. package/skills/brainstate/references/collective_model_operations.md +9 -9
  111. package/skills/brainstate/references/extension_mechanisms.md +12 -1
  112. package/skills/brainstate/references/libraries/prebuilt-activation-library.md +106 -97
  113. package/skills/brainstate/references/libraries/prebuilt-layer-library.md +102 -176
  114. package/skills/brainstate/references/model-interop-and-migration.md +11 -1
  115. package/skills/brainstate/references/size-inference-variations.md +11 -0
  116. package/skills/brainstate/references/state-graph-operations.md +13 -15
  117. package/skills/brainstate/references/state_collections_and_utilities.md +12 -1
  118. package/skills/brainx-general-guard/SKILL.md +68 -0
  119. package/skills/brainstate/references/braintools-optimizer-reference.md +0 -133
  120. package/skills/brainstate/references/libraries/solver-library-with-effects.md +0 -85
@@ -0,0 +1,85 @@
1
+ # BrainCell channel library
2
+
3
+ Use this reference when selecting a built-in membrane channel, matching it to its ion owner, or designing a controlled channel comparison. Author a custom channel only after the built-in library and literature-derived templates have been checked.
4
+
5
+ ## Mental model
6
+
7
+ A channel computes membrane current from voltage, its internal gating state, and the `IonInfo` supplied by its `root_type`.
8
+
9
+ Built-in names usually follow `<current>_<source><year>`, so a similar current name does not imply interchangeable kinetics. Match the requested model, paper, temperature convention, reversal-potential treatment, and ion dependency before tuning `g_max`.
10
+
11
+ ## Choose a channel family
12
+
13
+ ### Sodium channels
14
+
15
+ Use sodium channels for inward current that initiates or sustains depolarization.
16
+
17
+ | API | Description |
18
+ |---|---|
19
+ | `braincell.channel.Na_HH1952(size, ...)` | Use for the classical Hodgkin-Huxley 1952 sodium current. |
20
+ | `braincell.channel.Na_TM1991(size, ...)` | Use when reproducing the Traub-Miles 1991 sodium formulation. |
21
+ | `braincell.channel.Na_Ba2002(size, ...)` | Use for models based on the Bazhenov 2002 sodium current. |
22
+ | `braincell.channel.NaF_SU2015_DCN(size, ...)` | Use when the requested model requires the fast sodium current from the Sudhakar 2015 DCN template family. |
23
+ | `braincell.channel.NaP_SU2015_DCN(size, ...)` | Use when the requested model requires the persistent sodium current from the same template family. |
24
+
25
+ Attach these channels to a sodium ion. Do not select among them by maximal conductance alone; their gating equations and source-model conventions differ.
26
+
27
+ ### Potassium channels
28
+
29
+ Use potassium channels for repolarization, resting conductance, delayed rectification, transient A-current, M-current, or inward rectification.
30
+
31
+ | API | Description |
32
+ |---|---|
33
+ | `braincell.channel.K_HH1952(size, ...)` | Use for the classical Hodgkin-Huxley 1952 delayed-rectifier potassium current. |
34
+ | `braincell.channel.K_TM1991(size, ...)` | Use when reproducing the Traub-Miles 1991 potassium formulation. |
35
+ | `braincell.channel.K_Leak(size, ...)` | Use for an ion-specific potassium leak current owned by a potassium ion. |
36
+ | `braincell.channel.KDR_Ba2002(size, ...)` | Use for the Bazhenov 2002 delayed-rectifier potassium current. |
37
+ | `braincell.channel.KA1_HM1992(size, ...)` | Use for the Huguenard-McCormick 1992 `IA1` transient potassium current. |
38
+ | `braincell.channel.KA2_HM1992(size, ...)` | Use for the Huguenard-McCormick 1992 `IA2` transient potassium current. |
39
+
40
+ The API also exposes `KM_*`, `Kv*`, and `Kir*` template families. Use the exact literature-derived class when the user names a model or source paper; consult the installed API for the complete list.
41
+
42
+ ### Calcium channels
43
+
44
+ Use calcium channels for calcium entry, low- or high-threshold activation, rebound behavior, or calcium-dependent downstream mechanisms.
45
+
46
+ | API | Description |
47
+ |---|---|
48
+ | `braincell.channel.CaL_IS2008(size, ...)` | Use for the Inoue-Strowbridge 2008 L-type calcium current. |
49
+ | `braincell.channel.CaN_IS2008(size, ...)` | Use for the Inoue-Strowbridge 2008 calcium-activated non-selective cation current. |
50
+ | `braincell.channel.CaT_HM1992(size, ...)` | Use for the Huguenard-McCormick 1992 low-threshold T-type calcium current. |
51
+ | `braincell.channel.CaT_HP1992(size, ...)` | Use for the Huguenard-Prince 1992 T-type current for reticular-nucleus models. |
52
+ | `braincell.channel.CaHT_HM1992(size, ...)` | Use for the Huguenard-McCormick 1992 high-threshold calcium current. |
53
+
54
+ Attach calcium channels to a calcium ion. Use a dynamic calcium ion when accumulated calcium must affect reversal potential or calcium-dependent channels; otherwise a fixed calcium ion may be sufficient.
55
+
56
+ ### Mixed-ion, HCN, and leak channels
57
+
58
+ | API | Description |
59
+ |---|---|
60
+ | `braincell.channel.AHP_De1994(size, ...)` | Use for a calcium-activated potassium AHP current; attach it to `MixIons(k, ca)` in that order. |
61
+ | `braincell.channel.HCN_HM1992(size, E=..., ...)` | Use for the Huguenard-McCormick 1992 hyperpolarization-activated current and related sag or rebound behavior. |
62
+ | `braincell.channel.IL(size, E=..., g_max=...)` | Use for a root-cell leakage current with its own reversal potential; attach it directly to the cell. |
63
+ | `braincell.channel.LeakageChannel` | Use as the base class when implementing leakage-channel dynamics, not as the normal concrete leak mechanism. |
64
+
65
+ The `Kca*`, `HCN*`, and template-import families contain model-specific alternatives. Prefer the exact source match over a name that merely has the same broad current type.
66
+
67
+
68
+ ## Route custom authoring
69
+
70
+ Open `references/braincell-custom-ion-channel-authoring.md` only when:
71
+
72
+ - no built-in or literature-derived class implements the required kinetics;
73
+ - the requested ion dependency can be stated as a correct `root_type`;
74
+ - the governing equations, units, initialization rule, and validation target are known.
75
+
76
+ For a multicompartment task, establish the `Morphology -> Cell -> paint/place -> init_state` workflow in `references/multicompartment/multicompartment-cell-workflow.md` before reusing the custom-authoring route.
77
+
78
+
79
+ ## Sources
80
+
81
+ - Ions & Channels: https://brainx.chaobrain.com/braincell/concepts/ions_channels.html
82
+ - Channels tutorial: https://brainx.chaobrain.com/braincell/tutorials/channel.html
83
+ - `braincell.channel` API: https://brainx.chaobrain.com/braincell/apis/braincell.channel.html
84
+ - Channel ablation: https://brainx.chaobrain.com/braincell/examples/channel_ablation.html
85
+ - Spike-frequency adaptation: https://brainx.chaobrain.com/braincell/examples/spike_frequency_adaptation.html
@@ -0,0 +1,87 @@
1
+ # BrainCell ion library
2
+
3
+ Use this reference when choosing a fixed, Nernst-initialized, or dynamic BrainCell ion, or when a channel depends on more than one ion species. Use the built-in ion classes before authoring a custom ion.
4
+
5
+ ## Mental model
6
+
7
+ An `Ion` owns one species' `Ci`, `Co`, `E`, and `valence`, packages them as `IonInfo`, and supplies that information to the channels whose currents it aggregates.
8
+
9
+ - A fixed ion keeps its concentrations and reversal potential constant.
10
+ - An initialized-Nernst ion keeps its concentrations fixed but computes `E` from them during initialization and reset.
11
+ - A dynamic-Nernst ion stores `Ci` as `DiffEqState`, derives `E` from the current `Ci`, and lets a concrete ion define `dCi/dt`.
12
+
13
+ Channels carry current; ions organize the shared electrochemical state that drives those currents. Do not put a shared reversal potential independently on every ion-specific channel.
14
+
15
+ ## Choose an ion
16
+
17
+ | API | Use when | Important behavior |
18
+ |---|---|---|
19
+ | `braincell.ion.SodiumFixed(size, E=...)` | Use for classical sodium currents with a prescribed reversal potential. | It keeps sodium electrochemical values fixed and accepts channels whose `root_type` is `Sodium`. |
20
+ | `braincell.ion.SodiumInitNernst(size, ...)` | Use when fixed sodium concentrations should determine the initial reversal potential. | It recomputes `E` from the Nernst equation during initialization and reset; it does not integrate concentration. |
21
+ | `braincell.ion.PotassiumFixed(size, E=...)` | Use for classical potassium currents with a prescribed reversal potential. | It keeps potassium electrochemical values fixed and accepts channels whose `root_type` is `Potassium`. |
22
+ | `braincell.ion.PotassiumInitNernst(size, ...)` | Use when fixed potassium concentrations should determine the initial reversal potential. | It recomputes `E` from the Nernst equation during initialization and reset; it does not integrate concentration. |
23
+ | `braincell.ion.CalciumFixed(size, E=..., ...)` | Use when calcium current matters but intracellular calcium feedback does not. | It keeps calcium concentration and reversal potential fixed. |
24
+ | `braincell.ion.CalciumInitNernst(size, ...)` | Use when fixed calcium concentrations should initialize `E`. | It derives `E` from fixed `Ci`, `Co`, temperature, and valence during initialization and reset. |
25
+ | `braincell.ion.CalciumDetailed(size, C_rest=..., tau=..., d=...)` | Use when calcium influx must change intracellular calcium and its Nernst reversal potential. | It integrates `Ci`, receives total current from its calcium channels, and derives `E` live from the current concentration. |
26
+ | `braincell.ion.CalciumFirstOrder(size, ...)` | Use when simplified first-order calcium concentration dynamics are sufficient. | It replaces the detailed calcium-removal model with a lower-complexity concentration ODE. |
27
+
28
+ The ion API also exposes literature-derived calcium-dynamics templates such as `CdpHVA_SU2015_DCN`, `CdpLVA_SU2015_DCN`, and `CdpStC_MA2020_GoC`. Select one only when the requested model or source paper matches it; use the official `braincell.ion` API for the complete installed list.
29
+
30
+
31
+ ## Use dynamic calcium
32
+
33
+ `CalciumDetailed` couples the summed calcium current to intracellular concentration, then feeds the resulting Nernst potential back to calcium channels.
34
+
35
+ | API | Description |
36
+ |---|---|
37
+ | `braincell.ion.CalciumDetailed(...)` | Use for calcium-dependent adaptation, rebound, signaling, or another workflow in which `Ci` changes during integration. |
38
+ | `ca.Ci.value` | Read the current intracellular concentration after initialization; it is the value carried by the ion's `DiffEqState`. |
39
+ | `ca.E` | Read the current Nernst reversal potential; it is derived from the current `Ci`, not a fixed cache. |
40
+
41
+ ```python
42
+ ca = braincell.ion.CalciumDetailed(
43
+ size=1,
44
+ C_rest=5.0e-5 * u.mM,
45
+ tau=10.0 * u.ms,
46
+ d=0.5 * u.um,
47
+ )
48
+ ca.add(
49
+ ICaT=braincell.channel.CaT_HM1992(
50
+ size=1,
51
+ g_max=2.1 * u.mS / u.cm**2,
52
+ )
53
+ )
54
+ ```
55
+
56
+ The concentration ODE receives the total current from all channels owned by this calcium ion. Do not update `Ci` manually inside the cell loop or compute a second independent reversal potential in the channel.
57
+
58
+ Open `references/mixions-for-adaptation.md` when dynamic calcium participates in an AHP/KCa adaptation or rebound workflow.
59
+
60
+ ## Combine ion dependencies
61
+
62
+ Use `MixIons` only when one channel's `root_type` requires several ion species.
63
+
64
+ | API | Description |
65
+ |---|---|
66
+ | `braincell.MixIons(*ions)` | Use to create a multi-ion owner in the exact order declared by the target channel's `root_type`. |
67
+ | `braincell.mix_ions(*ions)` | Use as the convenience function for the same combination. |
68
+ | `mixed.add(name=channel)` | Use to attach a channel after the ordered ion tuple has been constructed. |
69
+
70
+ ```python
71
+ kca = braincell.MixIons(k, ca)
72
+ kca.add(
73
+ IAHP=braincell.channel.AHP_De1994(
74
+ size=1,
75
+ g_max=0.3 * u.mS / u.cm**2,
76
+ )
77
+ )
78
+ ```
79
+
80
+ For `AHP_De1994`, the required order is potassium followed by calcium. Match `root_type` exactly; `(ca, k)` is not interchangeable with `(k, ca)`.
81
+
82
+
83
+ ## Sources
84
+
85
+ - Ions & Channels: https://brainx.chaobrain.com/braincell/concepts/ions_channels.html
86
+ - Ions tutorial: https://brainx.chaobrain.com/braincell/tutorials/ion.html
87
+ - `braincell.ion` API: https://brainx.chaobrain.com/braincell/apis/braincell.ion.html
@@ -0,0 +1,81 @@
1
+ # MixIons for adaptation
2
+
3
+ Use this reference when adding a calcium-activated potassium current, calcium-dependent afterhyperpolarization, spike-frequency adaptation, or a thalamic/rebound variant that needs dynamic calcium plus a K/Ca mixed current.
4
+
5
+ In single-compartment models, use the class pattern below directly. In multicompartment `Cell` work, use this reference for ion/channel composition choices, but keep morphology, targeting, `paint`, `place`, CV policy, clamps, and probes in `references/multicompartment/multicompartment-cell-workflow.md`.
6
+
7
+ ## Rule
8
+
9
+ Use `braincell.MixIons(k, ca)` only when a channel depends on multiple ions. For calcium-activated potassium currents, potassium supplies the reversal potential and calcium supplies intracellular concentration dynamics. Keep ion order consistent with the channel's `root_type`.
10
+
11
+ ## Pattern
12
+
13
+ ```python
14
+ import braincell
15
+ import braintools
16
+ import brainunit as u
17
+
18
+
19
+ class AdaptingCell(braincell.SingleCompartment):
20
+ def __init__(self, size, solver="ind_exp_euler"):
21
+ super().__init__(
22
+ size,
23
+ V_initializer=braintools.init.Constant(-65. * u.mV),
24
+ V_th=20. * u.mV,
25
+ solver=solver,
26
+ )
27
+
28
+ self.na = braincell.ion.SodiumFixed(size, E=50. * u.mV)
29
+ self.na.add(INa=braincell.channel.Na_Ba2002(size, V_sh=-30. * u.mV))
30
+
31
+ self.k = braincell.ion.PotassiumFixed(size, E=-90. * u.mV)
32
+ self.k.add(IKL=braincell.channel.K_Leak(size, g_max=0.01 * (u.mS / u.cm ** 2)))
33
+ self.k.add(
34
+ IDR=braincell.channel.KDR_Ba2002(
35
+ size,
36
+ V_sh=-30. * u.mV,
37
+ q10=2.0,
38
+ temp=u.celsius2kelvin(16.),
39
+ )
40
+ )
41
+
42
+ self.ca = braincell.ion.CalciumDetailed(
43
+ size,
44
+ C_rest=5e-5 * u.mM,
45
+ tau=10. * u.ms,
46
+ d=0.5 * u.um,
47
+ )
48
+ self.ca.add(ICaL=braincell.channel.CaL_IS2008(size, g_max=0.5 * (u.mS / u.cm ** 2)))
49
+ self.ca.add(ICaN=braincell.channel.CaN_IS2008(size, g_max=0.5 * (u.mS / u.cm ** 2)))
50
+ self.ca.add(ICaT=braincell.channel.CaT_HM1992(size, g_max=2.1 * (u.mS / u.cm ** 2)))
51
+ self.ca.add(ICaHT=braincell.channel.CaHT_HM1992(size, g_max=3.0 * (u.mS / u.cm ** 2)))
52
+
53
+ self.kca = braincell.MixIons(self.k, self.ca)
54
+ self.kca.add(IAHP=braincell.channel.AHP_De1994(size, g_max=0.3 * (u.mS / u.cm ** 2)))
55
+
56
+ self.IL = braincell.channel.IL(
57
+ size,
58
+ E=-70. * u.mV,
59
+ g_max=0.0075 * (u.mS / u.cm ** 2),
60
+ )
61
+ ```
62
+
63
+ ## Rebound Input Variant
64
+
65
+ For post-inhibitory rebound, add or retain a low-threshold T-type calcium current such as `CaT_HM1992` and drive a time-dependent hyperpolarizing input.
66
+
67
+ ```python
68
+ def I_of_t(t):
69
+ return u.math.where(
70
+ t < 200. * u.ms,
71
+ -2. * u.uA / u.cm ** 2,
72
+ 0. * u.uA / u.cm ** 2,
73
+ )
74
+ ```
75
+
76
+ ## Checks
77
+
78
+ - Add AHP/KCa channels to the `MixIons` owner, not directly to `self.k` or `self.ca`.
79
+ - Use dynamic calcium such as `CalciumDetailed` when intracellular calcium should feed back into adaptation.
80
+ - Preserve a potassium ion container even when the adaptation current is calcium-dependent; the K reversal potential still matters.
81
+ - Inspect `channel.root_type` before changing ion order.
@@ -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)