def Biophys1(cell, template_name, dynamic_params): """Loads a biophysical NEURON hoc object using Cell-Types database objects.""" morphology_file = cell.morphology_file hobj = h.Biophys1(str(morphology_file)) #fix_axon(hobj) #set_params_peri(hobj, dynamic_params) return hobj
def Biophys1_dict(cell): """ Set parameters for cells from the Allen Cell Types database Prior to setting parameters will replace the axon with the stub """ morphology_file = cell['morphology'] hobj = h.Biophys1(str(morphology_file)) return hobj
def Biophys1_adjusted(cell_prop): morphology_file_name = str(cell_prop['morphology_file']) hobj = h.Biophys1(morphology_file_name) fix_axon_allactive(hobj) # set_params_peri(hobj, cell_prop.model_params) set_params(hobj, cell_prop.model_params) return hobj
def Biophys1(cell_prop): morphology_file_name = str(cell_prop['morphology_file']) hobj = h.Biophys1(morphology_file_name) fix_axon(hobj) set_params_peri(hobj, cell_prop.model_params) return hobj
def Biophys1_dict(cell): """ Set parameters for cells from the Allen Cell Types database Prior to setting parameters will replace the axon with the stub """ morphology_file = cell['morphology_file'] hobj = h.Biophys1(str(morphology_file)) fix_axon(hobj) set_params_peri(hobj, cell.model_params) return hobj
def __init__(self, swc_file, random_seed=10): nrn.load_neuron_modules(None, None) self._hobj = h.Biophys1(swc_file) self._morphology = Morphology(self._hobj) self._morphology.set_seg_props() self._morphology.calc_seg_coords() self._prng = np.random.RandomState(random_seed) self._secs = [] self._save_sections()
def Biophys1(cell_prop): ''' Set parameters for cells from the Allen Cell Types database Prior to setting parameters will replace the axon with the stub ''' morphology_file_name = str(cell_prop['morphology_file']) hobj = h.Biophys1(morphology_file_name) fix_axon(hobj) # set_params_peri(hobj, cell_prop.model_params) set_params(hobj, cell_prop.model_params) return hobj
def Biophys1(cell_prop): ''' Set parameters for cells from the Allen Cell Types database Prior to setting parameters will replace the axon with the stub ''' morphology_file_name = str(cell_prop['morphology_file']) hobj = h.Biophys1(morphology_file_name) fix_axon_allactive(hobj) #fix_axon(hobj) # set_params_peri(hobj, cell_prop.model_params) set_params(hobj, cell_prop.model_params) def calc_density_exp(dist): # FILL IN HERE g_max = 2.84922026765e-07 density = g_max * (-0.8696 + 2.087 * np.exp((dist) * 0.0031)) #return dist return density targeted_sections = ['apic'] # only apply to these types of segements h.distance( sec=hobj.soma[0] ) # need this to set all distances relative to soma (not sure if from center?) for sec in hobj.all: sec_type = sec.name().split(".")[1][:4] if sec_type in targeted_sections: # sec.insert('Ih_mod') # insert channel mechanics for seg in sec: dist = h.distance(seg.x) sec_density = calc_density_exp( dist) # calculate the channel density setattr(seg, 'gbar_Ih_mod', sec_density) # 0.0166428509042) for sec in hobj.all: sec_type = sec.name().split(".")[1][:4] if sec_type == 'axon': continue # print the distance! #if sec_type in targeted_sections: print sec.name() for seg in sec: print h.distance(seg.x), seg.gbar_Ih_mod return hobj
def __init__(self, swc_path, fix_axon=True): self._swc_path = swc_path self._swc_df = pd.read_csv( swc_path, sep=' ', names=['id', 'type', 'x', 'y', 'z', 'r', 'pid'], comment='#') nrn.load_neuron_modules(None, None) self._hobj = h.Biophys1(swc_path) self._sections = [] self._swc_ids = [] section_list = list(self._hobj.all) for ln in range(len(self._swc_df)): sec_id = int(self._hobj.nl.point2sec[ln]) swc_id = int(self._hobj.nl.pt2id(ln)) sec = section_list[sec_id] self._sections.append(sec.name()) self._swc_ids.append(swc_id) self._swc_df['section_name'] = self._sections # self._swc_table = pd.DataFrame({ # 'section_name': self._sections, # 'swc_id': self._swc_ids # }). if fix_axon: self._fix_axon() axon_indices = [ i for i, sec_name in enumerate(self._sections) if 'axon' in sec_name ] self._sections = [ self._sections[i] for i in range(len(self._sections)) if i not in axon_indices ] self._swc_ids = [ self._swc_ids[i] for i in range(len(self._swc_ids)) if i not in axon_indices ]
def NMLLoad(cell, template_name, dynamic_params): """Convert a NEUROML file to a NEURON hoc cell object. Current limitations: * Ignores nml morphology section. You must pass in a swc file * Only for biophysically detailed cell biophysical components. All properties must be assigned to a segment group. :param cell: :param template_name: :param dynamic_params: :return: """ # Last I checked there is no built in way to load a NML file directly into NEURON through the API, instead we have # to manually parse the nml file and build the NEUROM cell object section-by-section. morphology_file = cell.morphology_file hobj = h.Biophys1(str(morphology_file)) # Depending on if the axon is cut before or after setting cell channels and mechanism can create drastically # different results. Currently NML files doesn't produce the same results if you use model_processing directives. # TODO: Find a way to specify model_processing directive with NML file fix_axon_peri(hobj) # Load the hoc template containing a swc initialized NEURON cell if template_name in nml_files: nml_params = nml_files[template_name] else: # Parse the NML parameters file xml tree and cache. biophys_dirs = cell.network.get_component( 'biophysical_neuron_models_dir') nml_path = os.path.join(biophys_dirs, template_name) nml_params = NMLTree(nml_path) nml_files[template_name] = nml_params # Iterate through the NML tree by section and use the properties to manually create cell mechanisms section_lists = [(sec, sec.name().split(".")[1][:4]) for sec in hobj.all] for sec, sec_name in section_lists: for prop_name, prop_obj in nml_params[sec_name].items(): if prop_obj.element_tag() == 'resistivity': sec.Ra = prop_obj.value elif prop_obj.element_tag() == 'specificCapacitance': sec.cm = prop_obj.value elif prop_obj.element_tag( ) == 'channelDensity' and prop_obj.ion_channel == 'pas': sec.insert('pas') setattr(sec, 'g_pas', prop_obj.cond_density) for seg in sec: seg.pas.e = prop_obj.erev elif prop_obj.element_tag( ) == 'channelDensity' or prop_obj.element_tag( ) == 'channelDensityNernst': sec.insert(prop_obj.ion_channel) setattr(sec, prop_obj.id, prop_obj.cond_density) if prop_obj.ion == 'na' and prop_obj: sec.ena = prop_obj.erev elif prop_obj.ion == 'k': sec.ek = prop_obj.erev elif prop_obj.element_tag() == 'concentrationModel': sec.insert(prop_obj.id) setattr(sec, 'gamma_' + prop_obj.type, prop_obj.gamma) setattr(sec, 'decay_' + prop_obj.type, prop_obj.decay) return hobj