From PyMOLWiki
Revision as of 02:58, 31 August 2011 by Speleo3 (talk | contribs) (get_object_list)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


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):
            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
        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):
    if int(reversed):

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

    return rList

cmd.extend("getNamesInSel", getNamesInSel)

See Also