This is a read-only mirror of pymolwiki.org
Difference between revisions of "Grepset"
Jump to navigation
Jump to search
m |
(Modified script to format output according to max length of matched settings.) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 45: | Line 45: | ||
<source lang="python"> | <source lang="python"> | ||
from pymol import cmd | from pymol import cmd | ||
+ | import re | ||
import pymol.setting | import pymol.setting | ||
def grepset(regexp=''): | def grepset(regexp=''): | ||
− | + | ''' | |
DESCRIPTION | DESCRIPTION | ||
− | + | "grepset" greps through the list of settings using a python | |
− | + | regular expression as defined in the 're' module. | |
− | + | It returns a list of settings/values matching the regexp. | |
− | + | No regexp returns every setting. | |
USAGE | USAGE | ||
− | + | grepset [regexp] | |
EXAMPLE | EXAMPLE | ||
− | + | grepset line | |
− | + | grepset ray | |
+ | grepset (^line|color$) | ||
SEE ALSO | SEE ALSO | ||
− | + | Python re module | |
− | + | ''' | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | count = 0 | ||
+ | regexp = re.compile(regexp) | ||
+ | matches = [] | ||
+ | for a in pymol.setting.get_index_list(): | ||
+ | setting = pymol.setting._get_name(a) | ||
+ | if regexp.search(setting): | ||
+ | count += 1 | ||
+ | matches.append( (setting, cmd.get_setting_text(a, '', -1)) ) | ||
+ | # max length of the setting names that matched | ||
+ | maxlen = max([len(s[0]) for s in matches]) | ||
+ | fmt = "%%-%ds : %%s" % (maxlen,) | ||
+ | for setting in matches: | ||
+ | print fmt % setting | ||
+ | print '%d settings matched' % (count,) | ||
+ | cmd.set('text', 1) | ||
+ | cmd.extend('grepset', grepset) | ||
</source> | </source> | ||
''Author: Ezequiel (Zac) Panepucci'' | ''Author: Ezequiel (Zac) Panepucci'' | ||
− | [[Category: | + | [[Category:Script_Library|Grepset]] |
+ | [[Category:UI_Scripts]] |
Revision as of 09:35, 5 November 2009
Use this little script to explore PyMOL's myriad settings.
Usefull for newbies and those with not so good memory skills...
To use:
- put the script in a file called grepset.py
- from within PyMOL execute run grepset.py
- try it out, see examples below.
Example 1: grepset light
cartoon_highlight_color default dot_lighting on light [ -0.40000, -0.40000, -1.00000 ] mesh_lighting off two_sided_lighting off 5 settings matched
Example 2: grepset trans
cartoon_transparency 0.00000 ray_transparency_contrast 1.00000 ray_transparency_shadows 1 ray_transparency_spec_cut 0.90000 ray_transparency_specular 0.40000 sphere_transparency 0.00000 stick_transparency 0.00000 transparency 0.00000 transparency_mode 2 transparency_picking_mode 2 10 settings matched
Example 3: grepset ^trans
transparency 0.00000 transparency_mode 2 transparency_picking_mode 2 3 settings matched
The Script itself: grepset.py
from pymol import cmd
import re
import pymol.setting
def grepset(regexp=''):
'''
DESCRIPTION
"grepset" greps through the list of settings using a python
regular expression as defined in the 're' module.
It returns a list of settings/values matching the regexp.
No regexp returns every setting.
USAGE
grepset [regexp]
EXAMPLE
grepset line
grepset ray
grepset (^line|color$)
SEE ALSO
Python re module
'''
count = 0
regexp = re.compile(regexp)
matches = []
for a in pymol.setting.get_index_list():
setting = pymol.setting._get_name(a)
if regexp.search(setting):
count += 1
matches.append( (setting, cmd.get_setting_text(a, '', -1)) )
# max length of the setting names that matched
maxlen = max([len(s[0]) for s in matches])
fmt = "%%-%ds : %%s" % (maxlen,)
for setting in matches:
print fmt % setting
print '%d settings matched' % (count,)
cmd.set('text', 1)
cmd.extend('grepset', grepset)
Author: Ezequiel (Zac) Panepucci