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
4b1c362c
Commit
4b1c362c
authored
May 19, 2014
by
Robert McGibbon
Browse files
Seed the rng from urandom
parent
0b8201b2
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
101 additions
and
21 deletions
+101
-21
openmmapi/include/openmm/Context.h
openmmapi/include/openmm/Context.h
+2
-2
openmmapi/include/openmm/internal/osrngseed.h
openmmapi/include/openmm/internal/osrngseed.h
+79
-0
openmmapi/src/AndersenThermostat.cpp
openmmapi/src/AndersenThermostat.cpp
+2
-2
openmmapi/src/BrownianIntegrator.cpp
openmmapi/src/BrownianIntegrator.cpp
+2
-2
openmmapi/src/CustomIntegrator.cpp
openmmapi/src/CustomIntegrator.cpp
+2
-2
openmmapi/src/LangevinIntegrator.cpp
openmmapi/src/LangevinIntegrator.cpp
+2
-2
openmmapi/src/MonteCarloAnisotropicBarostat.cpp
openmmapi/src/MonteCarloAnisotropicBarostat.cpp
+2
-2
openmmapi/src/MonteCarloBarostat.cpp
openmmapi/src/MonteCarloBarostat.cpp
+2
-2
openmmapi/src/VariableLangevinIntegrator.cpp
openmmapi/src/VariableLangevinIntegrator.cpp
+3
-2
plugins/drude/openmmapi/src/DrudeLangevinIntegrator.cpp
plugins/drude/openmmapi/src/DrudeLangevinIntegrator.cpp
+2
-2
plugins/rpmd/openmmapi/src/RPMDIntegrator.cpp
plugins/rpmd/openmmapi/src/RPMDIntegrator.cpp
+3
-3
No files found.
openmmapi/include/openmm/Context.h
View file @
4b1c362c
...
@@ -35,12 +35,12 @@
...
@@ -35,12 +35,12 @@
#include "Integrator.h"
#include "Integrator.h"
#include "State.h"
#include "State.h"
#include "System.h"
#include "System.h"
#include <ctime>
#include <iosfwd>
#include <iosfwd>
#include <map>
#include <map>
#include <string>
#include <string>
#include <vector>
#include <vector>
#include "internal/windowsExport.h"
#include "internal/windowsExport.h"
#include "internal/osrngseed.h"
namespace
OpenMM
{
namespace
OpenMM
{
...
@@ -164,7 +164,7 @@ public:
...
@@ -164,7 +164,7 @@ public:
* @param temperature the temperature for which to select the velocities (measured in Kelvin)
* @param temperature the temperature for which to select the velocities (measured in Kelvin)
* @param randomSeed the random number seed to use when selecting velocities
* @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.
* Get the value of an adjustable parameter defined by a Force object in the System.
*
*
...
...
openmmapi/include/openmm/internal/osrngseed.h
0 → 100644
View file @
4b1c362c
#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. *
* -------------------------------------------------------------------------- */
#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
/**
* 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
)
{
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
;
}
#endif
/* OPENMM_OSRNGSEED_H_ */
\ No newline at end of file
openmmapi/src/AndersenThermostat.cpp
View file @
4b1c362c
...
@@ -31,13 +31,13 @@
...
@@ -31,13 +31,13 @@
#include "openmm/AndersenThermostat.h"
#include "openmm/AndersenThermostat.h"
#include "openmm/internal/AndersenThermostatImpl.h"
#include "openmm/internal/AndersenThermostatImpl.h"
#include
<ctime>
#include
"openmm/internal/osrngseed.h"
using
namespace
OpenMM
;
using
namespace
OpenMM
;
AndersenThermostat
::
AndersenThermostat
(
double
defaultTemperature
,
double
defaultCollisionFrequency
)
:
AndersenThermostat
::
AndersenThermostat
(
double
defaultTemperature
,
double
defaultCollisionFrequency
)
:
defaultTemp
(
defaultTemperature
),
defaultFreq
(
defaultCollisionFrequency
)
{
defaultTemp
(
defaultTemperature
),
defaultFreq
(
defaultCollisionFrequency
)
{
setRandomNumberSeed
(
(
int
)
time
(
NULL
));
setRandomNumberSeed
(
osrngseed
(
));
}
}
ForceImpl
*
AndersenThermostat
::
createImpl
()
const
{
ForceImpl
*
AndersenThermostat
::
createImpl
()
const
{
...
...
openmmapi/src/BrownianIntegrator.cpp
View file @
4b1c362c
...
@@ -33,8 +33,8 @@
...
@@ -33,8 +33,8 @@
#include "openmm/Context.h"
#include "openmm/Context.h"
#include "openmm/OpenMMException.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/osrngseed.h"
#include "openmm/kernels.h"
#include "openmm/kernels.h"
#include <ctime>
#include <string>
#include <string>
using
namespace
OpenMM
;
using
namespace
OpenMM
;
...
@@ -46,7 +46,7 @@ BrownianIntegrator::BrownianIntegrator(double temperature, double frictionCoeff,
...
@@ -46,7 +46,7 @@ BrownianIntegrator::BrownianIntegrator(double temperature, double frictionCoeff,
setFriction
(
frictionCoeff
);
setFriction
(
frictionCoeff
);
setStepSize
(
stepSize
);
setStepSize
(
stepSize
);
setConstraintTolerance
(
1e-5
);
setConstraintTolerance
(
1e-5
);
setRandomNumberSeed
(
(
int
)
time
(
NULL
));
setRandomNumberSeed
(
osrngseed
(
));
}
}
void
BrownianIntegrator
::
initialize
(
ContextImpl
&
contextRef
)
{
void
BrownianIntegrator
::
initialize
(
ContextImpl
&
contextRef
)
{
...
...
openmmapi/src/CustomIntegrator.cpp
View file @
4b1c362c
...
@@ -34,8 +34,8 @@
...
@@ -34,8 +34,8 @@
#include "openmm/OpenMMException.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/osrngseed.h"
#include "openmm/kernels.h"
#include "openmm/kernels.h"
#include <ctime>
#include <string>
#include <string>
using
namespace
OpenMM
;
using
namespace
OpenMM
;
...
@@ -45,7 +45,7 @@ using std::vector;
...
@@ -45,7 +45,7 @@ using std::vector;
CustomIntegrator
::
CustomIntegrator
(
double
stepSize
)
:
globalsAreCurrent
(
true
),
forcesAreValid
(
false
)
{
CustomIntegrator
::
CustomIntegrator
(
double
stepSize
)
:
globalsAreCurrent
(
true
),
forcesAreValid
(
false
)
{
setStepSize
(
stepSize
);
setStepSize
(
stepSize
);
setConstraintTolerance
(
1e-5
);
setConstraintTolerance
(
1e-5
);
setRandomNumberSeed
(
(
int
)
time
(
NULL
));
setRandomNumberSeed
(
osrngseed
(
));
kineticEnergy
=
"m*v*v/2"
;
kineticEnergy
=
"m*v*v/2"
;
}
}
...
...
openmmapi/src/LangevinIntegrator.cpp
View file @
4b1c362c
...
@@ -33,8 +33,8 @@
...
@@ -33,8 +33,8 @@
#include "openmm/Context.h"
#include "openmm/Context.h"
#include "openmm/OpenMMException.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/osrngseed.h"
#include "openmm/kernels.h"
#include "openmm/kernels.h"
#include <ctime>
#include <string>
#include <string>
using
namespace
OpenMM
;
using
namespace
OpenMM
;
...
@@ -46,7 +46,7 @@ LangevinIntegrator::LangevinIntegrator(double temperature, double frictionCoeff,
...
@@ -46,7 +46,7 @@ LangevinIntegrator::LangevinIntegrator(double temperature, double frictionCoeff,
setFriction
(
frictionCoeff
);
setFriction
(
frictionCoeff
);
setStepSize
(
stepSize
);
setStepSize
(
stepSize
);
setConstraintTolerance
(
1e-5
);
setConstraintTolerance
(
1e-5
);
setRandomNumberSeed
(
(
int
)
time
(
NULL
));
setRandomNumberSeed
(
osrngseed
(
));
}
}
void
LangevinIntegrator
::
initialize
(
ContextImpl
&
contextRef
)
{
void
LangevinIntegrator
::
initialize
(
ContextImpl
&
contextRef
)
{
...
...
openmmapi/src/MonteCarloAnisotropicBarostat.cpp
View file @
4b1c362c
...
@@ -31,13 +31,13 @@
...
@@ -31,13 +31,13 @@
#include "openmm/MonteCarloAnisotropicBarostat.h"
#include "openmm/MonteCarloAnisotropicBarostat.h"
#include "openmm/internal/MonteCarloAnisotropicBarostatImpl.h"
#include "openmm/internal/MonteCarloAnisotropicBarostatImpl.h"
#include
<ctime>
#include
"openmm/internal/osrngseed.h"
using
namespace
OpenMM
;
using
namespace
OpenMM
;
MonteCarloAnisotropicBarostat
::
MonteCarloAnisotropicBarostat
(
const
Vec3
&
defaultPressure
,
double
temperature
,
bool
scaleX
,
bool
scaleY
,
bool
scaleZ
,
int
frequency
)
:
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
)
{
defaultPressure
(
defaultPressure
),
temperature
(
temperature
),
scaleX
(
scaleX
),
scaleY
(
scaleY
),
scaleZ
(
scaleZ
),
frequency
(
frequency
)
{
setRandomNumberSeed
(
(
int
)
time
(
NULL
));
setRandomNumberSeed
(
osrngseed
(
));
}
}
ForceImpl
*
MonteCarloAnisotropicBarostat
::
createImpl
()
const
{
ForceImpl
*
MonteCarloAnisotropicBarostat
::
createImpl
()
const
{
...
...
openmmapi/src/MonteCarloBarostat.cpp
View file @
4b1c362c
...
@@ -31,13 +31,13 @@
...
@@ -31,13 +31,13 @@
#include "openmm/MonteCarloBarostat.h"
#include "openmm/MonteCarloBarostat.h"
#include "openmm/internal/MonteCarloBarostatImpl.h"
#include "openmm/internal/MonteCarloBarostatImpl.h"
#include
<ctime>
#include
"openmm/internal/osrngseed.h"
using
namespace
OpenMM
;
using
namespace
OpenMM
;
MonteCarloBarostat
::
MonteCarloBarostat
(
double
defaultPressure
,
double
temperature
,
int
frequency
)
:
MonteCarloBarostat
::
MonteCarloBarostat
(
double
defaultPressure
,
double
temperature
,
int
frequency
)
:
defaultPressure
(
defaultPressure
),
temperature
(
temperature
),
frequency
(
frequency
)
{
defaultPressure
(
defaultPressure
),
temperature
(
temperature
),
frequency
(
frequency
)
{
setRandomNumberSeed
(
(
int
)
time
(
NULL
));
setRandomNumberSeed
(
osrngseed
(
));
}
}
ForceImpl
*
MonteCarloBarostat
::
createImpl
()
const
{
ForceImpl
*
MonteCarloBarostat
::
createImpl
()
const
{
...
...
openmmapi/src/VariableLangevinIntegrator.cpp
View file @
4b1c362c
...
@@ -33,10 +33,11 @@
...
@@ -33,10 +33,11 @@
#include "openmm/Context.h"
#include "openmm/Context.h"
#include "openmm/OpenMMException.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/osrngseed.h"
#include "openmm/kernels.h"
#include "openmm/kernels.h"
#include <limits>
#include <limits>
#include <string>
#include <string>
#include <ctime>
using
namespace
OpenMM
;
using
namespace
OpenMM
;
using
std
::
string
;
using
std
::
string
;
...
@@ -47,7 +48,7 @@ VariableLangevinIntegrator::VariableLangevinIntegrator(double temperature, doubl
...
@@ -47,7 +48,7 @@ VariableLangevinIntegrator::VariableLangevinIntegrator(double temperature, doubl
setFriction
(
frictionCoeff
);
setFriction
(
frictionCoeff
);
setErrorTolerance
(
errorTol
);
setErrorTolerance
(
errorTol
);
setConstraintTolerance
(
1e-5
);
setConstraintTolerance
(
1e-5
);
setRandomNumberSeed
(
(
int
)
time
(
NULL
));
setRandomNumberSeed
(
osrngseed
(
));
}
}
void
VariableLangevinIntegrator
::
initialize
(
ContextImpl
&
contextRef
)
{
void
VariableLangevinIntegrator
::
initialize
(
ContextImpl
&
contextRef
)
{
...
...
plugins/drude/openmmapi/src/DrudeLangevinIntegrator.cpp
View file @
4b1c362c
...
@@ -33,8 +33,8 @@
...
@@ -33,8 +33,8 @@
#include "openmm/Context.h"
#include "openmm/Context.h"
#include "openmm/OpenMMException.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/osrngseed.h"
#include "openmm/DrudeKernels.h"
#include "openmm/DrudeKernels.h"
#include <cmath>
#include <ctime>
#include <ctime>
#include <string>
#include <string>
...
@@ -49,7 +49,7 @@ DrudeLangevinIntegrator::DrudeLangevinIntegrator(double temperature, double fric
...
@@ -49,7 +49,7 @@ DrudeLangevinIntegrator::DrudeLangevinIntegrator(double temperature, double fric
setDrudeFriction
(
drudeFrictionCoeff
);
setDrudeFriction
(
drudeFrictionCoeff
);
setStepSize
(
stepSize
);
setStepSize
(
stepSize
);
setConstraintTolerance
(
1e-5
);
setConstraintTolerance
(
1e-5
);
setRandomNumberSeed
(
(
int
)
time
(
NULL
));
setRandomNumberSeed
(
osrngseed
(
));
}
}
void
DrudeLangevinIntegrator
::
initialize
(
ContextImpl
&
contextRef
)
{
void
DrudeLangevinIntegrator
::
initialize
(
ContextImpl
&
contextRef
)
{
...
...
plugins/rpmd/openmmapi/src/RPMDIntegrator.cpp
View file @
4b1c362c
...
@@ -33,10 +33,10 @@
...
@@ -33,10 +33,10 @@
#include "openmm/Context.h"
#include "openmm/Context.h"
#include "openmm/OpenMMException.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/osrngseed.h"
#include "openmm/RpmdKernels.h"
#include "openmm/RpmdKernels.h"
#include "SimTKOpenMMRealType.h"
#include "SimTKOpenMMRealType.h"
#include <cmath>
#include <cmath>
#include <ctime>
#include <string>
#include <string>
using
namespace
OpenMM
;
using
namespace
OpenMM
;
...
@@ -48,7 +48,7 @@ RPMDIntegrator::RPMDIntegrator(int numCopies, double temperature, double frictio
...
@@ -48,7 +48,7 @@ RPMDIntegrator::RPMDIntegrator(int numCopies, double temperature, double frictio
setFriction
(
frictionCoeff
);
setFriction
(
frictionCoeff
);
setStepSize
(
stepSize
);
setStepSize
(
stepSize
);
setConstraintTolerance
(
1e-5
);
setConstraintTolerance
(
1e-5
);
setRandomNumberSeed
(
(
int
)
time
(
NULL
));
setRandomNumberSeed
(
osrngseed
(
));
}
}
RPMDIntegrator
::
RPMDIntegrator
(
int
numCopies
,
double
temperature
,
double
frictionCoeff
,
double
stepSize
)
:
RPMDIntegrator
::
RPMDIntegrator
(
int
numCopies
,
double
temperature
,
double
frictionCoeff
,
double
stepSize
)
:
...
@@ -57,7 +57,7 @@ RPMDIntegrator::RPMDIntegrator(int numCopies, double temperature, double frictio
...
@@ -57,7 +57,7 @@ RPMDIntegrator::RPMDIntegrator(int numCopies, double temperature, double frictio
setFriction
(
frictionCoeff
);
setFriction
(
frictionCoeff
);
setStepSize
(
stepSize
);
setStepSize
(
stepSize
);
setConstraintTolerance
(
1e-5
);
setConstraintTolerance
(
1e-5
);
setRandomNumberSeed
(
(
int
)
time
(
NULL
));
setRandomNumberSeed
(
osrngseed
(
));
}
}
void
RPMDIntegrator
::
initialize
(
ContextImpl
&
contextRef
)
{
void
RPMDIntegrator
::
initialize
(
ContextImpl
&
contextRef
)
{
...
...
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