forked from Pymol-Scripts/Pymol-script-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grepset.py
41 lines (35 loc) · 1.01 KB
/
grepset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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] + [0])
fmt = "%%-%ds : %%s" % (maxlen,)
for setting in matches:
print((fmt % setting))
print(('%d settings matched' % (count,)))
cmd.set('text', 1)
cmd.extend('grepset', grepset)