# Grouping a large number of SpatialNeuron - Ressource

**URL:** <https://brian.discourse.group/t/grouping-a-large-number-of-spatialneuron-ressource/928>\
**Category:** Support\
**Tags:** performance, multicompartment\
**Created:** [3 March 2023 16:58 UTC](https://brian.discourse.group/t/grouping-a-large-number-of-spatialneuron-ressource/928 "2023-03-03T16:58:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AGuyNextDoor](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/aguynextdoor/32/582_2.png) [@AGuyNextDoor](https://brian.discourse.group/u/AGuyNextDoor)\
**Post date:** [3 March 2023 16:58 UTC](https://brian.discourse.group/t/grouping-a-large-number-of-spatialneuron-ressource/928/1 "2023-03-03T16:58:58Z")

</div>

# Description of problem

I’m trying to find a way to group and connect a large number (~1,500) of 2 compartments `SpatialNeuron`s (1 Soma and 1 Dendrite). I’m pretty new but I’ve been going through the documentation trying to find a way to make this work.

The idea would be to find a way to independently have Somas and Dendrites (with specific morphologies) and be able to connect them (Somas ↔ Somas, Somas ↔ Dendrites, and Dendrites ↔ Dendrites)

My questions :

- Is there a built-in Method or Class allowing for this behavior?
- Is it done " by hand", connecting via the `Synapse` class the `spatialNeuron` with a condition or a loop?

Thank you very much.

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [3 March 2023 17:32 UTC](https://brian.discourse.group/t/grouping-a-large-number-of-spatialneuron-ressource/928/2 "2023-03-03T17:32:45Z")

</div>

Hi @AGuyNextDoor. If each of your neurons is modelled as two compartments, I’d strongly advise against using `SpatialNeuron` in the first place. The reason is that `SpatialNeuron` treats each neuron as an independent unit, and having 1500 of them would among other things mean to compile 1500 C++ files representing the computations updating the neurons. Also, you’d need to have one `Synapses` object for each pair of neurons, adding to the complexity. In sum, this would be very inefficient, and – if using a C+±based code generation target – _very_ slow to compile.

If you only need two compartments, a much more efficient approach would be to directly represent these compartments in the equations, i.e. instead of having one `dv/dt = ...` equation, use `dv_soma/dt = ...` and `dv_dend/dt = ...` with a current proportional to `(v_soma - v_dend)` between the two variables. In particular, if you want to model a passive dendrite, this is quite straightforward to do. Instead of creating the equations by hand, you can also use the [dendrify package](https://dendrify.readthedocs.io/en/latest/index.html), which does the same thing under the hood (with additional options for efficient models of active dendrites).

If you follow that approach, you will only need a single `NeuronGroup` for all your neurons, and connecting them with synapses will therefore also be possible using the standard methods.

Does that help, or did I misunderstand what you want to do?

---

<div class="post-metadata">

**Author:** ![AGuyNextDoor](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/aguynextdoor/32/582_2.png) [@AGuyNextDoor](https://brian.discourse.group/u/AGuyNextDoor)\
**Post date:** [3 March 2023 17:53 UTC](https://brian.discourse.group/t/grouping-a-large-number-of-spatialneuron-ressource/928/3 "2023-03-03T17:53:23Z")

</div>

Thanks for the fast and qualitative reply!

It helps a lot! I now know my modelization direction, I really didn’t want to go in a direction and discovering a more suited Class after that …!

If I understand correctly, the SpatialNeuron class really aims at modeling more specific behaviors of a few number of neurons

I’ll check on the `dendrify package` thanks a lot !

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [6 March 2023 10:10 UTC](https://brian.discourse.group/t/grouping-a-large-number-of-spatialneuron-ressource/928/4 "2023-03-06T10:10:11Z")

</div>

> [@AGuyNextDoor](#):
>
> If I understand correctly, the SpatialNeuron class really aims at modeling more specific behaviors of a few number of neurons

Yes, indeed, the main use case at the moment is to use it either for models with a dendritic tree and something like hundreds of compartments (e.g. to study integration of synaptic input on various positions of the dendritic tree), or in simplified models but still with many compartments, e.g. to study the propagation of action potentials in an axon.

In the long run, we are planning to implement a `SpatialNeuronGroup` that would cover your use case as well, but we aren’t there yet…
