Beispiel #1
0
def scale_op(volumes,
             shift=0,
             factor=1,
             type=None,
             subregion='all',
             step=1,
             modelId=None):

    volumes = filter_volumes(volumes)
    check_number(shift, 'shift')
    check_number(factor, 'factor')
    if not type is None:
        import numpy as n
        types = {
            'int8': n.int8,
            'uint8': n.uint8,
            'int16': n.int16,
            'uint16': n.uint16,
            'int32': n.int32,
            'uint32': n.uint32,
            'float32': n.float32,
            'float64': n.float64,
        }
        if type in types:
            type = types[type]
        else:
            raise CommandError, ('Unknown data value type "%s", use %s' %
                                 (type, ', '.join(types.keys())))
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from scale import scaled_volume
    for v in volumes:
        scaled_volume(v, factor, shift, type, step, subregion, modelId)
Beispiel #2
0
def add_op(volumes,
           onGrid=None,
           boundingGrid=None,
           subregion='all',
           step=1,
           gridSubregion='all',
           gridStep=1,
           inPlace=False,
           scaleFactors=None,
           modelId=None):

    volumes = filter_volumes(volumes)
    if boundingGrid is None and not inPlace:
        boundingGrid = (onGrid is None)
    if onGrid is None:
        onGrid = volumes[:1]
    onGrid = filter_volumes(onGrid, 'onGrid')
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    gridSubregion = parse_subregion(gridSubregion, 'gridSubregion')
    gridStep = parse_step(gridStep, 'gridStep')
    if inPlace:
        if boundingGrid or gridStep != 1 or gridSubregion != 'all':
            raise CommandError, "Can't use inPlace option with boundingGrid or gridStep or gridSubregion options"
        for gv in onGrid:
            if not gv.data.writable:
                raise CommandError, "Can't modify volume in place: %s" % gv.name
            if not gv in volumes:
                raise CommandError, "Can't change grid in place"
    if isinstance(scaleFactors, basestring):
        scaleFactors = parse_floats(scaleFactors, 'scaleFactors', len(volumes))
    modelId = parse_model_id(modelId)
    for gv in onGrid:
        add_operation(volumes, subregion, step, gv, gridSubregion, gridStep,
                      boundingGrid, inPlace, scaleFactors, modelId)
def morph_op(volumes, frames = 25, start = 0, playStep = 0.04,
             playDirection = 1, playRange = None, addMode = False,
             constantVolume = False, scaleFactors = None,
             hideOriginalMaps = True, subregion = 'all', step = 1,
             modelId = None):

    volumes = filter_volumes(volumes)
    check_number(frames, 'frames', int, nonnegative = True)
    check_number(start, 'start')
    check_number(playStep, 'playStep', nonnegative = True)
    if playRange is None:
        if addMode:
            prange = (-1.0,1.0)
        else:
            prange = (0.0,1.0)
    else:
        prange = parse_floats(playRange, 'playRange', 2)
    check_number(playDirection, 'playDirection')
    sfactors = parse_floats(scaleFactors, 'scaleFactors', len(volumes))
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)
    vs = [tuple(v.matrix_size(step = step, subregion = subregion))
          for v in volumes]
    if len(set(vs)) > 1:
        sizes = ' and '.join([str(s) for s in vs])
        raise CommandError, "Volume grid sizes don't match: %s" % sizes
    from MorphMap import morph_maps
    morph_maps(volumes, frames, start, playStep, playDirection, prange,
               addMode, constantVolume, sfactors,
               hideOriginalMaps, subregion, step, modelId)
def subdivide_op(surfaces, spacing = None, inPlace = False, modelId = None):

    from Commands import parse_surface_pieces, check_number, parse_model_id
    plist = parse_surface_pieces(surfaces)
    if len(plist) == 0:
        raise CommandError, 'No surfaces specified'
    if spacing is None:
        raise CommandError, 'Must specify mesh spacing'
    check_number(spacing, 'spacing', positive = True)
    model_id = parse_model_id(modelId)
    if inPlace:
        s = None
    else:
        from _surface import SurfaceModel
        s = SurfaceModel()
        s.name = 'finer mesh'
        from chimera import openModels as om
        if model_id:
            id, subid = model_id
        else:
            id, subid = om.Default, om.Default
        om.add([s], baseId = id, subid = subid)
        s.openState.xform = plist[0].model.openState.xform
    from subdivide import subdivide
    for p in plist:
        np = subdivide(p, spacing, s)
        if np != p:
            np.save_in_session = True
Beispiel #5
0
def tube_shape(atoms, radius = 1.0, bandLength = 0.0, followBonds = False,
               divisions = 15, segmentSubdivisions = 10,
               color = (.745,.745,.745,1), mesh = None, linewidth = 1,
               modelName = 'tube', modelId = None):

    if len(atoms) == 0:
        raise CommandError, 'No atoms specified'
    check_number(radius, 'radius', nonnegative = True)
    check_number(bandLength, 'bandLength', nonnegative = True)
    check_number(divisions, 'divisions', positive = True)
    check_number(divisions, 'segmentSubdivisions', positive = True)
    check_number(linewidth, 'linewidth', nonnegative = True)
    from Commands import parse_rgba
    rgba = parse_rgba(color)
    model_id = parse_model_id(modelId)

    s = find_surface_model(model_id)
    from VolumePath import tube
    s,plist = tube.tube_through_atoms(atoms, radius, bandLength,
                                      segmentSubdivisions, divisions,
                                      followBonds, rgba, s, model_id)
    for p in plist:
        if mesh:
            p.displayStyle = p.Mesh
        p.lineThickness = linewidth
        p.save_in_session = True
    if s:
        s.name = modelName
def scale_op(volumes, shift = 0, factor = 1, type = None,
              subregion = 'all', step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    check_number(shift, 'shift')
    check_number(factor, 'factor')
    if not type is None:
        import numpy as n
        types = {'int8': n.int8,
                 'uint8': n.uint8,
                 'int16': n.int16,
                 'uint16': n.uint16,
                 'int32': n.int32,
                 'uint32': n.uint32,
                 'float32': n.float32,
                 'float64': n.float64,
                 }
        if type in types:
            type = types[type]
        else:
            raise CommandError, ('Unknown data value type "%s", use %s'
                                 % (type, ', '.join(types.keys())))
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from scale import scaled_volume
    for v in volumes:
        scaled_volume(v, factor, shift, type, step, subregion, modelId)
def cover_op(volumes, atomBox = None, pad = 5.0, 
             box = None, x = None, y = None, z = None,
             fBox = None, fx = None, fy = None, fz = None,
             iBox = None, ix = None, iy = None, iz = None,
             step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    check_number(pad, 'pad')

    if not atomBox is None and len(atomBox) == 0:
        raise CommandError, 'No atoms specified'
    box = parse_box(box, x, y, z, 'box', 'x', 'y', 'z')
    fBox = parse_box(fBox, fx, fy, fz, 'fBox', 'fx', 'fy', 'fz')
    iBox = parse_box(iBox, ix, iy, iz, 'iBox', 'ix', 'iy', 'iz')
    bc = len([b for b in (box, fBox, iBox, atomBox) if b])
    if bc == 0:
        raise CommandError, 'Must specify box to cover'
    if bc > 1:
        raise CommandError, 'Specify covering box in one way'

    step = parse_step(step, require_3_tuple = True)
    modelId = parse_model_id(modelId)

    from VolumeViewer import volume, volume_from_grid_data
    for v in volumes:
        g = v.grid_data(subregion = 'all', step = step, mask_zone = False)
        ijk_min, ijk_max = cover_box_bounds(v, step,
                                            atomBox, pad, box, fBox, iBox)
        cg = volume.map_from_periodic_map(g, ijk_min, ijk_max)
        cv = volume_from_grid_data(cg, model_id = modelId)
        cv.copy_settings_from(v, copy_region = False)
        cv.show()
Beispiel #8
0
def sphere_shape(radius = 10.0, center = None, rotation = None,
                 qrotation = None, coordinateSystem = None,
                 divisions = 72,
                 color = (.745,.745,.745,1), mesh = False, linewidth = 1,
                 slab = None, modelName = None, modelId = None):

    try:
        r = parse_floats(radius, 'radius', 3)
    except CommandError:
        check_number(radius, 'radius', nonnegative = True)
        r = (radius, radius, radius)
    check_number(divisions, 'divisions', positive = True)
    check_number(linewidth, 'linewidth', nonnegative = True)
    model_id = parse_model_id(modelId)

    varray, tarray = icosahedral_geometry(1.0, divisions, sphere_factor = 1)
    for a in range(3):
        varray[:,a] *= r[a]
    edge_mask = None

    if modelName is None:
        modelName = 'sphere' if r[1] == r[0] and r[2] == r[0] else 'ellipsoid'

    show_surface(varray, tarray, edge_mask, color, mesh, linewidth,
                 center, rotation, qrotation, coordinateSystem,
                 slab, model_id, modelName)
def cylinder_shape(radius=10.0,
                   height=40.0,
                   center=None,
                   rotation=None,
                   qrotation=None,
                   coordinateSystem=None,
                   divisions=72,
                   color=(.745, .745, .745, 1),
                   mesh=False,
                   linewidth=1,
                   caps=False,
                   slab=None,
                   modelName='cylinder',
                   modelId=None):

    check_number(radius, 'radius', nonnegative=True)
    check_number(height, 'height', nonnegative=True)
    check_number(divisions, 'divisions', positive=True)
    check_number(linewidth, 'linewidth', nonnegative=True)
    model_id = parse_model_id(modelId)

    nz, nc = cylinder_divisions(radius, height, divisions)
    varray, tarray = cylinder_geometry(radius, height, nz, nc, caps)
    edge_mask = None

    show_surface(varray, tarray, edge_mask, color, mesh, linewidth, center,
                 rotation, qrotation, coordinateSystem, slab, model_id,
                 modelName)
def tube_shape(atoms,
               radius=1.0,
               bandLength=0.0,
               followBonds=False,
               divisions=15,
               segmentSubdivisions=10,
               color=(.745, .745, .745, 1),
               mesh=None,
               linewidth=1,
               modelName='tube',
               modelId=None):

    if len(atoms) == 0:
        raise CommandError, 'No atoms specified'
    check_number(radius, 'radius', nonnegative=True)
    check_number(bandLength, 'bandLength', nonnegative=True)
    check_number(divisions, 'divisions', positive=True)
    check_number(divisions, 'segmentSubdivisions', positive=True)
    check_number(linewidth, 'linewidth', nonnegative=True)
    from Commands import parse_rgba
    rgba = parse_rgba(color)
    model_id = parse_model_id(modelId)

    s = find_surface_model(model_id)
    from VolumePath import tube
    s, plist = tube.tube_through_atoms(atoms, radius, bandLength,
                                       segmentSubdivisions, divisions,
                                       followBonds, rgba, s, model_id)
    for p in plist:
        if mesh:
            p.displayStyle = p.Mesh
        p.lineThickness = linewidth
        p.save_in_session = True
    if s:
        s.name = modelName
def sphere_shape(radius=10.0,
                 center=None,
                 rotation=None,
                 qrotation=None,
                 coordinateSystem=None,
                 divisions=72,
                 color=(.745, .745, .745, 1),
                 mesh=False,
                 linewidth=1,
                 slab=None,
                 modelName=None,
                 modelId=None):

    try:
        r = parse_floats(radius, 'radius', 3)
    except CommandError:
        check_number(radius, 'radius', nonnegative=True)
        r = (radius, radius, radius)
    check_number(divisions, 'divisions', positive=True)
    check_number(linewidth, 'linewidth', nonnegative=True)
    model_id = parse_model_id(modelId)

    varray, tarray = icosahedral_geometry(1.0, divisions, sphere_factor=1)
    for a in range(3):
        varray[:, a] *= r[a]
    edge_mask = None

    if modelName is None:
        modelName = 'sphere' if r[1] == r[0] and r[2] == r[0] else 'ellipsoid'

    show_surface(varray, tarray, edge_mask, color, mesh, linewidth, center,
                 rotation, qrotation, coordinateSystem, slab, model_id,
                 modelName)
def add_op(volumes, onGrid = None, boundingGrid = None,
           subregion = 'all', step = 1,
           gridSubregion = 'all', gridStep = 1,
           inPlace = False, scaleFactors = None, modelId = None):

    volumes = filter_volumes(volumes)
    if boundingGrid is None and not inPlace:
        boundingGrid = (onGrid is None)
    if onGrid is None:
        onGrid = volumes[:1]
    onGrid = filter_volumes(onGrid, 'onGrid')
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    gridSubregion = parse_subregion(gridSubregion, 'gridSubregion')
    gridStep = parse_step(gridStep, 'gridStep')
    if inPlace:
        if boundingGrid or gridStep != 1 or gridSubregion != 'all':
            raise CommandError, "Can't use inPlace option with boundingGrid or gridStep or gridSubregion options"
        for gv in onGrid:
            if not gv.data.writable:
                raise CommandError, "Can't modify volume in place: %s" % gv.name
            if not gv in volumes:
                raise CommandError, "Can't change grid in place"
    if isinstance(scaleFactors, basestring):
        scaleFactors = parse_floats(scaleFactors, 'scaleFactors', len(volumes))
    modelId = parse_model_id(modelId)
    for gv in onGrid:
        add_operation(volumes, subregion, step,
                      gv, gridSubregion, gridStep,
                      boundingGrid, inPlace, scaleFactors, modelId)
Beispiel #13
0
def fourier_op(volumes, subregion='all', step=1, modelId=None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from fourier import fourier_transform
    for v in volumes:
        fourier_transform(v, step, subregion, modelId)
Beispiel #14
0
def laplacian_op(volumes, subregion='all', step=1, modelId=None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from laplace import laplacian
    for v in volumes:
        laplacian(v, step, subregion, modelId)
def laplacian_op(volumes, subregion = 'all', step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)
    
    from laplace import laplacian
    for v in volumes:
        laplacian(v, step, subregion, modelId)
def fourier_op(volumes, subregion = 'all', step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from fourier import fourier_transform
    for v in volumes:
        fourier_transform(v, step, subregion, modelId)
Beispiel #17
0
def z_flip_op(volumes, subregion='all', step=1, inPlace=False, modelId=None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    check_in_place(inPlace, volumes[:1])
    modelId = parse_model_id(modelId)

    for v in volumes:
        zflip_operation(v, subregion, step, inPlace, modelId)
def z_flip_op(volumes, subregion = 'all', step = 1,
              inPlace = False, modelId = None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    check_in_place(inPlace, volumes[:1])
    modelId = parse_model_id(modelId)

    for v in volumes:
        zflip_operation(v, subregion, step, inPlace, modelId)
Beispiel #19
0
def gaussian_op(volumes, sDev=1.0, subregion='all', step=1, modelId=None):

    volumes = filter_volumes(volumes)
    check_number(sDev, 'sDev', positive=True)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from gaussian import gaussian_convolve
    for v in volumes:
        gaussian_convolve(v, sDev, step, subregion, modelId)
def gaussian_op(volumes, sDev = 1.0,
                subregion = 'all', step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    check_number(sDev, 'sDev', positive = True)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from gaussian import gaussian_convolve
    for v in volumes:
        gaussian_convolve(v, sDev, step, subregion, modelId)
def boxes_op(volumes, markers, size = 0, useMarkerSize = False,
             subregion = 'all', step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    check_number(size, 'size')
    if size <= 0 and not useMarkerSize:
        raise CommandError, 'Must specify size or enable useMarkerSize'
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from boxes import boxes
    for v in volumes:
        boxes(v, markers, size, useMarkerSize, step, subregion, modelId)
Beispiel #22
0
def bin_op(volumes, subregion='all', step=1, binSize=(2, 2, 2), modelId=None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    if isinstance(binSize, int):
        binSize = (binSize, binSize, binSize)
    elif isinstance(binSize, basestring):
        binSize = parse_ints(binSize, 'binSize', 3)
    modelId = parse_model_id(modelId)

    from bin import bin
    for v in volumes:
        bin(v, binSize, step, subregion, modelId)
def bin_op(volumes, subregion = 'all', step = 1,
           binSize = (2,2,2), modelId = None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    if isinstance(binSize, int):
        binSize = (binSize, binSize, binSize)
    elif isinstance(binSize, basestring):
        binSize = parse_ints(binSize, 'binSize', 3)
    modelId = parse_model_id(modelId)

    from bin import bin
    for v in volumes:
        bin(v, binSize, step, subregion, modelId)
def permute_axes_op(volumes, axisOrder = 'xyz',
                    subregion = 'all', step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    ao = {'xyz':(0,1,2), 'xzy':(0,2,1), 'yxz':(1,0,2), 
          'yzx':(1,2,0), 'zxy':(2,0,1), 'zyx':(2,1,0)}
    if not axisOrder in ao:
        raise CommandError, 'Axis order must be xyz, xzy, zxy, zyx, yxz, or yzx'
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from permute import permute_axes
    for v in volumes:
        permute_axes(v, ao[axisOrder], step, subregion, modelId)
def octant_complement_op(volumes, center = None, iCenter = None,
              subregion = 'all', step = 1, inPlace = False,
              fillValue = 0, modelId = None):

    volumes = filter_volumes(volumes)
    center = parse_floats(center, 'center', 3)
    iCenter = parse_floats(iCenter, 'iCenter', 3)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    check_in_place(inPlace, volumes)
    check_number(fillValue, 'fillValue')
    modelId = parse_model_id(modelId)
    outside = False
    for v in volumes:
        octant_operation(v, outside, center, iCenter, subregion, step,
                         inPlace, fillValue, modelId)
def median_op(volumes, binSize = 3, iterations = 1,
              subregion = 'all', step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    check_number(iterations, 'iterations', positive = True)
    binSize = parse_step(binSize, 'binSize', require_3_tuple = True)
    for b in binSize:
        if b <= 0 or b % 2 == 0:
            raise CommandError, 'Bin size must be positive odd integer, got %d' % b
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from median import median_filter
    for v in volumes:
        median_filter(v, binSize, iterations, step, subregion, modelId)
Beispiel #27
0
def cover_op(volumes,
             atomBox=None,
             pad=5.0,
             box=None,
             x=None,
             y=None,
             z=None,
             fBox=None,
             fx=None,
             fy=None,
             fz=None,
             iBox=None,
             ix=None,
             iy=None,
             iz=None,
             step=1,
             modelId=None):

    volumes = filter_volumes(volumes)
    check_number(pad, 'pad')

    if not atomBox is None and len(atomBox) == 0:
        raise CommandError, 'No atoms specified'
    box = parse_box(box, x, y, z, 'box', 'x', 'y', 'z')
    fBox = parse_box(fBox, fx, fy, fz, 'fBox', 'fx', 'fy', 'fz')
    iBox = parse_box(iBox, ix, iy, iz, 'iBox', 'ix', 'iy', 'iz')
    bc = len([b for b in (box, fBox, iBox, atomBox) if b])
    if bc == 0:
        raise CommandError, 'Must specify box to cover'
    if bc > 1:
        raise CommandError, 'Specify covering box in one way'

    step = parse_step(step, require_3_tuple=True)
    modelId = parse_model_id(modelId)

    from VolumeViewer import volume, volume_from_grid_data
    for v in volumes:
        g = v.grid_data(subregion='all', step=step, mask_zone=False)
        ijk_min, ijk_max = cover_box_bounds(v, step, atomBox, pad, box, fBox,
                                            iBox)
        cg = volume.map_from_periodic_map(g, ijk_min, ijk_max)
        cv = volume_from_grid_data(cg, model_id=modelId)
        cv.copy_settings_from(v, copy_region=False)
        cv.show()
def icosahedron_shape(radius=10.0,
                      center=None,
                      rotation=None,
                      qrotation=None,
                      coordinateSystem=None,
                      divisions=72,
                      color=(.745, .745, .745, 1),
                      mesh=None,
                      linewidth=1,
                      sphereFactor=0.0,
                      orientation='222',
                      lattice=None,
                      slab=None,
                      modelName='icosahedron',
                      modelId=None):

    check_number(radius, 'radius', nonnegative=True)
    check_number(divisions, 'divisions', positive=True)
    check_number(linewidth, 'linewidth', nonnegative=True)
    check_number(sphereFactor, 'sphereFactor')
    model_id = parse_model_id(modelId)

    if orientation == 222:
        orientation = '222'
    from Icosahedron import coordinate_system_names as csnames
    if not orientation in csnames:
        raise CommandError, ('Unknown orientation "%s", use %s' %
                             (orientation, ', '.join(csnames)))
    if not lattice is None and mesh is None:
        mesh = True

    from Commands import parse_ints
    hk = parse_ints(lattice, 'lattice', 2)

    if hk is None:
        varray, tarray = icosahedral_geometry(radius, divisions, sphereFactor,
                                              orientation)
        edge_mask = None
    else:
        varray, tarray, edge_mask = hk_icosahedral_geometry(
            radius, hk, sphereFactor, orientation)
    show_surface(varray, tarray, edge_mask, color, mesh, linewidth, center,
                 rotation, qrotation, coordinateSystem, slab, model_id,
                 modelName)
Beispiel #29
0
def boxes_op(volumes,
             markers,
             size=0,
             useMarkerSize=False,
             subregion='all',
             step=1,
             modelId=None):

    volumes = filter_volumes(volumes)
    check_number(size, 'size')
    if size <= 0 and not useMarkerSize:
        raise CommandError, 'Must specify size or enable useMarkerSize'
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from boxes import boxes
    for v in volumes:
        boxes(v, markers, size, useMarkerSize, step, subregion, modelId)
def resample_op(volumes, onGrid = None, boundingGrid = False,
                subregion = 'all', step = 1,
                gridSubregion = 'all', gridStep = 1,
                modelId = None):

    volumes = filter_volumes(volumes)
    if onGrid is None:
        raise CommandError, 'Resample operation must specify onGrid option'
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    gridSubregion = parse_subregion(gridSubregion, 'gridSubregion')
    gridStep = parse_step(gridStep, 'gridStep')
    onGrid = filter_volumes(onGrid, 'onGrid')
    modelId = parse_model_id(modelId)
    for v in volumes:
        for gv in onGrid:
            add_operation([v], subregion, step,
                          gv, gridSubregion, gridStep,
                          boundingGrid, False, None, modelId)
Beispiel #31
0
def median_op(volumes,
              binSize=3,
              iterations=1,
              subregion='all',
              step=1,
              modelId=None):

    volumes = filter_volumes(volumes)
    check_number(iterations, 'iterations', positive=True)
    binSize = parse_step(binSize, 'binSize', require_3_tuple=True)
    for b in binSize:
        if b <= 0 or b % 2 == 0:
            raise CommandError, 'Bin size must be positive odd integer, got %d' % b
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from median import median_filter
    for v in volumes:
        median_filter(v, binSize, iterations, step, subregion, modelId)
Beispiel #32
0
def molecule_map(
        atoms,
        resolution,
        gridSpacing=None,  # default is 1/3 resolution
        edgePadding=None,  # default is 3 times resolution
        cutoffRange=5,  # in standard deviations
        sigmaFactor=1 / (pi * sqrt(2)),  # resolution / standard deviation
        displayThreshold=0.95,  # fraction of total density
        modelId=None,  # integer
        replace=True,
        showDialog=True):

    from Commands import CommandError
    if len(atoms) == 0:
        raise CommandError, 'No atoms specified'

    for vname in ('resolution', 'gridSpacing', 'edgePadding', 'cutoffRange',
                  'sigmaFactor'):
        value = locals()[vname]
        if not isinstance(value, (float, int, type(None))):
            raise CommandError, '%s must be number, got "%s"' % (vname,
                                                                 str(value))

    if edgePadding is None:
        pad = 3 * resolution
    else:
        pad = edgePadding

    if gridSpacing is None:
        step = (1. / 3) * resolution
    else:
        step = gridSpacing

    if not modelId is None:
        from Commands import parse_model_id
        modelId = parse_model_id(modelId)

    v = make_molecule_map(atoms, resolution, step, pad, cutoffRange,
                          sigmaFactor, displayThreshold, modelId, replace,
                          showDialog)
    return v
Beispiel #33
0
def cylinder_shape(radius = 10.0, height = 40.0,
                   center = None, rotation = None, qrotation = None,
                   coordinateSystem = None,
                   divisions = 72, color = (.745,.745,.745,1),
                   mesh = False, linewidth = 1,
                   caps = False, slab = None,
                   modelName = 'cylinder', modelId = None):

    check_number(radius, 'radius', nonnegative = True)
    check_number(height, 'height', nonnegative = True)
    check_number(divisions, 'divisions', positive = True)
    check_number(linewidth, 'linewidth', nonnegative = True)
    model_id = parse_model_id(modelId)

    nz, nc = cylinder_divisions(radius, height, divisions)
    varray, tarray = cylinder_geometry(radius, height, nz, nc, caps)
    edge_mask = None

    show_surface(varray, tarray, edge_mask, color, mesh, linewidth,
                 center, rotation, qrotation, coordinateSystem,
                 slab, model_id, modelName)
Beispiel #34
0
def octant_complement_op(volumes,
                         center=None,
                         iCenter=None,
                         subregion='all',
                         step=1,
                         inPlace=False,
                         fillValue=0,
                         modelId=None):

    volumes = filter_volumes(volumes)
    center = parse_floats(center, 'center', 3)
    iCenter = parse_floats(iCenter, 'iCenter', 3)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    check_in_place(inPlace, volumes)
    check_number(fillValue, 'fillValue')
    modelId = parse_model_id(modelId)
    outside = False
    for v in volumes:
        octant_operation(v, outside, center, iCenter, subregion, step, inPlace,
                         fillValue, modelId)
Beispiel #35
0
def morph_op(volumes,
             frames=25,
             start=0,
             playStep=0.04,
             playDirection=1,
             playRange=None,
             addMode=False,
             constantVolume=False,
             scaleFactors=None,
             hideOriginalMaps=True,
             subregion='all',
             step=1,
             modelId=None):

    volumes = filter_volumes(volumes)
    check_number(frames, 'frames', int, nonnegative=True)
    check_number(start, 'start')
    check_number(playStep, 'playStep', nonnegative=True)
    if playRange is None:
        if addMode:
            prange = (-1.0, 1.0)
        else:
            prange = (0.0, 1.0)
    else:
        prange = parse_floats(playRange, 'playRange', 2)
    check_number(playDirection, 'playDirection')
    sfactors = parse_floats(scaleFactors, 'scaleFactors', len(volumes))
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)
    vs = [
        tuple(v.matrix_size(step=step, subregion=subregion)) for v in volumes
    ]
    if len(set(vs)) > 1:
        sizes = ' and '.join([str(s) for s in vs])
        raise CommandError, "Volume grid sizes don't match: %s" % sizes
    from MorphMap import morph_maps
    morph_maps(volumes, frames, start, playStep, playDirection, prange,
               addMode, constantVolume, sfactors, hideOriginalMaps, subregion,
               step, modelId)
Beispiel #36
0
def resample_op(volumes,
                onGrid=None,
                boundingGrid=False,
                subregion='all',
                step=1,
                gridSubregion='all',
                gridStep=1,
                modelId=None):

    volumes = filter_volumes(volumes)
    if onGrid is None:
        raise CommandError, 'Resample operation must specify onGrid option'
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    gridSubregion = parse_subregion(gridSubregion, 'gridSubregion')
    gridStep = parse_step(gridStep, 'gridStep')
    onGrid = filter_volumes(onGrid, 'onGrid')
    modelId = parse_model_id(modelId)
    for v in volumes:
        for gv in onGrid:
            add_operation([v], subregion, step, gv, gridSubregion, gridStep,
                          boundingGrid, False, None, modelId)
Beispiel #37
0
def molecule_map(atoms, resolution,
                 gridSpacing = None,    # default is 1/3 resolution
                 edgePadding = None,    # default is 3 times resolution
                 cutoffRange = 5,       # in standard deviations
                 sigmaFactor = 1/(pi*sqrt(2)), # resolution / standard deviation
                 displayThreshold = 0.95, # fraction of total density
                 modelId = None, # integer
                 replace = True,
		 showDialog = True
                 ):

    from Commands import CommandError
    if len(atoms) == 0:
        raise CommandError, 'No atoms specified'

    for vname in ('resolution', 'gridSpacing', 'edgePadding',
                  'cutoffRange', 'sigmaFactor'):
        value = locals()[vname]
        if not isinstance(value, (float,int,type(None))):
            raise CommandError, '%s must be number, got "%s"' % (vname,str(value))

    if edgePadding is None:
        pad = 3*resolution
    else:
        pad = edgePadding

    if gridSpacing is None:
        step = (1./3) * resolution
    else:
        step = gridSpacing

    if not modelId is None:
        from Commands import parse_model_id
        modelId = parse_model_id(modelId)

    v = make_molecule_map(atoms, resolution, step, pad,
                          cutoffRange, sigmaFactor,
                          displayThreshold, modelId, replace, showDialog)
    return v
Beispiel #38
0
def icosahedron_shape(radius = 10.0, center = None, rotation = None,
                      qrotation = None, coordinateSystem = None,
                      divisions = 72,
                      color = (.745,.745,.745,1), mesh = None, linewidth = 1,
                      sphereFactor = 0.0, orientation = '222', lattice = None,
                      slab = None, modelName = 'icosahedron', modelId = None):

    check_number(radius, 'radius', nonnegative = True)
    check_number(divisions, 'divisions', positive = True)
    check_number(linewidth, 'linewidth', nonnegative = True)
    check_number(sphereFactor, 'sphereFactor')
    model_id = parse_model_id(modelId)

    if orientation == 222:
        orientation = '222'
    from Icosahedron import coordinate_system_names as csnames
    if not orientation in csnames:
        raise CommandError, ('Unknown orientation "%s", use %s'
                             % (orientation, ', '.join(csnames)))
    if not lattice is None and mesh is None:
        mesh = True

    from Commands import parse_ints
    hk = parse_ints(lattice, 'lattice', 2)

    if hk is None:
        varray, tarray = icosahedral_geometry(radius, divisions,
                                              sphereFactor, orientation)
        edge_mask = None
    else:
        varray, tarray, edge_mask = hk_icosahedral_geometry(radius, hk,
                                                            sphereFactor,
                                                            orientation)
    show_surface(varray, tarray, edge_mask, color, mesh, linewidth,
                 center, rotation, qrotation, coordinateSystem,
                 slab, model_id, modelName)
Beispiel #39
0
def permute_axes_op(volumes,
                    axisOrder='xyz',
                    subregion='all',
                    step=1,
                    modelId=None):

    volumes = filter_volumes(volumes)
    ao = {
        'xyz': (0, 1, 2),
        'xzy': (0, 2, 1),
        'yxz': (1, 0, 2),
        'yzx': (1, 2, 0),
        'zxy': (2, 0, 1),
        'zyx': (2, 1, 0)
    }
    if not axisOrder in ao:
        raise CommandError, 'Axis order must be xyz, xzy, zxy, zyx, yxz, or yzx'
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from permute import permute_axes
    for v in volumes:
        permute_axes(v, ao[axisOrder], step, subregion, modelId)