Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgl committed Jan 29, 2025
2 parents ba03e95 + bbbe2ff commit a79c0d6
Show file tree
Hide file tree
Showing 41 changed files with 1,599 additions and 201 deletions.
30 changes: 14 additions & 16 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@ Dendrify
:alt: Contributor Covenant


Although neuronal dendrites play a crucial role in shaping how individual
neurons process synaptic information, their contribution to network-level
functions has remained largely unexplored. Current spiking neural networks
(SNNs) often oversimplify dendritic properties or overlook their essential
functions. On the other hand, circuit models with morphologically detailed
neuron representations are computationally intensive, making them impractical
for simulating large networks.

In an effort to bridge this gap, we present Dendrify—a freely available,
open-source Python package that seamlessly integrates with the
`Brian 2 simulator <https://brian2.readthedocs.io/en/stable/>`_. Dendrify,
through simple commands, automatically generates reduced compartmental neuron
models with simplified yet biologically relevant dendritic and synaptic
integrative properties. These models offer a well-rounded compromise between
flexibility, performance, and biological accuracy, enabling us to investigate
the impact of dendrites on network-level functions.
Neuronal dendrites play a crucial role in shaping how individual neurons process
synaptic information, yet their contributions to network-level functions remain
largely underexplored. While current spiking neural networks (SNNs) often
oversimplify or neglect essential dendritic properties, circuit models with
morphologically detailed neuron representations are computationally expensive,
limiting their practicality for large-scale network simulations.

To address these challenges, we introduce Dendrify, a free and open-source Python
package designed to work seamlessly with the
`Brian 2 simulator <https://brian2.readthedocs.io/en/stable/>`_. Dendrify enables
users to generate reduced compartmental neuron models with biologically relevant
dendritic and synaptic properties using simple commands. These models strike a
good balance between flexibility, performance, and accuracy, making it possible
to study the impact of dendrites on network-level functions.

.. image:: https://github.com/Poirazi-Lab/dendrify/assets/30598350/b6db9876-6de4-458a-b27e-61d4edd360db
:width: 70 %
Expand Down
2 changes: 1 addition & 1 deletion dendrify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
update_default_params)
from .equations import library
from .neuronmodel import NeuronModel, PointNeuronModel

from .playground import Playground
from .version import __version__
60 changes: 47 additions & 13 deletions dendrify/compartment.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(
self._connections = None
self._synapses = None
# Add membrane equations:
self._add_equations(model)
self._create_equations(model)
# Keep track of electrophysiological properties:
self._ephys_object = EphysProperties(
name=self.name,
Expand All @@ -130,7 +130,7 @@ def __str__(self):
f"USER PARAMETERS\n{15*'-'}\n{user}")
return txt

def _add_equations(self, model: str):
def _create_equations(self, model: str):
"""
Adds equations to a compartment.
Expand Down Expand Up @@ -386,6 +386,51 @@ def noise(self, tau: Quantity = 20*ms, sigma: Quantity = 1*pA,
self._params[f'tau_noise_{self.name}'] = tau
self._params[f'sigma_noise_{self.name}'] = sigma
self._params[f'mean_noise_{self.name}'] = mean

def add_equations(self, eqs: str):
"""
Adds custom equations to a compartment.
Parameters
----------
eqs : str
A string of Brian-compatible equations to be added to the compartment.
"""
if eqs in self._equations:
logger.warning("The equations you are trying to add already exist in the compartment.")
else:
self._equations += '\n' + eqs

def replace_equations(self, eqs_old: str, eqs_new: str):
"""
Replaces a set of equations with new ones.
Parameters
----------
eqs_old : str
The equations to be replaced.
eqs_new : str
The new equations.
"""
if eqs_old in self._equations:
self._equations = self._equations.replace(eqs_old, eqs_new)
else:
logger.warning(
"The equations to be replaced are not found in the compartment."
)

def add_params(self, params_dict: dict):
"""
Adds custom parameters to a compartment.
Parameters
----------
params_dict : dict
A dictionary of parameters to be added to the compartment.
"""
if not self._params:
self._params = {}
self._params.update(params_dict)

@property
def parameters(self) -> dict:
Expand Down Expand Up @@ -517,12 +562,6 @@ class Soma(Compartment):
and parameters needed to describe a somatic compartment and any currents
(synaptic, dendritic, noise) passing through it.
.. seealso::
Soma acts as a wrapper for Compartment with slight changes to account for
certain somatic properties. For a full list of its methods and attributes,
please see: :class:`.Compartment`.
Parameters
----------
name : str
Expand Down Expand Up @@ -604,11 +643,6 @@ class Dendrite(Compartment):
mechanisms, and any currents (synaptic, dendritic, ionic, noise) passing
through it.
.. seealso::
Dendrite inherits all the methods and attributes of its parent class
:class:`.Compartment`. For a complete list, please
refer to the documentation of the latter.
Parameters
----------
name : str
Expand Down
38 changes: 32 additions & 6 deletions dendrify/neuronmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,14 @@ def make_neurongroup(self,
for comp in self._compartments:
if show:
print(
f"Setting V_{comp.name} = {comp._ephys_object.v_rest}")
f"V_{comp.name} = {repr(comp._ephys_object.v_rest)}")
setattr(group, f'V_{comp.name}', comp._ephys_object.v_rest)

if init_events:
if self.event_actions:
for event, action in self.event_actions.items():
if show:
print(f"Setting run_on_event('{event}', '{action}')")
print(f"run_on_event('{event}', '{action}')")
group.run_on_event(event, action, order='before_groups')

ap_reset = None
Expand All @@ -406,7 +406,7 @@ def make_neurongroup(self,

def add_params(self, params_dict: dict):
"""
Allows specifying extra/custom parameters.
Adds extra/custom parameters to a NeuronModel.
Parameters
----------
Expand All @@ -429,7 +429,33 @@ def add_equations(self, eqs: str):
if not self._extra_equations:
self._extra_equations = f"{eqs}"
else:
self._extra_equations += f"\n{eqs}"
if eqs not in self._extra_equations:
self._extra_equations += f"\n{eqs}"
else:
logger.warning(
"The equations you are trying to add already exist in the model."
)

def replace_equations(self, eqs_old: str, eqs_new: str):
"""
Replaces existing equations with custom ones.
Parameters
----------
eqs_old : str
The existing equations to be replaced.
eqs_new : str
The custom equations.
"""
eqs_found = False
for comp in self._compartments:
if eqs_old in comp._equations:
comp._equations = comp._equations.replace(eqs_old, eqs_new)
eqs_found = True
if not eqs_found:
logger.warning(
"The equations to be replaced are not found in the model."
)

def as_graph(self, figsize: list = [6, 4], fontsize: int = 10, fontcolor: str = 'white',
scale_nodes: float = 1, color_soma: str = '#4C6C92',
Expand Down Expand Up @@ -622,7 +648,7 @@ def __init__(
self._extra_equations = None
self._extra_params = None
# Add membrane equations:
self._add_equations(model)
self._create_equations(model)
# Keep track of electrophysiological properties:
self._ephys_object = EphysProperties(
name=None,
Expand All @@ -645,7 +671,7 @@ def __str__(self):
f"USER PARAMETERS\n{15*'-'}\n{user}")
return txt

def _add_equations(self, model: str):
def _create_equations(self, model: str):
"""
Adds equations to a compartment.
Expand Down
Loading

0 comments on commit a79c0d6

Please sign in to comment.