Skip to content

Commit

Permalink
Merge pull request #128 from BlueBrain/square_ecode
Browse files Browse the repository at this point in the history
Square ecode
  • Loading branch information
AurelienJaquier committed Apr 12, 2024
2 parents 0ab79fb + eb56686 commit 53cff1c
Show file tree
Hide file tree
Showing 42 changed files with 1,041 additions and 443 deletions.
4 changes: 3 additions & 1 deletion bluepyemodel/ecode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from .sahp import sAHP
from .sinespec import SineSpec
from .spikerec import SpikeRecMultiSpikes
from .square import BPOSquarePulse
from .subwhitenoise import SubWhiteNoise
from .thresholdaddition import ThresholdAddition
from .whitenoise import WhiteNoise
Expand All @@ -44,10 +45,10 @@
# define duplicates.
eCodes = {
"spontaneous": IDrest,
"step": IDrest,
"idrest": IDrest,
"idthres": IDrest,
"idthresh": IDrest,
"step": IDrest,
"spontaps": IDrest,
"sponnohold30": IDrest,
"sponhold30": IDrest,
Expand Down Expand Up @@ -83,6 +84,7 @@
"startnohold": IDrest,
"thresholdaddition": ThresholdAddition,
"probampanmda_ems": ProbAMPANMDA_EMS,
"bposquarepulse": BPOSquarePulse,
}

fixed_timestep_eCodes = ["probampanmda_ems"]
118 changes: 118 additions & 0 deletions bluepyemodel/ecode/square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
"""BPEM_stimulus class"""

"""
Copyright 2023, EPFL/Blue Brain Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import logging

import numpy
from bluepyopt.ephys.stimuli import NrnSquarePulse

logger = logging.getLogger(__name__)


class BPOSquarePulse(NrnSquarePulse):
"""Abstract current stimulus based on BluePyOpt square stimulus.
Can be used to reproduce results using BluePyOpt's NrnSquarePulse.
.. code-block:: none
holdi holdi+amp holdi
: : :
: : :
: ______________________ :
: | | :
: | | :
: | | :
: | | :
|__________________| |______________________
^ ^ ^ ^
: : : :
: : : :
t=0 delay delay+duration totduration
"""

name = ""

def __init__(self, location, **kwargs):
"""Constructor
Args:
location(Location): location of stimulus
"""

super().__init__(
step_amplitude=kwargs.get("amp", None),
step_delay=kwargs.get("delay", 250.0),
step_duration=kwargs.get("duration", 1350.0),
total_duration=kwargs.get("totduration", 1850.0),
location=location,
)

self.holding_current = kwargs.get("holding_current", None)
self.holding_iclamp = None

@property
def stim_start(self):
return self.step_delay

@property
def stim_end(self):
return self.step_delay + self.step_duration

@property
def amplitude(self):
return self.step_amplitude

def instantiate(self, sim=None, icell=None):
"""Run stimulus"""

icomp = self.location.instantiate(sim=sim, icell=icell)

self.iclamp = sim.neuron.h.IClamp(icomp.x, sec=icomp.sec)
self.iclamp.dur = self.step_duration

self.iclamp.delay = self.step_delay
self.iclamp.amp = self.step_amplitude

if self.holding_current is not None:
self.holding_iclamp = sim.neuron.h.IClamp(icomp.x, sec=icomp.sec)
self.holding_iclamp.dur = self.total_duration
self.holding_iclamp.delay = 0
self.holding_iclamp.amp = self.holding_current

def destroy(self, sim=None): # pylint:disable=W0613
"""Destroy stimulus"""
self.iclamp = None
self.holding_iclamp = None

def generate(self, dt=0.1):
"""Return current time series"""
holding_current = self.holding_current if self.holding_current is not None else 0

t = numpy.arange(0.0, self.total_duration, dt)
current = numpy.full(t.shape, holding_current, dtype="float64")

ton_idx = int(self.stim_start / dt)
toff_idx = int(self.stim_end / dt)

current[ton_idx:toff_idx] += self.amplitude

return t, current

def __str__(self):
"""String representation"""
return f"{self.name} current played at {self.location}"
3 changes: 2 additions & 1 deletion bluepyemodel/efeatures_extraction/targets_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ def is_configuration_valid(self):

def check_presence_RMP_Rin_efeatures(self, name_rmp_protocol, name_Rin_protocol):
"""Check that the protocols supposed to be used for RMP and Rin are present in the target
and that they have the correct efeatures. If some features are missing, add them."""
and that they have the correct efeatures. If some features are missing, add them.
"""

if self.targets:
efeatures_rmp = [
Expand Down
5 changes: 4 additions & 1 deletion bluepyemodel/emodel_pipeline/emodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ def get_related_nexus_ids(self):
"type": "Generation",
"activity": {
"type": "Activity",
"followedWorkflow": {"type": "EModelWorkflow", "id": self.workflow_id},
"followedWorkflow": {
"type": "EModelWorkflow",
"id": self.workflow_id,
},
},
}
}
Expand Down
13 changes: 11 additions & 2 deletions bluepyemodel/emodel_pipeline/emodel_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,15 @@ def as_dict(self):
def as_string(self, seed=None, use_allen_notation=True):
s = ""

for k in ["emodel", "etype", "ttype", "mtype", "species", "brain_region", "iteration"]:
for k in [
"emodel",
"etype",
"ttype",
"mtype",
"species",
"brain_region",
"iteration",
]:
v = getattr(self, k)
if use_allen_notation and k == "brain_region" and self.allen_notation:
v = self.allen_notation
Expand All @@ -220,7 +228,8 @@ def as_string(self, seed=None, use_allen_notation=True):

def check_emodel_name(self):
"""Check if name complies with requirements:
https://nrn.readthedocs.io/en/8.2.3/guide/hoc_chapter_11_old_reference.html#names"""
https://nrn.readthedocs.io/en/8.2.3/guide/hoc_chapter_11_old_reference.html#names
"""

allowed_chars = string.ascii_letters + string.digits + "_"
translate_args = str.maketrans("", "", allowed_chars)
Expand Down
15 changes: 13 additions & 2 deletions bluepyemodel/emodel_pipeline/emodel_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ def __init__(
)

def configure_model(
self, morphology_name, morphology_path=None, morphology_format=None, use_gene_data=False
self,
morphology_name,
morphology_path=None,
morphology_format=None,
use_gene_data=False,
):
"""To be deprecated"""

Expand Down Expand Up @@ -335,7 +339,14 @@ def sanitize_gitignore():

lines = " ".join(line for line in lines)

to_add = ["run/", "checkpoints/", "figures/", "logs/", ".ipython/", ".ipynb_checkpoints/"]
to_add = [
"run/",
"checkpoints/",
"figures/",
"logs/",
".ipython/",
".ipynb_checkpoints/",
]

with open(str(path_gitignore), "a") as f:
for a in to_add:
Expand Down
5 changes: 4 additions & 1 deletion bluepyemodel/emodel_pipeline/emodel_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def get_related_nexus_ids(self):
"type": "Generation",
"activity": {
"type": "Activity",
"followedWorkflow": {"type": "EModelWorkflow", "id": self.workflow_id},
"followedWorkflow": {
"type": "EModelWorkflow",
"id": self.workflow_id,
},
},
}
}
Expand Down
10 changes: 8 additions & 2 deletions bluepyemodel/emodel_pipeline/emodel_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,19 @@ def get_related_nexus_ids(self):
generates = emodels_ids + emodel_scripts_ids
if self.fitness_configuration_id:
generates.append(
{"id": self.fitness_configuration_id, "type": "FitnessCalculatorConfiguration"}
{
"id": self.fitness_configuration_id,
"type": "FitnessCalculatorConfiguration",
}
)

has_part = []
if self.targets_configuration_id:
has_part.append(
{"id": self.targets_configuration_id, "type": "ExtractionTargetsConfiguration"}
{
"id": self.targets_configuration_id,
"type": "ExtractionTargetsConfiguration",
}
)
if self.pipeline_settings_id:
has_part.append({"id": self.pipeline_settings_id, "type": "EModelPipelineSettings"})
Expand Down
Loading

0 comments on commit 53cff1c

Please sign in to comment.