forked from BlueBrain/SimulationTutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcell_model.py
More file actions
executable file
·145 lines (120 loc) · 4.85 KB
/
cell_model.py
File metadata and controls
executable file
·145 lines (120 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""Run simple cell optimisation"""
"""
Copyright (c) 2016, EPFL/Blue Brain Project
This file is part of BluePyOpt <https://github.com/BlueBrain/BluePyOpt>
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License version 3.0 as published
by the Free Software Foundation.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
# pylint: disable=R0914
import os
import json
import bluepyopt.ephys as ephys
script_dir = os.path.dirname(__file__)
config_dir = os.path.join(script_dir, 'config')
# TODO store definition dicts in json
# TODO rename 'score' into 'objective'
# TODO add functionality to read settings of every object from config format
def define_mechanisms():
"""Define mechanisms"""
mech_definitions = json.load(
open(
os.path.join(
config_dir,
'mechanisms.json')))
mechanisms = []
for sectionlist, channels in mech_definitions.iteritems():
seclist_loc = ephys.locations.NrnSeclistLocation(
sectionlist,
seclist_name=sectionlist)
for channel in channels:
mechanisms.append(ephys.mechanisms.NrnMODMechanism(
name='%s.%s' % (channel, sectionlist),
mod_path=None,
prefix=channel,
locations=[seclist_loc],
preloaded=True))
return mechanisms
def define_parameters():
"""Define parameters"""
param_configs = json.load(open(os.path.join(config_dir, 'parameters.json')))
parameters = []
for param_config in param_configs:
if 'value' in param_config:
frozen = True
value = param_config['value']
bounds = None
elif 'bounds':
frozen = False
bounds = param_config['bounds']
value = None
else:
raise Exception(
'Parameter config has to have bounds or value: %s'
% param_config)
if param_config['type'] == 'global':
parameters.append(
ephys.parameters.NrnGlobalParameter(
name=param_config['param_name'],
param_name=param_config['param_name'],
frozen=frozen,
bounds=bounds,
value=value))
elif param_config['type'] in ['section', 'range']:
if param_config['dist_type'] == 'uniform':
scaler = ephys.parameterscalers.NrnSegmentLinearScaler()
elif param_config['dist_type'] == 'exp':
scaler = ephys.parameterscalers.NrnSegmentSomaDistanceScaler(
distribution=param_config['dist'])
seclist_loc = ephys.locations.NrnSeclistLocation(
param_config['sectionlist'],
seclist_name=param_config['sectionlist'])
name = '%s.%s' % (param_config['param_name'],
param_config['sectionlist'])
if param_config['type'] == 'section':
parameters.append(
ephys.parameters.NrnSectionParameter(
name=name,
param_name=param_config['param_name'],
value_scaler=scaler,
value=value,
frozen=frozen,
bounds=bounds,
locations=[seclist_loc]))
elif param_config['type'] == 'range':
parameters.append(
ephys.parameters.NrnRangeParameter(
name=name,
param_name=param_config['param_name'],
value_scaler=scaler,
value=value,
frozen=frozen,
bounds=bounds,
locations=[seclist_loc]))
else:
raise Exception(
'Param config type has to be global, section or range: %s' %
param_config)
return parameters
# def define_morphology():
# """Define morphology"""
# return ephys.morphologies.NrnFileMorphology(
# os.path.join(
# script_dir,
# 'morphology/C060114A7.asc'),
# do_replace_axon=True)
def create():
"""Create cell model"""
cell = ephys.models.CellModel(
'abi_cell',
morph=define_morphology(),
mechs=define_mechanisms(),
params=define_parameters())
return cell