Total Complexity | 158 |
Total Lines | 1600 |
Duplicated Lines | 12.81 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like build.rna_tools.tools.PyMOL4RNA.PyMOL4RNA often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | #!/usr/bin/env python |
||
2 | #from icecream import ic |
||
3 | #import sys |
||
4 | #ic.configureOutput(outputFunction=lambda *a: print(*a, file=sys.stderr), includeContext=True) |
||
5 | #ic.configureOutput(prefix='') |
||
6 | |||
7 | try: |
||
8 | from icecream import ic |
||
9 | ic.configureOutput(outputFunction=lambda *a: print(*a, file=sys.stderr)) |
||
10 | ic.configureOutput(prefix='> ') |
||
11 | except ImportError: |
||
12 | ic = print |
||
13 | |||
14 | BIN = "/Users/magnus/miniconda3/bin/" |
||
15 | print(BIN) |
||
16 | |||
17 | """ |
||
18 | DOCS! Quick reference: |
||
19 | |||
20 | - clarna: show contacts classification of the selected fragment based on ClaRNA |
||
21 | - ss: show secondary structure of the selection based on py3dna.py (3DNA (Lu, Olson 2003)) |
||
22 | - ss_all: the same as ss() but for all objects |
||
23 | - pdbsrc: show PDB content (source) of selection. |
||
24 | - seq: show sequence of the selection |
||
25 | - ino: represent ions as sphare and yellow inorganic, such us Mg |
||
26 | - p: shortcut for putting a seq at the bottom. Pretty cool for screenshots with names of objects |
||
27 | - spli: color snRNA of the spliceosome and bases according to identity U(blue), A(orange), G(red), C(forest) |
||
28 | - rp: @todo |
||
29 | - rs: @todo |
||
30 | - rib: @todo |
||
31 | - select br. all within 12 of resi 574 |
||
32 | |||
33 | If you want more, read for interesting functions <https://daslab.stanford.edu/site_data/docs_pymol_rhiju.pdf> |
||
34 | |||
35 | Tips; cmd.do |
||
36 | |||
37 | """ |
||
38 | # imports |
||
39 | import tempfile |
||
40 | import math |
||
41 | import subprocess |
||
42 | import os |
||
43 | import sys |
||
44 | |||
45 | import getpass |
||
46 | user = getpass.getuser() |
||
47 | |||
48 | import os |
||
49 | import sys |
||
50 | |||
51 | |||
52 | def exe(cmd, verbose=False): |
||
53 | """Helper function to run cmd. Using in this Python module.""" |
||
54 | if verbose: print('cmd:' + cmd) |
||
55 | o = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
||
56 | executable=EXECUTABLE) |
||
57 | out = o.stdout.read().strip().decode() |
||
58 | err = o.stderr.read().strip().decode() |
||
59 | return out, err |
||
60 | |||
61 | def spla(): |
||
62 | cmd.do("color forest, chain A") |
||
63 | cmd.do("color firebrick, chain B") |
||
64 | cmd.extend('spla', spla) |
||
|
|||
65 | print('spla - color A and B') |
||
66 | |||
67 | def spln(): |
||
68 | cmd.do("color forest, chain 2") |
||
69 | cmd.do("color firebrick, chain 6") |
||
70 | cmd.extend('spln', spln) |
||
71 | print('spln - color 2 and 6') |
||
72 | |||
73 | def color_protein(): |
||
74 | cmd.do("color blue, resn ARG+LYS+HIS and (sele)") |
||
75 | cmd.do("color red, resn ASP+GLU and (sele)") |
||
76 | cmd.do("color green, resn GLY+ALA+VAL+LEU+ILE+MET+PHE and (sele)") |
||
77 | cmd.do("color yellow, resn TYR+TRP and (sele)") |
||
78 | cmd.do("color forest, resn SER+THR+CYS+ASN+GLN and (sele)") |
||
79 | cmd.do("color pink, resn PRO and (sele)") |
||
80 | |||
81 | cmd.extend('cp', color_protein) |
||
82 | |||
83 | def save_transformed(object, file): |
||
84 | """Saves the molecule with coordinates from the current orientation. |
||
85 | |||
86 | Args: |
||
87 | object (string): PyMOL name |
||
88 | file (string): a file name to output file |
||
89 | |||
90 | Example:: |
||
91 | |||
92 | PyMOL>save_transformed 6bk8_RNA_only_Oriented, 6bk8_RNA_only_Oriented.pdb |
||
93 | |||
94 | Source: <https://pymolwiki.org/index.php/Modeling_and_Editing_Structures> |
||
95 | """ |
||
96 | m = cmd.get_view(0) |
||
97 | ttt = [m[0], m[1], m[2], 0.0, |
||
98 | m[3], m[4], m[5], 0.0, |
||
99 | m[6], m[7], m[8], 0.0, |
||
100 | 0.0, 0.0, 0.0, 1.0] |
||
101 | cmd.transform_object(object,ttt,transpose=1) |
||
102 | cmd.save(file,object) |
||
103 | |||
104 | |||
105 | def color_by_text(txt): |
||
106 | """Helper function used for color-coding based on residue indexes ranges.""" |
||
107 | for t in txt.strip().split('\n'): |
||
108 | print(t) |
||
109 | color, resi = t.replace('color ', '').split(',') |
||
110 | print((color, resi)) |
||
111 | cmd.color(color.strip(), resi.strip()) |
||
112 | |||
113 | def cmd_text(txt): |
||
114 | """Helper function used for color-coding based on residue indexes ranges.""" |
||
115 | for t in txt.strip().split('\n'): |
||
116 | cmd.do(t) |
||
117 | |||
118 | def delete_all(): |
||
119 | cmd.delete('*') |
||
120 | cmd.extend('dall', delete_all) |
||
121 | print('dall - delete_all') |
||
122 | |||
123 | def rp(): |
||
124 | """Represent your RNA.""" |
||
125 | cmd.hide("sticks", "all") |
||
126 | cmd.hide("lines", "all") |
||
127 | cmd.show("cartoon", "all") |
||
128 | cmd.set("cartoon_ring_mode", 3) |
||
129 | cmd.set("cartoon_ring_finder", 2) |
||
130 | cmd.set("cartoon_ladder_mode", 1) |
||
131 | |||
132 | def show_all_at_once(): |
||
133 | cmd.set('states', 'on') |
||
134 | |||
135 | |||
136 | def grid_on(): |
||
137 | cmd.set('grid_mode', 1) |
||
138 | |||
139 | def grid_off(): |
||
140 | cmd.set('grid_mode', 0) |
||
141 | |||
142 | cmd.extend('gridon', grid_on) |
||
143 | cmd.extend('gridoff', grid_off) |
||
144 | cmd.extend('gn', grid_on) |
||
145 | cmd.extend('gf', grid_off) |
||
146 | |||
147 | |||
148 | def rs(): |
||
149 | """ The function creates super-cool cartoon-like RNA and colors each structure as a rainbow. |
||
150 | Good to view aligned structures in a grid. |
||
151 | |||
152 | .. image:: ../../rna_tools/utils/PyMOL4RNA/doc/rs.png |
||
153 | """ |
||
154 | cmd.hide("sticks", "all") |
||
155 | cmd.hide("lines", "all") |
||
156 | cmd.show("cartoon", "all") |
||
157 | cmd.set("cartoon_ring_mode", 3) |
||
158 | cmd.set("cartoon_ring_finder", 2) |
||
159 | cmd.set("cartoon_ladder_mode", 2) |
||
160 | cmd.set("cartoon_ring_transparency", 0.30) |
||
161 | cmd.spectrum() |
||
162 | |||
163 | obj_list = cmd.get_names('objects') |
||
164 | |||
165 | colours = ['rainbow'] |
||
166 | ncolours = len(colours) |
||
167 | # Loop over objects |
||
168 | i = 0 |
||
169 | for obj in obj_list: |
||
170 | print(" ", obj, colours[i]) |
||
171 | cmd.spectrum('count', colours[i], obj) |
||
172 | i = i+1 |
||
173 | if(i == ncolours): |
||
174 | i = 0 |
||
175 | |||
176 | |||
177 | def rx(): |
||
178 | """ The function creates super-cool cartoon-like RNA and colors each structure as a rainbow. |
||
179 | Good to view aligned structures in a grid. |
||
180 | |||
181 | .. image:: ../../rna_tools/utils/PyMOL4RNA/doc/rs.png |
||
182 | """ |
||
183 | cmd.hide("sticks", "all") |
||
184 | cmd.hide("lines", "all") |
||
185 | cmd.show("cartoon", "all") |
||
186 | cmd.set("cartoon_ring_mode", 0) |
||
187 | cmd.set("cartoon_ring_finder", 0) |
||
188 | cmd.set("cartoon_ladder_mode", 0) |
||
189 | cmd.set("cartoon_ring_transparency", 0.30) |
||
190 | |||
191 | cmd.extend('rx', rx) |
||
192 | |||
193 | |||
194 | def get_intrs_all_vs_all(verbose=True, redundant=True): |
||
195 | """ |
||
196 | get_intrs_all_vs_all() |
||
197 | get_raw_distances contacts_all # U6_C-CWC2_C_all |
||
198 | |||
199 | # if true all vs all (a-b and b-a) then set redundant to True |
||
200 | # this is sometimes useful if you want to have interactions of b in form of |
||
201 | # b-a |
||
202 | # b-c |
||
203 | # if redundant False then you will have only |
||
204 | # a-b |
||
205 | # b-c |
||
206 | |||
207 | """ |
||
208 | # cmd.delete('contacts') |
||
209 | objs = cmd.get_names_of_type("object:molecule") |
||
210 | if verbose: |
||
211 | print(objs) |
||
212 | # objs = ['U6_C', 'CWC25_C'] |
||
213 | objs2 = objs.copy() |
||
214 | for o in objs: |
||
215 | if not redundant: |
||
216 | objs2.pop(0) |
||
217 | if verbose: |
||
218 | print(' ', objs2) |
||
219 | for o2 in objs2: |
||
220 | if o != o2: # don't compare object to itself |
||
221 | print(o,'<>',o2) |
||
222 | results = o + '-' + o2 |
||
223 | if show_contacts(o, o2, results): #, 'contacts) #) # results to U6_C-CWC15_C |
||
224 | # if not None |
||
225 | p = '/Users/magnus/Desktop/spl-csv/' # TODO |
||
226 | # _all or |
||
227 | get_raw_distances(results + '_all', filename=p + results + '.csv') |
||
228 | |||
229 | cmd.extend('get_intrs_all_vs_all', get_intrs_all_vs_all) |
||
230 | |||
231 | def align_all(cycles = 5, filename="_rmsd_.csv"): |
||
232 | """ |
||
233 | Args: |
||
234 | |||
235 | cycles (int): maximum number of outlier rejection cycles {default: 5} |
||
236 | |||
237 | Returns: |
||
238 | |||
239 | Prints a table of ref vs models with 7 items: |
||
240 | |||
241 | RaR RMSD after refinement |
||
242 | #AA Number of aligned atoms after refinement |
||
243 | CoR Number of refinement cycles |
||
244 | RbR RMSD before refinement |
||
245 | #AbR Number of aligned atoms before refinement |
||
246 | RS Raw alignment score |
||
247 | AR Number of residues aligned |
||
248 | |||
249 | and saves the table to filename as csv |
||
250 | |||
251 | old version: |
||
252 | |||
253 | 1_solution_0_rpr 1_santalucia_1_rpr 5.60600471496582 958 4 5.763411521911621 974 416.0 46 -- RMSD 5.76 of 46 residues |
||
254 | |||
255 | """ |
||
256 | molecules = cmd.get_names_of_type("object:molecule") |
||
257 | ref = molecules.pop(0) |
||
258 | print(""" |
||
259 | RaR RMSD after refinement |
||
260 | #AA Number of aligned atoms after refinement |
||
261 | CoR Number of refinement cycles |
||
262 | RbR RMSD before refinement |
||
263 | #AbR Number of aligned atoms before refinement |
||
264 | RS Raw alignment score |
||
265 | AR Number of residues aligned |
||
266 | """) |
||
267 | report = [] |
||
268 | header = 'Ref Model RaR #AA CoR RbR #AbR RS AR' |
||
269 | print(header) |
||
270 | txt = 'Ref,Model,RMSD after refinement,Number of aligned atoms after refinement, Number of refinement cycles, RMSD before refinement, Number of aligned atoms before refinement, Raw alignment score, Number of residues aligned\n' |
||
271 | for molecule in molecules: |
||
272 | values = cmd.align(molecule, ref, cycles=cycles) |
||
273 | l = ([ref[:20].ljust(20), molecule[:20].ljust(20), str(round(values[0], 2)).ljust(4), |
||
274 | str(round(values[1], 2)).ljust(4), |
||
275 | str(round(values[2], 2)).ljust(4), |
||
276 | str(round(values[3], 2)).ljust(4), |
||
277 | str(round(values[4], 2)).ljust(4), |
||
278 | str(round(values[5])).ljust(4), |
||
279 | str(round(values[6], 2)).ljust(4)]) |
||
280 | print(' '.join(l)) |
||
281 | txt += ','.join([x.strip() for x in l]) + '\n' |
||
282 | report.append([ref, molecule, values[3], values[6]]) |
||
283 | |||
284 | with open(filename, 'w') as f: |
||
285 | f.write(txt) |
||
286 | |||
287 | cmd.extend('align_all', align_all) |
||
288 | |||
289 | def align_all_atoms(cycles = 5, filename="_rmsd_.csv"): |
||
290 | """ |
||
291 | Args: |
||
292 | |||
293 | cycles (int): maximum number of outlier rejection cycles {default: 5} |
||
294 | |||
295 | Returns: |
||
296 | |||
297 | Prints a table of ref vs models with 7 items: |
||
298 | |||
299 | RaR RMSD after refinement |
||
300 | #AA Number of aligned atoms after refinement |
||
301 | CoR Number of refinement cycles |
||
302 | RbR RMSD before refinement |
||
303 | #AbR Number of aligned atoms before refinement |
||
304 | RS Raw alignment score |
||
305 | AR Number of residues aligned |
||
306 | |||
307 | and saves the table to filename as csv |
||
308 | |||
309 | old version: |
||
310 | |||
311 | 1_solution_0_rpr 1_santalucia_1_rpr 5.60600471496582 958 4 5.763411521911621 974 416.0 46 -- RMSD 5.76 of 46 residues |
||
312 | |||
313 | """ |
||
314 | molecules = cmd.get_names_of_type("object:molecule") |
||
315 | ref = molecules.pop(0) |
||
316 | print(""" |
||
317 | RaR RMSD after refinement |
||
318 | #AA Number of aligned atoms after refinement |
||
319 | CoR Number of refinement cycles |
||
320 | RbR RMSD before refinement |
||
321 | #AbR Number of aligned atoms before refinement |
||
322 | RS Raw alignment score |
||
323 | AR Number of residues aligned |
||
324 | """) |
||
325 | report = [] |
||
326 | header = 'Ref Model RaR #AA CoR RbR #AbR RS AR' |
||
327 | print(header) |
||
328 | txt = 'Ref,Model,RMSD after refinement,Number of aligned atoms after refinement, Number of refinement cycles, RMSD before refinement, Number of aligned atoms before refinement, Raw alignment score, Number of residues aligned\n' |
||
329 | atoms = "O4'+C1'+C4'+C3'" |
||
330 | atoms = "P+O5'+C5'" #OP1' |
||
331 | ref = r"/" + ref + "////" + atoms |
||
332 | for molecule in molecules: |
||
333 | molecule = r"/" + molecule + "////" + atoms |
||
334 | values = cmd.align(molecule, ref, cycles=cycles) |
||
335 | l = ([ref[:20].ljust(20), molecule[:20].ljust(20), str(round(values[0], 2)).ljust(4), |
||
336 | str(round(values[1], 2)).ljust(4), |
||
337 | str(round(values[2], 2)).ljust(4), |
||
338 | str(round(values[3], 2)).ljust(4), |
||
339 | str(round(values[4], 2)).ljust(4), |
||
340 | str(round(values[5])).ljust(4), |
||
341 | str(round(values[6], 2)).ljust(4)]) |
||
342 | print(' '.join(l)) |
||
343 | txt += ','.join([x.strip() for x in l]) + '\n' |
||
344 | report.append([ref, molecule, values[3], values[6]]) |
||
345 | with open(filename, 'w') as f: |
||
346 | f.write(txt) |
||
347 | |||
348 | cmd.extend('aaa', align_all_atoms) |
||
349 | |||
350 | def load(f): |
||
351 | from glob import glob |
||
352 | lst = glob(f) |
||
353 | lst.sort() |
||
354 | for fil in lst: |
||
355 | cmd.load(fil) |
||
356 | cmd.extend('load', load) |
||
357 | |||
358 | |||
359 | def rmsdx(cycles = 5, matrix_fn = 'matrix.txt'): |
||
360 | """ |
||
361 | Args: |
||
362 | |||
363 | cycles (int): refinement cycles of PyMOL align, default: 5 |
||
364 | matrix_fn (string): a file to save the matrix |
||
365 | matrix is pretty much saved in space-separated values |
||
366 | so you can load it to pandas with |
||
367 | |||
368 | df = pd.read_csv('matrix.txt', sep=' ', index_col=False) |
||
369 | df = df.set_index(df.columns) |
||
370 | print(df) |
||
371 | Bact_7DCO_S Bact_5gm6_S |
||
372 | Bact_7DCO_S 0.000 0.562 |
||
373 | |||
374 | Returns: |
||
375 | |||
376 | string: matrix |
||
377 | and matrix_fn file ;-) |
||
378 | |||
379 | """ |
||
380 | models = cmd.get_names_of_type("object:molecule") |
||
381 | print(' # of models:', len(models)) |
||
382 | |||
383 | f = open(matrix_fn, 'w') |
||
384 | #t = '# ' # for numpy |
||
385 | t = '' # for pandas |
||
386 | for r1 in models: |
||
387 | # print r1, |
||
388 | t += str(r1) + ' ' # here ' ' could be changed to , or \t |
||
389 | t = t.strip() + '\n' |
||
390 | |||
391 | c = 1 |
||
392 | for r1 in models: |
||
393 | for r2 in models: |
||
394 | if r1 == r2: |
||
395 | rmsd = 0 |
||
396 | else: |
||
397 | print(r1, r2) |
||
398 | values = cmd.align(r1, r2, cycles=cycles) |
||
399 | # RaR [1] RbR [3] |
||
400 | # RaR #AA CoR RbR #AbR RS AR' |
||
401 | # (0.668652355670929, 241, 5, 1.1646124124526978, 293, 199.0, 38) |
||
402 | rmsd = round(values[0], 3) |
||
403 | t += str(rmsd) + ' ' |
||
404 | #print('...', c, r1) |
||
405 | c += 1 |
||
406 | t += '\n' |
||
407 | |||
408 | f.write(t) |
||
409 | f.close() |
||
410 | |||
411 | print(t.strip()) # matrix |
||
412 | return t |
||
413 | |||
414 | cmd.extend('rmsdx', rmsdx) |
||
415 | |||
416 | def save_all(dir=''): |
||
417 | """save_all molecule objects as pdb files. Use `cd` to get to the right folder |
||
418 | or use dir argument""" |
||
419 | if dir: |
||
420 | dir += '/' |
||
421 | molecules = cmd.get_names_of_type("object:molecule") |
||
422 | for molecule in molecules: |
||
423 | print('Saving %s ...' % molecule) |
||
424 | cmd.save(dir + molecule + '.pdb', molecule) |
||
425 | |||
426 | cmd.extend('save_all', save_all) |
||
427 | |||
428 | def ls(name='', width=80): |
||
429 | molecules = cmd.get_names_of_type("object:molecule") |
||
430 | for i in range(10): |
||
431 | print() |
||
432 | t = '' |
||
433 | if name: |
||
434 | t = name + ': ' |
||
435 | for molecule in molecules: |
||
436 | t += '%s' % molecule + ' | ' |
||
437 | print(t[:-2].center(int(width))) # remove ending | |
||
438 | print() |
||
439 | cmd.extend('ls', ls) |
||
440 | |||
441 | |||
442 | def save_each_object(folder='', prefix=''): |
||
443 | """ |
||
444 | |||
445 | Usage:: |
||
446 | |||
447 | save_each_object /Users/magnus/work/spliceosome/PyMOL4Spliceosome/chains/yB_5zwo, yB_5zwo_ |
||
448 | |||
449 | p = 'yP_6exn' # yP_5ylz' #yI_5y88' # yE_6n7r' |
||
450 | pth = '/Users/magnus/work/spliceosome/PyMOL4Spliceosome/chains/' |
||
451 | save_each_object(pth + p, p + '_') |
||
452 | |||
453 | See the application here <https://github.com/mmagnus/PyMOL4Spliceosome/releases/tag/v0.32> |
||
454 | |||
455 | .. todo:: add some way to select which objects to use |
||
456 | """ |
||
457 | obj_list = cmd.get_names('objects') |
||
458 | for o in obj_list: |
||
459 | if folder: |
||
460 | folder += '/' |
||
461 | fn = folder + prefix.strip() + o.strip() + '.pdb' |
||
462 | cmd.save(fn, o) |
||
463 | |||
464 | cmd.extend('save_each_object', save_each_object) |
||
465 | |||
466 | def rcomp(): |
||
467 | """RNA like in papers ;-) |
||
468 | |||
469 | Similar to rc() but this time it colors each (and every) structure in different colour. |
||
470 | Great on viewing-comparing superimposed structures. |
||
471 | |||
472 | """ |
||
473 | cmd.hide("sticks", "all") |
||
474 | cmd.hide("lines", "all") |
||
475 | cmd.show("cartoon", "all") |
||
476 | cmd.set("cartoon_ring_mode", 3) |
||
477 | cmd.set("cartoon_ring_finder", 2) |
||
478 | cmd.set("cartoon_ladder_mode", 2) |
||
479 | cmd.set("cartoon_ring_transparency", 0.30) |
||
480 | |||
481 | obj_list = cmd.get_names('objects') |
||
482 | |||
483 | colours = ['red', 'green', 'blue', 'yellow', 'violet', 'cyan', \ |
||
484 | 'salmon', 'lime', 'pink', 'slate', 'magenta', 'orange', 'marine', \ |
||
485 | 'olive', 'purple', 'teal', 'forest', 'firebrick', 'chocolate', \ |
||
486 | 'wheat', 'white', 'grey' ] |
||
487 | ncolours = len(colours) |
||
488 | |||
489 | # Loop over objects |
||
490 | i = 0 |
||
491 | for obj in obj_list: |
||
492 | print(" ", obj, colours[i]) |
||
493 | cmd.color(colours[i], obj) |
||
494 | i = i+1 |
||
495 | if(i == ncolours): |
||
496 | i = 0 |
||
497 | |||
498 | |||
499 | def colmol(): # donors accepters |
||
500 | t = """ |
||
501 | h_add, |
||
502 | bg gray, |
||
503 | color white, |
||
504 | color black, elem C |
||
505 | color blue , elem N |
||
506 | color red, elem O |
||
507 | color violet, elem P |
||
508 | """ |
||
509 | cmd.do(t) |
||
510 | cmd.extend('colmol', colmol) |
||
511 | |||
512 | def da(): # donors accepters |
||
513 | t = """ |
||
514 | h_add; |
||
515 | set sphere_scale, 0.3, (all) |
||
516 | set sphere_transparency, 0 |
||
517 | color blue, donors; |
||
518 | color green, acceptors; |
||
519 | show sphere, donors; |
||
520 | show sphere, acceptors; |
||
521 | color gray, name H*; # color atoms from white to gray |
||
522 | """ |
||
523 | cmd.do(t) |
||
524 | |||
525 | cmd.extend('da', da) |
||
526 | |||
527 | def da(): # donors accepters |
||
528 | t = """ |
||
529 | h_add; |
||
530 | #color blue, donors; |
||
531 | #color green, acceptors; |
||
532 | set sphere_scale, 0.3, (donors) |
||
533 | set sphere_transparency, 0 |
||
534 | show sphere, donors; |
||
535 | set sphere_scale, 0.2, (acceptors) |
||
536 | set sphere_transparency, 0 |
||
537 | set dot_width, 0.3, (donors) |
||
538 | show dots, acceptors; |
||
539 | color gray, name H*; # color atoms from white to gray |
||
540 | """ |
||
541 | cmd.do(t) |
||
542 | #cmd.extend('da', da) |
||
543 | |||
544 | def pdb(sele = ''): |
||
545 | """Get PDB content of selection. |
||
546 | .. image:: ../../rna_tools/utils/PyMOL4RNA/doc/pdb.png""" |
||
547 | f = tempfile.NamedTemporaryFile(delete=False) # True) |
||
548 | f = f.name + '.pdb' |
||
549 | #tmpfn = '/tmp/pymol_get_pdb.pdb' |
||
550 | if sele: |
||
551 | cmd.save(f, '(' + sele + ')') |
||
552 | else: |
||
553 | cmd.save(f, '(sele)') |
||
554 | for l in open(f): |
||
555 | if l.strip() not in ['TER', 'END']: |
||
556 | print(l.strip()) |
||
557 | #s = RNAStructure(tmpfn) |
||
558 | #for l in s.lines: |
||
559 | # print(l) |
||
560 | |||
561 | |||
562 | def x3dna(): |
||
563 | f = tempfile.NamedTemporaryFile(delete=False) # True) |
||
564 | #cmd.save(f.name + '.pdb', '(backbone_)') |
||
565 | cmd.save(f.name + '.pdb', '(sele)') |
||
566 | out, err = exe("rna_x3dna.py --show-log " + f.name + ".pdb ") |
||
567 | print('\n'.join(out.split('\n')[1:])) # to remove first line of py3dna /tmp/xxx |
||
568 | if err: |
||
569 | print(err) |
||
570 | f.close() |
||
571 | |||
572 | |||
573 | def clarna2(): |
||
574 | """Get contacts classification of the selected fragment based on ClaRNA (for each object). |
||
575 | |||
576 | .. image:: ../../rna_tools/tools/PyMOL4RNA/doc/clarna.png |
||
577 | """ |
||
578 | objs = cmd.get_names("objects") |
||
579 | for name in objs[:]: |
||
580 | print(name + ' ' + '-' * (70 - len(name))) |
||
581 | f = tempfile.NamedTemporaryFile(delete=False) # True) |
||
582 | #cmd.save(f.name + '.pdb', '(backbone_)') |
||
583 | cmd.save(f.name + '.pdb', '(sele) and "' + name + '"') |
||
584 | CLARNA_RUN = BIN + 'rna_clarna_run.py' |
||
585 | #cmdline = #SOURCE + " && " + |
||
586 | cmdline = CLARNA_RUN + " -ipdb " + f.name + '.pdb -bp+stack' |
||
587 | print(cmdline) |
||
588 | out, err = exe(cmdline) |
||
589 | print('\n'.join(out.split('\n')[1:])) # to remove first line of py3dna /tmp/xxx |
||
590 | if err: |
||
591 | print(err) |
||
592 | f.close() |
||
593 | |||
594 | |||
595 | def clarna(selection, folder:str='', sele_as_name=False):# fn:str=''): |
||
596 | """Get contacts classification of the selected fragment based on ClaRNA (for each object). |
||
597 | |||
598 | Args: |
||
599 | |||
600 | folder (str): The path to save temporary files, by default they are save to system tmp |
||
601 | |||
602 | # replace resi? or keep resi there? |
||
603 | |||
604 | Example:: |
||
605 | |||
606 | PyMOL>clarna sele |
||
607 | rna_clarna_run.py -ipdb /var/folders/yc/ssr9692s5fzf7k165grnhpk80000gp/T/tmp1h_bwvtx.pdb -bp+stack |
||
608 | chains: X 15 16 |
||
609 | X 15 X 16 bp A A >< 0.9427 |
||
610 | |||
611 | .. image:: ../../rna_tools/tools/PyMOL4RNA/doc/clarna.png |
||
612 | """ |
||
613 | # save the file |
||
614 | f = tempfile.NamedTemporaryFile(delete=False) # True) |
||
615 | if not folder: |
||
616 | output = f.name + '_clarna.pdb' |
||
617 | else: |
||
618 | output= folder + os.sep + os.path.basename(f.name) + '_clarna.pdb' |
||
619 | cmd.save(output, selection) |
||
620 | # run cmd |
||
621 | CLARNA_RUN = 'rna_clarna_run.py' |
||
622 | cmdline = CLARNA_RUN + " -ipdb " + output + ' -bp+stack' |
||
623 | out, err = exe(cmdline) |
||
624 | # get the output |
||
625 | print('\n'.join(out.split('\n')[1:])) # to remove first line of py3dna /tmp/xxx |
||
626 | if err: |
||
627 | print(err) |
||
628 | # load a (sele) pdb file |
||
629 | cmd.load(output) |
||
630 | f.close() |
||
631 | |||
632 | cmd.extend('clarna', clarna) # export the function for pymol |
||
633 | |||
634 | def seq(selection): |
||
635 | """Get sequence of the selected fragment using ``rna_pdb_tools.py --get_seq ``. |
||
636 | |||
637 | .. image:: ../../rna_tools/utils/PyMOL4RNA/doc/ss.png |
||
638 | """ |
||
639 | if selection.strip() == "*": |
||
640 | AllObj = cmd.get_names("all") |
||
641 | # print AllObj |
||
642 | for name in AllObj[:]: |
||
643 | if not name.startswith('_align'): |
||
644 | f = tempfile.NamedTemporaryFile(delete=False) # True) |
||
645 | f.name = f.name + '.pdb' |
||
646 | cmd.save(f.name, name) |
||
647 | cmdline = 'rna_pdb_tools.py --color-seq --get-seq ' + f.name |
||
648 | out, err = exe(cmdline) |
||
649 | if out: |
||
650 | print('> ' + name) |
||
651 | print('\n'.join(out.split('\n')[2:])) # to remove first line of py3dna /tmp/xxx |
||
652 | # hide this line: is >tmpGCszi7 nts=4 [tmpGCszi7] -- secondary structure derived by DSSR |
||
653 | if err: |
||
654 | # print(err) |
||
655 | pass |
||
656 | f.close() |
||
657 | else: |
||
658 | f = tempfile.NamedTemporaryFile(delete=False) |
||
659 | selection = strip_selection_name(selection) |
||
660 | input = os.path.dirname(f.name) + os.sep + selection + '.pdb' |
||
661 | cmd.save(input, selection) |
||
662 | cmdline = 'rna_pdb_tools.py --color-seq --get-seq ' + input |
||
663 | # print(cmdline) |
||
664 | out, err = exe(cmdline) |
||
665 | print(out) |
||
666 | if err: |
||
667 | print(err) |
||
668 | f.close() |
||
669 | |||
670 | def seqsel(): |
||
671 | """Get sequence of the selected fragment using ``rna_pdb_tools.py --get_seq ``. |
||
672 | """ |
||
673 | f = tempfile.NamedTemporaryFile(delete=False) |
||
674 | selection = '(sele)' |
||
675 | input = os.path.dirname(f.name) + os.sep + '_sele.pdb' |
||
676 | cmd.save(input, selection) |
||
677 | |||
678 | cmdline = 'rna_pdb_tools.py --get-seq ' + input |
||
679 | print(cmdline) |
||
680 | out, err = exe(cmdline) |
||
681 | print(out) |
||
682 | if err: |
||
683 | print(err) |
||
684 | f.close() |
||
685 | |||
686 | |||
687 | def ss(selection): |
||
688 | """Get Secondary Structure of (sele) based on py3dna.py. |
||
689 | |||
690 | .. image:: ../../rna_tools/utils/PyMOL4RNA/doc/ss.png |
||
691 | """ |
||
692 | f = tempfile.NamedTemporaryFile(delete=False) |
||
693 | output = os.path.dirname(f.name) + os.sep + selection + '.pdb' |
||
694 | cmd.save(output, '(sele)') |
||
695 | |||
696 | cmdline = 'rna_x3dna.py ' + output |
||
697 | out, err = exe(cmdline) |
||
698 | print('\n'.join(out.split('\n')[2:])) # to remove first line of py3dna /tmp/xxx |
||
699 | if err: |
||
700 | print(err) |
||
701 | f.close() |
||
702 | |||
703 | |||
704 | |||
705 | def rtrun(cmd, selection, suffix): |
||
706 | f = tempfile.NamedTemporaryFile(delete=False) # True) |
||
707 | output = os.path.dirname(f.name) + os.sep + selection + '.pdb' |
||
708 | output2 = os.path.dirname(f.name) + os.sep + selection + '_mut.pdb' |
||
709 | exe(cmdline) |
||
710 | print(cmdline) |
||
711 | cmd.save(output, selection) |
||
712 | |||
713 | # 'A:1A+2A+3A+4A' |
||
714 | |||
715 | def mutate(mutation, selection): |
||
716 | """ |
||
717 | """ |
||
718 | f = tempfile.NamedTemporaryFile(delete=False) # True) |
||
719 | output = os.path.dirname(f.name) + os.sep + selection + '.pdb' |
||
720 | output2 = os.path.dirname(f.name) + os.sep + selection + '_mut.pdb' |
||
721 | cmdline = "rna_pdb_tools.py --mutate " + mutation + ' ' + output + ' > ' + output2 |
||
722 | print(cmdline) |
||
723 | exe(cmdline) |
||
724 | cmd.load(output2) |
||
725 | |||
726 | cmd.extend('mutate', mutate) |
||
727 | |||
728 | |||
729 | def ss_all(): |
||
730 | """The same as ss() but for all objects.""" |
||
731 | subset = "*" |
||
732 | AllObj = cmd.get_names("all") |
||
733 | # print AllObj |
||
734 | for name in AllObj[:]: |
||
735 | if not name.startswith('_align'): |
||
736 | print('> ' + name) |
||
737 | f = tempfile.NamedTemporaryFile(delete=False) # True) |
||
738 | cmd.save(f.name, name) |
||
739 | out, err = exe(RNA_TOOLS_PATH + '/bin/rna_x3dna.py ' + f.name) |
||
740 | print('\n'.join(out.split('\n')[2:])) # to remove first line of py3dna /tmp/xxx |
||
741 | # hide this line: is >tmpGCszi7 nts=4 [tmpGCszi7] -- secondary structure derived by DSSR |
||
742 | if err: |
||
743 | print(err) |
||
744 | f.close() |
||
745 | print('-- secondary structure derived by DSSR') |
||
746 | |||
747 | |||
748 | def p(): |
||
749 | """A shortcut for putting a seq at the bottom. Pretty cool for screenshots with names of objects. |
||
750 | |||
751 | .. image:: ../../rna_tools/utils/PyMOL4RNA/doc/p.png |
||
752 | """ |
||
753 | cmd.set("seq_view_format", 4) |
||
754 | cmd.set("seq_view", 1) |
||
755 | cmd.set("seq_view_location", 1) |
||
756 | cmd.set("seq_view_overlay", 1) |
||
757 | |||
758 | |||
759 | def rna_cartoon(): |
||
760 | """http://www-cryst.bioc.cam.ac.uk/members/zbyszek/figures_pymol |
||
761 | |||
762 | .. image:: ../pngs/rna_cartoon.png |
||
763 | """ |
||
764 | cmd.set("cartoon_ring_mode", 3) |
||
765 | cmd.set("cartoon_ring_finder", 1) |
||
766 | cmd.set("cartoon_ladder_mode", 1) |
||
767 | cmd.set("cartoon_nucleic_acid_mode", 4) |
||
768 | cmd.set("cartoon_ring_transparency", 0.5) |
||
769 | |||
770 | |||
771 | def color_aa_types(): |
||
772 | """Color aminoacides types like in Cider (http://pappulab.wustl.edu/CIDER/)""" |
||
773 | txt = """ |
||
774 | color gray70, resn Ala+Ile+Leu+Met+Phe+Trp+Val #hydrophobic |
||
775 | color yellow, resn Tyr+Trp #aromatic |
||
776 | color blue, resn Arg+Lys+His # positive |
||
777 | color forest, resn GLN+SER+GLY+thr |
||
778 | color pink, resn PRO # pro |
||
779 | color red, resn GLU+asp # """ |
||
780 | print("""color (according to) amino-acids types) |
||
781 | hydrohobic (gray) Ala+Ile+Leu+Met+Phe+Trp+Val |
||
782 | aromatic (yellow) Tyr+Trp |
||
783 | positive (blue) Arg+Lys+His |
||
784 | polar (forest) Gln+Ser+Glu+Thr |
||
785 | negative (red) Glu+Asp |
||
786 | prolina ;) (pink) Pro""") |
||
787 | color_by_text(txt) |
||
788 | |||
789 | |||
790 | View Code Duplication | def color_obj(rainbow=0): |
|
791 | |||
792 | """ |
||
793 | stolen from :) |
||
794 | AUTHOR |
||
795 | Gareth Stockwell |
||
796 | |||
797 | USAGE |
||
798 | color_obj(rainbow=0) |
||
799 | |||
800 | This function colours each object currently in the PyMOL heirarchy |
||
801 | with a different colour. Colours used are either the 22 named |
||
802 | colours used by PyMOL (in which case the 23rd object, if it exists, |
||
803 | gets the same colour as the first), or are the colours of the rainbow |
||
804 | |||
805 | """ |
||
806 | |||
807 | # Process arguments |
||
808 | rainbow = int(rainbow) |
||
809 | |||
810 | # Get names of all PyMOL objects |
||
811 | obj_list = cmd.get_names('objects') |
||
812 | |||
813 | if rainbow: |
||
814 | |||
815 | print("\nColouring objects as rainbow\n") |
||
816 | |||
817 | nobj = len(obj_list) |
||
818 | |||
819 | # Create colours starting at blue(240) to red(0), using intervals |
||
820 | # of 240/(nobj-1) |
||
821 | for j in range(nobj): |
||
822 | hsv = (240-j*240/(nobj-1), 1, 1) |
||
823 | # Convert to RGB |
||
824 | rgb = hsv_to_rgb(hsv) |
||
825 | # Define the new colour |
||
826 | cmd.set_color("col" + str(j), rgb) |
||
827 | print(obj_list[j], rgb) |
||
828 | # Colour the object |
||
829 | cmd.color("col" + str(j), obj_list[j]) |
||
830 | |||
831 | else: |
||
832 | # List of available colours |
||
833 | colours = ['red', 'green', 'blue', 'yellow', 'violet', 'cyan', \ |
||
834 | 'salmon', 'lime', 'pink', 'slate', 'magenta', 'orange', 'marine', \ |
||
835 | 'olive', 'purple', 'teal', 'forest', 'firebrick', 'chocolate', \ |
||
836 | 'wheat', 'white', 'grey' ] |
||
837 | ncolours = len(colours) |
||
838 | |||
839 | # Loop over objects |
||
840 | i = 0 |
||
841 | for obj in obj_list: |
||
842 | print(" ", obj, colours[i]) |
||
843 | cmd.color(colours[i], obj) |
||
844 | i = i+1 |
||
845 | if(i == ncolours): |
||
846 | i = 0 |
||
847 | |||
848 | |||
849 | def names(): |
||
850 | # Get names of all PyMOL objects |
||
851 | obj_list = cmd.get_names('objects') |
||
852 | for o in obj_list: |
||
853 | print(o) |
||
854 | |||
855 | |||
856 | View Code Duplication | def color_rbw(rainbow=0): |
|
857 | """ |
||
858 | similar to color_obj() but this time colors every obect as rainbow |
||
859 | """ |
||
860 | rainbow = int(rainbow) |
||
861 | |||
862 | # Get names of all PyMOL objects |
||
863 | obj_list = cmd.get_names('objects') |
||
864 | |||
865 | if rainbow: |
||
866 | |||
867 | print("\nColouring objects as rainbow\n") |
||
868 | |||
869 | nobj = len(obj_list) |
||
870 | |||
871 | # Create colours starting at blue(240) to red(0), using intervals |
||
872 | # of 240/(nobj-1) |
||
873 | for j in range(nobj): |
||
874 | hsv = (240-j*240/(nobj-1), 1, 1) |
||
875 | # Convert to RGB |
||
876 | rgb = hsv_to_rgb(hsv) |
||
877 | # Define the new colour |
||
878 | cmd.set_color("col" + str(j), rgb) |
||
879 | print(obj_list[j], rgb) |
||
880 | # Colour the object |
||
881 | cmd.color("col" + str(j), obj_list[j]) |
||
882 | else: |
||
883 | colours = ['rainbow'] |
||
884 | ncolours = len(colours) |
||
885 | |||
886 | # Loop over objects |
||
887 | i = 0 |
||
888 | for obj in obj_list: |
||
889 | print(" ", obj, colours[i]) |
||
890 | cmd.spectrum('count', colours[i], obj) |
||
891 | # cmd.color(colours[i], obj) |
||
892 | i = i+1 |
||
893 | if(i == ncolours): |
||
894 | i = 0 |
||
895 | |||
896 | |||
897 | def strip_selection_name(selection_name): |
||
898 | """Quick function: (sele) -> sele""" |
||
899 | return selection_name.replace('(', '').replace(')', '') |
||
900 | |||
901 | |||
902 | View Code Duplication | def edges(selection): |
|
903 | """Save selection into a file in a temp folder and run rna_draw_edges.py on it and load it into this session""" |
||
904 | my_view = cmd.get_view() |
||
905 | f = tempfile.TemporaryDirectory() |
||
906 | tmpf = f.name + os.sep + strip_selection_name(selection) + '.pdb' |
||
907 | outf = f.name + '/output.py' |
||
908 | cmd.save(tmpf, selection) |
||
909 | cmdline = '/Users/magnus/miniconda3/bin/rna_draw_edges.py --name %s %s > %s' % (strip_selection_name(selection), tmpf, outf) |
||
910 | print(cmdline) |
||
911 | out, err = exe(cmdline) |
||
912 | if err: |
||
913 | print(err) |
||
914 | cmd.load(outf) |
||
915 | cmd.set_view(my_view) |
||
916 | |||
917 | cmd.extend('edges', edges) |
||
918 | |||
919 | View Code Duplication | def fr(selection): |
|
920 | """Save selection into a file in a temp folder and run rna_draw_edges.py on it and load it into this session""" |
||
921 | my_view = cmd.get_view() |
||
922 | f = tempfile.TemporaryDirectory() |
||
923 | tmpf = f.name + os.sep + strip_selection_name(selection) + '.pdb' |
||
924 | outf = f.name + '/output.py' |
||
925 | cmd.save(tmpf, selection) |
||
926 | path = "/Users/magnus/work/src/rna-tools/rna_tools/tools/PyMOL4RNA/" |
||
927 | cmdline = path + 'rna_draw_frames.py --name %s %s > %s' % (strip_selection_name(selection), tmpf, outf) |
||
928 | print(cmdline) |
||
929 | out, err = exe(cmdline) |
||
930 | if err: |
||
931 | print(err) |
||
932 | cmd.load(outf) |
||
933 | cmd.set_view(my_view) |
||
934 | |||
935 | cmd.extend('fr', fr) |
||
936 | |||
937 | |||
938 | def ino(): |
||
939 | """Sphare and yellow inorganic, such us Mg. |
||
940 | |||
941 | .. image:: ../../rna_tools/utils/PyMOL4RNA/doc/ion.png""" |
||
942 | cmd.show("spheres", "inorganic") |
||
943 | cmd.set('sphere_scale', '0.25', '(all)') |
||
944 | #cmd.set('sphere_scale', '1', '(all)') |
||
945 | cmd.color("yellow", "inorganic") |
||
946 | |||
947 | 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']] |
||
948 | |||
949 | |||
950 | View Code Duplication | def rgyration(selection='(all)', quiet=1): |
|
951 | ''' |
||
952 | |||
953 | [PyMOL] RES: radius of gyration |
||
954 | From: Tsjerk Wassenaar <tsjerkw@gm...> - 2011-03-31 14:07:03 |
||
955 | https://sourceforge.net/p/pymol/mailman/message/27288491/ |
||
956 | DESCRIPTION |
||
957 | |||
958 | Calculate radius of gyration |
||
959 | |||
960 | USAGE |
||
961 | |||
962 | rgyrate [ selection ] |
||
963 | :::warning::: |
||
964 | if nothing is selected function is calculating radius of gyration for all pdbs in current Pymol session |
||
965 | ''' |
||
966 | try: |
||
967 | from itertools import izip |
||
968 | except ImportError: |
||
969 | izip = zip |
||
970 | quiet = int(quiet) |
||
971 | model = cmd.get_model(selection).atom |
||
972 | x = [i.coord for i in model] |
||
973 | mass = [i.get_mass() for i in model] |
||
974 | xm = [(m*i,m*j,m*k) for (i,j,k),m in izip(x,mass)] |
||
975 | tmass = sum(mass) |
||
976 | rr = sum(mi*i+mj*j+mk*k for (i,j,k),(mi,mj,mk) in izip(x,xm)) |
||
977 | mm = sum((sum(i)/tmass)**2 for i in izip(*xm)) |
||
978 | rg = math.sqrt(rr/tmass - mm) |
||
979 | if not quiet: |
||
980 | print("Radius of gyration: %.2f" % (rg)) |
||
981 | return rg |
||
982 | |||
983 | |||
984 | View Code Duplication | def rgyrate(selection='(all)', quiet=1): |
|
985 | ''' |
||
986 | DESCRIPTION |
||
987 | |||
988 | Radius of gyration |
||
989 | |||
990 | USAGE |
||
991 | |||
992 | rgyrate [ selection ] |
||
993 | ''' |
||
994 | try: |
||
995 | from itertools import izip |
||
996 | except ImportError: |
||
997 | izip = zip |
||
998 | quiet = int(quiet) |
||
999 | model = cmd.get_model(selection).atom |
||
1000 | x = [i.coord for i in model] |
||
1001 | mass = [i.get_mass() for i in model] |
||
1002 | xm = [(m*i,m*j,m*k) for (i,j,k),m in izip(x,mass)] |
||
1003 | tmass = sum(mass) |
||
1004 | rr = sum(mi*i+mj*j+mk*k for (i,j,k),(mi,mj,mk) in izip(x,xm)) |
||
1005 | mm = sum((sum(i)/tmass)**2 for i in izip(*xm)) |
||
1006 | rg = math.sqrt(rr/tmass - mm) |
||
1007 | if not quiet: |
||
1008 | print("Radius of gyration: %.2f" % (rg)) |
||
1009 | return rg |
||
1010 | |||
1011 | cmd.extend("rgyrate", rgyrate) |
||
1012 | |||
1013 | |||
1014 | def exe(cmd): |
||
1015 | o = subprocess.Popen( |
||
1016 | cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
||
1017 | out = o.stdout.read().strip().decode() |
||
1018 | err = o.stderr.read().strip().decode() |
||
1019 | return out, err |
||
1020 | |||
1021 | |||
1022 | def qrnass(): |
||
1023 | cmd.save('/tmp/sele.pdb', '(sele)') |
||
1024 | #os.system('/home/magnus/opt/qrnas/QRNA02/QRNA -i ' + f + ' -c /home/magnus/opt/qrnas/QRNA02/configfile.txt -o out.pdb') |
||
1025 | cmdline = '~/opt/qrnas/QRNA -i /tmp/sele.pdb -c ~/opt/qrnas/configfile.txt -o out.pdb' |
||
1026 | print(cmdline) |
||
1027 | os.system(cmdline) |
||
1028 | #print(exe(cmdline)) |
||
1029 | cmd.delete('mini') |
||
1030 | cmd.load('out.pdb', 'mini') |
||
1031 | |||
1032 | cmd.extend('qrnass', qrnass) |
||
1033 | |||
1034 | def qrnas(): |
||
1035 | subset = "*" |
||
1036 | AllObj=cmd.get_names("all") |
||
1037 | #print AllObj |
||
1038 | for x in AllObj[:]: |
||
1039 | print(x, 'qrnas...') |
||
1040 | #print(AllObj[0],x) |
||
1041 | f = tempfile.NamedTemporaryFile(delete=True) |
||
1042 | #print f.name |
||
1043 | #f.write(XX) |
||
1044 | cmd.save(f.name, x) |
||
1045 | #p = Process(target=mini) |
||
1046 | #p.start() |
||
1047 | mini() |
||
1048 | #cmd.load('out.pdb', 'ref') |
||
1049 | #p.join() |
||
1050 | #print x |
||
1051 | #print '\n'.join(out.split('\n')[1:]) # to remove first line of py3dna /tmp/xxx |
||
1052 | f.close() |
||
1053 | break |
||
1054 | align_all() |
||
1055 | rr() |
||
1056 | cmd.set('grid_mode', 1) |
||
1057 | |||
1058 | |||
1059 | def inspect(name, dont_green=False): |
||
1060 | f = tempfile.NamedTemporaryFile(delete=False) |
||
1061 | cmd.save(f.name + '.pdb', name) |
||
1062 | out, err = exe('rna_pdb_tools.py --inspect ' + f.name + '.pdb') |
||
1063 | if not dont_green: |
||
1064 | cmd.color('green', name) |
||
1065 | for l in out.split('\n'): |
||
1066 | hit = re.findall('chain: (?P<chain>\w+).*\# (?P<residue>\d+)', l) |
||
1067 | if hit: # [('X', '1')] |
||
1068 | cmd.color('red', name + ' and chain ' + hit[0][0] + ' and resi ' + hit[0][1]) |
||
1069 | print(out) |
||
1070 | |||
1071 | cmd.extend('inspect', inspect) |
||
1072 | |||
1073 | def ll(): |
||
1074 | cmd.do('hide all') |
||
1075 | cmd.do('show lines') |
||
1076 | cmd.extend('ll', ll) |
||
1077 | print('ll - show lines only') |
||
1078 | |||
1079 | View Code Duplication | def rpr(selection): |
|
1080 | """rpr""" |
||
1081 | f = tempfile.NamedTemporaryFile(delete=False) |
||
1082 | input = os.path.dirname(f.name) + os.sep + selection + '.pdb' |
||
1083 | cmd.save(input, selection) |
||
1084 | |||
1085 | output = os.path.dirname(f.name) + os.sep + selection + '_rpr.pdb' |
||
1086 | |||
1087 | out, err = exe('rna_pdb_tools.py --rpr ' + input + ' > ' + output) |
||
1088 | cmd.load(output) |
||
1089 | print(out) |
||
1090 | cmd.extend('rpr', rpr) |
||
1091 | |||
1092 | View Code Duplication | def diff(selection, selection2): |
|
1093 | """rpr""" |
||
1094 | f = tempfile.NamedTemporaryFile(delete=False) |
||
1095 | input = os.path.dirname(f.name) + os.sep + selection + '.pdb' |
||
1096 | cmd.save(input, selection) |
||
1097 | output = os.path.dirname(f.name) + os.sep + selection2 + '.pdb' |
||
1098 | cmd.save(input, selection) |
||
1099 | cmdline = 'diffpdb.py ' + input + ' ' + output + ' &' |
||
1100 | print(cmdline) |
||
1101 | #os.system(cmdline) |
||
1102 | exe(cmdline) |
||
1103 | |||
1104 | cmd.extend('diff', diff) |
||
1105 | |||
1106 | def mini(f): # min with qrna |
||
1107 | #os.system('/home/magnus/opt/qrnas/QRNA02/QRNA -i ' + f + ' -c /home/magnus/opt/qrnas/QRNA02/configfile.txt -o out.pdb') |
||
1108 | cmd = '~/opt/qrnas/QRNA -i /tmp/' + f + ' -c ~/opt/qrnas/configfile.txt -o out.pdb' |
||
1109 | print(cmd) |
||
1110 | os.system(cmd) |
||
1111 | |||
1112 | #cmd.delete('mini') |
||
1113 | cmd.load('out.pdb', 'mini') |
||
1114 | print('end') |
||
1115 | |||
1116 | |||
1117 | def reload(): |
||
1118 | """Reload ~/.pymolrc and all included there packages (e.g. with run <foo.py>)""" |
||
1119 | cmd.do('@ ~/.pymolrc') |
||
1120 | |||
1121 | |||
1122 | def rlabel(): |
||
1123 | cmd = "n. C1'", '"%s %s" % (resn, resi)' |
||
1124 | print('label ' + cmd) |
||
1125 | cmd.label(cmd) |
||
1126 | |||
1127 | |||
1128 | |||
1129 | def sav(name): #sav |
||
1130 | # cmd.bg_color( "white" ) |
||
1131 | tf = tempfile.NamedTemporaryFile(delete=False) |
||
1132 | fn = tf.name + '.png' |
||
1133 | tf = tempfile.NamedTemporaryFile(delete=False) |
||
1134 | cfn = tf.name + '.png' |
||
1135 | |||
1136 | psefn = '~/Desktop/' + name + '.pse' |
||
1137 | cmd.save(psefn) |
||
1138 | |||
1139 | cmd.save(fn) |
||
1140 | |||
1141 | cmdline= "/opt/homebrew/bin/convert " + fn + " -gravity center -crop 3:3 +repage " + cfn |
||
1142 | print(cmdline) |
||
1143 | os.system(cmdline) |
||
1144 | cmdline = '/opt/homebrew/bin/fileicon set ' + psefn + ' ' + cfn |
||
1145 | print(cmdline) |
||
1146 | os.system(cmdline) |
||
1147 | |||
1148 | #cmd.png(coverfn, 576,576) |
||
1149 | #cmd.ray(576,576) |
||
1150 | cmd.extend('sav', sav) |
||
1151 | |||
1152 | def hide_rna(): |
||
1153 | cmd.hide('(polymer.nucleic)') |
||
1154 | cmd.extend('rna-hide', hide_rna) |
||
1155 | |||
1156 | def show_rna(): |
||
1157 | cmd.show('(polymer.nucleic)') |
||
1158 | cmd.extend('rna-show', show_rna) |
||
1159 | |||
1160 | def clr(): |
||
1161 | cmd.do('delete *') |
||
1162 | cmd.extend('clr', clr) |
||
1163 | print('clr - delete all') |
||
1164 | |||
1165 | def bw(): |
||
1166 | """clr - make white bg and structure black""" |
||
1167 | cmd.bg_color( "white" ) |
||
1168 | color_by_text('color black, all') |
||
1169 | cmd.extend('bw', bw) |
||
1170 | print('bw - white bg, black all') |
||
1171 | |||
1172 | def select_rna(): |
||
1173 | cmd.select('polymer.nucleic') |
||
1174 | cmd.extend('select-rna', select_rna) |
||
1175 | |||
1176 | def hide_protein(): |
||
1177 | cmd.hide('(polymer.protein)') |
||
1178 | #cmd.extend('protein-hide', hide_protein) |
||
1179 | #cmd.extend('rp-hide', hide_protein) |
||
1180 | def select_protein(): |
||
1181 | cmd.select('polymer.protein') |
||
1182 | cmd.extend('protein-select', select_protein) |
||
1183 | |||
1184 | def tmp(): |
||
1185 | cmd.save('/home/' + user + '/Desktop/' + tmp + '.png') |
||
1186 | cmd.save('/home/' + user + '/Desktop/' + tmp + '.pse') |
||
1187 | |||
1188 | def tp(): #tp temp pse |
||
1189 | """tp here""" |
||
1190 | import datetime |
||
1191 | |||
1192 | # cmd.bg_color( "white" ) |
||
1193 | tf = tempfile.NamedTemporaryFile(delete=False) |
||
1194 | fn = tf.name + '.png' |
||
1195 | tf = tempfile.NamedTemporaryFile(delete=False) |
||
1196 | cfn = tf.name + '.png' |
||
1197 | |||
1198 | date = datetime.datetime.today().strftime('%Y-%m-%d.%H%M%S') |
||
1199 | psefn = '~/Desktop/' + date + '.pse' |
||
1200 | cmd.save(psefn) |
||
1201 | |||
1202 | cmd.save(fn) |
||
1203 | |||
1204 | cmdline= "/opt/homebrew/bin/convert " + fn + " -gravity center -crop 3:3 +repage " + cfn |
||
1205 | print(cmdline) |
||
1206 | os.system(cmdline) |
||
1207 | cmdline = '/opt/homebrew/bin/fileicon set ' + psefn + ' ' + cfn |
||
1208 | print(cmdline) |
||
1209 | os.system(cmdline) |
||
1210 | |||
1211 | cmd.extend('tp', tp) |
||
1212 | |||
1213 | def sav_tmp(): |
||
1214 | from shutil import copyfile |
||
1215 | import datetime |
||
1216 | try: |
||
1217 | TMP_FOLDER + ' ' |
||
1218 | except: |
||
1219 | print("Error: Set up TMP_FOLDER in your ~/.pymolrc, e.g. TMP_FOLDER = '/home/magnus/Desktop/PyMOL/'") |
||
1220 | return |
||
1221 | |||
1222 | try: |
||
1223 | os.mkdir(TMP_FOLDER) |
||
1224 | except: |
||
1225 | pass |
||
1226 | |||
1227 | date = datetime.datetime.today().strftime('%Y-%m-%d.%H%M%S') |
||
1228 | try: |
||
1229 | fn = TMP_FOLDER + os.sep + id + '_' + date + '.pse' |
||
1230 | except TypeError: |
||
1231 | fn = TMP_FOLDER + os.sep + '_' + date + '.pse' |
||
1232 | cmd.save(fn) |
||
1233 | print('Save...' + fn) |
||
1234 | cmd.save(fn.replace('.pse', '.png')) |
||
1235 | copyfile(fn, TMP_FOLDER + '/last.pse') |
||
1236 | |||
1237 | def load_tmp(): |
||
1238 | print('Load...') |
||
1239 | cmd.load(TMP_FOLDER + '/last.pse') |
||
1240 | |||
1241 | |||
1242 | def trim(): |
||
1243 | cmd.do("remove solvent") |
||
1244 | cmd.do("remove resn NA") |
||
1245 | |||
1246 | cmd.extend('trim', trim) |
||
1247 | |||
1248 | def get_resi(): |
||
1249 | """ |
||
1250 | PyMOL>get_resi() |
||
1251 | 358+376+288+290+359+383+386+382+289+287+384+357+385+360+377+361 |
||
1252 | """ |
||
1253 | stored.residues = set() |
||
1254 | cmd.iterate('(sele)', "stored.residues.add(resi)") # ('289') # residue only |
||
1255 | print('+'.join(stored.residues))#[:-1]) |
||
1256 | |||
1257 | #cmd.iterate('(sele)', "stored.residues.add((chain, resi))") # ('A', '289') |
||
1258 | #print(r, end='+') # ('A', '289') |
||
1259 | #selection = object + ' and index ' + str(index) |
||
1260 | #cmd.iterate('(sele)', 'l.append([resn, resi])') |
||
1261 | #rint(l) |
||
1262 | |||
1263 | def findN(r): |
||
1264 | c = 'select br. all within ' + str(r) + ' of (sele)' |
||
1265 | cmd.do(c) |
||
1266 | |||
1267 | def white(): |
||
1268 | cmd.set('dash_color', 'black') |
||
1269 | cmd.set('dash_width', 2) |
||
1270 | cmd.bg_color( "white" ) |
||
1271 | cmd.extend('w', white) |
||
1272 | |||
1273 | def desc(t='', width=80): |
||
1274 | print() |
||
1275 | print() |
||
1276 | print() |
||
1277 | print(t.center(int(width))) |
||
1278 | print() |
||
1279 | print() |
||
1280 | print() |
||
1281 | |||
1282 | def s(): # quick save selected to tmp.pdb |
||
1283 | cmd.do('save tmp.pdb, (sele)') |
||
1284 | cmd.extend('s', s) |
||
1285 | print('s - quick save selected to tmp.pdb') |
||
1286 | |||
1287 | def draw(): |
||
1288 | #cmd.select("name C1'") |
||
1289 | t = """ |
||
1290 | |||
1291 | |||
1292 | set sphere_scale, 0.4, name C1' |
||
1293 | show sphere, name C1' |
||
1294 | color black, name C1' |
||
1295 | |||
1296 | remove name OP2+OP1+O5'+P+C5'+O2'+O3'+C4'+C3'+C2'+O4' |
||
1297 | |||
1298 | h_add |
||
1299 | |||
1300 | select (bound_to name C1') and name H* |
||
1301 | remove (sele) |
||
1302 | |||
1303 | set spec_reflect, 0 |
||
1304 | # https://pymolwiki.org/index.php/Spec_reflect |
||
1305 | |||
1306 | #set sphere_transparency, 0 |
||
1307 | #color blue, donors; |
||
1308 | #color green, acceptors; |
||
1309 | #show sphere, donors; |
||
1310 | #show sphere, acceptors; |
||
1311 | |||
1312 | color gray, name H*; # color atoms from white to gray |
||
1313 | |||
1314 | |||
1315 | set dash_color, black |
||
1316 | set dash_width, 1; set dash_gap, 0.2 |
||
1317 | bg white; |
||
1318 | #color black; |
||
1319 | """ |
||
1320 | cmd_text(t) |
||
1321 | |||
1322 | cmd.extend('draw', draw) |
||
1323 | cmd.extend('dr', draw) |
||
1324 | |||
1325 | def se(): # save |
||
1326 | cmd.do('save tmp.pdb, (enabled)') |
||
1327 | cmd.extend('se', se) |
||
1328 | print('se - quick save enabled to tmp.pdb') |
||
1329 | |||
1330 | |||
1331 | def axes_big(): |
||
1332 | """ |
||
1333 | https://pymolwiki.org/index.php/Axes |
||
1334 | """ |
||
1335 | cmd.delete('axes') |
||
1336 | |||
1337 | # create the axes object, draw axes with cylinders coloured red, green, |
||
1338 | #blue for X, Y and Z |
||
1339 | |||
1340 | obj = [ |
||
1341 | CYLINDER, 0., 0., 0., 10., 0., 0., 0.2, 1.0, 1.0, 1.0, 1.0, 0.0, 0., |
||
1342 | CYLINDER, 0., 0., 0., 0., 10., 0., 0.2, 1.0, 1.0, 1.0, 0., 1.0, 0., |
||
1343 | CYLINDER, 0., 0., 0., 0., 0., 10., 0.2, 1.0, 1.0, 1.0, 0., 0.0, 1.0, |
||
1344 | ] |
||
1345 | |||
1346 | # add labels to axes object (requires pymol version 0.8 or greater, I |
||
1347 | # believe |
||
1348 | |||
1349 | cyl_text(obj,plain,[-5.,-5.,-1],'Origin',0.20,axes=[[3,0,0],[0,3,0],[0,0,3]]) |
||
1350 | cyl_text(obj,plain,[10.,0.,0.],'X',0.20,axes=[[3,0,0],[0,3,0],[0,0,3]]) |
||
1351 | cyl_text(obj,plain,[0.,10.,0.],'Y',0.20,axes=[[3,0,0],[0,3,0],[0,0,3]]) |
||
1352 | cyl_text(obj,plain,[0.,0.,10.],'Z',0.20,axes=[[3,0,0],[0,3,0],[0,0,3]]) |
||
1353 | |||
1354 | # then we load it into PyMOL |
||
1355 | cmd.load_cgo(obj,'axes') |
||
1356 | |||
1357 | def axes(gradient=False): |
||
1358 | """ |
||
1359 | https://pymolwiki.org/index.php/Axes |
||
1360 | """ |
||
1361 | cmd.delete('axes') |
||
1362 | |||
1363 | # create the axes object, draw axes with cylinders coloured red, green, |
||
1364 | #blue for X, Y and Z |
||
1365 | |||
1366 | l = 1 |
||
1367 | width = 0.01 # 0.2 |
||
1368 | if gradient: # with gradient |
||
1369 | obj = [ |
||
1370 | CYLINDER, 0., 0., 0., l, 0., 0., width, 1.0, 1.0, 1.0, 1.0, 0.0, 0., |
||
1371 | CYLINDER, 0., 0., 0., 0., l, 0., width, 1.0, 1.0, 1.0, 0., 1.0, 0., |
||
1372 | CYLINDER, 0., 0., 0., 0., 0., l, width, 1.0, 1.0, 1.0, 0., 0.0, 1.0, |
||
1373 | ] |
||
1374 | else: |
||
1375 | obj = [ |
||
1376 | CYLINDER, 0., 0., 0., l, 0., 0., width, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, |
||
1377 | CYLINDER, 0., 0., 0., 0., l, 0., width, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, |
||
1378 | CYLINDER, 0., 0., 0., 0., 0., l, width, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, |
||
1379 | ] |
||
1380 | |||
1381 | # add labels to axes object (requires pymol version 0.8 or greater, I |
||
1382 | # believe |
||
1383 | l |
||
1384 | #cyl_text(obj,plain,[-5.,-5.,-1],'Origin',0.20,axes=[[3,0,0],[0,3,0],[0,0,3]]) |
||
1385 | width = 0.005 # 0.20 |
||
1386 | size = 0.05 |
||
1387 | cyl_text(obj,plain,[l,0.,0.],'X',width,axes=[[size,0,0],[0,size,0],[0,0,size]]) |
||
1388 | cyl_text(obj,plain,[0.,l,0.],'Y',width,axes=[[size,0,0],[0,size,0],[0,0,size]]) |
||
1389 | cyl_text(obj,plain,[0.,0.,l],'Z',width,axes=[[size,0,0],[0,size,0],[0,0,size]]) |
||
1390 | |||
1391 | # then we load it into PyMOL |
||
1392 | cmd.load_cgo(obj,'axes') |
||
1393 | |||
1394 | |||
1395 | cmd.extend('axes', axes) |
||
1396 | |||
1397 | |||
1398 | def axes2(length=0.75): |
||
1399 | """Draw XYZ, no lables here, see axes() |
||
1400 | https://pymolwiki.org/index.php/Axes |
||
1401 | |||
1402 | Args: |
||
1403 | lenght: length of axes |
||
1404 | """ |
||
1405 | cmd.delete('axes') |
||
1406 | print('Draw axis red, green blue for X, Y and Z') |
||
1407 | w = 0.06 # cylinder width |
||
1408 | l = float(length) # cylinder length |
||
1409 | h = 0.25 # cone hight |
||
1410 | d = w * 1.618 # cone base diameter |
||
1411 | |||
1412 | obj = [CYLINDER, 0.0, 0.0, 0.0, l, 0.0, 0.0, w, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, |
||
1413 | CYLINDER, 0.0, 0.0, 0.0, 0.0, l, 0.0, w, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, |
||
1414 | CYLINDER, 0.0, 0.0, 0.0, 0.0, 0.0, l, w, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, |
||
1415 | CONE, l, 0.0, 0.0, h+l, 0.0, 0.0, d, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, |
||
1416 | CONE, 0.0, l, 0.0, 0.0, h+l, 0.0, d, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, |
||
1417 | CONE, 0.0, 0.0, l, 0.0, 0.0, h+l, d, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0] |
||
1418 | |||
1419 | cmd.load_cgo(obj, 'axes') |
||
1420 | cmd.extend('axes2', axes2) |
||
1421 | |||
1422 | def v(x, y, z, name='v'): |
||
1423 | cmd.delete(name) |
||
1424 | w = 0.01 # cylinder width |
||
1425 | length=0.75 |
||
1426 | l = float(length) # cylinder length |
||
1427 | h = 0.25 # cone hight |
||
1428 | d = w * 1.618 # cone base diameter |
||
1429 | r1,g1,b1 = 1,1,1 |
||
1430 | r2,g2,b2 = r1,g1,b1 |
||
1431 | obj = [CYLINDER, 0.0, 0.0, 0.0, x, y, z, w, r1, g1, b1, r2, g2, b2] |
||
1432 | width = 0.005 # 0.20 |
||
1433 | size = 0.2 |
||
1434 | cyl_text(obj,plain,[x,y,z],name,width,axes=[[size,0,0],[0,size,0],[0,0,size]]) |
||
1435 | cmd.load_cgo(obj, name) |
||
1436 | |||
1437 | cmd.extend('v', v) |
||
1438 | |||
1439 | def ha(): |
||
1440 | """ |
||
1441 | cmd.do('h_add') |
||
1442 | """ |
||
1443 | cmd.do('h_add') |
||
1444 | cmd.extend('ha', ha) |
||
1445 | |||
1446 | def hb(): # hydrogen bonds |
||
1447 | cmd.do('contacts *,*') |
||
1448 | cmd.extend('hb', hb) |
||
1449 | |||
1450 | |||
1451 | def pn(): # pn |
||
1452 | cmd_text('save ~/Desktop/tmp.png') |
||
1453 | cmd.extend('pn', pn) # pn |
||
1454 | def quickref(): |
||
1455 | print(' PyMOL4RNA (rna-tools) ') |
||
1456 | print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') |
||
1457 | print('Quickref `qr`: ') |
||
1458 | print(' alter (sele), chain="B" ') |
||
1459 | print(' alter (sele), resv -= 4') |
||
1460 | print(' alter (chain B), resv -= 44 ') |
||
1461 | print(" select br. all within 15 of (sele)") |
||
1462 | print(" select br. all within 15 of resi 574") |
||
1463 | print(" select br. all within 15 of resi 377 # O. ihheyensis") |
||
1464 | print(' select br. all within 15 of U6_snRNA and resi 80') |
||
1465 | print(' set dash_color, red; set dash_width, 4') |
||
1466 | print(' p - prepare seq for printing') |
||
1467 | print(' rp - rna present, object names only click to get compact legend') |
||
1468 | print(' rp17') |
||
1469 | print(' rna_cartoon') |
||
1470 | print(' rs') |
||
1471 | print(' rcomp') |
||
1472 | print(' color_obj') |
||
1473 | print(' color_rbw') |
||
1474 | print(' aa') |
||
1475 | print(' findN') |
||
1476 | print(' savt - save_transformed <object>, <file>') |
||
1477 | print(' select br. all within 20 of (sele) #within with aa') |
||
1478 | #print(' spl - color snRNAs of the spliceosome:' |
||
1479 | # green: U2, blue: U5, red:U6, orange:U2""") |
||
1480 | print('\_ RNA_TOOLS_PATH env variable used: ' + RNA_TOOLS_PATH) |
||
1481 | |||
1482 | from rna_tools.tools.PyMOL4RNA.libs.show_contacts import show_contacts |
||
1483 | from rna_tools.tools.PyMOL4RNA.libs.get_raw_distances import get_raw_distances |
||
1484 | |||
1485 | |||
1486 | try: |
||
1487 | from pymol import cmd |
||
1488 | # axes.py |
||
1489 | from pymol.cgo import * |
||
1490 | from pymol.vfont import plain |
||
1491 | except ImportError: |
||
1492 | print("PyMOL Python lib is missing") |
||
1493 | # sys.exit(0) |
||
1494 | |||
1495 | try: |
||
1496 | import imp |
||
1497 | from rna_tools.rna_tools_lib import RNAStructure |
||
1498 | from rna_tools.tools.PyMOL4RNA import code_for_spl |
||
1499 | imp.reload(code_for_spl) |
||
1500 | print('code_for_spl loaded...') |
||
1501 | from rna_tools.tools.PyMOL4RNA import code_for_color_spl |
||
1502 | imp.reload(code_for_color_spl) |
||
1503 | print('code_for_color_spl loaded...') |
||
1504 | import rna_tools |
||
1505 | RNA_TOOLS_PATH = rna_tools.rna_tools_lib.get_rna_tools_path() |
||
1506 | sys.path.insert(0, RNA_TOOLS_PATH) # '/Users/magnus/work/src/rna-tools/rna_tools/tools/PyMOL4RNA')# |
||
1507 | #(os.path.abspath(os.path.dirname(__file__)))) |
||
1508 | from rna_tools.tools.PyMOL4RNA import PyMOL4Spliceosome |
||
1509 | imp.reload(PyMOL4Spliceosome) |
||
1510 | except ImportError: |
||
1511 | print("rna_tools lib is missing") |
||
1512 | RNA_TOOLS_PATH = '' |
||
1513 | |||
1514 | try: |
||
1515 | RNA_TOOLS_PATH |
||
1516 | EXECUTABLE |
||
1517 | except NameError: |
||
1518 | EXECUTABLE="/bin/zsh" |
||
1519 | SOURCE="" |
||
1520 | |||
1521 | try: |
||
1522 | cmd.set('cartoon_gap_cutoff', 0) |
||
1523 | except: |
||
1524 | pass |
||
1525 | |||
1526 | |||
1527 | print(__doc__) |
||
1528 | try: |
||
1529 | from pymol import cmd |
||
1530 | except ImportError: |
||
1531 | print("PyMOL Python lib is missing") |
||
1532 | else: |
||
1533 | #quickref() |
||
1534 | #cmd.set_key('CTRL-S', cmd.save, ['/home/magnus/Desktop/tmp.pse']) |
||
1535 | cmd.set_key('CTRL-S', sav_tmp) |
||
1536 | cmd.set_key('CTRL-Z', load_tmp) # ostatni wrzucam tutaj |
||
1537 | #cmd.load, ['/home/magnus/Desktop/tmp.pse']) |
||
1538 | # main code # |
||
1539 | |||
1540 | cmd.extend('quickref', quickref) |
||
1541 | cmd.extend('qr', quickref) |
||
1542 | |||
1543 | cmd.extend('rp', rp) |
||
1544 | cmd.extend('p', p) |
||
1545 | cmd.extend('pdb', pdb) |
||
1546 | cmd.extend('seq', seq) |
||
1547 | cmd.extend('seqsel', seqsel) |
||
1548 | cmd.extend('rseq', seq) |
||
1549 | cmd.extend('rna_cartoon', rna_cartoon) |
||
1550 | cmd.extend('rs', rs) |
||
1551 | cmd.extend('ino', ino) |
||
1552 | cmd.extend('rcomp', rcomp) |
||
1553 | cmd.extend('color_obj', color_obj) |
||
1554 | cmd.extend('color_rbw', color_rbw) |
||
1555 | cmd.extend('aa', align_all) |
||
1556 | cmd.extend('ss', ss) |
||
1557 | cmd.extend('ss_all', ss_all) |
||
1558 | cmd.extend('clarna', clarna) |
||
1559 | cmd.extend('x3dna', x3dna) |
||
1560 | cmd.extend("rgyration", rgyration) |
||
1561 | cmd.extend('rlabel', 'rlabel') |
||
1562 | |||
1563 | cmd.extend('reload', reload) |
||
1564 | cmd.extend('rl', reload) |
||
1565 | |||
1566 | cmd.extend('color_aa_types', color_aa_types) |
||
1567 | |||
1568 | cmd.extend('names', names) |
||
1569 | |||
1570 | cmd.extend('findX', findN) |
||
1571 | |||
1572 | # set dash lines #hbonds #hydrogen |
||
1573 | cmd.set('dash_color', 'white') |
||
1574 | cmd.set('dash_width', 2) |
||
1575 | cmd.set('cartoon_tube_radius', 0.5) |
||
1576 | |||
1577 | cmd.extend('save_transformed', save_transformed) |
||
1578 | cmd.extend('savt', save_transformed) |
||
1579 | cmd.extend('show_all_at_once', show_all_at_once) |
||
1580 | |||
1581 | cmd.set('ignore_case', 'off') |
||
1582 | #cmd.set('cartoon_ring_mode', '3') |
||
1583 | #cmd.set('cartoon_ring_finder', '2') |
||
1584 | #cmd.extend('spl_select', spl_select) |
||
1585 | # print('ignore_case made off') |
||
1586 | print('\_ PYMOL4RNA loading .... [ok]') |
||
1587 | |||
1588 | cmd.extend('desc', desc) |
||
1589 | #cmd.do('set overlay, 1') |
||
1590 | |||
1591 | #### change do desktop |
||
1592 | user = getpass.getuser() |
||
1593 | cw = os.path.abspath(os.getcwd()) |
||
1594 | print(cw) |
||
1595 | if cw == '/Users/magnus': |
||
1596 | print('change to Desktop') |
||
1597 | os.chdir('/Users/magnus/Desktop/') |
||
1598 | cw = os.path.abspath(os.getcwd()) |
||
1599 | print(cw) |
||
1600 |