Ejemplo n.º 1
0
def color_op(surfaces, color=None):

    from Commands import parse_surfaces, parse_color
    surfs = parse_surfaces(surfaces)

    if color == 'byatom':
        from chimera import MSMSModel
        if [s for s in surfs if not isinstance(s, MSMSModel)]:
            raise CommandError, 'Cannot color byatom non-molecular surfaces'
    elif not color is None:
        color = parse_color(color)

    for surf in surfs:
        import SurfaceColor as sc
        sc.stop_coloring_surface(surf)
        if color == 'byatom':
            surf.colorMode = surf.ByAtom
        elif not color is None:
            import Surface
            Surface.set_coloring_method('static', surf)
            from chimera import MSMSModel
            if isinstance(surf, MSMSModel):
                surf.customRGBA = [color] * surf.vertexCount
            else:
                for p in surf.surfacePieces:
                    p.color = color
Ejemplo n.º 2
0
def gradient_op(surfaces,
                gradient=None,
                cmap='redblue',
                cmapRange=None,
                reverseColors=False,
                colorOutsideVolume='gray',
                offset=0,
                autoUpdate=True,
                capOnly=False):

    from Commands import parse_surfaces, single_volume
    from Commands import parse_color, parse_colormap
    surfs = parse_surfaces(surfaces)
    gradient = single_volume(gradient)
    if colorOutsideVolume:
        colorOutsideVolume = parse_color(colorOutsideVolume)
    cmap, cmapRange = parse_colormap(cmap, cmapRange, reverseColors)
    offset = parse_offset(offset)

    import SurfaceColor as sc
    for surf in surfs:
        cs = sc.Gradient_Color()
        cs.set_volume(gradient)
        cs.offset = offset
        cm = colormap(cs, cmap, cmapRange, capOnly, surf, colorOutsideVolume)
        cs.set_colormap(cm)
        sc.color_surface(surf, cs, capOnly, autoUpdate)
Ejemplo n.º 3
0
def volume_op(surfaces,
              volume=None,
              cmap='redblue',
              cmapRange=None,
              reverseColors=False,
              colorOutsideVolume='gray',
              offset=0,
              autoUpdate=True,
              capOnly=False,
              perPixel=False):

    from Commands import parse_surfaces, single_volume
    from Commands import parse_color, parse_colormap
    surfs = parse_surfaces(surfaces)
    volume = single_volume(volume)
    if colorOutsideVolume:
        colorOutsideVolume = parse_color(colorOutsideVolume)
    cmap, cmapRange = parse_colormap(cmap, cmapRange, reverseColors)
    offset = parse_offset(offset)

    import SurfaceColor as sc
    for surf in surfs:
        cs = sc.Volume_Color()
        cs.set_volume(volume)
        cs.offset = offset
        cm = colormap(cs, cmap, cmapRange, capOnly, surf, colorOutsideVolume)
        cs.set_colormap(cm)
        cs.per_pixel_coloring = perPixel
        sc.color_surface(surf, cs, capOnly, autoUpdate)
Ejemplo n.º 4
0
def color_op(surfaces, color = None):

    from Commands import parse_surfaces, parse_color
    surfs = parse_surfaces(surfaces)

    if color == 'byatom':
        from chimera import MSMSModel
        if [s for s in surfs if not isinstance(s, MSMSModel)]:
            raise CommandError, 'Cannot color byatom non-molecular surfaces'
    elif not color is None:
        color = parse_color(color)

    for surf in surfs:
        import SurfaceColor as sc
        sc.stop_coloring_surface(surf)
        if color == 'byatom':
            surf.colorMode = surf.ByAtom
        elif not color is None:
            import Surface
            Surface.set_coloring_method('static', surf)
            from chimera import MSMSModel
            if isinstance(surf, MSMSModel):
                surf.customRGBA = [color] * surf.vertexCount
            else:
                for p in surf.surfacePieces:
                    p.color = color
Ejemplo n.º 5
0
def inertia(operation, objects, showEllipsoid = True, color = None,
            perChain = False):

    from chimera import specifier
    try:
        sel = specifier.evalSpec(objects)
    except:
        raise CommandError, 'Bad object specifier "%s"' % objects

    if not color is None:
        from Commands import parse_color
        color = parse_color(color)

    atoms = sel.atoms()
    if atoms:
        import inertia
        if perChain:
            xf = atoms[0].molecule.openState.xform
            mname = molecules_name(list(set([a.molecule for a in atoms])))
            s = inertia.surface_model(None, xf, 'ellipsoids ' + mname)
            for achain in atoms_by_chain(atoms):
                p = inertia.atoms_inertia_ellipsoid(achain, showEllipsoid,
                                                    color, s)
                if p:
                    p.oslName = achain[0].residue.id.chainId
        else:
            inertia.atoms_inertia_ellipsoid(atoms, showEllipsoid, color)

    import Surface
    plist = Surface.selected_surface_pieces(sel, include_outline_boxes = False)
    if plist:
        import inertia
        inertia.surface_inertia_ellipsoid(plist, showEllipsoid, color)
Ejemplo n.º 6
0
def spine(operation,
          regions,
          spacing=None,
          tipLength=None,
          color=None,
          showDiameter=False):

    sel = parse_object_specifier(regions, 'segmentation region')

    import Surface
    plist = Surface.selected_surface_pieces(sel, include_outline_boxes=False)
    from Segger.regions import Segmentation
    rlist = [
        p.region for p in plist
        if (hasattr(p, 'region') and isinstance(p.model, Segmentation))
    ]
    if len(rlist) == 0:
        raise CommandError('No segmentation regions specified: "%s"' % regions)

    if not (spacing is None or isinstance(spacing,
                                          (int, float)) and spacing > 0):
        raise CommandError('spacing must be positive numeric value')
    if not (tipLength is None or isinstance(tipLength,
                                            (int, float)) and tipLength > 0):
        raise CommandError('tipLength must be positive numeric value')

    if not color is None:
        from Commands import parse_color
        color = parse_color(color)

    if showDiameter:
        from _surface import SurfaceModel
        diam_model = SurfaceModel()
        diam_model.name = 'Diameters'
        from chimera import openModels
        openModels.add([diam_model], sameAs=rlist[0].segmentation)
    else:
        diam_model = None

    import spine
    from chimera import replyobj
    from PathLength import path_length
    for r in rlist:
        mset = spine.trace_spine(r, spacing, tipLength, color)
        slen = path_length([l.bond for l in mset.links()])
        r.set_attribute('spine length', slen)
        msg = 'Spine length for region %d is %.4g' % (r.rid, slen)
        dmax, dmin = spine.measure_diameter(r, mset, diam_model)
        if not dmax is None:
            r.set_attribute('diameter1', dmax)
            r.set_attribute('diameter2', dmin)
            msg += ', diameters %.4g, %.4g' % (dmax, dmin)
        kave, kmin, kmax = spine.measure_curvature(mset)
        if not kmax is None:
            r.set_attribute('curvature average', kave)
            r.set_attribute('curvature minimum', kmin)
            r.set_attribute('curvature maximum', kmax)
            msg += ', curvature %.4g (ave), %.4g (max), %.4g (min)' % (
                kave, kmax, kmin)
        replyobj.info(msg + '\n')
Ejemplo n.º 7
0
def distance(operation,
             object1,
             object2,
             multiple=False,
             show=False,
             color=(0, 1, 1, 1)):

    a1 = object1.atoms()
    import Surface as s
    s1 = s.selected_surface_pieces(object1, include_outline_boxes=False)

    if len(a1) == 0 and len(s1) == 0:
        raise CommandError('No atoms or surfaces specified')

    a2 = object2.atoms()
    s2 = s.selected_surface_pieces(object2, include_outline_boxes=False)

    if len(a2) == 0 and len(s2) == 0:
        raise CommandError('No target atoms or surfaces')

    # Remove near stuff.
    if a1:
        a2 = list(set(a2).difference(a1))
    if s1:
        s2 = list(set(s2).difference(s1))

    name2 = object_name(a2, s2)
    xyz2 = point_array(a2, s2)

    if show:
        from Commands import parse_color
        color = parse_color(color)
        from _surface import SurfaceModel
        surf = SurfaceModel()
        surf.name = 'Distance measurement'
        from chimera import openModels
        openModels.add([surf])
    else:
        surf = None

    if multiple:
        pairs = [([a], []) for a in a1] + [([], [s]) for s in s1]
    else:
        pairs = [(a1, s1)]

    for a, s in pairs:
        name = object_name(a, s)
        xyz = point_array(a, s)
        report_distance(xyz, xyz2, name, name2, surf, color)
Ejemplo n.º 8
0
def contact_area(operation,
                 surf1,
                 surf2,
                 distance,
                 show=True,
                 color=(1, 0, 0, 1),
                 offset=1,
                 slab=None,
                 smooth=False,
                 optimize=True):

    plist = []
    import Surface
    for spec in (surf1, surf2):
        s = parse_object_specifier(spec, 'surface')
        p = Surface.selected_surface_pieces(s, include_outline_boxes=False)
        if len(p) == 0:
            raise CommandError('%s has no surface pieces' % spec)
        elif len(p) > 1:
            raise CommandError('%s has %d surface pieces, require 1' %
                               (spec, len(p)))
        plist.append(p[0])
    p1, p2 = plist

    from Commands import parse_color
    color = parse_color(color)
    if not show:
        color = None

    from Commands import check_number
    check_number(offset, 'offset')

    if not slab is None:
        if isinstance(slab, (float, int)):
            slab = (-0.5 * slab, 0.5 * slab)
        else:
            from Commands import parse_floats
            slab = parse_floats(slab, 'slab', 2)
        offset = None

    import contactarea as c
    area = c.contact_area(p1, p2, distance, color, offset, slab, smooth,
                          optimize)

    from chimera import replyobj
    replyobj.info('Contact area on %s within distance %.4g\nof %s = %.4g\n' %
                  (p1.model.name, distance, p2.model.name, area))
    replyobj.status('Contact area = %.4g' % area)
Ejemplo n.º 9
0
def gradient_op(surfaces, gradient = None, cmap = 'redblue', cmapRange = None,
                reverseColors = False, colorOutsideVolume = 'gray', offset = 0,
                autoUpdate = True, capOnly = False):

    from Commands import parse_surfaces, single_volume
    from Commands import parse_color, parse_colormap
    surfs = parse_surfaces(surfaces)
    gradient = single_volume(gradient)
    if colorOutsideVolume:
        colorOutsideVolume = parse_color(colorOutsideVolume)
    cmap, cmapRange = parse_colormap(cmap, cmapRange, reverseColors)
    offset = parse_offset(offset)
    
    import SurfaceColor as sc
    for surf in surfs:
        cs = sc.Gradient_Color()
        cs.set_volume(gradient)
        cs.offset = offset
        cm = colormap(cs, cmap, cmapRange, capOnly, surf, colorOutsideVolume)
        cs.set_colormap(cm)
        sc.color_surface(surf, cs, capOnly, autoUpdate)
Ejemplo n.º 10
0
def volume_op(surfaces, volume = None, cmap = 'redblue', cmapRange = None,
              reverseColors = False, colorOutsideVolume = 'gray', offset = 0,
              autoUpdate = True, capOnly = False, perPixel = False):

    from Commands import parse_surfaces, single_volume
    from Commands import parse_color, parse_colormap
    surfs = parse_surfaces(surfaces)
    volume = single_volume(volume)
    if colorOutsideVolume:
        colorOutsideVolume = parse_color(colorOutsideVolume)
    cmap, cmapRange = parse_colormap(cmap, cmapRange, reverseColors)
    offset = parse_offset(offset)

    import SurfaceColor as sc
    for surf in surfs:
        cs = sc.Volume_Color()
        cs.set_volume(volume)
        cs.offset = offset
        cm = colormap(cs, cmap, cmapRange, capOnly, surf, colorOutsideVolume)
        cs.set_colormap(cm)
        cs.per_pixel_coloring = perPixel
        sc.color_surface(surf, cs, capOnly, autoUpdate)
def inertia(operation,
            objects,
            showEllipsoid=True,
            color=None,
            perChain=False):

    from chimera import specifier
    try:
        sel = specifier.evalSpec(objects)
    except:
        raise CommandError, 'Bad object specifier "%s"' % objects

    if not color is None:
        from Commands import parse_color
        color = parse_color(color)

    atoms = sel.atoms()
    if atoms:
        import inertia
        if perChain:
            xf = atoms[0].molecule.openState.xform
            mname = molecules_name(list(set([a.molecule for a in atoms])))
            s = inertia.surface_model(None, xf, 'ellipsoids ' + mname)
            for achain in atoms_by_chain(atoms):
                p = inertia.atoms_inertia_ellipsoid(achain, showEllipsoid,
                                                    color, s)
                if p:
                    p.oslName = achain[0].residue.id.chainId
        else:
            inertia.atoms_inertia_ellipsoid(atoms, showEllipsoid, color)

    import Surface
    plist = Surface.selected_surface_pieces(sel, include_outline_boxes=False)
    if plist:
        import inertia
        inertia.surface_inertia_ellipsoid(plist, showEllipsoid, color)