Commit 3cc6a186 authored by peastman's avatar peastman Committed by GitHub
Browse files

Merge pull request #1536 from peastman/filewarning

Eliminated warnings about unclosed files
parents c3d1e8a4 258ef062
......@@ -81,7 +81,7 @@ class CharmmCrdFile(object):
def _parse(self, fname):
crdfile = open(fname, 'r')
with open(fname, 'r') as crdfile:
line = crdfile.readline()
while len(line.strip()) == 0: # Skip whitespace, as a precaution
......
......@@ -178,7 +178,7 @@ class CharmmPsfFile(object):
if not os.path.exists(psf_name):
raise IOError('Could not find PSF file %s' % psf_name)
# Open the PSF and read the first line. It must start with "PSF"
psf = open(psf_name, 'r')
with open(psf_name, 'r') as psf:
line = psf.readline()
if not line.startswith('PSF'):
raise CharmmPSFError('Unrecognized PSF file. First line is %s' %
......
......@@ -165,7 +165,8 @@ class TestCharmmFiles(unittest.TestCase):
#out = open('systems/ala-ala-ala-implicit-forces/'+file[i]+'.xml', 'w')
#out.write(XmlSerializer.serialize(state1))
#out.close()
state2 = XmlSerializer.deserialize(open('systems/ala-ala-ala-implicit-forces/'+file[i]+'.xml').read())
with open('systems/ala-ala-ala-implicit-forces/'+file[i]+'.xml') as xml:
state2 = XmlSerializer.deserialize(xml.read())
for f1, f2, in zip(state1.getForces().value_in_unit(kilojoules_per_mole/nanometer), state2.getForces().value_in_unit(kilojoules_per_mole/nanometer)):
diff = norm(f1-f2)
self.assertTrue(diff < 0.1 or diff/norm(f1) < 1e-4)
......
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