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
e3b25204
Commit
e3b25204
authored
Jul 15, 2013
by
leeping
Browse files
Merge github.com:leeping/openmm
parents
41e9a095
74415dd9
Changes
295
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
638 additions
and
320 deletions
+638
-320
CMakeLists.txt
CMakeLists.txt
+16
-0
cmake_modules/FindFFTW.cmake
cmake_modules/FindFFTW.cmake
+25
-0
libraries/lepton/src/Parser.cpp
libraries/lepton/src/Parser.cpp
+2
-2
olla/include/openmm/kernels.h
olla/include/openmm/kernels.h
+64
-0
openmmapi/include/OpenMM.h
openmmapi/include/OpenMM.h
+1
-0
openmmapi/include/openmm/GBSAOBCForce.h
openmmapi/include/openmm/GBSAOBCForce.h
+8
-2
openmmapi/include/openmm/MonteCarloAnisotropicBarostat.h
openmmapi/include/openmm/MonteCarloAnisotropicBarostat.h
+176
-0
openmmapi/include/openmm/MonteCarloBarostat.h
openmmapi/include/openmm/MonteCarloBarostat.h
+1
-170
openmmapi/include/openmm/internal/AssertionUtilities.h
openmmapi/include/openmm/internal/AssertionUtilities.h
+3
-1
openmmapi/include/openmm/internal/MonteCarloAnisotropicBarostatImpl.h
...clude/openmm/internal/MonteCarloAnisotropicBarostatImpl.h
+71
-0
openmmapi/include/openmm/internal/MonteCarloBarostatImpl.h
openmmapi/include/openmm/internal/MonteCarloBarostatImpl.h
+0
-22
openmmapi/src/Context.cpp
openmmapi/src/Context.cpp
+1
-1
openmmapi/src/MonteCarloAnisotropicBarostat.cpp
openmmapi/src/MonteCarloAnisotropicBarostat.cpp
+45
-0
openmmapi/src/MonteCarloAnisotropicBarostatImpl.cpp
openmmapi/src/MonteCarloAnisotropicBarostatImpl.cpp
+154
-0
openmmapi/src/MonteCarloBarostat.cpp
openmmapi/src/MonteCarloBarostat.cpp
+0
-9
openmmapi/src/MonteCarloBarostatImpl.cpp
openmmapi/src/MonteCarloBarostatImpl.cpp
+6
-111
platforms/cuda/CMakeLists.txt
platforms/cuda/CMakeLists.txt
+5
-1
platforms/cuda/include/CudaArray.h
platforms/cuda/include/CudaArray.h
+0
-0
platforms/cuda/include/CudaBondedUtilities.h
platforms/cuda/include/CudaBondedUtilities.h
+0
-0
platforms/cuda/include/CudaContext.h
platforms/cuda/include/CudaContext.h
+60
-1
No files found.
CMakeLists.txt
View file @
e3b25204
...
@@ -396,6 +396,20 @@ IF(OPENMM_BUILD_DRUDE_PLUGIN)
...
@@ -396,6 +396,20 @@ IF(OPENMM_BUILD_DRUDE_PLUGIN)
ADD_SUBDIRECTORY
(
plugins/drude
)
ADD_SUBDIRECTORY
(
plugins/drude
)
ENDIF
(
OPENMM_BUILD_DRUDE_PLUGIN
)
ENDIF
(
OPENMM_BUILD_DRUDE_PLUGIN
)
# CPU PME plugin
FIND_PACKAGE
(
FFTW QUIET
)
IF
(
FFTW_FOUND
)
SET
(
OPENMM_BUILD_PME_PLUGIN ON CACHE BOOL
"Build CPU PME plugin"
)
ELSE
(
FFTW_FOUND
)
SET
(
OPENMM_BUILD_PME_PLUGIN OFF CACHE BOOL
"Build CPU PME plugin"
)
ENDIF
(
FFTW_FOUND
)
SET
(
OPENMM_BUILD_PME_PATH
)
IF
(
OPENMM_BUILD_PME_PLUGIN
)
SET
(
OPENMM_BUILD_PME_PATH
${
CMAKE_CURRENT_SOURCE_DIR
}
/plugins/cpupme
)
ADD_SUBDIRECTORY
(
plugins/cpupme
)
ENDIF
(
OPENMM_BUILD_PME_PLUGIN
)
INSTALL_TARGETS
(
/lib RUNTIME_DIRECTORY /lib
${
SHARED_TARGET
}
)
INSTALL_TARGETS
(
/lib RUNTIME_DIRECTORY /lib
${
SHARED_TARGET
}
)
IF
(
OPENMM_BUILD_STATIC_LIB
)
IF
(
OPENMM_BUILD_STATIC_LIB
)
INSTALL_TARGETS
(
/lib RUNTIME_DIRECTORY /lib
${
STATIC_TARGET
}
)
INSTALL_TARGETS
(
/lib RUNTIME_DIRECTORY /lib
${
STATIC_TARGET
}
)
...
@@ -403,9 +417,11 @@ ENDIF(OPENMM_BUILD_STATIC_LIB)
...
@@ -403,9 +417,11 @@ ENDIF(OPENMM_BUILD_STATIC_LIB)
FILE
(
GLOB CORE_HEADERS include/*.h */include/*.h
)
FILE
(
GLOB CORE_HEADERS include/*.h */include/*.h
)
FILE
(
GLOB TOP_HEADERS include/openmm/*.h */include/openmm/*.h
)
FILE
(
GLOB TOP_HEADERS include/openmm/*.h */include/openmm/*.h
)
FILE
(
GLOB INTERNAL_HEADERS include/openmm/internal/*.h */include/openmm/internal/*.h
)
FILE
(
GLOB INTERNAL_HEADERS include/openmm/internal/*.h */include/openmm/internal/*.h
)
FILE
(
GLOB REFERENCE_HEADERS platforms/reference/include/*.h
)
INSTALL_FILES
(
/include FILES
${
CORE_HEADERS
}
)
INSTALL_FILES
(
/include FILES
${
CORE_HEADERS
}
)
INSTALL_FILES
(
/include/openmm FILES
${
TOP_HEADERS
}
)
INSTALL_FILES
(
/include/openmm FILES
${
TOP_HEADERS
}
)
INSTALL_FILES
(
/include/openmm/internal FILES
${
INTERNAL_HEADERS
}
)
INSTALL_FILES
(
/include/openmm/internal FILES
${
INTERNAL_HEADERS
}
)
INSTALL_FILES
(
/include/openmm/reference FILES
${
REFERENCE_HEADERS
}
)
# Serialization support
# Serialization support
...
...
cmake_modules/FindFFTW.cmake
0 → 100644
View file @
e3b25204
# - Find FFTW
# Find the native FFTW includes and library
#
# FFTW_INCLUDES - where to find fftw3.h
# FFTW_LIBRARY - the main FFTW library.
# FFTW_THREADS_LIBRARY - the FFTW multithreading support library.
# FFTW_FOUND - True if FFTW found.
if
(
FFTW_INCLUDES
)
# Already in cache, be silent
set
(
FFTW_FIND_QUIETLY TRUE
)
endif
(
FFTW_INCLUDES
)
find_path
(
FFTW_INCLUDES fftw3.h
)
find_library
(
FFTW_LIBRARY NAMES fftw3f
)
find_library
(
FFTW_THREADS_LIBRARY NAMES fftw3f_threads
)
# handle the QUIETLY and REQUIRED arguments and set FFTW_FOUND to TRUE if
# all listed variables are TRUE
include
(
FindPackageHandleStandardArgs
)
find_package_handle_standard_args
(
FFTW DEFAULT_MSG FFTW_LIBRARY FFTW_INCLUDES
)
find_package_handle_standard_args
(
FFTW_THREADS DEFAULT_MSG FFTW_THREADS_LIBRARY FFTW_INCLUDES
)
mark_as_advanced
(
FFTW_LIBRARY FFTW_THREADS_LIBRARY FFTW_INCLUDES
)
libraries/lepton/src/Parser.cpp
View file @
e3b25204
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* 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) 2009-201
1
Stanford University and the Authors. *
* Portions copyright (c) 2009-201
3
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -112,7 +112,7 @@ ParseToken Parser::getNextToken(const string& expression, int start) {
...
@@ -112,7 +112,7 @@ ParseToken Parser::getNextToken(const string& expression, int start) {
}
}
if
((
c
==
'e'
||
c
==
'E'
)
&&
!
foundExp
)
{
if
((
c
==
'e'
||
c
==
'E'
)
&&
!
foundExp
)
{
foundExp
=
true
;
foundExp
=
true
;
if
(
pos
<
(
int
)
expression
.
size
()
-
1
&&
expression
[
pos
+
1
]
==
'-'
)
if
(
pos
<
(
int
)
expression
.
size
()
-
1
&&
(
expression
[
pos
+
1
]
==
'-'
||
expression
[
pos
+
1
]
==
'+'
)
)
pos
++
;
pos
++
;
continue
;
continue
;
}
}
...
...
olla/include/openmm/kernels.h
View file @
e3b25204
...
@@ -1155,6 +1155,70 @@ public:
...
@@ -1155,6 +1155,70 @@ public:
virtual
void
execute
(
ContextImpl
&
context
)
=
0
;
virtual
void
execute
(
ContextImpl
&
context
)
=
0
;
};
};
/**
* This kernel performs the reciprocal space calculation for PME. In most cases, this
* calculation is done directly by CalcNonbondedForceKernel so this kernel is unneeded.
* In some cases it may want to outsource the work to a different kernel. In particular,
* GPU based platforms sometimes use a CPU based implementation provided by a separate
* plugin.
*/
class
CalcPmeReciprocalForceKernel
:
public
KernelImpl
{
public:
class
IO
;
static
std
::
string
Name
()
{
return
"CalcPmeReciprocalForce"
;
}
CalcPmeReciprocalForceKernel
(
std
::
string
name
,
const
Platform
&
platform
)
:
KernelImpl
(
name
,
platform
)
{
}
/**
* Initialize the kernel.
*
* @param gridx the x size of the PME grid
* @param gridy the y size of the PME grid
* @param gridz the z size of the PME grid
* @param numParticles the number of particles in the system
* @param alpha the Ewald blending parameter
*/
virtual
void
initialize
(
int
gridx
,
int
gridy
,
int
gridz
,
int
numParticles
,
double
alpha
)
=
0
;
/**
* Begin computing the force and energy.
*
* @param io an object that coordinates data transfer
* @param periodicBoxSize the size of the periodic box (measured in nm)
* @param includeEnergy true if potential energy should be computed
*/
virtual
void
beginComputation
(
IO
&
io
,
Vec3
periodicBoxSize
,
bool
includeEnergy
)
=
0
;
/**
* Finish computing the force and energy.
*
* @param io an object that coordinates data transfer
* @return the potential energy due to the PME reciprocal space interactions
*/
virtual
double
finishComputation
(
IO
&
io
)
=
0
;
};
/**
* Any class that uses CalcPmeReciprocalForceKernel should create an implementation of this
* class, then pass it to the kernel to manage communication with it.
*/
class
CalcPmeReciprocalForceKernel
::
IO
{
public:
/**
* Get a pointer to the atom charges and positions. This array should contain four
* elements for each atom: x, y, z, and q in that order.
*/
virtual
float
*
getPosq
()
=
0
;
/**
* Record the forces calculated by the kernel.
*
* @param force an array containing four elements for each atom. The first three
* are the x, y, and z components of the force, while the fourth element
* should be ignored.
*/
virtual
void
setForce
(
float
*
force
)
=
0
;
};
}
// namespace OpenMM
}
// namespace OpenMM
#endif
/*OPENMM_KERNELS_H_*/
#endif
/*OPENMM_KERNELS_H_*/
openmmapi/include/OpenMM.h
View file @
e3b25204
...
@@ -53,6 +53,7 @@
...
@@ -53,6 +53,7 @@
#include "openmm/Integrator.h"
#include "openmm/Integrator.h"
#include "openmm/LangevinIntegrator.h"
#include "openmm/LangevinIntegrator.h"
#include "openmm/LocalEnergyMinimizer.h"
#include "openmm/LocalEnergyMinimizer.h"
#include "openmm/MonteCarloAnisotropicBarostat.h"
#include "openmm/MonteCarloBarostat.h"
#include "openmm/MonteCarloBarostat.h"
#include "openmm/NonbondedForce.h"
#include "openmm/NonbondedForce.h"
#include "openmm/Context.h"
#include "openmm/Context.h"
...
...
openmmapi/include/openmm/GBSAOBCForce.h
View file @
e3b25204
...
@@ -40,13 +40,19 @@ namespace OpenMM {
...
@@ -40,13 +40,19 @@ namespace OpenMM {
/**
/**
* This class implements an implicit solvation force using the GBSA-OBC model.
* This class implements an implicit solvation force using the GBSA-OBC model.
*
<p>
*
* To use this class, create a GBSAOBCForce object, then call addParticle() once for each particle in the
* To use this class, create a GBSAOBCForce object, then call addParticle() once for each particle in the
* System to define its parameters. The number of particles for which you define GBSA parameters must
* System to define its parameters. The number of particles for which you define GBSA parameters must
* be exactly equal to the number of particles in the System, or else an exception will be thrown when you
* be exactly equal to the number of particles in the System, or else an exception will be thrown when you
* try to create a Context. After a particle has been added, you can modify its force field parameters
* try to create a Context. After a particle has been added, you can modify its force field parameters
* by calling setParticleParameters(). This will have no effect on Contexts that already exist unless you
* by calling setParticleParameters(). This will have no effect on Contexts that already exist unless you
* call updateParametersInContext().
* call updateParametersInContext().
*
* When using this Force, the System should also include a NonbondedForce, and both objects must specify
* identical charges for all particles. Otherwise, the results will not be correct. Furthermore, if the
* nonbonded method is set to CutoffNonPeriodic or CutoffPeriodic, you should call setReactionFieldDielectric(1.0)
* on the NonbondedForce to turn off the reaction field approximation, which does not produce correct results
* when combined with GBSA.
*/
*/
class
OPENMM_EXPORT
GBSAOBCForce
:
public
Force
{
class
OPENMM_EXPORT
GBSAOBCForce
:
public
Force
{
...
@@ -70,7 +76,7 @@ public:
...
@@ -70,7 +76,7 @@ public:
*/
*/
CutoffPeriodic
=
2
,
CutoffPeriodic
=
2
,
};
};
/*
/*
*
* Create a GBSAOBCForce.
* Create a GBSAOBCForce.
*/
*/
GBSAOBCForce
();
GBSAOBCForce
();
...
...
openmmapi/include/openmm/MonteCarloAnisotropicBarostat.h
0 → 100644
View file @
e3b25204
#ifndef OPENMM_MONTECARLOANISOTROPICBAROSTAT_H_
#define OPENMM_MONTECARLOANISOTROPICBAROSTAT_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-2013 Stanford University and the Authors. *
* Authors: Peter Eastman, Lee-Ping Wang *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "Force.h"
#include "Vec3.h"
#include <string>
#include "internal/windowsExport.h"
namespace
OpenMM
{
/**
* This class uses a Monte Carlo algorithm to adjust the size of the periodic box, simulating the
* effect of constant pressure.
*
* This class is similar to MonteCarloBarostat, but each Monte Carlo move is applied to only one axis
* of the periodic box (unlike MonteCarloBarostat, which scales the entire box isotropically). This
* means that the box may change shape as well as size over the course of the simulation. It also
* allows you to specify a different pressure for each axis of the box, or to keep the box size fixed
* along certain axes while still allowing it to change along others.
*
* This class assumes the simulation is also being run at constant temperature, and requires you
* to specify the system temperature (since it affects the acceptance probability for Monte Carlo
* moves). It does not actually perform temperature regulation, however. You must use another
* mechanism along with it to maintain the temperature, such as LangevinIntegrator or AndersenThermostat.
*/
class
OPENMM_EXPORT
MonteCarloAnisotropicBarostat
:
public
Force
{
public:
/**
* This is the name of the parameter which stores the current pressure acting on
* the X-axis (in bar).
*/
static
const
std
::
string
&
PressureX
()
{
static
const
std
::
string
key
=
"MonteCarloPressureX"
;
return
key
;
}
/**
* This is the name of the parameter which stores the current pressure acting on
* the Y-axis (in bar).
*/
static
const
std
::
string
&
PressureY
()
{
static
const
std
::
string
key
=
"MonteCarloPressureY"
;
return
key
;
}
/**
* This is the name of the parameter which stores the current pressure acting on
* the Z-axis (in bar).
*/
static
const
std
::
string
&
PressureZ
()
{
static
const
std
::
string
key
=
"MonteCarloPressureZ"
;
return
key
;
}
/**
* Create a MonteCarloAnisotropicBarostat.
*
* @param defaultPressure The default pressure acting on each axis (in bar)
* @param temperature the temperature at which the system is being maintained (in Kelvin)
* @param frequency the frequency at which Monte Carlo pressure changes should be attempted (in time steps)
* @param scaleX whether to allow the X dimension of the periodic box to change size
* @param scaleY whether to allow the Y dimension of the periodic box to change size
* @param scaleZ whether to allow the Z dimension of the periodic box to change size
*/
MonteCarloAnisotropicBarostat
(
const
Vec3
&
defaultPressure
,
double
temperature
,
int
frequency
=
25
,
bool
scaleX
=
1
,
bool
scaleY
=
1
,
bool
scaleZ
=
1
);
/**
* Get the default pressure (in bar).
*
* @return the default pressure acting along each axis, measured in bar.
*/
const
Vec3
&
getDefaultPressure
()
const
{
return
defaultPressure
;
}
/**
* Get whether to allow the X dimension of the periodic box to change size.
*/
bool
getScaleX
()
const
{
return
scaleX
;
}
/**
* Get whether to allow the Y dimension of the periodic box to change size.
*/
bool
getScaleY
()
const
{
return
scaleY
;
}
/**
* Get whether to allow the Z dimension of the periodic box to change size.
*/
bool
getScaleZ
()
const
{
return
scaleZ
;
}
/**
* Get the frequency (in time steps) at which Monte Carlo pressure changes should be attempted. If this is set to
* 0, the barostat is disabled.
*/
int
getFrequency
()
const
{
return
frequency
;
}
/**
* Set the frequency (in time steps) at which Monte Carlo pressure changes should be attempted. If this is set to
* 0, the barostat is disabled.
*/
void
setFrequency
(
int
freq
)
{
frequency
=
freq
;
}
/**
* Get the temperature at which the system is being maintained, measured in Kelvin.
*/
double
getTemperature
()
const
{
return
temperature
;
}
/**
* Set the temperature at which the system is being maintained.
*
* @param temp the system temperature, measured in Kelvin.
*/
void
setTemperature
(
double
temp
)
{
temperature
=
temp
;
}
/**
* Get the random number seed. See setRandomNumberSeed() for details.
*/
int
getRandomNumberSeed
()
const
{
return
randomNumberSeed
;
}
/**
* Set the random number seed. It is guaranteed that if two simulations are run
* with different random number seeds, the sequence of Monte Carlo steps will be different. On
* the other hand, no guarantees are made about the behavior of simulations that use the same seed.
* In particular, Platforms are permitted to use non-deterministic algorithms which produce different
* results on successive runs, even if those runs were initialized identically.
*/
void
setRandomNumberSeed
(
int
seed
)
{
randomNumberSeed
=
seed
;
}
protected:
ForceImpl
*
createImpl
()
const
;
private:
Vec3
defaultPressure
;
double
temperature
;
bool
scaleX
,
scaleY
,
scaleZ
;
int
frequency
,
randomNumberSeed
;
};
}
// namespace OpenMM
#endif
/*OPENMM_MONTECARLOANISOTROPICBAROSTAT_H_*/
openmmapi/include/openmm/MonteCarloBarostat.h
View file @
e3b25204
...
@@ -123,176 +123,7 @@ protected:
...
@@ -123,176 +123,7 @@ protected:
private:
private:
double
defaultPressure
,
temperature
;
double
defaultPressure
,
temperature
;
int
frequency
,
randomNumberSeed
;
int
frequency
,
randomNumberSeed
;
};
double
GetTemperature
()
const
{
return
temperature
;
}
void
SetTemperature
(
double
temperature
)
{
this
->
temperature
=
temperature
;
}
};
/**
* This class uses a Monte Carlo algorithm to adjust the size of the periodic box, simulating the
* effect of constant pressure.
*
* Compared to MonteCarloBarostat, this class scales the three axes of the simulation cell independently.
* The user supplies three doubles to specify the pressure along each axis.
*
* This class assumes the simulation is also being run at constant temperature, and requires you
* to specify the system temperature (since it affects the acceptance probability for Monte Carlo
* moves). It does not actually perform temperature regulation, however. You must use another
* mechanism along with it to maintain the temperature, such as LangevinIntegrator or AndersenThermostat.
*/
class
OPENMM_EXPORT
MonteCarloAnisotropicBarostat
:
public
Force
{
public:
/**
* This is the name of the parameter which stores the current pressure acting on
* the X-axis (in bar).
*/
static
const
std
::
string
&
PressureX
()
{
static
const
std
::
string
key
=
"MonteCarloPressureX"
;
return
key
;
}
/**
* This is the name of the parameter which stores the current pressure acting on
* the Y-axis (in bar).
*/
static
const
std
::
string
&
PressureY
()
{
static
const
std
::
string
key
=
"MonteCarloPressureY"
;
return
key
;
}
/**
* This is the name of the parameter which stores the current pressure acting on
* the Z-axis (in bar).
*/
static
const
std
::
string
&
PressureZ
()
{
static
const
std
::
string
key
=
"MonteCarloPressureZ"
;
return
key
;
}
/**
* Create a MonteCarloAnisotropicBarostat.
*
* @param defaultPressureX The default pressure acting on the X-axis (in bar)
* @param defaultPressureY The default pressure acting on the Y-axis (in bar)
* @param defaultPressureZ The default pressure acting on the Z-axis (in bar)
* @param temperature the temperature at which the system is being maintained (in Kelvin)
* @param frequency the frequency at which Monte Carlo pressure changes should be attempted (in time steps)
* @param scaleX on/off switch for whether to scale the X axis
* @param scaleY on/off switch for whether to scale the Y axis
* @param scaleZ on/off switch for whether to scale the Z axis
*/
MonteCarloAnisotropicBarostat
(
double
defaultPressureX
,
double
defaultPressureY
,
double
defaultPressureZ
,
double
temperature
,
int
frequency
=
25
,
bool
scaleX
=
1
,
bool
scaleY
=
1
,
bool
scaleZ
=
1
);
/**
* Get the default pressure acting on the X-axis (in bar).
*
* @return the default pressure acting on the system, measured in bar.
*/
double
getDefaultPressureX
()
const
{
return
defaultPressureX
;
}
/**
* Get the default pressure acting on the Y-axis (in bar).
*
* @return the default pressure acting on the system, measured in bar.
*/
double
getDefaultPressureY
()
const
{
return
defaultPressureY
;
}
/**
* Get the default pressure acting on the Z-axis (in bar).
*
* @return the default pressure acting on the system, measured in bar.
*/
double
getDefaultPressureZ
()
const
{
return
defaultPressureZ
;
}
/**
* Get the true/false flag for scaling the X-axis.
*
* @return the true/false flag for scaling the X-axis.
*/
bool
getScaleX
()
const
{
return
scaleX
;
}
/**
* Get the true/false flag for scaling the Y-axis.
*
* @return the true/false flag for scaling the Y-axis.
*/
bool
getScaleY
()
const
{
return
scaleY
;
}
/**
* Get the true/false flag for scaling the Z-axis.
*
* @return the true/false flag for scaling the Z-axis.
*/
bool
getScaleZ
()
const
{
return
scaleZ
;
}
/**
* Get the frequency (in time steps) at which Monte Carlo pressure changes should be attempted. If this is set to
* 0, the barostat is disabled.
*/
int
getFrequency
()
const
{
return
frequency
;
}
/**
* Set the frequency (in time steps) at which Monte Carlo pressure changes should be attempted. If this is set to
* 0, the barostat is disabled.
*/
void
setFrequency
(
int
freq
)
{
frequency
=
freq
;
}
/**
* Get the temperature at which the system is being maintained, measured in Kelvin.
*/
double
getTemperature
()
const
{
return
temperature
;
}
/**
* Set the temperature at which the system is being maintained.
*
* @param temp the system temperature, measured in Kelvin.
*/
void
setTemperature
(
double
temp
)
{
temperature
=
temp
;
}
/**
* Get the random number seed. See setRandomNumberSeed() for details.
*/
int
getRandomNumberSeed
()
const
{
return
randomNumberSeed
;
}
/**
* Set the random number seed. It is guaranteed that if two simulations are run
* with different random number seeds, the sequence of Monte Carlo steps will be different. On
* the other hand, no guarantees are made about the behavior of simulations that use the same seed.
* In particular, Platforms are permitted to use non-deterministic algorithms which produce different
* results on successive runs, even if those runs were initialized identically.
*/
void
setRandomNumberSeed
(
int
seed
)
{
randomNumberSeed
=
seed
;
}
protected:
ForceImpl
*
createImpl
()
const
;
private:
double
defaultPressureX
,
defaultPressureY
,
defaultPressureZ
;
double
temperature
;
bool
scaleX
,
scaleY
,
scaleZ
;
int
frequency
,
randomNumberSeed
;
double
GetTemperature
()
const
{
return
temperature
;
}
void
SetTemperature
(
double
temperature
)
{
this
->
temperature
=
temperature
;
}
};
}
// namespace OpenMM
}
// namespace OpenMM
...
...
openmmapi/include/openmm/internal/AssertionUtilities.h
View file @
e3b25204
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
* 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) 2008-201
2
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
3
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -54,6 +54,8 @@ void OPENMM_EXPORT throwException(const char* file, int line, const std::string&
...
@@ -54,6 +54,8 @@ void OPENMM_EXPORT throwException(const char* file, int line, const std::string&
#define ASSERT_EQUAL_VEC(expected, found, tol) {double _norm_ = std::sqrt((expected).dot(expected)); double _scale_ = _norm_ > 1.0 ? _norm_ : 1.0; if ((std::abs(((expected)[0])-((found)[0]))/_scale_ > (tol)) || (std::abs(((expected)[1])-((found)[1]))/_scale_ > (tol)) || (std::abs(((expected)[2])-((found)[2]))/_scale_ > (tol))) {std::stringstream details; details << " Expected "<<(expected)<<", found "<<(found); throwException(__FILE__, __LINE__, details.str());}};
#define ASSERT_EQUAL_VEC(expected, found, tol) {double _norm_ = std::sqrt((expected).dot(expected)); double _scale_ = _norm_ > 1.0 ? _norm_ : 1.0; if ((std::abs(((expected)[0])-((found)[0]))/_scale_ > (tol)) || (std::abs(((expected)[1])-((found)[1]))/_scale_ > (tol)) || (std::abs(((expected)[2])-((found)[2]))/_scale_ > (tol))) {std::stringstream details; details << " Expected "<<(expected)<<", found "<<(found); throwException(__FILE__, __LINE__, details.str());}};
#define ASSERT_USUALLY_TRUE(cond) {if (!(cond)) throwException(__FILE__, __LINE__, "(This test is stochastic and may occasionally fail)");};
#define ASSERT_USUALLY_EQUAL_TOL(expected, found, tol) {double _scale_ = std::abs(expected) > 1.0 ? std::abs(expected) : 1.0; if (!(std::abs((expected)-(found))/_scale_ <= (tol))) {std::stringstream details; details << "Expected "<<(expected)<<", found "<<(found)<<" (This test is stochastic and may occasionally fail)"; throwException(__FILE__, __LINE__, details.str());}};
#define ASSERT_USUALLY_EQUAL_TOL(expected, found, tol) {double _scale_ = std::abs(expected) > 1.0 ? std::abs(expected) : 1.0; if (!(std::abs((expected)-(found))/_scale_ <= (tol))) {std::stringstream details; details << "Expected "<<(expected)<<", found "<<(found)<<" (This test is stochastic and may occasionally fail)"; throwException(__FILE__, __LINE__, details.str());}};
#define ASSERT_VALID_INDEX(index, vector) {if (index < 0 || index >= (int) vector.size()) throwException(__FILE__, __LINE__, "Index out of range");};
#define ASSERT_VALID_INDEX(index, vector) {if (index < 0 || index >= (int) vector.size()) throwException(__FILE__, __LINE__, "Index out of range");};
...
...
openmmapi/include/openmm/internal/MonteCarloAnisotropicBarostatImpl.h
0 → 100644
View file @
e3b25204
#ifndef OPENMM_MONTECARLOANISOTROPICBAROSTATIMPL_H_
#define OPENMM_MONTECARLOANISOTROPICBAROSTATIMPL_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "ForceImpl.h"
#include "openmm/MonteCarloAnisotropicBarostat.h"
#include "openmm/Kernel.h"
#include "sfmt/SFMT.h"
#include <string>
namespace
OpenMM
{
/**
* This is the internal implementation of MonteCarloAnisotropicBarostat.
*/
class
MonteCarloAnisotropicBarostatImpl
:
public
ForceImpl
{
public:
MonteCarloAnisotropicBarostatImpl
(
const
MonteCarloAnisotropicBarostat
&
owner
);
void
initialize
(
ContextImpl
&
context
);
const
MonteCarloAnisotropicBarostat
&
getOwner
()
const
{
return
owner
;
}
void
updateContextState
(
ContextImpl
&
context
);
double
calcForcesAndEnergy
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
,
int
groups
)
{
// This force doesn't apply forces to particles.
return
0.0
;
}
std
::
map
<
std
::
string
,
double
>
getDefaultParameters
();
std
::
vector
<
std
::
string
>
getKernelNames
();
private:
const
MonteCarloAnisotropicBarostat
&
owner
;
int
step
,
numAttempted
[
3
],
numAccepted
[
3
];
double
volumeScale
[
3
];
OpenMM_SFMT
::
SFMT
random
;
Kernel
kernel
;
};
}
// namespace OpenMM
#endif
/*OPENMM_MONTECARLOANISOTROPICBAROSTATIMPL_H_*/
openmmapi/include/openmm/internal/MonteCarloBarostatImpl.h
View file @
e3b25204
...
@@ -66,28 +66,6 @@ private:
...
@@ -66,28 +66,6 @@ private:
Kernel
kernel
;
Kernel
kernel
;
};
};
class
MonteCarloAnisotropicBarostatImpl
:
public
ForceImpl
{
public:
MonteCarloAnisotropicBarostatImpl
(
const
MonteCarloAnisotropicBarostat
&
owner
);
void
initialize
(
ContextImpl
&
context
);
const
MonteCarloAnisotropicBarostat
&
getOwner
()
const
{
return
owner
;
}
void
updateContextState
(
ContextImpl
&
context
);
double
calcForcesAndEnergy
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
,
int
groups
)
{
// This force doesn't apply forces to particles.
return
0.0
;
}
std
::
map
<
std
::
string
,
double
>
getDefaultParameters
();
std
::
vector
<
std
::
string
>
getKernelNames
();
private:
const
MonteCarloAnisotropicBarostat
&
owner
;
int
step
,
numAttempted
[
3
],
numAccepted
[
3
];
double
volumeScale
[
3
];
OpenMM_SFMT
::
SFMT
random
;
Kernel
kernel
;
};
}
// namespace OpenMM
}
// namespace OpenMM
#endif
/*OPENMM_MONTECARLOBAROSTATIMPL_H_*/
#endif
/*OPENMM_MONTECARLOBAROSTATIMPL_H_*/
openmmapi/src/Context.cpp
View file @
e3b25204
...
@@ -33,7 +33,7 @@
...
@@ -33,7 +33,7 @@
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/OpenMMException.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/ForceImpl.h"
#include "openmm/internal/ForceImpl.h"
#include "
../src/SimTKUtilities/
SimTKOpenMMRealType.h"
#include "SimTKOpenMMRealType.h"
#include "sfmt/SFMT.h"
#include "sfmt/SFMT.h"
#include <cmath>
#include <cmath>
...
...
openmmapi/src/MonteCarloAnisotropicBarostat.cpp
0 → 100644
View file @
e3b25204
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/MonteCarloAnisotropicBarostat.h"
#include "openmm/internal/MonteCarloAnisotropicBarostatImpl.h"
#include <ctime>
using
namespace
OpenMM
;
MonteCarloAnisotropicBarostat
::
MonteCarloAnisotropicBarostat
(
const
Vec3
&
defaultPressure
,
double
temperature
,
int
frequency
,
bool
scaleX
,
bool
scaleY
,
bool
scaleZ
)
:
defaultPressure
(
defaultPressure
),
temperature
(
temperature
),
frequency
(
frequency
),
scaleX
(
scaleX
),
scaleY
(
scaleY
),
scaleZ
(
scaleZ
)
{
setRandomNumberSeed
((
int
)
time
(
NULL
));
}
ForceImpl
*
MonteCarloAnisotropicBarostat
::
createImpl
()
const
{
return
new
MonteCarloAnisotropicBarostatImpl
(
*
this
);
}
openmmapi/src/MonteCarloAnisotropicBarostatImpl.cpp
0 → 100644
View file @
e3b25204
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-2013 Stanford University and the Authors. *
* Authors: Peter Eastman, Lee-Ping Wang *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/MonteCarloAnisotropicBarostatImpl.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/Context.h"
#include "openmm/kernels.h"
#include <cmath>
#include <vector>
using
namespace
OpenMM
;
using
namespace
OpenMM_SFMT
;
using
std
::
vector
;
const
float
BOLTZMANN
=
1.380658e-23
f
;
// (J/K)
const
float
AVOGADRO
=
6.0221367e23
f
;
const
float
RGAS
=
BOLTZMANN
*
AVOGADRO
;
// (J/(mol K))
const
float
BOLTZ
=
RGAS
/
1000
;
// (kJ/(mol K))
MonteCarloAnisotropicBarostatImpl
::
MonteCarloAnisotropicBarostatImpl
(
const
MonteCarloAnisotropicBarostat
&
owner
)
:
owner
(
owner
),
step
(
0
)
{
}
void
MonteCarloAnisotropicBarostatImpl
::
initialize
(
ContextImpl
&
context
)
{
kernel
=
context
.
getPlatform
().
createKernel
(
ApplyMonteCarloBarostatKernel
::
Name
(),
context
);
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
initialize
(
context
.
getSystem
(),
owner
);
Vec3
box
[
3
];
context
.
getPeriodicBoxVectors
(
box
[
0
],
box
[
1
],
box
[
2
]);
double
volume
=
box
[
0
][
0
]
*
box
[
1
][
1
]
*
box
[
2
][
2
];
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
volumeScale
[
i
]
=
0.01
*
volume
;
numAttempted
[
i
]
=
0
;
numAccepted
[
i
]
=
0
;
}
init_gen_rand
(
owner
.
getRandomNumberSeed
(),
random
);
}
void
MonteCarloAnisotropicBarostatImpl
::
updateContextState
(
ContextImpl
&
context
)
{
if
(
++
step
<
owner
.
getFrequency
()
||
owner
.
getFrequency
()
==
0
)
return
;
if
(
!
owner
.
getScaleX
()
&&
!
owner
.
getScaleY
()
&&
!
owner
.
getScaleZ
())
return
;
step
=
0
;
// Compute the current potential energy.
double
initialEnergy
=
context
.
getOwner
().
getState
(
State
::
Energy
).
getPotentialEnergy
();
double
pressure
;
// Choose which axis to modify at random.
int
axis
;
while
(
true
)
{
double
rnd
=
genrand_real2
(
random
)
*
3.0
;
if
(
rnd
<
1.0
)
{
if
(
owner
.
getScaleX
())
{
axis
=
0
;
pressure
=
context
.
getParameter
(
MonteCarloAnisotropicBarostat
::
PressureX
())
*
(
AVOGADRO
*
1e-25
);
break
;
}
}
else
if
(
rnd
<
2.0
)
{
if
(
owner
.
getScaleY
())
{
axis
=
1
;
pressure
=
context
.
getParameter
(
MonteCarloAnisotropicBarostat
::
PressureY
())
*
(
AVOGADRO
*
1e-25
);
break
;
}
}
else
if
(
owner
.
getScaleZ
())
{
axis
=
2
;
pressure
=
context
.
getParameter
(
MonteCarloAnisotropicBarostat
::
PressureZ
())
*
(
AVOGADRO
*
1e-25
);
break
;
}
}
// Modify the periodic box size.
Vec3
box
[
3
];
context
.
getPeriodicBoxVectors
(
box
[
0
],
box
[
1
],
box
[
2
]);
double
volume
=
box
[
0
][
0
]
*
box
[
1
][
1
]
*
box
[
2
][
2
];
double
deltaVolume
=
volumeScale
[
axis
]
*
2
*
(
genrand_real2
(
random
)
-
0.5
);
double
newVolume
=
volume
+
deltaVolume
;
Vec3
lengthScale
(
1.0
,
1.0
,
1.0
);
lengthScale
[
axis
]
=
newVolume
/
volume
;
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
scaleCoordinates
(
context
,
lengthScale
[
0
],
lengthScale
[
1
],
lengthScale
[
2
]);
context
.
getOwner
().
setPeriodicBoxVectors
(
box
[
0
]
*
lengthScale
[
0
],
box
[
1
]
*
lengthScale
[
1
],
box
[
2
]
*
lengthScale
[
2
]);
// Compute the energy of the modified system.
double
finalEnergy
=
context
.
getOwner
().
getState
(
State
::
Energy
).
getPotentialEnergy
();
double
kT
=
BOLTZ
*
owner
.
getTemperature
();
double
w
=
finalEnergy
-
initialEnergy
+
pressure
*
deltaVolume
-
context
.
getMolecules
().
size
()
*
kT
*
std
::
log
(
newVolume
/
volume
);
if
(
w
>
0
&&
genrand_real2
(
random
)
>
std
::
exp
(
-
w
/
kT
))
{
// Reject the step.
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
restoreCoordinates
(
context
);
context
.
getOwner
().
setPeriodicBoxVectors
(
box
[
0
],
box
[
1
],
box
[
2
]);
volume
=
newVolume
;
}
else
numAccepted
[
axis
]
++
;
numAttempted
[
axis
]
++
;
if
(
numAttempted
[
axis
]
>=
10
)
{
if
(
numAccepted
[
axis
]
<
0.25
*
numAttempted
[
axis
])
{
volumeScale
[
axis
]
/=
1.1
;
numAttempted
[
axis
]
=
0
;
numAccepted
[
axis
]
=
0
;
}
else
if
(
numAccepted
[
axis
]
>
0.75
*
numAttempted
[
axis
])
{
volumeScale
[
axis
]
=
std
::
min
(
volumeScale
[
axis
]
*
1.1
,
volume
*
0.3
);
numAttempted
[
axis
]
=
0
;
numAccepted
[
axis
]
=
0
;
}
}
}
std
::
map
<
std
::
string
,
double
>
MonteCarloAnisotropicBarostatImpl
::
getDefaultParameters
()
{
std
::
map
<
std
::
string
,
double
>
parameters
;
parameters
[
MonteCarloAnisotropicBarostat
::
PressureX
()]
=
getOwner
().
getDefaultPressure
()[
0
];
parameters
[
MonteCarloAnisotropicBarostat
::
PressureY
()]
=
getOwner
().
getDefaultPressure
()[
1
];
parameters
[
MonteCarloAnisotropicBarostat
::
PressureZ
()]
=
getOwner
().
getDefaultPressure
()[
2
];
return
parameters
;
}
std
::
vector
<
std
::
string
>
MonteCarloAnisotropicBarostatImpl
::
getKernelNames
()
{
std
::
vector
<
std
::
string
>
names
;
names
.
push_back
(
ApplyMonteCarloBarostatKernel
::
Name
());
return
names
;
}
openmmapi/src/MonteCarloBarostat.cpp
View file @
e3b25204
...
@@ -43,12 +43,3 @@ MonteCarloBarostat::MonteCarloBarostat(double defaultPressure, double temperatur
...
@@ -43,12 +43,3 @@ MonteCarloBarostat::MonteCarloBarostat(double defaultPressure, double temperatur
ForceImpl
*
MonteCarloBarostat
::
createImpl
()
const
{
ForceImpl
*
MonteCarloBarostat
::
createImpl
()
const
{
return
new
MonteCarloBarostatImpl
(
*
this
);
return
new
MonteCarloBarostatImpl
(
*
this
);
}
}
MonteCarloAnisotropicBarostat
::
MonteCarloAnisotropicBarostat
(
double
defaultPressureX
,
double
defaultPressureY
,
double
defaultPressureZ
,
double
temperature
,
int
frequency
,
bool
scaleX
,
bool
scaleY
,
bool
scaleZ
)
:
defaultPressureX
(
defaultPressureX
),
defaultPressureY
(
defaultPressureY
),
defaultPressureZ
(
defaultPressureZ
),
temperature
(
temperature
),
frequency
(
frequency
),
scaleX
(
scaleX
),
scaleY
(
scaleY
),
scaleZ
(
scaleZ
)
{
setRandomNumberSeed
((
int
)
time
(
NULL
));
}
ForceImpl
*
MonteCarloAnisotropicBarostat
::
createImpl
()
const
{
return
new
MonteCarloAnisotropicBarostatImpl
(
*
this
);
}
openmmapi/src/MonteCarloBarostatImpl.cpp
View file @
e3b25204
...
@@ -64,13 +64,13 @@ void MonteCarloBarostatImpl::updateContextState(ContextImpl& context) {
...
@@ -64,13 +64,13 @@ void MonteCarloBarostatImpl::updateContextState(ContextImpl& context) {
if
(
++
step
<
owner
.
getFrequency
()
||
owner
.
getFrequency
()
==
0
)
if
(
++
step
<
owner
.
getFrequency
()
||
owner
.
getFrequency
()
==
0
)
return
;
return
;
step
=
0
;
step
=
0
;
// Compute the current potential energy.
// Compute the current potential energy.
double
initialEnergy
=
context
.
getOwner
().
getState
(
State
::
Energy
).
getPotentialEnergy
();
double
initialEnergy
=
context
.
getOwner
().
getState
(
State
::
Energy
).
getPotentialEnergy
();
// Modify the periodic box size.
// Modify the periodic box size.
Vec3
box
[
3
];
Vec3
box
[
3
];
context
.
getPeriodicBoxVectors
(
box
[
0
],
box
[
1
],
box
[
2
]);
context
.
getPeriodicBoxVectors
(
box
[
0
],
box
[
1
],
box
[
2
]);
double
volume
=
box
[
0
][
0
]
*
box
[
1
][
1
]
*
box
[
2
][
2
];
double
volume
=
box
[
0
][
0
]
*
box
[
1
][
1
]
*
box
[
2
][
2
];
...
@@ -79,7 +79,7 @@ void MonteCarloBarostatImpl::updateContextState(ContextImpl& context) {
...
@@ -79,7 +79,7 @@ void MonteCarloBarostatImpl::updateContextState(ContextImpl& context) {
double
lengthScale
=
std
::
pow
(
newVolume
/
volume
,
1.0
/
3.0
);
double
lengthScale
=
std
::
pow
(
newVolume
/
volume
,
1.0
/
3.0
);
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
scaleCoordinates
(
context
,
lengthScale
,
lengthScale
,
lengthScale
);
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
scaleCoordinates
(
context
,
lengthScale
,
lengthScale
,
lengthScale
);
context
.
getOwner
().
setPeriodicBoxVectors
(
box
[
0
]
*
lengthScale
,
box
[
1
]
*
lengthScale
,
box
[
2
]
*
lengthScale
);
context
.
getOwner
().
setPeriodicBoxVectors
(
box
[
0
]
*
lengthScale
,
box
[
1
]
*
lengthScale
,
box
[
2
]
*
lengthScale
);
// Compute the energy of the modified system.
// Compute the energy of the modified system.
double
finalEnergy
=
context
.
getOwner
().
getState
(
State
::
Energy
).
getPotentialEnergy
();
double
finalEnergy
=
context
.
getOwner
().
getState
(
State
::
Energy
).
getPotentialEnergy
();
...
@@ -88,7 +88,7 @@ void MonteCarloBarostatImpl::updateContextState(ContextImpl& context) {
...
@@ -88,7 +88,7 @@ void MonteCarloBarostatImpl::updateContextState(ContextImpl& context) {
double
w
=
finalEnergy
-
initialEnergy
+
pressure
*
deltaVolume
-
context
.
getMolecules
().
size
()
*
kT
*
std
::
log
(
newVolume
/
volume
);
double
w
=
finalEnergy
-
initialEnergy
+
pressure
*
deltaVolume
-
context
.
getMolecules
().
size
()
*
kT
*
std
::
log
(
newVolume
/
volume
);
if
(
w
>
0
&&
genrand_real2
(
random
)
>
std
::
exp
(
-
w
/
kT
))
{
if
(
w
>
0
&&
genrand_real2
(
random
)
>
std
::
exp
(
-
w
/
kT
))
{
// Reject the step.
// Reject the step.
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
restoreCoordinates
(
context
);
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
restoreCoordinates
(
context
);
context
.
getOwner
().
setPeriodicBoxVectors
(
box
[
0
],
box
[
1
],
box
[
2
]);
context
.
getOwner
().
setPeriodicBoxVectors
(
box
[
0
],
box
[
1
],
box
[
2
]);
volume
=
newVolume
;
volume
=
newVolume
;
...
@@ -122,108 +122,3 @@ std::vector<std::string> MonteCarloBarostatImpl::getKernelNames() {
...
@@ -122,108 +122,3 @@ std::vector<std::string> MonteCarloBarostatImpl::getKernelNames() {
return
names
;
return
names
;
}
}
MonteCarloAnisotropicBarostatImpl
::
MonteCarloAnisotropicBarostatImpl
(
const
MonteCarloAnisotropicBarostat
&
owner
)
:
owner
(
owner
),
step
(
0
)
{
}
void
MonteCarloAnisotropicBarostatImpl
::
initialize
(
ContextImpl
&
context
)
{
kernel
=
context
.
getPlatform
().
createKernel
(
ApplyMonteCarloBarostatKernel
::
Name
(),
context
);
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
initialize
(
context
.
getSystem
(),
owner
);
Vec3
box
[
3
];
context
.
getPeriodicBoxVectors
(
box
[
0
],
box
[
1
],
box
[
2
]);
double
volume
=
box
[
0
][
0
]
*
box
[
1
][
1
]
*
box
[
2
][
2
];
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
volumeScale
[
i
]
=
0.01
*
volume
;
numAttempted
[
i
]
=
0
;
numAccepted
[
i
]
=
0
;
}
init_gen_rand
(
owner
.
getRandomNumberSeed
(),
random
);
}
void
MonteCarloAnisotropicBarostatImpl
::
updateContextState
(
ContextImpl
&
context
)
{
if
(
++
step
<
owner
.
getFrequency
()
||
owner
.
getFrequency
()
==
0
)
return
;
if
(
owner
.
getScaleX
()
==
0
&&
owner
.
getScaleY
()
==
0
&&
owner
.
getScaleZ
()
==
0
)
return
;
step
=
0
;
// Compute the current potential energy.
double
initialEnergy
=
context
.
getOwner
().
getState
(
State
::
Energy
).
getPotentialEnergy
();
double
pressure
;
// Choose which axis to modify at random.
double
rnd
=
genrand_real2
(
random
)
*
3.0
;
int
axis
;
while
(
1
)
{
if
(
rnd
<
1.0
&&
owner
.
getScaleX
())
{
axis
=
0
;
pressure
=
context
.
getParameter
(
MonteCarloAnisotropicBarostat
::
PressureX
())
*
(
AVOGADRO
*
1e-25
);
break
;
}
else
if
(
rnd
<
2.0
&&
owner
.
getScaleY
())
{
axis
=
1
;
pressure
=
context
.
getParameter
(
MonteCarloAnisotropicBarostat
::
PressureY
())
*
(
AVOGADRO
*
1e-25
);
break
;
}
else
if
(
owner
.
getScaleZ
())
{
axis
=
2
;
pressure
=
context
.
getParameter
(
MonteCarloAnisotropicBarostat
::
PressureZ
())
*
(
AVOGADRO
*
1e-25
);
break
;
}
}
// Modify the periodic box size.
Vec3
box
[
3
];
context
.
getPeriodicBoxVectors
(
box
[
0
],
box
[
1
],
box
[
2
]);
double
volume
=
box
[
0
][
0
]
*
box
[
1
][
1
]
*
box
[
2
][
2
];
double
deltaVolume
=
volumeScale
[
axis
]
*
2
*
(
genrand_real2
(
random
)
-
0.5
);
double
newVolume
=
volume
+
deltaVolume
;
Vec3
lengthScale
;
for
(
int
i
=
0
;
i
<
3
;
i
++
)
lengthScale
[
i
]
=
1.0
;
lengthScale
[
axis
]
=
newVolume
/
volume
;
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
scaleCoordinates
(
context
,
lengthScale
[
0
],
lengthScale
[
1
],
lengthScale
[
2
]);
context
.
getOwner
().
setPeriodicBoxVectors
(
box
[
0
]
*
lengthScale
[
0
],
box
[
1
]
*
lengthScale
[
1
],
box
[
2
]
*
lengthScale
[
2
]);
// Compute the energy of the modified system.
double
finalEnergy
=
context
.
getOwner
().
getState
(
State
::
Energy
).
getPotentialEnergy
();
double
kT
=
BOLTZ
*
owner
.
getTemperature
();
double
w
=
finalEnergy
-
initialEnergy
+
pressure
*
deltaVolume
-
context
.
getMolecules
().
size
()
*
kT
*
std
::
log
(
newVolume
/
volume
);
if
(
w
>
0
&&
genrand_real2
(
random
)
>
std
::
exp
(
-
w
/
kT
))
{
// Reject the step.
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
restoreCoordinates
(
context
);
context
.
getOwner
().
setPeriodicBoxVectors
(
box
[
0
],
box
[
1
],
box
[
2
]);
volume
=
newVolume
;
}
else
numAccepted
[
axis
]
++
;
numAttempted
[
axis
]
++
;
if
(
numAttempted
[
axis
]
>=
10
)
{
if
(
numAccepted
[
axis
]
<
0.25
*
numAttempted
[
axis
])
{
volumeScale
[
axis
]
/=
1.1
;
numAttempted
[
axis
]
=
0
;
numAccepted
[
axis
]
=
0
;
}
else
if
(
numAccepted
[
axis
]
>
0.75
*
numAttempted
[
axis
])
{
volumeScale
[
axis
]
=
std
::
min
(
volumeScale
[
axis
]
*
1.1
,
volume
*
0.3
);
numAttempted
[
axis
]
=
0
;
numAccepted
[
axis
]
=
0
;
}
}
}
std
::
map
<
std
::
string
,
double
>
MonteCarloAnisotropicBarostatImpl
::
getDefaultParameters
()
{
std
::
map
<
std
::
string
,
double
>
parameters
;
parameters
[
MonteCarloAnisotropicBarostat
::
PressureX
()]
=
getOwner
().
getDefaultPressureX
();
parameters
[
MonteCarloAnisotropicBarostat
::
PressureY
()]
=
getOwner
().
getDefaultPressureY
();
parameters
[
MonteCarloAnisotropicBarostat
::
PressureZ
()]
=
getOwner
().
getDefaultPressureZ
();
return
parameters
;
}
std
::
vector
<
std
::
string
>
MonteCarloAnisotropicBarostatImpl
::
getKernelNames
()
{
std
::
vector
<
std
::
string
>
names
;
names
.
push_back
(
ApplyMonteCarloBarostatKernel
::
Name
());
return
names
;
}
platforms/cuda/CMakeLists.txt
View file @
e3b25204
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
IF
(
APPLE
)
IF
(
APPLE
)
SET
(
CMAKE_OSX_DEPLOYMENT_TARGET
"10.6"
)
SET
(
CMAKE_OSX_DEPLOYMENT_TARGET
"10.6"
)
SET
(
CMAKE_OSX_SYSROOT
"/Developer/SDKs/MacOSX10.6.sdk"
)
ENDIF
(
APPLE
)
ENDIF
(
APPLE
)
set
(
OPENMM_BUILD_CUDA_TESTS TRUE CACHE BOOL
"Whether to build CUDA test cases"
)
set
(
OPENMM_BUILD_CUDA_TESTS TRUE CACHE BOOL
"Whether to build CUDA test cases"
)
...
@@ -103,4 +102,9 @@ SET(CUDA_KERNELS_H ${CMAKE_CURRENT_BINARY_DIR}/src/${CUDA_SOURCE_CLASS}.h)
...
@@ -103,4 +102,9 @@ SET(CUDA_KERNELS_H ${CMAKE_CURRENT_BINARY_DIR}/src/${CUDA_SOURCE_CLASS}.h)
SET
(
SOURCE_FILES
${
SOURCE_FILES
}
${
CUDA_KERNELS_CPP
}
${
CUDA_KERNELS_H
}
)
SET
(
SOURCE_FILES
${
SOURCE_FILES
}
${
CUDA_KERNELS_CPP
}
${
CUDA_KERNELS_H
}
)
INCLUDE_DIRECTORIES
(
BEFORE
${
CMAKE_CURRENT_BINARY_DIR
}
/src
)
INCLUDE_DIRECTORIES
(
BEFORE
${
CMAKE_CURRENT_BINARY_DIR
}
/src
)
# Install headers
FILE
(
GLOB CORE_HEADERS include/*.h
)
INSTALL_FILES
(
/include/openmm/cuda FILES
${
CORE_HEADERS
}
)
SUBDIRS
(
sharedTarget
)
SUBDIRS
(
sharedTarget
)
platforms/cuda/
src
/CudaArray.h
→
platforms/cuda/
include
/CudaArray.h
View file @
e3b25204
File moved
platforms/cuda/
src
/CudaBondedUtilities.h
→
platforms/cuda/
include
/CudaBondedUtilities.h
View file @
e3b25204
File moved
platforms/cuda/
src
/CudaContext.h
→
platforms/cuda/
include
/CudaContext.h
View file @
e3b25204
...
@@ -70,6 +70,8 @@ public:
...
@@ -70,6 +70,8 @@ public:
class
WorkTask
;
class
WorkTask
;
class
WorkThread
;
class
WorkThread
;
class
ReorderListener
;
class
ReorderListener
;
class
ForcePreComputation
;
class
ForcePostComputation
;
static
const
int
ThreadBlockSize
;
static
const
int
ThreadBlockSize
;
static
const
int
TileSize
;
static
const
int
TileSize
;
CudaContext
(
const
System
&
system
,
int
deviceIndex
,
bool
useBlockingSync
,
const
std
::
string
&
precision
,
CudaContext
(
const
System
&
system
,
int
deviceIndex
,
bool
useBlockingSync
,
const
std
::
string
&
precision
,
...
@@ -454,6 +456,28 @@ public:
...
@@ -454,6 +456,28 @@ public:
std
::
vector
<
ReorderListener
*>&
getReorderListeners
()
{
std
::
vector
<
ReorderListener
*>&
getReorderListeners
()
{
return
reorderListeners
;
return
reorderListeners
;
}
}
/**
* Add a pre-computation that should be called at the very start of force and energy evaluations.
* The CudaContext assumes ownership of the object, and deletes it when the context itself is deleted.
*/
void
addPreComputation
(
ForcePreComputation
*
computation
);
/**
* Get the list of ForcePreComputations.
*/
std
::
vector
<
ForcePreComputation
*>&
getPreComputations
()
{
return
preComputations
;
}
/**
* Add a post-computation that should be called at the very end of force and energy evaluations.
* The CudaContext assumes ownership of the object, and deletes it when the context itself is deleted.
*/
void
addPostComputation
(
ForcePostComputation
*
computation
);
/**
* Get the list of ForcePostComputations.
*/
std
::
vector
<
ForcePostComputation
*>&
getPostComputations
()
{
return
postComputations
;
}
/**
/**
* Mark that the current molecule definitions (and hence the atom order) may be invalid.
* Mark that the current molecule definitions (and hence the atom order) may be invalid.
* This should be called whenever force field parameters change. It will cause the definitions
* This should be called whenever force field parameters change. It will cause the definitions
...
@@ -519,6 +543,8 @@ private:
...
@@ -519,6 +543,8 @@ private:
std
::
vector
<
CUdeviceptr
>
autoclearBuffers
;
std
::
vector
<
CUdeviceptr
>
autoclearBuffers
;
std
::
vector
<
int
>
autoclearBufferSizes
;
std
::
vector
<
int
>
autoclearBufferSizes
;
std
::
vector
<
ReorderListener
*>
reorderListeners
;
std
::
vector
<
ReorderListener
*>
reorderListeners
;
std
::
vector
<
ForcePreComputation
*>
preComputations
;
std
::
vector
<
ForcePostComputation
*>
postComputations
;
CudaIntegrationUtilities
*
integration
;
CudaIntegrationUtilities
*
integration
;
CudaExpressionUtilities
*
expression
;
CudaExpressionUtilities
*
expression
;
CudaBondedUtilities
*
bonded
;
CudaBondedUtilities
*
bonded
;
...
@@ -580,7 +606,7 @@ private:
...
@@ -580,7 +606,7 @@ private:
/**
/**
* This abstract class defines a function to be executed whenever atoms get reordered.
* This abstract class defines a function to be executed whenever atoms get reordered.
* Objects that need to know when reordering happens should create a
r
eorderListener
* Objects that need to know when reordering happens should create a
R
eorderListener
* and register it by calling addReorderListener().
* and register it by calling addReorderListener().
*/
*/
class
CudaContext
::
ReorderListener
{
class
CudaContext
::
ReorderListener
{
...
@@ -590,6 +616,39 @@ public:
...
@@ -590,6 +616,39 @@ public:
}
}
};
};
/**
* This abstract class defines a function to be executed at the very beginning of force and
* energy evaluation, before any other calculation has been done. It is useful for operations
* that need to be performed at a nonstandard point in the process. After creating a
* ForcePreComputation, register it by calling addForcePreComputation().
*/
class
CudaContext
::
ForcePreComputation
{
public:
/**
* @param includeForce true if forces should be computed
* @param includeEnergy true if potential energy should be computed
* @param groups a set of bit flags for which force groups to include
*/
virtual
void
computeForceAndEnergy
(
bool
includeForces
,
bool
includeEnergy
,
int
groups
)
=
0
;
};
/**
* This abstract class defines a function to be executed at the very end of force and
* energy evaluation, after all other calculations have been done. It is useful for operations
* that need to be performed at a nonstandard point in the process. After creating a
* ForcePostComputation, register it by calling addForcePostComputation().
*/
class
CudaContext
::
ForcePostComputation
{
public:
/**
* @param includeForce true if forces should be computed
* @param includeEnergy true if potential energy should be computed
* @param groups a set of bit flags for which force groups to include
* @return an optional contribution to add to the potential energy.
*/
virtual
double
computeForceAndEnergy
(
bool
includeForces
,
bool
includeEnergy
,
int
groups
)
=
0
;
};
}
// namespace OpenMM
}
// namespace OpenMM
#endif
/*OPENMM_CUDACONTEXT_H_*/
#endif
/*OPENMM_CUDACONTEXT_H_*/
Prev
1
2
3
4
5
…
15
Next
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