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
0305b4b7
Commit
0305b4b7
authored
Dec 05, 2016
by
peastman
Committed by
GitHub
Dec 05, 2016
Browse files
Merge pull request #1684 from peastman/checkpoint
CheckpointReporter does not create output file until first report
parents
bb2d463c
c232858c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
16 deletions
+25
-16
wrappers/python/simtk/openmm/app/checkpointreporter.py
wrappers/python/simtk/openmm/app/checkpointreporter.py
+25
-16
No files found.
wrappers/python/simtk/openmm/app/checkpointreporter.py
View file @
0305b4b7
...
@@ -6,7 +6,7 @@ Simbios, the NIH National Center for Physics-Based Simulation of
...
@@ -6,7 +6,7 @@ Simbios, the NIH National Center for Physics-Based Simulation of
Biological Structures at Stanford, funded under the NIH Roadmap for
Biological Structures at Stanford, funded under the NIH Roadmap for
Medical Research, grant U54 GM072970. See https://simtk.org.
Medical Research, grant U54 GM072970. See https://simtk.org.
Portions copyright (c) 2014 Stanford University and the Authors.
Portions copyright (c) 2014
-2016
Stanford University and the Authors.
Authors: Robert McGibbon
Authors: Robert McGibbon
Contributors:
Contributors:
...
@@ -33,6 +33,9 @@ __author__ = "Robert McGibbon"
...
@@ -33,6 +33,9 @@ __author__ = "Robert McGibbon"
__version__
=
"1.0"
__version__
=
"1.0"
import
simtk.openmm
as
mm
import
simtk.openmm
as
mm
import
os
import
os.path
__all__
=
[
'CheckpointReporter'
]
__all__
=
[
'CheckpointReporter'
]
...
@@ -80,12 +83,7 @@ class CheckpointReporter(object):
...
@@ -80,12 +83,7 @@ class CheckpointReporter(object):
"""
"""
self
.
_reportInterval
=
reportInterval
self
.
_reportInterval
=
reportInterval
if
isinstance
(
file
,
str
):
self
.
_file
=
file
self
.
_own_handle
=
True
self
.
_out
=
open
(
file
,
'w+b'
,
0
)
else
:
self
.
_out
=
file
self
.
_own_handle
=
False
def
describeNextReport
(
self
,
simulation
):
def
describeNextReport
(
self
,
simulation
):
"""Get information about the next report this object will generate.
"""Get information about the next report this object will generate.
...
@@ -116,13 +114,24 @@ class CheckpointReporter(object):
...
@@ -116,13 +114,24 @@ class CheckpointReporter(object):
state : State
state : State
The current state of the simulation
The current state of the simulation
"""
"""
self
.
_out
.
seek
(
0
)
if
isinstance
(
self
.
_file
,
str
):
chk
=
simulation
.
context
.
createCheckpoint
()
# Do a safe save.
self
.
_out
.
write
(
chk
)
self
.
_out
.
truncate
()
tempFilename1
=
self
.
_file
+
".backup1"
self
.
_out
.
flush
()
tempFilename2
=
self
.
_file
+
".backup2"
with
open
(
tempFilename1
,
'w+b'
,
0
)
as
out
:
def
__del__
(
self
):
out
.
write
(
simulation
.
context
.
createCheckpoint
())
if
self
.
_own_handle
:
exists
=
os
.
path
.
exists
(
self
.
_file
)
self
.
_out
.
close
()
if
exists
:
os
.
rename
(
self
.
_file
,
tempFilename2
)
os
.
rename
(
tempFilename1
,
self
.
_file
)
if
exists
:
os
.
remove
(
tempFilename2
)
else
:
# Replace the contents of the file.
self
.
_file
.
seek
(
0
)
chk
=
simulation
.
context
.
createCheckpoint
()
self
.
_file
.
write
(
chk
)
self
.
_file
.
truncate
()
self
.
_file
.
flush
()
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