Commit 258ef062 authored by peastman's avatar peastman
Browse files

Eliminated warnings about unclosed files

parent 01f9e415
...@@ -81,7 +81,7 @@ class CharmmCrdFile(object): ...@@ -81,7 +81,7 @@ class CharmmCrdFile(object):
def _parse(self, fname): def _parse(self, fname):
crdfile = open(fname, 'r') with open(fname, 'r') as crdfile:
line = crdfile.readline() line = crdfile.readline()
while len(line.strip()) == 0: # Skip whitespace, as a precaution while len(line.strip()) == 0: # Skip whitespace, as a precaution
......
...@@ -178,7 +178,7 @@ class CharmmPsfFile(object): ...@@ -178,7 +178,7 @@ class CharmmPsfFile(object):
if not os.path.exists(psf_name): if not os.path.exists(psf_name):
raise IOError('Could not find PSF file %s' % 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" # 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() line = psf.readline()
if not line.startswith('PSF'): if not line.startswith('PSF'):
raise CharmmPSFError('Unrecognized PSF file. First line is %s' % raise CharmmPSFError('Unrecognized PSF file. First line is %s' %
......
...@@ -165,7 +165,8 @@ class TestCharmmFiles(unittest.TestCase): ...@@ -165,7 +165,8 @@ class TestCharmmFiles(unittest.TestCase):
#out = open('systems/ala-ala-ala-implicit-forces/'+file[i]+'.xml', 'w') #out = open('systems/ala-ala-ala-implicit-forces/'+file[i]+'.xml', 'w')
#out.write(XmlSerializer.serialize(state1)) #out.write(XmlSerializer.serialize(state1))
#out.close() #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)): 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) diff = norm(f1-f2)
self.assertTrue(diff < 0.1 or diff/norm(f1) < 1e-4) 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