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