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/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright
|
|
189
|
+
Copyright 2026 BrainX Team
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -1,29 +1,39 @@
|
|
|
1
|
-
# BrainX
|
|
1
|
+
# BrainX Skill
|
|
2
2
|
|
|
3
|
-
|
|
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)
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
[](#installation-locations)
|
|
11
|
+
|
|
12
|
+
make your coding agent understand the power of BrainX
|
|
6
13
|
|
|
7
14
|
## Requirements
|
|
8
15
|
|
|
9
16
|
- Node.js 18 or newer
|
|
10
17
|
- macOS, Linux, or Windows
|
|
11
|
-
- Write access to your user-level skill directories
|
|
12
|
-
|
|
13
|
-
The installer does not require harness executables to be on `PATH`.
|
|
14
|
-
|
|
15
18
|
## Install
|
|
16
19
|
|
|
17
20
|
```bash
|
|
18
21
|
npx brainx-skill install
|
|
19
22
|
```
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
```bash
|
|
25
|
+
# Claude Code, current project
|
|
26
|
+
npx skills add chaobrain/BrainX-skill --agent claude-code
|
|
27
|
+
|
|
28
|
+
# Codex, current project
|
|
29
|
+
npx skills add chaobrain/BrainX-skill --agent codex
|
|
22
30
|
|
|
23
|
-
|
|
31
|
+
# Claude Code, globally
|
|
32
|
+
npx skills add chaobrain/BrainX-skill --agent claude-code --global
|
|
24
33
|
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
# Specific project
|
|
35
|
+
cd /actual/path/to/project
|
|
36
|
+
npx skills add chaobrain/BrainX-skill --agent codex
|
|
27
37
|
```
|
|
28
38
|
|
|
29
39
|
## Update
|
|
@@ -32,22 +42,15 @@ npx brainx-skill@latest install
|
|
|
32
42
|
npx brainx-skill update
|
|
33
43
|
```
|
|
34
44
|
|
|
35
|
-
To force npm to resolve the latest published release:
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
npx brainx-skill@latest update
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
Update uses the harness destinations recorded by the previous installation and does not prompt again. It replaces only skill directories proven to be owned by `brainx-skill`. If no managed installation exists, it leaves all destinations unchanged.
|
|
42
45
|
|
|
43
|
-
##
|
|
46
|
+
## When the internet connection is low
|
|
44
47
|
|
|
45
48
|
```bash
|
|
49
|
+
# install
|
|
46
50
|
npx --registry=https://registry.npmmirror.com brainx-skill install
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
npx --registry=https://registry.npmmirror.com brainx-skill@latest install
|
|
51
|
+
|
|
52
|
+
# update
|
|
53
|
+
npx --registry=https://registry.npmmirror.com brainx-skill update
|
|
51
54
|
```
|
|
52
55
|
|
|
53
56
|
## Installation locations
|
|
@@ -58,47 +61,9 @@ Depending on the selected scope, the canonical `brainx-install` skill is install
|
|
|
58
61
|
Claude Code: ~/.claude/skills/<skill-name> or <cwd>/.claude/skills/<skill-name>
|
|
59
62
|
Codex: ~/.agents/skills/<skill-name> or <cwd>/.agents/skills/<skill-name>
|
|
60
63
|
Cursor: ~/.cursor/skills/<skill-name> or <cwd>/.cursor/skills/<skill-name>
|
|
64
|
+
Windsurf: ~/.codeium/windsurf/skills/<skill-name> or <cwd>/.codeium/windsurf/skills/<skill-name>
|
|
65
|
+
Gemini CLI: ~/.gemini/skills/<skill-name> or <cwd>/.gemini/skills/<skill-name>
|
|
66
|
+
OpenCode: ~/.config/opencode/skills/<skill-name> or <cwd>/.config/opencode/skills/<skill-name>
|
|
61
67
|
```
|
|
62
68
|
|
|
63
69
|
Installation ownership is recorded in `~/.brainx/receipt.json`.
|
|
64
|
-
|
|
65
|
-
## Managed-files warning
|
|
66
|
-
|
|
67
|
-
Installed BrainX skill directories are package-managed and may be replaced during install or update. Do not edit installed copies. Edit the canonical skill in the source repository and publish a new package release instead.
|
|
68
|
-
|
|
69
|
-
Directories that are not proven to be BrainX-managed are never overwritten or deleted.
|
|
70
|
-
|
|
71
|
-
## Troubleshooting
|
|
72
|
-
|
|
73
|
-
- Conflict errors identify an existing unowned directory. Move or remove that directory, then retry.
|
|
74
|
-
- Permission errors identify the affected agent and path. Restore write access to that user-level directory, then retry.
|
|
75
|
-
- An invalid receipt blocks destructive changes. Inspect `~/.brainx/receipt.json` and restore a valid receipt before retrying.
|
|
76
|
-
- A partial failure can leave one agent updated and the other unchanged. Resolve the reported destination and run the same command again.
|
|
77
|
-
|
|
78
|
-
## Development and publishing notes
|
|
79
|
-
|
|
80
|
-
Run the tests and inspect the package contents without publishing:
|
|
81
|
-
|
|
82
|
-
```bash
|
|
83
|
-
npm test
|
|
84
|
-
npm pack --dry-run
|
|
85
|
-
npm pack
|
|
86
|
-
test_home="$(mktemp -d '/tmp/brainx skills.XXXXXX')"
|
|
87
|
-
HOME="$test_home" npx --yes --package ./brainx-skill-1.0.3.tgz brainx install
|
|
88
|
-
HOME="$test_home" npx --yes --package ./brainx-skill-1.0.3.tgz brainx update
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
To preview the interaction directly from this checkout:
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
npx --yes --package . brainx install
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Recheck that the npm name is available, authenticate, and publish with:
|
|
98
|
-
|
|
99
|
-
```bash
|
|
100
|
-
npm view brainx-skill
|
|
101
|
-
npm publish --access public
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
Do not run the publication command until the package contents and release version have been reviewed.
|
|
@@ -3,16 +3,19 @@
|
|
|
3
3
|
const os = require('node:os');
|
|
4
4
|
const fs = require('node:fs/promises');
|
|
5
5
|
const path = require('node:path');
|
|
6
|
-
const codex = require('
|
|
7
|
-
const claude = require('
|
|
8
|
-
const cursor = require('
|
|
6
|
+
const codex = require('../../adapters/codex');
|
|
7
|
+
const claude = require('../../adapters/claude');
|
|
8
|
+
const cursor = require('../../adapters/cursor');
|
|
9
|
+
const windsurf = require('../../adapters/windsurf');
|
|
10
|
+
const gemini = require('../../adapters/gemini');
|
|
11
|
+
const opencode = require('../../adapters/opencode');
|
|
9
12
|
const { prepareAdapter, AdapterOperationError } = require('./adapter-transaction');
|
|
10
13
|
const { validateBundle } = require('./bundle');
|
|
11
14
|
const { PACKAGE_NAME, RECEIPT_SCHEMA_VERSION } = require('./constants');
|
|
12
15
|
const { resolveDestinationRoot, resolveLocations } = require('./paths');
|
|
13
16
|
const { readReceipt, writeReceiptAtomic } = require('./receipt');
|
|
14
17
|
|
|
15
|
-
const DEFAULT_ADAPTERS = [claude, codex, cursor];
|
|
18
|
+
const DEFAULT_ADAPTERS = [claude, codex, cursor, windsurf, gemini, opencode];
|
|
16
19
|
|
|
17
20
|
function writeLine(stream, text = '') {
|
|
18
21
|
stream.write(`${text}\n`);
|
|
@@ -51,7 +54,7 @@ async function runInstaller(command, options = {}) {
|
|
|
51
54
|
const availableAdapters = options.adapters || DEFAULT_ADAPTERS;
|
|
52
55
|
const stdout = options.stdout || process.stdout;
|
|
53
56
|
const stderr = options.stderr || process.stderr;
|
|
54
|
-
const packageRoot = options.packageRoot || path.resolve(__dirname, '
|
|
57
|
+
const packageRoot = options.packageRoot || path.resolve(__dirname, '../..');
|
|
55
58
|
const homeDir = options.homeDir || os.homedir();
|
|
56
59
|
const cwd = options.cwd || process.cwd();
|
|
57
60
|
const now = options.now || (() => new Date().toISOString());
|
package/manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brainx-skill",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Portable BrainX Agent Skills for Claude Code, Codex, and
|
|
3
|
+
"version": "1.0.8",
|
|
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",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "node --test .github/scripts/*.test.mjs",
|
|
9
|
+
"prepublishOnly": "npm test"
|
|
10
|
+
},
|
|
7
11
|
"bin": {
|
|
8
|
-
"brainx": "bin/brainx.js"
|
|
12
|
+
"brainx": "installation/bin/brainx.js"
|
|
9
13
|
},
|
|
10
14
|
"files": [
|
|
11
15
|
"adapters/",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
16
|
+
"installation/",
|
|
17
|
+
"skills/braincell/",
|
|
14
18
|
"skills/brainx-install/",
|
|
19
|
+
"skills/brainunit/",
|
|
20
|
+
"skills/brainstate/",
|
|
21
|
+
"skills/brainevent/",
|
|
22
|
+
"skills/brainpy-state/",
|
|
23
|
+
"skills/brainx-general-guard/",
|
|
15
24
|
"manifest.json",
|
|
16
25
|
"README.md",
|
|
17
26
|
"LICENSE"
|
|
@@ -22,17 +31,23 @@
|
|
|
22
31
|
"dependencies": {
|
|
23
32
|
"enquirer": "^2.4.1"
|
|
24
33
|
},
|
|
25
|
-
"scripts": {
|
|
26
|
-
"test": "node --test test/bundle.test.js test/cli.test.js test/installer.test.js test/paths.test.js test/prompts.test.js",
|
|
27
|
-
"prepublishOnly": "npm test"
|
|
28
|
-
},
|
|
29
34
|
"repository": {
|
|
30
35
|
"type": "git",
|
|
31
|
-
"url": "git+https://github.com/
|
|
36
|
+
"url": "git+https://github.com/chaobrain/BrainX-skill.git"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/chaobrain/BrainX-skill#readme",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/chaobrain/BrainX-skill/issues"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public",
|
|
44
|
+
"provenance": true
|
|
32
45
|
},
|
|
33
46
|
"keywords": [
|
|
34
47
|
"agent-skills",
|
|
35
48
|
"brainx",
|
|
49
|
+
"brainunit",
|
|
50
|
+
"brainevent",
|
|
36
51
|
"claude-code",
|
|
37
52
|
"codex",
|
|
38
53
|
"cursor"
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: braincell
|
|
3
|
+
description: BrainCell provides conductance-based single-compartment and morphology-based multicompartment neuron models in BrainX. Use this skill for `SingleCompartment`, Hodgkin-Huxley ions and channels, `Cell`, `Morphology`, control volumes, `paint` and `place`, current clamps, probes, cellular solver choice, and single-cell simulations. Do not use it for wiring cells into networks, synaptic projections between cells, or network training; route those tasks to BrainPy-State.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# BrainCell
|
|
7
|
+
|
|
8
|
+
## Purpose and boundary
|
|
9
|
+
|
|
10
|
+
Use BrainCell for cellular biophysics at either of its two supported spatial scales:
|
|
11
|
+
|
|
12
|
+
- Use `SingleCompartment` when voltage is uniform across one isopotential cell and the task is channel prototyping, current injection, fitting, or a batch of independent point neurons.
|
|
13
|
+
- Use `Cell` when soma, dendrite, axon, branch geometry, spatial channel distribution, or location-specific stimulation and recording affect the result.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Keep network wiring, projections, and network training outside this skill. Open `skills/brainpy-state/SKILL.md` when multiple cells must communicate.
|
|
17
|
+
|
|
18
|
+
## Underlying principle of BrainCell
|
|
19
|
+
|
|
20
|
+
`HHTypedNeuron` represents conductance-based membrane dynamics. It supplies the shared ion, channel, state, and integration contract used by both cell front ends.
|
|
21
|
+
|
|
22
|
+
`SingleCompartment` represents one isopotential neuron. It collapses morphology and discretization and attaches ions and channels imperatively.
|
|
23
|
+
|
|
24
|
+
`Morphology` represents cable geometry and topology. `Cell` discretizes that geometry into isopotential control volumes whose axial coupling produces spatial voltage dynamics.
|
|
25
|
+
|
|
26
|
+
`braincell.mech` declarations represent what cellular mechanisms exist, while `braincell.filter` expressions represent where they apply. `paint()` distributes density mechanisms over cable regions; `place()` attaches point mechanisms at locations.
|
|
27
|
+
|
|
28
|
+
### API structure
|
|
29
|
+
|
|
30
|
+
| Module | Use |
|
|
31
|
+
|---|---|
|
|
32
|
+
| `braincell` | Use the public modeling surface for cells, morphology and branch types, control-volume policies, ion-channel bases, clamps, and run results. |
|
|
33
|
+
| `braincell.morph` | Represent, manipulate, and measure neuronal morphology structures before simulation. |
|
|
34
|
+
| `braincell.ion` | Choose sodium, potassium, and calcium ion models and their reversal-potential or concentration dynamics. |
|
|
35
|
+
| `braincell.channel` | Choose built-in membrane-channel dynamics for calcium, HCN, leak, potassium, potassium-calcium, and sodium currents. |
|
|
36
|
+
| `braincell.synapse` | Choose built-in AMPA, GABAa, and NMDA Markov synapse models. |
|
|
37
|
+
| `braincell.mech` | Declare what a multicompartment `Cell` installs: cable properties, density ions and channels, point mechanisms, and probes. |
|
|
38
|
+
| `braincell.filter` | Build regions for `paint()` and locsets for `place()`, including composed spatial selections. |
|
|
39
|
+
| `braincell.io` | Load, validate, checkpoint, and retrieve morphologies from supported file formats and NeuroMorpho.Org. |
|
|
40
|
+
| `braincell.quad` | Define differential-equation modules and choose, inspect, or register numerical integrators. |
|
|
41
|
+
| `braincell.vis` | Visualize morphologies, topology, control volumes, values, traces, and morphometric analyses in 2D or 3D. |
|
|
42
|
+
|
|
43
|
+
## Build and run a single-compartment cell
|
|
44
|
+
|
|
45
|
+
A `SingleCompartment` cell stores one membrane voltage per independent neuron and advances its attached ion and channel states from an external current supplied to `update()`.
|
|
46
|
+
|
|
47
|
+
| API | Description |
|
|
48
|
+
|---|---|
|
|
49
|
+
| `braincell.SingleCompartment(size, ..., solver=...)` | Use for a conductance-based point cell; `size` sets the independent population shape, `n_compartment` remains one, and `solver` selects a registered integrator. |
|
|
50
|
+
| `braincell.ion.*Fixed(size, E=...)` | Use when an ion's reversal potential is constant; it owns `E` and receives channels driven by that ion. |
|
|
51
|
+
| `ion.add(name=channel)` | Use after constructing an ion; it registers a channel under that ion so the channel reads the correct reversal potential. |
|
|
52
|
+
| `braincell.channel.*` | Use for membrane-current and gating dynamics; inspect `root_type` before attachment, and attach root-cell channels such as `IL` directly to the cell. |
|
|
53
|
+
| `cell.init_state()` / `cell.reset_state()` | Use before the first step or to reseed an existing cell; they initialize or reset voltage, spike, ion, and channel State without changing the model declaration. |
|
|
54
|
+
| `cell.update(I_ext)` | Use for one integration step; pass a current-density or total-current `Quantity`, let the cell area normalize total current, update all cellular State, and receive the spike output. |
|
|
55
|
+
| `brainstate.environ.context()` / `brainstate.transform.for_loop()` | Use to provide `dt` and `t` and to execute a transformed time loop that returns recorded State instead of mutating Python containers. |
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import braincell
|
|
59
|
+
import brainstate
|
|
60
|
+
import brainunit as u
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class HH(braincell.SingleCompartment):
|
|
64
|
+
def __init__(self, size, solver="exp_euler"):
|
|
65
|
+
super().__init__(size, V_th=20.0 * u.mV, solver=solver)
|
|
66
|
+
|
|
67
|
+
self.na = braincell.ion.SodiumFixed(size, E=50.0 * u.mV)
|
|
68
|
+
self.na.add(INa=braincell.channel.Na_HH1952(size))
|
|
69
|
+
|
|
70
|
+
self.k = braincell.ion.PotassiumFixed(size, E=-77.0 * u.mV)
|
|
71
|
+
self.k.add(IK=braincell.channel.K_HH1952(size))
|
|
72
|
+
|
|
73
|
+
self.IL = braincell.channel.IL(
|
|
74
|
+
size,
|
|
75
|
+
E=-54.387 * u.mV,
|
|
76
|
+
g_max=0.03 * u.mS / u.cm**2,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
cell = HH(1)
|
|
81
|
+
cell.init_state()
|
|
82
|
+
current = 5.0 * u.uA / u.cm**2
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def step(t):
|
|
86
|
+
with brainstate.environ.context(t=t):
|
|
87
|
+
spike = cell.update(current)
|
|
88
|
+
return cell.V.value, spike
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
with brainstate.environ.context(dt=0.01 * u.ms):
|
|
92
|
+
times = u.math.arange(
|
|
93
|
+
0.0 * u.ms,
|
|
94
|
+
100.0 * u.ms,
|
|
95
|
+
brainstate.environ.get_dt(),
|
|
96
|
+
)
|
|
97
|
+
voltages, spikes = brainstate.transform.for_loop(step, times)
|
|
98
|
+
|
|
99
|
+
assert voltages.shape[:1] == times.shape
|
|
100
|
+
assert spikes.shape[:1] == times.shape
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Treat `V_th` only as the spike-event threshold; it does not change the membrane equation. Keep membrane capacitance and channel conductance density-based in the canonical path. `update()` accepts current density or total current and uses `SingleCompartment.area` to normalize total input; do not manually area-scale only part of the model. Use `size=N` for `N` independent cells, never for `N` compartments.
|
|
104
|
+
|
|
105
|
+
Open `references/area-scaled-hh-pattern.md` when changing cell geometry or explicitly converting density parameters to total quantities. Open `references/ion-library.md`, `references/channel-library.md`, or `references/mixions-for-adaptation.md` only when the classical fixed-ion HH path is insufficient.
|
|
106
|
+
|
|
107
|
+
## Build and run a multicompartment cell
|
|
108
|
+
|
|
109
|
+
A `Cell` lowers morphology, spatial selectors, and declarative mechanisms into coupled control-volume State, then returns only the traces defined by placed probes.
|
|
110
|
+
|
|
111
|
+
| API | Description |
|
|
112
|
+
|---|---|
|
|
113
|
+
| `braincell.Morphology` | Use to load or construct branch geometry and topology before creating a cell; it describes continuous cable, not simulation compartments. |
|
|
114
|
+
| `braincell.Cell(morpho, cv_policy=..., solver=...)` | Use when spatial structure matters; it clones the morphology, applies a CV policy, and owns distinct declaration and initialized runtime phases. |
|
|
115
|
+
| `braincell.CVPolicy` | Use to control spatial resolution; it divides branches into isopotential control volumes, trading accuracy against State size and computation. |
|
|
116
|
+
| `cell.paint(region, *mechanisms)` | Use for cable properties and density mechanisms; it records declarations over a cable region and returns the cell for chaining. |
|
|
117
|
+
| `cell.place(locset, *mechanisms)` | Use for clamps, probes, and other point mechanisms; it records declarations at selected locations and returns the cell for chaining. |
|
|
118
|
+
| `cell.init_state()` | Use after all `paint()` and `place()` calls; it lowers declarations and allocates runtime State, and it raises if the cell is already initialized. |
|
|
119
|
+
| `cell.run(dt=..., duration=...)` | Use to advance the initialized cell and collect probe traces; it initializes on first use when needed and requires at least one placed probe. |
|
|
120
|
+
| `cell.reset_state()` / `cell.reset()` | Use `reset_state()` to reseed State while remaining initialized; use `reset()` to discard runtime State and return to the declaration phase before changing `paint()` or `place()` rules. |
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
import braincell
|
|
124
|
+
import braincell.mech as mech
|
|
125
|
+
import brainunit as u
|
|
126
|
+
from braincell.filter import AllRegion, RootLocation, at, branch_in
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
morphology = braincell.Morphology.from_swc("neuron.swc")
|
|
130
|
+
cell = braincell.Cell(
|
|
131
|
+
morphology,
|
|
132
|
+
cv_policy=braincell.CVPerBranch(cv_per_branch=2),
|
|
133
|
+
solver="staggered",
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
cell.paint(
|
|
137
|
+
AllRegion(),
|
|
138
|
+
mech.CableProperty(
|
|
139
|
+
resting_potential=-65.0 * u.mV,
|
|
140
|
+
membrane_capacitance=1.0 * u.uF / u.cm**2,
|
|
141
|
+
axial_resistivity=100.0 * u.ohm * u.cm,
|
|
142
|
+
),
|
|
143
|
+
mech.Channel("IL", g_max=0.03 * u.mS / u.cm**2, E=-54.387 * u.mV),
|
|
144
|
+
)
|
|
145
|
+
cell.paint(
|
|
146
|
+
branch_in("type", "soma"),
|
|
147
|
+
mech.Channel("Na_HH1952", g_max=120.0 * u.mS / u.cm**2),
|
|
148
|
+
mech.Channel("K_HH1952", g_max=36.0 * u.mS / u.cm**2),
|
|
149
|
+
)
|
|
150
|
+
cell.place(
|
|
151
|
+
RootLocation(x=0.5),
|
|
152
|
+
mech.CurrentClamp(
|
|
153
|
+
delay=20.0 * u.ms,
|
|
154
|
+
durations=60.0 * u.ms,
|
|
155
|
+
amplitudes=0.2 * u.nA,
|
|
156
|
+
),
|
|
157
|
+
)
|
|
158
|
+
cell.place(at("soma", 0.5), mech.StateProbe())
|
|
159
|
+
|
|
160
|
+
cell.init_state()
|
|
161
|
+
result = cell.run(dt=0.1 * u.ms, duration=100.0 * u.ms)
|
|
162
|
+
|
|
163
|
+
assert "soma(0.5)_v" in result.traces
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Use `paint()` only with regions and density mechanisms. Use `place()` only with locsets and point mechanisms. Declare all mechanisms before `init_state()`; call `reset()` before altering the declaration of an initialized cell.
|
|
167
|
+
|
|
168
|
+
Open `references/multicompartment/multicompartment-cell-workflow.md` for the complete advanced morphology-to-simulation path. Let that workflow select the exclusive morphology, filter, CV-policy, probe, or topology reference; do not open those leaves directly from this root skill.
|
|
169
|
+
|
|
170
|
+
## Reference routing
|
|
171
|
+
|
|
172
|
+
Open only the smallest reference that owns the non-canonical decision.
|
|
173
|
+
|
|
174
|
+
| Reference | Open when |
|
|
175
|
+
|---|---|
|
|
176
|
+
| `references/area-scaled-hh-pattern.md` | Changing single-compartment geometry or converting density parameters consistently to total capacitance and conductance. |
|
|
177
|
+
| `references/braincell-custom-ion-channel-authoring.md` | Implementing a custom ion or channel after confirming that no built-in mechanism fits. |
|
|
178
|
+
| `references/channel-library.md` | Selecting a built-in sodium, potassium, calcium, leak, HCN, or mixed-ion channel. |
|
|
179
|
+
| `references/ion-library.md` | Choosing fixed, Nernst-initialized, or dynamic ions and their concentration behavior. |
|
|
180
|
+
| `references/mixions-for-adaptation.md` | Adding calcium-dependent adaptation, AHP/KCa currents, rebound, dynamic calcium, or multi-ion channel dependencies. |
|
|
181
|
+
| `references/multicompartment/multicompartment-cell-workflow.md` | Extending the canonical `Morphology -> Cell -> paint/place -> run` path and selecting the exclusive multicompartment references. |
|
|
182
|
+
| `references/solver-library-with-effects.md` | Comparing registered integrators, stability, accuracy, and solver-dependent trace effects. |
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Area-Scaled HH Pattern
|
|
2
|
+
|
|
3
|
+
Use this reference when a single-compartment HH model provides cell area, total capacitance, or conductance densities that must be converted to total conductance and total capacitance.
|
|
4
|
+
|
|
5
|
+
## Rule
|
|
6
|
+
|
|
7
|
+
Keep `C`, `g_max`, and injected `I` all density-based by default. Only multiply by area when converting the entire model consistently to total capacitance, total conductance, and total current.
|
|
8
|
+
|
|
9
|
+
## Pattern
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
import braincell
|
|
13
|
+
import brainunit as u
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
area = (20000. * u.um ** 2).in_unit(u.cm ** 2)
|
|
17
|
+
Cm = (1. * u.uF / u.cm ** 2) * area
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class AreaHH(braincell.SingleCompartment):
|
|
21
|
+
def __init__(self, size, solver="ind_exp_euler"):
|
|
22
|
+
super().__init__(size, C=Cm, solver=solver)
|
|
23
|
+
|
|
24
|
+
self.na = braincell.ion.SodiumFixed(size, E=50. * u.mV)
|
|
25
|
+
self.na.add(
|
|
26
|
+
INa=braincell.channel.Na_TM1991(
|
|
27
|
+
size,
|
|
28
|
+
g_max=(100. * u.mS / u.cm ** 2) * area,
|
|
29
|
+
V_sh=-63. * u.mV,
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
self.k = braincell.ion.PotassiumFixed(size, E=-90. * u.mV)
|
|
34
|
+
self.k.add(
|
|
35
|
+
IK=braincell.channel.K_TM1991(
|
|
36
|
+
size,
|
|
37
|
+
g_max=(30. * u.mS / u.cm ** 2) * area,
|
|
38
|
+
V_sh=-63. * u.mV,
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
self.IL = braincell.channel.IL(
|
|
43
|
+
size,
|
|
44
|
+
E=-60. * u.mV,
|
|
45
|
+
g_max=(5. * u.nS / u.cm ** 2) * area,
|
|
46
|
+
)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Checks
|
|
50
|
+
|
|
51
|
+
- Density conductance times area should become conductance.
|
|
52
|
+
- Capacitance density times area should become capacitance.
|
|
53
|
+
- If conductances and capacitance are total quantities, injected current should also be a total current rather than a current density.
|
|
54
|
+
- If the model remains density-based, do not multiply only one channel by area.
|