def load_morpho(self, filepath): """ :param filepath: swc file path """ if not path.exists(filepath): raise FileNotFoundError(filepath) # SWC fileformat = filepath.split('.')[-1] if fileformat == 'swc': morpho = h.Import3d_SWC_read() # Neurolucida elif fileformat == 'asc': morpho = h.Import3d_Neurolucida3() else: raise Exception('file format `%s` not recognized' % filepath) self.all = [] morpho.input(filepath) i3d = h.Import3d_GUI(morpho, 0) i3d.instantiate(self) for hoc_sec in self.all: name = hoc_sec.name().split('.')[-1] # eg. name="dend[19]" if len(self.filter_secs(name)) > 0: raise LookupError( "The name '%s' is already taken by another section of the cell: '%s' of type: '%s'." % (name, self.name, self.__class__.__name__)) sec = Sec(hoc_sec, cell=self, name=name) self.secs.append(sec) del self.all
def build_morphology(self): """ Loads a 3D morphology of the neuron """ # Load hoc routines to import 3D morphologies h.load_file('stdlib.hoc') h.load_file("import3d.hoc") cell = h.Import3d_SWC_read() # We have a .swc morphology file #cell = h.Import3d_Neurolucida3() # We have an .asc morphology file # Read the file and creates automatically section.connect(parent) statements cell.input('Pyr_01.swc') # Instantiate morphology for simulation and # execute the connect statements and loads the cell into h scope self.importedcell = h.Import3d_GUI(cell, 0) self.importedcell.instantiate(None) # Create python lists from the morphology with the different sections: soma, dend, apic and axon self.soma = [] self.dend = [] self.apic = [] self.axon = [] # for the moment we will forget about the axon self.all = [] for sec in h.allsec(): if 'soma' in sec.name(): self.soma.append(sec) if 'dend' in sec.name(): self.dend.append(sec) if 'apic' in sec.name(): self.apic.append(sec) if 'axon' in sec.name(): self.axon.append(sec)
def load_morphology(filename): h = get_h() swc = h.Import3d_SWC_read() swc.input(str(filename)) imprt = h.Import3d_GUI(swc, 0) h("objref this") imprt.instantiate(h.this)
def initialize_neuron(swc_path, file_paths): h.load_file("stdgui.hoc") h.load_file("import3d.hoc") swc = h.Import3d_SWC_read() swc.input(swc_path) imprt = h.Import3d_GUI(swc, 0) h("objref this") imprt.instantiate(h.this) print file_paths for sec in h.allsec(): if sec.name().startswith("axon"): h.delete_section(sec=sec) axon = h.Section() axon.L = 60 axon.diam = 1 axon.connect(h.soma[0], 0.5, 0) h.define_shape() for sec in h.allsec(): sec.insert('pas') for seg in sec: seg.pas.e = 0 for file_path in file_paths: h.load_file(file_path.encode("ascii", "ignore"))
def __init__(self, morph): morph = str(morph) self.axon = [] cell = h.Import3d_Neurolucida3() cell.input(morph) i3d = h.Import3d_GUI(cell, 0) i3d.instantiate(self) self.add_axon() self.init_once()
def import_swc_cell(path): morph = h.Import3d_SWC_read() morph.input(path) i3d = h.Import3d_GUI(morph, 0) i3d.instantiate(h.nil) return i3d
def load_morpho(self, filepath, seg_per_L_um=1.0, add_const_segs=11): """ :param filepath: swc file path :param seg_per_L_um: how many segments per single um of L, Length. Can be < 1. None is 0. :param add_const_segs: how many segments have each section by default. With each um of L this number will be increased by seg_per_L_um """ if not path.exists(filepath): raise FileNotFoundError() # SWC fileformat = filepath.split('.')[-1] if fileformat == 'swc': morpho = h.Import3d_SWC_read() # Neurolucida elif fileformat == 'asc': morpho = h.Import3d_Neurolucida3() else: raise Exception('file format `%s` not recognized' % filepath) morpho.input(filepath) h.Import3d_GUI(morpho, 0) i3d = h.Import3d_GUI(morpho, 0) i3d.instantiate(self) # add all SWC sections to self.secs; self.all is defined by SWC import new_secs = {} for sec in self.all: name = sec.name().split('.')[-1] # eg. name="dend[19]" new_secs[name] = sec # change segment number based on seg_per_L_um and add_const_segs for sec in new_secs.values(): add = int(sec.L * seg_per_L_um) if seg_per_L_um is not None else 0 sec.nseg = add_const_segs + add self.secs.update(new_secs) del self.all
def create_morph(swc_file, template): h.load_file("import3d.hoc") h.load_file("nrngui.hoc") h("objref cell, tobj") h.load_file(template + ".hoc") h.execute("cell = new " + template + "()") #replace nl = h.Import3d_SWC_read() nl.quiet = 1 nl.input(swc_file) imprt = h.Import3d_GUI(nl, 0) imprt.instantiate(h.cell) return h.cell
def set_morphology(hobj, morph_file): """Set morphology for the cell from a swc :param hobj: NEURON's cell object :param morph_file: name of swc file containing 3d coordinates of morphology """ swc = h.Import3d_SWC_read() swc.quiet = True swc.input(str(morph_file)) imprt = h.Import3d_GUI(swc, 0) imprt.quiet = True imprt.instantiate(hobj)
def func2map(i): cell = h.Import3d_SWC_read() print(len(nfs)) print(i) morphology_filename = nfs[i] cell = h.Import3d_SWC_read() cell.input(morphology_filename) i3d = h.Import3d_GUI(cell, 0) i3d.instantiate(None) file_name = str(nfs[i]) + str('.wrl') print(file_name) ctng(show=False, magnification=200, file_name=file_name) mlab.savefig(str(nfs[i]) + '.wrl')
def swc2morph(swc_file: str): """ Generate morph sectioning data from .swc file. """ if HAS_NEURON: h.load_file('stdlib.hoc') h.load_file('import3d.hoc') cell = h.Import3d_SWC_read() cell.input(swc_file) i3d = h.Import3d_GUI(cell, 0) i3d.instantiate(None) return neuron2morph(h) else: print("NEURON module is not available.")
def create_model(model_name, morph_file): h("objref cell, tobj") morph_file = "../morphs/" + morph_file model_path = "../PassiveModels/" h.load_file(model_path + model_name + ".hoc") h.execute("cell = new " + model_name + "()") #replace? nl = h.Import3d_Neurolucida3() nl.quiet = 1 nl.input(morph_file) imprt = h.Import3d_GUI(nl, 0) imprt.instantiate(h.cell) cell = h.cell cell.geom_nseg() cell.delete_axon() cell.biophys() return cell
def mkswc(swc_contents): f = open("temp.tmp", "w") f.write(swc_contents) f.close() swc = h.Import3d_SWC_read() swc.input("temp.tmp") ig = h.Import3d_GUI(swc) ig.box.unmap() h.doNotify() ig.box.map("Import3d", 650, 200, -1, -1) h.doNotify() ig.instantiate(None) print (swc_contents) h.topology() print (secinfo()) print ("\n\n\n") return ig
def swc2morph(swc_file): """ Generate morph sectioning data from swc file. """ from neuron import h h.load_file('stdlib.hoc') h.load_file('import3d.hoc') cell = h.Import3d_SWC_read() cell.input(swc_file) i3d = h.Import3d_GUI(cell, 0) i3d.instantiate(None) sections = {} for sec in h.allsec(): sections[sec.name()] = {} sections[sec.name()]["name"] = sec.name() sr = h.SectionRef(sec=sec) if sr.has_parent(): parent = sr.parent.name() else: parent = None sections[sec.name()]["parent"] = parent children = [] for child in sr.child: children.append(child.name()) sections[sec.name()]["children"] = children x = [] y = [] z = [] d = [] n3d = int(h.n3d()) sections[sec.name()]["points"] = [] for i in range(n3d): sections[sec.name()]["points"].append( [h.x3d(i), h.y3d(i), h.z3d(i), h.diam3d(i)]) return sections
def _load_morphology(self, Jonas_cell): ''' internal function: loads morphology and creates section lists''' fileEnding = self.morphology.split('.')[-1] if fileEnding == 'hoc': h.load_file(1, self.morphology) else: h('objref this') # why do i need this? if fileEnding == 'swc': Import = h.Import3d_SWC_read() Import.input(self.morphology) imprt = h.Import3d_GUI(Import, 0) imprt.instantiate(h.this) h.define_shape() # not sure what this does either # set up section names: You need to clarify differences between h.allsec(), h.SectionList() - just makes a new #sectionlist - to do with if have multple cells? self.all_section_names = [] self.sec_list = h.SectionList() self.nsec = 0 self.dendrites = h.SectionList( ) # maybe these should be h.SectionList()? rather than python lists self.axon = h.SectionList() self.soma = h.SectionList() self.root = 'none' for sec in h.allsec(): self.all_section_names.append(sec.name()) self.sec_list.append(sec=sec) self.nsec += 1 # Set up categories for different cell regions if sec.name().find('soma') >= 0: self.soma.append(sec=sec) if sec.name().find('0') >= 0: self.root = sec if self.verbose: print(sec.name(), 'is root') elif Jonas_cell: self.root = sec if sec.name().find('dend') >= 0: self.dendrites.append(sec=sec) if sec.name().find('axon') >= 0: self.dendrites.append(sec=sec)
def create_model(morphology_file, model_obj_name, instance_name, create_type): '''Creates a full morphology cell instance from Neurolucida morphology model template filenames This function is called to create the original instance to be reduced and to create the control cell TODO: To support non-Neurolucida morphology files, this function should be CHANGED. ''' assert instance_name in ('original_cell', 'control_cell'), \ "name must be one of ('original_cell', 'control_cell')" h("{objref %s}" % instance_name) model = dict(instance_name=instance_name, model_obj_name=model_obj_name) if create_type in ('basic', 'human'): h("{instance_name} = new {model_obj_name}()".format(**model)) # instantiates according to morphology using import3d nl = h.Import3d_Neurolucida3() nl.quiet = 1 nl.input(morphology_file) import_3d = h.Import3d_GUI(nl, 0) instance_created = getattr(h, instance_name) # associates cell instance with the morphology file import_3d.instantiate(instance_created) # this function should be included in the model.hoc file given as a parameter instance_created.complete_full_model_creation() elif create_type in ('bbp', 'bbpactive'): h('{instance_name} = new {model_obj_name}(1, "{morphology_file}")'.format( morphology_file=morphology_file, **model)) h('{instance_name} = {instance_name}.CellRef'.format(**model)) elif create_type in ('bbpnew', ): with chdir(morphology_file[:morphology_file.rindex('/')]): h('{instance_name} = new {model_obj_name}(0)'.format(**model)) elif create_type in ('hay', 'almog', 'allen'): h('{instance_name} = new {model_obj_name}("{morphology_file}")'.format( morphology_file=morphology_file, **model)) return getattr(h, instance_name)
def create_model(model_file, morph_file, model_path="../PassiveModels/", morph_path="../morphs/"): # creating the model h.load_file("import3d.hoc") h.load_file("nrngui.hoc") h("objref cell, tobj") h.load_file(model_path + model_file + ".hoc") h.execute("cell = new " + model_file + "()") nl = h.Import3d_Neurolucida3() nl.quiet = 1 nl.input(morph_path + morph_file) imprt = h.Import3d_GUI(nl, 0) imprt.instantiate(h.cell) HCell = h.cell HCell.geom_nseg() HCell.create_model() HCell.biophys() return HCell
def initialize_neuron(swc_path, file_paths): """ Initialize neuron with morphology and load hoc files Parameters ---------- swc_path : str Path to SWC file file_paths : list List of str file paths of files for NEURON to load """ h.load_file("stdgui.hoc") h.load_file("import3d.hoc") swc = h.Import3d_SWC_read() swc.input(swc_path) imprt = h.Import3d_GUI(swc, 0) h("objref this") imprt.instantiate(h.this) for sec in h.allsec(): if sec.name().startswith("axon"): h.delete_section(sec=sec) axon = h.Section() axon.L = 60 axon.diam = 1 axon.connect(h.soma[0], 0.5, 0) h.define_shape() for sec in h.allsec(): sec.insert('pas') for seg in sec: seg.pas.e = 0 for file_path in file_paths: h.load_file(file_path.encode("ascii", "ignore"))
def instantiate_swc(filename): """load an swc file and instantiate it""" ### I have done this already: ########################################### ## load the NEURON library (just in case h is defined otherwise elsewhere) #from neuron import h, gui ## a helper library, included with NEURON #h.load_file('import3d.hoc') ######################################################################### # load the data. Use Import3d_SWC_read for swc, Import3d_Neurolucida3 for # Neurolucida V3, Import3d_MorphML for MorphML (level 1 of NeuroML), or # Import3d_Eutectic_read for Eutectic. (There is also an # Import3d_Neurolucida_read for old Neurolucida files, but I've never seen one # in practice; try Import3d_Neurolucida3 first.) cell = h.Import3d_SWC_read() cell.input(filename) # easiest to instantiate by passing the loaded morphology to the Import3d_GUI # tool; with a second argument of 0, it won't display the GUI, but it will allow # use of the GUI's features i3d = h.Import3d_GUI(cell, 0) i3d.instantiate(None)
def createPops(self): # Get info from nodes files for n in self.network_config['networks']['nodes']: nodes_file = self.subs(n['nodes_file']) node_types_file = self.subs(n['node_types_file']) print("\nLoading nodes from %s and %s" % (nodes_file, node_types_file)) h5file = tables.open_file(nodes_file, mode='r') self.parse_group(h5file.root.nodes) h5file.close() self.nodes_info[self.current_node] = load_csv_props( node_types_file) self.current_node = None pp.pprint(self.nodes_info) # Use extracted node/cell info to create populations for sonata_pop in self.cell_info: # iterate over cell types -- will make one netpyne population per cell type for type in self.cell_info[sonata_pop]['type_numbers']: info = self.nodes_info[sonata_pop][type] pop_name = info['pop_name'] if 'pop_name' in info else None ref = info['model_name'] if 'model_name' in info else info[ 'model_type'] model_type = info['model_type'] model_template = info[ 'model_template'] if 'model_template' in info else '- None -' if pop_name: pop_id = '%s_%s' % (sonata_pop, pop_name) else: pop_id = '%s_%s_%s' % (sonata_pop, ref, type) self.pop_id_from_type[(sonata_pop, type)] = pop_id print(" - Adding population: %s which has model info: %s" % (pop_id, info)) size = self.cell_info[sonata_pop]['type_numbers'][type] # create netpyne pop # Note: alternatively could create sim.net.params.popParams and then call sim.createPops() popTags = {} popTags['cellModel'] = model_type popTags['cellType'] = info[ 'model_name'] if 'model_name' in info else pop_id popTags['numCells'] = size popTags['pop'] = pop_id popTags['ei'] = info['ei'] if 'ei' in info else '' sim.net.pops[pop_id] = sim.Pop(pop_id, popTags) # create population cell template (sections) from morphology and dynamics params files if model_type == 'biophysical': sim.net.pops[pop_id].cellModelClass = sim.CompartCell # morphology morphology_file = self.subs( self.network_config['components']['morphologies_dir'] ) + '/' + info['morphology'] + '.swc' cellMorph = EmptyCell() swcData = h.Import3d_SWC_read() swcData.input(morphology_file) swcSecs = h.Import3d_GUI(swcData, 0) swcSecs.instantiate(cellMorph) # replace axon with AIS stub if self.replaceAxon: fix_axon_peri_v2(cellMorph) # extract netpyne parameters secs, secLists, synMechs, globs = neuronPyHoc.getCellParams( cellMorph) if self.setdLNseg: fix_sec_nseg(secs, sim.cfg.dL) # create mapping of sec ids secLists['SONATA_sec_id'] = [ sim.conversion.getSecName(sec) for sec in cellMorph.all ] cellRule = { 'conds': { 'pop': pop_id }, 'secs': secs, 'secLists': secLists, 'globals': globs } # dynamics params dynamics_params_file = self.subs( self.network_config['components'] ['biophysical_neuron_models_dir'] + '/' + info['model_template']) if info['model_template'].startswith('nml'): dynamics_params_file = dynamics_params_file.replace( 'nml:', '') nml_doc = read_neuroml2_file(dynamics_params_file) cell_dynamic_params = nml_doc.cells[0] cellRule = self.setCellRuleDynamicParamsFromNeuroml( cell_dynamic_params, cellRule) elif info['dynamics_params'].startswith('json'): dynamics_params = load_json(dynamics_params_file) pass # set extracted cell params in cellParams rule sim.net.params.cellParams[pop_id] = cellRule # clean up before next import del swcSecs, cellMorph h.initnrn() # create population of virtual cells (VecStims so can add spike times) elif model_type == 'virtual': popTags['cellModel'] = 'VecStim' sim.net.pops[pop_id].cellModelClass = sim.PointCell
def __init__(self, _id): self._id = _id h.load_file('stdlib.hoc') h.load_file('import3d.hoc') cell = h.Import3d_Neurolucida3() cell.input('morphology/GrC2020.asc') i3d = h.Import3d_GUI(cell, 0) i3d.instantiate(self) #Soma channels self.soma[0].nseg = 1 + (2 * int(self.soma[0].L / 40)) self.soma[0].Ra = 100 self.soma[0].cm = 2 self.soma[0].insert('Leak') self.soma[0].gmax_Leak = 0.00020821612897999999 self.soma[0].e_Leak = -60 self.soma[0].insert('Kv3_4') self.soma[0].gkbar_Kv3_4 = 0.00053837153610999998 self.soma[0].insert('Kv4_3') self.soma[0].gkbar_Kv4_3 = 0.0032501728450999999 self.soma[0].ek = -88 self.soma[0].insert('Kir2_3') self.soma[0].gkbar_Kir2_3 = 0.00080747403035999997 self.soma[0].insert('GRC_CA') self.soma[0].gcabar_GRC_CA = 0.00066384354030999998 self.soma[0].insert('Kv1_1') self.soma[0].gbar_Kv1_1 = 0.0046520692281700003 self.soma[0].insert('Kv1_5') self.soma[0].gKur_Kv1_5 = 0.00106988075956 self.soma[0].insert('Kv2_2_0010') self.soma[0].gKv2_2bar_Kv2_2_0010 = 2.5949576899999998e-05 self.soma[0].insert('cdp5_CR') self.soma[0].push() self.soma[0].eca = 137.5 h.pop_section() self.whatami = "GrC_2020_mild" #DEND for i in self.dend: i.nseg = 1 + (2 * int(i.L / 40)) i.Ra = 100 i.cm = 2.5 i.insert('Leak') i.gmax_Leak = 0.00020424219215 i.e_Leak = -60 i.insert('GRC_CA') i.gcabar_GRC_CA = 0.01841833779253 i.insert('Kca1_1') i.gbar_Kca1_1 = 0.02998872868395 i.ek = -88 i.insert('Kv1_1') i.gbar_Kv1_1 = 0.00010675447184 i.insert('cdp5_CR') i.push() i.eca = 137.5 h.pop_section() #Hilock self.axon = h.Section(name='hilock', cell=self) self.axon.L = 1 self.axon.nseg = 1 self.axon.diam = 1.5 self.axon.Ra = 100 self.axon.cm = 2 self.axon.insert('Leak') self.axon.gmax_Leak = 0.00025295417368000002 self.axon.e_Leak = -60 self.axon.insert('GRC_NA_FHF') self.axon.gnabar_GRC_NA_FHF = 0.011082499796400001 self.axon.ena = 87.39 self.axon.insert('Kv3_4') self.axon.gkbar_Kv3_4 = 0.050732563882920002 self.axon.ek = -88 self.axon.insert('GRC_CA') self.axon.gcabar_GRC_CA = 0.00028797253573000002 self.axon.insert('cdp5_CR') self.axon.push() self.axon.eca = 137.5 h.pt3dadd(0.0, 5.62232, 0.0, self.axon.diam) h.pt3dadd(0.0, 6.62232, 0.0, self.axon.diam) h.pop_section() self.axon.connect(self.soma[0], 0, 0) #AIS self.ais = h.Section(name='ais', cell=self) self.ais.L = 10 self.ais.nseg = 1 self.ais.diam = 0.7 self.ais.Ra = 100 self.ais.cm = 1 self.ais.insert('GRC_NA_FHF') self.ais.gnabar_GRC_NA_FHF = 1.06883116205825 self.ais.ena = 87.39 self.ais.insert('Kv3_4') self.ais.gkbar_Kv3_4 = 0.034592458064240002 self.ais.ek = -88 self.ais.insert('Leak') self.ais.gmax_Leak = 0.00025011065810000001 self.ais.e_Leak = -60 self.ais.insert('GRC_CA') self.ais.gcabar_GRC_CA = 0.00011630629281 self.ais.insert('GRC_KM') self.ais.gkbar_GRC_KM = 0.00044764153078999998 self.ais.insert('cdp5_CR') self.ais.push() self.ais.eca = 137.5 h.pt3dadd(0.0, 6.62232, 0.0, self.ais.diam) h.pt3dadd(0.0, 16.62232, 0.0, self.ais.diam) h.pop_section() lensec = 7 secnumber_aa = int(126 / lensec) secnumber_pf = int(1000 / lensec) self.ais.connect(self.axon, 1, 0) self.HD_aa = [ h.Section(cell=self, name='aa_' + str(x)) for x in range(secnumber_aa) ] for b in self.HD_aa: b.L = lensec b.nseg = 1 b.diam = 0.3 b.Ra = 100 b.cm = 1 b.insert('GRC_NA') b.gnabar_GRC_NA = 0.029973709719629999 b.ena = 87.39 b.insert('Kv3_4') b.gkbar_Kv3_4 = 0.0046029972380800003 b.ek = -88 b.insert('Leak') b.gmax_Leak = 7.8963697590000003e-05 b.e_Leak = -60 b.insert('GRC_CA') b.gcabar_GRC_CA = 0.00059214434259999998 b.insert('cdp5_CR') b.push() b.eca = 137.5 len_initial = 16.62232 len_ending = 7 h.pt3dadd(0.0, len_initial, 0.0, b.diam) h.pt3dadd(0.0, len_initial + len_ending, 0.0, b.diam) h.pop_section() len_initial = len_initial + len_ending self.HD_pf1 = [ h.Section(cell=self, name='pf_' + str(x)) for x in range(secnumber_pf) ] for i in self.HD_pf1: i.L = lensec i.nseg = 1 i.diam = 0.15 i.Ra = 100 i.cm = 1 i.insert('GRC_NA') i.gnabar_GRC_NA = 0.01896618618573 i.ena = 87.39 i.insert('Kv3_4') i.gkbar_Kv3_4 = 0.0094015060525799998 i.ek = -88 i.insert('Leak') i.gmax_Leak = 4.1272473000000001e-07 i.e_Leak = -60 i.insert('GRC_CA') i.gcabar_GRC_CA = 0.00064742320254000001 i.insert('cdp5_CR') i.push() i.eca = 137.5 len_initial = 142.62232 len_ending = 7 h.pt3dadd(len_initial, len_initial, 0.0, i.diam) h.pt3dadd(len_initial + len_ending, len_initial, 0.0, i.diam) h.pop_section() len_initial = len_initial + len_ending self.HD_pf2 = [ h.Section(cell=self, name='pf_' + str(x)) for x in range(secnumber_pf) ] for z in self.HD_pf2: z.L = lensec z.nseg = 1 z.diam = 0.15 z.Ra = 100 z.cm = 1 z.insert('GRC_NA') z.gnabar_GRC_NA = 0.01896618618573 z.ena = 87.39 z.insert('Kv3_4') z.gkbar_Kv3_4 = 0.0094015060525799998 z.ek = -88 z.insert('Leak') z.gmax_Leak = 4.1272473000000001e-07 z.e_Leak = -60 z.insert('GRC_CA') z.gcabar_GRC_CA = 0.00064742320254000001 z.insert('cdp5_CR') z.push() z.eca = 137.5 len_initial = 142.62232 len_ending = 7 h.pt3dadd(len_initial, len_initial, 0.0, i.diam) h.pt3dadd(len_initial - len_ending, len_initial, 0.0, i.diam) h.pop_section() len_initial = len_initial - len_ending #Connections #AA for j in range(secnumber_aa - 1): l = j + 1 self.HD_aa[l].connect(self.HD_aa[j], 1, 0) #PF for i in range(secnumber_pf - 1): l = i + 1 self.HD_pf1[l].connect(self.HD_pf1[i], 1, 0) self.HD_pf2[l].connect(self.HD_pf2[i], 1, 0) self.HD_pf1[0].connect(self.HD_aa[secnumber_aa - 1], 1, 0) self.HD_pf2[0].connect(self.HD_aa[secnumber_aa - 1], 1, 0) #Axon connection to the AIS self.HD_aa[0].connect(self.ais, 1, 0) #Time and Voltage vectors self.time_vector = h.Vector() self.time_vector.record(h._ref_t) self.vm_soma = h.Vector() self.vm_soma.record(self.soma[0](0.5)._ref_v)
# sodium inactivation 'h' alpha = 0.07 * exp(-(v + 65.0) / 20.0) beta = 1.0 / (exp(-(v + 35.0) / 10.0) + 1.0) htau = 1.0 / (q10 * (alpha + beta)) hinf = alpha / (alpha + beta) # potassium activation 'n' alpha = 0.01 * vtrap(-(v + 55.0), 10.0) beta = 0.125 * exp(-(v + 65.0) / 80.0) ntau = 1.0 / (q10 * (alpha + beta)) ninf = alpha / (alpha + beta) h.load_file("import3d.hoc") cell = h.Import3d_SWC_read() cell.input("c91662.swc") i3d = h.Import3d_GUI(cell, 0) class Cell: def move(self, offset=(0, 0, 0)): ox, oy, oz = offset[0], offset[1], offset[2] h.define_shape() xlo = ylo = zlo = xhi = yhi = zhi = None for sec in self.all: sec.nseg = 1 n3d = sec.n3d() xs = [sec.x3d(i) + ox for i in range(n3d)] ys = [sec.y3d(i) + oy for i in range(n3d)] zs = [sec.z3d(i) + oz for i in range(n3d)] ds = [sec.diam3d(i) for i in range(n3d)] sec.pt3dclear()
def createPops(self): # Get info from nodes files for n in self.network_config['networks']['nodes']: nodes_file = self.subs(n['nodes_file']) node_types_file = self.subs(n['node_types_file']) print("\nLoading nodes from %s and %s"%(nodes_file, node_types_file)) h5file = tables.open_file(nodes_file,mode='r') self.parse_group(h5file.root.nodes) h5file.close() self.nodes_info[self.current_node] = load_csv_props(node_types_file) self.current_node = None pp.pprint(self.nodes_info) # Use extracted node/cell info to create populations for sonata_pop in self.cell_info: # iterate over cell types -- will make one netpyne population per cell type for type in self.cell_info[sonata_pop]['type_numbers']: info = self.nodes_info[sonata_pop][type] pop_name = info['pop_name'] if 'pop_name' in info else None ref = info['model_name'] if 'model_name' in info else info['model_type'] model_type = info['model_type'] model_template = info['model_template'] if 'model_template' in info else '- None -' if pop_name: pop_id = '%s_%s'%(sonata_pop, pop_name) else: pop_id = '%s_%s_%s'%(sonata_pop,ref,type) self.pop_id_from_type[(sonata_pop, type)] = pop_id print(" - Adding population: %s which has model info: %s"%(pop_id, info)) size = self.cell_info[sonata_pop]['type_numbers'][type] # create netpyne pop # Note: alternatively could create sim.net.params.popParams and then call sim.createPops() popTags = {} popTags['cellModel'] = model_type popTags['cellType'] = info['model_name'] if 'model_name' in info else pop_id popTags['numCells'] = size popTags['pop'] = pop_id popTags['ei'] = info['ei'] if 'ei' in info else '' sim.net.pops[pop_id] = sim.Pop(pop_id, popTags) sim.net.params.popParams[pop_id] = popTags # create population cell template (sections) from morphology and dynamics params files if model_type == 'biophysical': sim.net.pops[pop_id].cellModelClass = sim.CompartCell # morphology morphology_file = self.subs(self.network_config['components']['morphologies_dir']) +'/'+info['morphology'] + '.swc' cellMorph = EmptyCell() swcData = h.Import3d_SWC_read() swcData.input(morphology_file) swcSecs = h.Import3d_GUI(swcData, 0) swcSecs.instantiate(cellMorph) # replace axon with AIS stub if self.replaceAxon: fix_axon_peri(cellMorph) # extract netpyne parameters secs, secLists, synMechs, globs = neuronPyHoc.getCellParams(cellMorph) # remove sec vinits since imported temporary cell with morph for secName in secs: del secs[secName]['vinit'] # fix nseg based on dL if self.setdLNseg: fix_sec_nseg(secs, sim.cfg.dL) # invert y coordinates # if self.swapSomaXY: # swap_soma_xy(secs) # make soma mid segment (x,y,z) = (0,0,0) # somaLabel = next((s for s in secs.keys() if 'soma' in s), None) # somaPtFirst = secs[somaLabel]['geom']['pt3d'][0] # somaPtLast = secs[somaLabel]['geom']['pt3d'][-1] # somaPt = [(p1+p2)/2.0 for p1,p2 in zip(somaPtFirst, somaPtLast)] # for secLabel in secs: # for ipt3d in range(len(secs[secLabel]['geom']['pt3d'])): # origPt = secs[secLabel]['geom']['pt3d'][ipt3d] # offsetX = 0.0 # if 'apic' in secLabel: # offsetX = 0.0 # newpt = (origPt[0] - somaPt[0] + offsetX, origPt[1] - somaPt[1], origPt[2] - somaPt[2], origPt[3]) # secs[secLabel]['geom']['pt3d'][ipt3d] = newpt # create mapping of sec ids secLists['SONATA_sec_id'] = [sim.conversion.getSecName(sec) for sec in cellMorph.all] cellRule = {'conds': {'pop': pop_id}, 'secs': secs, 'secLists': secLists, 'globals': globs} # dynamics params if info['model_template'].startswith('nml'): dynamics_params_file = self.subs(self.network_config['components']['biophysical_neuron_models_dir']+'/'+info['model_template']) dynamics_params_file = dynamics_params_file.replace('nml:', '') #nml_doc = read_neuroml2_file(dynamics_params_file) #cell_dynamic_params = nml_doc.cells[0] cell_dynamic_params = NMLTree(dynamics_params_file) cellRule = self.setCellRuleDynamicParamsFromNeuroml(cell_dynamic_params, cellRule) elif info['dynamics_params'].endswith('json'): dynamics_params_file = self.subs(self.network_config['components']['biophysical_neuron_models_dir']+'/'+info['dynamics_params']) cell_dynamic_params = load_json(dynamics_params_file) cellRule = self.setCellRuleDynamicParamsFromJson(cell_dynamic_params, cellRule) # set extracted cell params in cellParams rule sim.net.params.cellParams[pop_id] = cellRule # clean up before next import del swcSecs, cellMorph h.initnrn() # create population of virtual cells (VecStims so can add spike times) elif model_type == 'virtual': popTags['cellModel'] = 'VecStim' sim.net.pops[pop_id].cellModelClass = sim.PointCell
def __init__(self, params=defparams, factors=None): Import = h.Import3d_SWC_read() Import.input(morphology + 'latest_WT-P270-20-14ak.swc') imprt = h.Import3d_GUI(Import, 0) imprt.instantiate(None) h.define_shape() # h.cao0_ca_ion = 2 # default in nrn h.celsius = 35 self._create_sectionlists() self._set_nsegs() self.v_init = -80 for sec in self.allseclist: sec.Ra = 150 sec.cm = 1.0 sec.insert('pas') #sec.g_pas = 1e-5 # set using json file sec.e_pas = -70 # -73 for sec in self.somalist: sec.insert('naf') sec.insert('kaf') sec.insert('kas') sec.insert('kdr') sec.insert('kir') sec.ena = 50 sec.ek = -85 # -90 sec.insert('cal12') sec.insert('cal13') sec.insert('car') sec.insert('cadyn') sec.insert('caldyn') sec.insert('sk') sec.insert('bk') sec.insert('can') #sec.kb_cadyn = 200. for sec in self.axonlist: sec.insert('naf') #sec.insert('kaf') sec.insert('kas') #sec.insert('kdr') #sec.insert('kir') sec.ena = 50 sec.ek = -85 # -90 for sec in self.dendlist: sec.insert('naf') sec.insert('kaf') sec.insert('kas') sec.insert('kdr') sec.insert('kir') sec.ena = 50 sec.ek = -85 # -90 sec.insert('cal12') sec.insert('cal13') sec.insert('car') sec.insert('cadyn') sec.insert('caldyn') sec.insert('sk') sec.insert('bk') sec.insert('cat32') sec.insert('cat33') with open(params) as file: par = json.load(file) self.distribute_channels("soma", "g_pas", 0, 1, 0, 0, 0, float(par['g_pas_all']['Value'])) self.distribute_channels("axon", "g_pas", 0, 1, 0, 0, 0, float(par['g_pas_all']['Value'])) self.distribute_channels("dend", "g_pas", 0, 1, 0, 0, 0, float(par['g_pas_all']['Value'])) self.distribute_channels("soma", "gbar_naf", 0, 1, 0, 0, 0, float(par['gbar_naf_somatic']['Value']),factors=factors) self.distribute_channels("soma", "gbar_kaf", 0, 1, 0, 0, 0, float(par['gbar_kaf_somatic']['Value'])) self.distribute_channels("soma", "gbar_kas", 0, 1, 0, 0, 0, float(par['gbar_kas_somatic']['Value'])) self.distribute_channels("soma", "gbar_kdr", 0, 1, 0, 0, 0, float(par['gbar_kdr_somatic']['Value'])) self.distribute_channels("soma", "gbar_kir", 0, 1, 0, 0, 0, float(par['gbar_kir_somatic']['Value'])) self.distribute_channels("soma", "gbar_sk", 0, 1, 0, 0, 0, float(par['gbar_sk_somatic']['Value'])) self.distribute_channels("soma", "gbar_bk", 0, 1, 0, 0, 0, float(par['gbar_bk_somatic']['Value'])) #self.distribute_channels("axon", "gbar_naf", 0, 1, 0, 0, 0, float(par['gbar_naf_somatic']['Value']),factors=factors) self.distribute_channels("axon", "gbar_naf", 3, 1, 1.1, 30, 500, float(par['gbar_naf_axonal']['Value']),factors=factors) #self.distribute_channels("axon", "gbar_naf", 3, 1, 1.1, 20, 500, float(par['gbar_naf_axonal']['Value'])) #self.distribute_channels("dend", "gbar_naf", 1, 1, 1.2, 30, -5, float(par['gbar_naf_axonal']['Value'])) self.distribute_channels("axon", "gbar_kas", 0, 1, 0, 0, 0, float(par['gbar_kas_axonal']['Value'])) self.distribute_channels("dend", "gbar_naf", 1, 0.1, 0.9, 60.0, 10.0, float(par['gbar_naf_basal']['Value']),factors=factors) self.distribute_channels("dend", "gbar_kaf", 1, 1, 0.5, 120, -30, float(par['gbar_kaf_basal']['Value'])) #self.distribute_channels("dend", "gbar_naf", 0, 1, -0.0072, 0, 0, float(par['gbar_naf_basal']['Value'])) #self.distribute_channels("dend", "gbar_kaf", 0, 1, 0.0167, 0, 0, float(par['gbar_kaf_basal']['Value'])) self.distribute_channels("dend", "gbar_kas", 2, 1, 9.0, 0.0, -5.0, float(par['gbar_kas_basal']['Value'])) self.distribute_channels("dend", "gbar_kdr", 0, 1, 0, 0, 0, float(par['gbar_kdr_basal']['Value'])) self.distribute_channels("dend", "gbar_kir", 0, 1, 0, 0, 0, float(par['gbar_kir_basal']['Value'])) self.distribute_channels("dend", "gbar_sk", 0, 1, 0, 0, 0, float(par['gbar_sk_basal']['Value'])) self.distribute_channels("dend", "gbar_bk", 0, 1, 0, 0, 0, float(par['gbar_bk_basal']['Value'])) self.distribute_channels("soma", "pbar_cal12", 0, 1, 0, 0, 0, 1e-5) self.distribute_channels("soma", "pbar_cal13", 0, 1, 0, 0, 0, 1e-6) self.distribute_channels("soma", "pbar_car", 0, 1, 0, 0, 0, 1e-4) self.distribute_channels("soma", "pbar_can", 0, 1, 0, 0, 0, 3e-5) #self.distribute_channels("soma", "kb_cadyn", 0, 1, 0, 0, 0, 200.0) self.distribute_channels("dend", "pbar_cal12", 0, 1, 0, 0, 0, 1e-5) self.distribute_channels("dend", "pbar_cal13", 0, 1, 0, 0, 0, 1e-6) self.distribute_channels("dend", "pbar_car", 0, 1, 0, 0, 0, 1e-4) self.distribute_channels("dend", "pbar_cat32", 1, 0, 1.0, 70.0, -4.5, 1e-7) self.distribute_channels("dend", "pbar_cat33", 1, 0, 1.0, 70.0, -4.5, 1e-8)
def __init__(self, params=None, \ morphology=None, \ variables=None, \ section=None ): Import = h.Import3d_SWC_read() Import.input(morphology) imprt = h.Import3d_GUI(Import, 0) imprt.instantiate(None) h.define_shape() # h.cao0_ca_ion = 2 # default in nrn h.celsius = 35 self._create_sectionlists() self._set_nsegs(section=section) self.v_init = -85 self.dendritic_channels = [ "naf", "kaf", "kas", "kdr", "kir", "cal12", "cal13", "can", "car", "cav32", "cav33", "sk", "bk" ] self.somatic_channels = [ "naf", "kaf", "kas", "kdr", "kir", "cal12", "cal13", "can", "car", "sk", "bk" ] self.axonal_channels = [ "naf", "kas" , "Im" ] # insert active mechanisms (related to channels) ------------- for sec in self.somalist: for mech in self.somatic_channels+["cadyn", "caldyn"]: sec.insert(mech) for sec in self.axonlist: for mech in self.axonal_channels: sec.insert(mech) for sec in self.dendlist: for mech in self.dendritic_channels+["cadyn", "caldyn"]: sec.insert(mech) with open(params) as file: par = json.load(file) # set passive parameters -------------------------------------------- for sec in self.allseclist: sec.Ra = 150 sec.cm = 1.0 sec.insert('pas') #sec.g_pas = 1e-5 # set using json file sec.e_pas = -70 # -73 sec.g_pas = float(par['g_pas_all']['Value']) sec.ena = 50 sec.ek = -85 # -90 self.distribute_channels("soma", "gbar_naf", 0, 1, 0, 0, 0, float(par['gbar_naf_somatic']['Value'])) self.distribute_channels("soma", "gbar_kaf", 0, 1, 0, 0, 0, float(par['gbar_kaf_somatic']['Value'])) self.distribute_channels("soma", "gbar_kas", 0, 1, 0, 0, 0, float(par['gbar_kas_somatic']['Value'])) self.distribute_channels("soma", "gbar_kdr", 0, 1, 0, 0, 0, float(par['gbar_kdr_somatic']['Value'])) self.distribute_channels("soma", "gbar_bk", 0, 1, 0, 0, 0, float(par['gbar_bk_somatic' ]['Value'])) self.distribute_channels("soma", "pbar_cal12", 0, 1, 0, 0, 0, 1.34e-5) self.distribute_channels("soma", "pbar_cal13", 0, 1, 0, 0, 0, 1.34e-6) self.distribute_channels("soma", "pbar_car", 0, 1, 0, 0, 0, 1.34e-4) self.distribute_channels("soma", "pbar_can", 0, 1, 0, 0, 0, 4e-5) self.distribute_channels("dend", "gbar_kdr", 0, 1, 0, 0, 0, float(par['gbar_kdr_basal']['Value'])) self.distribute_channels("dend", "gbar_bk", 0, 1, 0, 0, 0, float(par['gbar_bk_basal' ]['Value'])) self.distribute_channels("dend", "pbar_cal12", 0, 1, 0, 0, 0, 1e-5) self.distribute_channels("dend", "pbar_cal13", 0, 1, 0, 0, 0, 1e-6) self.distribute_channels("dend", "pbar_car", 0, 1, 0, 0, 0, 1e-4) self.distribute_channels("axon", "gbar_kas", 0, 1, 0, 0, 0, float(par['gbar_kas_axonal']['Value'])) self.distribute_channels("axon", "gbar_naf", 3, 1, 1.1, 30, 500, float(par['gbar_naf_axonal']['Value'])) self.distribute_channels("axon", "gbar_Im", 0, 1, 0, 0, 0, 1.0e-3) # in ephys step functions are not supported so something like below formula will be used instead. #self.distribute_channels("axon", "gbar_naf", 1, 1, 0.1, 30, -1, float(par['gbar_naf_axonal']['Value'])) #(1 + 0.9/(1 + math.exp(({distance}-30.0)/-1.0) )) if variables: self.distribute_channels("dend", "gbar_naf", 1, 1.0-variables['naf'][1], \ variables['naf'][1], \ variables['naf'][2], \ variables['naf'][3], \ np.power(10,variables['naf'][0])*float(par['gbar_naf_basal']['Value'])) self.distribute_channels("dend", "gbar_kaf", 1, 1.0, \ variables['kaf'][1], \ variables['kaf'][2], \ variables['kaf'][3], \ np.power(10,variables['kaf'][0])*float(par['gbar_kaf_basal']['Value'])) self.distribute_channels("dend", "gbar_kas", 1, 0.1, \ 0.9, \ variables['kas'][1], \ variables['kas'][2], \ np.power(10,variables['kas'][0])*float(par['gbar_kas_basal']['Value'])) self.distribute_channels("dend", "gbar_kir", 0, np.power(10,variables['kir'][0]), 0, 0, 0, float(par['gbar_kir_basal' ]['Value'])) self.distribute_channels("soma", "gbar_kir", 0, np.power(10,variables['kir'][0]), 0, 0, 0, float(par['gbar_kir_somatic']['Value'])) self.distribute_channels("dend", "gbar_sk", 0, np.power(10,variables['sk' ][0]), 0, 0, 0, float(par['gbar_sk_basal' ]['Value'])) self.distribute_channels("soma", "gbar_sk", 0, np.power(10,variables['sk' ][0]), 0, 0, 0, float(par['gbar_sk_somatic' ]['Value'])) self.distribute_channels("dend", "pbar_can", 1, 1.0-variables['can'][1], \ variables['can'][1], \ variables['can'][2], \ variables['can'][3], \ np.power(10,variables['can'][0])) self.distribute_channels("dend", "pbar_cav32", 1, 0, \ 1, \ variables['c32'][1], \ variables['c32'][2], \ np.power(10,variables['c32'][0])) self.distribute_channels("dend", "pbar_cav33", 1, 0, \ 1, \ variables['c33'][1], \ variables['c33'][2], \ np.power(10,variables['c33'][0])) else: self.distribute_channels("dend", "gbar_naf", 1, 0.1, 0.9, 60.0, 10.0, float(par['gbar_naf_basal']['Value'])) self.distribute_channels("dend", "gbar_kaf", 1, 1, 0.5, 120.0, -30.0, float(par['gbar_kaf_basal']['Value'])) self.distribute_channels("dend", "gbar_kas", 2, 1, 9.0, 0.0, -5.0, float(par['gbar_kas_basal']['Value'])) self.distribute_channels("dend", "gbar_kir", 0, 1, 0, 0, 0, float(par['gbar_kir_basal']['Value'])) self.distribute_channels("soma", "gbar_kir", 0, 1, 0, 0, 0, float(par['gbar_kir_somatic']['Value'])) self.distribute_channels("dend", "gbar_sk", 0, 1, 0, 0, 0, float(par['gbar_sk_basal']['Value'])) self.distribute_channels("soma", "gbar_sk", 0, 1, 0, 0, 0, float(par['gbar_sk_basal']['Value'])) self.distribute_channels("dend", "pbar_can", 0, 1, 0, 0, 0, 1e-7) self.distribute_channels("dend", "pbar_cav32", 1, 0, 1.0, 120.0, -30.0, 1e-7) self.distribute_channels("dend", "pbar_cav33", 1, 0, 1.0, 120.0, -30.0, 1e-8)
def simulate_models_IF(cells_list, models_dirs, models_path="../ActiveModels/", morphs_path="../Morphs/", save_traces=False, save_path='simulated_models_IF_Curve/', thresh=0): h.load_file("import3d.hoc") h.steps_per_ms = 25 h.dt = 1.0 / h.steps_per_ms h.tstop = 1500 h.celsius = 37 h.v_init = -86 for ix, cell in enumerate(cells_list): model = models_dirs[cell]['model'] print "simulates model", model h.load_file(models_path + model + ".hoc") h("objref HCell") h("HCell = new " + model + "()") HCell = h.HCell nl = h.Import3d_Neurolucida3() # Creating the model nl.quiet = 1 nl.input(morphs_path + models_dirs[cell]['morph']) imprt = h.Import3d_GUI(nl, 0) imprt.instantiate(HCell) HCell.indexSections(imprt) HCell.geom_nsec() HCell.geom_nseg() HCell.delete_axon() HCell.insertChannel() HCell.init_biophys() HCell.biophys() # The stimulus icl = h.IClamp(0.5, sec=HCell.soma[0]) icl.dur = 1000 icl.delay = 120.33 icl.amp = 0 # Record the voltage at the soma Vsoma = h.Vector() Vsoma.record(HCell.soma[0](.5)._ref_v) tvec = h.Vector() tvec.record(h._ref_t) HCell.soma[0].push() MODEL_IF = [] range_amps = range(0, 3000, 100) bar = progressbar.ProgressBar(max_value=len(range_amps), widgets=[ ' [', progressbar.Timer(), '] ', progressbar.Bar(), ' (', progressbar.ETA(), ') ', ]) for jx, amp1000 in enumerate(range_amps): amp = amp1000 / 1000.0 icl.amp = amp h.init(h.v_init) h.run() n = count_spikes(np.array(Vsoma), thresh) MODEL_IF.append((amp, n)) bar.update(jx) MODEL_IF = np.array(MODEL_IF) models_dirs[cell]['I'] = MODEL_IF[:, 0] models_dirs[cell]['F'] = MODEL_IF[:, 1] if save_traces: if not os.path.exists(save_path): os.mkdir(save_path) np.savetxt(save_path + model + "IF.txt", np.array(MODEL_IF))
def load(filename, fileformat=None, cell=None, use_axon=True, xshift=0, yshift=0, zshift=0): """ Load an SWC from filename and instantiate inside cell. Code kindly provided by @ramcdougal. Args: filename = .swc file containing morphology cell = Cell() object. (Default: None, creates new object) filename = the filename of the SWC file use_axon = include the axon? Default: True (yes) xshift, yshift, zshift = use to position the cell Returns: Cell() object with populated soma, axon, dend, & apic fields Minimal example: # pull the morphology for the demo from NeuroMorpho.Org from PyNeuronToolbox import neuromorphoorg with open('c91662.swc', 'w') as f: f.write(neuromorphoorg.morphology('c91662')) cell = load_swc(filename) """ if cell is None: cell = Cell(name=string.join(filename.split('.')[:-1])) if fileformat is None: fileformat = filename.split('.')[-1] name_form = {1: 'soma[%d]', 2: 'axon[%d]', 3: 'dend[%d]', 4: 'apic[%d]'} # load the data. Use Import3d_SWC_read for swc, Import3d_Neurolucida3 for # Neurolucida V3, Import3d_MorphML for MorphML (level 1 of NeuroML), or # Import3d_Eutectic_read for Eutectic. if fileformat == 'swc': morph = h.Import3d_SWC_read() elif fileformat == 'asc': morph = h.Import3d_Neurolucida3() else: raise Exception('file format `%s` not recognized' % (fileformat)) morph.input(filename) # easiest to instantiate by passing the loaded morphology to the Import3d_GUI # tool; with a second argument of 0, it won't display the GUI, but it will allow # use of the GUI's features i3d = h.Import3d_GUI(morph, 0) # get a list of the swc section objects swc_secs = i3d.swc.sections swc_secs = [swc_secs.object(i) for i in xrange(int(swc_secs.count()))] # initialize the lists of sections sec_list = {1: cell.soma, 2: cell.axon, 3: cell.dend, 4: cell.apic} # name and create the sections real_secs = {} for swc_sec in swc_secs: cell_part = int(swc_sec.type) # skip everything else if it's an axon and we're not supposed to # use it... or if is_subsidiary if (not (use_axon) and cell_part == 2) or swc_sec.is_subsidiary: continue # figure out the name of the new section if cell_part not in name_form: raise Exception('unsupported point type') name = name_form[cell_part] % len(sec_list[cell_part]) # create the section sec = h.Section(name=name) # connect to parent, if any if swc_sec.parentsec is not None: sec.connect(real_secs[swc_sec.parentsec.hname()](swc_sec.parentx)) # define shape if swc_sec.first == 1: h.pt3dstyle(1, swc_sec.raw.getval(0, 0), swc_sec.raw.getval(1, 0), swc_sec.raw.getval(2, 0), sec=sec) j = swc_sec.first xx, yy, zz = [swc_sec.raw.getrow(i).c(j) for i in xrange(3)] dd = swc_sec.d.c(j) if swc_sec.iscontour_: # never happens in SWC files, but can happen in other formats supported # by NEURON's Import3D GUI raise Exception('Unsupported section style: contour') if dd.size() == 1: # single point soma; treat as sphere x, y, z, d = [dim.x[0] for dim in [xx, yy, zz, dd]] for xprime in [x - d / 2., x, x + d / 2.]: h.pt3dadd(xprime + xshift, y + yshift, z + zshift, d, sec=sec) else: for x, y, z, d in zip(xx, yy, zz, dd): h.pt3dadd(x + xshift, y + yshift, z + zshift, d, sec=sec) # store the section in the appropriate list in the cell and lookup table sec_list[cell_part].append(sec) real_secs[swc_sec.hname()] = sec cell.all = cell.soma + cell.apic + cell.dend + cell.axon return cell
def __init__(self, params=None, \ morphology='latest_WT-P270-20-14ak.swc' ): Import = h.Import3d_SWC_read() Import.input(morphology) imprt = h.Import3d_GUI(Import, 0) imprt.instantiate(None) h.define_shape() # h.cao0_ca_ion = 2 # default in nrn h.celsius = 35 self._create_sectionlists() self._set_nsegs() self.v_init = -80 for sec in self.somalist: for mech in [ "naf", "kaf", "kas", "kdr", "kir", "cal12", "cal13", "can", "car", "cadyn", "caldyn", "sk", "bk" ]: sec.insert(mech) for sec in self.axonlist: for mech in ["naf", "kas"]: sec.insert(mech) for sec in self.dendlist: for mech in [ "naf", "kaf", "kas", "kdr", "kir", "cal12", "cal13", "car", "cat32", "cat33", "cadyn", "caldyn", "sk", "bk" ]: sec.insert(mech) for sec in self.allseclist: sec.Ra = 150 sec.cm = 1.0 sec.insert('pas') #sec.g_pas = 1e-5 # set using json file sec.e_pas = -70 # -73 sec.ena = 50 sec.ek = -85 # -90 with open(params) as file: par = json.load(file) self.distribute_channels("soma", "g_pas", 0, 1, 0, 0, 0, float(par['g_pas_all']['Value'])) self.distribute_channels("axon", "g_pas", 0, 1, 0, 0, 0, float(par['g_pas_all']['Value'])) self.distribute_channels("dend", "g_pas", 0, 1, 0, 0, 0, float(par['g_pas_all']['Value'])) self.distribute_channels("soma", "gbar_naf", 0, 1, 0, 0, 0, float(par['gbar_naf_somatic']['Value'])) self.distribute_channels("soma", "gbar_kaf", 0, 1, 0, 0, 0, float(par['gbar_kaf_somatic']['Value'])) self.distribute_channels("soma", "gbar_kas", 0, 1, 0, 0, 0, float(par['gbar_kas_somatic']['Value'])) self.distribute_channels("soma", "gbar_kdr", 0, 1, 0, 0, 0, float(par['gbar_kdr_somatic']['Value'])) self.distribute_channels("soma", "gbar_kir", 0, 1, 0, 0, 0, float(par['gbar_kir_somatic']['Value'])) self.distribute_channels("soma", "gbar_sk", 0, 1, 0, 0, 0, float(par['gbar_sk_somatic']['Value'])) self.distribute_channels("soma", "gbar_bk", 0, 1, 0, 0, 0, float(par['gbar_bk_somatic']['Value'])) self.distribute_channels("axon", "gbar_naf", 3, 1, 1.1, 30, 500, float(par['gbar_naf_axonal']['Value'])) self.distribute_channels("axon", "gbar_kas", 0, 1, 0, 0, 0, float(par['gbar_kas_axonal']['Value'])) self.distribute_channels("dend", "gbar_naf", 1, 0.1, 0.9, 60.0, 10.0, float(par['gbar_naf_basal']['Value'])) self.distribute_channels("dend", "gbar_kaf", 1, 1, 0.5, 120.0, -30.0, float(par['gbar_kaf_basal']['Value'])) self.distribute_channels("dend", "gbar_kas", 2, 1, 9.0, 0.0, -5.0, float(par['gbar_kas_basal']['Value'])) self.distribute_channels("dend", "gbar_kdr", 0, 1, 0, 0, 0, float(par['gbar_kdr_basal']['Value'])) self.distribute_channels("dend", "gbar_kir", 0, 1, 0, 0, 0, float(par['gbar_kir_basal']['Value'])) self.distribute_channels("dend", "gbar_sk", 0, 1, 0, 0, 0, float(par['gbar_sk_basal']['Value'])) self.distribute_channels("dend", "gbar_bk", 0, 1, 0, 0, 0, float(par['gbar_bk_basal']['Value'])) self.distribute_channels("soma", "pbar_cal12", 0, 1, 0, 0, 0, 1e-5) self.distribute_channels("soma", "pbar_cal13", 0, 1, 0, 0, 0, 1e-6) self.distribute_channels("soma", "pbar_car", 0, 1, 0, 0, 0, 1e-4) self.distribute_channels("soma", "pbar_can", 0, 1, 0, 0, 0, 3e-5) self.distribute_channels("dend", "pbar_cal12", 0, 1, 0, 0, 0, 1e-5) self.distribute_channels("dend", "pbar_cal13", 0, 1, 0, 0, 0, 1e-6) self.distribute_channels("dend", "pbar_car", 0, 1, 0, 0, 0, 1e-4) self.distribute_channels("dend", "pbar_cat32", 1, 0, 1.0, 120.0, -30.0, 1e-7) self.distribute_channels("dend", "pbar_cat33", 1, 0, 1.0, 120.0, -30.0, 1e-8)
PARALLEL_ENV = 1 h.load_file("import3d.hoc") h.load_file("nrngui.hoc") h("objref cell, tobj") path = "../" morph_file = path + "Morphs/2013_03_06_cell08_876_H41_05_Cell2.ASC" model_file = "cell0603_08_model_cm_0_45" model_path = path + "PassiveModels/" print os.getcwd() h.load_file(model_path + model_file + ".hoc") h.execute("cell = new " + model_file + "()") #replace? nl = h.Import3d_Neurolucida3() nl.quiet = 1 nl.input(morph_file) imprt = h.Import3d_GUI(nl, 0) imprt.instantiate(h.cell) HCell = h.cell HCell.geom_nseg() HCell.create_model() HCell.biophys() T_DATA, V_DATA = read_epsp_file(PATH_exp + expname + ".dat") h.dt = T_DATA[1] - T_DATA[0] h.steps_per_ms = 1.0 / h.dt h.tstop = T_DATA[-1] V_DATA_Neuron = h.Vector(V_DATA.size) for i, v in enumerate(V_DATA): V_DATA_Neuron.x[i] = v
def run_RTHW(WRITE_TO_FILE=1, output_filename="rise_and_width_synapses_locations.txt"): # creating the model h.load_file("import3d.hoc") h.load_file("nrngui.hoc") h("objref cell, tobj") morph_file = "../morphs/2013_03_06_cell08_876_H41_05_Cell2.ASC" model_file = "cell0603_08_model_cm_0_45" model_path = "../PassiveModels/" h.load_file(model_path + model_file + ".hoc") h.execute("cell = new " + model_file + "()") nl = h.Import3d_Neurolucida3() nl.quiet = 1 nl.input(morph_file) imprt = h.Import3d_GUI(nl, 0) imprt.instantiate(h.cell) HCell = h.cell HCell.geom_nseg() HCell.create_model() HCell.biophys() PLOT_MODE = 0 TAU_1 = 0.3 TAU_2 = 1.8 E_SYN = 0 WEIGHT = 0.0003 E_PAS = -86 Spike_time = 10 DELAY = 0 NUM_OF_SYNAPSES = 1 DT = 0.01 h.tstop = 100 h.v_init = E_PAS h.steps_per_ms = 1.0 / DT h.dt = DT if WRITE_TO_FILE: f1 = open(output_filename, 'w+') Stim1 = h.NetStim() Stim1.interval = 10000 Stim1.start = Spike_time Stim1.noise = 0 Stim1.number = 1 # for a given synapse, this function run the simulation and calculate its shape index def calc_rise_and_width(PLOT_MODE=0): Vvec = h.Vector() Vvec.record(HCell.soma[0](0.5)._ref_v) h.init(h.v_init) h.run() np_v = np.array(Vvec) max_idx = np.argmax(np_v) rise_time = max_idx * DT - Stim1.start half_v = E_PAS + (np_v[max_idx] - E_PAS) / 2.0 for i in range(max_idx): if np_v[i] > half_v: rise_half = i * h.dt break for i in range(max_idx, np_v.size): if np_v[i] < half_v: decay_half = i * h.dt break half_width = decay_half - rise_half if PLOT_MODE: print "rise ,", rise_time, " half width ", half_width np_t = np.arange(0, h.tstop + h.dt, h.dt) print np_v.size, np_t.size plt.plot(np_t, np_v, 'b') plt.plot(np_t[max_idx], np_v[max_idx], 'b*') plt.plot(np.array([rise_half, decay_half]), np.array([half_v, half_v]), 'r') plt.show() return rise_time, half_width output_txt = "secanme\tx\tsoma_distance\trise_time\thalf_width\n" h.distance(sec=HCell.soma[0]) # run over all the electrical segments in the model. # in each one of them put a synapse and run the simulation. print "re-creating the theoretical_RTHW" num_secs = len([sec for sec in HCell.all]) bar = progressbar.ProgressBar(max_value=num_secs, widgets=[ ' [', progressbar.Timer(), '] ', progressbar.Bar(), ' (', progressbar.ETA(), ') ', ]) for ix, sec in enumerate(HCell.all): for seg in list(sec) + [sec(1)]: Syn1 = h.Exp2Syn(seg.x, sec=sec) Syn1.e = E_SYN Syn1.tau1 = TAU_1 Syn1.tau2 = TAU_2 Con1 = h.NetCon(Stim1, Syn1) Con1.weight[0] = WEIGHT Con1.delay = DELAY rise_time, half_width = calc_rise_and_width() output_txt += sec.name() + '\t' + str(seg.x) + '\t' + str( h.distance(seg.x, sec=sec)) + '\t' output_txt += str(rise_time) + '\t' + str(half_width) + '\n' bar.update(ix) if WRITE_TO_FILE: f1.write(output_txt) f1.close() return output_txt.strip().split("\n")