Example Scripts

From PyMOLWiki
Revision as of 17:17, 6 May 2005 by Inchoate (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Multiple Object Manipulation Scripts

Dis/Enable Objects

If someone has many (possibly hundreds) of objects -- say distance objects -- one can turn them all on or off by using Python scripts within PyMol. The following script will extend the commands "sd" and "hd" for "show distance" and "hide distance," respectively. The first script,

from pymol import cmd 
num_dist = 100 
        
def show_dist(): 
    """ show all of my distance objects """ 
    for i in range(num_dist): 
        cmd.enable('_dist%s'%i) 
        
def hide_dist(): 
    """ hide all of my distance objects """ 
    for i in range(num_dist): 
        cmd.disable('_dist%s'%i) 
        
cmd.extend('sd',show_dist) 
cmd.extend('hd',hide_dist)

works on 100 objects. We can extend the idea with more elegant scripting to work w/o forcing us to keep track of the number of objects:

def show_dist(): 
    dists = [name for name in cmd.get_names() if cmd.get_type(name) == 'object:distance'] 
    for name in dists: cmd.enable(name)

Now, just running "sd" would show all the distance objects.

Sources

Taken from the PyMol Users list. Python source by Michael Lerner.