|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
""" |
|
3
|
|
|
Quick reference: |
|
4
|
|
|
|
|
5
|
|
|
- clarna: show contacts classification of the selected fragment based on ClaRNA |
|
6
|
|
|
- ss: show secondary structure of the selection based on py3dna.py (3DNA (Lu, Olson 2003)) |
|
7
|
|
|
- ss_all: the same as ss() but for all objects |
|
8
|
|
|
- pdbsrc: show PDB content (source) of selection. |
|
9
|
|
|
- seq: show sequence of the selection |
|
10
|
|
|
- ino: represent ions as sphare and yellow inorganic, such us Mg |
|
11
|
|
|
- p: shortcut for putting a seq at the bottom. Pretty cool for screenshots with names of objects |
|
12
|
|
|
- spli: color snRNA of the spliceosome and bases according to identity U(blue), A(orange), G(red), C(forest) |
|
13
|
|
|
- rp: @todo |
|
14
|
|
|
- rs: @todo |
|
15
|
|
|
- rib: @todo |
|
16
|
|
|
- select br. all within 12 of resi 574 |
|
17
|
|
|
- |
|
18
|
|
|
If you want more, read for interesting functions https://daslab.stanford.edu/site_data/docs_pymol_rhiju.pdf |
|
19
|
|
|
""" |
|
20
|
|
|
# imports |
|
21
|
|
|
import tempfile |
|
22
|
|
|
import math |
|
23
|
|
|
import subprocess |
|
24
|
|
|
import os |
|
25
|
|
|
import sys |
|
26
|
|
|
|
|
27
|
|
|
import getpass |
|
28
|
|
|
user = getpass.getuser() |
|
29
|
|
|
|
|
30
|
|
|
try: |
|
31
|
|
|
from pymol import cmd |
|
32
|
|
|
except ImportError: |
|
33
|
|
|
print("PyMOL Python lib is missing") |
|
34
|
|
|
# sys.exit(0) |
|
35
|
|
|
|
|
36
|
|
|
import imp |
|
37
|
|
|
try: |
|
38
|
|
|
from rna_tools.rna_tools_lib import RNAStructure |
|
39
|
|
|
from rna_tools.tools.PyMOL4RNA import code_for_spl |
|
40
|
|
|
imp.reload(code_for_spl) |
|
41
|
|
|
from rna_tools.tools.PyMOL4RNA import code_for_color_spl |
|
42
|
|
|
imp.reload(code_for_color_spl) |
|
43
|
|
|
from rna_tools.tools.PyMOL4RNA import code_for_color_spl_objects |
|
44
|
|
|
imp.reload(code_for_color_spl_objects) |
|
45
|
|
|
import rna_tools |
|
46
|
|
|
RNA_TOOLS_PATH = rna_tools.rna_tools_lib.get_rna_tools_path() |
|
47
|
|
|
except ImportError: |
|
48
|
|
|
print("rna_tools lib is missing") |
|
49
|
|
|
RNA_TOOLS_PATH = '' |
|
50
|
|
|
|
|
51
|
|
|
try: |
|
52
|
|
|
RNA_TOOLS_PATH |
|
53
|
|
|
EXECUTABLE |
|
|
|
|
|
|
54
|
|
|
except NameError: |
|
55
|
|
|
EXECUTABLE="/bin/zsh" |
|
56
|
|
|
SOURCE="" |
|
57
|
|
|
|
|
58
|
|
|
try: |
|
59
|
|
|
cmd.set('cartoon_gap_cutoff', 0) |
|
60
|
|
|
except: |
|
61
|
|
|
pass |
|
62
|
|
|
|
|
63
|
|
|
def exe(cmd, verbose=False): |
|
64
|
|
|
"""Helper function to run cmd. Using in this Python module.""" |
|
65
|
|
|
if verbose: print('cmd:' + cmd) |
|
66
|
|
|
o = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
|
67
|
|
|
executable=EXECUTABLE) |
|
68
|
|
|
out = o.stdout.read().strip().decode() |
|
69
|
|
|
err = o.stderr.read().strip().decode() |
|
70
|
|
|
return out, err |
|
71
|
|
|
|
|
72
|
|
|
def color_protein(): |
|
73
|
|
|
cmd.do("color blue, resn ARG+LYS+HIS") |
|
74
|
|
|
cmd.do("color red, resn ASP+GLU") |
|
75
|
|
|
cmd.do("color green, resn GLY+ALA+VAL+LEU+ILE+MET+PHE") |
|
76
|
|
|
cmd.do("color yellow, resn TYR+TRP") |
|
77
|
|
|
cmd.do("color forest, resn SER+THR+CYS+ASN+GLN") |
|
78
|
|
|
cmd.do("color pink, resn PRO") |
|
79
|
|
|
|
|
80
|
|
|
cmd.extend('cp', color_protein) |
|
81
|
|
|
|
|
82
|
|
|
def save_transformed(object, file): |
|
83
|
|
|
"""Saves the molecule with coordinates from the current orientation. |
|
84
|
|
|
|
|
85
|
|
|
Args: |
|
86
|
|
|
object (string): PyMOL name |
|
87
|
|
|
file (string): a file name to output file |
|
88
|
|
|
|
|
89
|
|
|
Example:: |
|
90
|
|
|
|
|
91
|
|
|
PyMOL>save_transformed 6bk8_RNA_only_Oriented, 6bk8_RNA_only_Oriented.pdb |
|
92
|
|
|
|
|
93
|
|
|
Source: <https://pymolwiki.org/index.php/Modeling_and_Editing_Structures> |
|
94
|
|
|
""" |
|
95
|
|
|
m = cmd.get_view(0) |
|
96
|
|
|
ttt = [m[0], m[1], m[2], 0.0, |
|
97
|
|
|
m[3], m[4], m[5], 0.0, |
|
98
|
|
|
m[6], m[7], m[8], 0.0, |
|
99
|
|
|
0.0, 0.0, 0.0, 1.0] |
|
100
|
|
|
cmd.transform_object(object,ttt,transpose=1) |
|
101
|
|
|
cmd.save(file,object) |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
def color_by_text(txt): |
|
105
|
|
|
"""Helper function used for color-coding based on residue indexes ranges.""" |
|
106
|
|
|
for t in txt.strip().split('\n'): |
|
107
|
|
|
print(t) |
|
108
|
|
|
color, resi = t.replace('color ', '').split(',') |
|
109
|
|
|
print((color, resi)) |
|
110
|
|
|
cmd.color(color.strip(), resi.strip()) |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
def rp(): |
|
114
|
|
|
"""Represent your RNA.""" |
|
115
|
|
|
cmd.hide("sticks", "all") |
|
116
|
|
|
cmd.hide("lines", "all") |
|
117
|
|
|
cmd.show("cartoon", "all") |
|
118
|
|
|
cmd.set("cartoon_ring_mode", 3) |
|
119
|
|
|
cmd.set("cartoon_ring_finder", 2) |
|
120
|
|
|
cmd.set("cartoon_ladder_mode", 1) |
|
121
|
|
|
|
|
122
|
|
|
def show_all_at_once(): |
|
123
|
|
|
cmd.set('states', 'on') |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
def rp06(): |
|
127
|
|
|
txt = """color black, all |
|
128
|
|
|
color pink, resi 2-10+163-170 |
|
129
|
|
|
color grey, resi 12-33 |
|
130
|
|
|
color green, resi 40-41 |
|
131
|
|
|
color green, resi 161-162 |
|
132
|
|
|
color orange, resi 45-61 |
|
133
|
|
|
color green, resi 64-73 |
|
134
|
|
|
color blue, resi 74-155 |
|
135
|
|
|
color cyan, resn B1Z""" |
|
136
|
|
|
for t in txt.split('\n'): |
|
137
|
|
|
color, resi = t.replace('color ', '').split(',') |
|
138
|
|
|
print(color, resi) |
|
139
|
|
|
cmd.color(color.strip(), resi.strip()) |
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
def grid_on(): |
|
143
|
|
|
cmd.set('grid_mode', 1) |
|
144
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
def grid_off(): |
|
147
|
|
|
cmd.set('grid_mode', 0) |
|
148
|
|
|
|
|
149
|
|
|
|
|
150
|
|
|
def rp14(): |
|
151
|
|
|
"""color black; # everything |
|
152
|
|
|
color blue, resi 1-5+55-59; # p1 |
|
153
|
|
|
color green, resi 7-11+16-20; # p2 |
|
154
|
|
|
color magenta, resi 23+60; # pk |
|
155
|
|
|
color yellow, resi 29-34+45-50; # p3 |
|
156
|
|
|
color grey, resi 24-28+51-54; # e-loop |
|
157
|
|
|
color red, resi 6+21+22+24+25+28+52+54; # higly conserved""" |
|
158
|
|
|
#color blue, resi 5+55 |
|
159
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
txt ="""color black, all |
|
162
|
|
|
color red, resi 1-5+55-59 |
|
163
|
|
|
color blue, resi 1-5+55-59; # p1 |
|
164
|
|
|
color green, resi 7-11+16-20 |
|
165
|
|
|
color magenta, resi 23+60 |
|
166
|
|
|
color yellow, resi 29-34+45-50 |
|
167
|
|
|
color grey, resi 24-28+51-54 |
|
168
|
|
|
color red, resi 6+21+22""" |
|
169
|
|
|
for t in txt.split('\n'): |
|
170
|
|
|
color, resi = t.replace('color ', '').split(',') |
|
171
|
|
|
print(color, resi) |
|
172
|
|
|
cmd.color(color.strip(), resi.strip()) |
|
173
|
|
|
|
|
174
|
|
|
def rp14s(): |
|
175
|
|
|
"""color with Baker's SHAPE data for rp14!""" |
|
176
|
|
|
txt = """ |
|
177
|
|
|
color yellow, resi 12-15+25-29+35-44 |
|
178
|
|
|
color red, resi 21-24+53+54+60 |
|
179
|
|
|
""" |
|
180
|
|
|
color_by_text(txt) |
|
181
|
|
|
|
|
182
|
|
|
def rs(): |
|
183
|
|
|
""" The function creates super-cool cartoon-like RNA and colors each structure as a rainbow. |
|
184
|
|
|
Good to view aligned structures in a grid. |
|
185
|
|
|
|
|
186
|
|
|
.. image:: ../../rna_tools/utils/PyMOL4RNA/doc/rs.png |
|
187
|
|
|
""" |
|
188
|
|
|
cmd.hide("sticks", "all") |
|
189
|
|
|
cmd.hide("lines", "all") |
|
190
|
|
|
cmd.show("cartoon", "all") |
|
191
|
|
|
cmd.set("cartoon_ring_mode", 3) |
|
192
|
|
|
cmd.set("cartoon_ring_finder", 2) |
|
193
|
|
|
cmd.set("cartoon_ladder_mode", 2) |
|
194
|
|
|
cmd.set("cartoon_ring_transparency", 0.30) |
|
195
|
|
|
cmd.spectrum() |
|
196
|
|
|
|
|
197
|
|
|
obj_list = cmd.get_names('objects') |
|
198
|
|
|
|
|
199
|
|
|
colours = ['rainbow'] |
|
200
|
|
|
ncolours = len(colours) |
|
201
|
|
|
# Loop over objects |
|
202
|
|
|
i = 0 |
|
203
|
|
|
for obj in obj_list: |
|
204
|
|
|
print(" ", obj, colours[i]) |
|
205
|
|
|
cmd.spectrum('count', colours[i], obj) |
|
206
|
|
|
i = i+1 |
|
207
|
|
|
if(i == ncolours): |
|
208
|
|
|
i = 0 |
|
209
|
|
|
|
|
210
|
|
|
|
|
211
|
|
|
|
|
212
|
|
|
def align_all(): |
|
213
|
|
|
""" |
|
214
|
|
|
This returns a list with 7 items: |
|
215
|
|
|
|
|
216
|
|
|
RMSD after refinement |
|
217
|
|
|
Number of aligned atoms after refinement |
|
218
|
|
|
Number of refinement cycles |
|
219
|
|
|
RMSD before refinement |
|
220
|
|
|
Number of aligned atoms before refinement |
|
221
|
|
|
Raw alignment score |
|
222
|
|
|
Number of residues aligned |
|
223
|
|
|
|
|
224
|
|
|
old version: |
|
225
|
|
|
|
|
226
|
|
|
1_solution_0_rpr 1_santalucia_1_rpr 5.60600471496582 958 4 5.763411521911621 974 416.0 46 -- RMSD 5.76 of 46 residues |
|
227
|
|
|
|
|
228
|
|
|
""" |
|
229
|
|
|
molecules = cmd.get_names_of_type("object:molecule") |
|
230
|
|
|
ref = molecules.pop(0) |
|
231
|
|
|
report = [] |
|
232
|
|
|
print('Ref Model RaR #AA CoR RbR #AbR RS AR') |
|
233
|
|
|
for molecule in molecules: |
|
234
|
|
|
values = cmd.align(molecule, ref) |
|
235
|
|
|
print(ref[:20].ljust(20), molecule[:20].ljust(20), |
|
236
|
|
|
str(round(values[0], 2)).ljust(4), |
|
237
|
|
|
str(round(values[1], 2)).ljust(4), |
|
238
|
|
|
str(round(values[2], 2)).ljust(4), |
|
239
|
|
|
str(round(values[3], 2)).ljust(4), |
|
240
|
|
|
str(round(values[4], 2)).ljust(4), |
|
241
|
|
|
str(round(values[5])).ljust(4), |
|
242
|
|
|
str(round(values[6], 2)).ljust(4), |
|
243
|
|
|
) |
|
244
|
|
|
#' '.join([str(v) for v in values]), '-- RMSD', round(values[3], 2), ' of ', values[6], 'residues') |
|
245
|
|
|
#print(ref, molecule, 'RMSD: ', round(values[3], 2), ' of ', values[6], 'residues') |
|
246
|
|
|
report.append([ref, molecule, values[3], values[6]]) |
|
247
|
|
|
|
|
248
|
|
|
for l in report: |
|
249
|
|
|
if not l[1].startswith('_align'): |
|
250
|
|
|
# rp14_5ddp_bound_clean_ligand rp14_farna_eloop_nol2fixed_cst.out.1 RMSD: 4.49360132217 of 52 residues |
|
251
|
|
|
if l[1] not in ['sele', 'rov_pc']: # skip them |
|
252
|
|
|
#print(l[0], l[1], 'RMSD:', round(l[2],2), str(l[3]) + 'nt') |
|
253
|
|
|
pass |
|
254
|
|
|
#f.write(i[0] + '-' + i[1] + ' ' + str(i[2]) + '\n') |
|
255
|
|
|
|
|
256
|
|
|
cmd.extend('align_all', align_all) |
|
257
|
|
|
|
|
258
|
|
|
def save_each_object(folder='', prefix=''): |
|
259
|
|
|
""" |
|
260
|
|
|
|
|
261
|
|
|
Usage:: |
|
262
|
|
|
|
|
263
|
|
|
save_each_object /Users/magnus/work/spliceosome/PyMOL4Spliceosome/chains/yB_5zwo, yB_5zwo_ |
|
264
|
|
|
|
|
265
|
|
|
p = 'yP_6exn' # yP_5ylz' #yI_5y88' # yE_6n7r' |
|
266
|
|
|
pth = '/Users/magnus/work/spliceosome/PyMOL4Spliceosome/chains/' |
|
267
|
|
|
save_each_object(pth + p, p + '_') |
|
268
|
|
|
|
|
269
|
|
|
See the application here <https://github.com/mmagnus/PyMOL4Spliceosome/releases/tag/v0.32> |
|
270
|
|
|
|
|
271
|
|
|
.. todo:: add some way to select which objects to use |
|
272
|
|
|
""" |
|
273
|
|
|
obj_list = cmd.get_names('objects') |
|
274
|
|
|
for o in obj_list: |
|
275
|
|
|
if folder: |
|
276
|
|
|
folder += '/' |
|
277
|
|
|
fn = folder + prefix.strip() + o.strip() + '.pdb' |
|
278
|
|
|
cmd.save(fn, o) |
|
279
|
|
|
|
|
280
|
|
|
cmd.extend('save_each_object', save_each_object) |
|
281
|
|
|
|
|
282
|
|
|
def rcomp(): |
|
283
|
|
|
"""RNA like in papers ;-) |
|
284
|
|
|
|
|
285
|
|
|
Similar to rc() but this time it colors each (and every) structure in different colour. |
|
286
|
|
|
Great on viewing-comparing superimposed structures. |
|
287
|
|
|
|
|
288
|
|
|
""" |
|
289
|
|
|
cmd.hide("sticks", "all") |
|
290
|
|
|
cmd.hide("lines", "all") |
|
291
|
|
|
cmd.show("cartoon", "all") |
|
292
|
|
|
cmd.set("cartoon_ring_mode", 3) |
|
293
|
|
|
cmd.set("cartoon_ring_finder", 2) |
|
294
|
|
|
cmd.set("cartoon_ladder_mode", 2) |
|
295
|
|
|
cmd.set("cartoon_ring_transparency", 0.30) |
|
296
|
|
|
|
|
297
|
|
|
obj_list = cmd.get_names('objects') |
|
298
|
|
|
|
|
299
|
|
|
colours = ['red', 'green', 'blue', 'yellow', 'violet', 'cyan', \ |
|
300
|
|
|
'salmon', 'lime', 'pink', 'slate', 'magenta', 'orange', 'marine', \ |
|
301
|
|
|
'olive', 'purple', 'teal', 'forest', 'firebrick', 'chocolate', \ |
|
302
|
|
|
'wheat', 'white', 'grey' ] |
|
303
|
|
|
ncolours = len(colours) |
|
304
|
|
|
|
|
305
|
|
|
# Loop over objects |
|
306
|
|
|
i = 0 |
|
307
|
|
|
for obj in obj_list: |
|
308
|
|
|
print(" ", obj, colours[i]) |
|
309
|
|
|
cmd.color(colours[i], obj) |
|
310
|
|
|
i = i+1 |
|
311
|
|
|
if(i == ncolours): |
|
312
|
|
|
i = 0 |
|
313
|
|
|
|
|
314
|
|
|
|
|
315
|
|
|
def align_all2( subset = [] ): |
|
316
|
|
|
""" |
|
317
|
|
|
Superimpose all open models onto the first one. |
|
318
|
|
|
This may not work well with selections. |
|
319
|
|
|
|
|
320
|
|
|
This function is probably taken from https://daslab.stanford.edu/site_data/docs_pymol_rhiju.pdf |
|
321
|
|
|
""" |
|
322
|
|
|
print("""This returns a list with 7 items: |
|
323
|
|
|
|
|
324
|
|
|
RMSD after refinement |
|
325
|
|
|
Number of aligned atoms after refinement |
|
326
|
|
|
Number of refinement cycles |
|
327
|
|
|
RMSD before refinement |
|
328
|
|
|
Number of aligned atoms before refinement |
|
329
|
|
|
Raw alignment score |
|
330
|
|
|
Number of residues aligned """) |
|
331
|
|
|
|
|
332
|
|
|
AllObj=cmd.get_names("all") |
|
333
|
|
|
for x in AllObj[1:]: |
|
334
|
|
|
#print(AllObj[0],x) |
|
335
|
|
|
subset_tag = '' |
|
336
|
|
|
if isinstance( subset, int ): |
|
337
|
|
|
subset_tag = ' and resi %d' % subset |
|
338
|
|
|
elif isinstance( subset, list ) and len( subset ) > 0: |
|
339
|
|
|
subset_tag = ' and resi %d' % (subset[0]) |
|
340
|
|
|
for m in range( 1,len(subset)): subset_tag += '+%d' % subset[m] |
|
341
|
|
|
elif isinstance( subset, str ) and len( subset ) > 0: |
|
342
|
|
|
subset_tag = ' and %s' % subset |
|
343
|
|
|
values = cmd.align(x+subset_tag,AllObj[0]+subset_tag) |
|
344
|
|
|
print(AllObj[0], x, ' '.join([str(v) for v in values]), '-- RMSD', values[3], ' of ', values[6], 'residues') |
|
345
|
|
|
cmd.zoom() |
|
346
|
|
|
|
|
347
|
|
|
|
|
348
|
|
|
def pdb(): |
|
349
|
|
|
"""Get PDB content of selection. |
|
350
|
|
|
|
|
351
|
|
|
.. image:: ../../rna_tools/utils/PyMOL4RNA/doc/pdb.png""" |
|
352
|
|
|
tmpfn = '/tmp/pymol_get_pdb.pdb' |
|
353
|
|
|
cmd.save(tmpfn, '(sele)') |
|
354
|
|
|
s = RNAStructure(tmpfn) |
|
355
|
|
|
for l in s.lines: |
|
356
|
|
|
print(l) |
|
357
|
|
|
|
|
358
|
|
|
|
|
359
|
|
|
def x3dna(): |
|
360
|
|
|
f = tempfile.NamedTemporaryFile(delete=False) # True) |
|
361
|
|
|
#cmd.save(f.name + '.pdb', '(backbone_)') |
|
362
|
|
|
cmd.save(f.name + '.pdb', '(sele)') |
|
363
|
|
|
out, err = exe("rna_x3dna.py --show-log " + f.name + ".pdb ") |
|
364
|
|
|
print('\n'.join(out.split('\n')[1:])) # to remove first line of py3dna /tmp/xxx |
|
365
|
|
|
if err: |
|
366
|
|
|
print(err) |
|
367
|
|
|
f.close() |
|
368
|
|
|
|
|
369
|
|
|
def clarna(): |
|
370
|
|
|
"""Get contacts classification of the selected fragment based on ClaRNA. |
|
371
|
|
|
|
|
372
|
|
|
.. image:: ../../rna_tools/tools/PyMOL4RNA/doc/clarna.png |
|
373
|
|
|
""" |
|
374
|
|
|
AllObj = cmd.get_names("objects") |
|
375
|
|
|
# print AllObj |
|
376
|
|
|
for name in AllObj[:]: |
|
377
|
|
|
print(name + ' ' + '-' * (70 - len(name))) |
|
378
|
|
|
f = tempfile.NamedTemporaryFile(delete=False) # True) |
|
379
|
|
|
#cmd.save(f.name + '.pdb', '(backbone_)') |
|
380
|
|
|
cmd.save(f.name + '.pdb', '(sele) and "' + name + '"') |
|
381
|
|
|
CLARNA_RUN = 'rna_clarna_run.py' |
|
382
|
|
|
out, err = exe(SOURCE + " && " + CLARNA_RUN + " -ipdb " + f.name + '.pdb -bp+stack') |
|
383
|
|
|
print('\n'.join(out.split('\n')[1:])) # to remove first line of py3dna /tmp/xxx |
|
384
|
|
|
if err: |
|
385
|
|
|
print(err) |
|
386
|
|
|
f.close() |
|
387
|
|
|
|
|
388
|
|
|
|
|
389
|
|
|
def seq(): |
|
390
|
|
|
"""Get sequence of the selected fragment using ``rna_pdb_toolsx.py --get_seq ``. |
|
391
|
|
|
|
|
392
|
|
|
.. image:: ../../rna_tools/utils/PyMOL4RNA/doc/ss.png |
|
393
|
|
|
""" |
|
394
|
|
|
f = tempfile.NamedTemporaryFile(delete=False) # True) |
|
395
|
|
|
cmd.save(f.name, '(sele)') |
|
396
|
|
|
out, err = exe('source ~/.zshrc && ' + RNA_TOOLS_PATH + '/bin/rna_pdb_toolsx.py --get_seq ' + f.name) |
|
397
|
|
|
print(out) |
|
398
|
|
|
if err: |
|
399
|
|
|
print(err) |
|
400
|
|
|
f.close() |
|
401
|
|
|
|
|
402
|
|
|
def ss(): |
|
403
|
|
|
"""Get Secondary Structure of (sele) based on py3dna.py. |
|
404
|
|
|
|
|
405
|
|
|
.. image:: ../../rna_tools/utils/PyMOL4RNA/doc/ss.png |
|
406
|
|
|
""" |
|
407
|
|
|
f = tempfile.NamedTemporaryFile(delete=False) # True) |
|
408
|
|
|
cmd.save(f.name, '(sele)') |
|
409
|
|
|
out, err = exe(RNA_TOOLS_PATH + '/bin/rna_x3dna.py ' + f.name) |
|
410
|
|
|
print('\n'.join(out.split('\n')[2:])) # to remove first line of py3dna /tmp/xxx |
|
411
|
|
|
if err: |
|
412
|
|
|
print(err) |
|
413
|
|
|
f.close() |
|
414
|
|
|
|
|
415
|
|
|
|
|
416
|
|
|
def ss_all(): |
|
417
|
|
|
"""The same as ss() but for all objects.""" |
|
418
|
|
|
subset = "*" |
|
419
|
|
|
AllObj = cmd.get_names("all") |
|
420
|
|
|
# print AllObj |
|
421
|
|
|
for name in AllObj[:]: |
|
422
|
|
|
if not name.startswith('_align'): |
|
423
|
|
|
print('> ' + name) |
|
424
|
|
|
f = tempfile.NamedTemporaryFile(delete=False) # True) |
|
425
|
|
|
cmd.save(f.name, name) |
|
426
|
|
|
out, err = exe(RNA_TOOLS_PATH + '/bin/rna_x3dna.py ' + f.name) |
|
427
|
|
|
print('\n'.join(out.split('\n')[2:])) # to remove first line of py3dna /tmp/xxx |
|
428
|
|
|
# hide this line: is >tmpGCszi7 nts=4 [tmpGCszi7] -- secondary structure derived by DSSR |
|
429
|
|
|
if err: |
|
430
|
|
|
print(err) |
|
431
|
|
|
f.close() |
|
432
|
|
|
print('-- secondary structure derived by DSSR') |
|
433
|
|
|
|
|
434
|
|
|
|
|
435
|
|
|
def p(): |
|
436
|
|
|
"""A shortcut for putting a seq at the bottom. Pretty cool for screenshots with names of objects. |
|
437
|
|
|
|
|
438
|
|
|
.. image:: ../../rna_tools/utils/PyMOL4RNA/doc/p.png |
|
439
|
|
|
""" |
|
440
|
|
|
cmd.set("seq_view_format", 4) |
|
441
|
|
|
cmd.set("seq_view", 1) |
|
442
|
|
|
cmd.set("seq_view_location", 1) |
|
443
|
|
|
cmd.set("seq_view_overlay", 1) |
|
444
|
|
|
|
|
445
|
|
|
|
|
446
|
|
|
def rna_cartoon(): |
|
447
|
|
|
"""http://www-cryst.bioc.cam.ac.uk/members/zbyszek/figures_pymol |
|
448
|
|
|
|
|
449
|
|
|
.. image:: ../pngs/rna_cartoon.png |
|
450
|
|
|
""" |
|
451
|
|
|
cmd.set("cartoon_ring_mode", 3) |
|
452
|
|
|
cmd.set("cartoon_ring_finder", 1) |
|
453
|
|
|
cmd.set("cartoon_ladder_mode", 1) |
|
454
|
|
|
cmd.set("cartoon_nucleic_acid_mode", 4) |
|
455
|
|
|
cmd.set("cartoon_ring_transparency", 0.5) |
|
456
|
|
|
|
|
457
|
|
|
|
|
458
|
|
|
def rp17(): |
|
459
|
|
|
"""Color-coding for secondary structure elements for the RNA Puzzle 17. |
|
460
|
|
|
|
|
461
|
|
|
For the variant:: |
|
462
|
|
|
|
|
463
|
|
|
CGUGGUUAGGGCCACGUUAAAUAGUUGCUUAAGCCCUAAGCGUUGAUAAAUAUCAGGUGCAA |
|
464
|
|
|
((((.[[[[[[.))))........((((.....]]]]]]...(((((....)))))..)))) |
|
465
|
|
|
# len 62-nt |
|
466
|
|
|
|
|
467
|
|
|
.. image:: ../../rna_tools/tools/PyMOL4RNA/doc/rna.png |
|
468
|
|
|
""" |
|
469
|
|
|
txt = """color forest, resi 1-5+12-16; # p1 |
|
470
|
|
|
color magenta, resi 6-11+34-39; |
|
471
|
|
|
color grey, resi 17-24; |
|
472
|
|
|
color marine, resi 25-28+59-62; |
|
473
|
|
|
color deepblue, resi 29-33+40-42; |
|
474
|
|
|
color orange, resi 44-47+48-56; |
|
475
|
|
|
color yellow, resi 57-58; |
|
476
|
|
|
color red, resi 19+20+21; |
|
477
|
|
|
""" |
|
478
|
|
|
color_by_text(txt) |
|
479
|
|
|
|
|
480
|
|
|
def rp17csrv(): |
|
481
|
|
|
"""Color-coding for secondary structure elements for the RNA Puzzle 17. |
|
482
|
|
|
|
|
483
|
|
|
For the variant:: |
|
484
|
|
|
|
|
485
|
|
|
CGUGGUUAGGGCCACGUUAAAUAGUUGCUUAAGCCCUAAGCGUUGAUAAAUAUCAGGUGCAA |
|
486
|
|
|
((((.[[[[[[.))))........((((.....]]]]]]...(((((....)))))..)))) |
|
487
|
|
|
# len 62-nt |
|
488
|
|
|
|
|
489
|
|
|
.. image:: ../../rna_tools/utils/PyMOL4RNA/doc/rna.png |
|
490
|
|
|
""" |
|
491
|
|
|
txt = """color forest, resi 1-5+12-16; # p1 |
|
492
|
|
|
color magenta, resi 6-11+34-39; |
|
493
|
|
|
color grey, resi 17-24; |
|
494
|
|
|
color marine, resi 25-28+59-62; |
|
495
|
|
|
color deepblue, resi 29-33+40-42; |
|
496
|
|
|
color orange, resi 44-47+48-56; |
|
497
|
|
|
color yellow, resi 57-58; |
|
498
|
|
|
color red, resi 5+19+20+21+31+32+33+40+41+42 |
|
499
|
|
|
""" |
|
500
|
|
|
color_by_text(txt) |
|
501
|
|
|
|
|
502
|
|
|
|
|
503
|
|
|
|
|
504
|
|
|
def rp172(): |
|
505
|
|
|
"""Color-coding for secondary structure elements for the RNA Puzzle 17. |
|
506
|
|
|
|
|
507
|
|
|
For the variant:: |
|
508
|
|
|
|
|
509
|
|
|
CGUGGUUAGGGCCACGUUAAAUAGUUGCUUAAGCCCUAAGCGUUGAUAUCAGGUGCAA |
|
510
|
|
|
((((.[[[[[[.))))........((((.....]]]]]]...((((()))))..)))) |
|
511
|
|
|
# len 58-nt |
|
512
|
|
|
|
|
513
|
|
|
See rp17() |
|
514
|
|
|
""" |
|
515
|
|
|
|
|
516
|
|
|
txt = """color forest, resi 1-5+12-16; # p1 |
|
517
|
|
|
color magenta, resi 6-11+34-39 |
|
518
|
|
|
color grey, resi 17-24 |
|
519
|
|
|
color marine, resi 25-28+55-58 |
|
520
|
|
|
color deepblue, resi 29-33+40-42; |
|
521
|
|
|
color orange, resi 43-47+48-52; |
|
522
|
|
|
color yellow, resi 53-54; |
|
523
|
|
|
color red, resi 19+20+21; |
|
524
|
|
|
""" |
|
525
|
|
|
color_by_text(txt) |
|
526
|
|
|
|
|
527
|
|
|
def color_aa_types(): |
|
528
|
|
|
"""Color aminoacides types like in Cider (http://pappulab.wustl.edu/CIDER/)""" |
|
529
|
|
|
txt = """ |
|
530
|
|
|
color gray70, resn Ala+Ile+Leu+Met+Phe+Trp+Val #hydrophobic |
|
531
|
|
|
color yellow, resn Tyr+Trp #aromatic |
|
532
|
|
|
color blue, resn Arg+Lys+His # positive |
|
533
|
|
|
color forest, resn GLN+SER+GLY+thr |
|
534
|
|
|
color pink, resn PRO # pro |
|
535
|
|
|
color red, resn GLU+asp # """ |
|
536
|
|
|
print("""color (according to) amino-acids types) |
|
537
|
|
|
hydrohobic (gray) Ala+Ile+Leu+Met+Phe+Trp+Val |
|
538
|
|
|
aromatic (yellow) Tyr+Trp |
|
539
|
|
|
positive (blue) Arg+Lys+His |
|
540
|
|
|
polar (forest) Gln+Ser+Glu+Thr |
|
541
|
|
|
negative (red) Glu+Asp |
|
542
|
|
|
prolina ;) (pink) Pro""") |
|
543
|
|
|
color_by_text(txt) |
|
544
|
|
|
|
|
545
|
|
|
|
|
546
|
|
View Code Duplication |
def color_obj(rainbow=0): |
|
|
|
|
|
|
547
|
|
|
|
|
548
|
|
|
""" |
|
549
|
|
|
stolen from :) |
|
550
|
|
|
AUTHOR |
|
551
|
|
|
Gareth Stockwell |
|
552
|
|
|
|
|
553
|
|
|
USAGE |
|
554
|
|
|
color_obj(rainbow=0) |
|
555
|
|
|
|
|
556
|
|
|
This function colours each object currently in the PyMOL heirarchy |
|
557
|
|
|
with a different colour. Colours used are either the 22 named |
|
558
|
|
|
colours used by PyMOL (in which case the 23rd object, if it exists, |
|
559
|
|
|
gets the same colour as the first), or are the colours of the rainbow |
|
560
|
|
|
|
|
561
|
|
|
""" |
|
562
|
|
|
|
|
563
|
|
|
# Process arguments |
|
564
|
|
|
rainbow = int(rainbow) |
|
565
|
|
|
|
|
566
|
|
|
# Get names of all PyMOL objects |
|
567
|
|
|
obj_list = cmd.get_names('objects') |
|
568
|
|
|
|
|
569
|
|
|
if rainbow: |
|
570
|
|
|
|
|
571
|
|
|
print("\nColouring objects as rainbow\n") |
|
572
|
|
|
|
|
573
|
|
|
nobj = len(obj_list) |
|
574
|
|
|
|
|
575
|
|
|
# Create colours starting at blue(240) to red(0), using intervals |
|
576
|
|
|
# of 240/(nobj-1) |
|
577
|
|
|
for j in range(nobj): |
|
578
|
|
|
hsv = (240-j*240/(nobj-1), 1, 1) |
|
579
|
|
|
# Convert to RGB |
|
580
|
|
|
rgb = hsv_to_rgb(hsv) |
|
|
|
|
|
|
581
|
|
|
# Define the new colour |
|
582
|
|
|
cmd.set_color("col" + str(j), rgb) |
|
583
|
|
|
print(obj_list[j], rgb) |
|
584
|
|
|
# Colour the object |
|
585
|
|
|
cmd.color("col" + str(j), obj_list[j]) |
|
586
|
|
|
|
|
587
|
|
|
else: |
|
588
|
|
|
# List of available colours |
|
589
|
|
|
colours = ['red', 'green', 'blue', 'yellow', 'violet', 'cyan', \ |
|
590
|
|
|
'salmon', 'lime', 'pink', 'slate', 'magenta', 'orange', 'marine', \ |
|
591
|
|
|
'olive', 'purple', 'teal', 'forest', 'firebrick', 'chocolate', \ |
|
592
|
|
|
'wheat', 'white', 'grey' ] |
|
593
|
|
|
ncolours = len(colours) |
|
594
|
|
|
|
|
595
|
|
|
# Loop over objects |
|
596
|
|
|
i = 0 |
|
597
|
|
|
for obj in obj_list: |
|
598
|
|
|
print(" ", obj, colours[i]) |
|
599
|
|
|
cmd.color(colours[i], obj) |
|
600
|
|
|
i = i+1 |
|
601
|
|
|
if(i == ncolours): |
|
602
|
|
|
i = 0 |
|
603
|
|
|
|
|
604
|
|
|
|
|
605
|
|
|
def names(): |
|
606
|
|
|
# Get names of all PyMOL objects |
|
607
|
|
|
obj_list = cmd.get_names('objects') |
|
608
|
|
|
for o in obj_list: |
|
609
|
|
|
print(o) |
|
610
|
|
|
|
|
611
|
|
|
|
|
612
|
|
View Code Duplication |
def color_rbw(rainbow=0): |
|
|
|
|
|
|
613
|
|
|
""" |
|
614
|
|
|
similar to color_obj() but this time colors every obect as rainbow |
|
615
|
|
|
""" |
|
616
|
|
|
rainbow = int(rainbow) |
|
617
|
|
|
|
|
618
|
|
|
# Get names of all PyMOL objects |
|
619
|
|
|
obj_list = cmd.get_names('objects') |
|
620
|
|
|
|
|
621
|
|
|
if rainbow: |
|
622
|
|
|
|
|
623
|
|
|
print("\nColouring objects as rainbow\n") |
|
624
|
|
|
|
|
625
|
|
|
nobj = len(obj_list) |
|
626
|
|
|
|
|
627
|
|
|
# Create colours starting at blue(240) to red(0), using intervals |
|
628
|
|
|
# of 240/(nobj-1) |
|
629
|
|
|
for j in range(nobj): |
|
630
|
|
|
hsv = (240-j*240/(nobj-1), 1, 1) |
|
631
|
|
|
# Convert to RGB |
|
632
|
|
|
rgb = hsv_to_rgb(hsv) |
|
|
|
|
|
|
633
|
|
|
# Define the new colour |
|
634
|
|
|
cmd.set_color("col" + str(j), rgb) |
|
635
|
|
|
print(obj_list[j], rgb) |
|
636
|
|
|
# Colour the object |
|
637
|
|
|
cmd.color("col" + str(j), obj_list[j]) |
|
638
|
|
|
else: |
|
639
|
|
|
colours = ['rainbow'] |
|
640
|
|
|
ncolours = len(colours) |
|
641
|
|
|
|
|
642
|
|
|
# Loop over objects |
|
643
|
|
|
i = 0 |
|
644
|
|
|
for obj in obj_list: |
|
645
|
|
|
print(" ", obj, colours[i]) |
|
646
|
|
|
cmd.spectrum('count', colours[i], obj) |
|
647
|
|
|
# cmd.color(colours[i], obj) |
|
648
|
|
|
i = i+1 |
|
649
|
|
|
if(i == ncolours): |
|
650
|
|
|
i = 0 |
|
651
|
|
|
|
|
652
|
|
|
def ino(): |
|
653
|
|
|
"""Sphare and yellow inorganic, such us Mg. |
|
654
|
|
|
|
|
655
|
|
|
.. image:: ../../rna_tools/utils/PyMOL4RNA/doc/ion.png""" |
|
656
|
|
|
cmd.show("spheres", "inorganic") |
|
657
|
|
|
#cmd.set('sphere_scale', '0.25', '(all)') |
|
658
|
|
|
cmd.set('sphere_scale', '1', '(all)') |
|
659
|
|
|
cmd.color("yellow", "inorganic") |
|
660
|
|
|
|
|
661
|
|
|
mapping = [[u'PRP8', 'A', u'skyblue'], [u'BRR2', 'B', u'grey60'], [u'BUD31', 'C', u'dirtyviolet'], [u'CEF1', 'D', u'raspberry'], [u'CLF1', 'E', u'raspberry'], [u'CWC15', 'F', u'dirtyviolet'], [u'CWC16/YJU2', 'G', u'lightteal'], [u'CWC2', 'H', u'ruby'], [u'CWC21', 'I', u'violetpurple'], [u'CWC22', 'J', u'bluewhite'], [u'CWC25', 'K', u'deepteal'], [u'Intron', 'L', u'black'], [u'ISY1', 'M', u'dirtyviolet'], [u'LEA1', 'N', u'palegreen'], [u'Msl1', 'O', u'palegreen'], [u'PRP45', 'P', u'lightpink'], [u'PRP16', 'Q', u'smudge'], [u'CDC40\xa0(PRP17, SLU4, XRS2)', 'R', u'dirtyviolet'], [u'PRP19 (PSO4)', 'S', u'grey70'], [u'PRP46', 'T', u'lightblue'], [u'SLT11/ECM2', 'U', u'chocolate'], [u'SNT309', 'V', u'grey70'], [u'SNU114', 'W', u'slate'], [u'SYF2', 'X', u'brightorange'], [u'SYF1', 'Y', u'brightorange'], [u'U2', 'Z', u'forest'], [u'U5', 'a', u'density'], [u'U5_SmRNP', 'b', u'deepblue'], [u'U6', 'c', u'firebrick'], [u'Intron', 'r', u'grey50'], [u'Exon', 'z', u'yellow'], [u'exon-3', 'y', u'yellow'], [u'exon-5', 'z', u'yellow'], [u'PRP4 ', 'd', u'grey50'], [u'PRP31', 'e', u'grey50'], [u'PRP6', 'f', u'grey50'], [u'PRP3', 'g', u'grey50'], [u'DIB1', 'h', u'grey50'], [u'SNU13', 'i', u'grey50'], [u'LSM8', 'j', u'grey50'], [u'LSM2', 'k', u'grey50'], [u'LSM3', 'l', u'grey50'], [u'LSM6', 'm', u'grey50'], [u'LSM5', 'n', u'grey50'], [u'LSM7', 'o', u'grey50'], [u'LSM4', 'p', u'grey50'], [u'SNU66', 'q', u'grey50'], [u'RNA (intron or U6 snRNA)', 'r', u'grey50'], [u'5EXON', 's', u'grey50'], [u'BUD13', 't', u'grey60'], [u'CLF2', 'u', u'rasberry'], [u'Cus1', 'v', u'palegreen'], [u'CWC24', 'w', u'grey60'], [u'CWC27', 'x', u'grey60'], [u'HSH155', '1', u'smudge'], [u'HSH49', '2', u'sand'], [u'PML1', '3', u'grey60'], [u'PRP11', '4', u'palegreen'], [u'PRP2', '5', u'palegreen'], [u'RDS3', '6', u'palegreen'], [u'RSE1', '7', u'smudge'], [u'SNU17', '8', u'grey60'], [u'Ysf3', '9', u'palegreen'], [u'cwc23', 'd', u'grey50'], [u'SPP382\xa0(CCF8, NTR1)', 'e', u'grey50'], [u'NTR2', 'f', u'grey50'], [u'PRP43', 'g', u'grey50'], [u'SMB1', 'h', u'grey50'], [u'SME1', 'i', u'grey50'], [u'SMX3', 'j', u'grey50'], [u'SMX2\xa0(SNP2)', 'k', u'grey50'], [u'SMD3', 'l', u'grey50'], [u'SMD1', 'm', u'grey50'], [u'SMD2', 'n', u'grey50'], [u'PRP22', 'o', u'grey50'], [u'PRP18', 'p', u'grey50'], [u'SLU7', 'q', u'grey50'], [u'SMF', 'd', u'grey50'], [u'SMG', 'e', u'grey50'], [u'PRP9', 'f', u'grey50'], [u'PRP21', 'g', u'grey50'], [u'SNU23', 'r', u'grey50'], [u'PRP38', 's', u'grey50'], [u'SPP381', 'w', u'grey50']] |
|
662
|
|
|
|
|
663
|
|
|
def spl(arg=''): |
|
664
|
|
|
""" |
|
665
|
|
|
action='', name='' |
|
666
|
|
|
""" |
|
667
|
|
|
if ' ' in arg: |
|
668
|
|
|
action, name = arg.split() |
|
669
|
|
|
name = name.lower() |
|
670
|
|
|
else: |
|
671
|
|
|
action = arg |
|
672
|
|
|
name = '' |
|
673
|
|
|
#import pandas as pd |
|
674
|
|
|
#df = pd.read_excel("/home/magnus/Desktop/pyMoL_colors-EMX.xlsx") |
|
675
|
|
|
if not action or action == 'help': |
|
676
|
|
|
spl_help() |
|
677
|
|
|
elif action == 'color' or arg=='c': |
|
678
|
|
|
code_for_color_spl.spl_color() |
|
|
|
|
|
|
679
|
|
|
code_for_color_spl_objects.spl_color() |
|
680
|
|
|
elif arg == 'extract all' or arg == 'e': |
|
681
|
|
|
code_for_spl.spl_extract() |
|
682
|
|
|
elif arg == 'align' or arg=='a': |
|
683
|
|
|
cmd.do(""" |
|
684
|
|
|
align /5gm6//6, /5lj3//V; |
|
685
|
|
|
align /5mps//6, /5lj3//V; |
|
686
|
|
|
align /6exn//6, /5lj3//V; |
|
687
|
|
|
align /5y88//D, /5lj3//V; |
|
688
|
|
|
align /5ylz//D, /5lj3//V; |
|
689
|
|
|
""") |
|
690
|
|
|
else: |
|
691
|
|
|
spl_help() |
|
692
|
|
|
|
|
693
|
|
|
cmd.extend('spl', spl) |
|
694
|
|
|
|
|
695
|
|
|
def spl_help(): |
|
696
|
|
|
print("""################ SPL ################# |
|
697
|
|
|
extract all (ea) - show |
|
698
|
|
|
colors - list all colors |
|
699
|
|
|
###################################### |
|
700
|
|
|
""") |
|
701
|
|
|
|
|
702
|
|
|
spl_help() |
|
703
|
|
|
|
|
704
|
|
|
|
|
705
|
|
|
def __spl_color(): |
|
706
|
|
|
for m in mapping: |
|
707
|
|
|
protein = m[0] |
|
708
|
|
|
chain = m[1] |
|
709
|
|
|
color = m[2] |
|
710
|
|
|
print('\_' + ' '.join([protein, chain, color])) |
|
711
|
|
|
cmd.do('color ' + color + ', chain ' + chain) |
|
712
|
|
|
# cmd.do('color firebrick, chain V') # U6 |
|
713
|
|
|
|
|
714
|
|
|
def _spl_color(): |
|
715
|
|
|
"""Color spl RNAs (for only color spl RNA and use 4-color code for residues see `spl2`) |
|
716
|
|
|
""" |
|
717
|
|
|
AllObj = cmd.get_names("all") |
|
718
|
|
|
for name in AllObj: |
|
719
|
|
|
if 'Exon' in name or 'exon' in name: |
|
720
|
|
|
cmd.color('yellow', name) |
|
721
|
|
|
if 'Intron' in name or 'intron' in name or '5splicing-site' in name: |
|
722
|
|
|
cmd.color('gray40', name) |
|
723
|
|
|
if '3exon-intron' in name.lower(): |
|
724
|
|
|
cmd.color('gray20', name) |
|
725
|
|
|
if name.startswith("U2_snRNA"): |
|
726
|
|
|
cmd.color('forest', name) |
|
727
|
|
|
if name.startswith("U5_snRNA"): |
|
728
|
|
|
cmd.color('blue', name) |
|
729
|
|
|
if name.startswith("U4_snRNA"): |
|
730
|
|
|
cmd.color('orange', name) |
|
731
|
|
|
if name.startswith("U6_snRNA"): |
|
732
|
|
|
cmd.color('red', name) |
|
733
|
|
|
|
|
734
|
|
|
cmd.do('color gray') |
|
735
|
|
|
|
|
736
|
|
|
# trisnrp |
|
737
|
|
|
cmd.do('color orange, chain V') # conflict |
|
738
|
|
|
cmd.do('color red, chain W') |
|
739
|
|
|
cmd.do('color blue, chain U') |
|
740
|
|
|
# |
|
741
|
|
|
cmd.do('color blue, chain 5') |
|
742
|
|
|
cmd.do('color forest, chain 2') |
|
743
|
|
|
cmd.do('color red, chain 6') |
|
744
|
|
|
cmd.do('color orange, chain 4') |
|
745
|
|
|
cmd.do('color yellow, chain Y') |
|
746
|
|
|
# shi |
|
747
|
|
|
cmd.do('color blue, chain D') # u5 |
|
748
|
|
|
cmd.do('color forest, chain L') # u2 |
|
749
|
|
|
cmd.do('color red, chain E') # u6 |
|
750
|
|
|
cmd.do('color yellow, chain M') |
|
751
|
|
|
cmd.do('color yellow, chain N') |
|
752
|
|
|
# afte branch |
|
753
|
|
|
cmd.do('color blue, chain U') # u5 |
|
754
|
|
|
cmd.do('color forest, chain Z') # u2 |
|
755
|
|
|
cmd.do('color red, chain V') # u6 |
|
756
|
|
|
cmd.do('color yellow, chain E') |
|
757
|
|
|
cmd.do('color black, chain I') |
|
758
|
|
|
# 5WSG |
|
759
|
|
|
# Cryo-EM structure of the Catalytic Step II spliceosome (C* complex) at 4.0 angstrom resolution |
|
760
|
|
|
cmd.do('color blue, chain D') # u5 |
|
761
|
|
|
#cmd.do('color forest, chain L') # u2 |
|
762
|
|
|
cmd.do('color yellow, chain B') |
|
763
|
|
|
cmd.do('color yellow, chain b') |
|
764
|
|
|
cmd.do('color black, chain N') |
|
765
|
|
|
cmd.do('color black, chain M') |
|
766
|
|
|
|
|
767
|
|
|
cmd.do('color black, chain 3') # orange |
|
768
|
|
|
cmd.do('color black, chain E') # yellow |
|
769
|
|
|
cmd.do('color black, chain i') |
|
770
|
|
|
cmd.do('color black, chain e') |
|
771
|
|
|
|
|
772
|
|
|
cmd.do('color black, chain e') |
|
773
|
|
|
|
|
774
|
|
|
cmd.do('color dirtyviolet, chain L') # bud31 |
|
775
|
|
|
cmd.do('color rasberry, chain L') # CERF1 |
|
776
|
|
|
|
|
777
|
|
|
cmd.do('color skyblue, chain A') # PRP8 |
|
778
|
|
|
cmd.do('color grey60, chain B') # BRR2 |
|
779
|
|
|
cmd.do('color dirtyiolet, chain L') # BUD31 |
|
780
|
|
|
cmd.do('color rasberry, chain O') # CEF1 |
|
781
|
|
|
cmd.do('color rasberry, chain S') # CLF1 |
|
782
|
|
|
cmd.do('color dirtyviolet, chain P') # CWC15 |
|
783
|
|
|
cmd.do('color lightteal, chain D') # CWC16/YJU2 |
|
784
|
|
|
cmd.do('color ruby, chain M') # CWC2 |
|
785
|
|
|
cmd.do('color violetpurple, chain R') # CWC21 |
|
786
|
|
|
cmd.do('color bluewhite, chain H') # CWC22 |
|
787
|
|
|
cmd.do('color deepteal, chain F') # CWC25 |
|
788
|
|
|
cmd.do('color black, chain I') # Intron |
|
789
|
|
|
cmd.do('color dirtyviolet, chain G') # ISY1 |
|
790
|
|
|
cmd.do('color palegreen, chain W') # LEA1 |
|
791
|
|
|
cmd.do('color palegreen, chain Y') # Msl1 |
|
792
|
|
|
cmd.do('color lightpink, chain K') # PRP45 |
|
793
|
|
|
cmd.do('color smudge, chain Q') # Prp16 |
|
794
|
|
|
cmd.do('color grey70, chain t') # Prp19 |
|
795
|
|
|
cmd.do('color lightblue, chain J') # PRP46 |
|
796
|
|
|
cmd.do('color chocolate, chain N') # SLT11/ECM2 |
|
797
|
|
|
cmd.do('color grey70, chain s') # Snt309 |
|
798
|
|
|
cmd.do('color slate, chain C') # SNU114 |
|
799
|
|
|
cmd.do('color brightorange, chain T') # SYF1 |
|
800
|
|
|
cmd.do('color forest, chain Z') # U2 |
|
801
|
|
|
cmd.do('color density, chain U') # U5 |
|
802
|
|
|
cmd.do('color deepblue, chain b') # U5_Sm |
|
803
|
|
|
|
|
804
|
|
|
cmd.do('bg gray') |
|
805
|
|
|
# cmd.do('remove (polymer.protein)') |
|
806
|
|
|
|
|
807
|
|
|
cmd.set("cartoon_tube_radius", 1.0) |
|
808
|
|
|
ino() |
|
809
|
|
|
|
|
810
|
|
|
def spl2(): |
|
811
|
|
|
"""Color spl RNAs and use 4-color code for residues (for only color spl RNA see `spl`) |
|
812
|
|
|
""" |
|
813
|
|
|
|
|
814
|
|
|
AllObj = cmd.get_names("all") |
|
815
|
|
|
for name in AllObj: |
|
816
|
|
|
if 'Exon' in name or 'exon' in name: |
|
817
|
|
|
cmd.color('yellow', name) |
|
818
|
|
|
if 'Intron' in name or 'intron' in name or '5splicing-site' in name: |
|
819
|
|
|
cmd.color('gray40', name) |
|
820
|
|
|
if '3exon-intron' in name.lower(): |
|
821
|
|
|
cmd.color('gray20', name) |
|
822
|
|
|
if name.startswith("U2_snRNA"): |
|
823
|
|
|
cmd.color('forest', name) |
|
824
|
|
|
if name.startswith("U5_snRNA"): |
|
825
|
|
|
cmd.color('blue', name) |
|
826
|
|
|
if name.startswith("U4_snRNA"): |
|
827
|
|
|
cmd.color('orange', name) |
|
828
|
|
|
if name.startswith("U6_snRNA"): |
|
829
|
|
|
cmd.color('red', name) |
|
830
|
|
|
|
|
831
|
|
|
cmd.do('color gray') |
|
832
|
|
|
|
|
833
|
|
|
# trisnrp |
|
834
|
|
|
cmd.do('color orange, chain V') # conflict |
|
835
|
|
|
cmd.do('color red, chain W') |
|
836
|
|
|
cmd.do('color blue, chain U') |
|
837
|
|
|
# |
|
838
|
|
|
cmd.do('color blue, chain 5') |
|
839
|
|
|
cmd.do('color forest, chain 2') |
|
840
|
|
|
cmd.do('color red, chain 6') |
|
841
|
|
|
cmd.do('color orange, chain 4') |
|
842
|
|
|
cmd.do('color yellow, chain Y') |
|
843
|
|
|
# shi |
|
844
|
|
|
cmd.do('color blue, chain D') # u5 |
|
845
|
|
|
cmd.do('color forest, chain L') # u2 |
|
846
|
|
|
cmd.do('color red, chain E') # u6 |
|
847
|
|
|
cmd.do('color yellow, chain M') |
|
848
|
|
|
cmd.do('color yellow, chain N') |
|
849
|
|
|
# afte branch |
|
850
|
|
|
cmd.do('color blue, chain U') # u5 |
|
851
|
|
|
cmd.do('color forest, chain Z') # u2 |
|
852
|
|
|
cmd.do('color red, chain V') # u6 |
|
853
|
|
|
cmd.do('color yellow, chain E') |
|
854
|
|
|
cmd.do('color black, chain I') |
|
855
|
|
|
# 5WSG |
|
856
|
|
|
# Cryo-EM structure of the Catalytic Step II spliceosome (C* complex) at 4.0 angstrom resolution |
|
857
|
|
|
cmd.do('color blue, chain D') # u5 |
|
858
|
|
|
#cmd.do('color forest, chain L') # u2 |
|
859
|
|
|
cmd.do('color yellow, chain B') |
|
860
|
|
|
cmd.do('color yellow, chain b') |
|
861
|
|
|
cmd.do('color black, chain N') |
|
862
|
|
|
cmd.do('color black, chain M') |
|
863
|
|
|
|
|
864
|
|
|
cmd.do('color black, chain 3') # orange |
|
865
|
|
|
cmd.do('color black, chain E') # yellow |
|
866
|
|
|
cmd.do('color black, chain i') |
|
867
|
|
|
cmd.do('color black, chain e') |
|
868
|
|
|
|
|
869
|
|
|
cmd.do('bg gray') |
|
870
|
|
|
cmd.do('remove (polymer.protein)') |
|
871
|
|
|
|
|
872
|
|
|
cmd.color("red",'resn rG+G and name n1+c6+o6+c5+c4+n7+c8+n9+n3+c2+n1+n2') |
|
873
|
|
|
cmd.color("forest",'resn rC+C and name n1+c2+o2+n3+c4+n4+c5+c6') |
|
874
|
|
|
cmd.color("orange",'resn rA+A and name n1+c6+n6+c5+n7+c8+n9+c4+n3+c2') |
|
875
|
|
|
cmd.color("blue",'resn rU+U and name n3+c4+o4+c5+c6+n1+c2+o2') |
|
876
|
|
|
cmd.set("cartoon_tube_radius", 1.0) |
|
877
|
|
|
ino() |
|
878
|
|
|
|
|
879
|
|
|
|
|
880
|
|
|
def _spli(): |
|
881
|
|
|
""" |
|
882
|
|
|
# this trick is taken from Rhiju's Das code |
|
883
|
|
|
color red,resn rG+G and name n1+c6+o6+c5+c4+n7+c8+n9+n3+c2+n1+n2 |
|
884
|
|
|
color forest,resn rC+C and name n1+c2+o2+n3+c4+n4+c5+c6 |
|
885
|
|
|
color orange, resn rA+A and name n1+c6+n6+c5+n7+c8+n9+c4+n3+c2 |
|
886
|
|
|
color blue, resn rU+U and name n3+c4+o4+c5+c6+n1+c2+o2 |
|
887
|
|
|
|
|
888
|
|
|
# |
|
889
|
|
|
#cmd.color("yellow", "*intron*") |
|
890
|
|
|
#cmd.color("yellow", "*exon*") |
|
891
|
|
|
|
|
892
|
|
|
#cmd.show("spheres", "inorganic") |
|
893
|
|
|
#cmd.color("yellow", "inorganic") |
|
894
|
|
|
""" |
|
895
|
|
|
cmd.color("orange", "U4_snRNA*") |
|
896
|
|
|
cmd.color("red", "U6_snRNA*") |
|
897
|
|
|
cmd.color("blue", "U5_snRNA*") |
|
898
|
|
|
cmd.color("green", "U2_snRNA*") |
|
899
|
|
|
cmd.color("red",'resn rG+G and name n1+c6+o6+c5+c4+n7+c8+n9+n3+c2+n1+n2') |
|
900
|
|
|
cmd.color("forest",'resn rC+C and name n1+c2+o2+n3+c4+n4+c5+c6') |
|
901
|
|
|
cmd.color("orange",'resn rA+A and name n1+c6+n6+c5+n7+c8+n9+c4+n3+c2') |
|
902
|
|
|
cmd.color("blue",'resn rU+U and name n3+c4+o4+c5+c6+n1+c2+o2') |
|
903
|
|
|
|
|
904
|
|
|
|
|
905
|
|
|
def g2(): |
|
906
|
|
|
txt = """color gray, all; |
|
907
|
|
|
color yellow, chain B; |
|
908
|
|
|
color red, resi 788-824; |
|
909
|
|
|
color yellow, resi 828-866; |
|
910
|
|
|
color forest, resi 476-490; |
|
911
|
|
|
""" |
|
912
|
|
|
color_by_text(txt) |
|
913
|
|
|
cmd.color('pink', 'resi 120') |
|
914
|
|
|
cmd.color('pink', 'resi 2') |
|
915
|
|
|
|
|
916
|
|
|
|
|
917
|
|
|
def rgyration(selection='(all)', quiet=1): |
|
918
|
|
|
''' |
|
919
|
|
|
|
|
920
|
|
|
[PyMOL] RES: radius of gyration |
|
921
|
|
|
From: Tsjerk Wassenaar <tsjerkw@gm...> - 2011-03-31 14:07:03 |
|
922
|
|
|
https://sourceforge.net/p/pymol/mailman/message/27288491/ |
|
923
|
|
|
DESCRIPTION |
|
924
|
|
|
|
|
925
|
|
|
Calculate radius of gyration |
|
926
|
|
|
|
|
927
|
|
|
USAGE |
|
928
|
|
|
|
|
929
|
|
|
rgyrate [ selection ] |
|
930
|
|
|
:::warning::: |
|
931
|
|
|
if nothing is selected function is calculating radius of gyration for all pdbs in current Pymol session |
|
932
|
|
|
''' |
|
933
|
|
|
from itertools import izip |
|
934
|
|
|
quiet = int(quiet) |
|
935
|
|
|
model = cmd.get_model(selection).atom |
|
936
|
|
|
x = [i.coord for i in model] |
|
937
|
|
|
mass = [i.get_mass() for i in model] |
|
938
|
|
|
xm = [(m*i,m*j,m*k) for (i,j,k),m in izip(x,mass)] |
|
939
|
|
|
tmass = sum(mass) |
|
940
|
|
|
rr = sum(mi*i+mj*j+mk*k for (i,j,k),(mi,mj,mk) in izip(x,xm)) |
|
941
|
|
|
mm = sum((sum(i)/tmass)**2 for i in izip(*xm)) |
|
942
|
|
|
rg = math.sqrt(rr/tmass - mm) |
|
943
|
|
|
if not quiet: |
|
944
|
|
|
print("Radius of gyration: %.2f" % (rg)) |
|
945
|
|
|
return rg |
|
946
|
|
|
|
|
947
|
|
|
|
|
948
|
|
|
def qrnass(): |
|
949
|
|
|
cmd.save('sele.pdb', '(sele)') |
|
950
|
|
|
mini('sele.pdb') |
|
951
|
|
|
|
|
952
|
|
|
|
|
953
|
|
|
def qrnas(): |
|
954
|
|
|
subset = "*" |
|
955
|
|
|
AllObj=cmd.get_names("all") |
|
956
|
|
|
#print AllObj |
|
957
|
|
|
for x in AllObj[:]: |
|
958
|
|
|
print(x, 'qrnas...') |
|
959
|
|
|
#print(AllObj[0],x) |
|
960
|
|
|
f = tempfile.NamedTemporaryFile(delete=True) |
|
961
|
|
|
#print f.name |
|
962
|
|
|
#f.write(XX) |
|
963
|
|
|
cmd.save(f.name, x) |
|
964
|
|
|
#p = Process(target=mini) |
|
965
|
|
|
#p.start() |
|
966
|
|
|
mini() |
|
967
|
|
|
#cmd.load('out.pdb', 'ref') |
|
968
|
|
|
#p.join() |
|
969
|
|
|
#print x |
|
970
|
|
|
#print '\n'.join(out.split('\n')[1:]) # to remove first line of py3dna /tmp/xxx |
|
971
|
|
|
f.close() |
|
972
|
|
|
break |
|
973
|
|
|
align_all() |
|
974
|
|
|
rr() |
|
|
|
|
|
|
975
|
|
|
cmd.set('grid_mode', 1) |
|
976
|
|
|
|
|
977
|
|
|
|
|
978
|
|
|
def mini(f): |
|
979
|
|
|
#os.system('/home/magnus/opt/qrnas/QRNA02/QRNA -i ' + f + ' -c /home/magnus/opt/qrnas/QRNA02/configfile.txt -o out.pdb') |
|
980
|
|
|
os.system('~/opt/qrnas/QRNA02/QRNA -i ' + f + ' -c ~/opt/qrnas/QRNA02/configfile.txt -o out.pdb') |
|
981
|
|
|
cmd.delete('mini') |
|
982
|
|
|
cmd.load('out.pdb', 'mini') |
|
983
|
|
|
print('end') |
|
984
|
|
|
|
|
985
|
|
|
|
|
986
|
|
|
def reload(): |
|
987
|
|
|
"""Reload ~/.pymolrc and all included there packages (e.g. with run <foo.py>)""" |
|
988
|
|
|
cmd.do('@ ~/.pymolrc') |
|
989
|
|
|
|
|
990
|
|
|
def clr(): |
|
991
|
|
|
"""clr - make white bg and structure black""" |
|
992
|
|
|
cmd.bg_color( "white" ) |
|
993
|
|
|
color_by_text('color black, all') |
|
994
|
|
|
|
|
995
|
|
|
|
|
996
|
|
|
def rlabel(): |
|
997
|
|
|
cmd = "n. C1'", '"%s %s" % (resn, resi)' |
|
998
|
|
|
print('label ' + cmd) |
|
999
|
|
|
cmd.label(cmd) |
|
1000
|
|
|
|
|
1001
|
|
|
|
|
1002
|
|
|
def sav(name): |
|
1003
|
|
|
cmd.bg_color( "white" ) |
|
1004
|
|
|
cmd.save('/home/magnus/Desktop/' + name + '.png') |
|
1005
|
|
|
cmd.save('/home/magnus/Desktop/' + name + '.pse') |
|
1006
|
|
|
|
|
1007
|
|
|
def hide_rna(): |
|
1008
|
|
|
cmd.hide('(polymer.nucleic)') |
|
1009
|
|
|
cmd.extend('rna-hide', hide_rna) |
|
1010
|
|
|
|
|
1011
|
|
|
def show_rna(): |
|
1012
|
|
|
cmd.show('(polymer.nucleic)') |
|
1013
|
|
|
cmd.extend('rna-show', show_rna) |
|
1014
|
|
|
|
|
1015
|
|
|
def select_rna(): |
|
1016
|
|
|
cmd.select('polymer.nucleic') |
|
1017
|
|
|
cmd.extend('select-rna', select_rna) |
|
1018
|
|
|
|
|
1019
|
|
|
def hide_protein(): |
|
1020
|
|
|
cmd.hide('(polymer.protein)') |
|
1021
|
|
|
cmd.extend('protein-hide', hide_protein) |
|
1022
|
|
|
cmd.extend('rprotein-hide', hide_protein) |
|
1023
|
|
|
|
|
1024
|
|
|
def select_protein(): |
|
1025
|
|
|
cmd.select('polymer.protein') |
|
1026
|
|
|
cmd.extend('protein-select', select_protein) |
|
1027
|
|
|
|
|
1028
|
|
|
def tmp(): |
|
1029
|
|
|
cmd.save('/home/' + user + '/Desktop/' + tmp + '.png') |
|
1030
|
|
|
cmd.save('/home/' + user + '/Desktop/' + tmp + '.pse') |
|
1031
|
|
|
|
|
1032
|
|
|
|
|
1033
|
|
|
################################################################################ |
|
1034
|
|
|
def sav_tmp(): |
|
1035
|
|
|
from shutil import copyfile |
|
1036
|
|
|
import datetime |
|
1037
|
|
|
try: |
|
1038
|
|
|
TMP_FOLDER + ' ' |
|
|
|
|
|
|
1039
|
|
|
except: |
|
1040
|
|
|
print("Error: Set up TMP_FOLDER in your ~/.pymolrc, e.g. TMP_FOLDER = '/home/magnus/Desktop/PyMOL/'") |
|
1041
|
|
|
return |
|
1042
|
|
|
|
|
1043
|
|
|
try: |
|
1044
|
|
|
os.mkdir(TMP_FOLDER) |
|
1045
|
|
|
except: |
|
1046
|
|
|
pass |
|
1047
|
|
|
|
|
1048
|
|
|
date = datetime.datetime.today().strftime('%Y-%m-%d.%S') |
|
1049
|
|
|
try: |
|
1050
|
|
|
fn = TMP_FOLDER + os.sep + id + '_' + date + '.pse' |
|
1051
|
|
|
except TypeError: |
|
1052
|
|
|
fn = TMP_FOLDER + os.sep + '_' + date + '.pse' |
|
1053
|
|
|
cmd.save(fn) |
|
1054
|
|
|
print('Save...' + fn) |
|
1055
|
|
|
cmd.save(fn.replace('.pse', '.png')) |
|
1056
|
|
|
copyfile(fn, TMP_FOLDER + '/last.pse') |
|
1057
|
|
|
|
|
1058
|
|
|
def load_tmp(): |
|
1059
|
|
|
print('Load...') |
|
1060
|
|
|
cmd.load(TMP_FOLDER + '/last.pse') |
|
|
|
|
|
|
1061
|
|
|
|
|
1062
|
|
|
def quickref(): |
|
1063
|
|
|
print(' PyMOL4RNA (rna-tools) ') |
|
1064
|
|
|
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') |
|
1065
|
|
|
print('Quickref `qr`: ') |
|
1066
|
|
|
print(' alter (sele), chain="B" ') |
|
1067
|
|
|
print(' alter (sele), resv -= 4') |
|
1068
|
|
|
print(' alter (chain B), resv -= 44 ') |
|
1069
|
|
|
print(" select br. all within 15 of (sele)") |
|
1070
|
|
|
print(" select br. all within 15 of resi 574") |
|
1071
|
|
|
print(" select br. all within 15 of resi 377 # O. ihheyensis") |
|
1072
|
|
|
print(' select br. all within 15 of U6_snRNA and resi 80') |
|
1073
|
|
|
print(' set dash_color, red; set dash_width, 4') |
|
1074
|
|
|
print(' p - prepare seq for printing') |
|
1075
|
|
|
print(' rp - rna present, object names only click to get compact legend') |
|
1076
|
|
|
print(' rp17') |
|
1077
|
|
|
print(' rna_cartoon') |
|
1078
|
|
|
print(' rs') |
|
1079
|
|
|
print(' rcomp') |
|
1080
|
|
|
print(' color_obj') |
|
1081
|
|
|
print(' color_rbw') |
|
1082
|
|
|
print(' aa') |
|
1083
|
|
|
print(' savt - save_transformed <object>, <file>') |
|
1084
|
|
|
#print(' spl - color snRNAs of the spliceosome:' |
|
1085
|
|
|
# green: U2, blue: U5, red:U6, orange:U2""") |
|
1086
|
|
|
print('\_ RNA_TOOLS_PATH env variable used: ' + RNA_TOOLS_PATH) |
|
1087
|
|
|
|
|
1088
|
|
|
try: |
|
1089
|
|
|
from pymol import cmd |
|
1090
|
|
|
except ImportError: |
|
1091
|
|
|
print("PyMOL Python lib is missing") |
|
1092
|
|
|
else: |
|
1093
|
|
|
quickref() |
|
1094
|
|
|
#cmd.set_key('CTRL-S', cmd.save, ['/home/magnus/Desktop/tmp.pse']) |
|
1095
|
|
|
cmd.set_key('CTRL-S', sav_tmp) |
|
1096
|
|
|
cmd.set_key('CTRL-Z', load_tmp) # ostatni wrzucam tutaj |
|
1097
|
|
|
#cmd.load, ['/home/magnus/Desktop/tmp.pse']) |
|
1098
|
|
|
# main code # |
|
1099
|
|
|
|
|
1100
|
|
|
cmd.extend('quickref', quickref) |
|
1101
|
|
|
cmd.extend('qr', quickref) |
|
1102
|
|
|
cmd.extend('rp17', rp17) |
|
1103
|
|
|
cmd.extend('rp17csrv', rp17csrv) |
|
1104
|
|
|
cmd.extend('rg2', g2) |
|
1105
|
|
|
cmd.extend('x', g2) |
|
1106
|
|
|
|
|
1107
|
|
|
cmd.extend('rp', rp) |
|
1108
|
|
|
cmd.extend('p', p) |
|
1109
|
|
|
cmd.extend('pdb', pdb) |
|
1110
|
|
|
cmd.extend('seq', seq) |
|
1111
|
|
|
cmd.extend('rseq', seq) |
|
1112
|
|
|
cmd.extend('rna_cartoon', rna_cartoon) |
|
1113
|
|
|
cmd.extend('rs', rs) |
|
1114
|
|
|
cmd.extend('ino', ino) |
|
1115
|
|
|
cmd.extend('rcomp', rcomp) |
|
1116
|
|
|
cmd.extend('color_obj', color_obj) |
|
1117
|
|
|
cmd.extend('color_rbw', color_rbw) |
|
1118
|
|
|
cmd.extend('aa', align_all) |
|
1119
|
|
|
cmd.extend('ss', ss) |
|
1120
|
|
|
cmd.extend('ss_all', ss_all) |
|
1121
|
|
|
cmd.extend('clarna', clarna) |
|
1122
|
|
|
cmd.extend('x3dna', x3dna) |
|
1123
|
|
|
cmd.extend("rgyration", rgyration) |
|
1124
|
|
|
#cmd.extend("spl", spl) |
|
1125
|
|
|
cmd.extend("spl2", spl2) |
|
1126
|
|
|
cmd.extend('rlabel', 'rlabel') |
|
1127
|
|
|
|
|
1128
|
|
|
cmd.extend('grid_on', grid_on) |
|
1129
|
|
|
cmd.extend('grid_off', grid_off) |
|
1130
|
|
|
cmd.extend('reload', reload) |
|
1131
|
|
|
|
|
1132
|
|
|
cmd.extend('color_aa_types', color_aa_types) |
|
1133
|
|
|
|
|
1134
|
|
|
cmd.extend('names', names) |
|
1135
|
|
|
|
|
1136
|
|
|
# set dash lines |
|
1137
|
|
|
cmd.set('dash_color', 'red') |
|
1138
|
|
|
cmd.set('dash_width', 4) |
|
1139
|
|
|
|
|
1140
|
|
|
cmd.extend('sav', sav) |
|
1141
|
|
|
cmd.extend('save_transformed', save_transformed) |
|
1142
|
|
|
cmd.extend('savt', save_transformed) |
|
1143
|
|
|
cmd.extend('show_all_at_once', show_all_at_once) |
|
1144
|
|
|
|
|
1145
|
|
|
cmd.set('ignore_case', 'off') |
|
1146
|
|
|
#cmd.set('cartoon_ring_mode', '3') |
|
1147
|
|
|
#cmd.set('cartoon_ring_finder', '2') |
|
1148
|
|
|
#cmd.extend('spl_select', spl_select) |
|
1149
|
|
|
# print('ignore_case made off') |
|
1150
|
|
|
print('\_ PYMOL4RNA loading .... [ok]') |
|
1151
|
|
|
|