Source code for emodelrunner.protocols.protocols_func
"""Protocol-related functions."""
# Copyright 2020-2022 Blue Brain Project / EPFL
# 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
from bluepyopt import ephys
from emodelrunner.recordings import RecordingCustom
from emodelrunner.locations import SOMA_LOC
logger = logging.getLogger(__name__)
seclist_to_sec = {
"somatic": "soma",
"apical": "apic",
"axonal": "axon",
"myelinated": "myelin",
}
[docs]
class CurrentOutputKeyMixin:
"""Contains methods useful for multiple Protocol classes."""
[docs]
def curr_output_key(self):
"""Get the output key for current based on the one for voltage.
Returns:
str used as key in current dict
"""
if self.recordings is not None:
# this gives 'prefix.name'
name = ".".join(self.recordings[0].name.split(".")[:2])
else:
name = ""
return "current_" + name
[docs]
def get_recordings(protocol_name, protocol_definition, prefix, apical_point_isec=-1):
"""Get recordings from protocol definition.
Args:
protocol_name (str): name of the protocol
protocol_definition (dict): dict containing the protocol data
prefix (str): prefix used in naming responses, features, recordings, etc.
apical_point_isec (int): apical point section index
Should be given if there is "somadistanceapic" in "type"
of at least one of the extra recording definition
Returns:
list of RecordingCustom
"""
recordings = []
recordings.append(
RecordingCustom(
name=f"{prefix}.{protocol_name}.soma.v",
location=SOMA_LOC,
variable="v",
)
)
if "extra_recordings" in protocol_definition:
for recording_definition in protocol_definition["extra_recordings"]:
location = get_extra_recording_location(
recording_definition, apical_point_isec
)
var = recording_definition["var"]
recording = RecordingCustom(
name=f"{prefix}.{protocol_name}.{location.name}.{var}",
location=location,
variable=var,
)
recordings.append(recording)
return recordings
[docs]
def check_for_forbidden_protocol(protocols_dict):
"""Check for unsupported protocol.
Args:
protocols_dict (dict): contains all protocols to be run
Raises:
ValueError: If a protocol that should only be used with MainProtocol is present
in protocols_dict
"""
# Those protocols cannot be used if they are not in MainProtocol
forbidden_prots = [
"RatSSCxRinHoldcurrentProtocol",
"RatSSCxThresholdDetectionProtocol",
"StepThresholdProtocol",
"RampThresholdProtocol",
]
# check the class name of each protocol
for prot in protocols_dict.values():
if type(prot).__name__ in forbidden_prots:
prot_name = type(prot).__name__
raise ValueError(
f"No MainProtocol found, but {prot_name} was found."
f"To use {prot_name}, please set MainProtocol."
)