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
b4488289
Commit
b4488289
authored
Jan 27, 2016
by
Jason Swails
Browse files
Add alternate Simulation constructor taking XML files.
parent
bf141989
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
10 deletions
+53
-10
wrappers/python/simtk/openmm/app/simulation.py
wrappers/python/simtk/openmm/app/simulation.py
+53
-10
No files found.
wrappers/python/simtk/openmm/app/simulation.py
View file @
b4488289
...
@@ -36,6 +36,10 @@ import simtk.openmm as mm
...
@@ -36,6 +36,10 @@ import simtk.openmm as mm
import
simtk.unit
as
unit
import
simtk.unit
as
unit
import
sys
import
sys
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
try
:
string_types
=
(
unicode
,
str
)
except
NameError
:
string_types
=
(
str
,)
class
Simulation
(
object
):
class
Simulation
(
object
):
"""Simulation provides a simplified API for running simulations with OpenMM and reporting results.
"""Simulation provides a simplified API for running simulations with OpenMM and reporting results.
...
@@ -52,28 +56,38 @@ class Simulation(object):
...
@@ -52,28 +56,38 @@ class Simulation(object):
simulation.reporters.append(PDBReporter('output.pdb', 1000))
simulation.reporters.append(PDBReporter('output.pdb', 1000))
"""
"""
def
__init__
(
self
,
topology
,
system
,
integrator
,
platform
=
None
,
platformProperties
=
None
):
def
__init__
(
self
,
topology
,
system
,
integrator
,
platform
=
None
,
platformProperties
=
None
,
state
=
None
):
"""Create a Simulation.
"""Create a Simulation.
Parameters
Parameters
----------
----------
topology : Topology
topology : Topology
A Topology describing the the system to simulate
A Topology describing the the system to simulate
system : System
system : System or XML file name
The OpenMM System object to simulate
The OpenMM System object to simulate (or the name of an XML file
integrator : Integrator
with a serialized System)
The OpenMM Integrator to use for simulating the System
integrator : Integrator or XML file name
The OpenMM Integrator to use for simulating the System (or the name
of an XML file with a serialized System)
platform : Platform=None
platform : Platform=None
If not None, the OpenMM Platform to use
If not None, the OpenMM Platform to use
platformProperties : map=None
platformProperties : map=None
If not None, a set of platform-specific properties to pass to the
If not None, a set of platform-specific properties to pass to the
Context's constructor
Context's constructor
state : XML file name
The name of an XML file containing a serialized State
"""
"""
## The Topology describing the system being simulated
self
.
topology
=
topology
## The System being simulated
## The System being simulated
if
isinstance
(
system
,
string_types
):
with
open
(
system
,
'r'
)
as
f
:
self
.
system
=
mm
.
XmlSerializer
.
deserialize
(
f
.
read
())
else
:
self
.
system
=
system
self
.
system
=
system
## The Integrator used to advance the simulation
## The Integrator used to advance the simulation
if
isinstance
(
integrator
,
string_types
):
with
open
(
integrator
,
'r'
)
as
f
:
self
.
integrator
=
mm
.
XmlSerializer
.
deserialize
(
f
.
read
())
else
:
self
.
integrator
=
integrator
self
.
integrator
=
integrator
## The index of the current time step
## The index of the current time step
self
.
currentStep
=
0
self
.
currentStep
=
0
...
@@ -86,6 +100,34 @@ class Simulation(object):
...
@@ -86,6 +100,34 @@ class Simulation(object):
self
.
context
=
mm
.
Context
(
system
,
integrator
,
platform
)
self
.
context
=
mm
.
Context
(
system
,
integrator
,
platform
)
else
:
else
:
self
.
context
=
mm
.
Context
(
system
,
integrator
,
platform
,
platformProperties
)
self
.
context
=
mm
.
Context
(
system
,
integrator
,
platform
,
platformProperties
)
if
state
is
not
None
:
with
open
(
state
,
'r'
)
as
f
:
self
.
context
.
setState
(
mm
.
XmlSerializer
.
deserialize
(
f
.
read
()))
## Determines whether or not we are using PBC. If no Topology is provided, take it from the System
if
topology
is
None
:
self
.
_usesPBC
=
system
.
usesPeriodicBoundaryConditions
()
else
:
self
.
_usesPBC
=
topology
.
getUnitCellDimensions
()
is
not
None
@
classmethod
def
fromXmlFiles
(
cls
,
system
,
integrator
,
state
=
None
,
platform
=
None
,
platformProperties
=
None
):
""" Initialize a Simulation object from a set of XML files
Parameters
----------
system : str (or mm.System)
XML file name containing a serialized OpenMM System object
integrator : str (or mm.Integrator)
XML file name containing a serialized OpenMM Integrator subclass
state : str, optional
XML file name containing a serialized OpenMM State
platform : Platform=None
If not None, the OpenMM Platform to use
platformProperties : map=None
If not None, a set of platform-specific properties to pass to the
Context's constructor
"""
return
cls
(
None
,
system
,
integrator
,
platform
,
platformProperties
,
state
=
state
)
def
minimizeEnergy
(
self
,
tolerance
=
10
*
unit
.
kilojoule
/
unit
.
mole
,
maxIterations
=
0
):
def
minimizeEnergy
(
self
,
tolerance
=
10
*
unit
.
kilojoule
/
unit
.
mole
,
maxIterations
=
0
):
"""Perform a local energy minimization on the system.
"""Perform a local energy minimization on the system.
...
@@ -186,7 +228,8 @@ class Simulation(object):
...
@@ -186,7 +228,8 @@ class Simulation(object):
getForces
=
True
getForces
=
True
if
next
[
4
]:
if
next
[
4
]:
getEnergy
=
True
getEnergy
=
True
state
=
self
.
context
.
getState
(
getPositions
=
getPositions
,
getVelocities
=
getVelocities
,
getForces
=
getForces
,
getEnergy
=
getEnergy
,
getParameters
=
True
,
enforcePeriodicBox
=
(
self
.
topology
.
getUnitCellDimensions
()
is
not
None
))
state
=
self
.
context
.
getState
(
getPositions
=
getPositions
,
getVelocities
=
getVelocities
,
getForces
=
getForces
,
getEnergy
=
getEnergy
,
getParameters
=
True
,
enforcePeriodicBox
=
self
.
_usesPBC
)
for
reporter
,
next
in
zip
(
self
.
reporters
,
nextReport
):
for
reporter
,
next
in
zip
(
self
.
reporters
,
nextReport
):
if
next
[
0
]
==
nextSteps
:
if
next
[
0
]
==
nextSteps
:
reporter
.
report
(
self
,
state
)
reporter
.
report
(
self
,
state
)
...
...
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