示例#1
0
def dumbbell_geometry(major_radius=1,
                      minor_radius=0.1,
                      thickness=0.1,
                      height=1,
                      nz=2,
                      nc1=10,
                      nc2=10):
    from chimerax.surface.shapes import cylinder_geometry
    dva, dna, dta = cylinder_geometry(major_radius, thickness, nz, nc1, True)
    hva, hna, hta = cylinder_geometry(minor_radius, height, nz, nc2, False)
    nv = len(dva)
    vs = []
    ns = []
    ts = []
    offset = numpy.array([0, 0, height / 2])
    vs.append(dva - offset)
    ns.append(dna)
    ts.append(dta)
    vs.append(hva)
    ns.append(hna)
    ts.append(hta + nv)
    nv += len(hva)
    vs.append(dva + offset)
    ns.append(dna)
    ts.append(dta + nv)
    vd, nd, td = numpy.concatenate(vs), numpy.concatenate(
        ns), numpy.concatenate(ts)
    return vd, nd, td
def unit_cell_box_drawing(unit_cell_corners,
                          corner_radius=1.0,
                          origin_radius=2.0,
                          cylinder_radius=0.2):
    from chimerax.graphics import Drawing
    md = Drawing('Unit cell box')
    cd = Drawing('Corners')
    ed = Drawing('Edges')
    md.add_drawing(cd)
    md.add_drawing(ed)
    from chimerax.surface.shapes import sphere_geometry2, cylinder_geometry
    cd.set_geometry(*sphere_geometry2(80))
    ed.set_geometry(*cylinder_geometry())
    from chimerax.geometry import Places, cylinder_rotations
    import numpy
    shift_and_scale = numpy.empty((8, 4), numpy.float32)
    shift_and_scale[:, :3] = unit_cell_corners
    shift_and_scale[1:, 3] = corner_radius
    shift_and_scale[0, 3] = origin_radius
    cd.positions = Places(shift_and_scale=shift_and_scale)
    edges = [[0, 1], [0, 2], [0, 4], [1, 3], [1, 5], [2, 3], [2, 6], [3, 7],
             [4, 5], [4, 6], [5, 7], [6, 7]]
    xyz = [[], []]
    for e in edges:
        for i in range(2):
            xyz[i].append(unit_cell_corners[e[i]])
    xyz0, xyz1 = [numpy.array(x) for x in xyz]
    rot44 = numpy.empty((12, 4, 4), numpy.float32)
    cylinder_rotations(xyz0, xyz1,
                       numpy.ones(12, numpy.float32) * cylinder_radius, rot44)
    rot44[:, 3, :3] = 0.5 * (xyz0 + xyz1)
    ed.positions = Places(opengl_array=rot44)
    return md
示例#3
0
    def set_size(self, axis_length, axis_radius):
        from chimerax.surface.shapes import cylinder_geometry, cone_geometry
        vaz, naz, taz = cylinder_geometry(radius=axis_radius,
                                          height=axis_length)
        vcz, ncz, tcz = cone_geometry(radius=axis_radius * 2,
                                      height=axis_length * 0.2,
                                      caps=True)
        from chimerax.geometry import Place
        vct = Place(origin=(0, 0, axis_length / 2))
        vcz = vct.transform_points(vcz)
        nv = len(vaz)
        tcz = tcz + nv
        from numpy import concatenate
        vaz = concatenate((vaz, vcz))
        naz = concatenate((naz, ncz))
        taz = concatenate((taz, tcz))
        nv = len(vaz)
        tx = Place(axes=[[0, 0, 1], [0, -1, 0], [1, 0, 0]])
        vax, nax, tax = tx.transform_points(vaz), tx.transform_vectors(
            naz), taz.copy() + nv
        ty = Place(axes=[[1, 0, 0], [0, 0, -1], [0, 1, 0]])
        vay, nay, tay = ty.transform_points(vaz), ty.transform_vectors(
            naz), taz.copy() + 2 * nv

        vc = self.vertex_colors
        self.set_geometry(concatenate((vax, vay, vaz)),
                          concatenate((nax, nay, naz)),
                          concatenate((tax, tay, taz)))
        self.vertex_colors = vc  # Setting geometry clears vertex colors
示例#4
0
def pin_geometry(handle_radius, pin_radius, total_height):
    '''
    Simple 3D representation of a drawing pin.
    Args:
        handle_radius:
            The radius of the "handle" in Angstroms
        pin_radius:
            The radius of the "pin" in Angstroms
        height:
            The overall height of the drawing
    '''
    import numpy
    from chimerax.surface.shapes import cylinder_geometry, cone_geometry
    from chimerax.geometry import translation
    pin_height = total_height * 5 / 12
    handle_height = total_height * 7 / 12
    tb_height = total_height / 4

    pin = list(
        cone_geometry(radius=pin_radius, height=pin_height, points_up=False))
    handle_bottom = list(
        cone_geometry(radius=handle_radius, height=tb_height, nc=8))
    handle_middle = list(
        cylinder_geometry(radius=handle_radius / 2,
                          height=handle_height,
                          nc=8,
                          caps=False))
    handle_top = list(
        cone_geometry(radius=handle_radius,
                      height=tb_height,
                      nc=8,
                      points_up=False))

    pint = translation((0, 0, pin_height / 2))
    pin[0] = pint.transform_points(pin[0])
    hbt = translation((0, 0, pin_height + tb_height / 2.05))
    handle_bottom[0] = hbt.transform_points(handle_bottom[0])
    hmt = translation((0, 0, handle_height / 2 + pin_height))
    handle_middle[0] = hmt.transform_points(handle_middle[0])
    htt = translation((0, 0, total_height - tb_height / 2.05))
    handle_top[0] = htt.transform_points(handle_top[0])

    vertices = numpy.concatenate(
        (pin[0], handle_bottom[0], handle_middle[0], handle_top[0]))
    normals = numpy.concatenate(
        (pin[1], handle_bottom[1], handle_middle[1], handle_top[1]))

    ntri = len(pin[0])
    triangles = pin[2]
    for d in (handle_bottom, handle_middle, handle_top):
        triangles = numpy.concatenate((triangles, d[2] + ntri))
        ntri += len(d[0])

    return vertices, normals, triangles
示例#5
0
def post_geometry(radius, height, caps=False):
    '''
    Returns a simple cylinder, rotated and translated so its base is on
    the origin and it points along (1,0,0)
    '''
    from chimerax.surface.shapes import cylinder_geometry
    from chimerax.geometry import rotation, translation
    v, n, t = cylinder_geometry(radius=radius, height=height, caps=caps, nc=6)
    tr = translation([0, 0, height / 2])
    tr.transform_points(v, in_place=True)
    r = rotation([0, 1, 0], 90)
    r.transform_points(v, in_place=True)
    r.transform_vectors(n, in_place=True)
    return v, n, t
def _drawing_geometry(fold_symmetry):
    from chimerax.surface.shapes import cylinder_geometry
    return cylinder_geometry()
示例#7
0
 def _cb_annotation(self):
     from chimerax.surface.shapes import cylinder_geometry
     v, n, t = cylinder_geometry(radius=0.1, height=2, nc=8, caps=True)
     d = Drawing('rotamer cb indicator')
     d.set_geometry(v, n, t)
     return d