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
bff7086a
Commit
bff7086a
authored
May 27, 2020
by
Charlles Abreu
Browse files
Checking out unnecessarily changed files from master
parent
8a41f6df
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
32 deletions
+33
-32
serialization/include/openmm/serialization/TabulatedFunctionProxies.h
...n/include/openmm/serialization/TabulatedFunctionProxies.h
+6
-6
wrappers/python/simtk/openmm/app/__init__.py
wrappers/python/simtk/openmm/app/__init__.py
+1
-0
wrappers/python/simtk/openmm/app/simulatedtempering.py
wrappers/python/simtk/openmm/app/simulatedtempering.py
+26
-26
No files found.
serialization/include/openmm/serialization/TabulatedFunctionProxies.h
View file @
bff7086a
...
@@ -40,7 +40,7 @@ namespace OpenMM {
...
@@ -40,7 +40,7 @@ namespace OpenMM {
/**
/**
* This is a proxy for serializing Continuous1DFunction objects.
* This is a proxy for serializing Continuous1DFunction objects.
*/
*/
class
OPENMM_EXPORT
Continuous1DFunctionProxy
:
public
SerializationProxy
{
class
OPENMM_EXPORT
Continuous1DFunctionProxy
:
public
SerializationProxy
{
public:
public:
Continuous1DFunctionProxy
();
Continuous1DFunctionProxy
();
...
@@ -51,7 +51,7 @@ public:
...
@@ -51,7 +51,7 @@ public:
/**
/**
* This is a proxy for serializing Continuous2DFunction objects.
* This is a proxy for serializing Continuous2DFunction objects.
*/
*/
class
OPENMM_EXPORT
Continuous2DFunctionProxy
:
public
SerializationProxy
{
class
OPENMM_EXPORT
Continuous2DFunctionProxy
:
public
SerializationProxy
{
public:
public:
Continuous2DFunctionProxy
();
Continuous2DFunctionProxy
();
...
@@ -62,7 +62,7 @@ public:
...
@@ -62,7 +62,7 @@ public:
/**
/**
* This is a proxy for serializing Continuous3DFunction objects.
* This is a proxy for serializing Continuous3DFunction objects.
*/
*/
class
OPENMM_EXPORT
Continuous3DFunctionProxy
:
public
SerializationProxy
{
class
OPENMM_EXPORT
Continuous3DFunctionProxy
:
public
SerializationProxy
{
public:
public:
Continuous3DFunctionProxy
();
Continuous3DFunctionProxy
();
...
@@ -73,7 +73,7 @@ public:
...
@@ -73,7 +73,7 @@ public:
/**
/**
* This is a proxy for serializing Discrete1DFunction objects.
* This is a proxy for serializing Discrete1DFunction objects.
*/
*/
class
OPENMM_EXPORT
Discrete1DFunctionProxy
:
public
SerializationProxy
{
class
OPENMM_EXPORT
Discrete1DFunctionProxy
:
public
SerializationProxy
{
public:
public:
Discrete1DFunctionProxy
();
Discrete1DFunctionProxy
();
...
@@ -84,7 +84,7 @@ public:
...
@@ -84,7 +84,7 @@ public:
/**
/**
* This is a proxy for serializing Discrete2DFunction objects.
* This is a proxy for serializing Discrete2DFunction objects.
*/
*/
class
OPENMM_EXPORT
Discrete2DFunctionProxy
:
public
SerializationProxy
{
class
OPENMM_EXPORT
Discrete2DFunctionProxy
:
public
SerializationProxy
{
public:
public:
Discrete2DFunctionProxy
();
Discrete2DFunctionProxy
();
...
@@ -95,7 +95,7 @@ public:
...
@@ -95,7 +95,7 @@ public:
/**
/**
* This is a proxy for serializing Discrete3DFunction objects.
* This is a proxy for serializing Discrete3DFunction objects.
*/
*/
class
OPENMM_EXPORT
Discrete3DFunctionProxy
:
public
SerializationProxy
{
class
OPENMM_EXPORT
Discrete3DFunctionProxy
:
public
SerializationProxy
{
public:
public:
Discrete3DFunctionProxy
();
Discrete3DFunctionProxy
();
...
...
wrappers/python/simtk/openmm/app/__init__.py
View file @
bff7086a
...
@@ -53,3 +53,4 @@ Double = topology.Double
...
@@ -53,3 +53,4 @@ Double = topology.Double
Triple
=
topology
.
Triple
Triple
=
topology
.
Triple
Aromatic
=
topology
.
Aromatic
Aromatic
=
topology
.
Aromatic
Amide
=
topology
.
Amide
Amide
=
topology
.
Amide
wrappers/python/simtk/openmm/app/simulatedtempering.py
View file @
bff7086a
...
@@ -12,7 +12,7 @@ Portions copyright (c) 2015 Stanford University and the Authors.
...
@@ -12,7 +12,7 @@ Portions copyright (c) 2015 Stanford University and the Authors.
Authors: Peter Eastman
Authors: Peter Eastman
Contributors:
Contributors:
Permission is hereby granted, free of charge, to any person obtaining a
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
the rights to use, copy, modify, merge, publish, distribute, sublicense,
...
@@ -55,29 +55,29 @@ except: have_numpy = False
...
@@ -55,29 +55,29 @@ except: have_numpy = False
class
SimulatedTempering
(
object
):
class
SimulatedTempering
(
object
):
"""SimulatedTempering implements the simulated tempering algorithm for accelerated sampling.
"""SimulatedTempering implements the simulated tempering algorithm for accelerated sampling.
It runs a simulation while allowing the temperature to vary. At high temperatures, it can more easily cross
It runs a simulation while allowing the temperature to vary. At high temperatures, it can more easily cross
energy barriers to explore a wider area of conformation space. At low temperatures, it can thoroughly
energy barriers to explore a wider area of conformation space. At low temperatures, it can thoroughly
explore each local region. For details, see Marinari, E. and Parisi, G., Europhys. Lett. 19(6). pp. 451-458 (1992).
explore each local region. For details, see Marinari, E. and Parisi, G., Europhys. Lett. 19(6). pp. 451-458 (1992).
The set of temperatures to sample can be specified in two ways. First, you can explicitly provide a list
The set of temperatures to sample can be specified in two ways. First, you can explicitly provide a list
of temperatures by using the "temperatures" argument. Alternatively, you can specify the minimum and
of temperatures by using the "temperatures" argument. Alternatively, you can specify the minimum and
maximum temperatures, and the total number of temperatures to use. The temperatures are chosen spaced
maximum temperatures, and the total number of temperatures to use. The temperatures are chosen spaced
exponentially between the two extremes. For example,
exponentially between the two extremes. For example,
st = SimulatedTempering(simulation, numTemperatures=15, minTemperature=300*kelvin, maxTemperature=450*kelvin)
st = SimulatedTempering(simulation, numTemperatures=15, minTemperature=300*kelvin, maxTemperature=450*kelvin)
After creating the SimulatedTempering object, call step() on it to run the simulation.
After creating the SimulatedTempering object, call step() on it to run the simulation.
Transitions between temperatures are performed at regular intervals, as specified by the "tempChangeInterval"
Transitions between temperatures are performed at regular intervals, as specified by the "tempChangeInterval"
argument. For each transition, a new temperature is selected using the independence sampling method, as
argument. For each transition, a new temperature is selected using the independence sampling method, as
described in Chodera, J. and Shirts, M., J. Chem. Phys. 135, 194110 (2011).
described in Chodera, J. and Shirts, M., J. Chem. Phys. 135, 194110 (2011).
Simulated tempering requires a "weight factor" for each temperature. Ideally, these should be chosen so
Simulated tempering requires a "weight factor" for each temperature. Ideally, these should be chosen so
the simulation spends equal time at every temperature. You can specify the list of weights to use with the
the simulation spends equal time at every temperature. You can specify the list of weights to use with the
optional "weights" argument. If this is omitted, weights are selected automatically using the Wang-Landau
optional "weights" argument. If this is omitted, weights are selected automatically using the Wang-Landau
algorithm as described in Wang, F. and Landau, D. P., Phys. Rev. Lett. 86(10), pp. 2050-2053 (2001).
algorithm as described in Wang, F. and Landau, D. P., Phys. Rev. Lett. 86(10), pp. 2050-2053 (2001).
To properly analyze the results of the simulation, it is important to know the temperature and weight factors
To properly analyze the results of the simulation, it is important to know the temperature and weight factors
at every point in time. The SimulatedTempering object functions as a reporter, writing this information
at every point in time. The SimulatedTempering object functions as a reporter, writing this information
to a file or stdout at regular intervals (which should match the interval at which you save frames from the
to a file or stdout at regular intervals (which should match the interval at which you save frames from the
...
@@ -87,7 +87,7 @@ class SimulatedTempering(object):
...
@@ -87,7 +87,7 @@ class SimulatedTempering(object):
def
__init__
(
self
,
simulation
,
temperatures
=
None
,
numTemperatures
=
None
,
minTemperature
=
None
,
maxTemperature
=
None
,
weights
=
None
,
tempChangeInterval
=
25
,
reportInterval
=
1000
,
reportFile
=
stdout
):
def
__init__
(
self
,
simulation
,
temperatures
=
None
,
numTemperatures
=
None
,
minTemperature
=
None
,
maxTemperature
=
None
,
weights
=
None
,
tempChangeInterval
=
25
,
reportInterval
=
1000
,
reportFile
=
stdout
):
"""Create a new SimulatedTempering.
"""Create a new SimulatedTempering.
Parameters
Parameters
----------
----------
simulation: Simulation
simulation: Simulation
...
@@ -108,7 +108,7 @@ class SimulatedTempering(object):
...
@@ -108,7 +108,7 @@ class SimulatedTempering(object):
The interval (in time steps) at which to write information to the report file
The interval (in time steps) at which to write information to the report file
reportFile: string or file
reportFile: string or file
The file to write reporting information to, specified as a file name or file object
The file to write reporting information to, specified as a file name or file object
"""
"""
self
.
simulation
=
simulation
self
.
simulation
=
simulation
if
temperatures
is
None
:
if
temperatures
is
None
:
if
unit
.
is_quantity
(
minTemperature
):
if
unit
.
is_quantity
(
minTemperature
):
...
@@ -143,9 +143,9 @@ class SimulatedTempering(object):
...
@@ -143,9 +143,9 @@ class SimulatedTempering(object):
self
.
_out
=
open
(
reportFile
,
'w'
,
1
)
self
.
_out
=
open
(
reportFile
,
'w'
,
1
)
else
:
else
:
self
.
_out
=
reportFile
self
.
_out
=
reportFile
# Initialize the weights.
# Initialize the weights.
if
weights
is
None
:
if
weights
is
None
:
self
.
_weights
=
[
0.0
]
*
numTemperatures
self
.
_weights
=
[
0.0
]
*
numTemperatures
self
.
_updateWeights
=
True
self
.
_updateWeights
=
True
...
@@ -157,12 +157,12 @@ class SimulatedTempering(object):
...
@@ -157,12 +157,12 @@ class SimulatedTempering(object):
self
.
_updateWeights
=
False
self
.
_updateWeights
=
False
# Select the initial temperature.
# Select the initial temperature.
self
.
currentTemperature
=
0
self
.
currentTemperature
=
0
self
.
simulation
.
integrator
.
setTemperature
(
self
.
temperatures
[
self
.
currentTemperature
])
self
.
simulation
.
integrator
.
setTemperature
(
self
.
temperatures
[
self
.
currentTemperature
])
# Add a reporter to the simulation which will handle the updates and reports.
# Add a reporter to the simulation which will handle the updates and reports.
class
STReporter
(
object
):
class
STReporter
(
object
):
def
__init__
(
self
,
st
):
def
__init__
(
self
,
st
):
self
.
st
=
st
self
.
st
=
st
...
@@ -181,11 +181,11 @@ class SimulatedTempering(object):
...
@@ -181,11 +181,11 @@ class SimulatedTempering(object):
st
.
_attemptTemperatureChange
(
state
)
st
.
_attemptTemperatureChange
(
state
)
if
simulation
.
currentStep
%
st
.
reportInterval
==
0
:
if
simulation
.
currentStep
%
st
.
reportInterval
==
0
:
st
.
_writeReport
()
st
.
_writeReport
()
simulation
.
reporters
.
append
(
STReporter
(
self
))
simulation
.
reporters
.
append
(
STReporter
(
self
))
# Write out the header line.
# Write out the header line.
headers
=
[
'Steps'
,
'Temperature (K)'
]
headers
=
[
'Steps'
,
'Temperature (K)'
]
for
t
in
self
.
temperatures
:
for
t
in
self
.
temperatures
:
headers
.
append
(
'%gK Weight'
%
t
.
value_in_unit
(
unit
.
kelvin
))
headers
.
append
(
'%gK Weight'
%
t
.
value_in_unit
(
unit
.
kelvin
))
...
@@ -194,7 +194,7 @@ class SimulatedTempering(object):
...
@@ -194,7 +194,7 @@ class SimulatedTempering(object):
def
__del__
(
self
):
def
__del__
(
self
):
if
self
.
_openedFile
:
if
self
.
_openedFile
:
self
.
_out
.
close
()
self
.
_out
.
close
()
@
property
@
property
def
weights
(
self
):
def
weights
(
self
):
return
[
x
-
self
.
_weights
[
0
]
for
x
in
self
.
_weights
]
return
[
x
-
self
.
_weights
[
0
]
for
x
in
self
.
_weights
]
...
@@ -202,10 +202,10 @@ class SimulatedTempering(object):
...
@@ -202,10 +202,10 @@ class SimulatedTempering(object):
def
step
(
self
,
steps
):
def
step
(
self
,
steps
):
"""Advance the simulation by integrating a specified number of time steps."""
"""Advance the simulation by integrating a specified number of time steps."""
self
.
simulation
.
step
(
steps
)
self
.
simulation
.
step
(
steps
)
def
_attemptTemperatureChange
(
self
,
state
):
def
_attemptTemperatureChange
(
self
,
state
):
"""Attempt to move to a different temperature."""
"""Attempt to move to a different temperature."""
# Compute the probability for each temperature. This is done in log space to avoid overflow.
# Compute the probability for each temperature. This is done in log space to avoid overflow.
logProbability
=
[(
self
.
_weights
[
i
]
-
self
.
inverseTemperatures
[
i
]
*
state
.
getPotentialEnergy
())
for
i
in
range
(
len
(
self
.
_weights
))]
logProbability
=
[(
self
.
_weights
[
i
]
-
self
.
inverseTemperatures
[
i
]
*
state
.
getPotentialEnergy
())
for
i
in
range
(
len
(
self
.
_weights
))]
...
@@ -217,7 +217,7 @@ class SimulatedTempering(object):
...
@@ -217,7 +217,7 @@ class SimulatedTempering(object):
if
r
<
probability
[
j
]:
if
r
<
probability
[
j
]:
if
j
!=
self
.
currentTemperature
:
if
j
!=
self
.
currentTemperature
:
# Rescale the velocities.
# Rescale the velocities.
scale
=
math
.
sqrt
(
self
.
temperatures
[
j
]
/
self
.
temperatures
[
self
.
currentTemperature
])
scale
=
math
.
sqrt
(
self
.
temperatures
[
j
]
/
self
.
temperatures
[
self
.
currentTemperature
])
if
have_numpy
:
if
have_numpy
:
velocities
=
scale
*
state
.
getVelocities
(
asNumpy
=
True
).
value_in_unit
(
unit
.
nanometers
/
unit
.
picoseconds
)
velocities
=
scale
*
state
.
getVelocities
(
asNumpy
=
True
).
value_in_unit
(
unit
.
nanometers
/
unit
.
picoseconds
)
...
@@ -226,26 +226,26 @@ class SimulatedTempering(object):
...
@@ -226,26 +226,26 @@ class SimulatedTempering(object):
self
.
simulation
.
context
.
setVelocities
(
velocities
)
self
.
simulation
.
context
.
setVelocities
(
velocities
)
# Select this temperature.
# Select this temperature.
self
.
_hasMadeTransition
=
True
self
.
_hasMadeTransition
=
True
self
.
currentTemperature
=
j
self
.
currentTemperature
=
j
self
.
simulation
.
integrator
.
setTemperature
(
self
.
temperatures
[
j
])
self
.
simulation
.
integrator
.
setTemperature
(
self
.
temperatures
[
j
])
if
self
.
_updateWeights
:
if
self
.
_updateWeights
:
# Update the weight factors.
# Update the weight factors.
self
.
_weights
[
j
]
-=
self
.
_weightUpdateFactor
self
.
_weights
[
j
]
-=
self
.
_weightUpdateFactor
self
.
_histogram
[
j
]
+=
1
self
.
_histogram
[
j
]
+=
1
minCounts
=
min
(
self
.
_histogram
)
minCounts
=
min
(
self
.
_histogram
)
if
minCounts
>
20
and
minCounts
>=
0.2
*
sum
(
self
.
_histogram
)
/
len
(
self
.
_histogram
):
if
minCounts
>
20
and
minCounts
>=
0.2
*
sum
(
self
.
_histogram
)
/
len
(
self
.
_histogram
):
# Reduce the weight update factor and reset the histogram.
# Reduce the weight update factor and reset the histogram.
self
.
_weightUpdateFactor
*=
0.5
self
.
_weightUpdateFactor
*=
0.5
self
.
_histogram
=
[
0
]
*
len
(
self
.
temperatures
)
self
.
_histogram
=
[
0
]
*
len
(
self
.
temperatures
)
self
.
_weights
=
[
x
-
self
.
_weights
[
0
]
for
x
in
self
.
_weights
]
self
.
_weights
=
[
x
-
self
.
_weights
[
0
]
for
x
in
self
.
_weights
]
elif
not
self
.
_hasMadeTransition
and
probability
[
self
.
currentTemperature
]
>
0.99
:
elif
not
self
.
_hasMadeTransition
and
probability
[
self
.
currentTemperature
]
>
0.99
:
# Rapidly increase the weight update factor at the start of the simulation to find
# Rapidly increase the weight update factor at the start of the simulation to find
# a reasonable starting value.
# a reasonable starting value.
self
.
_weightUpdateFactor
*=
2.0
self
.
_weightUpdateFactor
*=
2.0
self
.
_histogram
=
[
0
]
*
len
(
self
.
temperatures
)
self
.
_histogram
=
[
0
]
*
len
(
self
.
temperatures
)
return
return
...
...
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