This is a read-only mirror of pymolwiki.org

Difference between revisions of "Find symbol"

From PyMOL Wiki
Jump to navigation Jump to search
m (1 revision)
 
(No difference)

Latest revision as of 02:00, 28 March 2014

Overview

This script looks for the given symbol in a given module(s). This can be handy if you forgot which module something is in or just want to query for a substring in a set of modules.

Usage

# search pymol and pymol.cmd for any symbol starting with 'mov'

fs("mov")
['cmd.get_movie_length',
 'cmd.get_movie_locked',
 'cmd.get_movie_playing',
 'cmd.mmove',
 'cmd.move',
 'cmd.movie',
 'cmd.moving',
 'cmd.remove',
 'cmd.remove_picked']

# Search PyMOL's CMD module for something called align

fs("align", "cmd")
['cmd.align', 'cmd.alignto', 'cmd.cealign', 'cmd.get_raw_alignment']

The Code

import pymol
import inspect
import pprint

def fs(needle,haystack=["pymol","cmd"]):
    """
    This script will find the 'needle' in the 'haystack,' where the former is
    a symbol to be found in the latter, which is a module.
    """
    
    if type("") == type(haystack):

        haystack = [haystack,]

    for mod in haystack:

        found_list = map(lambda x: "%s.%s" % (mod,x), [name for name,obj in inspect.getmembers(eval(mod)) if needle in name])

    pprint.pprint(found_list)

    return found_list