def optimize_nseg(self): """ Set up nseg """ # Set up sectionList - easy to modify properties self.all = h.SectionList() self.all_no_axon = h.SectionList() self.all.append(sec=self.soma) self.all_no_axon.append(sec=self.soma) for section in self.basal: self.all.append(sec=section) for section in self.apical: self.all.append(sec=section) self.all_no_axon.append(sec=section) self.basals = h.SectionList() self.axons = h.SectionList() for section in self.axon: self.axons.append(sec=section) self.all.append(sec=section) for section in self.basal: self.basals.append(sec=section) #self.basals.remove(sec = self.basal[16]) for section in self.basals: self.all_no_axon.append(sec=section) for sec in self.all: # Set up Ra and cm first, since the nseg calculation depends on the value of Ra and cm sec.Ra = global_Ra sec.cm = 1
def setup_pcmorphology(kk, x, y, z): print 'i value is:', kk cellpc = Purkinje() h.define_shape() sections = h.SectionList() sections.wholetree(cellpc.soma) cellpc.soma.push() n = h.n3d(sec=cellpc.soma) xs = [h.x3d(i) for i in range(int(n))] ys = [h.y3d(i) for i in range(int(n))] zs = [h.z3d(i) for i in range(int(n))] ds = [h.diam3d(i) for i in range(int(n))] j = 0 #sec.push() for a, b, c, d in zip(xs, ys, zs, ds): #print 'sec here is:', sec h.pt3dchange(j, a + x, b + y, c + z, d) j += 1 h.define_shape() h.pop_section() pulist.append(cellpc) #call another function to locate the local granule neurons cellpc.soma.push() getpurksecs = h.SectionList() getpurksecs.wholetree(cellpc.soma) func_local_grcneurons(kk, getpurksecs)
def _create_sectionlists(self, replace_axon=False): # soma self.nsomasec = 0 self.somalist = h.SectionList() for sec in h.allsec(): if sec.name().find('soma') >= 0: self.somalist.append(sec=sec) if self.nsomasec == 0: self.soma = sec self.nsomasec += 1 # dendrite self.dendlist = h.SectionList() for sec in h.allsec(): if sec.name().find('dend') >= 0: self.dendlist.append(sec=sec) # axon self.axonlist = h.SectionList() if replace_axon: self._create_AIS() else: axon=[] for sec in h.allsec(): if sec.name().find('axon') >= 0: self.axonlist.append(sec=sec) # all self.allsecnames = [] self.allseclist = h.SectionList() for sec in h.allsec(): self.allsecnames.append(sec.name()) self.allseclist.append(sec=sec)
def __init__(self, secs=None, geos=None): self._secs = {} self._default = None if not secs: if isinstance(geos, list): self._default = geos[0] elif isinstance(geos, RxDGeometry): self._default = geos else: raise RxDException( "MultipleGeometry requires a list-of-lists of sections and their corresponding geometry" ) else: assert len(secs) == len(geos) if all([g.is_area() for g in geos]): self.is_area = _always_true self.is_volume = _always_false elif all([g.is_volume() for g in geos]): self.is_area = _always_false self.is_volume = _always_true else: raise RxDException( "MultipleGeometry requires all geometries are areas or all geometries are volumes" ) for s, g in zip(secs, geos): if not s: self._default = g elif isinstance(s, list): self._secs[h.SectionList(s)] = g else: self._secs[h.SectionList([s])] = g
def __init__(self, regions): global _c_region_lookup self._regions = [weakref.ref(r) for r in regions] self._overlap = h.SectionList(self._regions[0]()._secs1d) self.num_regions = len(self._regions) self.num_species = 0 self.num_params = 0 self.num_ecs_species = 0 self.num_ecs_params = 0 self._ecs_react_species = list() self._ecs_react_params = list() self._react_species = list() self._react_params = list() self._react_regions = dict() self._initialized = False self.location_index = None self.ecs_location_index = None self._ecs_species_ids = None self._ecs_params_ids = None self._voltage_dependent = False self._vptrs = None for rptr in self._regions: r = rptr() self._overlap = h.SectionList([sec for sec in r._secs1d if sec in self._overlap]) if r in _c_region_lookup: _c_region_lookup[rptr].append(self) else: _c_region_lookup[rptr] = [self]
def optimize_nseg(self): self.all = h.SectionList() self.prox = h.SectionList() self.mid = h.SectionList() self.dist = h.SectionList() self.all_no_axon = h.SectionList() for section in self.soma: self.all.append(sec=section) self.all_no_axon.append(sec=section) for section in self.proximal: self.all.append(sec=section) self.all_no_axon.append(sec=section) self.prox.append(sec=section) for section in self.middend: self.all.append(sec=section) self.all_no_axon.append(sec=section) self.mid.append(sec=section) for section in self.distal: self.all.append(sec=section) self.all_no_axon.append(sec=section) self.dist.append(sec=section) for section in self.axon: self.all.append(sec=section) for section in self.myelin: self.all.append(sec=section) for sec in self.all: sec.Ra = 100 sec.cm = 0.900001 for sec in self.myelin: sec.cm = 0.01800002
def splitmitral(mgid, cell, piecelist): ''' split a mitral cell into secondary dendrites and the soma/priden/axon and destroy pieces not on this cpu and connect pieces with multisplit. Note that -1 is the piece that includes the soma. Also note that secondary dendrites have branches and the piecelist is for the indices of secondary dentrites that connect to the soma. The {mgid:cell} is added to mgid2piece so the assumption is that piecelist is not empty. ''' isecden = secden_indices_connected_to_soma(cell) #disconnect all secden and destroy what is not supposed to exist for i in isecden: s = cell.secden[i] h.disconnect(sec=s) if i not in piecelist: subtree = h.SectionList() subtree.wholetree(sec=s) for ss in subtree: h.delete_section(sec=ss) rest = h.SectionList() rest.wholetree(sec=cell.soma) if -1 not in piecelist: for s in rest: h.delete_section(sec=s) #multisplit connect using mgid for i in piecelist: if i == -1: pc.multisplit(0.5, mgid, sec=cell.soma) else: pc.multisplit(0.0, mgid, sec=cell.secden[i]) # add to piece dictionary model.mgid2piece.update({mgid: cell})
def build_subsets(self): self.all = h.SectionList() self.all.wholetree(sec=self.soma) self.adend = h.SectionList() self.adend.append(self.bcdend1[0]) self.adend.append(self.bcdend2[0]) self.adend.append(self.bcdend3[0]) self.adend.append(self.bcdend4[0]) self.bdend = h.SectionList() self.bdend.append(self.bcdend1[1]) self.bdend.append(self.bcdend2[1]) self.bdend.append(self.bcdend3[1]) self.bdend.append(self.bcdend4[1]) self.cdend = h.SectionList() self.cdend.append(self.bcdend1[2]) self.cdend.append(self.bcdend2[2]) self.cdend.append(self.bcdend3[2]) self.cdend.append(self.bcdend4[2]) self.ddend = h.SectionList() self.ddend.append(self.bcdend1[3]) self.ddend.append(self.bcdend2[3]) self.ddend.append(self.bcdend3[3]) self.ddend.append(self.bcdend4[3])
def mkallsecs (): """ mkallsecs - make the global allsecs variable, containing all the NEURON sections. """ global allsecs allsecs=h.SectionList() # no .clear() command roots=h.SectionList() roots.allroots() for s in roots: s.push() allsecs.wholetree() return allsecs
def _sort_secs(secs): # sort the sections root_secs = h.SectionList() root_secs.allroots() all_sorted = h.SectionList() for root in root_secs: all_sorted.wholetree(sec=root) secs_names = dict([(sec.hoc_internal_name(),sec) for sec in secs]) for sec in secs: if sec.orientation(): raise RxDException('still need to deal with backwards sections') return [secs_names[sec.hoc_internal_name()] for sec in all_sorted if sec.hoc_internal_name() in secs_names]
def _sort_secs(secs): # sort the sections root_secs = h.SectionList() root_secs.allroots() all_sorted = h.SectionList() for root in root_secs: all_sorted.wholetree(sec=root) secs_names = {sec.name(): sec for sec in secs} for sec in secs: if h.section_orientation(sec=sec): raise Exception('still need to deal with backwards sections') return [ secs_names[sec.name()] for sec in all_sorted if sec.name() in secs_names ]
def build_subsets(self): ''' adds sections in NEURON SectionList ''' self.all = h.SectionList() for sec in h.allsec(): self.all.append(sec=sec)
def root_sections(h): """ Returns a list of all sections that have no parent. """ roots = h.SectionList() roots.allroots() return list(roots)
def __init__(self, index, i, j, k, r, d, seg, speciesref, data_type=_concentration_node): """ Parameters ---------- index : int the offset into the global rxd data i : int the x coordinate in the region's matrix j : int the y coordinate in the region's matrix k : int the z coordinate in the region's matrix r : rxd.Region the region that contains this node seg : nrn.Segment the segment containing this node """ self._index = index self._i = i self._j = j self._k = k self._neighbors = None # TODO: store region as a weakref! (weakref.proxy?) self._r = r self._sec = h.SectionList([seg.sec]) self._x = seg.x self._speciesref = speciesref self._data_type = data_type _point_indices.setdefault(self._r, {}) _point_indices[self._r][(self._i,self._j,self._k)] = self._index
def build_subsets(self): self.all = h.SectionList() self.all.wholetree(sec=self.soma) self.pdend = h.SectionList() self.pdend.append(self.hcdend1[0]) self.pdend.append(self.hcdend2[0]) self.pdend.append(self.hcdend3[0]) self.pdend.append(self.hcdend4[0]) self.ddend = h.SectionList() for r in range(1,3): self.ddend.append(self.hcdend1[r]) self.ddend.append(self.hcdend2[r]) self.ddend.append(self.hcdend3[r]) self.ddend.append(self.hcdend4[r])
def __init__(self, pts, master=True): self.master = master diam = p.cell_diameter self.pts = pts self.sections = {} self.sl = h.SectionList() for pt in pts: gid = org2gid(*pt) sec = h.Section(name=str(gid)) sec.pt3dclear() #draw the line a little shorter so we can see the junctions p1 = xyz(*pt) p2 = xyz(pt[0], pt[1], pt[2] + 1) dp = (p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]) x, y, z = p1[0] + .05 * dp[0], p1[1] + .05 * dp[1], p1[ 2] + .05 * dp[2] sec.pt3dadd(x, y, z, diam - 1) x, y, z = p2[0] - .05 * dp[0], p2[1] - .05 * dp[1], p2[ 2] - .05 * dp[2] sec.pt3dadd(x, y, z, diam - 1) self.sections[sec] = gid self.sl.append(sec=sec) self.sh = h.Shape(self.sl) self.sh.menu_tool("print info", self.callback) if not master: for sec in self.sections: self.sh.color(gid2org(self.sections[sec])[0] + 1, sec=sec)
def _create_sectionlists(self): '''Create section lists for different kinds of sections''' #list with all sections self.allsecnames = [] self.allseclist = h.SectionList() for sec in h.allsec(): if sec.name().find('Mn_') >= 0: self.allsecnames.append(sec.name()) self.allseclist.append(sec=sec) #list of soma sections, assuming it is named on the format "soma*" self.nsomasec = 0 self.somalist = h.SectionList() for sec in h.allsec(): if sec.name().find('Mn_soma') >= 0: self.somalist.append(sec=sec) self.nsomasec += 1
def optimize_nseg(self): self.all = h.SectionList() for section in self.soma: self.all.append(sec=section) for sec in self.all: sec.Ra = 100 sec.cm = 1
def build_subsets(self): ''' adds sections in NEURON SectionList ''' self.all = h.SectionList() for sec in self.stimsec: self.all.append(sec=sec) self.all.append(sec=self.branch)
def make_section_lists(): apic_trunk = nrn.SectionList() basal = nrn.SectionList() apic_tuft = nrn.SectionList() #oblique_dendrites = nrn.SectionList() for sec in nrn.allsec(): sec_type = sec.name().split('[')[0] sec_idx = int(sec.name().split('[')[1][:-1]) if sec_type == 'dend': basal.append(sec) elif sec_type == 'apic' and sec_idx > 0: apic_tuft.append(sec) elif sec_type == 'apic' and sec_idx == 0: apic_trunk.append(sec) return apic_trunk, basal, apic_tuft
def dipole_insert(self, yscale): # insert dipole into each section of this cell # dends must have already been created!! # it's easier to use wholetree here, this includes soma seclist = h.SectionList() seclist.wholetree(sec=self.soma) # create a python section list list_all self.list_all = [sec for sec in seclist] for sect in self.list_all: sect.insert('dipole') # Dipole is defined in dipole_pp.mod self.dipole_pp = [h.Dipole(1, sec=sect) for sect in self.list_all] # setting pointers and ztan values for sect, dpp in zip(self.list_all, self.dipole_pp): # assign internal resistance values to dipole point process (dpp) dpp.ri = h.ri(1, sec=sect) # sets pointers in dipole mod file to the correct locations # h.setpointer(ref, ptr, obj) h.setpointer(sect(0.99)._ref_v, 'pv', dpp) if self.celltype.startswith('L2'): h.setpointer(h._ref_dp_total_L2, 'Qtotal', dpp) elif self.celltype.startswith('L5'): h.setpointer(h._ref_dp_total_L5, 'Qtotal', dpp) # gives INTERNAL segments of the section, non-endpoints # creating this because need multiple values simultaneously loc = np.array([seg.x for seg in sect]) # these are the positions, including 0 but not L pos = np.array([seg.x for seg in sect.allseg()]) # diff in yvals, scaled against the pos np.array. y_long as in longitudinal y_scale = (yscale[sect.name()] * sect.L) * pos # y_long = (h.y3d(1, sec=sect) - h.y3d(0, sec=sect)) * pos # diff values calculate length between successive section points y_diff = np.diff(y_scale) # y_diff = np.diff(y_long) # doing range to index multiple values of the same np.array simultaneously for i in range(len(loc)): # assign the ri value to the dipole sect(loc[i]).dipole.ri = h.ri(loc[i], sec=sect) # range variable 'dipole' # set pointers to previous segment's voltage, with boundary condition if i: h.setpointer( sect(loc[i - 1])._ref_v, 'pv', sect(loc[i]).dipole) else: h.setpointer(sect(0)._ref_v, 'pv', sect(loc[i]).dipole) # set aggregate pointers h.setpointer(dpp._ref_Qsum, 'Qsum', sect(loc[i]).dipole) if self.celltype.startswith('L2'): h.setpointer(h._ref_dp_total_L2, 'Qtotal', sect(loc[i]).dipole) elif self.celltype.startswith('L5'): h.setpointer(h._ref_dp_total_L5, 'Qtotal', sect(loc[i]).dipole) # add ztan values sect(loc[i]).dipole.ztan = y_diff[i] # set the pp dipole's ztan value to the last value from y_diff dpp.ztan = y_diff[-1]
def __init__(self): self.soma = soma = h.Section(name='soma', cell=self) self.dend = dend = h.Section(name='dend', cell=self) self.dend.connect(self.soma(1), 0) self.section_names = ["soma", "dend"] self.all = h.SectionList() self.init_section_list() self.init_soma() self.init_dend()
def insert_dipole(self, yscale): """Insert dipole into each section of this cell. Parameters ---------- yscale : dict Dictionary of length scales to calculate dipole without 3d shape. """ self.dpl_vec = h.Vector(1) self.dpl_ref = self.dpl_vec._ref_x[0] # dends must have already been created!! # it's easier to use wholetree here, this includes soma sec_list = h.SectionList() sec_list.wholetree(sec=self.soma) sec_list = [sec for sec in sec_list] for sect in sec_list: sect.insert('dipole') # Dipole is defined in dipole_pp.mod self.dipole_pp = [h.Dipole(1, sec=sect) for sect in sec_list] # setting pointers and ztan values for sect, dpp in zip(sec_list, self.dipole_pp): dpp.ri = h.ri(1, sec=sect) # assign internal resistance # sets pointers in dipole mod file to the correct locations dpp._ref_pv = sect(0.99)._ref_v dpp._ref_Qtotal = self.dpl_ref # gives INTERNAL segments of the section, non-endpoints # creating this because need multiple values simultaneously pos_all = np.array([seg.x for seg in sect.allseg()]) # diff in yvals, scaled against the pos np.array. y_long as # in longitudinal sect_name = sect.name().split('_', 1)[1] y_scale = (yscale[sect_name] * sect.L) * pos_all # y_long = (h.y3d(1, sec=sect) - h.y3d(0, sec=sect)) * pos # diff values calculate length between successive section points y_diff = np.diff(y_scale) # y_diff = np.diff(y_long) # doing range to index multiple values of the same # np.array simultaneously for idx, pos in enumerate(pos_all[1:-1]): # assign the ri value to the dipole # ri not defined at 0 and L sect(pos).dipole.ri = h.ri(pos, sec=sect) # range variable 'dipole' # set pointers to previous segment's voltage, with # boundary condition sect(pos).dipole._ref_pv = sect(pos_all[idx])._ref_v # set aggregate pointers sect(pos).dipole._ref_Qsum = dpp._ref_Qsum sect(pos).dipole._ref_Qtotal = self.dpl_ref # add ztan values sect(pos).dipole.ztan = y_diff[idx] # set the pp dipole's ztan value to the last value from y_diff dpp.ztan = y_diff[-1] self.dipole = h.Vector().record(self.dpl_ref)
def __init__( self, secs=None, nrn_region=None, geometry=None, dimension=None, dx=None, name=None, ): """ In NEURON 7.4+, secs is optional at initial region declaration, but it must be specified before the reaction-diffusion model is instantiated. .. note:: dimension and dx will be deprecated in a future version """ self._allow_setting = True if hasattr(secs, "__len__"): self._secs = secs else: self._secs = [secs] if secs == [] or secs is None: warnings.warn( "Warning: No sections. Region 'secs' should be a list of NEURON sections." ) from nrn import Section for sec in self._secs: if not isinstance(sec, Section): raise RxDException( "Error: Region 'secs' must be a list of NEURON sections, %r is not a valid NEURON section." % sec ) self._secs = h.SectionList(self._secs) self.nrn_region = nrn_region self.geometry = geometry if dimension is not None: warnings.warn( "dimension argument was a development feature only; use set_solve_type instead... the current version sets all the sections to your requested dimension, but this will override any previous settings" ) import neuron neuron.rxd.set_solve_type(secs, dimension=dimension) self._name = name if dx is not None: try: dx = float(dx) except: dx = -1 if dx <= 0: raise RxDException("dx must be a positive real number or None") self.dx = dx _all_regions.append(weakref.ref(self)) # initialize self if the rest of rxd is already initialized if initializer.is_initialized(): self._do_init()
def __init__(self): self.x, self.y, self.z = 0, 0, 0 self.synlist = [] self.all = h.SectionList() self.create_sections() self.build_topology() self.build_subsets() self.define_geometry() self.define_biophysics() self.create_synapses()
def build_subsets(self): self.all = h.SectionList() self.all.wholetree(sec=self.soma) self.gcldend = h.SectionList() self.gcldend.append(self.gcdend1[0]) self.gcldend.append(self.gcdend2[0]) self.pdend = h.SectionList() self.pdend.append(self.gcdend1[1]) self.pdend.append(self.gcdend2[1]) self.mdend = h.SectionList() self.mdend.append(self.gcdend1[2]) self.mdend.append(self.gcdend2[2]) self.ddend = h.SectionList() self.ddend.append(self.gcdend1[3]) self.ddend.append(self.gcdend2[3])
def _sort_secs(secs): # sort the sections root_secs = h.SectionList() root_secs.allroots() all_sorted = h.SectionList() for root in root_secs: all_sorted.wholetree(sec=root) secs_names = dict([(sec.hoc_internal_name(), sec) for sec in secs]) #for sec in secs: # if sec.orientation(): # raise RxDException('still need to deal with backwards sections') secs = [ secs_names[sec.hoc_internal_name()] for sec in all_sorted if sec.hoc_internal_name() in secs_names ] # return an empty list rather than an empty SectionList because # bool([]) == False # bool(h.SectionList([])) == True # secs are checked in some reactions to determine active regions return [] if secs == [] else h.SectionList(secs)
def get_roots(self): self.roots = h.SectionList() self.roots.allroots() self.roots = list(self.roots) self.update_section_index() return [{ "index": i, "name": sec.name() } for i, sec in enumerate(self.roots)]
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_sectionlists(self): self.allsecnames = [] self.allseclist = h.SectionList() for sec in h.allsec(): self.allsecnames.append(sec.name()) self.allseclist.append(sec=sec) self.nsomasec = 0 self.somalist = h.SectionList() for sec in h.allsec(): if sec.name().find('soma') >= 0: self.somalist.append(sec=sec) if self.nsomasec == 0: self.soma = sec self.nsomasec += 1 self.axonlist = h.SectionList() for sec in h.allsec(): if sec.name().find('axon') >= 0: self.axonlist.append(sec=sec) self.dendlist = h.SectionList() for sec in h.allsec(): if sec.name().find('dend') >= 0: self.dendlist.append(sec=sec)