Skip to content

Commit 7cc8a42

Browse files
committed
Python3 support
Signed-off-by: Justin Lecher <[email protected]>
1 parent 6a44dfb commit 7cc8a42

12 files changed

+155
-148
lines changed

ccp4_ncont.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
44
ccp4_ncont -- parses CCP4/NCONT log file and selects residues and atoms.
55
http://www.ccp4.ac.uk/html/ncont.html
6-
6+
77
PARAMS
88
contactsfile
99
filename of the CCP4/NCONT contacts log file
10-
10+
1111
selName1
1212
the name prefix for the _res and _atom selections returned for the
1313
source set of chain
14-
14+
1515
selName2
16-
the name prefix for the _res and _atom selections returned for the
16+
the name prefix for the _res and _atom selections returned for the
1717
target set of chain
18-
18+
1919
RETURNS
2020
4 selections of interface residues and atoms are created and named
2121
depending on what you passed into selName1 and selName2
22-
22+
2323
AUTHOR
2424
Gerhard Reitmayr and Dalia Daujotyte, 2009.
2525
'''
26-
26+
from __future__ import print_function
2727
from pymol import cmd
2828
import re
2929

@@ -53,7 +53,7 @@ def parseNCONTContacts(f):
5353
s2.append(matches[0])
5454
pairs.append((len(s1) - 1, len(s2) - 1))
5555
else:
56-
print "Unknown mode", mode
56+
print("Unknown mode", mode)
5757

5858

5959
def ccp4_ncont(contactsfile, selName1="source", selName2="target"):

ccp4_pisa.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22
See more here: http://www.pymolwiki.org/index.php/ccp4_pisa
33
44
parse a PISA contact file and create atoms selections for all interfaces
5-
6-
For each interface, two selections are created containing the atoms of
7-
the interface on each chain. The selection names follow the convention
8-
bondtype_#Id_Chain1Chain2. If Chain1 equals Chain2 then the two selections are
9-
numbered.
10-
5+
6+
For each interface, two selections are created containing the atoms of
7+
the interface on each chain. The selection names follow the convention
8+
bondtype_#Id_Chain1Chain2. If Chain1 equals Chain2 then the two selections are
9+
numbered.
10+
1111
bondtype corresponds to h-bonds, salt-bridges, ss-bonds and cov-bonds and
1212
are marked with the prefixes hb, sb, ss and cov.
13-
13+
1414
For example, all h-bonds in interface 3 between chain A and D create the selections
1515
hb_3_AD and hb_3_DA.
16-
16+
1717
Salt-bridges in interface 4 between chain A and a symmetry copy of A creates the selections
1818
sb_4_AA1 and sb_4_AA2.
19-
19+
2020
PARAMS
21-
filename
21+
filename
2222
filename of the PISA contacts file
23-
23+
2424
RETURNS
25-
a set of selections in PYMOL.
26-
25+
a set of selections in PYMOL.
26+
2727
AUTHOR
2828
Gerhard Reitmayr and Dalia Daujotyte, 2011.
2929
'''
30-
30+
from __future__ import print_function
3131
from pymol import cmd
3232
from xml.etree import ElementTree
3333

@@ -47,7 +47,7 @@ def parseBond(elementDir):
4747

4848

4949
def parseInterface(interface, bondname):
50-
""" parses a single interface into the interface id, the two chain names connected
50+
""" parses a single interface into the interface id, the two chain names connected
5151
and two lists of atoms for each chain"""
5252
bonds = interface.findall(bondname)
5353
id = interface.find('id').text.strip()
@@ -86,8 +86,8 @@ def createInterfaceSelection(interface, prefix):
8686
cmd.select(leftname, leftlist)
8787
cmd.select(rightname, rightlist)
8888
except:
89-
print leftname, '\t', leftlist
90-
print rightname, '\t', rightlist
89+
print(leftname, '\t', leftlist)
90+
print(rightname, '\t', rightlist)
9191
return leftname, rightname
9292

9393

@@ -115,11 +115,11 @@ def ccp4_pisa(filename):
115115
try:
116116
cmd.select(name, " or ".join(allselections))
117117
except:
118-
print name, '\t', " or ".join(allselections)
118+
print(name, '\t', " or ".join(allselections))
119119

120-
print 'selectPISAContacts found interfaces with',
120+
print('selectPISAContacts found interfaces with', end=' ')
121121
for number, type in zip(result, bond_types):
122-
print number, type[0], ",",
122+
print(number, type[0], ",", end=' ')
123123

124124
try:
125125
cmd.extend("ccp4_pisa", ccp4_pisa)

center_of_mass.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
See more here: http://www.pymolwiki.org/index.php/center_of_mass
33
44
DESCRIPTION
5-
5+
66
Places a pseudoatom at the center of mass
7-
7+
88
Author: Sean Law
99
Michigan State University
1010
slaw (at) msu . edu
11-
11+
1212
SEE ALSO
13-
13+
1414
pseudoatom, get_com
1515
'''
1616

17-
17+
from __future__ import print_function
1818
from pymol import cmd
1919

2020

@@ -31,14 +31,14 @@ def com(selection, state=None, mass=None, object=None, quiet=1, **kwargs):
3131
if (state != None):
3232
x, y, z = get_com(selection, mass=mass, quiet=quiet)
3333
if not quiet:
34-
print "%f %f %f" % (x, y, z)
34+
print("%f %f %f" % (x, y, z))
3535
cmd.pseudoatom(object, pos=[x, y, z], **kwargs)
3636
cmd.show("spheres", object)
3737
else:
3838
for i in range(cmd.count_states()):
3939
x, y, z = get_com(selection, mass=mass, state=i + 1, quiet=quiet)
4040
if not quiet:
41-
print "State %d:%f %f %f" % (i + 1, x, y, z)
41+
print("State %d:%f %f %f" % (i + 1, x, y, z))
4242
cmd.pseudoatom(object, pos=[x, y, z], state=i + 1, **kwargs)
4343
cmd.show("spheres", 'last ' + object)
4444

@@ -59,7 +59,7 @@ def get_com(selection, state=1, mass=None, quiet=1):
5959

6060
totmass = 0.0
6161
if mass != None and not quiet:
62-
print "Calculating mass-weighted COM"
62+
print("Calculating mass-weighted COM")
6363

6464
state = int(state)
6565
model = cmd.get_model(selection, state)

centroid.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
44
DESCRIPTION
55
get the centroid (geometric center) of a selection or move selection to the origin.
6-
6+
77
ARGUMENTS
88
selection = string: a valid PyMOL selection {default: all}
99
center = 0 or 1: if center=1 center the selection {default: 0}
1010
returns: centroid: [ x, y, z ]
11-
11+
1212
SEE ALSO
1313
get_extent, get_position, http://pymolwiki.org/index.php/Center_Of_Mass
1414
@@ -37,6 +37,7 @@
3737
# REV : 1
3838
3939
'''
40+
from __future__ import print_function
4041
from pymol import cmd
4142
from pymol import stored
4243
from chempy import cpv
@@ -54,7 +55,7 @@ def centroid(selection='all', center=0, quiet=1):
5455
centroid = cpv.scale(centroid, 1. / nAtom)
5556

5657
if not int(quiet):
57-
print ' centroid: [%8.3f,%8.3f,%8.3f]' % tuple(centroid)
58+
print(' centroid: [%8.3f,%8.3f,%8.3f]' % tuple(centroid))
5859

5960
if int(center):
6061
cmd.alter_state(1, selection, "(x,y,z)=sub((x,y,z), centroid)",

cgo_arrow.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
License: BSD-2-Clause
77
'''
88

9+
from __future__ import print_function
910
from pymol import cmd, cgo, CmdException
1011

1112

cgo_grid.py

+28-28
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
################################################################################
2020
'''
21-
21+
from __future__ import print_function
2222
from pymol import cmd
2323
from pymol import stored
2424
from pymol.cgo import *
@@ -167,7 +167,7 @@ def get_coord(v):
167167
# more than one atom --> use "center"
168168
# alt check!
169169
if cmd.count_atoms('(alt *) and not (alt "")')!=0:
170-
print "cgo_grid: warning! alternative coordinates found for origin, using center!"
170+
print("cgo_grid: warning! alternative coordinates found for origin, using center!")
171171
view_temp=cmd.get_view()
172172
cmd.zoom(v)
173173
v=cmd.get_position()
@@ -180,8 +180,8 @@ def eval_color(v):
180180
try:
181181
if not v:
182182
v=eval(cmd.get('bg_rgb'))
183-
v=map(sum, zip(v,[-1,-1,-1]))
184-
v=map(abs, v)
183+
v=list(map(sum, list(zip(v,[-1,-1,-1]))))
184+
v=list(map(abs, v))
185185
if v[0]==v[1]==v[2]==0.5: # grey
186186
v=[0,0,0]
187187
return v
@@ -209,7 +209,7 @@ def eval_color(v):
209209
nstates=int(nstates)
210210
if nstates<1:
211211
nstates=1
212-
print "NB! nstates set to 1 (automatic minimum)"
212+
print("NB! nstates set to 1 (automatic minimum)")
213213
length_x=float(length_x)
214214
if length_z=='':
215215
length_z=length_x
@@ -221,14 +221,14 @@ def eval_color(v):
221221
npoints_x=int(npoints_x)
222222
if npoints_x<1:
223223
npoints_x=1
224-
print "NB! npoints_x set to 1 (automatic minimum)"
224+
print("NB! npoints_x set to 1 (automatic minimum)")
225225
if npoints_z =='':
226226
npoints_z=int(length_z)+1
227227
else:
228228
npoints_z=int(npoints_z)
229229
if npoints_z<1:
230230
npoints_z=1
231-
print "NB! npoints_x set to 1 (automatic minimum)"
231+
print("NB! npoints_x set to 1 (automatic minimum)")
232232

233233
nwaves_x=abs(float(nwaves_x))
234234
if nwaves_z=='':
@@ -314,11 +314,11 @@ def eval_color(v):
314314
raise Exception("Unexpected error!")
315315

316316
if (nstates==1):
317-
if not quiet: print "Creating one state object!"
317+
if not quiet: print("Creating one state object!")
318318

319319
if startframe > endframe:
320320
startframe, endframe = endframe, startframe
321-
if not quiet: print "Inverted start and end frames!"
321+
if not quiet: print("Inverted start and end frames!")
322322

323323

324324
########## BEGIN OF FUNCTIONAL SCRIPT ##########
@@ -464,36 +464,36 @@ def eval_color(v):
464464
framecount=0
465465
# count up from first state
466466
if framecount==1: countvar=1
467-
if not quiet: print "object loaded and animated with frames!"
467+
if not quiet: print("object loaded and animated with frames!")
468468
else:
469-
if not quiet: print "object loaded!"
469+
if not quiet: print("object loaded!")
470470

471471
#OUTPUT
472472
if not quiet:
473-
print "Grid variables for:",name
474-
print "corner:", xyz1
475-
print "vector 1:", xyz2
476-
print "vector 2:", xyz3
473+
print("Grid variables for:",name)
474+
print("corner:", xyz1)
475+
print("vector 1:", xyz2)
476+
print("vector 2:", xyz3)
477477

478-
print "length_x:",length_x
479-
print "length_z:",length_z
480-
print "npoints_x:", npoints_x
481-
print "npoints_z:", npoints_z
478+
print("length_x:",length_x)
479+
print("length_z:",length_z)
480+
print("npoints_x:", npoints_x)
481+
print("npoints_z:", npoints_z)
482482

483-
print "nwaves_x:", nwaves_x
484-
print "nwaves_z:", nwaves_z
483+
print("nwaves_x:", nwaves_x)
484+
print("nwaves_z:", nwaves_z)
485485

486-
print "offset_x:",offset_x
487-
print "offset_z:",offset_z
486+
print("offset_x:",offset_x)
487+
print("offset_z:",offset_z)
488488

489-
print "gain_x:",gain_x
490-
print "gain_z:",gain_z
489+
print("gain_x:",gain_x)
490+
print("gain_z:",gain_z)
491491

492-
print "thickness:",thickness
492+
print("thickness:",thickness)
493493

494-
print "states", nstates
494+
print("states", nstates)
495495
if (not endframe==startframe):
496-
print "frames: start:",startframe,"end:",endframe
496+
print("frames: start:",startframe,"end:",endframe)
497497

498498
return grid_xyz
499499

color_by_conservation.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,32 @@
1010
from the alignment object
1111
color
1212
(string) valid PyMOL spectrum name
13-
13+
1414
as_putty
1515
(0 or 1) if 0 display is not changed, else participating objects are shown
1616
as cartoon putty, colored by the 'color' field
1717
'''
1818

19+
from __future__ import print_function
1920
from pymol import cmd
2021

2122

2223
def color_by_conservation(aln, names=(), color="rainbow", as_putty=0, _self=cmd):
2324
# PyMOL doesn't yet know about object:alignment
2425
# but we need to check that this exists or we might crash
2526
if _self.get_type(aln) not in ("object:", "object:alignment"):
26-
print "Error: Bad or incorrectly specified alignment object."
27+
print("Error: Bad or incorrectly specified alignment object.")
2728
return None
2829

2930
r = cmd.get_raw_alignment(aln)
3031

3132
if names == ():
3233
known_objs = []
33-
map(known_objs.extend, map(lambda x: map(lambda y: y[0], x), r))
34+
list(map(known_objs.extend, [[y[0] for y in x] for x in r]))
3435
known_objs = set(known_objs)
3536

3637
# highest number of matches seen
37-
M = max(map(len, r)) + 1
38+
M = max(list(map(len, r))) + 1
3839
else:
3940
known_objs = set(names)
4041
M = len(known_objs) + 1

0 commit comments

Comments
 (0)