From 77ef4fc9cf8cc4026fa7a501580c0f6c589eb509 Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Tue, 9 Jul 2024 12:43:12 -0400 Subject: [PATCH] MAINT: setting up gui cell params default values --- hnn_core/gui/gui.py | 195 ++++++++++++++++++++++++++------------------ 1 file changed, 115 insertions(+), 80 deletions(-) diff --git a/hnn_core/gui/gui.py b/hnn_core/gui/gui.py index ccb05282f3..3f12cf303d 100644 --- a/hnn_core/gui/gui.py +++ b/hnn_core/gui/gui.py @@ -26,84 +26,98 @@ from hnn_core.network import pick_connection from hnn_core.params import _extract_drive_specs_from_hnn_params from hnn_core.dipole import _read_dipole_txt +from hnn_core.cells_default import pyramidal +from hnn_core.params_default import (get_L2Pyr_params_default, + get_L5Pyr_params_default) import base64 import zipfile import numpy as np from copy import deepcopy -cell_parameters_dic = { + +class CellParamGui(): + def __init__(self, cell_type, layer, label, units): + self.layer = layer + self.cell_type = cell_type + self.label = label + self.units = units + + +cell_parameters_dict = { "Geometry": [ - ('Soma lenght', 'micron'), - ('Soma diameter', 'micron'), - ('Soma capacitive density', 'F/cm2'), - ('Soma resistivity', 'ohm-cm'), - ('Dendrite capacitive density', 'F/cm2'), - ('Dendrite resistivity', 'ohm-cm'), - ('Apical Dendrite Trunk lenght', 'micron'), - ('Apical Dendrite 1 lenght', 'micron'), - ('Apical Dendrite 1 diameter', 'micron'), - ('Apical Dendrite Tuft lenght', 'micron'), - ('Apical Dendrite Tuft diameter', 'micron'), - ('Oblique Apical Dendrite lenght', 'micron'), - ('Oblique Apical Dendrite diameter', 'micron'), - ('Basal Dendrite 1 lenght', 'micron'), - ('Basal Dendrite 1 diameter', 'micron'), - ('Basal Dendrite 2 lenght', 'micron'), - ('Basal Dendrite 2 diameter', 'micron'), - ('Basal Dendrite 3 lenght', 'micron'), - ('Basal Dendrite 3 diameter', 'micron') + ('Soma length', 'micron', 'soma_L'), + ('Soma diameter', 'micron', 'soma_diam'), + ('Soma capacitive density', 'F/cm2', 'soma_cm'), + ('Soma resistivity', 'ohm-cm', 'soma_Ra'), + ('Dendrite capacitive density', 'F/cm2', 'dend_cm'), + ('Dendrite resistivity', 'ohm-cm', 'dend_Ra'), + ('Apical Dendrite Trunk length', 'micron', 'apicaltrunk_L'), + ('Apical Dendrite 1 length', 'micron', 'apicaltrunk_diam'), + ('Apical Dendrite 1 diameter', 'micron', 'apical1_L'), + ('Apical Dendrite Tuft length', 'micron', 'apicaltuft_L'), + ('Apical Dendrite Tuft diameter', 'micron', 'apicaltuft_diam'), + ('Oblique Apical Dendrite length', 'micron', 'apicaloblique_L'), + ('Oblique Apical Dendrite diameter', 'micron', 'apicaloblique_diam'), + ('Basal Dendrite 1 length', 'micron', 'basal1_L'), + ('Basal Dendrite 1 diameter', 'micron', 'basal1_diam'), + ('Basal Dendrite 2 length', 'micron', 'basal2_L'), + ('Basal Dendrite 2 diameter', 'micron', 'basal2_diam'), + ('Basal Dendrite 3 length', 'micron', 'basal3_L'), + ('Basal Dendrite 3 diameter', 'micron', 'basal3_diam') ], "Synapses": [ - ('AMPA reversal', 'mV'), - ('AMPA rise time', 'ms'), - ('AMPA decay time', 'ms'), - ('NMDA reversal', 'mV'), - ('NMDA rise time', 'ms'), - ('NMDA decay time', 'ms'), - ('GABAA reversal', 'mV'), - ('GABAA rise time', 'ms'), - ('GABAA decay time', 'ms'), - ('GABAB reversal', 'mV'), - ('GABAB rise time', 'ms'), - ('GABAB decay time', 'ms') + ('AMPA reversal', 'mV', 'ampa_e'), + ('AMPA rise time', 'ms', 'ampa_tau1'), + ('AMPA decay time', 'ms', 'ampa_tau2'), + ('NMDA reversal', 'mV', 'nmda_e'), + ('NMDA rise time', 'ms', 'nmda_tau1'), + ('NMDA decay time', 'ms', 'nmda_tau2'), + ('GABAA reversal', 'mV', 'gabaa_e'), + ('GABAA rise time', 'ms', 'gabaa_tau1'), + ('GABAA decay time', 'ms', 'gabaa_tau2'), + ('GABAB reversal', 'mV', 'gabab_e'), + ('GABAB rise time', 'ms', 'gabab_tau1'), + ('GABAB decay time', 'ms', 'gabab_tau2') ], "Biophysics L2": [ - ('Soma Kv channel density', 'S/cm2'), - ('Soma Na channel density', 'S/cm2'), - ('Soma leak reversal', 'mV'), - ('Soma leak channel density', 'S/cm2'), - ('Soma Km channel density', 'pS/micron2'), - ('Dendrite Kv channel density', 'S/cm2'), - ('Dendrite Na channel density', 'S/cm2'), - ('Dendrite leak reversal', 'mV'), - ('Dendrite leak channel density', 'S/cm2'), - ('Dendrite Km channel density', 'pS/micron2') + ('Soma Kv channel density', 'S/cm2', 'soma_gkbar_hh2'), + ('Soma Na channel density', 'S/cm2', 'soma_gnabar_hh2'), + ('Soma leak reversal', 'mV', 'soma_el_hh2'), + ('Soma leak channel density', 'S/cm2', 'soma_gl_hh2'), + ('Soma Km channel density', 'pS/micron2', 'soma_gbar_km'), + ('Dendrite Kv channel density', 'S/cm2', 'dend_gkbar_hh2'), + ('Dendrite Na channel density', 'S/cm2', 'dend_gnabar_hh2'), + ('Dendrite leak reversal', 'mV', 'dend_el_hh2'), + ('Dendrite leak channel density', 'S/cm2', 'dend_gl_hh2'), + ('Dendrite Km channel density', 'pS/micron2', 'dend_gbar_km') ], "Biophysics L5": [ - ('Soma Kv channel density', 'S/cm2'), - ('Soma Na channel density', 'S/cm2'), - ('Soma leak reversal', 'mV'), - ('Soma leak channel density', 'S/cm2'), - ('Soma Ca channel density', 'pS/micron2'), - ('Soma Ca decay time', 'ms'), - ('Soma Kca channel density', 'pS/micron2'), - ('Soma Km channel density', 'pS/micron2'), - ('Soma CaT channel density', 'S/cm2'), - ('Soma HCN channel density', 'S/cm2'), - ('Dendrite Kv channel density', 'S/cm2'), - ('Dendrite Na channel density', 'S/cm2'), - ('Dendrite leak reversal', 'mV'), - ('Dendrite leak channel density', 'S/cm2'), - ('Dendrite KCa channel density', 'pS/micron2'), - ('Dendrite Km channel density', 'pS/micron2'), - ('Dendrite CaT channel density', 'S/cm2'), - ('Dendrite HCN channel density', 'S/cm2') + ('Soma Kv channel density', 'S/cm2', 'soma_gkbar_hh2'), + ('Soma Na channel density', 'S/cm2', 'soma_gnabar_hh2'), + ('Soma leak reversal', 'mV', 'soma_el_hh2'), + ('Soma leak channel density', 'S/cm2', 'soma_gl_hh2'), + ('Soma Ca channel density', 'pS/micron2', 'soma_gbar_ca'), + ('Soma Ca decay time', 'ms', 'soma_taur_cad'), + ('Soma Kca channel density', 'pS/micron2', 'soma_gbar_kca'), + ('Soma Km channel density', 'pS/micron2', 'soma_gbar_km'), + ('Soma CaT channel density', 'S/cm2', 'soma_gbar_cat'), + ('Soma HCN channel density', 'S/cm2', 'soma_gbar_ar'), + ('Dendrite Kv channel density', 'S/cm2', 'dend_gkbar_hh2'), + ('Dendrite Na channel density', 'S/cm2', 'dend_gnabar_hh2'), + ('Dendrite leak reversal', 'mV', 'dend_el_hh2'), + ('Dendrite leak channel density', 'S/cm2', 'dend_gl_hh2'), + ('Dendrite Ca channel density', 'pS/micron2', 'dend_gbar_ca'), + ('Dendrite Ca decay time', 'ms', 'dend_taur_cad'), + ('Dendrite KCa channel density', 'pS/micron2', 'dend_gbar_kca'), + ('Dendrite Km channel density', 'pS/micron2', 'dend_gbar_km'), + ('Dendrite CaT channel density', 'S/cm2', 'dend_gbar_cat'), + ('Dendrite HCN channel density', 'S/cm2', 'dend_gbar_ar') ] } @@ -1365,30 +1379,36 @@ def add_cell_parameters_tab(network, cell_params_out, cell_pameters_vboxes, cell_layer_radio_button, cell_type_radio_button, layout): - cell_types = ["L2", "L5"] + L2_defautl_values = get_L2Pyr_params_default() + L5_default_values = get_L5Pyr_params_default() + cell_types = [("L2", L2_defautl_values), ("L5", L5_default_values)] style = {'description_width': '235px'} kwargs = dict(layout=layout, style=style) # get_cell_params_dic_values(network.cell_types) for cell_type in cell_types: layer_parameters = list() - for layer in cell_parameters_dic.keys(): - if 'Biophysic' in layer and cell_type not in layer: + for layer in cell_parameters_dict.keys(): + if 'Biophysic' in layer and cell_type[0] not in layer: continue - for parameter in cell_parameters_dic[layer]: - param_name = parameter[0] - param_units = parameter[1] + for parameter in cell_parameters_dict[layer]: + param_name, param_units, params_key = (parameter[0], + parameter[1], + parameter[2]) + default_value = get_cell_param_default_value( + f'{cell_type[0]}Pyr_{params_key}', cell_type[1]) description = f"{param_name} ({param_units})" - text_field = BoundedFloatText(value=0.0, - min=0, - max=10.0, + min_value = -1000.0 if param_units not in 'ms' else 0 + text_field = BoundedFloatText(value=default_value, + min=min_value, + max=1000.0, step=0.1, description=description, disabled=False, **kwargs) layer_parameters.append(text_field) - cell_pameters_key = cell_type + "_" + layer + cell_pameters_key = f'{cell_type[0]}_{layer}' cell_pameters_vboxes[cell_pameters_key] = VBox(layer_parameters) layer_parameters.clear() @@ -1405,15 +1425,8 @@ def add_cell_parameters_tab(network, cell_params_out, cell_pameters_vboxes, cell_layer_radio_button.value)) -def get_cell_params_dic_values(network_cell_types): - # cell_types = [ct for ct in network_cell_types.keys() - # if "pyramidal" in ct] - ... - # for type in cell_types: - # cell_type = network_cell_types[type] - # # get geometry params - - # cell_types.sections['soma'] +def get_cell_param_default_value(cell_type_key, param_dict): + return param_dict[cell_type_key] def add_drive_tab(params, log_out, drives_out, drive_widgets, drive_boxes, @@ -1549,7 +1562,7 @@ def on_upload_params_change(change, tstop, dt, log_out, drive_boxes, def _init_network_from_widgets(params, dt, tstop, single_simulation_data, drive_widgets, connectivity_textfields, - add_drive=True): + cell_pararms_widgets, add_drive=True): """Construct network and add drives.""" print("init network") params['dt'] = dt.value @@ -1576,6 +1589,28 @@ def _init_network_from_widgets(params, dt, tstop, single_simulation_data, single_simulation_data['net'].connectivity[conn_idx][ 'probability'] = vbox.children[2].value + # add cell parameters + # Geometry + cell_type_template = dict() + for cell_layer in cell_pararms_widgets.keys(): + if 'Geometry' in cell_layer: + float_text_fields = cell_pararms_widgets[cell_layer].children + cell_type = cell_layer.split('_')[0] + # at this point only L2 and L5 should be in the cell_type variable + # althought, it still has the Pyr substring as suffix + geometry_param_list = cell_parameters_dict['Geometry'] + for index, geometry_param in enumerate(geometry_param_list): + # proccess a list of tuples (label,units,desc_key) + cell_pameters_key = f'{cell_type}_{geometry_param[2]}' + cell_type_template[cell_pameters_key] = ( + float_text_fields[index].value) + l_geometry_template = pyramidal(cell_type, + override_params=cell_type_template) + print(l_geometry_template) + # single_simulation_data['net']._add_cell_type(cell_type,cell_template=l_geometry_template) + # clean dictionary for next cell type geometry + cell_type_template.clear() + if add_drive is False: return # add drives to network