Skip to content

Commit 9ed2717

Browse files
authored
Independent color and as_putty options for color_by_conservation.py (#145)
Independent color and as_putty options for color_by_conservation.py Now the option color and as_putty works independent of each other.
1 parent 1cb0eaf commit 9ed2717

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

color_by_conservation.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
1-
'''
2-
See more here: http://www.pymolwiki.org/index.php/color_by_conservation
1+
from pymol import cmd, CmdException
32

4-
PARAMETERS
5-
aln
6-
(string) the alignment object name
7-
names
8-
(list) a list of object names that are in the alignment;
9-
if (), then PyMOL will attempt to glean the names
10-
from the alignment object
11-
color
12-
(string) valid PyMOL spectrum name
133

14-
as_putty
15-
(0 or 1) if 0 display is not changed, else participating objects are shown
16-
as cartoon putty, colored by the 'color' field
17-
'''
4+
@cmd.extend
5+
def color_by_conservation(aln, names=(), color=None, as_putty=0, _self=cmd):
6+
'''
7+
See more here: http://www.pymolwiki.org/index.php/color_by_conservation
188
19-
from __future__ import print_function
20-
from pymol import cmd
9+
PARAMETERS
10+
aln
11+
(string) the alignment object name
12+
names
13+
(list) a list of object names that are in the alignment;
14+
if (), then PyMOL will attempt to glean the names
15+
from the alignment object
16+
color
17+
(string) valid PyMOL spectrum name
2118
19+
as_putty
20+
(0 or 1) if 0 display is not changed, else participating objects are shown
21+
as cartoon putty, colored by the 'color' field
22+
'''
2223

23-
def color_by_conservation(aln, names=(), color="rainbow", as_putty=0, _self=cmd):
24-
# PyMOL doesn't yet know about object:alignment
25-
# but we need to check that this exists or we might crash
26-
if _self.get_type(aln) not in ("object:", "object:alignment"):
27-
print("Error: Bad or incorrectly specified alignment object.")
28-
return None
24+
if _self.get_type(aln) != "object:alignment":
25+
raise CmdException("Error: Bad or incorrectly specified alignment object.")
2926

30-
r = cmd.get_raw_alignment(aln)
27+
r = _self.get_raw_alignment(aln)
3128

3229
if names == ():
3330
known_objs = []
@@ -48,12 +45,14 @@ def color_by_conservation(aln, names=(), color="rainbow", as_putty=0, _self=cmd)
4845
for y in af:
4946
_self.alter("%s and index %s" % (y[0], y[1]), "b=c", space={'c': c})
5047

51-
if as_putty != 0:
48+
if int(as_putty) != 0:
5249
for obj in known_objs:
5350
_self.show_as("cartoon", "%s" % obj)
5451
_self.cartoon("putty", "%s" % obj)
52+
53+
if color is not None:
54+
for obj in known_objs:
5555
_self.spectrum('b', color, obj)
56-
_self.sort()
57-
_self.rebuild()
58-
return None
59-
cmd.extend("color_by_conservation", color_by_conservation)
56+
57+
_self.sort()
58+
_self.rebuild()

0 commit comments

Comments
 (0)