GetNamesInSel: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
No edit summary
(get_object_list)
 
Line 5: Line 5:
<source lang="python">
<source lang="python">
from pymol import cmd, stored
from pymol import cmd, stored
def getNamesInSel(sel, sorted=False, reversed=False):
def getNamesInSel(sel, sorted=0, reversed=0, quiet=1):
     """
     """
     PARAMETERS
     PARAMETERS
Line 21: Line 21:


     """
     """
     stored.tempNames = set()
     rList = cmd.get_object_list('(' + sel + ')')
    cmd.iterate_state(1, sel, "stored.tempNames.add(model)")
    rList = list(stored.tempNames)


     # if you want the list reversed or sorted,
     # if you want the list reversed or sorted,
     # uncomment the following lines
     # uncomment the following lines
     if sorted:
     if int(sorted):
         rList.sort()
         rList.sort()
     if reversed:
     if int(reversed):
         rList.reverse()
         rList.reverse()
    if not int(quiet):
        print ' getNamesInSel: ', rList


     return rList
     return rList
Line 39: Line 40:
= See Also =
= See Also =
* [[Get_Names]]
* [[Get_Names]]
* [[get_object_list]]


[[Category:Script_Library]]
[[Category:Script_Library]]
[[Category:ObjSel_Scripts]]
[[Category:ObjSel_Scripts]]

Latest revision as of 03:58, 31 August 2011

Overview

This script returns the list of object names that exist in any given selection. For example, if you have 100 objects loaded (viz. ligand poses from small molecule docking) and select all atoms w/in some cutoff, then you have a selection. What objects are actually in that selection? This script will tell you.

The Code

from pymol import cmd, stored
def getNamesInSel(sel, sorted=0, reversed=0, quiet=1):
    """
    PARAMETERS
        sel,
            The selection, object or group to iterate over
        sorted (boolean),
            Should the list be sorted?
        reversed (boolean)
            Should the list be reversed before returned?  (Combined
            with the above, you can return a decreasing-sorted list
            of names
 
    RETURNS
        list[] of strings, representing the object names desired.

    """
    rList = cmd.get_object_list('(' + sel + ')')

    # if you want the list reversed or sorted,
    # uncomment the following lines
    if int(sorted):
        rList.sort()
    if int(reversed):
        rList.reverse()

    if not int(quiet):
        print ' getNamesInSel: ', rList

    return rList

cmd.extend("getNamesInSel", getNamesInSel)

See Also