Beispiel #1
0
def show_surface():
    'Show MSMS molecular surface'
    from chimera.selection import currentAtoms
    from Surface import selected_surface_pieces, show_surfaces
    if len(currentAtoms()) > 0 or len(selected_surface_pieces()) == 0:
        # If actions.showSurface() with no atoms selected and a SurfacePiece is
        # selected then it shows a warning dialog.  Suppress that.
        from chimera import actions
        actions.showSurface()  # MSMSModel surfaces
    show_surfaces(selected_surface_pieces())  # SurfaceModel surfaces
Beispiel #2
0
    def record_movable_objects(self, event):

        mode = self.mode
        if mode == self.MOVE_SELECTION:
            from chimera import selection
            atoms = selection.currentAtoms()
            chains = selected_multiscale_chains()
            spieces = selected_surface_pieces()
            self.movable_groups = objects_grouped_by_model(
                atoms, chains, spieces)
        elif mode in (self.MOVE_MOLECULE, self.MOVE_CHAIN,
                      self.MOVE_SECONDARY_STRUCTURE):
            from chimera import viewer, Atom, Residue
            # TODO: Appears to be a bug where picking 1a0m ribbon gives
            # lists of many erroneous residues.  It is caused by LensViewer
            # pick(x,y) doing drag pick using previously set x,y!  Not clear
            # why since there is separate dragPick(x,y) method.
            viewer.delta(event.x, event.y)  # Sets lastx, lasty
            objects = viewer.pick(event.x, event.y)
            atoms = [a for a in objects if isinstance(a, Atom)]
            residues = [r for r in objects if isinstance(r, Residue)]
            if mode == self.MOVE_MOLECULE:
                catoms = extend_to_molecules(atoms, residues)
                mschains = multiscale_chain_pieces(objects,
                                                   full_molecules=True)
            elif mode == self.MOVE_CHAIN:
                catoms = extend_to_chains(atoms, residues)
                mschains = multiscale_chain_pieces(objects)
            elif mode == self.MOVE_SECONDARY_STRUCTURE:
                catoms = extend_to_secondary_structure(atoms, residues)
                mschains = []
            self.movable_groups = objects_grouped_by_model(catoms, mschains)
        else:
            self.movable_groups = []
def mask_volume_using_selected_surfaces(axis=(0, 1, 0), pad=None):

    from VolumeViewer import active_volume
    v = active_volume()
    if v is None:
        return

    from Surface import selected_surface_pieces
    plist = selected_surface_pieces()
    from Matrix import xform_matrix, invert_matrix
    tf = invert_matrix(xform_matrix(v.model_transform()))
    surfaces = surface_geometry(plist, tf, pad)

    if surfaces:
        masked_volume(v, surfaces, axis)
def mask_volume_using_selected_surfaces(axis = (0,1,0), pad = None):

  from VolumeViewer import active_volume
  v = active_volume()
  if v is None:
    return

  from Surface import selected_surface_pieces
  plist = selected_surface_pieces()
  from Matrix import xform_matrix, invert_matrix
  tf = invert_matrix(xform_matrix(v.model_transform()))
  surfaces = surface_geometry(plist, tf, pad)

  if surfaces:
    masked_volume(v, surfaces, axis)
def mask(volumes, surfaces, axis = None, fullMap = False,
         pad = 0., slab = None, sandwich = True, invertMask = False):

    from Commands import CommandError, filter_volumes, parse_floats
    vlist = filter_volumes(volumes)

    from Surface import selected_surface_pieces
    glist = selected_surface_pieces(surfaces, include_outline_boxes = False)
    if len(glist) == 0:
        raise CommandError, 'No surfaces specified'

    axis = parse_floats(axis, 'axis', 3, (0,1,0))

    if not isinstance(fullMap, (bool,int)):
        raise CommandError, 'fullMap option value must be true or false'

    if not isinstance(invertMask, (bool,int)):
        raise CommandError, 'invertMask option value must be true or false'

    if not isinstance(pad, (float,int)):
        raise CommandError, 'pad option value must be a number'

    if isinstance(slab, (float,int)):
        pad = (-0.5*slab, 0.5*slab)
    elif not slab is None:
        pad = parse_floats(slab, 'slab', 2)

    if not isinstance(sandwich, bool):
        raise CommandError, 'sandwich option value must be true or false'

    from depthmask import surface_geometry, masked_volume
    from Matrix import xform_matrix, invert_matrix
    for v in vlist:
        tf = invert_matrix(xform_matrix(v.model_transform()))
        surfs = surface_geometry(glist, tf, pad)
        masked_volume(v, surfs, axis, fullMap, sandwich, invertMask)
def selected_surfaces():

    from Surface import selected_surface_pieces
    splist = selected_surface_pieces()
    splist.sort(lambda a, b: cmp(surface_name(a), surface_name(b)))
    return splist
Beispiel #7
0
def selected_surface_pieces():

    from Surface import selected_surface_pieces
    from MultiScale import is_chain_piece
    spieces = [p for p in selected_surface_pieces() if not is_chain_piece(p)]
    return spieces
Beispiel #8
0
def _nextSel():
    sel = selection.ItemizedSelection()
    sel.add(selection.currentBarrenGraphs())
    if selLevel == SELRES:
        items = []
        addResidues = {}
        for r in selection.currentResidues():
            addResidues[r] = 1
        selPseudoBonds = filter(
            lambda e, PB=chimera.PseudoBond: isinstance(e, PB),
            selection.currentEdges())
        # for currently selected chain-trace pseudobonds
        # act as if they select their residues
        for ct in filter(
                lambda e: isinstance(e.pseudoBondGroup, chimera.ChainTrace),
                selPseudoBonds):
            addResidues[ct.atoms[0].residue] = 1
            addResidues[ct.atoms[1].residue] = 1
        for r in addResidues.keys():
            items.extend(r.atoms)
        sel.add(items)
        sel.addImplied(vertices=0)
        sel.add(selPseudoBonds)
        # add chain trace pseudobonds that should be selected
        sel.add(selChainTrace(sel))

    elif selLevel == SELCHAIN:
        chainIDs = {}
        for a in selection.currentAtoms():
            chainID = a.residue.id.chainId
            try:
                chainIDs[a.molecule][chainID] = 1
            except KeyError:
                chainIDs[a.molecule] = {chainID: 1}
        items = []
        for m, ids in chainIDs.items():
            for a in m.atoms:
                if not ids.has_key(a.residue.id.chainId):
                    continue
                items.append(a)
                items.extend(a.bonds)
        pbgs = {}
        for pb in filter(lambda b, PB=chimera.PseudoBond: isinstance(b, PB),
                         selection.currentEdges()):
            pbgs[pb.pseudoBondGroup] = 1
        for pbg in pbgs.keys():
            if isinstance(pbg, chimera.ChainTrace):
                continue
            items.extend(pbg.pseudoBonds)
        sel.add(items)
        sel.add(selChainTrace(sel))

    elif selLevel == SELSUBMODEL:
        items = []
        for m in selection.currentMolecules():
            items.extend(m.atoms)
            items.extend(m.bonds)
        items.extend(
            filter(lambda e, PB=chimera.PseudoBond: isinstance(e, PB),
                   selection.currentEdges()))
        sel.add(items)
        sel.add(selChainTrace(sel))
    elif selLevel == SELMODEL:
        molDict = {}
        for m in selection.currentMolecules():
            osl = m.oslIdent()
            if '.' in osl:
                molDict[osl[:osl.index('.')]] = 1
            else:
                molDict[m] = 1
        items = []
        for mosl in molDict.keys():
            if isinstance(mosl, basestring):
                for m in selection.OSLSelection(mosl).molecules():
                    items.extend(m.atoms)
                    items.extend(m.bonds)
            else:
                items.extend(mosl.atoms)
                items.extend(mosl.bonds)
        items.extend(
            filter(lambda e, PB=chimera.PseudoBond: isinstance(e, PB),
                   selection.currentEdges()))
        sel.add(items)
        sel.add(selChainTrace(sel))
    elif selLevel == SELALL:
        global _topValid
        _topValid = True
        items = []
        if selection.currentMolecules():
            for m in chimera.openModels.list():
                if hasattr(m, 'atoms'):
                    items.extend(m.atoms)
                    items.extend(m.bonds)
        for e in selection.currentEdges():
            if isinstance(e, chimera.PseudoBond):
                pbsSelected = True
                break
        else:
            pbsSelected = False
        if pbsSelected:
            mgr = chimera.PseudoBondMgr.mgr()
            for grp in mgr.pseudoBondGroups:
                items.extend(grp.pseudoBonds)
        sel.add(items)
        sel.add(selChainTrace(sel))
        global _selAllHandler
        if _selAllHandler is not None:
            _selAllHandler = \
             chimera.openModels.addAddHandler(
               _addModelHandler, None)
    else:
        raise ValueError, "Bad selection level"

    # Handle selected surface pieces
    from Surface import selected_surface_pieces
    plist = selected_surface_pieces()
    mlist = set([p.model for p in plist])
    if selLevel == SELALL and len(mlist) > 0:
        from _surface import SurfaceModel
        mlist = chimera.openModels.list(modelTypes=[SurfaceModel])
    sel.add(mlist)

    return sel