brainx-skill 1.0.8 → 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.
- package/README.md +1 -6
- package/manifest.json +3 -2
- package/package.json +2 -1
- package/skills/braincell/SKILL.md +1 -1
- package/skills/braincell/references/braincell-custom-ion-channel-authoring.md +107 -44
- package/skills/braincell/references/channel-library.md +0 -85
- package/skills/braincell/references/ion-library.md +0 -67
- package/skills/braincell/references/multicompartment/filter-function-library.md +0 -8
- package/skills/braincell/references/multicompartment/topology-building-and-visualization.md +204 -65
- package/skills/brainmass/SKILL.md +290 -0
- package/skills/brainmass/references/batch-transform-acceleration.md +136 -0
- package/skills/brainmass/references/brainstate/parameter-constraints-regularization.md +214 -0
- package/skills/brainmass/references/brainstate/parameter-transforms-regularizers-catalog.md +171 -0
- package/skills/brainmass/references/braintools/cogtask.md +190 -0
- package/skills/brainmass/references/braintools/data-preprocessing.md +83 -0
- package/skills/brainmass/references/braintools/metric.md +157 -0
- package/skills/brainmass/references/braintools/optimizer.md +187 -0
- package/skills/brainmass/references/braintools/parameter-initializer.md +187 -0
- package/skills/brainmass/references/braintools/surrogate.md +151 -0
- package/skills/brainmass/references/coupling-network-api.md +148 -0
- package/skills/brainmass/references/datasets-api.md +72 -0
- package/skills/brainmass/references/fitting-with-objectives-api.md +146 -0
- package/skills/brainmass/references/forward-observation-api.md +131 -0
- package/skills/brainmass/references/horn-task-training.md +199 -0
- package/skills/brainmass/references/modellibrary.md +104 -0
- package/skills/brainmass/references/noiseprocesses.md +121 -0
- package/skills/brainmass/references/parameter-sweeps-and-regime-analysis.md +130 -0
- package/skills/brainmass/references/scripts/eeg-fitting-with-gradients.py +230 -0
- package/skills/brainmass/references/scripts/gradient-free-fitting.py +106 -0
- package/skills/brainmass/references/scripts/hopf-bifurcation-single-node.py +78 -0
- package/skills/brainmass/references/scripts/horn-cognitive-task-training.py +211 -0
- package/skills/brainmass/references/scripts/jansen-rit-eeg-proxy.py +76 -0
- package/skills/brainmass/references/scripts/kuramoto-synchronization.py +81 -0
- package/skills/brainmass/references/scripts/linear-baseline-node.py +81 -0
- package/skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +249 -0
- package/skills/brainmass/references/scripts/seizure-epileptor-case-study.py +126 -0
- package/skills/brainmass/references/scripts/wilson-cowan-ei-dynamics.py +86 -0
- package/skills/brainmass/references/scripts/wong-wang-decision-making.py +167 -0
- package/skills/brainmass/references/scripts/wong-wang-dmf-resting-state.py +72 -0
- package/skills/brainmass/references/visualization-analysis-api.md +130 -0
- package/skills/brainpy-state/SKILL.md +1 -1
- package/skills/brainx-general-guard/SKILL.md +43 -128
- package/skills/brainx-general-guard/references/brainstate-randomness-reproducibility/advanced-randomness.md +0 -303
- package/skills/brainx-general-guard/references/brainstate-randomness-reproducibility/randomness-and-reproducibility.md +0 -62
package/README.md
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
# BrainX Skill
|
|
2
2
|
|
|
3
|
-
[](skills/brainx-install/references/compatibility-and-release-matching.md#version-compatibility-matrix)
|
|
4
|
-
[](LICENSE)
|
|
5
|
-
[](https://www.npmjs.com/package/brainx-skill)
|
|
6
|
-
[](manifest.json)
|
|
7
|
-
[](https://github.com/chaobrain/BrainX-skill/actions/workflows/agent-skills-validation.yml)
|
|
8
|
-
[](https://scorecard.dev/viewer/?uri=github.com/chaobrain/BrainX-skill)
|
|
3
|
+
[](skills/brainx-install/references/compatibility-and-release-matching.md#version-compatibility-matrix) [](LICENSE) [](https://www.npmjs.com/package/brainx-skill) [](manifest.json) [](https://github.com/chaobrain/BrainX-skill/actions/workflows/agent-skills-validation.yml) [](https://scorecard.dev/viewer/?uri=github.com/chaobrain/BrainX-skill)
|
|
9
4
|
|
|
10
5
|
[](#installation-locations)
|
|
11
6
|
|
package/manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brainx-skill",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Portable BrainX Agent Skills for Claude Code, Codex, Cursor, Windsurf, Gemini CLI, and OpenCode",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"adapters/",
|
|
16
16
|
"installation/",
|
|
17
17
|
"skills/braincell/",
|
|
18
|
+
"skills/brainmass/",
|
|
18
19
|
"skills/brainx-install/",
|
|
19
20
|
"skills/brainunit/",
|
|
20
21
|
"skills/brainstate/",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: braincell
|
|
3
|
-
description:
|
|
3
|
+
description: Use for cell modeling with conductance-based or Hodgkin-Huxley ions, channels, compartments, or morphology. Use alone for cell studies or together with BrainPy-State and/or BrainMass when cellular mechanisms participate in a multiscale model.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# BrainCell
|
|
@@ -12,19 +12,16 @@ Keep custom dynamics inside BrainCell's lifecycle:
|
|
|
12
12
|
|
|
13
13
|
Do not replace this lifecycle with detached ODE functions or raw JAX arrays.
|
|
14
14
|
|
|
15
|
-
## Choose the extension level
|
|
15
|
+
## Choose the channel extension level
|
|
16
16
|
|
|
17
|
-
|
|
|
18
|
-
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
| Fixed concentrations with Nernst initialization | `braincell.ion._base.InitNernstIon` | Define fixed concentrations, valence, and temperature behavior; let initialization/reset compute `E`. |
|
|
24
|
-
| Dynamic intracellular concentration | `braincell.ion._base.DynamicNernstIon` | Define `derivative(Ci, V, total_current=...)`, whether total owned current is required, and the concentration initialization rule. |
|
|
25
|
-
| Multicompartment string declaration | `register_channel` or `register_ion` | Register a unique name at import time before `mech.Channel(...)` or `mech.Ion(...)` resolves it. |
|
|
17
|
+
| Use | Need |
|
|
18
|
+
|---|---|
|
|
19
|
+
| `braincell.channel._base.HH` | Use for independent Hodgkin-Huxley gates. Declare `Gate` objects, implement one recognized kinetic form per gate, and implement `current()`. |
|
|
20
|
+
| `braincell.channel._base.Markov` | Use for coupled probabilistic channel states. Declare transitions, one dependent state, a conservation total, transition-rate methods, and current from open-state probability. |
|
|
21
|
+
| `braincell.Channel` | Use for dynamics that HH and Markov templates cannot express. Implement State initialization/reset, derivatives, required lifecycle hooks, and current directly. |
|
|
22
|
+
| `register_channel` | Use when `mech.Channel(...)` must resolve the custom channel by name. Register a unique name when the defining module is imported. |
|
|
26
23
|
|
|
27
|
-
`braincell.channel._base`
|
|
24
|
+
`braincell.channel._base` is a lower-level authoring module. Inspect the installed version before relying on it across releases.
|
|
28
25
|
|
|
29
26
|
## Define the channel contract
|
|
30
27
|
|
|
@@ -138,30 +135,16 @@ Use `braincell.Channel` directly only when neither HH gates nor a conserved Mark
|
|
|
138
135
|
|
|
139
136
|
Do not implement all Markov probabilities as independent States when they must sum to one. Choose one dependent state and test conservation after stepping.
|
|
140
137
|
|
|
141
|
-
##
|
|
142
|
-
|
|
143
|
-
Registration makes a custom class available to multicompartment declarations by name.
|
|
138
|
+
## Choose the ion extension level
|
|
144
139
|
|
|
145
|
-
|
|
|
140
|
+
| Use | Need |
|
|
146
141
|
|---|---|
|
|
147
|
-
| `braincell.
|
|
148
|
-
| `braincell.
|
|
149
|
-
| `braincell.
|
|
150
|
-
| `
|
|
151
|
-
|
|
152
|
-
The `DemoKChannel` example registers `"DemoK"` and can therefore be declared after its module has been imported:
|
|
153
|
-
|
|
154
|
-
```python
|
|
155
|
-
import braincell.mech as mech
|
|
142
|
+
| `braincell.ion._base.FixedIon` or a matching concrete ion base | Use for a custom ion with fixed `Ci`, `Co`, `E`, and `valence`. Preserve the ion/channel ownership contract. |
|
|
143
|
+
| `braincell.ion._base.InitNernstIon` | Use when concentrations stay fixed but initialization and reset must compute `E` from concentrations, valence, and temperature. |
|
|
144
|
+
| `braincell.ion._base.DynamicNernstIon` | Use when intracellular concentration is dynamic. Define its initializer, `derivative(Ci, V, total_current=...)`, and whether the total owned current is required. |
|
|
145
|
+
| `register_ion` | Use when `mech.Ion(...)` must resolve the custom ion by name. Register a unique name when the defining module is imported. |
|
|
156
146
|
|
|
157
|
-
|
|
158
|
-
demo_k = mech.Channel(
|
|
159
|
-
"DemoK",
|
|
160
|
-
g_max=0.1 * u.mS / u.cm**2,
|
|
161
|
-
)
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
Import registration modules before constructing a declaration. An unresolved string is a registry/import problem, not a reason to duplicate the mechanism under a built-in name.
|
|
147
|
+
`braincell.ion._base` is a lower-level authoring module. Inspect the installed version before relying on it across releases.
|
|
165
148
|
|
|
166
149
|
## Author a custom ion only when required
|
|
167
150
|
|
|
@@ -173,6 +156,97 @@ Use a custom ion when the missing behavior belongs to reversal potential or conc
|
|
|
173
156
|
4. Package ion state through the inherited `IonInfo` path; do not pass the ion object directly into channels.
|
|
174
157
|
5. Register the concrete class only when string-based `mech.Ion(...)` declarations need it.
|
|
175
158
|
|
|
159
|
+
This custom calcium pool uses the owned channel current for influx and a saturating removal pump:
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
import braincell
|
|
163
|
+
import braintools
|
|
164
|
+
import brainunit as u
|
|
165
|
+
import jax.numpy as jnp
|
|
166
|
+
from braincell.ion import Calcium
|
|
167
|
+
from braincell.ion._base import DynamicNernstIon
|
|
168
|
+
|
|
169
|
+
DEFAULT_TEMP = u.celsius2kelvin(36.0)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class DemoSaturatingCalcium(Calcium, DynamicNernstIon):
|
|
173
|
+
uses_total_current = True
|
|
174
|
+
|
|
175
|
+
def __init__(
|
|
176
|
+
self,
|
|
177
|
+
size,
|
|
178
|
+
temp=DEFAULT_TEMP,
|
|
179
|
+
depth=1.0 * u.um,
|
|
180
|
+
pump_max=1.0e-4 * u.mM / u.ms,
|
|
181
|
+
pump_half=1.0e-4 * u.mM,
|
|
182
|
+
Co=None,
|
|
183
|
+
Ci_initializer=2.4e-4 * u.mM,
|
|
184
|
+
):
|
|
185
|
+
super().__init__(size=size)
|
|
186
|
+
self._init_dynamic_nernst_ion(
|
|
187
|
+
Co=Co,
|
|
188
|
+
temp=temp,
|
|
189
|
+
valence=None,
|
|
190
|
+
Ci_initializer=Ci_initializer,
|
|
191
|
+
)
|
|
192
|
+
self.depth = braintools.init.param(
|
|
193
|
+
depth, self.varshape, allow_none=False
|
|
194
|
+
)
|
|
195
|
+
self.pump_max = braintools.init.param(
|
|
196
|
+
pump_max, self.varshape, allow_none=False
|
|
197
|
+
)
|
|
198
|
+
self.pump_half = braintools.init.param(
|
|
199
|
+
pump_half, self.varshape, allow_none=False
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
def derivative(self, Ci, V, total_current=None):
|
|
203
|
+
_ = V
|
|
204
|
+
influx = total_current / (
|
|
205
|
+
self.valence * u.faraday_constant * self.depth
|
|
206
|
+
)
|
|
207
|
+
influx = u.math.maximum(influx, u.math.zeros_like(influx))
|
|
208
|
+
pump = self.pump_max * Ci / (Ci + self.pump_half)
|
|
209
|
+
return influx - pump
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
V = jnp.array([-65.0]) * u.mV
|
|
213
|
+
initial_Ci = 2.4e-4 * u.mM
|
|
214
|
+
|
|
215
|
+
calcium = DemoSaturatingCalcium(size=1, Ci_initializer=initial_Ci)
|
|
216
|
+
calcium.add(
|
|
217
|
+
ICaT=braincell.channel.CaT_HM1992(
|
|
218
|
+
size=1,
|
|
219
|
+
g_max=2.0 * u.mS / u.cm**2,
|
|
220
|
+
)
|
|
221
|
+
)
|
|
222
|
+
calcium.init_state(V)
|
|
223
|
+
calcium.compute_derivative(V)
|
|
224
|
+
|
|
225
|
+
total_current = calcium.current(V, include_external=True)
|
|
226
|
+
expected = calcium.derivative(
|
|
227
|
+
calcium.Ci.value,
|
|
228
|
+
V,
|
|
229
|
+
total_current=total_current,
|
|
230
|
+
)
|
|
231
|
+
assert u.math.allclose(
|
|
232
|
+
calcium.Ci.derivative.to_decimal(u.mM / u.ms),
|
|
233
|
+
expected.to_decimal(u.mM / u.ms),
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
E_before = calcium.E
|
|
237
|
+
calcium.Ci.value = jnp.array([1.0e-3]) * u.mM
|
|
238
|
+
assert not u.math.allclose(
|
|
239
|
+
E_before.to_decimal(u.mV),
|
|
240
|
+
calcium.E.to_decimal(u.mV),
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
calcium.reset_state(V)
|
|
244
|
+
assert u.math.allclose(
|
|
245
|
+
calcium.Ci.value.to_decimal(u.mM),
|
|
246
|
+
initial_Ci.to_decimal(u.mM),
|
|
247
|
+
)
|
|
248
|
+
```
|
|
249
|
+
|
|
176
250
|
Use `CalciumFixed`, `CalciumInitNernst`, and `CalciumDetailed` as the three concrete source patterns. Do not author a custom ion merely to change a channel's `g_max`, gating kinetics, or current formula.
|
|
177
251
|
|
|
178
252
|
## Validate the extension
|
|
@@ -189,18 +263,7 @@ For an ohmic current written as `g * gates * (E - V)`, verify that current appro
|
|
|
189
263
|
|
|
190
264
|
Add a co-located test when the extension becomes repository code. Registration success alone does not validate kinetics.
|
|
191
265
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
- Authoring before checking the library: inspect built-in channel, ion, and template families first.
|
|
195
|
-
- Omitting or misordering `root_type`: declare the exact ion dependency and test wrong-owner rejection.
|
|
196
|
-
- Reaching into a parent ion object: consume the supplied `IonInfo`.
|
|
197
|
-
- Mixing kinetic forms for one HH gate: implement either `inf/tau` or `alpha/beta`.
|
|
198
|
-
- Returning unit-bearing HH time constants or rates when the template expects plain millisecond-based numbers: follow the installed template convention.
|
|
199
|
-
- Allocating Markov probabilities without conservation: define one dependent state and test the total.
|
|
200
|
-
- Returning raw floats from `current()`: preserve the cell's current or current-density units.
|
|
201
|
-
- Stripping units before the formula boundary: convert only the term that must enter a dimensionless empirical expression.
|
|
202
|
-
- Registering a class but never importing its module: ensure import-time registration occurs before string resolution.
|
|
203
|
-
- Validating only one trace at one `dt`: test formula invariants and numerical convergence separately.
|
|
266
|
+
|
|
204
267
|
|
|
205
268
|
## Sources
|
|
206
269
|
|
|
@@ -64,82 +64,6 @@ Attach calcium channels to a calcium ion. Use a dynamic calcium ion when accumul
|
|
|
64
64
|
|
|
65
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
66
|
|
|
67
|
-
## Attach built-in channels
|
|
68
|
-
|
|
69
|
-
`root_type` determines which object supplies a channel's ion information and where the channel may be attached.
|
|
70
|
-
|
|
71
|
-
| API | Description |
|
|
72
|
-
|---|---|
|
|
73
|
-
| `channel.root_type` | Inspect before attachment; it identifies a sodium, potassium, calcium, ordered multi-ion, or root-cell dependency. |
|
|
74
|
-
| `ion.add(name=channel)` | Use for a single-ion channel in a `SingleCompartment`; it validates the channel against the ion owner. |
|
|
75
|
-
| `mixed.add(name=channel)` | Use for a channel whose `root_type` is an ordered multi-ion dependency. |
|
|
76
|
-
| `braincell.mech.Channel(name_or_class, **parameters)` | Use inside `Cell.paint()` for a multicompartment density-channel declaration; string names resolve through the channel registry. |
|
|
77
|
-
|
|
78
|
-
```python
|
|
79
|
-
import braincell
|
|
80
|
-
import brainunit as u
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
class HH(braincell.SingleCompartment):
|
|
84
|
-
def __init__(self, size, solver="exp_euler"):
|
|
85
|
-
super().__init__(size, V_th=20.0 * u.mV, solver=solver)
|
|
86
|
-
|
|
87
|
-
self.na = braincell.ion.SodiumFixed(size, E=50.0 * u.mV)
|
|
88
|
-
self.na.add(INa=braincell.channel.Na_HH1952(size))
|
|
89
|
-
|
|
90
|
-
self.k = braincell.ion.PotassiumFixed(size, E=-77.0 * u.mV)
|
|
91
|
-
self.k.add(IK=braincell.channel.K_HH1952(size))
|
|
92
|
-
|
|
93
|
-
self.IL = braincell.channel.IL(
|
|
94
|
-
size,
|
|
95
|
-
E=-54.387 * u.mV,
|
|
96
|
-
g_max=0.03 * u.mS / u.cm**2,
|
|
97
|
-
)
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
This pattern keeps ion-specific channels under their matching ion and the root-cell leak on the cell. Adding `K_HH1952` to `SodiumFixed`, for example, raises a type error instead of silently using the wrong reversal potential.
|
|
101
|
-
|
|
102
|
-
Open `references/ion-library.md` when choosing fixed, Nernst-initialized, or dynamic ion behavior. Open `references/mixions-for-adaptation.md` when a mixed potassium-calcium channel participates in adaptation or rebound.
|
|
103
|
-
|
|
104
|
-
## Isolate a channel effect
|
|
105
|
-
|
|
106
|
-
Expose the target channel's parameter while holding the cell declaration, initial state, input, solver, `dt`, and recording path constant.
|
|
107
|
-
|
|
108
|
-
```python
|
|
109
|
-
class AblationHH(braincell.SingleCompartment):
|
|
110
|
-
def __init__(
|
|
111
|
-
self,
|
|
112
|
-
size,
|
|
113
|
-
gK=36.0 * u.mS / u.cm**2,
|
|
114
|
-
solver="exp_euler",
|
|
115
|
-
):
|
|
116
|
-
super().__init__(size, V_th=20.0 * u.mV, solver=solver)
|
|
117
|
-
|
|
118
|
-
self.na = braincell.ion.SodiumFixed(size, E=50.0 * u.mV)
|
|
119
|
-
self.na.add(INa=braincell.channel.Na_HH1952(size))
|
|
120
|
-
|
|
121
|
-
self.k = braincell.ion.PotassiumFixed(size, E=-77.0 * u.mV)
|
|
122
|
-
self.k.add(
|
|
123
|
-
IK=braincell.channel.K_HH1952(size, g_max=gK)
|
|
124
|
-
)
|
|
125
|
-
|
|
126
|
-
self.IL = braincell.channel.IL(
|
|
127
|
-
size,
|
|
128
|
-
E=-54.387 * u.mV,
|
|
129
|
-
g_max=0.03 * u.mS / u.cm**2,
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
intact = AblationHH(size=1)
|
|
134
|
-
ablated = AblationHH(
|
|
135
|
-
size=1,
|
|
136
|
-
gK=0.0 * u.mS / u.cm**2,
|
|
137
|
-
)
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
The official potassium-ablation example uses `gK = 0` to remove delayed-rectifier current while preserving the rest of the model. Initialize both cells identically and drive them with the same current before attributing a trace difference to the ablated channel.
|
|
141
|
-
|
|
142
|
-
Do not interpret a waveform difference as a channel effect until it persists under an appropriate time-step refinement. Open `references/solver-library-with-effects.md` when the result may be solver-dependent.
|
|
143
67
|
|
|
144
68
|
## Route custom authoring
|
|
145
69
|
|
|
@@ -151,15 +75,6 @@ Open `references/braincell-custom-ion-channel-authoring.md` only when:
|
|
|
151
75
|
|
|
152
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.
|
|
153
77
|
|
|
154
|
-
## Common failures
|
|
155
|
-
|
|
156
|
-
- Writing a custom channel first: search `braincell.channel` and the source-model templates before authoring.
|
|
157
|
-
- Attaching a channel to the wrong owner: inspect `root_type`; use the matching ion, ordered `MixIons`, or root cell.
|
|
158
|
-
- Treating `IL` and `K_Leak` as interchangeable: `IL` is a root-cell leak with its own `E`; `K_Leak` is potassium-specific.
|
|
159
|
-
- Comparing source models by `g_max` alone: preserve their gating, temperature, shift, and reversal-potential conventions.
|
|
160
|
-
- Using a fixed calcium ion in a calcium-feedback experiment: select dynamic calcium before adding the dependent current.
|
|
161
|
-
- Removing a channel while changing input or numerics: hold all non-ablated conditions constant.
|
|
162
|
-
- Passing a bare maximal conductance: use the density or total-conductance unit expected by the surrounding cell convention.
|
|
163
78
|
|
|
164
79
|
## Sources
|
|
165
80
|
|
|
@@ -27,32 +27,6 @@ Channels carry current; ions organize the shared electrochemical state that driv
|
|
|
27
27
|
|
|
28
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
29
|
|
|
30
|
-
## Attach fixed ions and channels
|
|
31
|
-
|
|
32
|
-
Construct the ion first, then add only channels whose `root_type` matches that ion.
|
|
33
|
-
|
|
34
|
-
| API | Description |
|
|
35
|
-
|---|---|
|
|
36
|
-
| `ion.add(name=channel)` | Use after constructing a single-compartment ion; it registers the channel under that ion and raises a type error when the channel's `root_type` does not match. |
|
|
37
|
-
| `ion.pack_info()` | Use when testing a channel directly; it returns the ion's `IonInfo(Ci, Co, E, valence)`. |
|
|
38
|
-
| `channel.root_type` | Inspect before attachment when the required ion owner is uncertain. |
|
|
39
|
-
|
|
40
|
-
```python
|
|
41
|
-
import braincell
|
|
42
|
-
import brainunit as u
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
na = braincell.ion.SodiumFixed(size=1, E=50.0 * u.mV)
|
|
46
|
-
na.add(INa=braincell.channel.Na_HH1952(size=1))
|
|
47
|
-
|
|
48
|
-
k = braincell.ion.PotassiumFixed(size=1, E=-77.0 * u.mV)
|
|
49
|
-
k.add(IK=braincell.channel.K_HH1952(size=1))
|
|
50
|
-
|
|
51
|
-
assert braincell.channel.Na_HH1952.root_type is braincell.ion.Sodium
|
|
52
|
-
assert braincell.channel.K_HH1952.root_type is braincell.ion.Potassium
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Attach root-cell channels such as `IL` directly to the cell. They do not belong under a sodium, potassium, or calcium ion.
|
|
56
30
|
|
|
57
31
|
## Use dynamic calcium
|
|
58
32
|
|
|
@@ -105,47 +79,6 @@ kca.add(
|
|
|
105
79
|
|
|
106
80
|
For `AHP_De1994`, the required order is potassium followed by calcium. Match `root_type` exactly; `(ca, k)` is not interchangeable with `(k, ca)`.
|
|
107
81
|
|
|
108
|
-
## Declare ions on a multicompartment cell
|
|
109
|
-
|
|
110
|
-
`braincell.mech.Ion` and `braincell.mech.Channel` are declarations; `Cell.init_state()` lowers them into runtime ion and channel objects over the selected control volumes.
|
|
111
|
-
|
|
112
|
-
```python
|
|
113
|
-
import braincell.mech as mech
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
cell.paint(
|
|
117
|
-
region,
|
|
118
|
-
mech.Ion(
|
|
119
|
-
"CalciumDetailed",
|
|
120
|
-
name="ca_dyn",
|
|
121
|
-
d=0.5 * u.um,
|
|
122
|
-
tau=10.0 * u.ms,
|
|
123
|
-
C_rest=5.0e-5 * u.mM,
|
|
124
|
-
Ci_initializer=2.4e-4 * u.mM,
|
|
125
|
-
),
|
|
126
|
-
)
|
|
127
|
-
cell.paint(
|
|
128
|
-
region,
|
|
129
|
-
mech.Channel(
|
|
130
|
-
"CaT_HM1992",
|
|
131
|
-
ion_name="ca_dyn",
|
|
132
|
-
g_max=2.0 * u.mS / u.cm**2,
|
|
133
|
-
),
|
|
134
|
-
)
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
Use an explicit ion `name` when a channel must bind to a particular runtime ion owner. Open `references/multicompartment/multicompartment-cell-workflow.md` before applying this fragment to a `Cell`; that workflow owns morphology, regions, CV policies, initialization, and runtime inspection.
|
|
138
|
-
|
|
139
|
-
## Common failures
|
|
140
|
-
|
|
141
|
-
- Adding a channel to the wrong ion: inspect `root_type`, then attach it to the matching ion or ordered `MixIons`.
|
|
142
|
-
- Treating an ion as the current-producing mechanism: attach channels; the ion aggregates their current and owns shared electrochemical information.
|
|
143
|
-
- Using fixed calcium when the result depends on calcium accumulation: use `CalciumDetailed`, `CalciumFirstOrder`, or a matching documented template.
|
|
144
|
-
- Expecting `InitNernstIon` concentration to evolve: choose a dynamic ion when `Ci` must be integrated.
|
|
145
|
-
- Passing bare concentrations, voltages, time constants, temperature, or shell depth: use BrainUnit quantities.
|
|
146
|
-
- Authoring a new ion before checking `braincell.ion`: inspect the installed API and literature-derived templates first.
|
|
147
|
-
|
|
148
|
-
Open `references/braincell-custom-ion-channel-authoring.md` only when the required ion species or concentration dynamics remain unavailable after that inspection.
|
|
149
82
|
|
|
150
83
|
## Sources
|
|
151
84
|
|
|
@@ -146,14 +146,6 @@ The current filter API exports additional names, but the official filter tutoria
|
|
|
146
146
|
|
|
147
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
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
149
|
|
|
158
150
|
## Sources
|
|
159
151
|
|