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
174b57e4
Commit
174b57e4
authored
Feb 19, 2019
by
tic20
Browse files
Revert "Ensuring opened files are closed properly when done"
This reverts commit
5ef91d22
.
parent
5ef91d22
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
40 deletions
+36
-40
wrappers/python/simtk/openmm/app/gromacsgrofile.py
wrappers/python/simtk/openmm/app/gromacsgrofile.py
+33
-34
wrappers/python/simtk/openmm/app/pdbxfile.py
wrappers/python/simtk/openmm/app/pdbxfile.py
+0
-1
wrappers/python/tests/TestAmberPrmtopFile.py
wrappers/python/tests/TestAmberPrmtopFile.py
+1
-2
wrappers/python/tests/TestPdbFile.py
wrappers/python/tests/TestPdbFile.py
+2
-3
No files found.
wrappers/python/simtk/openmm/app/gromacsgrofile.py
View file @
174b57e4
...
@@ -133,40 +133,39 @@ class GromacsGroFile(object):
...
@@ -133,40 +133,39 @@ class GromacsGroFile(object):
xyz
=
[]
xyz
=
[]
ln
=
0
ln
=
0
frame
=
0
frame
=
0
with
open
(
file
)
as
grofile
:
for
line
in
open
(
file
):
for
line
in
grofile
:
if
ln
==
0
:
if
ln
==
0
:
comms
.
append
(
line
.
strip
())
comms
.
append
(
line
.
strip
())
elif
ln
==
1
:
elif
ln
==
1
:
na
=
int
(
line
.
strip
())
na
=
int
(
line
.
strip
())
elif
_is_gro_coord
(
line
):
elif
_is_gro_coord
(
line
):
if
frame
==
0
:
# Create the list of residues, atom names etc. only if it's the first frame.
if
frame
==
0
:
# Create the list of residues, atom names etc. only if it's the first frame.
(
thisresnum
,
thisresname
,
thisatomname
)
=
[
line
[
i
*
5
:
i
*
5
+
5
].
strip
()
for
i
in
range
(
3
)]
(
thisresnum
,
thisresname
,
thisatomname
)
=
[
line
[
i
*
5
:
i
*
5
+
5
].
strip
()
for
i
in
range
(
3
)]
resname
.
append
(
thisresname
)
resname
.
append
(
thisresname
)
resid
.
append
(
int
(
thisresnum
))
resid
.
append
(
int
(
thisresnum
))
atomname
.
append
(
thisatomname
)
atomname
.
append
(
thisatomname
)
thiselem
=
thisatomname
thiselem
=
thisatomname
if
len
(
thiselem
)
>
1
:
if
len
(
thiselem
)
>
1
:
thiselem
=
thiselem
[
0
]
+
sub
(
'[A-Z0-9]'
,
''
,
thiselem
[
1
:])
thiselem
=
thiselem
[
0
]
+
sub
(
'[A-Z0-9]'
,
''
,
thiselem
[
1
:])
try
:
try
:
elements
.
append
(
elem
.
get_by_symbol
(
thiselem
))
elements
.
append
(
elem
.
get_by_symbol
(
thiselem
))
except
KeyError
:
except
KeyError
:
elements
.
append
(
None
)
elements
.
append
(
None
)
firstDecimalPos
=
line
.
index
(
'.'
,
20
)
firstDecimalPos
=
line
.
index
(
'.'
,
20
)
secondDecimalPos
=
line
.
index
(
'.'
,
firstDecimalPos
+
1
)
secondDecimalPos
=
line
.
index
(
'.'
,
firstDecimalPos
+
1
)
digits
=
secondDecimalPos
-
firstDecimalPos
digits
=
secondDecimalPos
-
firstDecimalPos
pos
=
[
float
(
line
[
20
+
i
*
digits
:
20
+
(
i
+
1
)
*
digits
])
for
i
in
range
(
3
)]
pos
=
[
float
(
line
[
20
+
i
*
digits
:
20
+
(
i
+
1
)
*
digits
])
for
i
in
range
(
3
)]
xyz
.
append
(
Vec3
(
pos
[
0
],
pos
[
1
],
pos
[
2
]))
xyz
.
append
(
Vec3
(
pos
[
0
],
pos
[
1
],
pos
[
2
]))
elif
_is_gro_box
(
line
)
and
ln
==
na
+
2
:
elif
_is_gro_box
(
line
)
and
ln
==
na
+
2
:
sline
=
line
.
split
()
sline
=
line
.
split
()
boxes
.
append
(
_construct_box_vectors
(
line
))
boxes
.
append
(
_construct_box_vectors
(
line
))
xyzs
.
append
(
xyz
*
nanometers
)
xyzs
.
append
(
xyz
*
nanometers
)
xyz
=
[]
xyz
=
[]
ln
=
-
1
ln
=
-
1
frame
+=
1
frame
+=
1
else
:
else
:
raise
Exception
(
"Unexpected line in .gro file: "
+
line
)
raise
Exception
(
"Unexpected line in .gro file: "
+
line
)
ln
+=
1
ln
+=
1
## The atom positions read from the file. If the file contains multiple frames, these are the positions in the first frame.
## The atom positions read from the file. If the file contains multiple frames, these are the positions in the first frame.
self
.
positions
=
xyzs
[
0
]
self
.
positions
=
xyzs
[
0
]
...
...
wrappers/python/simtk/openmm/app/pdbxfile.py
View file @
174b57e4
...
@@ -75,7 +75,6 @@ class PDBxFile(object):
...
@@ -75,7 +75,6 @@ class PDBxFile(object):
reader
=
PdbxReader
(
inputFile
)
reader
=
PdbxReader
(
inputFile
)
data
=
[]
data
=
[]
reader
.
read
(
data
)
reader
.
read
(
data
)
inputfile
.
close
()
block
=
data
[
0
]
block
=
data
[
0
]
# Build the topology.
# Build the topology.
...
...
wrappers/python/tests/TestAmberPrmtopFile.py
View file @
174b57e4
...
@@ -293,8 +293,7 @@ class TestAmberPrmtopFile(unittest.TestCase):
...
@@ -293,8 +293,7 @@ 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
)
with
open
(
'systems/alanine-dipeptide-implicit-forces/'
+
file
[
i
]
+
'.xml'
)
as
infile
:
state2
=
XmlSerializer
.
deserialize
(
open
(
'systems/alanine-dipeptide-implicit-forces/'
+
file
[
i
]
+
'.xml'
).
read
())
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 @
174b57e4
...
@@ -67,13 +67,12 @@ class TestPdbFile(unittest.TestCase):
...
@@ -67,13 +67,12 @@ 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."""
with
open
(
'systems/triclinic.pdb'
,
'rb'
)
as
infile
:
pdb
=
PDBFile
(
open
(
'systems/triclinic.pdb'
,
'rb'
))
pdb
=
PDBFile
(
infile
)
self
.
assertEqual
(
len
(
pdb
.
positions
),
8
)
self
.
assertEqual
(
len
(
pdb
.
positions
),
8
)
def
test_ExtraParticles
(
self
):
def
test_ExtraParticles
(
self
):
"""Test reading, and writing and re-reading of a file containing extra particle atoms."""
"""Test reading, and writing and re-reading of a file containing extra particle atoms."""
pdb
=
PDBFile
(
'systems/tip5p.pdb'
)
pdb
=
PDBFile
(
'systems/tip5p.pdb'
)
for
atom
in
pdb
.
topology
.
atoms
():
for
atom
in
pdb
.
topology
.
atoms
():
if
atom
.
index
>
2
:
if
atom
.
index
>
2
:
self
.
assertEqual
(
None
,
atom
.
element
)
self
.
assertEqual
(
None
,
atom
.
element
)
...
...
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