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
c6b6b894
Commit
c6b6b894
authored
Nov 14, 2014
by
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
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
4 deletions
+8
-4
wrappers/python/simtk/openmm/app/pdbfile.py
wrappers/python/simtk/openmm/app/pdbfile.py
+4
-0
wrappers/python/tests/TestDcdFile.py
wrappers/python/tests/TestDcdFile.py
+4
-4
No files found.
wrappers/python/simtk/openmm/app/pdbfile.py
View file @
c6b6b894
...
@@ -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
...
...
wrappers/python/tests/TestDcdFile.py
View file @
c6b6b894
...
@@ -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
:
dcd
=
app
.
DCDFile
(
f
,
pdbfile
.
topology
,
0.001
)
for
i
in
range
(
5
):
for
i
in
range
(
5
):
dcd
.
writeModel
([
mm
.
Vec3
(
random
(),
random
(),
random
())
for
j
in
range
(
natom
)]
*
unit
.
angstroms
)
dcd
.
writeModel
([
mm
.
Vec3
(
random
(),
random
(),
random
())
for
j
in
range
(
natom
)]
*
unit
.
angstroms
)
dcd
.
_file
.
close
()
os
.
remove
(
fname
)
os
.
remove
(
fname
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
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