Skip to content

Commit 7d8f6e5

Browse files
committed
dssr_block.py: A simple "x3dna-dssr --block-file" wrapper
1 parent 4ed3bff commit 7d8f6e5

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

dssr_block.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
'''
2+
http://pymolwiki.org/index.php/dssr_block
3+
4+
(c) Thomas Holder, Schrodinger LLC
5+
6+
License: BSD-2
7+
'''
8+
9+
from pymol import cmd, CmdException
10+
11+
def dssr_block(selection='all', state=-1,
12+
block_file='face',
13+
block_depth=0.5,
14+
name='',
15+
exe='x3dna-dssr',
16+
quiet=1):
17+
'''
18+
DESCRIPTION
19+
20+
Create a nucleic acid base "block" cartoon with DSSR.
21+
22+
Requires the "x3dna-dssr" program, available from http://x3dna.org/
23+
24+
USAGE
25+
26+
dssr_block [ selection [, state [, block_file [, block_depth
27+
[, name [, exe ]]]]]]
28+
29+
ARGUMENTS
30+
31+
selection = str: atom selection {default: all}
32+
33+
state = int: object state (0 for all states) {default: -1, current state}
34+
35+
block_file = face|edge|wc|equal|minor|gray: Corresponds to the --block-file
36+
option (see DSSR manual). Values can be combined, e.g. "wc-minor".
37+
{default: face}
38+
39+
block_depth = float: thickness of rectangular blocks {default: 0.5}
40+
41+
name = str: name of new CGO object {default: dssr_block##}
42+
43+
exe = str: path to "x3dna-dssr" executable {default: x3dna-dssr}
44+
45+
EXAMPLE
46+
47+
fetch 1ehz, async=0
48+
as cartoon
49+
dssr_block
50+
set cartoon_ladder_radius, 0.1
51+
set cartoon_ladder_color, gray
52+
set cartoon_nucleic_acid_mode, 1
53+
54+
# multi-state
55+
fetch 2n2d, async=0
56+
dssr_block 2n2d, 0
57+
set all_states
58+
'''
59+
import subprocess
60+
import tempfile, os
61+
62+
state, quiet = int(state), int(quiet)
63+
64+
tmpfilepdb = tempfile.mktemp('.pdb')
65+
tmpfiler3d = tempfile.mktemp('.r3d')
66+
67+
args = [exe,
68+
'--block-file=' + block_file,
69+
'--block-depth=' + str(block_depth),
70+
'-i=' + tmpfilepdb,
71+
'-o=' + tmpfiler3d,
72+
]
73+
74+
if not name:
75+
name = cmd.get_unused_name('dssr_block')
76+
77+
states = [state] if state != 0 else \
78+
range(1, cmd.count_states(selection) + 1)
79+
80+
try:
81+
for state in states:
82+
cmd.save(tmpfilepdb, selection, state)
83+
subprocess.check_call(args)
84+
cmd.load(tmpfiler3d, name, max(1, state), zoom=0)
85+
except subprocess.CalledProcessError:
86+
raise CmdException('"' + exe + '" failed')
87+
except OSError:
88+
raise CmdException('Cannot execute exe="' + exe + '"')
89+
finally:
90+
try:
91+
os.remove(tmpfilepdb)
92+
os.remove(tmpfiler3d)
93+
except OSError:
94+
pass
95+
96+
cmd.extend('dssr_block', dssr_block)
97+
98+
# tab-completion of arguments
99+
cmd.auto_arg[0].update({
100+
'dssr_block' : cmd.auto_arg[0]['zoom'],
101+
})
102+
cmd.auto_arg[2].update({
103+
'dssr_block' : [cmd.Shortcut(['face', 'edge', 'wc', 'equal', 'minor', 'gray']), 'block_file', ''],
104+
})
105+
106+
# vi: expandtab:smarttab

0 commit comments

Comments
 (0)