Commit 8d276c26 authored by peastman's avatar peastman
Browse files

Merge pull request #839 from peastman/decode

PdbStructure handles byte streams correctly in Python 3
parents decb586c 9fee45f9
......@@ -150,6 +150,8 @@ class PdbStructure(object):
self._reset_residue_numbers()
# Read one line at a time
for pdb_line in input_stream:
if not isinstance(pdb_line, str):
pdb_line = pdb_line.decode('utf-8')
# Look for atoms
if (pdb_line.find("ATOM ") == 0) or (pdb_line.find("HETATM") == 0):
self._add_atom(Atom(pdb_line, self))
......
......@@ -60,6 +60,12 @@ class TestPdbFile(unittest.TestCase):
self.assertEqual(atom1.name, atom2.name)
self.assertEqual(atom1.residue.name, atom2.residue.name)
def test_BinaryStream(self):
"""Test reading a stream that was opened in binary mode."""
pdb = PDBFile(open('systems/triclinic.pdb', 'rb'))
self.assertEqual(len(pdb.positions), 8)
def assertVecAlmostEqual(self, p1, p2, tol=1e-7):
unit = p1.unit
p1 = p1.value_in_unit(unit)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment