-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseq_diff.py
72 lines (53 loc) · 2.15 KB
/
seq_diff.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
# rlc color_b.py version 6.0
import colorsys,sys
from pymol import cmd
# main function called from within PyMOL
def seq_diff(obj1, obj2, doColor=False):
if cmd.count_atoms(obj1+' and name CA') == 0:
print('%s is empty' % obj1)
return
if cmd.count_atoms(obj2+' and name CA') == 0:
print('%s is empty' % obj2)
return
if cmd.count_atoms(obj1+' and name CA') != cmd.count_atoms(obj2+' and name CA'):
print('Selections have different number of residues.')
return
stored.resn1, stored.resn2 = [], []
stored.resi1, stored.resi2 = [], []
stored.chain1, stored.chain2 = [], []
cmd.iterate(obj1 + ' and name CA', 'stored.resn1.append(resn)')
cmd.iterate(obj2 + ' and name CA', 'stored.resn2.append(resn)')
cmd.iterate(obj1 + ' and name CA', 'stored.resi1.append(resi)')
cmd.iterate(obj2 + ' and name CA', 'stored.resi2.append(resi)')
cmd.iterate(obj1 + ' and name CA', 'stored.chain1.append(chain)')
cmd.iterate(obj2 + ' and name CA', 'stored.chain2.append(chain)')
#print len(stored.resn1)
mutant_selection = []
for n1, n2, i1, i2, c1, c2 in zip(stored.resn1, stored.resn2, stored.resi1, stored.resi2, stored.chain1, stored.chain2):
if c1 == '':
c1 = '""'
if c2 == '':
c2 = '""'
#print 'Resi1: '+i1
#print 'Resi2: '+i2
if n1 != n2:
#print 'Mutation at resi: '+i2
mutant_selection.append('%s and resi %s and chain %s' % (obj2, i2, c2))
if mutant_selection == '':
print('No mutations found')
#raise CmdException
total_selection = ''
total_color = ''
for m in mutant_selection:
total_selection += '('+m+') or '
total_color += '('+m+' and name C*) or '
total_selection = total_selection[:-4]
total_color = total_color[:-4]
cmd.select("%s_diff" % (obj2), total_selection )
if doColor:
cmd.color('%s' % doColor,total_color)
#cmd.deselect()
cmd.extend("seq_diff",seq_diff)
cmd.auto_arg[0]['seq_diff'] = cmd.auto_arg[0]['align']
cmd.auto_arg[1]['seq_diff'] = cmd.auto_arg[1]['align']
# vi: ts=1:sw=4:smarttab:expandtab