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 mkcells(gidinfo): timeit() for gid in gidinfo: x, y, z = gidinfo[gid] cell = h.Cell() gidinfo[gid] = CellInfo(cell) # cell shape is actually an arc and area is fastidious with respect # to all 6 sides. But length # treated as line distance between org points (interior corners # in circumferential direction. Set diam so area is correct including # end areas. cell.soma.pt3dclear() cell.soma.pt3dadd(x, y, z, 1.) ilayer, icircle, ipt = gid2org(gid) x1, y1, z1 = xyz(ilayer, icircle, ipt + 1) cell.soma.pt3dadd(x1, y1, z1, 1.) length = cell.soma.L area = sum(mkgap.cell_side_areas(gid)) diam = area / pi / length cell.soma.diam = diam assert (isclose(cell.soma(.5).area(), area, abs_tol=area * 1e-5)) cell.position(x, y, z) pc.set_gid2node(gid, rank) nc = cell.connect2target(None) pc.cell(gid, nc) x = pc.allreduce(len(gidinfo), 1) pr("Global number of real cells is %d" % x) timeit("mkcells")
def showpurk(): # only for nhost=1 global g g = h.Graph() g.size(0, npts[0][-1], 0, ncircle[0]) for gid, ci in gidinfo.items(): if ci.is_purk: ilayer, icircle, ipt = gid2org(gid) g.mark(ipt, icircle, "S", 10)
def movie(r, g1, g2): tt = 0.0 c = 1. for t, gid in r: x, y, z = xyz(*gid2org(gid)) if t > tt: time.sleep(0.1) tt += 1.0 c = 1 + tt / 10. #if int(tt)%50 == 0: g2.erase(); g1.erase() g1.mark(x, z, "S", 10, c, 1) g2.mark(y, z, "S", 10, c, 1)
def pras_(ras): global tt p = [] tt = 0.0 #segregate into groups of duration dtt for t, gid in ras: ilayer, icircle, ipt = gid2org(gid) if ilayer == 0: while t >= tt: tt += dtt pp = [] p.append(pp) pp.append((t, (ipt, icircle))) return p
def callback(self, type, x, y, keystate): #info about nearest section to mouse if type == 2: s = self.sh d = s.nearest(x, y) arc = s.push_selected() if arc >= 0: s.select() sec = h.cas() gid = self.sections[sec] ilayer, icircle, ipt = gid2org(gid) x, y, z = xyz(ilayer, icircle, ipt) print( "gid %d id (%d, %d, %d) prox pt at (%g, %g, %g) length %g" % (gid, ilayer, icircle, ipt, x, y, z, sec.L)) h.pop_section() if self.master: neighborhood(ilayer, icircle, ipt)
def cellconread(): timeit() # new Heart-3D paraboloid organization global ncon, ncell, connections import cellorg, mkgap from cellorg import sim_layers, sim_circles ncell = cellorg.ngid #old way iterating over all possible cells takes 5.4 seconds for gid in range(rank, ncell, nhost): ilayer, icircle, ipt = cellorg.gid2org(gid) if icircle < cellorg.ncircle[ilayer] - 1: if cellorg.is_simulated(ilayer, icircle, ipt): xyz = cellorg.xyz(ilayer, icircle, ipt) gidinfo[gid] = xyz ''' #new way iterating only over cells that exist takes import param as p for ilayer in sim_layers: for icircle in sim_circles[ilayer]: i0 = cellorg.angle2ipt(p.simulation_angledeg[0]*2*pi/360, ilayer, icircle) i1 = cellorg.angle2ipt(p.simulation_angledeg[1]*2*pi/360, ilayer, icircle) for ipt in range(i0, i1+1): if cellorg.is_simulated(ilayer, icircle, ipt): gid = cellorg.org2gid(ilayer, icircle, ipt) if gid%nhost == rank: gidinfo[gid] = cellorg.xyz(ilayer, icircle, ipt) ''' timeit("gidinfo setup") for gid in gidinfo: # because of floating round-off error which may or may not create # a gap with area close to 0, guarantee gap pairs by only creating # gaps where gid1 < gid2 mkgap.gaps_for_gid(gid) n = int(pc.allreduce(n_triang_zero(), 1)) pr("accurate_triang_area calculation returned zero %d times" % n) timeit("connections determined") # for parallel, copy gid2 gaps to ranks that need them mkgap.gaps_gid2_copy() connections = mkgap.gaps
def cell_side_areas(gid): o = gid2org(gid) ilayer, icircle, ipt = o assert (icircle < ncircle[ilayer] - 1) pinfo = paraboloid[ilayer][icircle] rf = pinfo[2] # RegionFace a = ipt2angle(1, ilayer, icircle) #circum coordinate, end to end area = area_circum(ilayer, icircle) side_areas = [area, area] # between layers if icircle < ncircle[ilayer] - 1: pinfo1 = paraboloid[ilayer][icircle + 1] for jlayer in [ilayer - 1, ilayer + 1]: area = 0. #jcircle, b = rf.p0b if jlayer < ilayer else rf.p1b p0, plast, pb = (pinfo[0], pinfo1[0], rf.p0b) if jlayer < ilayer else (pinfo[1], pinfo1[1], rf.p1b) jcircle, b = pb if pb else (0, []) for p1 in b + [plast]: area += side_area(p0, p1, a) p0 = p1 side_areas.append(area) # between circles in same layer jlayer = ilayer for jcircle in [icircle - 1, icircle + 1]: pinfo1 = paraboloid[ilayer][jcircle] if jcircle > icircle else None p0, p1 = (pinfo[0], pinfo[1]) if jcircle < icircle else (pinfo1[0], pinfo1[1]) area = side_area(p0, p1, a) side_areas.append(area) return side_areas
def gaps_for_gid(gid): if not gid_is_simulated(gid): return None o = gid2org(gid) ilayer, icircle, ipt = o pinfo = paraboloid[ilayer][icircle] rf = pinfo[2] # RegionFace a = ipt2angle(1, ilayer, icircle) afirst = a * ipt alast = a * (ipt + 1) gs = [] #circum coordinate, end to end if icircle < ncircle[ilayer] - 1: npt = npts[ilayer][icircle] area = area_circum(ilayer, icircle) for jpt in [ipt - 1, ipt + 1]: g2 = org2gid(ilayer, icircle, jpt) if g2 > gid: #dens_ipt = ipt if jpt < ipt else jpt%npts[ilayer][icircle] #g = conductance_density_circum(ilayer, icircle, dens_ipt) if gid_is_simulated(g2): gs.append(set_gap(gid, g2, area)) #abscond(area, g))) # between layers if icircle < ncircle[ilayer] - 1: pinfo1 = paraboloid[ilayer][icircle + 1] for jlayer in [ilayer - 1, ilayer + 1]: if jlayer >= 0 and jlayer < nlayer: # usually 2, sometimes 1, and rarely 3, circles in jlayer overlap icircle # n = int(param.layer_thickness/param.cell_diameter) n = 1 #jcircle, b = rf.p0b if jlayer < ilayer else rf.p1b p0, plast, (jcircle, b) = (pinfo[0], pinfo1[0], rf.p0b) if jlayer < ilayer else (pinfo[1], pinfo1[1], rf.p1b) for p1 in b + [plast]: jpt, angles = angle_overlap(o, jlayer, jcircle) a0 = afirst for a1 in angles + [alast]: area = side_area(p0, p1, a1 - a0) if area > 1e-9: # ignore very small areas g2 = org2gid(jlayer, jcircle, jpt) if g2 > gid: #dens_layer, dens_circle, dens_ipt = (ilayer, icircle, ipt) if jlayer < ilayer else (jlayer, jcircle, jpt) #g = conductance_density_layer(dens_layer, dens_circle, dens_ipt) if gid_is_simulated( g2) and jcircle < ncircle[jlayer] - 1: gs.append(set_gap( gid, g2, area)) #abscond(area, g))) jpt += 1 a0 = a1 jcircle += 1 p0 = p1 # between circles in same layer jlayer = ilayer for jcircle in [icircle - 1, icircle + 1]: if jcircle >= 0 and jcircle < ncircle[jlayer]: # how many cells between icircle and jcircle d = distance(xyz(ilayer, icircle, 0), xyz(jlayer, jcircle, 0)) n = int(d / param.cell_diameter) jpt, angles = angle_overlap(o, jlayer, jcircle) a0 = afirst pinfo1 = paraboloid[ilayer][jcircle] p0, p1, dens_circle, dens_ipt = (pinfo[0], pinfo[1], icircle, ipt) if jcircle < icircle else ( pinfo1[0], pinfo1[1], jcircle, jpt) for a1 in angles + [alast]: area = side_area(p0, p1, a1 - a0) if area > 1e-9: g2 = org2gid(jlayer, jcircle, jpt) if g2 > gid: #dens_circle, dens_ipt = (icircle, ipt) if jcircle < icircle else (jcircle, jpt) #g = conductance_density_parabola(ilayer, dens_circle, dens_ipt) if gid_is_simulated( g2) and jcircle < ncircle[jlayer] - 1: gs.append(set_gap(gid, g2, area)) #abscond(area, g))) jpt += 1 a0 = a1 return gs