示例#1
0
 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)
示例#2
0
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")
示例#3
0
def write_morphfile(outlayer, morphfile):
  mf = open(morphfile, "w")
  for icircle in range(cellorg.ncircle[outlayer]):
    for ipt in range(cellorg.npts[outlayer][icircle]):
      x,y,z = xyz(outlayer, icircle, ipt)
      gid = cellorg.org2gid(outlayer, icircle, ipt)
      assert (gid not in gid2orgmap)
      gid2orgmap[gid] = (outlayer, icircle, ipt)
      mf.write("%d %g %g %g\n"%(gid, x, y, z))
  mf.close()
示例#4
0
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)
示例#5
0
def neighborhood(ilayer, icircle, ipt):
    global focusedview
    x, y, z = xyz(ilayer, icircle, ipt)
    gid = org2gid(ilayer, icircle, ipt)
    angle = ipt2angle(ipt, ilayer, icircle)
    pts = []
    for jlayer in range(nlayer):
        for jcircle in range(max([icircle - 5, 0]),
                             min([icircle + 1 + 5, ncircle[jlayer]])):
            npt = npts[jlayer][jcircle]
            n = min([int(npts[jlayer][jcircle] / 2), 5])
            kpt = angle2ipt(angle, jlayer, jcircle)
            for jpt in [i % npt for i in range(kpt - n, kpt + 1 + n)]:
                pts.append((jlayer, jcircle, jpt))
    focusedview = View(pts, master=False)
示例#6
0
def cellcorners(ilayer, icircle, ipt):
    c = Corners()
    o0 = paraboloid[ilayer][icircle]
    o1 = paraboloid[ilayer][icircle + 1]
    a0 = ipt2angle(ipt, ilayer, icircle)
    a1 = ipt2angle(ipt + 1, ilayer, icircle)

    c.p000 = xyz(o0[0], a0)
    c.p001 = xyz(o0[0], a1)
    c.p100 = xyz(o0[1], a0)
    c.p101 = xyz(o0[1], a1)

    c.p010 = xyz(o1[0], a0)
    c.p011 = xyz(o1[0], a1)
    c.p110 = xyz(o1[1], a0)
    c.p111 = xyz(o1[1], a1)

    return c
示例#7
0
 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)
示例#8
0
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
示例#9
0
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