diff --git a/prody/dynamics/heatmapper.py b/prody/dynamics/heatmapper.py index 000bf0569..be00d0141 100644 --- a/prody/dynamics/heatmapper.py +++ b/prody/dynamics/heatmapper.py @@ -6,7 +6,7 @@ __author__ = 'Ahmet Bakan, Anindita Dutta' -from numpy import arange, fromstring, array +from numpy import arange, fromstring, frombuffer, array from prody.utilities import openFile, intorfloat, startswith, addext @@ -131,7 +131,11 @@ def parseHeatmap(heatmap, **kwargs): numbers.append(items[:nnums]) else: items = [arr] - heatmap.append(fromstring(items[-1], float, sep=';')) + + try: + heatmap.append(fromstring(items[-1], float, sep=';')) + except: + heatmap.append(frombuffer(items[-1], float, sep=';')) heatmap = array(heatmap) if nnums: diff --git a/prody/dynamics/nmdfile.py b/prody/dynamics/nmdfile.py index 12bdc8038..4ae1d01a4 100644 --- a/prody/dynamics/nmdfile.py +++ b/prody/dynamics/nmdfile.py @@ -272,7 +272,11 @@ def parseNMD(filename, type=NMA): line, coords = atomic.pop('coordinates', None) if coords is not None: - coords = np.fromstring(coords, dtype=float, sep=' ') + try: + coords = np.fromstring(coords, dtype=float, sep=' ') + except: + coords = np.frombuffer(coords, dtype=float, sep=' ') + dof = coords.shape[0] if dof % 3 != 0: LOGGER.warn('Coordinate data in {0} at line {1} is corrupt ' @@ -325,7 +329,11 @@ def parseNMD(filename, type=NMA): eigvals = [] count = 0 for i, (line, mode) in enumerate(modes): - mode = np.fromstring(mode, dtype=float, sep=' ') + try: + mode = np.fromstring(mode, dtype=float, sep=' ') + except: + mode = np.frombuffer(mode, dtype=float, sep=' ') + diff = len(mode) - dof if diff < 0 or diff > 2: LOGGER.warn('Mode data in {0} at line {1} is corrupt.' diff --git a/prody/proteins/header.py b/prody/proteins/header.py index 1a64132c6..2b532422e 100644 --- a/prody/proteins/header.py +++ b/prody/proteins/header.py @@ -1100,15 +1100,28 @@ def buildBiomolecules(header, atoms, biomol=None): for times in range(int((len(mt)) / 4)): rotation = np.zeros((3, 3)) translation = np.zeros(3) - line0 = np.fromstring(mt[times*4+1], sep=' ') + + try: + line0 = np.fromstring(mt[times*4+1], sep=' ') + except: + line0 = np.frombuffer(mt[times*4+1], sep=' ') rotation[0, :] = line0[:3] translation[0] = line0[3] - line1 = np.fromstring(mt[times*4+2], sep=' ') + + try: + line1 = np.fromstring(mt[times*4+2], sep=' ') + except: + line1 = np.frombuffer(mt[times*4+2], sep=' ') rotation[1, :] = line1[:3] translation[1] = line1[3] - line2 = np.fromstring(mt[times*4+3], sep=' ') + + try: + line2 = np.fromstring(mt[times*4+3], sep=' ') + except: + line2 = np.frombuffer(mt[times*4+3], sep=' ') rotation[2, :] = line2[:3] translation[2] = line2[3] + t = Transformation(rotation, translation) newag = atoms.select('chain ' + ' or chain '.join(mt[times*4+0])) diff --git a/prody/sequence/msa.py b/prody/sequence/msa.py index 5de2eb85d..62175e4ed 100644 --- a/prody/sequence/msa.py +++ b/prody/sequence/msa.py @@ -154,8 +154,16 @@ def __getitem__(self, index): if isinstance(rows, list): rows = self.getIndex(rows) or rows elif isinstance(rows, int): - return Sequence(self._msa[rows, cols].tobytes(), - self._labels[rows]) + if PY3K: + try: + return Sequence(self._msa[rows, cols].tostring().decode(), + self._labels[rows]) + except: + return Sequence(self._msa[rows, cols].tobytes().decode(), + self._labels[rows]) + else: + return Sequence(self._msa[rows, cols].tostring(), + self._labels[rows]) elif isinstance(rows, str): try: rows = self._mapping[rows] @@ -164,8 +172,12 @@ def __getitem__(self, index): .format(index)) else: if isinstance(rows, int): - return Sequence(self._msa[rows, cols].tobytes(), - self._labels[rows]) + try: + return Sequence(self._msa[rows, cols].tostring(), + self._labels[rows]) + except: + return Sequence(self._msa[rows, cols].tobytes(), + self._labels[rows]) if cols is None: msa = self._msa[rows] @@ -546,7 +558,16 @@ def refineMSA(msa, index=None, label=None, rowocc=None, seqid=None, colocc=None, from prody.utilities import GAP_PENALTY, GAP_EXT_PENALTY, ALIGNMENT_METHOD chseq = chain.getSequence() - algn = alignBioPairwise(pystr(arr[index].tobytes().upper()), pystr(chseq), + + if PY3K: + try: + arr2 = arr[index].tostring().decode() + except: + arr2 = arr[index].tobytes().decode() + else: + arr2 = arr[index].tostring() + + algn = alignBioPairwise(pystr(arr2.upper()), pystr(chseq), "local", MATCH_SCORE, MISMATCH_SCORE, GAP_PENALTY, GAP_EXT_PENALTY, diff --git a/prody/sequence/msafile.py b/prody/sequence/msafile.py index 8719e6bad..838f158b1 100644 --- a/prody/sequence/msafile.py +++ b/prody/sequence/msafile.py @@ -6,7 +6,7 @@ from os.path import isfile, splitext, split, getsize -from numpy import array, fromstring, empty +from numpy import array, fromstring, empty, frombuffer from .sequence import splitSeqLabel, Sequence @@ -425,15 +425,22 @@ def setSlice(self, slice): try: seq[slice] except Exception: - arr = fromstring(seq, '|S1') + try: + arr = fromstring(seq, '|S1') + except: + arr = frombuffer(seq, '|S1') try: arr[slice] except Exception: raise TypeError('invalid slice: ' + repr(slice)) else: self._slice = slice - self._slicer = lambda seq, slc=slice: fromstring(seq, - '|S1')[slc].tobytes() + try: + self._slicer = lambda seq, slc=slice: fromstring(seq, + '|S1')[slc].tostring() + except: + self._slicer = lambda seq, slc=slice: fromstring(seq, + '|S1')[slc].tobytes() else: self._slice = slice self._slicer = lambda seq, slc=slice: seq[slc] diff --git a/prody/sequence/sequence.py b/prody/sequence/sequence.py index 6cc78b206..486b08057 100644 --- a/prody/sequence/sequence.py +++ b/prody/sequence/sequence.py @@ -49,7 +49,10 @@ def _array(self): def __str__(self): if PY3K: - return self._array.tobytes().decode() + try: + return self._array.tostring().decode() + except: + return self._array.tobytes().decode() else: return self._array.tobytes()