Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
1586d560
Unverified
Commit
1586d560
authored
Feb 19, 2019
by
peastman
Committed by
GitHub
Feb 19, 2019
Browse files
Merge pull request #2264 from tristanic/files
Ensuring opened files are properly closed
parents
bd788d90
5c14022e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
36 deletions
+43
-36
wrappers/python/simtk/openmm/app/gromacsgrofile.py
wrappers/python/simtk/openmm/app/gromacsgrofile.py
+34
-33
wrappers/python/simtk/openmm/app/pdbxfile.py
wrappers/python/simtk/openmm/app/pdbxfile.py
+4
-0
wrappers/python/tests/TestAmberPrmtopFile.py
wrappers/python/tests/TestAmberPrmtopFile.py
+2
-1
wrappers/python/tests/TestPdbFile.py
wrappers/python/tests/TestPdbFile.py
+3
-2
No files found.
wrappers/python/simtk/openmm/app/gromacsgrofile.py
View file @
1586d560
...
@@ -133,7 +133,8 @@ class GromacsGroFile(object):
...
@@ -133,7 +133,8 @@ class GromacsGroFile(object):
xyz
=
[]
xyz
=
[]
ln
=
0
ln
=
0
frame
=
0
frame
=
0
for
line
in
open
(
file
):
with
open
(
file
)
as
grofile
:
for
line
in
grofile
:
if
ln
==
0
:
if
ln
==
0
:
comms
.
append
(
line
.
strip
())
comms
.
append
(
line
.
strip
())
elif
ln
==
1
:
elif
ln
==
1
:
...
...
wrappers/python/simtk/openmm/app/pdbxfile.py
View file @
1586d560
...
@@ -70,11 +70,15 @@ class PDBxFile(object):
...
@@ -70,11 +70,15 @@ class PDBxFile(object):
# Load the file.
# Load the file.
inputFile
=
file
inputFile
=
file
ownHandle
=
False
if
isinstance
(
file
,
str
):
if
isinstance
(
file
,
str
):
inputFile
=
open
(
file
)
inputFile
=
open
(
file
)
ownHandle
=
True
reader
=
PdbxReader
(
inputFile
)
reader
=
PdbxReader
(
inputFile
)
data
=
[]
data
=
[]
reader
.
read
(
data
)
reader
.
read
(
data
)
if
ownHandle
:
inputFile
.
close
()
block
=
data
[
0
]
block
=
data
[
0
]
# Build the topology.
# Build the topology.
...
...
wrappers/python/tests/TestAmberPrmtopFile.py
View file @
1586d560
...
@@ -293,7 +293,8 @@ class TestAmberPrmtopFile(unittest.TestCase):
...
@@ -293,7 +293,8 @@ class TestAmberPrmtopFile(unittest.TestCase):
context
=
Context
(
system
,
integrator
,
Platform
.
getPlatformByName
(
"Reference"
))
context
=
Context
(
system
,
integrator
,
Platform
.
getPlatformByName
(
"Reference"
))
context
.
setPositions
(
pdb
.
positions
)
context
.
setPositions
(
pdb
.
positions
)
state1
=
context
.
getState
(
getForces
=
True
)
state1
=
context
.
getState
(
getForces
=
True
)
state2
=
XmlSerializer
.
deserialize
(
open
(
'systems/alanine-dipeptide-implicit-forces/'
+
file
[
i
]
+
'.xml'
).
read
())
with
open
(
'systems/alanine-dipeptide-implicit-forces/'
+
file
[
i
]
+
'.xml'
)
as
infile
:
state2
=
XmlSerializer
.
deserialize
(
infile
.
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
)
...
...
wrappers/python/tests/TestPdbFile.py
View file @
1586d560
...
@@ -67,7 +67,8 @@ class TestPdbFile(unittest.TestCase):
...
@@ -67,7 +67,8 @@ class TestPdbFile(unittest.TestCase):
def
test_BinaryStream
(
self
):
def
test_BinaryStream
(
self
):
"""Test reading a stream that was opened in binary mode."""
"""Test reading a stream that was opened in binary mode."""
pdb
=
PDBFile
(
open
(
'systems/triclinic.pdb'
,
'rb'
))
with
open
(
'systems/triclinic.pdb'
,
'rb'
)
as
infile
:
pdb
=
PDBFile
(
infile
)
self
.
assertEqual
(
len
(
pdb
.
positions
),
8
)
self
.
assertEqual
(
len
(
pdb
.
positions
),
8
)
def
test_ExtraParticles
(
self
):
def
test_ExtraParticles
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment