Skip to content

Commit

Permalink
Python3 support
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Lecher <jlec@gentoo.org>
  • Loading branch information
jlec committed Dec 7, 2015
1 parent dc23f72 commit dbd3b1a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
31 changes: 16 additions & 15 deletions modevectors.py
@@ -1,6 +1,7 @@
'''
See more here: http://www.pymolwiki.org/index.php/Modevectors
'''
from __future__ import print_function
from pymol.cgo import * # get constants
from math import *
from pymol import cmd
Expand Down Expand Up @@ -37,7 +38,7 @@ def modevectors(first_obj_frame, last_obj_frame, first_state=1, last_state=1, ou
factor 1.0 Float Multiplies each mode vector length by a specified factor.
Values between 0 and 1 will decrease the relative mode vector length.
Values greater than 1 will increase the relative mode vector length.
notail 0 Integer Hides tails and only uses cones (porcupine plot)
notail 0 Integer Hides tails and only uses cones (porcupine plot)
"""

framefirst = cmd.get_model(first_obj_frame, first_state)
Expand All @@ -55,8 +56,8 @@ def modevectors(first_obj_frame, last_obj_frame, first_state=1, last_state=1, ou

headrgb = headrgb.strip('" []()')
tailrgb = tailrgb.strip('" []()')
hr, hg, hb = map(float, headrgb.split(','))
tr, tg, tb = map(float, tailrgb.split(','))
hr, hg, hb = list(map(float, headrgb.split(',')))
tr, tg, tb = list(map(float, tailrgb.split(',')))

version = cmd.get_version()[1]
arrow = []
Expand Down Expand Up @@ -138,10 +139,10 @@ def modevectors(first_obj_frame, last_obj_frame, first_state=1, last_state=1, ou
" ATMNUM " + str(atom.index)
# print current_atom
if 'current_atom' not in atom_lookup:
print "\nError: " + current_atom + " from \""\
print("\nError: " + current_atom + " from \""\
+ last_obj_frame +\
" \"is not found in \"" + first_obj_frame + "\"."
print "\nPlease check your input and/or selections and try again."
" \"is not found in \"" + first_obj_frame + "\".")
print("\nPlease check your input and/or selections and try again.")
exit_flag = True
break

Expand All @@ -168,10 +169,10 @@ def modevectors(first_obj_frame, last_obj_frame, first_state=1, last_state=1, ou
###################################################

if len(x2) != len(x1):
print "\nError: \"" + first_obj_frame +\
print("\nError: \"" + first_obj_frame +\
"\" and \"" + last_obj_frame +\
"\" contain different number of residue/atoms."
print "\nPlease check your input and/or selections and try again."
"\" contain different number of residue/atoms.")
print("\nPlease check your input and/or selections and try again.")
return
else:
# Continue with representing modevectors!
Expand Down Expand Up @@ -232,7 +233,7 @@ def modevectors(first_obj_frame, last_obj_frame, first_state=1, last_state=1, ou
intfactor = int(factor)
if version < 1.1: # Version >= 1.1 has cone primitive
for i in range(100, 0, -1): # i=100 is tip of cone
print i
print(i)
t1 = seg * i
t2 = seg * (i + 1)
radius = arrow_head_radius * (1.0 - i / (100.0)) # Radius of each disc that forms cone
Expand All @@ -257,13 +258,13 @@ def modevectors(first_obj_frame, last_obj_frame, first_state=1, last_state=1, ou

if stat == "show":
natoms = skipcounter + keepcounter
print "\nTotal number of atoms = " + str(natoms)
print "Atoms skipped = " + str(skipcounter)
print("\nTotal number of atoms = " + str(natoms))
print("Atoms skipped = " + str(skipcounter))
if keepcounter - cutoff_counter > 0:
print "Atoms counted = " + str(keepcounter - cutoff_counter) + " (see PyMOL object \"" + objectname + "\")"
print("Atoms counted = " + str(keepcounter - cutoff_counter) + " (see PyMOL object \"" + objectname + "\")")
else:
print "Atoms counted = " + str(keepcounter - cutoff_counter) + " (Empty CGO object not loaded)"
print "Atoms cutoff = " + str(cutoff_counter) # Note that cutoff occurs AFTER skipping!
print("Atoms counted = " + str(keepcounter - cutoff_counter) + " (Empty CGO object not loaded)")
print("Atoms cutoff = " + str(cutoff_counter)) # Note that cutoff occurs AFTER skipping!
if keepcounter - cutoff_counter > 0:
cmd.delete(objectname)
cmd.load_cgo(arrow, objectname) # Ray tracing an empty object will cause a segmentation fault. No arrows = Do not display in PyMOL!!!
Expand Down
9 changes: 5 additions & 4 deletions movie_color_fade.py
Expand Up @@ -16,6 +16,7 @@
'''
#-------------------------------------------------------------------------------
# IMPORT
from __future__ import print_function
from pymol import cmd
from pymol import stored
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -72,7 +73,7 @@ def movie_color_fade(
movie_color_fade auto,white,auto,skyblue,ss s
movie_color_fade auto,white,auto,red,ss h
movie_color_fade auto,white,auto,grey,ss l+""
#####
#####
SEE ALSO
Expand All @@ -93,7 +94,7 @@ def movie_color_fade(
endframe = 1

if startframe == endframe:
print "start == end"
print("start == end")
return False

if startframe > endframe:
Expand All @@ -106,14 +107,14 @@ def movie_color_fade(
endcolor = cmd.get_color_tuple(endcolor)
diffcolor = [b - a for a, b in zip(startcolor, endcolor)]
except:
print "Input error - please provide regular colors"
print("Input error - please provide regular colors")
return False

for frame in range(startframe, endframe + 1):
# calculate intermediates
frac = float(frame - startframe) / (endframe - startframe)
endcolor = [a * frac for a in diffcolor]
endcolor = map(sum, zip(startcolor, endcolor))
endcolor = list(map(sum, list(zip(startcolor, endcolor))))
colorname = selection + "_" + str(frame)
# define new color
cmd.set_color(colorname, endcolor)
Expand Down
13 changes: 7 additions & 6 deletions nmr_cnstr.py
Expand Up @@ -17,6 +17,7 @@
##############################################################################################################
'''

from __future__ import print_function

def upl(fname):

Expand All @@ -26,7 +27,7 @@ def upl(fname):
#
while upl != '':

print upl, i
print(upl, i)
cns = string.split(upl)
cmd.dist('upl' + str(i), 'i. ' + cns[0] + ' & n. ' + cns[2], 'i. ' + cns[3] + ' & n. ' + cns[5])
upl = f.readline()
Expand All @@ -44,21 +45,21 @@ def cns(fname):
f = open(fname, 'r')
i = 1
upl = f.readline()
print upl, i
print(upl, i)
while upl != '':
if upl == '\n':
upl = f.readline()
continue
cns = string.split(upl)
print cns, i
print(cns, i)
if cns[0] == 'assign':
print 'CNS'
print('CNS')
if cns[5] == 'HB*':
print 'CNS***'
print('CNS***')
cmd.dist('upl' + str(i), 'i. ' + cns[2] + ' & n. ' + cns[5], 'i. ' + cns[7] + ' & n. ' + cns[10])
i += 1
upl = f.readline()
print '*' + upl + '*', i
print('*' + upl + '*', i)

f.close()
cmd.set('dash_gap', 0.05)
Expand Down

0 comments on commit dbd3b1a

Please sign in to comment.