Commit 51e51c3b authored by John Chodera (MSKCC)'s avatar John Chodera (MSKCC)
Browse files

Merge remote-tracking branch 'upstream/master'

parents bc240d4a 373c3878
......@@ -11,11 +11,11 @@ before_install:
script:
- cmake -DCMAKE_INSTALL_PREFIX=$HOME/OpenMM .
- make
- make install
- make -j2
- make -j2 install
- sudo make PythonInstall
- # run all of the tests
- ctest -V
- ctest -j2 -V
- # get a list of all of the failed tests into this stupid ctest format
- python -c 'fn = "Testing/Temporary/LastTestsFailed.log"; import os; os.path.exists(fn) or exit(0); l = [line.split(":")[0] for line in open(fn)]; triplets = zip(l, l, [","]*len(l)); print "".join(",".join(t) for t in triplets)' > FailedTests.log
- # rerun all of the failed tests
......
......@@ -273,7 +273,8 @@ ENDIF(WIN32)
SET(OPENMM_BUILD_STATIC_LIB OFF CACHE BOOL "Whether to build static OpenMM libraries")
IF(OPENMM_BUILD_STATIC_LIB)
ADD_LIBRARY(${STATIC_TARGET} STATIC ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_ABS_INCLUDE_FILES})
SET_TARGET_PROPERTIES(${STATIC_TARGET} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS}" COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_USE_STATIC_LIBRARIES -DOPENMM_BUILDING_STATIC_LIBRARY -DLEPTON_USE_STATIC_LIBRARIES -DLEPTON_BUILDING_STATIC_LIBRARY -DOPENMMM_VALIDATE_BUILDING_STATIC_LIBRARY -DOPENMM_VALIDATE_BUILDING_STATIC_LIBRARY")
SET(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_USE_STATIC_LIBRARIES -DLEPTON_USE_STATIC_LIBRARIES -DPTW32_STATIC_LIB")
SET_TARGET_PROPERTIES(${STATIC_TARGET} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS}" COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_BUILDING_STATIC_LIBRARY -DLEPTON_BUILDING_STATIC_LIBRARY -DOPENMMM_VALIDATE_BUILDING_STATIC_LIBRARY -DOPENMM_VALIDATE_BUILDING_STATIC_LIBRARY")
ENDIF(OPENMM_BUILD_STATIC_LIB)
IF(OPENMM_BUILD_C_AND_FORTRAN_WRAPPERS)
......
......@@ -660,7 +660,9 @@ amber99sbildn.xml AMBER99SB plus improved side chain torsions\ :cite:`Lindorff-
amber99sbnmr.xml AMBER99SB with modifications to fit NMR data\ :cite:`Li2010`
amber03.xml AMBER03\ :cite:`Duan2003`
amber10.xml AMBER10
amoeba2009.xml AMOEBA\ :cite:`Ren2002`
amoeba2009.xml AMOEBA 2009\ :cite:`Ren2002`. This force field is deprecated. It is
recommended to use AMOEBA 2013 instead.
amoeba2013.xml AMOEBA 2013\ :cite:`Shi2013`
================= ================================================================================
......@@ -675,7 +677,9 @@ files:
File Water Model
=========== ============================================
tip3p.xml TIP3P water model\ :cite:`Jorgensen1983`
tip3pfb.xml TIP3P-FB water model\ :cite:`Wang2014`
tip4pew.xml TIP4P-Ew water model\ :cite:`Horn2004`
tip4pfb.xml TIP4P-FB water model\ :cite:`Wang2014`
tip5p.xml TIP5P water model\ :cite:`Mahoney2000`
spce.xml SPC/E water model\ :cite:`Berendsen1987`
swm4ndp.xml SWM4-NDP water model\ :cite:`Lamoureux2006`
......@@ -692,15 +696,16 @@ the following files:
.. tabularcolumns:: |l|L|
================= ==============================================================================================
================= =================================================================================================
File Implicit Solvation Model
================= ==============================================================================================
================= =================================================================================================
amber96_obc.xml GBSA-OBC solvation model\ :cite:`Onufriev2004` for use with AMBER96 force field
amber99_obc.xml GBSA-OBC solvation model for use with AMBER99 force fields
amber03_obc.xml GBSA-OBC solvation model for use with AMBER03 force field
amber10_obc.xml GBSA-OBC solvation model for use with AMBER10 force field
amoeba2009_gk.xml Generalized Kirkwood solvation model\ :cite:`Schnieders2007` for use with AMOEBA force field
================= ==============================================================================================
amoeba2009_gk.xml Generalized Kirkwood solvation model\ :cite:`Schnieders2007` for use with AMOEBA 2009 force field
amoeba2013_gk.xml Generalized Kirkwood solvation model for use with AMOEBA 2013 force field
================= =================================================================================================
For example, to use the GBSA-OBC solvation model with the Amber99SB force field,
......@@ -1297,8 +1302,9 @@ water models:
modeller.addSolvent(forcefield, model='tip5p')
Allowed values for the :code:`model` option are 'tip3p', 'spce', 'tip4pew',
and 'tip5p'. Be sure to include the single quotes around the value.
Allowed values for the :code:`model` option are 'tip3p', 'tip3pfb', 'spce',
'tip4pew', 'tip4pfb', and 'tip5p'. Be sure to include the single quotes
around the value.
Another option is to add extra ion pairs to give a desired total ionic strength.
For example:
......@@ -2180,6 +2186,49 @@ second atom has class OS and the third has class P:
<Proper class1="" class2="OS" class3="P" class4="" per="3" phase="0.0" k="0.66944"/>
<CustomNonbondedForce>
===============
To add a CustomNonbondedForce to the System, include a tag that looks like this:
.. code-block:: xml
<CustomNonbondedForce energy="scale*epsilon1*epsilon2*((sigma1+sigma2)/r)^12" bondCutoff="3">
<GlobalParameter name="scale" defaultValue="1"/>
<PerParticleParameter name="sigma"/>
<PerParticleParameter name="epsilon"/>
<Atom type="0" sigma="0.3249" epsilon="0.7112"/>
<Atom type="1" sigma="0.1069" epsilon="0.0656"/>
<Atom type="2" sigma="0.3399" epsilon="0.4577"/>
...
</CustomNonbondedForce>
The energy expression for the CustomNonbondedForce is specified by the
:code:`energy` attribute. This is a mathematical expression that gives the
energy of each pairwise interaction as a function of the distance *r*\ . It
also may depend on an arbitrary list of global or per-particle parameters. Use
a :code:`<GlobalParameter>` tag to define a global parameter, and a
:code:`<PerParticleParameter>` tag to define a per-particle parameter.
Exclusions are created automatically based on the :code:`bondCutoff` attribute.
After setting the nonbonded parameters for all atoms, the force field calls
:code:`createExclusionsFromBonds()` on the CustomNonbondedForce, passing in this
value as its argument. To avoid creating exclusions, set :code:`bondCutoff` to 0.
Each :code:`<Atom>` tag specifies the parameters for one atom type
(specified with the :code:`type` attribute) or atom class (specified with
the :code:`class` attribute). It is fine to mix these two methods, having
some tags specify a type and others specify a class. However you do it, you
must make sure that a unique set of parameters is defined for every atom type.
The remaining attributes are the values to use for the per-atom parameters. All
per-atom parameters must be specified for every :code:`<Atom>` tag, and the
attribute name must match the name of the parameter. For instance, if there is
a per-atom parameter with the name radius, then every :code:`<Atom>` tag
must include an attribute called :code:`radius`\ .
CustomNonbondedForce also allows you to define tabulated functions. See section
:ref:`tabulated-functions` for details.
<CustomGBForce>
===============
......@@ -2237,30 +2286,8 @@ attribute name must match the name of the parameter. For instance, if there is
a per-atom parameter with the name radius, then every :code:`<Atom>` tag
must include an attribute called :code:`radius`\ .
CustomGBForce also allows you to define tabulated functions. To define a
function, include a :code:`<Function>` tag inside the
:code:`<CustomGBForce>` tag:
.. code-block:: xml
<Function name="myfn" min="-5" max="5">
0.983674857694 -0.980096396266 -0.975743130031 -0.970451936613 -0.964027580076
-0.956237458128 -0.946806012846 -0.935409070603 -0.921668554406 -0.905148253645
-0.885351648202 -0.861723159313 -0.833654607012 -0.800499021761 -0.761594155956
-0.716297870199 -0.664036770268 -0.604367777117 -0.537049566998 -0.46211715726
-0.379948962255 -0.291312612452 -0.197375320225 -0.099667994625 0.0
0.099667994625 0.197375320225 0.291312612452 0.379948962255 0.46211715726
0.537049566998 0.604367777117 0.664036770268 0.716297870199 0.761594155956
0.800499021761 0.833654607012 0.861723159313 0.885351648202 0.905148253645
0.921668554406 0.935409070603 0.946806012846 0.956237458128 0.964027580076
0.970451936613 0.975743130031 0.980096396266 0.983674857694 0.986614298151
0.989027402201
</Function>
The tags attributes define the name of the function and the range of values for
which it is defined. The tabulated values are listed inside the body of the
tag, with successive values separated by white space. Again, see the API
documentation for more details.
CustomGBForce also allows you to define tabulated functions. See section
:ref:`tabulated-functions` for details.
Writing Custom Expressions
==========================
......@@ -2297,6 +2324,55 @@ is exactly equivalent to
The definition of an intermediate value may itself involve other intermediate
values. All uses of a value must appear *before* that values definition.
.. _tabulated-functions:
TabulatedFunctions
==================
Some forces, such as CustomNonbondedForce and CustomGBForce, allow you to define
tabulated functions. To define a function, include a :code:`<Function>` tag inside the
:code:`<CustomNonbondedForce>` or :code:`<CustomGBForce>` tag:
.. code-block:: xml
<Function name="myfn" type="Continuous1D" min="-5" max="5">
0.983674857694 -0.980096396266 -0.975743130031 -0.970451936613 -0.964027580076
-0.956237458128 -0.946806012846 -0.935409070603 -0.921668554406 -0.905148253645
-0.885351648202 -0.861723159313 -0.833654607012 -0.800499021761 -0.761594155956
-0.716297870199 -0.664036770268 -0.604367777117 -0.537049566998 -0.46211715726
-0.379948962255 -0.291312612452 -0.197375320225 -0.099667994625 0.0
0.099667994625 0.197375320225 0.291312612452 0.379948962255 0.46211715726
0.537049566998 0.604367777117 0.664036770268 0.716297870199 0.761594155956
0.800499021761 0.833654607012 0.861723159313 0.885351648202 0.905148253645
0.921668554406 0.935409070603 0.946806012846 0.956237458128 0.964027580076
0.970451936613 0.975743130031 0.980096396266 0.983674857694 0.986614298151
0.989027402201
</Function>
The tags attributes define the name of the function, the type of function, and
the range of values for which it is defined. The required set of attributed
depends on the function type:
.. tabularcolumns:: |l|L|
============ =======================================================
Type Required Attributes
============ =======================================================
Continuous1D min, max
Continuous2D xmin, ymin, xmax, ymax, xsize, ysize
Continuous3D xmin, ymin, zmin, xmax, ymax, zmax, xsize, ysize, zsize
Discrete1D
Discrete2D xsize, ysize
Discrete3D xsize, ysize, zsize
============ =======================================================
The "min" and "max" attributes define the range of the independent variables for
a continuous function. The "size" attributes define the size of the table along
each axis. The tabulated values are listed inside the body of the tag, with
successive values separated by white space. See the API documentation for more
details.
Using Multiple Files
********************
......
......@@ -336,10 +336,20 @@
type = {Journal Article}
}
@article{Shi2013
author = {Shi, Yue and Xia, Zhen and Zhang, Jiajing and Best, Robert and Wu, Chuanjie and Ponder, Jay W. and Ren, Pengyu},
title = {Polarizable Atomic Multipole-Based AMOEBA Force Field for Proteins},
journal = {Journal of Chemical Theory and Computation},
volume = {9},
number = {9},
pages = {4046-4063},
year = {2013},
type = {Journal Article}
}
@article{Shirts2007
author = {Shirts, Michael R. and Mobley, David L. and Chodera, John D. and Pande, Vijay S.},
title = {Accurate and Efficient Corrections for Missing Dispersion Interactions in Molecular
Simulations},
title = {Accurate and Efficient Corrections for Missing Dispersion Interactions in Molecular Simulations},
journal = {Journal of Physical Chemistry B},
volume = {111},
pages = {13052-13063},
......@@ -399,3 +409,12 @@ Simulations},
type = {Journal Article}
}
@article{Wang2014
author = {Wang, Lee-Ping and Martinez, Todd J. and Pande, Vijay S.},
title = {Building force fields: an automatic, systematic, and reproducible approach},
journal = {Journal of Physical Chemistry Letters},
volume = {5},
pages = {1885-1891},
year = {2014},
type = {Journal Article}
}
......@@ -269,7 +269,15 @@ ExpressionTreeNode ParsedExpression::substituteSimplerExpression(const Expressio
return ExpressionTreeNode(new Operation::Constant(dynamic_cast<const Operation::MultiplyConstant*>(&node.getOperation())->getValue()*getConstantValue(children[0])));
if (children[0].getOperation().getId() == Operation::NEGATE) // Combine a multiply and a negate into a single multiply
return ExpressionTreeNode(new Operation::MultiplyConstant(-dynamic_cast<const Operation::MultiplyConstant*>(&node.getOperation())->getValue()), children[0].getChildren()[0]);
break;
}
default:
{
// If operation ID is not one of the above,
// we don't substitute a simpler expression.
break;
}
}
return ExpressionTreeNode(node.getOperation().clone(), children);
}
......
......@@ -35,12 +35,12 @@
#include "Integrator.h"
#include "State.h"
#include "System.h"
#include <ctime>
#include <iosfwd>
#include <map>
#include <string>
#include <vector>
#include "internal/windowsExport.h"
#include "internal/OSRngSeed.h"
namespace OpenMM {
......@@ -164,7 +164,7 @@ public:
* @param temperature the temperature for which to select the velocities (measured in Kelvin)
* @param randomSeed the random number seed to use when selecting velocities
*/
void setVelocitiesToTemperature(double temperature, int randomSeed=time(NULL));
void setVelocitiesToTemperature(double temperature, int randomSeed=osrngseed());
/**
* Get the value of an adjustable parameter defined by a Force object in the System.
*
......
......@@ -344,6 +344,8 @@ public:
/**
* Add a particle pair to the list of interactions that should be excluded.
*
* In many cases, you can use createExclusionsFromBonds() rather than adding each exclusion explicitly.
*
* @param particle1 the index of the first particle in the pair
* @param particle2 the index of the second particle in the pair
* @return the index of the exclusion that was added
......@@ -365,6 +367,15 @@ public:
* @param particle2 the index of the second particle in the pair
*/
void setExclusionParticles(int index, int particle1, int particle2);
/**
* Identify exclusions based on the molecular topology. Particles which are separated by up to a specified number of
* bonds are added as exclusions.
*
* @param bonds the set of bonds based on which to construct exclusions. Each element specifies the indices of
* two particles that are bonded to each other.
* @param bondCutoff pairs of particles that are separated by this many bonds or fewer are added to the list of exclusions
*/
void createExclusionsFromBonds(const std::vector<std::pair<int, int> >& bonds, int bondCutoff);
/**
* Add a tabulated function that may appear in the energy expression.
*
......
#ifndef OPENMM_OSRNGSEED_H_
#define OPENMM_OSRNGSEED_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) 2013 Stanford University and the Authors. *
* Authors: Robert T. McGibbon *
* 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. *
* -------------------------------------------------------------------------- */
/**
* Return an integer int for use as a seed for a random number generator.
*
* The behavior of this function is platform dependent. On Windows machines,
* this uses CryptGenRandom from the CryptoAPI to get a single int. On other
* platforms (*nix, apple), we read from /dev/urandom
*/
int osrngseed(void);
#endif /* OPENMM_OSRNGSEED_H_ */
\ No newline at end of file
......@@ -31,13 +31,13 @@
#include "openmm/AndersenThermostat.h"
#include "openmm/internal/AndersenThermostatImpl.h"
#include <ctime>
#include "openmm/internal/OSRngSeed.h"
using namespace OpenMM;
AndersenThermostat::AndersenThermostat(double defaultTemperature, double defaultCollisionFrequency) :
defaultTemp(defaultTemperature), defaultFreq(defaultCollisionFrequency) {
setRandomNumberSeed((int) time(NULL));
setRandomNumberSeed(osrngseed());
}
ForceImpl* AndersenThermostat::createImpl() const {
......
......@@ -33,8 +33,8 @@
#include "openmm/Context.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/OSRngSeed.h"
#include "openmm/kernels.h"
#include <ctime>
#include <string>
using namespace OpenMM;
......@@ -46,7 +46,7 @@ BrownianIntegrator::BrownianIntegrator(double temperature, double frictionCoeff,
setFriction(frictionCoeff);
setStepSize(stepSize);
setConstraintTolerance(1e-5);
setRandomNumberSeed((int) time(NULL));
setRandomNumberSeed(osrngseed());
}
void BrownianIntegrator::initialize(ContextImpl& contextRef) {
......
......@@ -34,8 +34,8 @@
#include "openmm/OpenMMException.h"
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/OSRngSeed.h"
#include "openmm/kernels.h"
#include <ctime>
#include <string>
using namespace OpenMM;
......@@ -45,7 +45,7 @@ using std::vector;
CustomIntegrator::CustomIntegrator(double stepSize) : globalsAreCurrent(true), forcesAreValid(false) {
setStepSize(stepSize);
setConstraintTolerance(1e-5);
setRandomNumberSeed((int) time(NULL));
setRandomNumberSeed(osrngseed());
kineticEnergy = "m*v*v/2";
}
......
......@@ -174,6 +174,33 @@ void CustomNonbondedForce::setExclusionParticles(int index, int particle1, int p
exclusions[index].particle1 = particle1;
exclusions[index].particle2 = particle2;
}
void CustomNonbondedForce::createExclusionsFromBonds(const vector<pair<int, int> >& bonds, int bondCutoff) {
if (bondCutoff < 1)
return;
vector<set<int> > exclusions(particles.size());
vector<set<int> > bonded12(exclusions.size());
for (int i = 0; i < (int) bonds.size(); ++i) {
int p1 = bonds[i].first;
int p2 = bonds[i].second;
exclusions[p1].insert(p2);
exclusions[p2].insert(p1);
bonded12[p1].insert(p2);
bonded12[p2].insert(p1);
}
for (int level = 0; level < bondCutoff-1; level++) {
vector<set<int> > currentExclusions = exclusions;
for (int i = 0; i < (int) particles.size(); i++) {
for (set<int>::const_iterator iter = currentExclusions[i].begin(); iter != currentExclusions[i].end(); ++iter)
exclusions[*iter].insert(bonded12[i].begin(), bonded12[i].end());
}
}
for (int i = 0; i < (int) exclusions.size(); ++i)
for (set<int>::const_iterator iter = exclusions[i].begin(); iter != exclusions[i].end(); ++iter)
if (*iter < i)
addExclusion(*iter, i);
}
int CustomNonbondedForce::addTabulatedFunction(const std::string& name, TabulatedFunction* function) {
functions.push_back(FunctionInfo(name, function));
return functions.size()-1;
......
......@@ -33,8 +33,8 @@
#include "openmm/Context.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/OSRngSeed.h"
#include "openmm/kernels.h"
#include <ctime>
#include <string>
using namespace OpenMM;
......@@ -46,7 +46,7 @@ LangevinIntegrator::LangevinIntegrator(double temperature, double frictionCoeff,
setFriction(frictionCoeff);
setStepSize(stepSize);
setConstraintTolerance(1e-5);
setRandomNumberSeed((int) time(NULL));
setRandomNumberSeed(osrngseed());
}
void LangevinIntegrator::initialize(ContextImpl& contextRef) {
......
......@@ -31,13 +31,13 @@
#include "openmm/MonteCarloAnisotropicBarostat.h"
#include "openmm/internal/MonteCarloAnisotropicBarostatImpl.h"
#include <ctime>
#include "openmm/internal/OSRngSeed.h"
using namespace OpenMM;
MonteCarloAnisotropicBarostat::MonteCarloAnisotropicBarostat(const Vec3& defaultPressure, double temperature, bool scaleX, bool scaleY, bool scaleZ, int frequency) :
defaultPressure(defaultPressure), temperature(temperature), scaleX(scaleX), scaleY(scaleY), scaleZ(scaleZ), frequency(frequency) {
setRandomNumberSeed((int) time(NULL));
setRandomNumberSeed(osrngseed());
}
ForceImpl* MonteCarloAnisotropicBarostat::createImpl() const {
......
......@@ -31,13 +31,13 @@
#include "openmm/MonteCarloBarostat.h"
#include "openmm/internal/MonteCarloBarostatImpl.h"
#include <ctime>
#include "openmm/internal/OSRngSeed.h"
using namespace OpenMM;
MonteCarloBarostat::MonteCarloBarostat(double defaultPressure, double temperature, int frequency) :
defaultPressure(defaultPressure), temperature(temperature), frequency(frequency) {
setRandomNumberSeed((int) time(NULL));
setRandomNumberSeed(osrngseed());
}
ForceImpl* MonteCarloBarostat::createImpl() const {
......
/* -------------------------------------------------------------------------- *
* 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) 2013 Stanford University and the Authors. *
* Authors: Robert T. McGibbon *
* 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 <stdexcept>
#if defined(_WIN32) || defined(__CYGWIN__)
#include <windows.h>
static HCRYPTPROV hCryptProv = 0;
#pragma comment(lib, "advapi32.lib")
#else
#include <fcntl.h>
#include <unistd.h>
#endif
#include "openmm/internal/OSRngSeed.h"
int osrngseed(void) {
int value;
#if defined(_WIN32) || defined(__CYGWIN__)
if (!::CryptAcquireContextW(&hCryptProv, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
throw std::runtime_error("Failed to initialize Windows random API (CryptoGen)");
}
if (!CryptGenRandom(hCryptProv, sizeof(int), (BYTE*) &value)) {
::CryptReleaseContext(hCryptProv, 0);
throw std::runtime_error("Failed to get random numbers");
}
if (!::CryptReleaseContext(hCryptProv, 0)) {
throw std::runtime_error("Failed to release Windows random API context");
}
#else
int m_fd = open("/dev/urandom", O_RDONLY);
if (m_fd == -1) {
throw std::runtime_error("Failed to open /dev/urandom");
}
if (read(m_fd, &value, sizeof(int)) != sizeof(int)) {
throw std::runtime_error("Failed to read bytes from /dev/urandom");
}
close(m_fd);
#endif
return value;
}
\ No newline at end of file
......@@ -33,10 +33,11 @@
#include "openmm/Context.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/OSRngSeed.h"
#include "openmm/kernels.h"
#include <limits>
#include <string>
#include <ctime>
using namespace OpenMM;
using std::string;
......@@ -47,7 +48,7 @@ VariableLangevinIntegrator::VariableLangevinIntegrator(double temperature, doubl
setFriction(frictionCoeff);
setErrorTolerance(errorTol);
setConstraintTolerance(1e-5);
setRandomNumberSeed((int) time(NULL));
setRandomNumberSeed(osrngseed());
}
void VariableLangevinIntegrator::initialize(ContextImpl& contextRef) {
......
......@@ -1520,7 +1520,7 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon
else
dispersionCoefficient = 0.0;
alpha = 0;
if (force.getNonbondedMethod() == NonbondedForce::Ewald && cu.getContextIndex() == 0) {
if (force.getNonbondedMethod() == NonbondedForce::Ewald) {
// Compute the Ewald parameters.
int kmaxx, kmaxy, kmaxz;
......@@ -1528,6 +1528,7 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon
defines["EWALD_ALPHA"] = cu.doubleToString(alpha);
defines["TWO_OVER_SQRT_PI"] = cu.doubleToString(2.0/sqrt(M_PI));
defines["USE_EWALD"] = "1";
if (cu.getContextIndex() == 0) {
ewaldSelfEnergy = -ONE_4PI_EPS0*alpha*sumSquaredCharges/sqrt(M_PI);
// Create the reciprocal space kernels.
......@@ -1547,7 +1548,8 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon
int elementSize = (cu.getUseDoublePrecision() ? sizeof(double2) : sizeof(float2));
cosSinSums = new CudaArray(cu, (2*kmaxx-1)*(2*kmaxy-1)*(2*kmaxz-1), elementSize, "cosSinSums");
}
else if (force.getNonbondedMethod() == NonbondedForce::PME && cu.getContextIndex() == 0) {
}
else if (force.getNonbondedMethod() == NonbondedForce::PME) {
// Compute the PME parameters.
int gridSizeX, gridSizeY, gridSizeZ;
......@@ -1560,6 +1562,7 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon
defines["EWALD_ALPHA"] = cu.doubleToString(alpha);
defines["TWO_OVER_SQRT_PI"] = cu.doubleToString(2.0/sqrt(M_PI));
defines["USE_EWALD"] = "1";
if (cu.getContextIndex() == 0) {
ewaldSelfEnergy = -ONE_4PI_EPS0*alpha*sumSquaredCharges/sqrt(M_PI);
pmeDefines["PME_ORDER"] = cu.intToString(PmeOrder);
pmeDefines["NUM_ATOMS"] = cu.intToString(numParticles);
......@@ -1698,6 +1701,7 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon
}
}
}
}
else
ewaldSelfEnergy = 0.0;
......
......@@ -7,7 +7,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-2012 Stanford University and the Authors. *
* Portions copyright (c) 2010-2014 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -170,6 +170,7 @@ void testVirtualSites() {
VerletIntegrator integrator(0.01);
Context context(system, integrator, platform);
context.setPositions(positions);
context.applyConstraints(1e-5);
State initialState = context.getState(State::Forces | State::Energy);
LocalEnergyMinimizer::minimize(context, tolerance);
State finalState = context.getState(State::Forces | State::Energy | State::Positions);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment