Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python 3 support #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
from build_utils import compile_a_file_collection, Link
import optparse
import collections
Expand Down Expand Up @@ -223,7 +224,7 @@ def availableCalculators():
produced_file = open(".products","r")
for produced_file_line in produced_file:
os.system("rm "+produced_file_line)
print "rm "+produced_file_line[:-1]
print("rm "+produced_file_line[:-1])
produced_file.close()
# Clear the products file itself
os.system("rm .products")
Expand Down
4 changes: 2 additions & 2 deletions build_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ def compile_a_file_collection(base_dir, file_collection, compiler, options, incl
modif_data = os.path.getmtime(file_name)
# Then open the dic with last mod. dates
if os.path.exists(modif_file):
last_modif_data = pickle.load(open(modif_file,"r"))
last_modif_data = pickle.load(open(modif_file,"rb"))
else:
last_modif_data = -1 # If it does not exist, compile
# Finally, do last = current for the next step
pickle.dump(modif_data, open(modif_file,"w"))
pickle.dump(modif_data, open(modif_file,"wb"))

filewoext,extension = file_name.split(".") #@UnusedVariable
product = os.path.join(folder,filewoext)+product_extension
Expand Down
5 changes: 3 additions & 2 deletions pyRMSD/RMSDCalculator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import numpy
import pyRMSD.calculators
from pyRMSD.availableCalculators import availableCalculators
Expand Down Expand Up @@ -46,7 +47,7 @@ def __init__(self, calculatorType,
@date: 26/11/2012
"""
if not calculatorType in availableCalculators():
print "Calculator ", calculatorType, " is not an available calculator."
print("Calculator ", calculatorType, " is not an available calculator.")
raise ValueError
else:
self.fitting_coordinates = fittingCoordsets
Expand All @@ -58,7 +59,7 @@ def __init__(self, calculatorType,
if self.calculation_coordinates is not None:
self.calculation_coordinates = calculationCoordsets
if self.number_of_conformations != self.calculation_coordinates.shape[0]:
print "Calculation coordinates must hold the same number of conformations than fitting coordinates."
print("Calculation coordinates must hold the same number of conformations than fitting coordinates.")
raise ValueError
self.number_of_calculation_atoms = self.calculation_coordinates.shape[1]
else:
Expand Down
19 changes: 10 additions & 9 deletions pyRMSD/benchmark/BenchmarkCheckBetterOMPAndCUDAParams.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@author: victor
"""
from __future__ import print_function
import pyRMSD.RMSDCalculator
import time
import os
Expand All @@ -13,26 +14,26 @@
using_cuda = "QCP_CUDA_CALCULATOR" in pyRMSD.RMSDCalculator.availableCalculators()

if not using_cuda:
print "Build it using --cuda."
print("Build it using --cuda.")
exit()

######################
# BENCHMARKING
######################
# Reading coords
print "Loading file..."
print("Loading file...")
t1 = time.time()
print "\tUncompressing..."
print("\tUncompressing...")
open("tmp_amber_long.pdb","w").write(bz2.BZ2File("data/amber_long.pdb.tar.bz2").read())
print "\tLoading..."
print("\tLoading...")
reader = Reader().readThisFile('tmp_amber_long.pdb').gettingOnlyCAs()
coordsets = reader.read()
number_of_atoms = reader.numberOfAtoms
number_of_conformations = reader.numberOfFrames
os.system("rm tmp_amber_long.pdb")
print "\tDeleting temporary file"
print("\tDeleting temporary file")
t2 = time.time()
print 'Loading took %0.3f s' % (t2-t1)
print('Loading took %0.3f s' % (t2-t1))

for number_of_threads in range(1,13):
calculator = pyRMSD.RMSDCalculator.RMSDCalculator(calculatorType="QCP_OMP_CALCULATOR",
Expand All @@ -42,7 +43,7 @@
rmsd = calculator.pairwiseRMSDMatrix()
t2 = time.time()
del rmsd
print 'OpenMP calculation took %0.3fs with number of threads %d' % (t2-t1, number_of_threads)
print('OpenMP calculation took %0.3fs with number of threads %d' % (t2-t1, number_of_threads))

# Generate test parameters
max_n_threads = 512
Expand All @@ -68,7 +69,7 @@
rmsd = calculator.pairwiseRMSDMatrix()
t2 = time.time()
del rmsd
print 'Calculating took %0.3fs with CUDA and numthreads:%d and numblocks:%d' % (t2-t1, number_of_threads, number_of_blocks)
print('Calculating took %0.3fs with CUDA and numthreads:%d and numblocks:%d' % (t2-t1, number_of_threads, number_of_blocks))

#Best in Minotauro (NVIDIA M2090): 128, 64
#Best with Quadro FX 580: 2, 16
#Best with Quadro FX 580: 2, 16
19 changes: 10 additions & 9 deletions pyRMSD/benchmark/BenchmarkCondensedMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@author: victor
"""
from __future__ import print_function
import time
import random
from pyRMSD.condensedMatrix import CondensedMatrix
Expand All @@ -11,7 +12,7 @@

if __name__ == '__main__':

print "Creating data..."
print("Creating data...")
row_size = 10000
matrix_elem_size = row_size*(row_size-1)/2
contents = random.sample(xrange(matrix_elem_size+1),matrix_elem_size)
Expand All @@ -21,9 +22,9 @@
matrixes["CythonCondensedMatrix"] = CythonCondensedMatrixes.CythonCondensedMatrix(contents)
matrixes["CythonCondensedMatrixWithDiagonal"] = CythonCondensedMatrixes.CythonCondensedMatrixWithDiagonal(contents)

print "========================"
print "Serial access Benchmark"
print "========================"
print("========================")
print("Serial access Benchmark")
print("========================")

for matrix_type in matrixes:
irange = range(row_size)
Expand All @@ -34,11 +35,11 @@
for j in jrange:
data = matrixes[matrix_type][i,j]
time_end = time.time()
print matrix_type+" access benchmark took %.3f s"%(time_end-time_start)
print(matrix_type+" access benchmark took %.3f s"%(time_end-time_start))

print "========================"
print "Random Access Benchmark"
print "========================"
print("========================")
print("Random Access Benchmark")
print("========================")
random_i = range(row_size)
random.shuffle(random_i)
random_j = range(row_size)
Expand All @@ -50,4 +51,4 @@
for j in random_j:
data = matrixes[matrix_type][i,j]
time_end = time.time()
print "Random access benchmark took %.3f s for %s"%(time_end-time_start, matrix_type)
print("Random access benchmark took %.3f s for %s"%(time_end-time_start, matrix_type))
11 changes: 6 additions & 5 deletions pyRMSD/benchmark/BenchmarkCuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@author: victor
"""
from __future__ import print_function
import pyRMSD.RMSDCalculator
import time
import numpy
Expand All @@ -14,15 +15,15 @@
using_cuda = "QCP_CUDA_CALCULATOR" in pyRMSD.RMSDCalculator.availableCalculators()

if not using_cuda:
print "Build it using --cuda."
print("Build it using --cuda.")
exit()

files = ["amber_5k.pdb","amber_10k.pdb","amber_15k.pdb","amber_20k.pdb","amber_25k.pdb","amber_30k.pdb","amber_35k.pdb"]
for pdb_file in files:
print "Reading file data/"+pdb_file,"...",
print("Reading file data/"+pdb_file,"...", end=' ')
sys.stdout.flush()
coordsets = numpy.load("data/%s.npy"%pdb_file.split(".")[0])
print "OK"
print("OK")
number_of_conformations = coordsets.shape[0]
number_of_atoms = coordsets.shape[1]

Expand All @@ -38,8 +39,8 @@
t2 = time.time()
del rmsd
times.append(t2-t1)
print t2-t1
print(t2-t1)
sys.stdout.flush()
print "With CUDA and ",pdb_file, " it took: ",numpy.mean(times),"[", numpy.std(times), "]"
print("With CUDA and ",pdb_file, " it took: ",numpy.mean(times),"[", numpy.std(times), "]")
sys.stdout.flush()

51 changes: 26 additions & 25 deletions pyRMSD/benchmark/BenchmarkNeighborOperations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@author: victor
"""
from __future__ import print_function
import time
import random
import numpy
Expand All @@ -13,7 +14,7 @@

if __name__ == '__main__':

print "Creating data..."
print("Creating data...")
row_size = 20000
matrix_elem_size = row_size*(row_size-1)/2
contents = numpy.array(random.sample(xrange(matrix_elem_size+1),matrix_elem_size))
Expand All @@ -23,57 +24,57 @@
matrix2 = PythonCondensedMatrix.CondensedMatrix(float_contents)
remaining_nodes = range(row_size)

print "======================================"
print "'get_neighbors_for_node' benchmark"
print "======================================"
print("======================================")
print("'get_neighbors_for_node' benchmark")
print("======================================")
time_start = time.time()
neighbors1 = matrix.get_neighbors_for_node(1,remaining_nodes, 0.5)
time_end = time.time()
print "Fast Neighbor search for Fast matrix took %.3fs"%(time_end-time_start)
print("Fast Neighbor search for Fast matrix took %.3fs"%(time_end-time_start))

time_start = time.time()
neighbors2 = matrix2.get_neighbors_for_node(1,remaining_nodes, 0.5)
time_end = time.time()
print "Slow Neighbor search for Slow matrix took %.3fs"%(time_end-time_start)
print("Slow Neighbor search for Slow matrix took %.3fs"%(time_end-time_start))

time_start = time.time()
neighbors3 = get_neighbors_for_node(matrix, 1,remaining_nodes, 0.5)
time_end = time.time()
print "Slow Neighbor search for Fast matrix took %.3fs"%(time_end-time_start)
print("Slow Neighbor search for Fast matrix took %.3fs"%(time_end-time_start))

print "======================================"
print "'get_neighbors_for_node' validation"
print "======================================"
print("======================================")
print("'get_neighbors_for_node' validation")
print("======================================")
try:
numpy.testing.assert_array_equal(neighbors1,neighbors2)
numpy.testing.assert_array_equal(neighbors1,neighbors3)
print "OK"
except Exception,message:
print message
print "KO"
print("OK")
except Exception as message:
print(message)
print("KO")

print "================================================"
print "'choose_node_with_higher_cardinality' benchmark"
print "================================================"
print("================================================")
print("'choose_node_with_higher_cardinality' benchmark")
print("================================================")
time_start = time.time()
neighbors1 = matrix.choose_node_with_higher_cardinality(remaining_nodes, 0.5)
time_end = time.time()
print "Fast Neighbor cardinality for Fast matrix took %.3fs"%(time_end-time_start)
print("Fast Neighbor cardinality for Fast matrix took %.3fs"%(time_end-time_start))

time_start = time.time()
neighbors2 = matrix2.choose_node_with_higher_cardinality(remaining_nodes, 0.5)
time_end = time.time()
print "Slow Neighbor cardinality for Slow matrix took %.3fs"%(time_end-time_start)
print("Slow Neighbor cardinality for Slow matrix took %.3fs"%(time_end-time_start))

time_start = time.time()
neighbors3 = choose_node_with_higher_cardinality(matrix,remaining_nodes, 0.5)
time_end = time.time()
print "Slow Neighbor cardinality for Fast matrix took %.3fs"%(time_end-time_start)
print("Slow Neighbor cardinality for Fast matrix took %.3fs"%(time_end-time_start))

print "================================================"
print "'choose_node_with_higher_cardinality' validation"
print "================================================"
print("================================================")
print("'choose_node_with_higher_cardinality' validation")
print("================================================")
if(neighbors1 == neighbors2 and neighbors2 == neighbors3):
print "OK"
print("OK")
else:
print "KO"
print("KO")
7 changes: 4 additions & 3 deletions pyRMSD/benchmark/BenchmarkOpenMP.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@author: victor
"""
from __future__ import print_function
import pyRMSD.RMSDCalculator
import time
import numpy
Expand All @@ -21,10 +22,10 @@
]

for pdb_file, tries in files:
print "Reading file ", "data/"+pdb_file,"...",
print("Reading file ", "data/"+pdb_file,"...", end=' ')
sys.stdout.flush()
coordsets = numpy.load("data/%s.npy"%(pdb_file.split(".")[0]))
print "OK"
print("OK")
number_of_conformations = coordsets.shape[0]
number_of_atoms = coordsets.shape[1]

Expand All @@ -38,6 +39,6 @@
t2 = time.time()
del rmsd
times.append(t2-t1)
print "With OpenMP and",pdb_file, " it took: ",numpy.mean(times),"[", numpy.std(times), "]"
print("With OpenMP and",pdb_file, " it took: ",numpy.mean(times),"[", numpy.std(times), "]")
sys.stdout.flush()

5 changes: 3 additions & 2 deletions pyRMSD/benchmark/BenchmarkOpenMPScalability.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@author: victor
"""
from __future__ import print_function
import pyRMSD.RMSDCalculator
import time
import numpy
Expand All @@ -13,7 +14,7 @@
coordsets = numpy.load("data/amber_30k.npy")
number_of_conformations = coordsets.shape[0]
number_of_atoms = coordsets.shape[1]
print "Coordsets read"
print("Coordsets read")
sys.stdout.flush()
calculator_types = ["KABSCH_OMP_CALCULATOR","QTRFIT_OMP_CALCULATOR","QCP_OMP_CALCULATOR"]
for calculator_type in calculator_types:
Expand All @@ -28,6 +29,6 @@
t2 = time.time()
del rmsd
times.append(t2-t1)
print calculator_type, num_threads, numpy.mean(times),"[", numpy.std(times), "]"
print(calculator_type, num_threads, numpy.mean(times),"[", numpy.std(times), "]")
sys.stdout.flush()

5 changes: 3 additions & 2 deletions pyRMSD/benchmark/BenchmarkPrecision.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@author: victor
"""

from __future__ import print_function
import pyRMSD.RMSDCalculator
import numpy
import math
Expand Down Expand Up @@ -38,10 +39,10 @@
rms = {}
calculator_names = rmsds.keys()
for calculator_name_i in calculator_names:
print "* ",calculator_name_i
print("* ",calculator_name_i)
rms[calculator_name_i] = {}
for calculator_name_j in calculator_names:
print "\t ",calculator_name_j
print("\t ",calculator_name_j)
rmsd_diff = rmsds[calculator_name_i] - rmsds[calculator_name_j]
rms[calculator_name_i][calculator_name_j] = math.sqrt(numpy.sum(rmsd_diff**2))
#---------------#
Expand Down
Loading