-
Notifications
You must be signed in to change notification settings - Fork 257
/
get_colors.py
74 lines (65 loc) · 2.53 KB
/
get_colors.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'''
get_colors.py
Described at: http://www.pymolwiki.org/get_colors
Version 1.0 (2014)
##################################################
Includes two functions:
get_colors: returns a list of defined pymol colors
get_random_color: returns a random color
##################################################
Plugin contributed by Andreas Warnecke
##################################################
VERSION NOTES:
1.0 2014 First release
'''
#-------------------------------------------------------------------------------
from __future__ import print_function
from pymol import cmd
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
def get_colors(selection='', quiet=1):
'''
DESCRIPTION:
returns a list of available pymol colors
USAGE:
get_colors [ selection [, quiet ]]
EXAMPLES:
get_colors # basic colors
get colors all # larger range with intermediates
'''
import pymol
pymol_color_list = []
for tuplepair in pymol.querying.get_color_indices(selection):
pymol_color_list.append(tuplepair[0])
pymol_color_list.sort()
if not int(quiet): print(pymol_color_list)
return pymol_color_list
cmd.extend('get_colors',get_colors)
cmd.auto_arg[0]['get_colors']=[lambda: cmd.Shortcut(['""','all']), 'selection=', ',']
cmd.auto_arg[1]['get_colors']=[lambda: cmd.Shortcut(['0']), 'quiet=', '']
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
def get_random_color(selection='', quiet=1):
'''
DESCRIPTION:
returns a random color name available in pymol
! Requires get_colors !Indended mostly for use in Python
USAGE:
get_random_color [ selection [, quiet ]]
EXAMPLES:
# print a random color name:
get_random_color
# color object randomly:
fetch 1hpv, async=0
cmd.color(get_random_color())
'''
import random
randomcolor=random.choice(get_colors(selection, 1))
if not int(quiet): print(randomcolor)
return randomcolor
cmd.extend('get_random_color', get_random_color)
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------