Find symbol
Jump to navigation
Jump to search
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