diff --git a/README.md b/README.md index cff4807..f02c354 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,6 @@ pdbTools is a set of command line [python](http://www.python.org) scripts that m Most of the scripts will run "out of the box" using a python interpreter. The command line parser is designed to be flexible. It will take an arbitrarily long list of pdb files, pdb ids, text files with pdb ids, or some mixture of all three. If the pdb file or id is not in the working directory, scripts will attempt to download the pdb file from [RCSB](http://www.rcsb.org/). Depending on the type of operation being done, a program will either write output files in the working directory or will print to stdout. All structure outputs are written in standard pdb format. All data outputs are in fixed-width column format. They were designed to be read by the statistics package [R](http://cran.r-project.org/); however, they should be easily parsed by other graphing programs. -*Note:* These scripts are only compatible with Python version 2.4-2.7. - ## Installation Install the development version by cloning this repo and running `pip`: diff --git a/pdbtools/addH.py b/pdbtools/addH.py index 2ea6a62..266e98b 100755 --- a/pdbtools/addH.py +++ b/pdbtools/addH.py @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from builtins import range __description__ = "Adds polar hydrogens to a pdb file for a UHBD calculation." __author__ = "Michael J. Harms" __date__ = "070727" @@ -69,8 +70,8 @@ def convertResidues(pdb,atom_conv={},resid_conv={},atom_skip=[],resid_skip=[]): states and give every group a charge. """ - atom_to_convert = atom_conv.keys() - res_to_convert = resid_conv.keys() + atom_to_convert = list(atom_conv.keys()) + res_to_convert = list(resid_conv.keys()) new_pdb = [] for line in pdb: @@ -181,7 +182,7 @@ def flipAtoms(pdb): flip = {"ASP":("OD1","OD2"), "GLU":("OE1","OE2")} - flip_keys = flip.keys() + flip_keys = list(flip.keys()) for index, line in enumerate(pdb): res = line[17:30] diff --git a/pdbtools/bfactor.py b/pdbtools/bfactor.py index 6e76f26..195e911 100755 --- a/pdbtools/bfactor.py +++ b/pdbtools/bfactor.py @@ -63,7 +63,7 @@ def pdbBfactor(pdb,data_dict): for line in pdb: if line[0:6] == "ATOM ": resnum = line[23:26].strip() - if resnum in data_dict.keys(): + if resnum in list(data_dict.keys()): out.append("%s%6.2F%s" % (line[:60],data_dict[resnum], line[66:])) else: diff --git a/pdbtools/centerasu.py b/pdbtools/centerasu.py index b2bd8bc..fd96ca7 100755 --- a/pdbtools/centerasu.py +++ b/pdbtools/centerasu.py @@ -5,6 +5,9 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function +from builtins import map +from builtins import range __description__ = \ """ pdb_centerasu.py @@ -20,8 +23,8 @@ try: from numpy import array, linalg, dot, mean, squeeze except ImportError: - print "numpy package is required for this program!" - print "(http://numpy.scipy.org/)" + print("numpy package is required for this program!") + print("(http://numpy.scipy.org/)") sys.exit() class PdbCenterAsuError(Exception): @@ -46,7 +49,7 @@ def pdbCenterasu(pdb, write_coord =False): fmx = [] for line in pdb: if line.startswith('SCALE'): - data = map(float, line[6:].split()[:-1]) + data = list(map(float, line[6:].split()[:-1])) fmx.append(data) if len(fmx) == 0: diff --git a/pdbtools/centermass.py b/pdbtools/centermass.py index c4c9659..c6dc8a7 100755 --- a/pdbtools/centermass.py +++ b/pdbtools/centermass.py @@ -4,6 +4,11 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import division +from __future__ import print_function +from __future__ import absolute_import +from builtins import range +from past.utils import old_div __description__ = \ """ pdb_centermass.py @@ -17,7 +22,7 @@ __date__ = "061109" import sys, re -from data import common +from .data import common def pdbCentermass(pdb,write_coord=False,include_hetatm=False,include_mass=True): """ @@ -73,15 +78,15 @@ def pdbCentermass(pdb,write_coord=False,include_hetatm=False,include_mass=True): try: masses.append(common.ATOM_WEIGHTS[atom_type]) except: - print "File contains atoms of unknown type (%s)" % atom_type - print "Will assign them mass of carbon (12.011 g/mol)" - print "To fix, edit ATOM_WEIGHTS dictionary in pdb_data/common.py" + print("File contains atoms of unknown type (%s)" % atom_type) + print("Will assign them mass of carbon (12.011 g/mol)") + print("To fix, edit ATOM_WEIGHTS dictionary in pdb_data/common.py") masses.append(12.011) num_atoms = len(coord) total_mass = sum(masses) - weights = [m/total_mass for m in masses] + weights = [old_div(m,total_mass) for m in masses] center = [sum([coord[i][j]*weights[i] for i in range(num_atoms)]) for j in range(3)] @@ -100,7 +105,7 @@ def pdbCentermass(pdb,write_coord=False,include_hetatm=False,include_mass=True): center_out = ["%10.4F" % c for c in center] if warn: - print "Warning. No element entries in file. Attempting to extract" - print "from the atom names. Not always reliable..." + print("Warning. No element entries in file. Attempting to extract") + print("from the atom names. Not always reliable...") return center_out, out diff --git a/pdbtools/charmm/interface.py b/pdbtools/charmm/interface.py index ed05f21..b677f8a 100644 --- a/pdbtools/charmm/interface.py +++ b/pdbtools/charmm/interface.py @@ -1,3 +1,5 @@ +from __future__ import print_function +from __future__ import absolute_import # Copyright 2007, Michael J. Harms # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. @@ -13,7 +15,7 @@ __date__ = "080418" import math, os -import gen_input +from . import gen_input # Set up charmm binary try: @@ -66,7 +68,7 @@ def runCharmm(input): err = "charmm binary \"%s\" does not exist!" % charmm_bin raise CharmmInterfaceError(err) - print "Running: %s" % (charmm_bin) + print("Running: %s" % (charmm_bin)) cin, cout = os.popen2(charmm_bin) cin.write(input) @@ -90,7 +92,7 @@ def charmm2pdb(charmm_output): # Rename oddball residues rename_dict = {"OCT1":" O ","OCT2":" OXT"} - rename_lines = [l for l in pdb if l[12:16] in rename_dict.keys()] + rename_lines = [l for l in pdb if l[12:16] in list(rename_dict.keys())] for line in rename_lines: index = pdb.index(line) new_atom = rename_dict[line[12:16]] diff --git a/pdbtools/clean.py b/pdbtools/clean.py index b3e1485..6748ee0 100755 --- a/pdbtools/clean.py +++ b/pdbtools/clean.py @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_clean.py @@ -56,7 +57,7 @@ def convertModifiedAA(coord,header): backbone_atoms = ["N ","CA ","C ","O "] new_coord = [] for line in coord: - if line[17:20] in mod_dict.keys(): + if line[17:20] in list(mod_dict.keys()): new = mod_dict[line[17:20]] if line[13:16] in backbone_atoms: new_line = "ATOM %s%s%s" % (line[6:17],new,line[20:]) @@ -72,7 +73,7 @@ def convertModifiedAA(coord,header): old_seq = line[19:70].split() new_seq = [] for aa in old_seq: - if aa in mod_dict.keys(): + if aa in list(mod_dict.keys()): new_seq.append(mod_dict[aa]) else: new_seq.append(aa) @@ -87,7 +88,7 @@ def convertModifiedAA(coord,header): # Create output remarks conv = ["REMARK converted %s to %s\n" % (k,mod_dict[k]) - for k in mod_dict.keys()] + for k in list(mod_dict.keys())] return new_coord, new_header, conv @@ -120,7 +121,7 @@ def removeLetters(line): # If the residue is not known, update known_atom_dict and append line # to coordinate file - if residue not in known_atom_dict.keys(): + if residue not in list(known_atom_dict.keys()): out = removeLetters(c) coord_out.append(out) known_atom_dict.update([(residue,[c[13:16]])]) @@ -197,7 +198,8 @@ def addMissingAtoms(coord,seqres,keep_temp=False,renumber_residues=False, try: new_coord = charmm.interface.charmmWash(structure_list, keep_temp=keep_temp,fix_atoms=fix_atoms,num_steps=num_steps) - except charmm.interface.CharmmInterfaceError, (strerror): + except charmm.interface.CharmmInterfaceError as xxx_todo_changeme: + (strerror) = xxx_todo_changeme err = "CharmmInterfaceError\n%s\n" % strerror raise PdbCleanError(err) @@ -265,7 +267,7 @@ def pdbClean(pdb,pdb_id="temp",chains="all",renumber_residues=False, coord, header, converted = convertModifiedAA(coord,header) if len(converted) != 0: log.append(log_fmt % "Modified amino acids converted.") - print log[-1], + print(log[-1], end=' ') log.extend(converted) if pdbCheck(coord): err = "Modified amino acid converter removed all atoms! Mangled pdb!" @@ -278,13 +280,13 @@ def pdbClean(pdb,pdb_id="temp",chains="all",renumber_residues=False, raise PdbCleanError(err) else: log.append(log_fmt % "HETATM entries removed.") - print log[-1], + print(log[-1], end=' ') # Grab only the chain we want, if specified if chains != "all": coord = [l for l in coord if l[21] in chains] log.append(log_fmt % ("Took only chain %r." % chains)) - print log[-1], + print(log[-1], end=' ') if pdbCheck(coord): err = "Chain filter (%r) removed all atoms in pdb file!" % chains raise PdbCleanError(err) @@ -293,7 +295,7 @@ def pdbClean(pdb,pdb_id="temp",chains="all",renumber_residues=False, coord, skipped = stripACS(coord) if len(skipped) != 0: log.append(log_fmt % "Alternate conformations were removed.") - print log[-1], + print(log[-1], end=' ') log.extend(skipped) if pdbCheck(coord): err = "ACS stripper removed all atoms! Mangled pdb file." @@ -303,14 +305,14 @@ def pdbClean(pdb,pdb_id="temp",chains="all",renumber_residues=False, coord, removed = backboneCheck(coord) if len(removed) != 0: log.append(log_fmt % "Residues with missing backbone atoms removed.") - print log[-1], + print(log[-1], end=' ') log.extend(removed) if pdbCheck(coord): err = "Backbone checker removed all atoms! Mangled pdb file." raise PdbCleanError(err) # Add missing atoms using CHARMM - print log_fmt % "Adding heavy atoms using CHARMM.", + print(log_fmt % "Adding heavy atoms using CHARMM.", end=' ') seqres = [l for l in header if l[0:6] == "SEQRES"] coord = addMissingAtoms(coord,seqres,keep_temp,renumber_residues,pdb_id, fix_atoms,num_steps) @@ -319,17 +321,17 @@ def pdbClean(pdb,pdb_id="temp",chains="all",renumber_residues=False, # Renumber residues if requested if renumber_residues: log.append(log_fmt % "Residues renumbered from one.") - print log[-1], + print(log[-1], end=' ') # Renumber atoms from 1 coord = pdb_atom_renumber.pdbAtomRenumber(coord) log.append(log_fmt % "Renumbered atoms from 1") - print log[-1], + print(log[-1], end=' ') # Standardize atom-type on far right pdb column coord = ["%s %s \n" % (c[:66],c[13]) for c in coord] log.append(log_fmt % "Atom types were standardized.") - print log[-1], + print(log[-1], end=' ') # Final check if pdbCheck(coord): diff --git a/pdbtools/closecontacts.py b/pdbtools/closecontacts.py index 653a973..cea215c 100755 --- a/pdbtools/closecontacts.py +++ b/pdbtools/closecontacts.py @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from builtins import range __description__ = \ """ pdb_close-contacts.py diff --git a/pdbtools/contact.py b/pdbtools/contact.py index ddb355f..9cb5552 100755 --- a/pdbtools/contact.py +++ b/pdbtools/contact.py @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from builtins import range __description__ = \ """ pdb_contacting-residues.py @@ -42,7 +43,7 @@ def pdbContacting(pdb,target,cutoff,target_type="resname"): contacts.append(a[0][5:].strip()) # Grab only unique contacts - contacts = dict([(c,()) for c in contacts]).keys() + contacts = list(dict([(c,()) for c in contacts]).keys()) out.append("%s\t%s\n" % (t[0],("\t".join(contacts)))) return out diff --git a/pdbtools/contactplot.py b/pdbtools/contactplot.py index 15bf5c8..21556fa 100755 --- a/pdbtools/contactplot.py +++ b/pdbtools/contactplot.py @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from builtins import range __description__ = \ """ pdb_contact.py diff --git a/pdbtools/coulomb.py b/pdbtools/coulomb.py index 8b1cc64..4713e70 100755 --- a/pdbtools/coulomb.py +++ b/pdbtools/coulomb.py @@ -4,6 +4,9 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import division +from builtins import range +from past.utils import old_div __description__ = \ """ pdb_coulomb.py @@ -33,7 +36,7 @@ def readPDB(pdb_file): # Grab only ATOM entries that are titratable pdb = [l for l in pdb if l[0:4] == "ATOM" and - l[17:20] in TITR_ATOM.keys() and + l[17:20] in list(TITR_ATOM.keys()) and l[13:16] == TITR_ATOM[l[17:20]]] # Initalize lists to hold coordinates, pkas, and charge @@ -60,7 +63,7 @@ def hendersonHasselbach(pKa,charge,pH): pH value. """ - return charge/(1 + 10**(charge*(pH-pKa))) + return old_div(charge,(1 + 10**(charge*(pH-pKa)))) def pdbCoulomb(coord,pKa,charge,dielec_const,ionic_str,pH,temperature): @@ -70,10 +73,10 @@ def pdbCoulomb(coord,pKa,charge,dielec_const,ionic_str,pH,temperature): ionic strength. """ - ionic_str = ionic_str/1000 + ionic_str = old_div(ionic_str,1000) # Initialize variables - kappa = 50.29*sqrt(ionic_str/(dielec_const*temperature)) + kappa = 50.29*sqrt(old_div(ionic_str,(dielec_const*temperature))) num_groups = len(coord) energy = 0. diff --git a/pdbtools/data/polar.py b/pdbtools/data/polar.py index 7197bf0..390a3e0 100644 --- a/pdbtools/data/polar.py +++ b/pdbtools/data/polar.py @@ -34,7 +34,7 @@ def _readParam(param_file): # Fill charge and radii dictionaries keyed to aa, then atom type charge = dict([(x[0],[]) for x in param]) radii = dict([(x[0],[]) for x in param]) - for k in charge.keys(): + for k in list(charge.keys()): charge[k] = dict([(x[1],x[2]) for x in param if x[0] == k]) radii[k] = dict([(x[1],x[3]) for x in param if x[0] == k]) diff --git a/pdbtools/dist_filter.py b/pdbtools/dist_filter.py index 81e26c0..8831c88 100755 --- a/pdbtools/dist_filter.py +++ b/pdbtools/dist_filter.py @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from builtins import range __author__ = "Michael J. Harms" __date__ = "070709" __description__ = \ diff --git a/pdbtools/disulfide.py b/pdbtools/disulfide.py index 078dc91..2fa8dcc 100755 --- a/pdbtools/disulfide.py +++ b/pdbtools/disulfide.py @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from builtins import range __description__ = \ """ pdb_disulfide.py diff --git a/pdbtools/download.py b/pdbtools/download.py index 0d66920..9e083d4 100755 --- a/pdbtools/download.py +++ b/pdbtools/download.py @@ -9,7 +9,9 @@ Download a pdb or set of pdb files and uncompress them. """ +from __future__ import print_function +from builtins import range __author__ = "Michael J. Harms" __date__ = "070521" __usage__ = "pdb_download.py pdb_id or file w/ list of ids" @@ -25,13 +27,9 @@ def unZip(some_file,some_output): """ Unzip some_file using the gzip library and write to some_output. """ - - f = gzip.open(some_file,'r') - g = open(some_output,'w') - g.writelines(f.readlines()) - f.close() - g.close() - + with gzip.open(some_file, 'r') as f: + with open(some_output, 'w') as g: + g.writelines(map(lambda x: x.decode(), f.readlines())) os.remove(some_file) def pdbDownload(file_list,hostname=HOSTNAME,directory=DIRECTORY,prefix=PREFIX, @@ -43,7 +41,7 @@ def pdbDownload(file_list,hostname=HOSTNAME,directory=DIRECTORY,prefix=PREFIX, success = True # Log into server - print "Connecting..." + print("Connecting...") ftp = ftplib.FTP() ftp.connect(hostname) ftp.login() @@ -63,10 +61,10 @@ def pdbDownload(file_list,hostname=HOSTNAME,directory=DIRECTORY,prefix=PREFIX, ftp.retrbinary("RETR %s" % to_get[i],open(to_write[i],"wb").write) final_name = "%s.pdb" % to_write[i][:to_write[i].index(".")] unZip(to_write[i],final_name) - print "%s retrieved successfully." % final_name + print("%s retrieved successfully." % final_name) except ftplib.error_perm: os.remove(to_write[i]) - print "ERROR! %s could not be retrieved!" % file_list[i] + print("ERROR! %s could not be retrieved!" % file_list[i]) success = False # Log out diff --git a/pdbtools/helper/cmdline.py b/pdbtools/helper/cmdline.py index f741dd7..8a5ef81 100644 --- a/pdbtools/helper/cmdline.py +++ b/pdbtools/helper/cmdline.py @@ -138,7 +138,7 @@ def parseCommandLine(): # Remove duplicates from file_list by placing in dictionary file_dict = dict([(f,"") for f in file_list]) - file_list = file_dict.keys() + file_list = list(file_dict.keys()) file_list.sort() return file_list, options diff --git a/pdbtools/helper/container.py b/pdbtools/helper/container.py index 2d5fdbb..19297b4 100644 --- a/pdbtools/helper/container.py +++ b/pdbtools/helper/container.py @@ -2,6 +2,8 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from builtins import range +from builtins import object __description__ = \ """ pdbObject.py @@ -27,7 +29,7 @@ class PdbContainerError(Exception): pass -class Fragment: +class Fragment(object): """ Holds a continuous fragment of amino acids and whether or not the fragment should have termini. @@ -65,7 +67,7 @@ def write(self,filename=None): else: return "".join(self.atom_lines) -class Chain: +class Chain(object): """ Hold a single molecule chain (as a set of fragments). """ @@ -218,7 +220,7 @@ def write(self,filename=None): return "".join(out) -class Structure: +class Structure(object): """ Class to hold a pdb file (broken into chains, then into fragments). """ diff --git a/pdbtools/helper/geometry.py b/pdbtools/helper/geometry.py index ffe3ac4..bc47c6f 100644 --- a/pdbtools/helper/geometry.py +++ b/pdbtools/helper/geometry.py @@ -1,7 +1,10 @@ +from __future__ import division # Copyright 2007, Michael J. Harms # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from builtins import range +from past.utils import old_div __description__ = \ """ geometry.py @@ -36,9 +39,9 @@ def calcDistances(coord): num_points = len(coord) d = [[0. for j in range(num_points)] for i in range(num_points)] - for i in xrange(num_points): + for i in range(num_points): d[i][i] = 0. - for j in xrange(i+1,num_points): + for j in range(i+1,num_points): d[i][j] = dist(coord[i],coord[j]) d[j][i] = d[i][j] @@ -72,7 +75,7 @@ def findAngle(u,v): mag_u = sqrt(u[0]**2 + u[1]**2 + u[2]**2) mag_v = sqrt(v[0]**2 + v[1]**2 + v[2]**2) - return 180/pi * acos(dotProduct(u,v)/(mag_u*mag_v)) + return 180/pi * acos(old_div(dotProduct(u,v),(mag_u*mag_v))) def genRotMatrix(axis,theta): """ @@ -82,9 +85,9 @@ def genRotMatrix(axis,theta): matrix = [[0. for j in range(3)] for i in range(3)] axis_length = sqrt((axis[0]**2 + axis[1]**2 + axis[2]**2)) - xNorm = axis[0]/axis_length - yNorm = axis[1]/axis_length - zNorm = axis[2]/axis_length + xNorm = old_div(axis[0],axis_length) + yNorm = old_div(axis[1],axis_length) + zNorm = old_div(axis[2],axis_length) sin_theta = sin(theta) cos_theta = cos(theta) @@ -136,7 +139,7 @@ def calcGlyCbeta(Ncoord,CAcoord,COcoord): CA_CO_vector.append(COcoord[i] - CAcoord[i]) CA_N_vector.append(Ncoord[i] - CAcoord[i]) - rotation_amount = 240*(pi/180.) + rotation_amount = 240*(old_div(pi,180.)) rotated = arbRot(CA_CO_vector, CA_N_vector, rotation_amount) @@ -163,7 +166,7 @@ def calcHXT(C_coord,O_coord,OXT_coord): HXT_coord = [0.,0.,0.] for i in range(3): - vector_3[i] = vector_3[i]/dv3 + vector_3[i] = old_div(vector_3[i],dv3) HXT_coord[i] = OXT_coord[i] + vector_3[i] return HXT_coord @@ -181,7 +184,7 @@ def calcHG(CB_coord,SG_coord): HG_coord = [0.,0.,0.] for i in range(3): - vector_1[i] = vector_1[i]/dv3 + vector_1[i] = old_div(vector_1[i],dv3) HG_coord[i] = SG_coord[i] + 1.08*vector_1[i] return HG_coord diff --git a/pdbtools/iondist.py b/pdbtools/iondist.py index 3dd29cb..ae62bf7 100755 --- a/pdbtools/iondist.py +++ b/pdbtools/iondist.py @@ -4,6 +4,9 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import division +from builtins import range +from past.utils import old_div __description__ = \ """ pdb_ion-dist.py @@ -30,11 +33,11 @@ def pdbIonDist(pdb,hist_step,remove_resid="TYR"): pdb = [l for l in pdb if l[0:4] == "ATOM"] titr_atom = [l for l in pdb if l[17:20] not in remove_resid and - l[17:20] in TITR_ATOM.keys() and + l[17:20] in list(TITR_ATOM.keys()) and l[13:16] == TITR_ATOM[l[17:20]]] # Extract coordinates and charges for each titratable atom - coord = [[float(l[30+8*i:38+8*i]) for i in xrange(3)] for l in titr_atom] + coord = [[float(l[30+8*i:38+8*i]) for i in range(3)] for l in titr_atom] charge = [CHARGE_DICT[l[17:20]] for l in titr_atom] # Calculate all ij distances @@ -45,18 +48,18 @@ def pdbIonDist(pdb,hist_step,remove_resid="TYR"): # counted. max_dist_bin = max([max([dist[i][j] for j in range(N)]) for i in range(N)]) - max_dist_bin = int(round(max_dist_bin/hist_step)) + 1 - histogram = [[0 for j in xrange(max_dist_bin)] for i in xrange(3)] + max_dist_bin = int(round(old_div(max_dist_bin,hist_step))) + 1 + histogram = [[0 for j in range(max_dist_bin)] for i in range(3)] # Populate histogram # Interaction types: # acid/acid --> 0 (-1 + -1)/2 + 1 # acid/base, base/acid --> 1 (-1 + 1)/2 + 1 # base/base --> 2 ( 1 + 1)/2 + 2 - for i in xrange(N): - for j in xrange(i+1,N): - interaction_type = int((charge[i] + charge[j])/2 + 1) - dist_bin = int(round(dist[i][j]/hist_step)) + for i in range(N): + for j in range(i+1,N): + interaction_type = int(old_div((charge[i] + charge[j]),2) + 1) + dist_bin = int(round(old_div(dist[i][j],hist_step))) histogram[interaction_type][dist_bin] += 1 return histogram diff --git a/pdbtools/ligand.py b/pdbtools/ligand.py index 0d1755d..1c06f98 100755 --- a/pdbtools/ligand.py +++ b/pdbtools/ligand.py @@ -22,6 +22,6 @@ def pdbLigand(pdb,skip_boring=False): """ ligands = [l[7:10].strip() for l in pdb if l.startswith("HET ")] - ligands = dict([(l,[]) for l in ligands if l not in BORING_LIGANDS]).keys() + ligands = list(dict([(l,[]) for l in ligands if l not in BORING_LIGANDS]).keys()) return ";".join(ligands) diff --git a/pdbtools/moment.py b/pdbtools/moment.py index fc136de..f2e3bfa 100755 --- a/pdbtools/moment.py +++ b/pdbtools/moment.py @@ -4,6 +4,9 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import division +from builtins import range +from past.utils import old_div __description__ = \ """ pdb_moment.py @@ -72,7 +75,7 @@ def pdbMoment(pdb): num_atoms = len(charges) # Center coordinates on center of mass - center = [sum([c[i] for c in coord])/num_atoms for i in range(3)] + center = [old_div(sum([c[i] for c in coord]),num_atoms) for i in range(3)] coord = [[c[i] - center[i] for i in range(3)] for c in coord] return calcMoment(charges,coord) diff --git a/pdbtools/mutator.py b/pdbtools/mutator.py index 9ee71fe..7504e40 100755 --- a/pdbtools/mutator.py +++ b/pdbtools/mutator.py @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_mutator.py @@ -16,8 +17,8 @@ __description__ = "Mutates a residue in a pdb file" import sys, time, string, os -import .atom_renumber -import .clean +from . import atom_renumber +from . import clean from .helper import container from .data.common import * @@ -89,7 +90,7 @@ def pdbMutator(pdb,residue,mutation,chain=None,run_charmm=True): # Add missing atoms using CHARMM if run_charmm: - print log_fmt % "Adding mutated side chain using CHARMM", + print(log_fmt % "Adding mutated side chain using CHARMM", end=' ') seqres = [l for l in header if l[0:6] == "SEQRES"] coord = pdb_clean.addMissingAtoms(coord,seqres) log.append(log_fmt % "Mutated sidechain built with CHARMM") @@ -97,12 +98,12 @@ def pdbMutator(pdb,residue,mutation,chain=None,run_charmm=True): # Renumber atoms from 1 coord = pdb_atom_renumber.pdbAtomRenumber(coord) log.append(log_fmt % "Renumbered atoms from 1") - print log[-1], + print(log[-1], end=' ') # Standardize atom-type on far right pdb column coord = ["%s %s \n" % (c[:66],c[13]) for c in coord] log.append(log_fmt % "Atom types were standardized.") - print log[-1], + print(log[-1], end=' ') # Final check if pdb_clean.pdbCheck(coord): diff --git a/pdbtools/neighbors.py b/pdbtools/neighbors.py index e2c92b4..ad7f227 100755 --- a/pdbtools/neighbors.py +++ b/pdbtools/neighbors.py @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from builtins import range __description__ =\ """ pdb_neighbors.py diff --git a/pdbtools/oligomer.py b/pdbtools/oligomer.py index 7e54dfd..12c25d2 100755 --- a/pdbtools/oligomer.py +++ b/pdbtools/oligomer.py @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from builtins import range __description__ = \ """ pdb_oligomer.py @@ -109,10 +110,10 @@ def findAllChains(pdb): # grab chains from HETATM entries (if they were not listed in the COMPND # section) - known_chains = chain_dict.keys() + known_chains = list(chain_dict.keys()) hetatm = [l for l in pdb if l[0:6] == "HETATM"] hetatm_chains = dict([(l[21],l[17:20]) for l in hetatm]) - for k in hetatm_chains.keys(): + for k in list(hetatm_chains.keys()): if k not in known_chains: chain_dict[k] = hetatm_chains[k] @@ -138,7 +139,7 @@ def pdbOligomer(pdb,collapse_repeat=True): # the system as non wysiwg, but will allow chains, etc. to be parsed for # output if biomat == (): - keys = chain_dict.keys() + keys = list(chain_dict.keys()) keys.sort() biomat = [[keys,(False,False)]] diff --git a/pdbtools/param.py b/pdbtools/param.py index 9ae8e7a..586e486 100755 --- a/pdbtools/param.py +++ b/pdbtools/param.py @@ -22,7 +22,7 @@ import os, sys -import .seq +from . import seq from .data.common import * class PdbParamError(Exception): @@ -37,7 +37,7 @@ def calcChargeState(count_dict,pH): """ charge_state = 0. - for aa in count_dict.keys(): + for aa in list(count_dict.keys()): pKa = PKA_DICT[aa] charge = CHARGE_DICT[aa] charge_state += count_dict[aa]*charge/(1 + 10**(charge*(pH-pKa))) @@ -51,8 +51,8 @@ def pdbPi(aa_list,initial_pH_step=2.0,cutoff=0.001): """ # Count the number of titratable amino acids in a sequence - count_dict = dict([(k,0) for k in PKA_DICT.keys()]) - for k in count_dict.keys(): + count_dict = dict([(k,0) for k in list(PKA_DICT.keys())]) + for k in list(count_dict.keys()): count_dict[k] = len([aa for aa in aa_list if aa == k]) count_dict["NTERM"] = 1 count_dict["CTERM"] = 1 @@ -107,18 +107,18 @@ def pdbParam(pdb,chain="all",use_atoms=False): # Convert chain dictionary to list of amino acids if chain == "all": aa_list = [] - for c in chain_dict.keys(): + for c in list(chain_dict.keys()): aa_list.extend(chain_dict[c]) else: - if chain in chain_dict.keys(): + if chain in list(chain_dict.keys()): aa_list = chain_dict[chain] else: err = "Chain \"%s\" is not in pdb file!" % chain raise PdbParamError(err) # Count number of each type of group - count_dict = dict([(k,0) for k in MW_DICT.keys()]) - for k in count_dict.keys(): + count_dict = dict([(k,0) for k in list(MW_DICT.keys())]) + for k in list(count_dict.keys()): count_dict[k] = len([aa for aa in aa_list if aa == k]) # Calculate molecular weight and pI diff --git a/pdbtools/residue_renumber.py b/pdbtools/residue_renumber.py index 400db4d..2fcd54a 100755 --- a/pdbtools/residue_renumber.py +++ b/pdbtools/residue_renumber.py @@ -43,7 +43,7 @@ def pdbResidueRenumber(pdb,start_res=None,renumber_het=True,remove_gaps=False, if line[0:6] in to_renumber: # If this is the first residue in a chain, set up counter etc. - if line[21] not in seen_chains.keys(): + if line[21] not in list(seen_chains.keys()): # If we're only looking at a specific chain (and this isn't it) # don't modify th eline and move along. diff --git a/pdbtools/sasa.py b/pdbtools/sasa.py index 3e696c2..fd9fc92 100755 --- a/pdbtools/sasa.py +++ b/pdbtools/sasa.py @@ -4,6 +4,9 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import division +from __future__ import print_function +from past.utils import old_div __description__ = \ """ pdb_sasa.py @@ -18,7 +21,7 @@ global standards -class PdbSasaError(StandardError): +class PdbSasaError(Exception): """ General error class for this module. """ @@ -35,7 +38,8 @@ def runNaccess(pdb_file,probe=1.4,z_sample=0.05,vdw_file=None,keep_temp=False): try: os.mkdir(tmp_dir) - except OSError, (errno,errstr): + except OSError as xxx_todo_changeme: + (errno,errstr) = xxx_todo_changeme.args if errno == 17: pass else: @@ -121,16 +125,16 @@ def pdbSASA(pdb_file,probe_radius=1.4,z_sample=0.05,vdw_file=None, if standards == None: try: - print "Reading standards" + print("Reading standards") standards = readStandards(probe_radius=probe_radius, z_sample=z_sample, vdw_file=vdw_file) except PdbSasaError: - print "Problem with standard calculation. Only absolute" - print "accessibility will be calculated." + print("Problem with standard calculation. Only absolute") + print("accessibility will be calculated.") standards = {} - print pdb_file + print(pdb_file) all_atoms = runNaccess(pdb_file,probe_radius,z_sample,vdw_file,keep_temp) residues = [] @@ -144,7 +148,7 @@ def pdbSASA(pdb_file,probe_radius=1.4,z_sample=0.05,vdw_file=None, absolute = float(atom[13:]) try: absolute_peptide = standards[atom[4:7]][atom[:3]] - fractional = "%10.3F" % (absolute/absolute_peptide) + fractional = "%10.3F" % (old_div(absolute,absolute_peptide)) except (KeyError,ZeroDivisionError): fractional = "%10s" % "NA" diff --git a/pdbtools/satk.py b/pdbtools/satk.py index b1880ee..c03ef5c 100755 --- a/pdbtools/satk.py +++ b/pdbtools/satk.py @@ -4,6 +4,12 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import division +from __future__ import print_function +from builtins import str +from builtins import zip +from builtins import range +from past.utils import old_div __description__ = \ """ pdb_satk.py @@ -73,7 +79,7 @@ def runMkwij(wij_name,wij_id='nothing',Dint=4,Dsolv=78.5,T=298.16,a=20,b=18,g=0, # Create wij input file if os.path.isfile(wij_name): - print wij_name,'deleted.' + print(wij_name,'deleted.') os.remove(wij_name) out = [] @@ -126,9 +132,9 @@ def runSetup(prefix): found_files = ["%s%s" % (prefix,ext) for ext in ext_check if os.path.isfile("%s%s" % (prefix,ext))] if found_files != []: - print 'The following files were deleted:' + print('The following files were deleted:') for output_file in found_files: - print '\t', output_file + print('\t', output_file) os.remove(output_file) crdfrmt_bin = os.path.join(satk_path,'crdfrmt.out') @@ -164,9 +170,9 @@ def createSin(prefix,cutoff=3.): # Find distance to nearest atom for each atom num_atoms = len(coord) - nearest = [100. for i in xrange(num_atoms)] - for i in xrange(num_atoms): - for j in xrange(num_atoms): + nearest = [100. for i in range(num_atoms)] + for i in range(num_atoms): + for j in range(num_atoms): if i == j or residue[i] == residue[j]: continue d = sqrt(sum([(coord[i][k]-coord[j][k])**2 for k in [0,1,2]])) @@ -188,7 +194,7 @@ def createSin(prefix,cutoff=3.): elif nearest[i+1] < cutoff: sin.append(elc[i+1]) else: - sort_list = zip(inverse_sa[i:i+2],[i,i+1]) + sort_list = list(zip(inverse_sa[i:i+2],[i,i+1])) sort_list.sort() sin.append(elc[sort_list[0][1]]) i += 2 @@ -221,7 +227,7 @@ def runSatkelni(prefix,wij_table,high_pH=20,low_pH=0,interval=0.25, raise SATKError(err) # Make sure there are < 100 pH steps (to avoid fortran array overrun) - num_pH = (high_pH - low_pH)/interval + num_pH = old_div((high_pH - low_pH),interval) if num_pH > 100: err = "Too many pH steps! (You can only have 100 steps)." raise SATKError(err) @@ -234,9 +240,9 @@ def runSatkelni(prefix,wij_table,high_pH=20,low_pH=0,interval=0.25, if os.access(output_file,os.R_OK) == 1: found_files.append(output_file) if found_files != []: - print 'The following files were deleted:' + print('The following files were deleted:') for output_file in found_files: - print '\t', output_file + print('\t', output_file) os.remove(output_file) # Count the number of atoms in the .sin file @@ -278,7 +284,7 @@ def runSatkelni(prefix,wij_table,high_pH=20,low_pH=0,interval=0.25, "%s.pov" % prefix] runBin(satkelni_bin,satkelni_args) - print 'satkelni run complete for', prefix + print('satkelni run complete for', prefix) def createPrettyOutput(prefix): """ @@ -334,13 +340,13 @@ def createPrettyOutput(prefix): titr_dict[salt_value] = titr[:] - salts = pka_dict.keys() + salts = list(pka_dict.keys()) salts.sort() # Write out pKa values out = header[:] out.append("%10s%12s%10s%10s\n" % (" ","residue","ionic_str","pKa")) - residues = pka_dict[salts[0]].keys() + residues = list(pka_dict[salts[0]].keys()) residues.sort() counter = 0 for r in residues: @@ -524,7 +530,7 @@ def GetIndivTitration(prefix,residtype,residnum): g.write("".join(out)) g.close() - print "%s%s%s%s%s" % (prefix,'_',residtype,residnum,'.indiv'), 'written' + print("%s%s%s%s%s" % (prefix,'_',residtype,residnum,'.indiv'), 'written') def GetPHTitration(prefix): @@ -602,4 +608,4 @@ def GetPHTitration(prefix): g.write("".join(out)) g.close() - print outputfile, 'written.' + print(outputfile, 'written.') diff --git a/pdbtools/seq.py b/pdbtools/seq.py index 11869be..24749d7 100755 --- a/pdbtools/seq.py +++ b/pdbtools/seq.py @@ -4,6 +4,9 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import division +from builtins import range +from past.utils import old_div __description__ = \ """ pdb_seq.py @@ -37,7 +40,7 @@ def pdbSeq(pdb,use_atoms=False): if len(seq) != 0 and not use_atoms: seq_type = "SEQRES" chain_dict = dict([(l[11],[]) for l in seq]) - for c in chain_dict.keys(): + for c in list(chain_dict.keys()): chain_seq = [l[19:70].split() for l in seq if l[11] == c] for x in chain_seq: chain_dict[c].extend(x) @@ -76,7 +79,7 @@ def pdbSeq(pdb,use_atoms=False): atoms.append(l) chain_dict = dict([(l[21],[]) for l in atoms]) - for c in chain_dict.keys(): + for c in list(chain_dict.keys()): chain_dict[c] = [l[17:20] for l in atoms if l[21] == c] return chain_dict, seq_type @@ -97,9 +100,9 @@ def convertModifiedAA(chain_dict,pdb): mod_dict = dict([(l[12:15],l[24:27]) for l in modres]) # Replace all entries in chain_dict with their unmodified counterparts. - for c in chain_dict.keys(): + for c in list(chain_dict.keys()): for i, a in enumerate(chain_dict[c]): - if mod_dict.has_key(a): + if a in mod_dict: chain_dict[c][i] = mod_dict[a] return chain_dict @@ -118,10 +121,10 @@ def pdbSeq2Fasta(pdb,pdb_id="",chain="all",use_atoms=False): # Determine which chains are being written out if chain == "all": - chains_to_write = chain_dict.keys() + chains_to_write = list(chain_dict.keys()) chains_to_write.sort() else: - if chain in chain_dict.keys(): + if chain in list(chain_dict.keys()): chains_to_write = [chain] else: err = "Chain \"%s\" not in pdb!" % chain @@ -141,7 +144,7 @@ def pdbSeq2Fasta(pdb,pdb_id="",chain="all",use_atoms=False): # Write output in lines 80 characters long seq_length = len(chain_dict[c]) - num_lines = seq_length / 80 + num_lines = old_div(seq_length, 80) for i in range(num_lines+1): out.append("".join([aa for aa in chain_dict[c][80*i:80*(i+1)]])) diff --git a/pdbtools/splitnmr.py b/pdbtools/splitnmr.py index beb6895..372196b 100755 --- a/pdbtools/splitnmr.py +++ b/pdbtools/splitnmr.py @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from builtins import range __description__ = \ """ pdb_splitnmr.py diff --git a/pdbtools/torsion.py b/pdbtools/torsion.py index d94458b..aa9b007 100755 --- a/pdbtools/torsion.py +++ b/pdbtools/torsion.py @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from builtins import range __description__ = \ """ Determines the dihedral angles (phi,psi) for each residue in a protein. @@ -60,7 +61,7 @@ def pdbTorsion(pdb): # Now record N, C, and CA entries. Take only a unique one from # each residue to deal with multiple conformations etc. - if not resid_contents.has_key(line[13:16]): + if line[13:16] not in resid_contents: resid_contents[line[13:16]] = line else: err = "Warning: %s has repeated atoms!\n" % current_residue diff --git a/pdbtools/watercontact.py b/pdbtools/watercontact.py index b0586ce..c302fc1 100755 --- a/pdbtools/watercontact.py +++ b/pdbtools/watercontact.py @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from builtins import range __description__ = \ """ pdb_water-contact.py diff --git a/scripts/pdb_addH b/scripts/pdb_addH index 8d27bc4..74aabc0 100755 --- a/scripts/pdb_addH +++ b/scripts/pdb_addH @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = "Adds polar hydrogens to a pdb file for a UHBD calculation." __author__ = "Michael J. Harms" __date__ = "070727" @@ -92,7 +93,7 @@ def main(): pdb_id = os.path.split(file)[-1][:-4] out_file = "%sH.pdb" % pdb_id - print "%s --> %s" % (file,out_file) + print("%s --> %s" % (file,out_file)) # Load in file f = open(file,'r') @@ -106,13 +107,14 @@ def main(): keep_temp=keep_temp, calc_type=calc_type, hbond=hbond) - except addH.PdbAddHError, (strerror): + except addH.PdbAddHError as xxx_todo_changeme: + (strerror) = xxx_todo_changeme err = "Addition of hydrogens failed for %s\n" % file err += "Problem was with CHARMM\n.%s" % strerror - print err + print(err) if options.skip: - print "CHARMM output written to error.log" + print("CHARMM output written to error.log") g = open("error.log","a") g.write(err) g.write("charmm.out copied below\n%s\n" % (79*"-")) diff --git a/scripts/pdb_atom_renumber b/scripts/pdb_atom_renumber index e2988b1..6a570f5 100755 --- a/scripts/pdb_atom_renumber +++ b/scripts/pdb_atom_renumber @@ -7,6 +7,7 @@ # Thanks to Blatter Markus for adding the capability to deal with HETATM and # NMR models +from __future__ import print_function __description__ = \ """ pdb_atom_renumber.py @@ -44,7 +45,7 @@ def main(): out = atom_renumber.pdbAtomRenumber(pdb,options.renumber_het) if len(file_list) == 1: - print "".join(out) + print("".join(out)) else: out_file = "%s_renum.pdb" % pdb_file[:-4] g = open(out_file,'w') diff --git a/scripts/pdb_bfactor b/scripts/pdb_bfactor index 93f80b0..cac26e9 100755 --- a/scripts/pdb_bfactor +++ b/scripts/pdb_bfactor @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_bfactor.py: @@ -74,7 +75,7 @@ def main(): out = bfactor.pdbBfactor(pdb,data_dict) - print "".join(out) + print("".join(out)) if __name__ == "__main__": main() diff --git a/scripts/pdb_centerasu b/scripts/pdb_centerasu index e3adbd9..adecc80 100755 --- a/scripts/pdb_centerasu +++ b/scripts/pdb_centerasu @@ -5,6 +5,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_centerasu.py @@ -41,7 +42,7 @@ def main(): f.close() translation, pdb_out = centerasu.pdbCenterasu(pdb, options.coord) - print "%s %s" % (pdb_file, tuple(translation.ravel())) + print("%s %s" % (pdb_file, tuple(translation.ravel()))) # If the user wants re-centered PDB files, write them out if options.coord: out_file = "%s_asucenter.pdb" % pdb_file[:-4] diff --git a/scripts/pdb_centermass b/scripts/pdb_centermass index 3b68af7..221a6b9 100755 --- a/scripts/pdb_centermass +++ b/scripts/pdb_centermass @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_centermass.py @@ -54,7 +55,7 @@ def main(): center, pdb_out = centermass.pdbCentermass(pdb,options.coord,options.hetatm, options.mass) - print "%s %s" % (pdb_file,"".join(center)) + print("%s %s" % (pdb_file,"".join(center))) # If the user wants re-centered coordinates, write them out if options.coord: diff --git a/scripts/pdb_clean b/scripts/pdb_clean index 1f199f7..562b1b9 100755 --- a/scripts/pdb_clean +++ b/scripts/pdb_clean @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_clean.py @@ -83,15 +84,16 @@ def main(): pdb = f.readlines() f.close() - print "Loading %s" % pdb_file + print("Loading %s" % pdb_file) pdb_id = pdb_file[:-4] try: pdb = clean.pdbClean(pdb,pdb_id,chains,renumber_residues,keep_temp, fix_atoms,num_steps) - except clean.PdbCleanError, (strerror): + except clean.PdbCleanError as xxx_todo_changeme: + (strerror) = xxx_todo_changeme err = "Error cleaning \"%s\"\n%s\n" % (pdb_file,strerror) - print err, + print(err, end=' ') if options.skip: g = open("error.log","a") @@ -106,7 +108,7 @@ def main(): g.writelines(pdb) g.close() - print "Cleaned pdb written to %s" % out_file + print("Cleaned pdb written to %s" % out_file) if __name__ == "__main__": main() diff --git a/scripts/pdb_contact b/scripts/pdb_contact index 2e143ec..2da7b8e 100755 --- a/scripts/pdb_contact +++ b/scripts/pdb_contact @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_contacting-residues.py @@ -76,4 +77,4 @@ def main(): if __name__ == "__main__": out = main() - print "".join(out) + print("".join(out)) diff --git a/scripts/pdb_contactplot b/scripts/pdb_contactplot index 75383a3..887e28d 100755 --- a/scripts/pdb_contactplot +++ b/scripts/pdb_contactplot @@ -4,6 +4,10 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import division +from __future__ import print_function +from builtins import range +from past.utils import old_div __description__ = \ """ pdb_contact.py @@ -43,7 +47,7 @@ def main(): # If we are calculating a difference map, calculate this first. if options.difference != None: if not os.path.isfile(options.difference): - print "\"%s\" is not a file!" % options.difference + print("\"%s\" is not a file!" % options.difference) sys.exit() f = open(options.difference,'r') @@ -64,8 +68,8 @@ def main(): # Make sure the difference and main pdbs have the same number of atoms if options.difference != None: if len(dist) != len(to_compare): - print "\"%s\" and \"%s\" do not have same number of atoms!" % \ - (pdb_file,options.difference) + print("\"%s\" and \"%s\" do not have same number of atoms!" % \ + (pdb_file,options.difference)) sys.exit() # Write output @@ -84,9 +88,9 @@ def main(): if options.difference != None: d = dist[i][j] - to_compare[i][j] - mean = (dist[i][j] + to_compare[i][j])/2. + mean = old_div((dist[i][j] + to_compare[i][j]),2.) if mean != 0: - d_m = d/mean + d_m = old_div(d,mean) else: d_m = 0 diff --git a/scripts/pdb_coulomb b/scripts/pdb_coulomb index babfe33..c70c0ac 100755 --- a/scripts/pdb_coulomb +++ b/scripts/pdb_coulomb @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_coulomb.py @@ -62,12 +63,12 @@ def main(): # create dictionary of option values where values are in lists value_dict = dict([(k,[options.__dict__[k]]) - for k in options.__dict__.keys() if k != "titrate"]) + for k in list(options.__dict__.keys()) if k != "titrate"]) # Deal with whether the user has specified a text file containing values # over which to titrate. if options.titrate != (None,None): - available_options = value_dict.keys() + available_options = list(value_dict.keys()) # Make sure that the specified option can titrate and the file exists. titration = options.titrate[0] @@ -90,20 +91,20 @@ def main(): # Do some basic error checking except ValueError: - print "Data file \"%s\" has mangled data!" % data_file + print("Data file \"%s\" has mangled data!" % data_file) sys.exit() if len(titr) == 0: - print "Data file \"%s\" is empty!" % data_file + print("Data file \"%s\" is empty!" % data_file) sys.exit() else: - print "Data file \"%s\" does not exist!" % data_file + print("Data file \"%s\" does not exist!" % data_file) sys.exit() else: - print "\"%s\" cannot be titrated!" % titration - print "Available titrations:" + print("\"%s\" cannot be titrated!" % titration) + print("Available titrations:") for option in available_options: - print "\t%s" % option + print("\t%s" % option) sys.exit() @@ -132,7 +133,7 @@ def main(): pH,temperature,energy)) counter += 1 - print "".join(out) + print("".join(out)) if __name__ == "__main__": main() diff --git a/scripts/pdb_dist_filter b/scripts/pdb_dist_filter index c5969f7..d9303a1 100755 --- a/scripts/pdb_dist_filter +++ b/scripts/pdb_dist_filter @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __author__ = "Michael J. Harms" __date__ = "070709" __description__ = \ @@ -71,7 +72,7 @@ def main(): # dump output to stdout out = ["%10i%10.3F\n" % (i,d) for i, d in enumerate(dist)] out.insert(0,"%10s%10s\n" % (" ","dist")) - print "".join(out) + print("".join(out)) # Parse command line if called from command line if __name__ == "__main__": diff --git a/scripts/pdb_disulfide b/scripts/pdb_disulfide index cc27b4d..e61e67c 100755 --- a/scripts/pdb_disulfide +++ b/scripts/pdb_disulfide @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_disulfide.py @@ -49,7 +50,7 @@ def main(): out.append("\nDisulfide Bonds: ") out.extend(["%s, " % d.strip() for d in disulfide_bonds]) - print "".join(out) + print("".join(out)) if __name__ == "__main__": main() diff --git a/scripts/pdb_download b/scripts/pdb_download index db02363..cb7c996 100755 --- a/scripts/pdb_download +++ b/scripts/pdb_download @@ -9,6 +9,7 @@ pdb_download.py Download a pdb or set of pdb files and uncompress them. """ +from __future__ import print_function __author__ = "Michael J. Harms" __date__ = "070521" @@ -26,7 +27,7 @@ def main(): try: file_input = sys.argv[1:] except IndexError: - print __usage__ + print(__usage__) sys.exit() pdb_list = [] diff --git a/scripts/pdb_exper b/scripts/pdb_exper index 28386b0..4121f5b 100755 --- a/scripts/pdb_exper +++ b/scripts/pdb_exper @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_experiment.py @@ -43,7 +44,7 @@ def main(): out.insert(0,"%10s%30s%48s%40s%5s%10s%10s%10s\n" % (" ","pdb","protein", "organism","exp","res","r_value","r_free")) - print "".join(out) + print("".join(out)) # If run from command line... diff --git a/scripts/pdb_iondist b/scripts/pdb_iondist index 70079db..e2bf148 100755 --- a/scripts/pdb_iondist +++ b/scripts/pdb_iondist @@ -4,6 +4,8 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function +from builtins import range __description__ = \ """ pdb_ion-dist.py @@ -49,23 +51,23 @@ def main(): # total histogram to take the new data if len(tmp_hist[0]) > len(histogram[0]): diff = len(tmp_hist[0]) - len(histogram[0]) - for i in xrange(3): - histogram[i].extend([0 for j in xrange(diff)]) + for i in range(3): + histogram[i].extend([0 for j in range(diff)]) # Take data from temporary histogram and append to total histogram - for i in xrange(len(tmp_hist[0])): - for j in xrange(3): + for i in range(len(tmp_hist[0])): + for j in range(3): histogram[j][i] += tmp_hist[j][i] # Create pretty output out = ["%10s%10s%10s%10s%10s\n" % (" ","dist","a-a","a-b","b-b")] - for i in xrange(len(histogram[0])): + for i in range(len(histogram[0])): step = options.step*i out.append("%10i%10.3F%10i%10i%10i\n" % (i,step,histogram[0][i],histogram[1][i],histogram[2][i])) - print "".join(out) + print("".join(out)) diff --git a/scripts/pdb_ligand b/scripts/pdb_ligand index 661bb57..1df7071 100755 --- a/scripts/pdb_ligand +++ b/scripts/pdb_ligand @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_ligand.py @@ -46,7 +47,7 @@ def main(): out = ["%i\t%s\n" % (i,l) for i, l in enumerate(out)] - print "".join(out) + print("".join(out)) # If run from command line... diff --git a/scripts/pdb_moment b/scripts/pdb_moment index 093af2c..e045ac9 100755 --- a/scripts/pdb_moment +++ b/scripts/pdb_moment @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_moment.py @@ -49,12 +50,12 @@ def main(): if len(ca) == 0: # If not in the correct format, try to add hydrogens - print "%s does not appear to have polar hydrogens!" % pdb_file + print("%s does not appear to have polar hydrogens!" % pdb_file) if options.addH: import pdb_addH - print "Attempting to add hydrogens with pdb_addH.py" + print("Attempting to add hydrogens with pdb_addH.py") try: pdb = pdb_addH.pdbAddH(pdb,pdb_id=pdb_file[:-4]) @@ -62,20 +63,22 @@ def main(): g.writelines(pdb) g.close() - except addH.PdbAddHError, (strerror): - print "Addition of hydrogens failed for %s" % file - print strerror + except addH.PdbAddHError as xxx_todo_changeme: + (strerror) = xxx_todo_changeme + print("Addition of hydrogens failed for %s" % file) + print(strerror) sys.exit() else: - print "Please add hydrogens to the file using pdb_addH.py" + print("Please add hydrogens to the file using pdb_addH.py") sys.exit() # Calculate the dipole moment and write out try: moment = moment.pdbMoment(pdb) - except PdbMomentError, (strerror): - print "Problem with %s" % pdb_file - print strerror + except PdbMomentError as xxx_todo_changeme1: + (strerror) = xxx_todo_changeme1 + print("Problem with %s" % pdb_file) + print(strerror) sys.exit() out.append("%30s" % short_pdb) out.append("%10.3F%10.3F%10.3F" % tuple(moment)) @@ -91,7 +94,7 @@ def main(): out.insert(0,"%10s%30s%10s%10s%10s%10s\n" % (" ","pdb","x","y","z","length")) - print "".join(out) + print("".join(out)) # If run from command line... diff --git a/scripts/pdb_mutator b/scripts/pdb_mutator index fa63d02..6c9d29f 100755 --- a/scripts/pdb_mutator +++ b/scripts/pdb_mutator @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_mutator.py @@ -75,7 +76,7 @@ def main(): pdb = f.readlines() f.close() - print "Loading %s" % file + print("Loading %s" % file) pdb_id = file[:-4] pdb, mutation_string = mutator.pdbMutator(pdb,residue,mutation,chain, run_charmm) @@ -85,7 +86,7 @@ def main(): g.writelines(pdb) g.close() - print "Mutated pdb written to %s" % out_file + print("Mutated pdb written to %s" % out_file) if __name__ == "__main__": main() diff --git a/scripts/pdb_neighbors b/scripts/pdb_neighbors index 81db068..b552c3e 100755 --- a/scripts/pdb_neighbors +++ b/scripts/pdb_neighbors @@ -4,6 +4,8 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function +from builtins import range __description__ =\ """ pdb_neighbors.py @@ -83,7 +85,7 @@ def main(): out.insert(0,"# Dist cutoff: %.2F\n# Seq cutoff: %i\n" % (options.dist,options.seq)) - print "".join(out) + print("".join(out)) if __name__ == "__main__": main() diff --git a/scripts/pdb_offset b/scripts/pdb_offset index 68ef22b..1832fa3 100755 --- a/scripts/pdb_offset +++ b/scripts/pdb_offset @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ =\ """ pdb_offset.py @@ -43,7 +44,7 @@ def main(): # If it is a single file, dump to command line. If it is a directory, # write each file to r%s % file. if len(out_files) == 1: - print out_files[0] + print(out_files[0]) else: for i, f in enumerate(file_list): out_name = list(os.path.split(f)) diff --git a/scripts/pdb_oligomer b/scripts/pdb_oligomer index 7eed5d8..8d3e621 100755 --- a/scripts/pdb_oligomer +++ b/scripts/pdb_oligomer @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_oligomer.py @@ -52,7 +53,7 @@ def main(): out = ["%i\t%s\n" % (i,l) for i, l in enumerate(out)] out.insert(0,"\tpdb\tcompounds\tchains\tWYSIWYG\n") - print "".join(out) + print("".join(out)) # If run from command line... diff --git a/scripts/pdb_param b/scripts/pdb_param index ec82494..29775bd 100755 --- a/scripts/pdb_param +++ b/scripts/pdb_param @@ -4,6 +4,9 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import division +from __future__ import print_function +from past.utils import old_div __description__ = \ """ pdb_param.py: @@ -62,20 +65,21 @@ def main(): try: count_dict, mw, pI, seq_type = param.pdbParam(pdb,chain=options.chain, use_atoms=options.atomseq) - except PdbParamError, (strerror): - print "Error processing file \"%s\":" % pdb_file - print "%s" % (strerror) + except PdbParamError as xxx_todo_changeme: + (strerror) = xxx_todo_changeme + print("Error processing file \"%s\":" % pdb_file) + print("%s" % (strerror)) sys.exit() - aa_list = count_dict.keys() + aa_list = list(count_dict.keys()) aa_list.sort() # Calculate fraction ionizable total = float(sum(count_dict.values())) - titr_aa_list = [aa for aa in aa_list if aa in PKA_DICT.keys()] + titr_aa_list = [aa for aa in aa_list if aa in list(PKA_DICT.keys())] titr_total = float(sum([count_dict[aa] for aa in titr_aa_list])) - fx_titr = titr_total/total + fx_titr = old_div(titr_total,total) # Calculate the apparent charge acid = sum([count_dict[aa] for aa in ["ASP","GLU"]]) @@ -90,8 +94,8 @@ def main(): # Write out amino acid frequencies if requested if options.freq: - total_freq = dict([(aa,count_dict[aa]/total) for aa in aa_list]) - titr_freq = dict([(aa,count_dict[aa]/titr_total) + total_freq = dict([(aa,old_div(count_dict[aa],total)) for aa in aa_list]) + titr_freq = dict([(aa,old_div(count_dict[aa],titr_total)) for aa in titr_aa_list]) freq_out = [5*"%10s" % (" ","aacid","counts","fx_total","fx_titr")] @@ -112,7 +116,7 @@ def main(): out = ["%10i%s" % (i,l) for i, l in enumerate(out)] out.insert(0,"%10s%30s%10s%10s%10s%10s%10s\n" % (" ","pdb","seq","mw","pI","fx_titr","charge")) - print "".join(out) + print("".join(out)) if __name__ == "__main__": diff --git a/scripts/pdb_residue_renumber b/scripts/pdb_residue_renumber index f4753bf..916f04b 100755 --- a/scripts/pdb_residue_renumber +++ b/scripts/pdb_residue_renumber @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_residue-renumber.py @@ -76,7 +77,7 @@ def main(): g.close() if options.align_out: - print "Residue alignment written out." + print("Residue alignment written out.") alignment.insert(0,"#%s" % pdb_out[0]) g = open("%s_res-algn.out" % short_pdb,'w') diff --git a/scripts/pdb_sasa b/scripts/pdb_sasa index bdc33f1..10f50fa 100755 --- a/scripts/pdb_sasa +++ b/scripts/pdb_sasa @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_sasa.py @@ -59,7 +60,7 @@ def main(): file_list, options = cmdline.parseCommandLine() - print "Generating standards." + print("Generating standards.") standards = sasa.readStandards(options.standard_dir,options.probe_radius, options.z_sample,options.vdw_file) diff --git a/scripts/pdb_seq b/scripts/pdb_seq index 41ec5b5..2792bae 100755 --- a/scripts/pdb_seq +++ b/scripts/pdb_seq @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_seq.py @@ -52,7 +53,7 @@ def main(): sequence = seq.pdbSeq2Fasta(pdb,pdb_id,options.chain,options.atomseq) - print sequence + print(sequence) diff --git a/scripts/pdb_torsion b/scripts/pdb_torsion index 88a6387..5b88d87 100755 --- a/scripts/pdb_torsion +++ b/scripts/pdb_torsion @@ -4,6 +4,8 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function +from builtins import range __description__ = \ """ Determines the dihedral angles (phi,psi) for each residue in a protein. @@ -47,7 +49,7 @@ def main(): header = "%10s%30s%4s%8s%10s%10s\n" % (" ","pdb","aa","res","phi","psi") out.insert(0,header) - print "".join(out) + print("".join(out)) if __name__ == "__main__": diff --git a/scripts/pdb_watercontact b/scripts/pdb_watercontact index 14f8a1f..beaa279 100755 --- a/scripts/pdb_watercontact +++ b/scripts/pdb_watercontact @@ -4,6 +4,7 @@ # This program is distributed under General Public License v. 3. See the file # COPYING for a copy of the license. +from __future__ import print_function __description__ = \ """ pdb_water-contact.py @@ -42,11 +43,11 @@ def main(): neighbors = watercontact.pdbWaterContact(pdb,options.probe) - residues = neighbors.keys() + residues = list(neighbors.keys()) residues.sort() for r in residues: - print "\"%5s\"%10i" % (r,len(neighbors[r])) + print("\"%5s\"%10i" % (r,len(neighbors[r]))) # If run from command line... if __name__ == "__main__": diff --git a/setup.py b/setup.py index 70304aa..e5b11a3 100644 --- a/setup.py +++ b/setup.py @@ -11,11 +11,14 @@ setup(name='pdbtools', version='0.1', - description='A set of tools for manipulating and doing calculations on wwPDB macromolecule structure files', + description= + 'A set of tools for manipulating and doing calculations on wwPDB ' + 'macromolecule structure files', author='Michael J. Harms', author_email='harms@uoregon.edu', packages=['pdbtools'], - scripts=['scripts/pdb_addH', + scripts=[ + 'scripts/pdb_addH', 'scripts/pdb_atom_renumber', 'scripts/pdb_bfactor', 'scripts/pdb_centerasu', @@ -47,5 +50,5 @@ 'scripts/pdb_torsion', 'scripts/pdb_watercontact' ], - #install_requires=[], + install_requires=['future'], zip_safe=False)