Skip to content

Commit

Permalink
running 2-to-3
Browse files Browse the repository at this point in the history
  • Loading branch information
harmsm committed Sep 6, 2019
1 parent 226c0a2 commit d00ca37
Show file tree
Hide file tree
Showing 48 changed files with 162 additions and 152 deletions.
6 changes: 3 additions & 3 deletions pdbtools/addH.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,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:
Expand Down Expand Up @@ -181,7 +181,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]
Expand Down
2 changes: 1 addition & 1 deletion pdbtools/bfactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions pdbtools/centerasu.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,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):
Expand All @@ -46,7 +46,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:
Expand Down
12 changes: 6 additions & 6 deletions pdbtools/centermass.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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):
"""
Expand Down Expand Up @@ -73,9 +73,9 @@ 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)
Expand All @@ -100,7 +100,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
6 changes: 3 additions & 3 deletions pdbtools/charmm/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
__date__ = "080418"

import math, os
import gen_input
from . import gen_input

# Set up charmm binary
try:
Expand Down Expand Up @@ -66,7 +66,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)
Expand All @@ -90,7 +90,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]]
Expand Down
29 changes: 15 additions & 14 deletions pdbtools/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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:])
Expand All @@ -72,7 +72,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)
Expand All @@ -87,7 +87,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

Expand Down Expand Up @@ -120,7 +120,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]])])
Expand Down Expand Up @@ -197,7 +197,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)

Expand Down Expand Up @@ -265,7 +266,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!"
Expand All @@ -278,13 +279,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)
Expand All @@ -293,7 +294,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."
Expand All @@ -303,14 +304,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)
Expand All @@ -319,17 +320,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):
Expand Down
2 changes: 1 addition & 1 deletion pdbtools/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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
2 changes: 1 addition & 1 deletion pdbtools/coulomb.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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
Expand Down
2 changes: 1 addition & 1 deletion pdbtools/data/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
6 changes: 3 additions & 3 deletions pdbtools/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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()
Expand All @@ -63,10 +63,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
Expand Down
2 changes: 1 addition & 1 deletion pdbtools/helper/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pdbtools/helper/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,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]

Expand Down
10 changes: 5 additions & 5 deletions pdbtools/iondist.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,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
Expand All @@ -46,15 +46,15 @@ def pdbIonDist(pdb,hist_step,remove_resid="TYR"):
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)]
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):
for i in range(N):
for j in range(i+1,N):
interaction_type = int((charge[i] + charge[j])/2 + 1)
dist_bin = int(round(dist[i][j]/hist_step))
histogram[interaction_type][dist_bin] += 1
Expand Down
2 changes: 1 addition & 1 deletion pdbtools/ligand.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 7 additions & 5 deletions pdbtools/mutator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
__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 . import helper
from .helper import container
from . import data
from .data.common import *

class MutatorError(Exception):
Expand Down Expand Up @@ -89,20 +91,20 @@ 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")

# 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):
Expand Down
6 changes: 3 additions & 3 deletions pdbtools/oligomer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,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]

Expand All @@ -138,7 +138,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)]]

Expand Down
Loading

0 comments on commit d00ca37

Please sign in to comment.