-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbfacramp.py
96 lines (84 loc) · 3.63 KB
/
bfacramp.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
from pymol import cmd, stored, math
def global_bounds():
objects = cmd.get_object_list()
print('Inspecting',len(objects),'objects')
stored.bfacts=[]
for obj in objects:
cmd.iterate(obj, 'stored.bfacts.append(b)')
print(min(stored.bfacts),'to',max(stored.bfacts))
round_min_to_10 = 10*int(min(stored.bfacts)/10)
#round_max_to_10 = 10*round(max(stored.bfacts)/10)
round_max_to_10 = 10*math.ceil(max(stored.bfacts)/10)
return round_min_to_10, round_max_to_10
def Bramp(mol=None, order='rainbow'):
"""
mol = any object selection (within one single object though)
example: Bramp 1LVM and chain A
"""
objects = cmd.get_object_list()
if len(objects) == 1 and mol is None:
obj=objects[0]
elif mol in objects:
obj=cmd.get_object_list(mol)[0]
elif len(objects)>1 and mol is None:
print(f'More than one object. Please specify one')
return
else:
print(f'Could not find {mol} in the list of objects')
return
stored.bfacts=[]
cmd.iterate(obj, 'stored.bfacts.append(b)')
print(min(stored.bfacts),'to',max(stored.bfacts))
round_min_to_10 = 10*int(min(stored.bfacts)/10)
#round_max_to_10 = 10*round(max(stored.bfacts)/10)
round_max_to_10 = 10*math.ceil(max(stored.bfacts)/10)
if order == 'rainbow':
cmd.ramp_new(f'scalebar_{obj}', obj, [round_min_to_10,round_max_to_10], 'rainbow')
print(f'coloring {obj} by b-factor from {round_min_to_10} to {round_max_to_10}')
cmd.spectrum('b',selection=obj, minimum=round_min_to_10,maximum=round_max_to_10, palette='rainbow')
elif order == 'AF2':
colorlist = ['red','yellow','green','cyan','blue']
rgblist = [list(cmd.get_color_tuple(cc)) for cc in colorlist]
print('rgblist',rgblist)
cmd.ramp_new(f'scalebar_{obj}', obj, [round_min_to_10,round_max_to_10], rgblist)
mypalette = '_'.join(colorlist)
print('mypalette',mypalette)
print(f'coloring {obj} by b-factor from {round_min_to_10} to {round_max_to_10}')
cmd.spectrum('b',selection=obj, minimum=round_min_to_10,maximum=round_max_to_10, palette=mypalette)
else:
print('color order is not recognized')
return
cmd.recolor()
def BrampAll(order='rainbow'):
"""
example: BrampAll
"""
objects = cmd.get_object_list()
round_min_to_10, round_max_to_10 = global_bounds()
if order == 'rainbow':
cmd.ramp_new('Bscalebar', objects[0], [round_min_to_10,round_max_to_10], 'rainbow')
for obj in objects:
print(f'coloring {obj} by b-factor from {round_min_to_10} to {round_max_to_10}')
cmd.spectrum('b',selection=obj, minimum=round_min_to_10,maximum=round_max_to_10, palette='rainbow')
elif order == 'AF2':
colorlist = ['red','yellow','green','cyan','blue']
rgblist = [list(cmd.get_color_tuple(cc)) for cc in colorlist]
print('rgblist',rgblist)
mypalette = '_'.join(colorlist)
print('mypalette',mypalette)
cmd.ramp_new('Bscalebar', objects[0], [round_min_to_10,round_max_to_10], rgblist)
for obj in objects:
print(f'coloring {obj} by b-factor from {round_min_to_10} to {round_max_to_10}')
cmd.spectrum('b',selection=obj, minimum=round_min_to_10,maximum=round_max_to_10, palette=mypalette)
else:
print('color order is not recognized')
return
cmd.recolor()
def AFscalebar(mol=None):
Bramp(mol=mol, order='AF2')
def AFscalebarAll():
BrampAll(order='AF2')
cmd.extend("Bramp", Bramp);
cmd.extend("BrampAll", BrampAll);
cmd.extend("AFscalebar", AFscalebar);
cmd.extend("AFscalebarAll", AFscalebarAll);