1
- '''
2
- See more here: http://www.pymolwiki.org/index.php/color_by_conservation
1
+ from pymol import cmd , CmdException
3
2
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
13
3
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
18
8
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
21
18
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
+ '''
22
23
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." )
29
26
30
- r = cmd .get_raw_alignment (aln )
27
+ r = _self .get_raw_alignment (aln )
31
28
32
29
if names == ():
33
30
known_objs = []
@@ -48,12 +45,14 @@ def color_by_conservation(aln, names=(), color="rainbow", as_putty=0, _self=cmd)
48
45
for y in af :
49
46
_self .alter ("%s and index %s" % (y [0 ], y [1 ]), "b=c" , space = {'c' : c })
50
47
51
- if as_putty != 0 :
48
+ if int ( as_putty ) != 0 :
52
49
for obj in known_objs :
53
50
_self .show_as ("cartoon" , "%s" % obj )
54
51
_self .cartoon ("putty" , "%s" % obj )
52
+
53
+ if color is not None :
54
+ for obj in known_objs :
55
55
_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