Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pdbfixer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pdbfixer
Commits
509dcb40
Commit
509dcb40
authored
Mar 28, 2014
by
Grinaway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added watchdog class from stackoverflow
parent
cbe0efa1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
13 deletions
+36
-13
tests/test_build_and_simulate.py
+36
-13
No files found.
tests/test_build_and_simulate.py
View file @
509dcb40
...
@@ -7,6 +7,32 @@ import os
...
@@ -7,6 +7,32 @@ import os
import
sys
import
sys
import
numpy
import
numpy
from
threading
import
Timer
#from a solution on stackoverflow
class
Watchdog
:
def
__init__
(
self
,
timeout
,
userHandler
=
None
):
# timeout in seconds
self
.
timeout
=
timeout
self
.
handler
=
userHandler
if
userHandler
is
not
None
else
self
.
defaultHandler
self
.
timer
=
Timer
(
self
.
timeout
,
self
.
handler
)
def
reset
(
self
):
self
.
timer
.
cancel
()
self
.
timer
=
Timer
(
self
.
timeout
,
self
.
handler
)
def
stop
(
self
):
self
.
timer
.
cancel
()
def
defaultHandler
(
self
):
raise
self
def
simulate
(
pdbcode
,
pdb_filename
):
def
simulate
(
pdbcode
,
pdb_filename
):
from
simtk.openmm
import
app
from
simtk.openmm
import
app
import
simtk.openmm
as
mm
import
simtk.openmm
as
mm
...
@@ -98,9 +124,10 @@ def test_build_and_simulate():
...
@@ -98,9 +124,10 @@ def test_build_and_simulate():
infile
=
open
(
input_pdb_filename
)
infile
=
open
(
input_pdb_filename
)
outfile
=
open
(
output_pdb_filename
,
'w'
)
outfile
=
open
(
output_pdb_filename
,
'w'
)
from
eventlet.timeout
import
Timeout
timeout_seconds
=
30.0
timeout_seconds
=
30.0
with
Timeout
(
timeout_seconds
)
as
timeout
:
watchdog
=
Watchdog
(
timeout_seconds
)
try
:
from
pdbfixer.pdbfixer
import
PDBFixer
,
PdbStructure
from
pdbfixer.pdbfixer
import
PDBFixer
,
PdbStructure
from
simtk.openmm
import
app
from
simtk.openmm
import
app
stage
=
"Creating PDBFixer..."
stage
=
"Creating PDBFixer..."
...
@@ -124,24 +151,20 @@ def test_build_and_simulate():
...
@@ -124,24 +151,20 @@ def test_build_and_simulate():
stage
=
"Done."
stage
=
"Done."
infile
.
close
()
infile
.
close
()
outfile
.
close
()
outfile
.
close
()
except
Watchdog
:
print
"timed out fixing PDB
%
s"
%
pdbcode
# Test simulating this with OpenMM.
# Test simulating this with OpenMM.
watchdog
.
stop
()
del
watchdog
if
pdbcode
in
pdbcodes_to_simulate
:
if
pdbcode
in
pdbcodes_to_simulate
:
timeout_seconds
=
30.0
watchdog
=
Watchdog
(
timeout_seconds
)
timeout
=
Timeout
(
timeout_seconds
)
try
:
try
:
simulate
(
pdbcode
,
output_pdb_filename
)
simulate
(
pdbcode
,
output_pdb_filename
)
except
Timeout
as
e
:
except
Watchdog
:
print
str
(
e
)
timeout
.
cancel
()
print
"PDB code
%
s timed out in stage '
%
s'."
%
(
pdbcode
,
stage
)
print
"PDB code
%
s timed out in stage '
%
s'."
%
(
pdbcode
,
stage
)
except
Exception
as
e
:
print
str
(
e
)
timeout
.
cancel
()
success
=
False
success
=
False
watchdog
.
stop
()
# Clean up.
# Clean up.
os
.
remove
(
input_pdb_filename
)
os
.
remove
(
input_pdb_filename
)
os
.
remove
(
output_pdb_filename
)
os
.
remove
(
output_pdb_filename
)
...
...
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