Skip to content

Commit 4ca8ba7

Browse files
committed
SuperSymPlugin: Preliminary Python 3 support
Can't test because cctbx is not Python 3 compatible yet.
1 parent 529bc61 commit 4ca8ba7

File tree

1 file changed

+41
-57
lines changed

1 file changed

+41
-57
lines changed

plugins/SuperSymPlugin.py

Lines changed: 41 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
from Tkinter import *
2-
import tkSimpleDialog
3-
import tkMessageBox
4-
import tkColorChooser
5-
import tkFileDialog
1+
from __future__ import print_function
2+
63
import sys
4+
if sys.version_info[0] < 3:
5+
from Tkinter import *
6+
import tkSimpleDialog
7+
import tkMessageBox
8+
import tkColorChooser
9+
else:
10+
from tkinter import *
11+
from tkinter import simpledialog as tkSimpleDialog
12+
import tkinter.messagebox as tkMessageBox
13+
import tkinter.colorchooser as tkColorChooser
14+
715
import re
8-
from pymol import stored, cmd, selector
16+
from pymol import stored, cmd
917
import math
1018
from pymol.cgo import *
1119
from pymol.vfont import plain
12-
try:
13-
from cctbx import sgtbx, uctbx
14-
import numpy as N
15-
from numpy.linalg import *
16-
from cctbx import uctbx, sgtbx
17-
except:
18-
quit("Oops! SuperSym requires cctbx and numeric python to function. Please install these.")
20+
21+
from cctbx import sgtbx, uctbx
22+
import numpy as N
23+
from numpy.linalg import *
1924

2025

2126
def __init__(self):
@@ -391,7 +396,7 @@ def symset(prefix = "sym", object = -1, x=0,y=0,z=0, opList = []):
391396
try:
392397
op = opMatrices[i]
393398
except:
394-
print "Bad symmetry partner numbers. Try again."
399+
print("Bad symmetry partner numbers. Try again.")
395400
quit()
396401
copy = "%s%02d_%d_%d_%d" % (prefix, i, x, y, z)
397402
cmd.copy(copy, object)
@@ -522,8 +527,8 @@ def get_orthogonalization_matrix(object, quiet = 0):
522527
[0.0, b * sg, c * (ca - cb * cg) / sg],
523528
[0.0, 0.0, c * sb * math.sqrt(1.0 - ((cb * cg - ca) / (sb * sg))**2)]])
524529
if not quiet:
525-
print fracToOrt
526-
print inv(fracToOrt)
530+
print(fracToOrt)
531+
print(inv(fracToOrt))
527532
return fracToOrt
528533

529534
# -*- coding: utf-8 -*-
@@ -562,7 +567,7 @@ def findSurfaceResidues(objSel="(all)", cutoff=2.5, selName = 0):
562567

563568
stored.tmp_dict = {}
564569
cmd.iterate(tmpObj, "stored.tmp_dict[(chain,resv)]=1")
565-
exposed = stored.tmp_dict.keys()
570+
exposed = list(stored.tmp_dict.keys())
566571
exposed.sort()
567572

568573
cmd.select(selName, objSel + " in " + tmpObj )
@@ -615,14 +620,14 @@ def draw_cell_param(cell_param_list,radius=1.0,mode=0):
615620

616621
U=uctbx.unit_cell((cell_param_list))
617622

618-
vert_000 = map(set_to_zero,U.orthogonalize((0.,0.,0)))
619-
vert_100 = map(set_to_zero,U.orthogonalize((1.,0.,0)))
620-
vert_010 = map(set_to_zero,U.orthogonalize((0.,1.,0)))
621-
vert_001 = map(set_to_zero,U.orthogonalize((0.,0.,1)))
622-
vert_110 = map(set_to_zero,U.orthogonalize((1.,1.,0)))
623-
vert_011 = map(set_to_zero,U.orthogonalize((0.,1.,1)))
624-
vert_101 = map(set_to_zero,U.orthogonalize((1.,0.,1)))
625-
vert_111 = map(set_to_zero,U.orthogonalize((1.,1.,1)))
623+
vert_000 = list(map(set_to_zero,U.orthogonalize((0.,0.,0))))
624+
vert_100 = list(map(set_to_zero,U.orthogonalize((1.,0.,0))))
625+
vert_010 = list(map(set_to_zero,U.orthogonalize((0.,1.,0))))
626+
vert_001 = list(map(set_to_zero,U.orthogonalize((0.,0.,1))))
627+
vert_110 = list(map(set_to_zero,U.orthogonalize((1.,1.,0))))
628+
vert_011 = list(map(set_to_zero,U.orthogonalize((0.,1.,1))))
629+
vert_101 = list(map(set_to_zero,U.orthogonalize((1.,0.,1))))
630+
vert_111 = list(map(set_to_zero,U.orthogonalize((1.,1.,1))))
626631

627632
# vert_000 = map(None,U.orthogonalize((0.,0.,0)))
628633
# vert_100 = map(None,U.orthogonalize((1.,0.,0)))
@@ -692,9 +697,9 @@ def draw_cell_param(cell_param_list,radius=1.0,mode=0):
692697
#wire_text(text,plain,map(None,U.orthogonalize((0.0,0.0,1.05))),'C',[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]])
693698

694699
cyl_text(text,plain,[-5.,-5.,-1],'Origin',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]],color=[1.0,0.0,1.0])
695-
cyl_text(text,plain,map(None,U.orthogonalize((1.05,0.0,0.0))),'A',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]],color=[1.0,0.0,0.0])
696-
cyl_text(text,plain,map(None,U.orthogonalize((0.0,1.05,0.0))),'B',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]],color=[0.0,1.0,0.0])
697-
cyl_text(text,plain,map(None,U.orthogonalize((0.0,0.0,1.05))),'C',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]],color=[0.0,0.0,1.0])
700+
cyl_text(text,plain,list(U.orthogonalize((1.05,0.0,0.0))),'A',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]],color=[1.0,0.0,0.0])
701+
cyl_text(text,plain,list(U.orthogonalize((0.0,1.05,0.0))),'B',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]],color=[0.0,1.0,0.0])
702+
cyl_text(text,plain,list(U.orthogonalize((0.0,0.0,1.05))),'C',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]],color=[0.0,0.0,1.0])
698703

699704
cmd.load_cgo(text,'text')
700705

@@ -865,8 +870,8 @@ def draw_symops_param(cell_param_list,sg,radius=0.2,extension=0):
865870
if symop_axes:
866871
for ax in symop_axes:
867872
#print ax
868-
start = map(set_to_zero,U.orthogonalize(list(ax['start'])))
869-
end = map(set_to_zero,U.orthogonalize(list(ax['end'])))
873+
start = list(map(set_to_zero,U.orthogonalize(list(ax['start']))))
874+
end = list(map(set_to_zero,U.orthogonalize(list(ax['end']))))
870875
###############################################################################
871876
# Tried rounding off start and end values in order to understand why axes go
872877
# missing in the drawing, but seem to be present in the cgo. Doesn't help!
@@ -910,7 +915,7 @@ def draw_symops_param(cell_param_list,sg,radius=0.2,extension=0):
910915
# #######################################################################################
911916

912917
else:
913-
print "\nNo symmetry axes found for this space group: %s\n" % sg
918+
print("\nNo symmetry axes found for this space group: %s\n" % sg)
914919

915920
for key,val in ax_obj.items():
916921
name=sg + "_" + key
@@ -937,27 +942,6 @@ def draw_symops_param(cell_param_list,sg,radius=0.2,extension=0):
937942
def list_plus(lhs, rhs):
938943
return [l + r for l, r in zip(lhs, rhs)]
939944

940-
def list_minus(lhs, rhs):
941-
return [l - r for l, r in zip(lhs, rhs)]
942-
943-
def list_multiplies(lhs, rhs):
944-
return [l * r for l, r in zip(lhs, rhs)]
945-
946-
def list_divides(lhs, rhs):
947-
return [l / r for l, r in zip(lhs, rhs)]
948-
949-
def list_modulus(lhs, rhs):
950-
return [l % r for l, r in zip(lhs, rhs)]
951-
952-
def list_dot_product(lhs, rhs=0):
953-
if rhs == 0: rhs = lhs
954-
result = 0
955-
for l, r in zip(lhs, rhs): result += l * r
956-
return result
957-
958-
def str_ev(EV):
959-
return "[%d,%d,%d]" % EV
960-
961945
###def fract_2_dec(fraction):
962946
### list = fraction.split('/')
963947
### if len(list) == 2 and list[1] != 0:
@@ -1081,7 +1065,7 @@ def get_all_axes(space_group_symbol=None, space_group_info=None, extension=0):
10811065
if rtmxanal:
10821066
#print rtmxanal
10831067
axes_dict[rtmxanal] = 0
1084-
axes_list = axes_dict.keys()
1068+
axes_list = list(axes_dict.keys())
10851069
axes_list.sort()
10861070

10871071
# reject nonenantiomorphic space groups
@@ -1090,14 +1074,14 @@ def get_all_axes(space_group_symbol=None, space_group_info=None, extension=0):
10901074
sgtbx.space_group_info(space_group_symbol).show_summary(),
10911075
#print len(axes_list), space_group_symbol
10921076
except:
1093-
print space_group, space_group_symbol
1094-
print
1077+
print(space_group, space_group_symbol)
1078+
print()
10951079
sys.exit(1)
10961080
axes = []
10971081
for a in axes_list:
10981082
if len(a) == 3 and len(a[1]) == 3 and len(a[2]) == 3:
10991083
tmp_dict = {}
1100-
print "%4s %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f " % (a[0],a[1][0],a[1][1],a[1][2],a[2][0],a[2][1],a[2][2])
1084+
print("%4s %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f " % (a[0],a[1][0],a[1][1],a[1][2],a[2][0],a[2][1],a[2][2]))
11011085
tmp_dict['symb'] = a[0]
11021086
start_array = N.asarray(a[1])
11031087
end_array = N.asarray(a[2])
@@ -1109,7 +1093,7 @@ def get_all_axes(space_group_symbol=None, space_group_info=None, extension=0):
11091093
#rlc# tmp_dict['end'] = a[2]
11101094
axes.append(tmp_dict)
11111095
else:
1112-
print a
1096+
print(a)
11131097
else:
11141098
return None
11151099

0 commit comments

Comments
 (0)