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 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 _insert_dipole(self, sec_name_apical): """Insert dipole into each section of this cell. Parameters ---------- sec_name_apical : str The name of the section along which dipole moment is calculated. """ self.dpl_vec = h.Vector(1) self.dpl_ref = self.dpl_vec._ref_x[0] cos_thetas = _get_cos_theta(self.sections, 'apical_trunk') # setting pointers and ztan values for sect_name in self.sections: sect = self._nrn_sections[sect_name] sect.insert('dipole') dpp = h.Dipole(1, sec=sect) # defined in dipole_pp.mod self.dipole_pp.append(dpp) 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()]) seg_lens = np.diff(pos_all) * sect.L seg_lens_z = seg_lens * cos_thetas[sect_name] # alternative procedure below with y_long(itudinal) # y_long = (h.y3d(1, sec=sect) - h.y3d(0, sec=sect)) * pos # 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 = seg_lens_z[idx] # set the pp dipole's ztan value to the last value from seg_lens_z dpp.ztan = seg_lens_z[-1] self.dipole = h.Vector().record(self.dpl_ref)