Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit d7d2f12

Browse files
authored
Merge pull request #443 from BlueBrain/api-changes
Api changes
2 parents b2c9ac3 + c6d28a9 commit d7d2f12

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

bluepyopt/ephys/create_hoc.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@
4949
'myelinated']
5050

5151

52+
def generate_channels_by_location(mechs, location_order):
53+
"""Create a OrderedDictionary of all channel mechs for hoc template.
54+
55+
Args:
56+
mechs (list of bluepyopt.ephys.mechanisms.Mechanism): mechanisms
57+
location_order (list of str): order of locations
58+
59+
Returns: tuple of channels, point_channels and location order
60+
"""
61+
loc_desc = _loc_desc
62+
return _generate_channels_by_location(mechs, location_order, loc_desc)
63+
64+
5265
def _generate_channels_by_location(mechs, location_order, loc_desc):
5366
"""Create a OrderedDictionary of all channel mechs for hoc template."""
5467
channels = OrderedDict((location, []) for location in location_order)
@@ -63,7 +76,7 @@ def _generate_channels_by_location(mechs, location_order, loc_desc):
6376
return channels, point_channels
6477

6578

66-
def _generate_reinitrng(mechs):
79+
def generate_reinitrng(mechs) -> str:
6780
"""Create re_init_rng function"""
6881

6982
for mech in mechs:
@@ -85,7 +98,7 @@ def _generate_reinitrng(mechs):
8598
return reinitrng_content
8699

87100

88-
def _range_exprs_to_hoc(range_params):
101+
def range_exprs_to_hoc(range_params):
89102
"""Process raw range parameters to hoc strings"""
90103

91104
ret = []
@@ -317,10 +330,10 @@ def create_hoc(mechs,
317330
del template_params['pprocess_params']
318331
del template_params['point_channels']
319332

320-
template_params['range_params'] = _range_exprs_to_hoc(
333+
template_params['range_params'] = range_exprs_to_hoc(
321334
template_params['range_params']
322335
)
323-
re_init_rng = _generate_reinitrng(mechs)
336+
re_init_rng = generate_reinitrng(mechs)
324337

325338
if custom_jinja_params is None:
326339
custom_jinja_params = {}

bluepyopt/ephys/locations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class NrnSecSomaDistanceCompLocation(NrnSomaDistanceCompLocation):
399399
"""Compartment on a section defined both by a section index and distance
400400
from the soma """
401401

402-
SERIALIZED_FIELDS = ('name', 'comment', 'soma_distance', 'sec_name',
402+
SERIALIZED_FIELDS = ('name', 'comment', 'soma_distance', 'seclist_name',
403403
'sec_index', )
404404

405405
def __init__(
@@ -416,7 +416,7 @@ def __init__(
416416
name (str): name of this object
417417
soma_distance (float): distance from soma to this compartment
418418
sec_index (int): index of the section to consider
419-
sec_name (str): name of Neuron sections (ex: 'apic')
419+
seclist_name (str): name of Neuron sections (ex: 'apic')
420420
"""
421421
super(NrnSecSomaDistanceCompLocation, self).__init__(
422422
name,

bluepyopt/tests/test_ephys/test_create_hoc.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
import os
66

7+
from bluepyopt.ephys.acc import ArbLabel
8+
from bluepyopt.ephys.parameterscalers import NrnSegmentSomaDistanceScaler
9+
710
from . import utils
8-
from bluepyopt.ephys import create_hoc
11+
from bluepyopt.ephys import create_acc, create_hoc
912

1013

1114
import pytest
12-
import numpy
1315

1416
DEFAULT_LOCATION_ORDER = [
1517
'all',
@@ -20,6 +22,19 @@
2022
'myelinated']
2123

2224

25+
@pytest.mark.unit
26+
def test_generate_channels_by_location():
27+
"""ephys.create_hoc: Test generate_channels_by_location"""
28+
mech = utils.make_mech()
29+
public_res = create_hoc.generate_channels_by_location(
30+
[mech], DEFAULT_LOCATION_ORDER,
31+
)
32+
private_res = create_hoc._generate_channels_by_location(
33+
[mech], DEFAULT_LOCATION_ORDER, create_hoc._loc_desc
34+
)
35+
assert public_res == private_res
36+
37+
2338
@pytest.mark.unit
2439
def test__generate_channels_by_location():
2540
"""ephys.create_hoc: Test _generate_channels_by_location"""
@@ -105,3 +120,34 @@ def test_create_hoc_filename():
105120
assert 'endtemplate' in hoc
106121
assert 'Test template' in hoc
107122
assert custom_param_val in hoc
123+
124+
125+
@pytest.mark.unit
126+
def test_generate_reinitrng():
127+
"""ephys.create_hoc: Test generate_reinitrng"""
128+
mech = utils.make_mech()
129+
re_init_rng = create_hoc.generate_reinitrng([mech])
130+
assert 'func hash_str() {localobj sf strdef right' in re_init_rng
131+
assert ' hash = (hash * 31 + char_int) % (2 ^ 31 - 1)' in re_init_rng
132+
133+
134+
@pytest.mark.unit
135+
def test_range_exprs_to_hoc():
136+
"""ephys.create_hoc: Test range_exprs_to_hoc"""
137+
apical_region = ArbLabel("region", "apic", "(tag 4)")
138+
param_scaler = NrnSegmentSomaDistanceScaler(
139+
name='soma-distance-scaler',
140+
distribution='(-0.8696 + 2.087*math.exp(({distance})*0.0031))*{value}'
141+
)
142+
143+
range_expr = create_acc.RangeExpr(
144+
location=apical_region,
145+
name="gkbar_hh",
146+
value=0.025,
147+
value_scaler=param_scaler
148+
)
149+
150+
hoc = create_hoc.range_exprs_to_hoc([range_expr])
151+
assert hoc[0].param_name == 'gkbar_hh'
152+
val_gt = '(-0.8696 + 2.087*exp((%.17g)*0.0031))*0.025000000000000001'
153+
assert hoc[0].value == val_gt

0 commit comments

Comments
 (0)