Commit 19d2885a authored by Lee-Ping's avatar Lee-Ping
Browse files

Merge github.com:SimTk/openmm

parents 99ef4344 57a6768e
This diff is collapsed.
This diff is collapsed.
......@@ -26,14 +26,16 @@ SET(BUILD_TESTING_STATIC OFF)
IF(OPENMM_BUILD_STATIC_LIB)
SET(BUILD_TESTING_STATIC ON)
ENDIF(OPENMM_BUILD_STATIC_LIB)
FOREACH(EX_ROOT ${CPP_EXAMPLES})
IF (BUILD_TESTING_SHARED)
# Link with shared library
ADD_EXECUTABLE(${EX_ROOT} ${EX_ROOT}.cpp)
SET_TARGET_PROPERTIES(${EX_ROOT}
PROPERTIES
PROJECT_LABEL "Example - ${EX_ROOT}")
PROPERTIES
PROJECT_LABEL "Example - ${EX_ROOT}"
LINK_FLAGS "${EXTRA_COMPILE_FLAGS}"
COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS}")
TARGET_LINK_LIBRARIES(${EX_ROOT} ${SHARED_TARGET})
ENDIF (BUILD_TESTING_SHARED)
......@@ -42,9 +44,10 @@ FOREACH(EX_ROOT ${CPP_EXAMPLES})
SET(EX_STATIC ${EX_ROOT}Static)
ADD_EXECUTABLE(${EX_STATIC} ${EX_ROOT}.cpp)
SET_TARGET_PROPERTIES(${EX_STATIC}
PROPERTIES
COMPILE_FLAGS "-DOPENMM_USE_STATIC_LIBRARIES"
PROJECT_LABEL "Example - ${EX_STATIC}")
PROPERTIES
PROJECT_LABEL "Example - ${EX_STATIC}"
LINK_FLAGS "${EXTRA_COMPILE_FLAGS}"
COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_USE_STATIC_LIBRARIES")
TARGET_LINK_LIBRARIES(${EX_STATIC} ${STATIC_TARGET})
ENDIF (BUILD_TESTING_STATIC)
......@@ -63,8 +66,10 @@ IF(OPENMM_BUILD_C_AND_FORTRAN_WRAPPERS)
# C++ libraries on the link line.
ADD_EXECUTABLE(${EX_ROOT} ${EX_ROOT}.c Empty.cpp)
SET_TARGET_PROPERTIES(${EX_ROOT}
PROPERTIES
PROJECT_LABEL "Example C - ${EX_ROOT}")
PROPERTIES
PROJECT_LABEL "Example C - ${EX_ROOT}"
LINK_FLAGS "${EXTRA_COMPILE_FLAGS}"
COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS}")
TARGET_LINK_LIBRARIES(${EX_ROOT} ${SHARED_TARGET})
ADD_DEPENDENCIES(${EX_ROOT} ApiWrappers)
ENDIF (BUILD_TESTING_SHARED)
......@@ -76,9 +81,10 @@ IF(OPENMM_BUILD_C_AND_FORTRAN_WRAPPERS)
# C++ libraries on the static link line.
ADD_EXECUTABLE(${EX_STATIC} ${EX_ROOT}.c Empty.cpp)
SET_TARGET_PROPERTIES(${EX_STATIC}
PROPERTIES
COMPILE_FLAGS "-DOPENMM_USE_STATIC_LIBRARIES"
PROJECT_LABEL "Example C - ${EX_STATIC}")
PROPERTIES
PROJECT_LABEL "Example C - ${EX_STATIC}"
LINK_FLAGS "${EXTRA_COMPILE_FLAGS}"
COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_USE_STATIC_LIBRARIES")
TARGET_LINK_LIBRARIES(${EX_STATIC} ${STATIC_TARGET})
ADD_DEPENDENCIES(${EX_STATIC} ApiWrappers)
ENDIF (BUILD_TESTING_STATIC)
......
......@@ -11,6 +11,8 @@
! other visualization tool to produce an animation of the resulting trajectory.
! -----------------------------------------------------------------------------
INCLUDE 'OpenMMFortranModule.f90'
PROGRAM HelloArgon
use OpenMM; implicit none
type(OpenMM_System) system
......
......@@ -17,6 +17,8 @@
! interface module.
! ------------------------------------------------------------------------------
INCLUDE 'OpenMMFortranModule.f90'
!-------------------------------------------------------------------------------
! ATOM, FORCE FIELD, AND SIMULATION PARAMETERS
!-------------------------------------------------------------------------------
......
......@@ -56,11 +56,11 @@ HelloSodiumChlorideInC: HelloSodiumChlorideInC.c
HelloArgonInFortran: HelloArgonInFortran.f90 openmm.mod
gfortran $(FFLAGS) HelloArgonInFortran.f90 \
-L$(LIB_DIR) $(LIBS) $(FCPPLIBS) -o HelloArgonInFortran
-I$(INCLUDE_DIR) -L$(LIB_DIR) $(LIBS) $(FCPPLIBS) -o HelloArgonInFortran
HelloSodiumChlorideInFortran: HelloSodiumChlorideInFortran.f90 openmm.mod
gfortran $(FFLAGS) HelloSodiumChlorideInFortran.f90 \
-L$(LIB_DIR) $(LIBS) $(FCPPLIBS) -o HelloSodiumChlorideInFortran
-I$(INCLUDE_DIR) -L$(LIB_DIR) $(LIBS) $(FCPPLIBS) -o HelloSodiumChlorideInFortran
# Build Fortran 95 Module file
......
from __future__ import print_function
import simtk.openmm.app as app
import simtk.openmm as mm
import simtk.unit as unit
import sys
from datetime import datetime
from optparse import OptionParser
def timeIntegration(context, steps):
"""Integrate a Context for a specified number of steps, then return how many seconds it took."""
context.getIntegrator().step(5) # Make sure everything is fully initialized
context.getState(getEnergy=True)
start = datetime.now()
context.getIntegrator().step(steps)
context.getState(getEnergy=True)
end = datetime.now()
elapsed = end -start
return elapsed.seconds + elapsed.microseconds*1e-6
def runOneTest(testName, options):
"""Perform a single benchmarking simulation."""
explicit = (testName in ('rf', 'pme', 'amoebapme'))
amoeba = (testName in ('amoebagk', 'amoebapme'))
hydrogenMass = None
print()
if amoeba:
print('Test: %s (epsilon=%g)' % (testName, options.epsilon))
elif testName == 'pme':
print('Test: pme (cutoff=%g)' % options.cutoff)
else:
print('Test: %s' % testName)
platform = mm.Platform.getPlatformByName(options.platform)
# Create the System.
if amoeba:
constraints = None
epsilon = float(options.epsilon)
if epsilon == 0:
polarization = 'direct'
else:
polarization = 'mutual'
if explicit:
ff = app.ForceField('amoeba2009.xml')
pdb = app.PDBFile('5dfr_solv-cube_equil.pdb')
cutoff = 0.7*unit.nanometers
vdwCutoff = 0.9*unit.nanometers
system = ff.createSystem(pdb.topology, nonbondedMethod=app.PME, nonbondedCutoff=cutoff, vdwCutoff=vdwCutoff, constraints=constraints, ewaldErrorTolerance=0.00075, mutualInducedTargetEpsilon=epsilon, polarization=polarization)
else:
ff = app.ForceField('amoeba2009.xml', 'amoeba2009_gk.xml')
pdb = app.PDBFile('5dfr_minimized.pdb')
cutoff = 2.0*unit.nanometers
vdwCutoff = 1.2*unit.nanometers
system = ff.createSystem(pdb.topology, nonbondedMethod=app.NoCutoff, constraints=constraints, mutualInducedTargetEpsilon=epsilon, polarization=polarization)
dt = 0.001*unit.picoseconds
else:
if explicit:
ff = app.ForceField('amber99sb.xml', 'tip3p.xml')
pdb = app.PDBFile('5dfr_solv-cube_equil.pdb')
if testName == 'pme':
method = app.PME
cutoff = options.cutoff
else:
method = app.CutoffPeriodic
cutoff = 1*unit.nanometers
else:
ff = app.ForceField('amber99sb.xml', 'amber99_obc.xml')
pdb = app.PDBFile('5dfr_minimized.pdb')
method = app.CutoffNonPeriodic
cutoff = 2*unit.nanometers
if options.heavy:
dt = 0.005*unit.picoseconds
constraints = app.AllBonds
hydrogenMass = 4*unit.amu
else:
dt = 0.002*unit.picoseconds
constraints = app.HBonds
hydrogenMass = None
system = ff.createSystem(pdb.topology, nonbondedMethod=method, nonbondedCutoff=cutoff, constraints=constraints, hydrogenMass=hydrogenMass)
print('Step Size: %g fs' % dt.value_in_unit(unit.femtoseconds))
properties = {}
if options.device is not None:
if platform.getName() == 'CUDA':
properties['CudaDeviceIndex'] = options.device
elif platform.getName() == 'OpenCL':
properties['OpenCLDeviceIndex'] = options.device
if options.precision is not None:
if platform.getName() == 'CUDA':
properties['CudaPrecision'] = options.precision
elif platform.getName() == 'OpenCL':
properties['OpenCLPrecision'] = options.precision
# Run the simulation.
integ = mm.LangevinIntegrator(300*unit.kelvin, 91*(1/unit.picoseconds), dt)
integ.setConstraintTolerance(1e-5)
if len(properties) > 0:
context = mm.Context(system, integ, platform, properties)
else:
context = mm.Context(system, integ, platform)
context.setPositions(pdb.positions)
context.setVelocitiesToTemperature(300*unit.kelvin)
steps = 20
while True:
time = timeIntegration(context, steps)
if time >= 0.5*options.seconds:
break
if time < 0.5:
steps = int(steps*1.0/time) # Integrate enough steps to get a reasonable estimate for how many we'll need.
else:
steps = int(steps*options.seconds/time)
print('Integrated %d steps in %g seconds' % (steps, time))
print('%g ns/day' % (dt*steps*86400/time).value_in_unit(unit.nanoseconds))
# Parse the command line options.
parser = OptionParser()
platformNames = [mm.Platform.getPlatform(i).getName() for i in range(mm.Platform.getNumPlatforms())]
parser.add_option('--platform', dest='platform', choices=platformNames, help='name of the platform to benchmark')
parser.add_option('--test', dest='test', choices=('gbsa', 'rf', 'pme', 'amoebagk', 'amoebapme'), help='the test to perform: gbsa, rf, pme, amoebagk, or amoebapme [default: all]')
parser.add_option('--pme-cutoff', default='0.9', dest='cutoff', type='float', help='direct space cutoff for PME in nm [default: 0.9]')
parser.add_option('--seconds', default='60', dest='seconds', type='float', help='target simulation length in seconds [default: 60]')
parser.add_option('--mutual-epsilon', default='1e-4', dest='epsilon', type='float', help='mutual induced epsilon for AMOEBA [default: 1e-4]')
parser.add_option('--heavy-hydrogens', action='store_true', default=False, dest='heavy', help='repartition mass to allow a larger time step')
parser.add_option('--device', default=None, dest='device', help='device index for CUDA or OpenCL')
parser.add_option('--precision', default='single', dest='precision', choices=('single', 'mixed', 'double'), help='precision mode for CUDA or OpenCL: single, mixed, or double [default: single]')
(options, args) = parser.parse_args()
if len(args) > 0:
parser.error('Unknown argument: '+args[0])
if options.platform is None:
parser.error('No platform specified')
print('Platform:', options.platform)
if options.platform in ('CUDA', 'OpenCL'):
print('Precision:', options.precision)
if options.device is not None:
print('Device:', options.device)
# Run the simulations.
if options.test is None:
for test in ('gbsa', 'rf', 'pme', 'amoebagk', 'amoebapme'):
try:
runOneTest(test, options)
except Exception as ex:
print('Test failed: %s' % ex.message)
else:
runOneTest(options.test, options)
......@@ -40,6 +40,7 @@
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
namespace Lepton {
......@@ -1002,7 +1003,7 @@ public:
return result;
}
else
return std::pow(args[0], value);
return std::pow(args[0], value);
}
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
double getValue() const {
......
#ifndef LEPTON_MSVC_ERFC_H_
#define LEPTON_MSVC_ERFC_H_
/*
* At least up to version 8 (VC++ 2005), Microsoft does not support the
* standard C99 erf() and erfc() functions. For now we're including these
* definitions for an MSVC compilation; if these are added later then
* the #ifdef below should change to compare _MSC_VER with a particular
* version level.
*/
#ifdef _MSC_VER
/***************************
* erf.cpp
* author: Steve Strand
* written: 29-Jan-04
***************************/
#include <cmath>
#define M_PI 3.14159265358979323846264338327950288
static const double rel_error= 1E-12; //calculate 12 significant figures
//you can adjust rel_error to trade off between accuracy and speed
//but don't ask for > 15 figures (assuming usual 52 bit mantissa in a double)
static double erfc(double x);
static double erf(double x)
//erf(x) = 2/sqrt(pi)*integral(exp(-t^2),t,0,x)
// = 2/sqrt(pi)*[x - x^3/3 + x^5/5*2! - x^7/7*3! + ...]
// = 1-erfc(x)
{
static const double two_sqrtpi= 1.128379167095512574; // 2/sqrt(pi)
if (fabs(x) > 2.2) {
return 1.0 - erfc(x); //use continued fraction when fabs(x) > 2.2
}
double sum= x, term= x, xsqr= x*x;
int j= 1;
do {
term*= xsqr/j;
sum-= term/(2*j+1);
++j;
term*= xsqr/j;
sum+= term/(2*j+1);
++j;
} while (fabs(term)/sum > rel_error);
return two_sqrtpi*sum;
}
static double erfc(double x)
//erfc(x) = 2/sqrt(pi)*integral(exp(-t^2),t,x,inf)
// = exp(-x^2)/sqrt(pi) * [1/x+ (1/2)/x+ (2/2)/x+ (3/2)/x+ (4/2)/x+ ...]
// = 1-erf(x)
//expression inside [] is a continued fraction so '+' means add to denominator only
{
static const double one_sqrtpi= 0.564189583547756287; // 1/sqrt(pi)
if (fabs(x) < 2.2) {
return 1.0 - erf(x); //use series when fabs(x) < 2.2
}
// Don't look for x==0 here!
if (x < 0) { //continued fraction only valid for x>0
return 2.0 - erfc(-x);
}
double a=1, b=x; //last two convergent numerators
double c=x, d=x*x+0.5; //last two convergent denominators
double q1, q2= b/d; //last two convergents (a/c and b/d)
double n= 1.0, t;
do {
t= a*n+b*x;
a= b;
b= t;
t= c*n+d*x;
c= d;
d= t;
n+= 0.5;
q1= q2;
q2= b/d;
} while (fabs(q1-q2)/q2 > rel_error);
return one_sqrtpi*exp(-x*x)*q2;
}
#endif // _MSC_VER
#endif // LEPTON_MSVC_ERFC_H_
#ifndef LEPTON_MSVC_ERFC_H_
#define LEPTON_MSVC_ERFC_H_
/*
* Up to version 11 (VC++ 2012), Microsoft does not support the
* standard C99 erf() and erfc() functions so we have to fake them here.
* These were added in version 12 (VC++ 2013), which sets _MSC_VER=1800
* (VC11 has _MSC_VER=1700).
*/
#if defined(_MSC_VER)
#define M_PI 3.14159265358979323846264338327950288
#if _MSC_VER <= 1700 // 1700 is VC11, 1800 is VC12
/***************************
* erf.cpp
* author: Steve Strand
* written: 29-Jan-04
***************************/
#include <cmath>
static const double rel_error= 1E-12; //calculate 12 significant figures
//you can adjust rel_error to trade off between accuracy and speed
//but don't ask for > 15 figures (assuming usual 52 bit mantissa in a double)
static double erfc(double x);
static double erf(double x)
//erf(x) = 2/sqrt(pi)*integral(exp(-t^2),t,0,x)
// = 2/sqrt(pi)*[x - x^3/3 + x^5/5*2! - x^7/7*3! + ...]
// = 1-erfc(x)
{
static const double two_sqrtpi= 1.128379167095512574; // 2/sqrt(pi)
if (fabs(x) > 2.2) {
return 1.0 - erfc(x); //use continued fraction when fabs(x) > 2.2
}
double sum= x, term= x, xsqr= x*x;
int j= 1;
do {
term*= xsqr/j;
sum-= term/(2*j+1);
++j;
term*= xsqr/j;
sum+= term/(2*j+1);
++j;
} while (fabs(term)/sum > rel_error);
return two_sqrtpi*sum;
}
static double erfc(double x)
//erfc(x) = 2/sqrt(pi)*integral(exp(-t^2),t,x,inf)
// = exp(-x^2)/sqrt(pi) * [1/x+ (1/2)/x+ (2/2)/x+ (3/2)/x+ (4/2)/x+ ...]
// = 1-erf(x)
//expression inside [] is a continued fraction so '+' means add to denominator only
{
static const double one_sqrtpi= 0.564189583547756287; // 1/sqrt(pi)
if (fabs(x) < 2.2) {
return 1.0 - erf(x); //use series when fabs(x) < 2.2
}
// Don't look for x==0 here!
if (x < 0) { //continued fraction only valid for x>0
return 2.0 - erfc(-x);
}
double a=1, b=x; //last two convergent numerators
double c=x, d=x*x+0.5; //last two convergent denominators
double q1, q2= b/d; //last two convergents (a/c and b/d)
double n= 1.0, t;
do {
t= a*n+b*x;
a= b;
b= t;
t= c*n+d*x;
c= d;
d= t;
n+= 0.5;
q1= q2;
q2= b/d;
} while (fabs(q1-q2)/q2 > rel_error);
return one_sqrtpi*exp(-x*x)*q2;
}
#endif // _MSC_VER <= 1700
#endif // _MSC_VER
#endif // LEPTON_MSVC_ERFC_H_
......@@ -90,8 +90,10 @@ namespace OpenMM_SFMT {
class SFMTData {
public:
/** Possibly incorrectly aligned memory for internal state array */
char baseData[(N+1)*sizeof(w128_t)];
/** the 128-bit internal state array */
w128_t sfmt[N];
w128_t* sfmt;
/** the 32bit integer pointer to the 128-bit internal state array */
uint32_t *psfmt32;
#if !defined(BIG_ENDIAN64) || defined(ONLY64)
......@@ -106,6 +108,9 @@ public:
/** a parity check vector which certificate the period of 2^{MEXP} */
uint32_t parity[4];
SFMTData() {
char* offsetData = baseData+15;
offsetData -= (long long)offsetData&0xF;
sfmt = (w128_t*) offsetData;
psfmt32 = &sfmt[0].u[0];
#if !defined(BIG_ENDIAN64) || defined(ONLY64)
psfmt64 = (uint64_t *)&sfmt[0].u[0];
......
......@@ -88,7 +88,12 @@ const string& Platform::getPropertyDefaultValue(const string& property) const {
}
void Platform::setPropertyDefaultValue(const string& property, const string& value) {
defaultProperties[property] = value;
for (int i = 0; i < (int) platformProperties.size(); i++)
if (platformProperties[i] == property) {
defaultProperties[property] = value;
return;
}
throw OpenMMException("setPropertyDefaultValue: Illegal property name");
}
void Platform::contextCreated(ContextImpl& context, const map<string, string>& properties) const {
......
......@@ -69,5 +69,6 @@
#include "openmm/VerletIntegrator.h"
#include "openmm/VirtualSite.h"
#include "openmm/Platform.h"
#include "openmm/serialization/XmlSerializer.h"
#endif /*OPENMM_H_*/
......@@ -74,6 +74,15 @@ public:
double getDefaultTemperature() const {
return defaultTemp;
}
/**
* Set the default temperature of the heat bath. This will affect any new Contexts you create,
* but not ones that already exist.
*
* @param temperature the default temperature of the heat bath (in Kelvin)
*/
void setDefaultTemperature(double temperature) {
defaultTemp = temperature;
}
/**
* Get the default collision frequency (in 1/ps).
*
......@@ -82,6 +91,15 @@ public:
double getDefaultCollisionFrequency() const {
return defaultFreq;
}
/**
* Set the default collision frequency. This will affect any new Contexts you create,
* but not ones that already exist.
*
* @param frequency the default collision frequency (in 1/ps)
*/
void setDefaultCollisionFrequency(double frequency) {
defaultFreq = frequency;
}
/**
* Get the random number seed. See setRandomNumberSeed() for details.
*/
......
......@@ -100,6 +100,15 @@ public:
const Vec3& getDefaultPressure() const {
return defaultPressure;
}
/**
* Set the default pressure acting on the system. This will affect any new Contexts you create,
* but not ones that already exist.
*
* @param pressure the default pressure acting on the system, measured in bar.
*/
void setDefaultPressure(const Vec3& pressure) {
defaultPressure = pressure;
}
/**
* Get whether to allow the X dimension of the periodic box to change size.
*/
......
......@@ -74,6 +74,15 @@ public:
double getDefaultPressure() const {
return defaultPressure;
}
/**
* Set the default pressure acting on the system. This will affect any new Contexts you create,
* but not ones that already exist.
*
* @param pressure the default pressure acting on the system, measured in bar.
*/
void setDefaultPressure(double pressure) {
defaultPressure = pressure;
}
/**
* 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.
......
......@@ -34,6 +34,7 @@
#include "Vec3.h"
#include <map>
#include <string>
#include <vector>
#include "internal/windowsExport.h"
......
#ifndef OPENMM_MSVC_ERFC_H_
#ifndef OPENMM_MSVC_ERFC_H_
#define OPENMM_MSVC_ERFC_H_
/*
* At least up to version 8 (VC++ 2005), Microsoft does not support the
* standard C99 erf() and erfc() functions. For now we're including these
* definitions for an MSVC compilation; if these are added later then
* the #ifdef below should change to compare _MSC_VER with a particular
* version level.
* Up to version 11 (VC++ 2012), Microsoft does not support the
* standard C99 erf() and erfc() functions so we have to fake them here.
* These were added in version 12 (VC++ 2013), which sets _MSC_VER=1800
* (VC11 has _MSC_VER=1700).
*/
#ifdef _MSC_VER
#if defined(_MSC_VER)
#define M_PI 3.14159265358979323846264338327950288
#if _MSC_VER <= 1700 // 1700 is VC11, 1800 is VC12
/***************************
* erf.cpp
* author: Steve Strand
......@@ -81,6 +81,7 @@ static double erfc(double x)
return one_sqrtpi*exp(-x*x)*q2;
}
#endif // _MSC_VER <= 1700
#endif // _MSC_VER
#endif // OPENMM_MSVC_ERFC_H_
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