Skip to content

Commit c8d6966

Browse files
committed
Revert "tmalign.py: Code cleanup"
This reverts commit 0b3aba1.
1 parent c8381d1 commit c8d6966

File tree

1 file changed

+72
-71
lines changed

1 file changed

+72
-71
lines changed

tmalign.py

+72-71
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
"""
1+
'''
22
(c) 2011-2012 Thomas Holder, MPI for Developmental Biology
3-
"""
3+
'''
44

55
from __future__ import print_function
6-
from pymol import cmd, CmdException
76

87
__author__ = 'Thomas Holder'
98
__version__ = '1.1'
109
__license__ = 'BSD-2-Clause'
1110

11+
from pymol import cmd, CmdException
12+
1213

1314
def save_pdb_without_ter(filename, selection, **kwargs):
14-
"""
15-
DESCRIPTION
15+
'''
16+
DESCRIPTION
1617
17-
Save PDB file without TER records. External applications like TMalign and
18-
DynDom stop reading PDB files at TER records, which might be undesired in
19-
case of missing loops.
20-
"""
18+
Save PDB file without TER records. External applications like TMalign and
19+
DynDom stop reading PDB files at TER records, which might be undesired in
20+
case of missing loops.
21+
'''
2122
v = cmd.get_setting_boolean('pdb_use_ter_records')
2223
if v:
2324
cmd.unset('pdb_use_ter_records')
@@ -28,34 +29,34 @@ def save_pdb_without_ter(filename, selection, **kwargs):
2829

2930
def alignwithanymethod(mobile, target, methods='align super cealign tmalign',
3031
async=1, quiet=1):
31-
"""
32-
DESCRIPTION
32+
'''
33+
DESCRIPTION
3334
34-
Align copies of mobile to target with several alignment methods
35+
Align copies of mobile to target with several alignment methods
3536
36-
ARGUMENTS
37+
ARGUMENTS
3738
38-
mobile = string: atom selection
39+
mobile = string: atom selection
3940
40-
target = string: atom selection
41+
target = string: atom selection
4142
42-
methods = string: space separated list of PyMOL commands which take
43-
arguments "mobile" and "target" (in any order) {default: align super
44-
cealign tmalign}
45-
"""
43+
methods = string: space separated list of PyMOL commands which take
44+
arguments "mobile" and "target" (in any order) {default: align super
45+
cealign tmalign}
46+
'''
4647
import threading
4748
import time
4849
methods = methods.split()
4950
async, quiet = int(async), int(quiet)
5051
mobile_obj = cmd.get_object_list('first (' + mobile + ')')[0]
5152

52-
def myalign(method_):
53-
newmobile = cmd.get_unused_name(mobile_obj + '_' + method_)
53+
def myalign(method):
54+
newmobile = cmd.get_unused_name(mobile_obj + '_' + method)
5455
cmd.create(newmobile, mobile_obj)
5556
start = time.time()
56-
cmd.do('%s mobile=%s in %s, target=%s' % (method_, newmobile, mobile, target))
57+
cmd.do('%s mobile=%s in %s, target=%s' % (method, newmobile, mobile, target))
5758
if not quiet:
58-
print('Finished: %s (%.2f sec)' % (method_, time.time() - start))
59+
print('Finished: %s (%.2f sec)' % (method, time.time() - start))
5960

6061
for method in methods:
6162
if async:
@@ -66,34 +67,34 @@ def myalign(method_):
6667
myalign(method)
6768

6869

69-
def tmalign(mobile, target, args='', exe='TMalign', ter=0, transform=1, object_=None, quiet=0):
70-
"""
71-
DESCRIPTION
70+
def tmalign(mobile, target, args='', exe='TMalign', ter=0, transform=1, object=None, quiet=0):
71+
'''
72+
DESCRIPTION
7273
73-
TMalign wrapper
74+
TMalign wrapper
7475
75-
Reference: Y. Zhang and J. Skolnick, Nucl. Acids Res. 2005 33, 2302-9
76-
http://zhanglab.ccmb.med.umich.edu/TM-align/
76+
Reference: Y. Zhang and J. Skolnick, Nucl. Acids Res. 2005 33, 2302-9
77+
http://zhanglab.ccmb.med.umich.edu/TM-align/
7778
78-
USAGE
79+
USAGE
7980
80-
tmalign mobile, target [, args [, exe ]]
81+
tmalign mobile, target [, args [, exe ]]
8182
82-
ARGUMENTS
83+
ARGUMENTS
8384
84-
mobile, target = string: atom selections
85+
mobile, target = string: atom selections
8586
86-
args = string: Extra arguments like -d0 5 -L 100
87+
args = string: Extra arguments like -d0 5 -L 100
8788
88-
exe = string: Path to TMalign executable {default: TMalign}
89+
exe = string: Path to TMalign executable {default: TMalign}
8990
90-
ter = 0/1: If ter=0, then ignore chain breaks because TMalign will stop
91-
at first TER record {default: 0}
91+
ter = 0/1: If ter=0, then ignore chain breaks because TMalign will stop
92+
at first TER record {default: 0}
9293
93-
SEE ALSO
94+
SEE ALSO
9495
95-
tmscore, mmalign
96-
"""
96+
tmscore, mmalign
97+
'''
9798
import subprocess
9899
import tempfile
99100
import os
@@ -104,8 +105,8 @@ def tmalign(mobile, target, args='', exe='TMalign', ter=0, transform=1, object_=
104105
mobile_filename = tempfile.mktemp('.pdb', 'mobile')
105106
target_filename = tempfile.mktemp('.pdb', 'target')
106107
matrix_filename = tempfile.mktemp('.txt', 'matrix')
107-
mobile_ca_sele = '(%s) and (not hetatm) and name CA and alt +A' % mobile
108-
target_ca_sele = '(%s) and (not hetatm) and name CA and alt +A' % target
108+
mobile_ca_sele = '(%s) and (not hetatm) and name CA and alt +A' % (mobile)
109+
target_ca_sele = '(%s) and (not hetatm) and name CA and alt +A' % (target)
109110

110111
if ter:
111112
save = cmd.save
@@ -121,7 +122,7 @@ def tmalign(mobile, target, args='', exe='TMalign', ter=0, transform=1, object_=
121122
process = subprocess.Popen(args, stdout=subprocess.PIPE)
122123
lines = process.stdout.readlines()
123124
except OSError:
124-
print('Cannot execute "%s", please provide full path to TMscore or TMalign executable' % exe)
125+
print('Cannot execute "%s", please provide full path to TMscore or TMalign executable' % (exe))
125126
raise CmdException
126127
finally:
127128
os.remove(mobile_filename)
@@ -148,7 +149,7 @@ def tmalign(mobile, target, args='', exe='TMalign', ter=0, transform=1, object_=
148149
elif line.lower().startswith(' -------- rotation matrix'):
149150
rowcount = 1
150151
elif line.startswith('(":" denotes'):
151-
alignment = [line_it.next().rstrip() for _ in range(3)]
152+
alignment = [line_it.next().rstrip() for i in range(3)]
152153
else:
153154
match = re_score.search(line)
154155
if match is not None:
@@ -166,10 +167,10 @@ def tmalign(mobile, target, args='', exe='TMalign', ter=0, transform=1, object_=
166167
matrix.extend([0, 0, 0, 1])
167168

168169
if int(transform):
169-
cmd.transform_selection('byobject (%s)' % mobile, matrix, homogenous=1)
170+
cmd.transform_selection('byobject (%s)' % (mobile), matrix, homogenous=1)
170171

171172
# alignment object
172-
if object_ is not None:
173+
if object is not None:
173174
mobile_idx, target_idx = [], []
174175
space = {'mobile_idx': mobile_idx, 'target_idx': target_idx}
175176
cmd.iterate(mobile_ca_sele, 'mobile_idx.append("%s`%d" % (model, index))', space=space)
@@ -180,61 +181,61 @@ def tmalign(mobile, target, args='', exe='TMalign', ter=0, transform=1, object_=
180181
for i, aa in enumerate(alignment[2]):
181182
if aa == '-':
182183
target_idx.insert(i, None)
183-
if len(mobile_idx) == len(target_idx) == len(alignment[2]):
184+
if (len(mobile_idx) == len(target_idx) == len(alignment[2])):
184185
cmd.rms_cur(
185186
' '.join(idx for (idx, m) in zip(mobile_idx, alignment[1]) if m in ':.'),
186187
' '.join(idx for (idx, m) in zip(target_idx, alignment[1]) if m in ':.'),
187-
cycles=0, matchmaker=4, object=object_)
188+
cycles=0, matchmaker=4, object=object)
188189
else:
189190
print('Could not load alignment object')
190191

191192
if not quiet and r is not None:
192-
print('Found in output TM-score = %.4f' % r)
193+
print('Found in output TM-score = %.4f' % (r))
193194

194195
return r
195196

196197

197198
def tmscore(mobile, target, args='', exe='TMscore', quiet=0, **kwargs):
198-
"""
199-
DESCRIPTION
199+
'''
200+
DESCRIPTION
200201
201-
TMscore wrapper
202+
TMscore wrapper
202203
203-
Reference: Yang Zhang and Jeffrey Skolnick, Proteins 2004 57: 702-710
204-
http://zhanglab.ccmb.med.umich.edu/TM-score/
204+
Reference: Yang Zhang and Jeffrey Skolnick, Proteins 2004 57: 702-710
205+
http://zhanglab.ccmb.med.umich.edu/TM-score/
205206
206-
ARGUMENTS
207+
ARGUMENTS
207208
208-
mobile, target = string: atom selections
209+
mobile, target = string: atom selections
209210
210-
args = string: Extra arguments like -d 5
211+
args = string: Extra arguments like -d 5
211212
212-
exe = string: Path to TMscore executable {default: TMscore}
213+
exe = string: Path to TMscore executable {default: TMscore}
213214
214-
ter = 0/1: If ter=0, then ignore chain breaks because TMscore will stop
215-
at first TER record {default: 0}
215+
ter = 0/1: If ter=0, then ignore chain breaks because TMscore will stop
216+
at first TER record {default: 0}
216217
217-
SEE ALSO
218+
SEE ALSO
218219
219-
tmalign, mmalign
220-
"""
220+
tmalign, mmalign
221+
'''
221222
kwargs.pop('_self', None)
222223
return tmalign(mobile, target, args, exe, quiet=quiet, **kwargs)
223224

224225

225226
def mmalign(mobile, target, args='', exe='MMalign', ter=0, transform=1, quiet=0):
226-
"""
227-
DESCRIPTION
227+
'''
228+
DESCRIPTION
228229
229-
MMalign wrapper
230+
MMalign wrapper
230231
231-
Reference: S. Mukherjee and Y. Zhang, Nucleic Acids Research 2009; 37: e83
232-
http://zhanglab.ccmb.med.umich.edu/MM-align/
232+
Reference: S. Mukherjee and Y. Zhang, Nucleic Acids Research 2009; 37: e83
233+
http://zhanglab.ccmb.med.umich.edu/MM-align/
233234
234-
SEE ALSO
235+
SEE ALSO
235236
236-
tmalign, tmscore
237-
"""
237+
tmalign, tmscore
238+
'''
238239
return tmalign(mobile, target, args, exe, ter, transform, quiet=quiet)
239240

240241
# pymol commands

0 commit comments

Comments
 (0)