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

Commit 57c9e5a

Browse files
author
Jaquier Aurélien Tristan
committed
Lint fix
1 parent e0b2bfb commit 57c9e5a

File tree

4 files changed

+136
-55
lines changed

4 files changed

+136
-55
lines changed

bluepyopt/neuroml/biophys.py

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
ignore_params = ["cm", "Ra", "ena", "ek"]
2727

28-
# Due to the use of 1e-4 in BREAKPOINT in StochKv.mod: ik = 1e-4 * gk * (v - ek)
28+
# Due to the use of 1e-4 in BREAKPOINT in StochKv.mod:
29+
# ik = 1e-4 * gk * (v - ek)
2930
density_scales = {"StochKv": 1e-4}
3031

3132
channel_substitutes = {"StochKv": "StochKv_deterministic"}
@@ -95,8 +96,10 @@ def adapt_CaDynamics_nml(
9596
channel_dir (str): repo in which to copy the channel files
9697
"""
9798
place_after = (
98-
' <concentrationModel id="CaDynamics_E2_NML2" type="concentrationModelHayEtAl" '
99-
'minCai="1e-4 mM" decay="80 ms" depth="0.1 um" gamma="0.05" ion="ca"/>\n'
99+
' <concentrationModel id="CaDynamics_E2_NML2" '
100+
'type="concentrationModelHayEtAl" '
101+
'minCai="1e-4 mM" decay="80 ms" depth="0.1 um" '
102+
'gamma="0.05" ion="ca"/>\n'
100103
)
101104
cadyn_filename = "baseCaDynamics_E2_NML2.nml"
102105
new_cadyn_filename = "CaDynamics_E2_NML2.nml"
@@ -112,7 +115,7 @@ def adapt_CaDynamics_nml(
112115
f'gamma="{value_dict["gamma"]}" '
113116
f'decay="{value_dict["decay"]} ms" depth="0.1 um"/>\n'
114117
)
115-
if not new_concentration in lines:
118+
if new_concentration not in lines:
116119
idx = lines.index(place_after) + 2 # 2 to account for blank line
117120
lines.insert(idx, f"{new_concentration}\n")
118121

@@ -136,7 +139,9 @@ def get_channel_from_param_name(param_name):
136139
elif len(split_name) == 2:
137140
channel = split_name[1]
138141
else:
139-
raise Exception(f"Could not extract channel from parameter name {param_name}")
142+
raise Exception(
143+
f"Could not extract channel from parameter name {param_name}"
144+
)
140145

141146
return channel
142147

@@ -152,7 +157,8 @@ def format_dist_fun(raw_expr, value, dist_param_names):
152157
"""
153158
if dist_param_names is not None:
154159
raise NotImplementedError(
155-
"Functions that depend on other parameters, like decay function, are not implemented yet."
160+
"Functions that depend on other parameters, "
161+
"like decay function, are not implemented yet."
156162
)
157163
new_expr = raw_expr.format(distance="p", value=value)
158164
if "math" in new_expr:
@@ -224,8 +230,10 @@ def get_arguments(
224230
parameter_name (str): name of the parameter (e.g. e_pas)
225231
section_list (str): name of the location of the parameter (e.g. axonal)
226232
channel (str): ion channel (e.g. StochKv)
227-
channel_name (str): ion channel name used in the neuroML channel file (e.g. StochKv_deterministic)
228-
variable_parameters (list of neuroml.VariableParameter): parameters for non-uniform distributions
233+
channel_name (str): ion channel name used in the neuroML channel file
234+
(e.g. StochKv_deterministic)
235+
variable_parameters (list of neuroml.VariableParameter):
236+
parameters for non-uniform distributions
229237
cond_density (str): conductance density
230238
release_params (dict): optimized parameters
231239
"""
@@ -240,7 +248,6 @@ def get_arguments(
240248
erev = None
241249
channel_class = "ChannelDensityNernst"
242250
elif erev == "pas":
243-
# do all pas have the same section_list? e.g. does it happen to have g_pas.all and e_pas.somatic?
244251
erev = params[f"e_pas.{section_list}"].value
245252
if erev is None:
246253
# non frozen parameter
@@ -338,7 +345,8 @@ def get_density(
338345
cell (ephys.CellModel)
339346
parameter (ephys.parameters)
340347
section_list (str): location
341-
included_channels (list): list of channels already included in the nml file
348+
included_channels (list): list of channels already included
349+
in the nml file
342350
skip_non_uniform (bool): True to skip non uniform distributions
343351
release_params (dict): optimized parameters
344352
skip_channels_copy (bool): True to skip the copy pasting
@@ -397,7 +405,9 @@ def get_specific_capacitance(capacitance_overwrites):
397405
capacitance = default_capacitances[section_list]
398406

399407
specific_capacitances.append(
400-
neuroml.SpecificCapacitance(value=capacitance, segment_groups=section_list)
408+
neuroml.SpecificCapacitance(
409+
value=capacitance, segment_groups=section_list
410+
)
401411
)
402412

403413
return specific_capacitances
@@ -426,7 +436,7 @@ def get_biophys(
426436
included_channels = []
427437
channel_densities = []
428438
channel_density_nernsts = []
429-
channel_density_non_uniform_nernsts = []
439+
channel_density_non_unif_nernsts = []
430440
channel_density_non_uniforms = []
431441
species = []
432442

@@ -460,8 +470,12 @@ def get_biophys(
460470
# add density to list of densities
461471
if channel_class == "ChannelDensityNernst":
462472
channel_density_nernsts.append(density)
463-
elif channel_class == "ChannelDensityNernstNonUniform":
464-
channel_density_non_uniform_nernsts.append(density)
473+
elif (
474+
channel_class == "ChannelDensityNernstNonUniform"
475+
):
476+
channel_density_non_unif_nernsts.append(
477+
density
478+
)
465479
elif channel_class == "ChannelDensityNonUniform":
466480
channel_density_non_uniforms.append(density)
467481
else:
@@ -474,7 +488,7 @@ def get_biophys(
474488
# non frozen parameter
475489
value = release_params[parameter.name]
476490

477-
if not model in concentrationModels:
491+
if model not in concentrationModels:
478492
concentrationModels[model] = {}
479493
concentrationModels[model]["gamma"] = value
480494

@@ -493,15 +507,17 @@ def get_biophys(
493507

494508
channel_nml2_file = "CaDynamics_E2_NML2.nml"
495509
add_nml_channel_to_nml_cell_file(
496-
cell_doc, included_channels, channel_nml2_file=channel_nml2_file
510+
cell_doc,
511+
included_channels,
512+
channel_nml2_file=channel_nml2_file,
497513
)
498514

499515
value = parameter.value
500516
if value is None:
501517
# non frozen parameter
502518
value = release_params[parameter.name]
503519

504-
if not model in concentrationModels:
520+
if model not in concentrationModels:
505521
concentrationModels[model] = {}
506522
concentrationModels[model]["decay"] = value
507523

@@ -524,15 +540,17 @@ def get_biophys(
524540
membrane_properties = neuroml.MembraneProperties(
525541
channel_densities=channel_densities,
526542
channel_density_nernsts=channel_density_nernsts,
527-
channel_density_non_uniform_nernsts=channel_density_non_uniform_nernsts,
543+
channel_density_non_uniform_nernsts=channel_density_non_unif_nernsts,
528544
channel_density_non_uniforms=channel_density_non_uniforms,
529545
specific_capacitances=specific_capacitances,
530546
init_memb_potentials=init_memb_potentials,
531547
)
532548

533549
# Intracellular Properties
534550
Ra = cell.params["Ra.all"].value
535-
resistivities = [neuroml.Resistivity(value=f"{Ra} ohm_cm", segment_groups="all")]
551+
resistivities = [
552+
neuroml.Resistivity(value=f"{Ra} ohm_cm", segment_groups="all")
553+
]
536554

537555
intracellular_properties = neuroml.IntracellularProperties(
538556
resistivities=resistivities,

bluepyopt/neuroml/cell.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def create_neuroml_cell(bpo_cell, release_params, skip_channels_copy=False):
3131
"""Create the cell.
3232
3333
Arguments:
34-
nml_mech_files (list): paths to the nml files containing the mechanisms
34+
nml_mech_files (list): paths to the nml files
35+
containing the mechanisms
3536
bpo_cell
3637
release_params (dict): the optimized parameters
3738
skip_channels_copy (bool): True to skip the copy pasting
@@ -45,11 +46,13 @@ def create_neuroml_cell(bpo_cell, release_params, skip_channels_copy=False):
4546
network_filename = f"{bpo_cell.name}.net.nml"
4647

4748
# Morphology
48-
logger.info("This will create a cell hoc file in order to create a cell nml file")
49+
logger.info(
50+
"This will create a cell hoc file in order to create a cell nml file"
51+
)
4952
create_morph_nml(bpo_cell, network_filename, release_params)
5053

5154
# change the network temperature.
52-
# For some reason, the pyneurom.export_to_neuroml2 sets it automatically to 6C.
55+
# because the pyneurom.export_to_neuroml2 sets it automatically to 6C.
5356
network_doc = pynml.read_neuroml2_file(network_filename)
5457
network = network_doc.networks[0]
5558
network.temperature = f"{bpo_cell.params['celsius'].value} degC"

bluepyopt/neuroml/morphology.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@ def create_loadcell_hoc(
3232
morph_path = Path(morphology_path)
3333
morph_dir = morph_path.parent
3434
morph_file = morph_path.name
35+
cell_cmd = '"cell = new %s(\\"%s\\", \\"%s\\")"'
36+
cell = f'{cell_cmd}, "{cell_name}", "{morph_dir}", "{morph_file}"'
3537
loadcell_hoc = f"""
3638
load_file("nrngui.hoc")
3739
load_file("import3d.hoc")
3840
load_file("{hoc_filename}")
3941
4042
// ================== constants ==================
4143
v_init={v_init}
42-
//=================== creating cell object ===========================
44+
// ================== creating cell object ==================
4345
objref cell
4446
4547
proc create_cell() {{ localobj cellstring
4648
cellstring = new String()
47-
sprint(cellstring.s, "cell = new %s(\\"%s\\", \\"%s\\")", "{cell_name}", "{morph_dir}", "{morph_file}")
49+
sprint(cellstring.s, {cell})
4850
execute(cellstring.s)
4951
}}
5052
create_cell(0)
@@ -76,12 +78,14 @@ def create_morph_nml(bpo_cell, network_filename, release_params):
7678

7779
if not os.path.isdir("x86_64"):
7880
logger.warning(
79-
"It seems you have not compiled the mechanisms. This program will likely fail."
81+
"It seems you have not compiled the mechanisms. "
82+
"This program will likely fail."
8083
)
8184

8285
# isolate the export_to_neuroml to a subprocess
8386
# so that the cell remain non-instantiated in the main process
84-
# that way, using this function will not prevent us to run the cell with bluepyopt
87+
# that way, using this function will not prevent us to run the cell
88+
# with bluepyopt
8589
with pebble.ProcessPool(max_workers=1, max_tasks=1) as pool:
8690
tasks = pool.schedule(
8791
export_to_neuroml2,
@@ -128,10 +132,14 @@ def add_segment_groups(cell):
128132
)
129133

130134
cell.morphology.segment_groups.append(
131-
neuroml.SegmentGroup(id="soma_group", includes=[neuroml.Include("somatic")])
135+
neuroml.SegmentGroup(
136+
id="soma_group", includes=[neuroml.Include("somatic")]
137+
)
132138
)
133139
cell.morphology.segment_groups.append(
134-
neuroml.SegmentGroup(id="axon_group", includes=[neuroml.Include("axonal")])
140+
neuroml.SegmentGroup(
141+
id="axon_group", includes=[neuroml.Include("axonal")]
142+
)
135143
)
136144
cell.morphology.segment_groups.append(
137145
neuroml.SegmentGroup(

0 commit comments

Comments
 (0)