This is a read-only mirror of pymolwiki.org

Difference between revisions of "Get object list"

From PyMOL Wiki
Jump to navigation Jump to search
m (1 revision)
m (print syntax for python 2+3)
Line 19: Line 19:
 
<source lang="python">
 
<source lang="python">
 
PyMOL> fetch 2x19 2xwu 1d7q, async=0
 
PyMOL> fetch 2x19 2xwu 1d7q, async=0
PyMOL> print cmd.get_object_list('solvent')
+
PyMOL> print(cmd.get_object_list('solvent'))
 
['2x19', '2xwu']
 
['2x19', '2xwu']
PyMOL> print cmd.get_object_list('hydro')
+
PyMOL> print(cmd.get_object_list('hydro'))
 
['1d7q']
 
['1d7q']
PyMOL> print cmd.get_object_list('2x*')    # FAIL!!!
+
PyMOL> print(cmd.get_object_list('2x*'))    # FAIL!!! (fixed in PyMOL 1.7.6)
 
['2x19']
 
['2x19']
PyMOL> print cmd.get_object_list('(2x*)')  # correct, with parenthesis
+
PyMOL> print(cmd.get_object_list('(2x*)'))  # correct, with parenthesis
 
['2x19', '2xwu']
 
['2x19', '2xwu']
 
</source>
 
</source>

Revision as of 17:10, 6 March 2017

cmd.get_object_list is an API only command which returns the list of all molecular objects in selection. It will not return selection names or objects which are not of type molecule.

PyMOL API

list cmd.get_object_list(string selection='(all)')

Important: Always put the selection in parenthesis to force PyMOL to interpret it as an atom selection. Otherwise this might fail on name wildcards, groups, etc.

For proper atom selections this should be identical to:

list cmd.get_names('objects', 0, string selection='(all)')

Examples

PyMOL> fetch 2x19 2xwu 1d7q, async=0
PyMOL> print(cmd.get_object_list('solvent'))
['2x19', '2xwu']
PyMOL> print(cmd.get_object_list('hydro'))
['1d7q']
PyMOL> print(cmd.get_object_list('2x*'))    # FAIL!!! (fixed in PyMOL 1.7.6)
['2x19']
PyMOL> print(cmd.get_object_list('(2x*)'))  # correct, with parenthesis
['2x19', '2xwu']

See Also