Commit c6b6b894 authored by Jason Swails's avatar Jason Swails
Browse files

Make sure the DCD file handle is closed -- do it the right way in the test.

Make sure files are appropriately closed by PDBFile()
parent a64e0db6
......@@ -75,9 +75,13 @@ class PDBFile(object):
pdb = file
else:
inputfile = file
own_handle = False
if isinstance(file, str):
inputfile = open(file)
own_handle = True
pdb = PdbStructure(inputfile, load_all_models=True)
if own_handle:
inputfile.close()
PDBFile._loadNameReplacementTables()
# Build the topology
......
......@@ -12,10 +12,10 @@ class TestDCDFile(unittest.TestCase):
fname = tempfile.mktemp(suffix='.dcd')
pdbfile = app.PDBFile('systems/alanine-dipeptide-implicit.pdb')
natom = len(list(pdbfile.topology.atoms()))
dcd = app.DCDFile(open(fname, 'wb'), pdbfile.topology, 0.001)
for i in range(5):
dcd.writeModel([mm.Vec3(random(), random(), random()) for j in range(natom)]*unit.angstroms)
dcd._file.close()
with open(fname, 'wb') as f:
dcd = app.DCDFile(f, pdbfile.topology, 0.001)
for i in range(5):
dcd.writeModel([mm.Vec3(random(), random(), random()) for j in range(natom)]*unit.angstroms)
os.remove(fname)
if __name__ == '__main__':
......
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