GetNamesInSel: Difference between revisions
Jump to navigation
Jump to search
(New page: = 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) an...) |
No edit summary |
||
Line 5: | Line 5: | ||
<source lang="python"> | <source lang="python"> | ||
from pymol import cmd, stored | from pymol import cmd, stored | ||
getNamesInSel(sel): | def getNamesInSel(sel, sorted=False, reversed=False): | ||
stored.tempNames = set() | stored.tempNames = set() | ||
cmd.iterate_state(1, sel, "stored.tempNames.add(model)") | cmd.iterate_state(1, sel, "stored.tempNames.add(model)") | ||
Line 12: | Line 12: | ||
# 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: | |||
rList.sort() | |||
if reversed: | |||
rList.reverse() | |||
return rList | return rList | ||
cmd.extend("getNamesInSel", getNamesInSel) | |||
</source> | </source> | ||
Revision as of 13:36, 23 March 2009
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=False, reversed=False):
stored.tempNames = set()
cmd.iterate_state(1, sel, "stored.tempNames.add(model)")
rList = list(stored.tempNames)
# if you want the list reversed or sorted,
# uncomment the following lines
if sorted:
rList.sort()
if reversed:
rList.reverse()
return rList
cmd.extend("getNamesInSel", getNamesInSel)