def locate_and_create(pair, positions): """ For a pair of cables and a set of resistor positions, locate, create and connect those resistors to the cables """ # Pair indices i, j = pair # Get resistors' lengths rl = get_rl(pair, positions) # Iterate over resistors positions for zr, l in zip(positions, rl): # For each cable, see where this falls # On cable i: i_sec, z_on_i = anatomy.locate(ws.seclens[i], zr) seci = ws.sections[i][i_sec] sgi = seci(z_on_i) # On cable j: j_sec, z_on_j = anatomy.locate(ws.seclens[j], zr) secj = ws.sections[j][j_sec] sgj = secj(z_on_j) # Value of the resistor (MOhm) ephres = res / l # Create the resistor create_eph(ephres, sgi, sgj, seci, secj, i, j, zr)
def locate_pads_on_nerve(self): """ Find the locations in the nerve corresponding to the pads """ # Iterate over the ring's pads self.contact_points = [] for i_pad in range(self.npads): # The pad's angular position determines which cable cell(s) # is (are) stimulated # Select which of the targets is in contact # with a pad 'i_pad' according to its angular position angdiff = np.abs(ws.contour_angles - self.thts[i_pad]) which_cables = np.where(angdiff == angdiff.min())[0] # Iterate over possible cables ncables_here = len(which_cables) for i_cable in which_cables: # For cable_cell i, see where this is try: i_sec, zpos = anatomy.locate(ws.seclens[i_cable], self.z) except TypeError: msg = 'ERROR: A ring of an electrode could not be placed on the nerve' ws.log(msg) ws.terminate() # Add the point point = {'cable': i_cable, 'section': i_sec, 'z': zpos} try: self.contact_points[i_pad].append(point) except IndexError: self.contact_points.append([point])
def __init__(self, name, index=0): PointElectrode.__init__(self, name, index) settings = self.settings try: self.xyz = settings['point'] except KeyError: self.xyz = settings['points'][self.index] self.x, self.y, self.z = self.xyz # Find the cable this corresponds to dists = geo.dist((self.x, self.y), (ws.nvt.x, ws.nvt.y)) these = np.where(dists == dists.min())[0] # print('Points:', these) # Choose only one cable cable_i = these[0] # print('Cable:', ws.nvt.cables[cable_i]) # Locate the section and segment (z value) of the cable j_sec, z_on_j = anatomy.locate(ws.seclens[cable_i], self.z) # print('Section and segment:', j_sec, z_on_j) # Cable and point of the cable to work on self.point = {'cable': cable_i, 'section': j_sec, 'z': z_on_j} self.set_stim_info()
def set_stimulation(self): """ Connect grounds """ # Go straigth to connect the wanted points to ground for (x, y, z) in ws.electrodes_settings[self.name]["points"]: # Find the cable this corresponds to dists = geo.dist((x, y), (ws.nvt.x, ws.nvt.y)) these = np.where(dists == dists.min())[0] # print('Points:', these) # Choose only one cable cable_i = these[0] # print('Cable:', ws.nvt.cables[cable_i]) # Locate the section and segment (z value) of the cable j_sec, z_on_j = anatomy.locate(ws.seclens[cable_i], z) # Cable and point of the cable to work on point = {'cable': cable_i, 'section': j_sec, 'z': z_on_j} # Ground it ground_segment(point)
def connect_resistors(self): """ Connect the transverse resistors with ephapses in NEURON """ def locate_and_create(pair, positions): """ For a pair of cables and a set of resistor positions, locate, create and connect those resistors to the cables """ # Pair indices i, j = pair # Get resistors' lengths rl = get_rl(pair, positions) # Iterate over resistors positions for zr, l in zip(positions, rl): # For each cable, see where this falls # On cable i: i_sec, z_on_i = anatomy.locate(ws.seclens[i], zr) seci = ws.sections[i][i_sec] sgi = seci(z_on_i) # On cable j: j_sec, z_on_j = anatomy.locate(ws.seclens[j], zr) secj = ws.sections[j][j_sec] sgj = secj(z_on_j) # Value of the resistor (MOhm) ephres = res / l # Create the resistor create_eph(ephres, sgi, sgj, seci, secj, i, j, zr) # ws.log("Created a transverse resistor at z = %f um with value %f MOhm"%(zr, ephres)) ws.eph_counter = 0 ws.nrn_res = {} for pair, res in self.resistors.items(): i, j = pair # Cable cable_cell_i = ws.cables_hoc[i] cable_cell_j = ws.cables_hoc[j] # I have to connect the cables in a staggered manner # If I am only taking the nodes of Ranvier into account # and the connection is to be set between two axons: if ws.EC["resistor network"][ "transverse resistor locations"] == "regular": # Separation between transverse resistors sep = float(ws.EC["resistor network"]["resistors separation"]) # Positions of the resistors # res_positions = np.arange(0, ws.length, sep) res_positions = np.arange(0.5, ws.length, sep) # Create and connect the resistors locate_and_create(pair, res_positions) elif ws.EC["resistor network"]["transverse resistor locations"] == "only nodes of Ranvier" and \ ('xon' in ws.cables[i].cabletype and 'xon' in ws.cables[j].cabletype): # Get resistors' positions and lengths (um) # Merge the ws.zprofs_RN of the two axons # This array will contain the postions of the resistors # over the z-axis zp_pair = np.append(ws.zprofs_RN[i], ws.zprofs_RN[j]) zp_pair.sort() # Remove repeated values (can --will, actually, happen if # there's aligned nodes) zp_pair = np.unique(zp_pair) # Create and connect the resistors locate_and_create(pair, zp_pair) else: # If I am taking all nodes into account, the compartments of only one # of the two cables (arbitrarily chosen; cable 'i' by default) # are plugged to transverse resistors. These are then connected # to the second cable wherever they must, regardless of the # topology of this second cable. # Get resistors' lengths (um) # From what is explained above, in this case the z-profile of one # of the cables only is used as zp_pair rl = get_rl(pair, ws.zprofs[i]) # Iterate over segments for ii, sgi in enumerate(ws.segments[i]): # Get the section and segment of cable j which sgi lies against zi = ws.zprofs[i][ii] j_sec, z_ioverj = anatomy.locate(ws.seclens[j], zi) seci = sgi.sec secj = ws.sections[j][j_sec] sgj = secj(z_ioverj) # Value of the resistor (MOhm) ephres = res / rl[ii] # Create the resistor create_eph(ephres, sgi, sgj, seci, secj, i, j, zi)