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
61293829
"ssh:/git@developer.sourcefind.cn:2222/tsoc/openmm.git" did not exist on "a28c8cf6c4d58483f5ec637f7dec0a6ffd832a1d"
Commit
61293829
authored
Nov 09, 2016
by
peastman
Browse files
Fixed error writing a DCD file for a very long trajectory
parent
31c883b3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
1 deletion
+23
-1
wrappers/python/simtk/openmm/app/dcdfile.py
wrappers/python/simtk/openmm/app/dcdfile.py
+12
-1
wrappers/python/tests/TestDcdFile.py
wrappers/python/tests/TestDcdFile.py
+11
-0
No files found.
wrappers/python/simtk/openmm/app/dcdfile.py
View file @
61293829
...
@@ -77,6 +77,7 @@ class DCDFile(object):
...
@@ -77,6 +77,7 @@ class DCDFile(object):
if
is_quantity
(
dt
):
if
is_quantity
(
dt
):
dt
=
dt
.
value_in_unit
(
picoseconds
)
dt
=
dt
.
value_in_unit
(
picoseconds
)
dt
/=
0.04888821
dt
/=
0.04888821
self
.
_dt
=
dt
boxFlag
=
0
boxFlag
=
0
if
topology
.
getUnitCellDimensions
()
is
not
None
:
if
topology
.
getUnitCellDimensions
()
is
not
None
:
boxFlag
=
1
boxFlag
=
1
...
@@ -116,9 +117,19 @@ class DCDFile(object):
...
@@ -116,9 +117,19 @@ class DCDFile(object):
raise
ValueError
(
'Particle position is infinite'
)
raise
ValueError
(
'Particle position is infinite'
)
file
=
self
.
_file
file
=
self
.
_file
self
.
_modelCount
+=
1
if
self
.
_interval
>
1
and
self
.
_firstStep
+
self
.
_modelCount
*
self
.
_interval
>
1
<<
31
:
# This will exceed the range of a 32 bit integer. To avoid crashing or producing a corrupt file,
# update the header to say the trajectory consisted of a smaller number of larger steps (so the
# total trajectory length remains correct).
self
.
_firstStep
//=
self
.
_interval
self
.
_dt
*=
self
.
_interval
self
.
_interval
=
1
file
.
seek
(
0
,
os
.
SEEK_SET
)
file
.
write
(
struct
.
pack
(
'<i4c9if'
,
84
,
b
'C'
,
b
'O'
,
b
'R'
,
b
'D'
,
0
,
self
.
_firstStep
,
self
.
_interval
,
0
,
0
,
0
,
0
,
0
,
0
,
self
.
_dt
))
# Update the header.
# Update the header.
self
.
_modelCount
+=
1
file
.
seek
(
8
,
os
.
SEEK_SET
)
file
.
seek
(
8
,
os
.
SEEK_SET
)
file
.
write
(
struct
.
pack
(
'<i'
,
self
.
_modelCount
))
file
.
write
(
struct
.
pack
(
'<i'
,
self
.
_modelCount
))
file
.
seek
(
20
,
os
.
SEEK_SET
)
file
.
seek
(
20
,
os
.
SEEK_SET
)
...
...
wrappers/python/tests/TestDcdFile.py
View file @
61293829
...
@@ -17,6 +17,17 @@ class TestDCDFile(unittest.TestCase):
...
@@ -17,6 +17,17 @@ class TestDCDFile(unittest.TestCase):
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
)
os
.
remove
(
fname
)
os
.
remove
(
fname
)
def
testLongTrajectory
(
self
):
"""Test writing a trajectory that has more than 2^31 steps."""
fname
=
tempfile
.
mktemp
(
suffix
=
'.dcd'
)
pdbfile
=
app
.
PDBFile
(
'systems/alanine-dipeptide-implicit.pdb'
)
natom
=
len
(
list
(
pdbfile
.
topology
.
atoms
()))
with
open
(
fname
,
'wb'
)
as
f
:
dcd
=
app
.
DCDFile
(
f
,
pdbfile
.
topology
,
0.001
,
interval
=
1000000000
)
for
i
in
range
(
5
):
dcd
.
writeModel
([
mm
.
Vec3
(
random
(),
random
(),
random
())
for
j
in
range
(
natom
)]
*
unit
.
angstroms
)
os
.
remove
(
fname
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
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