-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathColor.py
executable file
·172 lines (136 loc) · 4.94 KB
/
Color.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
'''
NRGsuite: PyMOL molecular tools interface
Copyright (C) 2011 Gaudreault, F., Morency, LP. & Najmanovich, R.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
# coding: utf-8
'''
@title: Color.py
@summary: Module that define all colors used from Pymol simulation.
@contain: Get_Pymol_HeatColor, Get_Hex_HeatColor, GetHeatColorList, CreateNoList
@organization: Najmanovich Research Group
@creation date: oct. 13, 2010
'''
NBCOLOR = 20
'''
@summary: Get_Pymol_HeatColor: Based on a heat scale color chart, return the color
related on the colorId number pass has argument.
Related link: http://www.pymolwiki.org/index.php/Color_Values
@param pColorId: Integer
@return: String - Color name used by Pymol
'''
def Get_Pymol_HeatColor(pColorId):
#From RED=0 to BLUE=19
ColorList = ['red',
'br8',
'tv_red',
'oxygen',
'iron',
'tv_orange',
'sulfur',
'gold',
'yelloworange',
'neodymium',
'limon',
'chartreuse',
'tv_green',
'limegreen',
'teal',
'rhodium',
'slate',
'tv_blue',
'blue',
'density']
if (pColorId<0) or (pColorId>19):
return 'grey50'
else:
return ColorList[pColorId]
def Get_Hex_HeatColor(pColorId):
#From RED=0 to BLUE=19
ColorList = ['#FF0000',
'#E61A33',
'#FF1515',
'#FF4D4D',
'#E06633',
'#FF8C26',
'#E6C740',
'#FFD124',
'#FFDE5E',
'#C7FFC7',
'#BFFF40',
'#80FF00',
'#33FF33',
'#00FF80',
'#00BFBF',
'#0A7DAB',
'#8080FF',
'#4D4DFF',
'#0000FF',
'#1A1A99']
if (pColorId<0) or (pColorId>19):
return '#7D7D7D'
else:
return ColorList[pColorId]
'''
@summary: GetHeatColorList: Based on a heat scale color chart, return a color
list depending on the total of colors.
Related link: http://www.pymolwiki.org/index.php/Color_Values
@param pTotColor: Integer
@param boolHex: Boolean - If Hex or NOT
@return: List - List of colors (Name or Hex)
'''
def GetHeatColorList(pTotColor, boolHex):
ColorList = []
noList = list()
TotalColorList = 20 # Total of colors available
if (pTotColor == 1):
if boolHex:
ColorList.append(Get_Hex_HeatColor(0))
else:
ColorList.append(Get_Pymol_HeatColor(0))
elif (pTotColor > 1) and (pTotColor < 21):
noList = CreateNoList(pTotColor, TotalColorList)
if boolHex:
for no in noList:
ColorList.append(Get_Hex_HeatColor(no))
else:
for no in noList:
ColorList.append(Get_Pymol_HeatColor(no))
else: # Number of color displayed higher then 20
if boolHex:
for i in range(0, pTotColor):
ColorList.append(Get_Hex_HeatColor(i))
else:
for i in range(0, pTotColor):
ColorList.append(Get_Pymol_HeatColor(i))
return ColorList
'''
@summary: CreateNoList: Create a list of number to get well repartitioned color list.
@param pTotColor: Integer
@param pTotalColorList: Integer
@return: noList - List of numbers
'''
def CreateNoList(pTotColor, pTotalColorList):
noList = list()
Modulo = (pTotalColorList-1) % (pTotColor-1)
Partition = (pTotalColorList-Modulo-1)/ (pTotColor-1)
stepStart = 0
stepEnd = pTotalColorList - 1
for i in range(0, pTotColor):
if ((i % 2) == 0):
noList.append(stepStart)
stepStart = stepStart + Partition
else:
noList.append(stepEnd)
stepEnd = stepEnd - Partition
noList.sort()
return [ int(i) for i in noList ]