Python 3 compatibility (issue #398) (#1192)

* Replace xrange with range or import from rdkit.six

* Remove use of string.lower

* The import of xrange in MolSurf added it to the Descriptors._descList
This commit is contained in:
gedeck
2016-12-16 02:11:28 -05:00
committed by Greg Landrum
parent ef12edaf24
commit bb707f9e02
14 changed files with 28 additions and 28 deletions

View File

@@ -205,7 +205,7 @@ class Library:
max_subsets = max(partitions)
enumeration_indices = []
for i in xrange(max_subsets):
for i in range(max_subsets):
combinations = []
for size in partitions:
combinations.append( i % size )

View File

@@ -97,7 +97,7 @@ for line in sys.stdin:
res = DataStructs.BulkTverskySimilarity(mfp, queries, 0, 1, False)
#query_frag_smiles,query_smiles,query_id,retrieved_smi,retrieved_id,tversky_sim
for i in xrange(fragments):
for i in range(fragments):
if (res[i] >= options.cutoff):
print("%s,%s,%s,%s,%s,%s" %
(query_info[i][2], query_info[i][0], query_info[i][1], smi, id, res[i]))

View File

@@ -48,8 +48,8 @@ def GetDistanceMatrix(data, metric, isSimilarity=1):
nPts = len(data)
res = numpy.zeros((nPts * (nPts - 1) / 2), numpy.float)
nSoFar = 0
for col in xrange(1, nPts):
for row in xrange(col):
for col in range(1, nPts):
for row in range(col):
fp1 = data[col][1]
fp2 = data[row][1]
if fp1.GetNumBits() > fp2.GetNumBits():

View File

@@ -72,7 +72,7 @@ def _pyLabuteHelper(mol, includeHs=1, force=0):
# 0 contains the H information
rads[0] = numTable[1][radCol]
for i in xrange(nAts):
for i in range(nAts):
rads[i + 1] = numTable[mol.GetAtomWithIdx(i).GetAtomicNum()][radCol]
# start with explicit bonds
@@ -94,14 +94,14 @@ def _pyLabuteHelper(mol, includeHs=1, force=0):
if includeHs:
j = 0
Rj = rads[j]
for i in xrange(1, nAts + 1):
for i in range(1, nAts + 1):
Ri = rads[i]
bij = Ri + Rj
dij = min(max(abs(Ri - Rj), bij), Ri + Rj)
Vi[i] += Rj * Rj - (Ri - dij)**2 / dij
Vi[j] += Ri * Ri - (Rj - dij)**2 / dij
for i in xrange(nAts + 1):
for i in range(nAts + 1):
Ri = rads[i]
Vi[i] = 4 * math.pi * Ri**2 - math.pi * Ri * Vi[i]

View File

@@ -44,7 +44,7 @@ class TestCase(unittest.TestCase):
except Exception:
import traceback
traceback.print_exc()
raise AssertionError('SMILES: %s' % smi)
raise AssertionError('SMILES: %s; Descriptor: %s' % (smi, nm))
def testMolFormula(self):
for (smiles, expected) in (("[NH4+]", "H4N+"),

View File

@@ -1047,7 +1047,7 @@ def find_duplicates(cangen_nodes, start, end):
result = []
prev_value = -1
count = 0
for index in xrange(start, end):
for index in range(start, end):
node = cangen_nodes[index]
if node.value == prev_value:
count += 1
@@ -2461,19 +2461,19 @@ def parse_select(s):
m = range_pat.match(s, start)
if m is not None:
# Selected from 'left' to (and including) 'right'
# Convert into xrange fields, starting from 0
# Convert into range fields, starting from 0
left = int(m.group(1))
right = m.group(2)
if not right:
ranges.append(starting_from(left - 1))
else:
ranges.append(xrange(left - 1, int(right)))
ranges.append(range(left - 1, int(right)))
else:
# Selected a single value
m = value_pat.match(s, start)
if m is not None:
val = int(m.group(1))
ranges.append(xrange(val - 1, val))
ranges.append(range(val - 1, val))
else:
raise argparse.ArgumentTypeError("Unknown character at position %d of %r" % (start + 1, s))
start = m.end()

View File

@@ -66,7 +66,7 @@ class DbConnect(object):
self.user = self.userEntry.GetValue()
self.password = self.passwdEntry.GetValue()
self.dbName = self.dbBrowseButton.GetValue()
for i in xrange(self.dbTableChoice.Number()):
for i in range(self.dbTableChoice.Number()):
self.dbTableChoice.Delete(0)
names = self.GetTableNames()

View File

@@ -251,12 +251,12 @@ def parseAFMfile(filename):
metriclines = []
between = 0
for line in alllines:
if string.find(string.lower(line), 'endcharmetrics') > -1:
if string.find(line.lower(), 'endcharmetrics') > -1:
between = 0
break
if between:
metriclines.append(line)
if string.find(string.lower(line), 'startcharmetrics') > -1:
if string.find(line.lower(), 'startcharmetrics') > -1:
between = 1
# break up - very shaky assumption about array size
@@ -307,7 +307,7 @@ class FontCache:
return self.getfont('courier')
def stringwidth(self, text, font):
widths = self.getfont(string.lower(font))
widths = self.getfont(font.lower())
w = 0
for char in text:
w = w + widths[ord(char)]

View File

@@ -221,7 +221,7 @@ class PDFCanvas(Canvas):
if not font.face:
face = 'serif'
else:
face = string.lower(font.face)
face = font.face.lower()
while face in font_face_map:
face = font_face_map[face]
#step 2, - resolve bold/italic to get the right PS font name

View File

@@ -219,10 +219,10 @@ _Widths = {'StandardEncoding': _stdenc_widths, 'Latin1Encoding': latin1MetricsCa
def stringwidth(text, font, encoding):
if font in fontinfo.NonRomanFonts:
widths = _Widths['StandardEncoding'][string.lower(font)]
widths = _Widths['StandardEncoding'][font.lower()]
else:
try:
widths = _Widths[encoding][string.lower(font)]
widths = _Widths[encoding][font.lower()]
except Exception:
raise KeyError("Improper encoding {0} or font name {1}".format(encoding, font))
w = 0

View File

@@ -74,7 +74,7 @@ def getPyartName(pidfont):
face = pidfont.face or DefaultFace
# print "pidfont.face = %s" % pidfont.face
face = string.lower(face)
face = face.lower()
if face in PidLegalFonts:
return MapPid2PyartFontName[(PidLegalFonts[face], shape)]
else:
@@ -93,7 +93,7 @@ getPdfName = getPyartName
# face = pidfont.face or DefaultFace
# # print "pidfont.face = %s" % pidfont.face
# face = string.lower(face)
# face = face.lower()
# if face in PidLegalFonts:
# return PDFFontMapping[ ( PidLegalFonts[face], shape) ]
# else:

View File

@@ -124,7 +124,7 @@ class PyartCanvas(Canvas):
}
try:
face = piddle_font_map[string.lower(font.face)]
face = piddle_font_map[font.face.lower()]
except Exception:
return 'Helvetica'

View File

@@ -74,7 +74,7 @@ def _PointListToSVG(points, dupFirst=0):
"""
outStr = ''
for i in xrange(len(points)):
for i in range(len(points)):
outStr = outStr + '%.2f,%.2f ' % (points[i][0], points[i][1])
# add back on the first point. This is not required in the spec,
# but Adobe's beta-quality viewer seems to not like it being skipped
@@ -130,9 +130,9 @@ class SVGCanvas(Canvas):
}
try:
face = piddle_font_map[string.lower(font.face)]
face = piddle_font_map[font.face.lower()]
except Exception:
return piddle_font_map[string.lower('sansserif')]
return piddle_font_map['sansserif']
name = face + '-'
if font.bold and face in ['Courier', 'Helvetica', 'Times']:
@@ -170,7 +170,7 @@ class SVGCanvas(Canvas):
familyStr = '\'%s\'' % (face)
else:
familyStr = face
for i in xrange(1, len(font.face)):
for i in range(1, len(font.face)):
face = font.face[i]
if len(string.split(face)) > 1:
familyStr = ', \'%s\'' % (face)
@@ -609,7 +609,7 @@ class SVGCanvas(Canvas):
into SVG is to read it from a file. So we'll save out to a PNG
file, then set a link to that in the SVG.
"""
imageFileName = '%s-%d.%s' % (self.name, self._nImages, string.lower(self._imageFormat))
imageFileName = '%s-%d.%s' % (self.name, self._nImages, self._imageFormat.lower())
self._nImages = self._nImages + 1
image.save(imageFileName, format=self._imageFormat)

View File

@@ -135,7 +135,7 @@ class FontManager:
if font.face:
# check if the user specified a generic face type
# like serif or monospaced. check is case-insenstive.
f = string.lower(font.face)
f = font.face.lower()
if f in self.__alt_faces:
family = self.__alt_faces[f]
else: