Find symbol

From PyMOLWiki
Jump to: navigation, search


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.


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


# 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])


    return found_list