Commit 7a36f461 authored by Mark Friedrichs's avatar Mark Friedrichs
Browse files

dded GB/VI to Cuda platform

Free energy plugin added
Plugin will not run w/ Obc or GB/VI forces unless line 2004 of gpu.cpp (gpu->sim.totalNonbondOutputBuffers  = 2*gpu->sim.nonbondOutputBuffers;) is commented in -- working on removing this constraint
Also unit tests for GB/VI currently fail 
parent 43ebedfb
......@@ -632,7 +632,9 @@ int CpuObc::computeBornEnergyForces( RealOpenMM* bornRadii, RealOpenMM** atomCoo
// cal to Joule conversion
RealOpenMM conversion = (RealOpenMM)0.4184;
RealOpenMM conversion = (RealOpenMM)(0.4184);
// RealOpenMM conversion = (RealOpenMM)(0.4184/0.987);
//fprintf( stderr, "Obc includes .987 XXXXXXXXXXXXXXXXXXXXXXX\n" );
for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
inputForces[atomI][0] += conversion*forces[atomI][0];
inputForces[atomI][1] += conversion*forces[atomI][1];
......
......@@ -368,7 +368,7 @@ int main() {
testEnergy1();
*/
// testSingleParticle();
testEnergyTwoParticle();
// testEnergyTwoParticle();
testEnergyEthane();
}
catch(const exception& e) {
......
#---------------------------------------------------
# OpenMM FreeEnergy Plugin
#
# Creates OpenMM FreeEnergy plugin library, base name=OpenMM.
# Default libraries are shared & optimized. Variants
# are created for static (_static) and debug (_d).
#
# Windows:
# OpenMM[_d].dll
# OpenMM[_d].lib
# OpenMM_static[_d].lib
# Unix:
# libOpenMM[_d].so
# libOpenMM_static[_d].a
#----------------------------------------------------
# On Linux it appears that cmake 2.4 does not work with Cuda cmake rules
#CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
# Does someone at Kitware actually believe that this policy crap
# might actually make cmake LESS brittle?
# (Probably the same genius who came up the endif(allthesamecrap) syntax)
# Older cmake versions do not have cmake_policy command
# Cmake 2.4.5, the default cmake on red hat linux, has the
# cmake_policy command, but it does not work
# "if(POLICY ..." does not work with cmake 2.4.[56] on red hat
# (cmake 2.4.7 is OK)
#if(COMMAND cmake_policy)
# if(CMAKE_MAJOR_VERSION GREATER 2 OR CMAKE_MINOR_VERSION GREATER 5)
# cmake_policy(SET CMP0003 NEW)
# cmake_policy(SET CMP0005 NEW)
# endif(CMAKE_MAJOR_VERSION GREATER 2 OR CMAKE_MINOR_VERSION GREATER 5)
# if(CMAKE_MAJOR_VERSION GREATER 2 OR CMAKE_MINOR_VERSION GREATER 6 OR CMAKE_PATCH_VERSION GREATER 2)
# cmake_policy(SET CMP0011 NEW)
# endif(CMAKE_MAJOR_VERSION GREATER 2 OR CMAKE_MINOR_VERSION GREATER 6 OR CMAKE_PATCH_VERSION GREATER 2)
#endif(COMMAND cmake_policy)
# Don't create a new project name if this is part of a mega-build from the
# parent directory
#IF( NOT PROJECT_NAME )
# PROJECT (OpenMM)
#ENDIF( NOT PROJECT_NAME )
# Where to install
#IF(${CMAKE_C_COMPILER} MATCHES "gcc")
# IF(NOT OPENMM_INSTALL_PREFIX)
# SET(OPENMM_INSTALL_PREFIX "/usr/local/openmm" CACHE PATH "Where to install OpenMM")
# ENDIF(NOT OPENMM_INSTALL_PREFIX)
#ELSE(${CMAKE_C_COMPILER} MATCHES "gcc")
# IF(NOT OPENMM_INSTALL_PREFIX)
# SET(OPENMM_INSTALL_PREFIX "$ENV{ProgramFiles}/OpenMM" CACHE PATH "Where to install OpenMM")
# ENDIF(NOT OPENMM_INSTALL_PREFIX)
#ENDIF(${CMAKE_C_COMPILER} MATCHES "gcc")
#MARK_AS_ADVANCED(OPENMM_INSTALL_PREFIX)
# It seems that on linux and mac, everything is trying to be installed in /usr/local/openmm
# But if every install target is prefixed with /openmm/, on Windows the install files
# end up in C:/Program Files/OpenMM/openmm/ which is ugly.
# Better to set CMAKE_INSTALL_PREFIX to /usr/local/openmm and leave /openmm/ off the
# install target names. Plus, the user now has the opportunity to install into /usr/local/
# if she so chooses. --cmb
#IF(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT})
# SET(CMAKE_INSTALL_PREFIX ${OPENMM_INSTALL_PREFIX} CACHE PATH "Where to install OpenMM" FORCE)
#ENDIF(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT})
#INCLUDE(Dart)
SET(LOG TRUE)
# ----------------------------------------------------------------------------
IF(LOG)
SET(LOG_FILE "CMakeLog.txt" )
FILE( WRITE ${LOG_FILE} "In OpenMM Cmake\n")
ENDIF(LOG)
IF(LOG)
MACRO(LOG_DIR LOG_FILE DIR_LIST )
FILE( APPEND ${LOG_FILE} "\n${DIR_LIST}\n")
FOREACH(currentFile ${ARGN})
FILE( APPEND ${LOG_FILE} " ${currentFile}\n" )
ENDFOREACH(currentFile)
ENDMACRO(LOG_DIR)
ENDIF(LOG)
# ----------------------------------------------------------------------------
# The source is organized into subdirectories, but we handle them all from
# this CMakeLists file rather than letting CMake visit them as SUBDIRS.
SET(OPENMM_FREE_ENERGY_PLUGIN_SOURCE_SUBDIRS . openmmapi platforms/reference)
# The build system will set ARCH64 for 64 bit builds, which require
# use of the lib64/ library directories rather than lib/.
#SET( ARCH64 OFF CACHE BOOL "ON for 64bit builds, OFF for 32bit builds")
#MARK_AS_ADVANCED( ARCH64 )
#IF (ARCH64)
# SET(LIB64 64)
#ELSE (ARCH64)
# SET(LIB64) # nothing
#ENDIF (ARCH64)
#IF( CMAKE_SIZEOF_VOID_P EQUAL 8 )
# SET( LIB64 64 )
#ELSE( CMAKE_SIZEOF_VOID_P EQUAL 8 )
# SET( LIB64 )
#ENDIF( CMAKE_SIZEOF_VOID_P EQUAL 8 )
# Build 32 bit binaries, since CUDA doesn't currently work with 64 bit
#IF (APPLE)
# SET (CMAKE_CXX_FLAGS "-arch i386")
# SET (CMAKE_C_FLAGS "-arch i386")
#ENDIF (APPLE)
#
#IF(UNIX AND NOT CMAKE_BUILD_TYPE)
# SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Debug or Release build" FORCE)
#ENDIF (UNIX AND NOT CMAKE_BUILD_TYPE)
#
#IF (NOT CMAKE_CXX_FLAGS_DEBUG)
# SET(CMAKE_CXX_FLAGS_DEBUG "-g" CACHE STRING "To use when CMAKE_BUILD_TYPE=Debug" FORCE)
#ENDIF (NOT CMAKE_CXX_FLAGS_DEBUG)
#
#IF (NOT CMAKE_CXX_FLAGS_RELEASE)
# SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING
# "To use when CMAKE_BUILD_TYPE=Release" FORCE)
#ENDIF (NOT CMAKE_CXX_FLAGS_RELEASE)
# Collect up information about the version of the OpenMM library we're building
# and make it available to the code so it can be built into the binaries.
SET(OPENMM_FREE_ENERGY_LIBRARY_NAME OpenMMFreeEnergy)
SET(OPENMM_FREE_ENERGY_MAJOR_VERSION 1)
SET(OPENMM_FREE_ENERGY_MINOR_VERSION 0)
SET(OPENMM_FREE_ENERGY_BUILD_VERSION 0)
#SET(OPENMM_COPYRIGHT_YEARS "2009")
# underbar separated list of dotted authors, no spaces or commas
#SET(OPENMM_AUTHORS "Peter.Eastman")
# Get the subversion revision number if we can
# It's possible that WIN32 installs use svnversion through cygwin
# so we'll try for both svnversion.exe and svnversion. Note that
# this will result in warnings if all you have is Tortoise without
# Cygwin, and your "about" string will say "unknown" rather than
# providing the SVN version of the source.
#FIND_PROGRAM (SVNVERSION_EXE svnversion.exe
# PATHS "C:/cygwin/bin"
#)
#IF (SVNVERSION_EXE)
# EXEC_PROGRAM (${SVNVERSION_EXE}
# ARGS \"${CMAKE_CURRENT_SOURCE_DIR}\"
# OUTPUT_VARIABLE OPENMM_SVN_REVISION )
#ELSE (SVNVERSION_EXE)
# FIND_PROGRAM (SVNVERSION svnversion)
# IF (SVNVERSION)
# EXEC_PROGRAM (${SVNVERSION}
# ARGS "${CMAKE_CURRENT_SOURCE_DIR}"
# OUTPUT_VARIABLE OPENMM_SVN_REVISION)
# ELSE (SVNVERSION)
# MESSAGE (STATUS
# "Could not find 'svnversion' executable; 'about' will be wrong. (Cygwin provides one on Windows.)"
# )
# SET (OPENMM_SVN_REVISION unknown)
# ENDIF (SVNVERSION)
#ENDIF (SVNVERSION_EXE)
# Remove colon from build version, for easier placement in directory names
#STRING(REPLACE ":" "_" OPENMM_SVN_REVISION ${OPENMM_SVN_REVISION})
ADD_DEFINITIONS(-DOPENMM_FREE_ENERGY_LIBRARY_NAME=${OPENMM_FREE_ENERGY_LIBRARY_NAME}
-DOPENMM_FREE_ENERGY_MAJOR_VERSION=${OPENMM_FREE_ENERGY_MAJOR_VERSION}
-DOPENMM_FREE_ENERGY_MINOR_VERSION=${OPENMM_FREE_ENERGY_MINOR_VERSION}
-DOPENMM_FREE_ENERGY_BUILD_VERSION=${OPENMM_FREE_ENERGY_BUILD_VERSION})
# CMake quotes automatically when building Visual Studio projects but we need
# to add them ourselves for Linux or Cygwin. Two cases to avoid duplicate quotes
# in Visual Studio which end up in the binary.
#
#IF (${CMAKE_GENERATOR} MATCHES "Visual Studio")
# SET(NEED_QUOTES FALSE)
#ELSE (${CMAKE_GENERATOR} MATCHES "Visual Studio")
# SET(NEED_QUOTES TRUE)
#ENDIF (${CMAKE_GENERATOR} MATCHES "Visual Studio")
##TODO: doesn't work without quotes in nightly build
#SET(NEED_QUOTES TRUE)
#IF(NEED_QUOTES)
# ADD_DEFINITIONS(-DOPENMM_SVN_REVISION="${OPENMM_SVN_REVISION}"
# -DOPENMM_COPYRIGHT_YEARS="${OPENMM_COPYRIGHT_YEARS}"
# -DOPENMM_AUTHORS="${OPENMM_AUTHORS}")
#ELSE(NEED_QUOTES)
# ADD_DEFINITIONS(-DOPENMM_SVN_REVISION=${OPENMM_SVN_REVISION}
# -DOPENMM_COPYRIGHT_YEARS=${OPENMM_COPYRIGHT_YEARS}
# -DOPENMM_AUTHORS=${OPENMM_AUTHORS})
#ENDIF(NEED_QUOTES)
# -DOPENMM_TYPE has to be defined in the target subdirectories.
# -Dsimbody_EXPORTS defined automatically when Windows DLL build is being done.
# Report the version number to the CMake UI
SET(OPENMM_VERSION
"${OPENMM_MAJOR_VERSION}.${OPENMM_MINOR_VERSION}.${OPENMM_BUILD_VERSION}"
CACHE STRING "This is the version of OpenMM FreeEnergy which will be built." FORCE)
SET(SHARED_FREE_ENERGY_TARGET ${OPENMM_FREE_ENERGY_LIBRARY_NAME})
SET(STATIC_FREE_ENERGY_TARGET ${OPENMM_FREE_ENERGY_LIBRARY_NAME}_static)
## If no one says otherwise, change the executable path to drop into the same binary
## location as the DLLs so that the test cases will use the just-build DLLs.
#IF(NOT EXECUTABLE_OUTPUT_PATH)
# SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}
# CACHE INTERNAL "Single output directory for building all executables.")
#ENDIF(NOT EXECUTABLE_OUTPUT_PATH)
#IF(NOT LIBRARY_OUTPUT_PATH)
# SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}
# CACHE INTERNAL "Single output directory for building all libraries.")
#ENDIF(NOT LIBRARY_OUTPUT_PATH)
#SET(${PROJECT_NAME}_EXECUTABLE_DIR ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR})
#SET(${PROJECT_NAME}_LIBRARY_DIR ${LIBRARY_OUTPUT_PATH}/${CMAKE_CFG_INTDIR})
# Ensure that debug libraries have "_d" appended to their names.
# CMake gets this right on Windows automatically with this definition.
#IF (${CMAKE_GENERATOR} MATCHES "Visual Studio")
# SET(CMAKE_DEBUG_POSTFIX "_d" CACHE INTERNAL "" FORCE)
#ENDIF (${CMAKE_GENERATOR} MATCHES "Visual Studio")
# But on Unix or Cygwin we have to add the suffix manually
IF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
SET(SHARED_FREE_ENERGY_TARGET ${SHARED_FREE_ENERGY_TARGET}_d)
SET(STATIC_FREE_ENERGY_TARGET ${STATIC_FREE_ENERGY_TARGET}_d)
ENDIF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
# These are all the places to search for header files which are
# to be part of the API.
SET(API_FREE_ENERGY_INCLUDE_DIRS) # start empty
FOREACH(subdir ${OPENMM_FREE_ENERGY_PLUGIN_SOURCE_SUBDIRS})
# append
SET(API_FREE_ENERGY_INCLUDE_DIRS ${API_FREE_ENERGY_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include
${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include/internal)
ENDFOREACH(subdir)
# We'll need both *relative* path names, starting with their API_INCLUDE_DIRS,
# and absolute pathnames.
SET(API_FREE_ENERGY_REL_INCLUDE_FILES) # start these out empty
SET(API_FREE_ENERGY_ABS_INCLUDE_FILES)
FOREACH(dir ${API_FREE_ENERGY_INCLUDE_DIRS})
FILE(GLOB fullpaths ${dir}/*.h) # returns full pathnames
SET(API_FREE_ENERGY_ABS_INCLUDE_FILES ${API_FREE_ENERGY_ABS_INCLUDE_FILES} ${fullpaths})
FOREACH(pathname ${fullpaths})
GET_FILENAME_COMPONENT(filename ${pathname} NAME)
SET(API_FREE_ENERGY_REL_INCLUDE_FILES ${API_FREE_ENERGY_REL_INCLUDE_FILES} ${dir}/${filename})
ENDFOREACH(pathname)
ENDFOREACH(dir)
# collect up source files
SET(SOURCE_FREE_ENERGY_FILES) # empty
SET(SOURCE_FREE_ENERGY_INCLUDE_FILES)
FOREACH(subdir ${OPENMM_FREE_ENERGY_PLUGIN_SOURCE_SUBDIRS})
FILE(GLOB src_files ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*/*.cpp)
FILE(GLOB incl_files ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.h)
SET(SOURCE_FREE_ENERGY_FILES ${SOURCE_FREE_ENERGY_FILES} ${src_files}) #append
SET(SOURCE_FREE_ENERGY_INCLUDE_FILES ${SOURCE_FREE_ENERGY_INCLUDE_FILES} ${incl_files})
## Make sure we find these locally before looking in OpenMM/include if
## OpenMM was previously installed there.
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include)
ENDFOREACH(subdir)
INCLUDE_DIRECTORIES(BEFORE ${OPENMM_DIR}/platforms/reference/src)
INCLUDE_DIRECTORIES(BEFORE ${OPENMM_DIR}/platforms/reference/src/SimTKReference)
# ----------------------------------------------------------------------------
IF(LOG)
FILE( APPEND ${LOG_FILE} "SOURCE_FREE_ENERGY_FILES=" ${SOURCE_FREE_ENERGY_FILES} "\n" )
FILE( APPEND ${LOG_FILE} "SOURCE_FREE_ENERGY_INCLUDE_FILES=" ${SOURCE_FREE_ENERGY_INCLUDE_FILES} "\n" )
FILE( APPEND ${LOG_FILE} "OPENMM_PATH=" ${OPENMM_PATH} "\n" )
FILE( APPEND ${LOG_FILE} "CUDA_PATH=" ${CUDA_PATH} "\n" )
ENDIF(LOG)
# ----------------------------------------------------------------------------
# If API_FREE_ENERGY wrappers are being generated, and add them to the build.
#SET(OPENMM_BUILD_API_FREE_ENERGY_WRAPPERS OFF CACHE BOOL "Build wrappers for C and Fortran")
#IF(OPENMM_BUILD_API_FREE_ENERGY_WRAPPERS)
# ADD_SUBDIRECTORY(wrappers)
# SET(SOURCE_FREE_ENERGY_FILES ${SOURCE_FREE_ENERGY_FILES} wrappers/OpenMMCWrapper.cpp wrappers/OpenMMFortranWrapper.cpp)
# SET_SOURCE_FREE_ENERGY_FILES_PROPERTIES(wrappers/OpenMMCWrapper.cpp wrappers/OpenMMFortranWrapper.cpp PROPERTIES GENERATED TRUE)
#ENDIF(OPENMM_BUILD_API_FREE_ENERGY_WRAPPERS)
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src)
ADD_LIBRARY(${SHARED_FREE_ENERGY_TARGET} SHARED ${SOURCE_FREE_ENERGY_FILES} ${SOURCE_FREE_ENERGY_INCLUDE_FILES} ${API_FREE_ENERGY_ABS_INCLUDE_FILES})
SET_TARGET_PROPERTIES(${SHARED_FREE_ENERGY_TARGET} PROPERTIES COMPILE_FLAGS "-DOPENMM_BUILDING_SHARED_LIBRARY -DLEPTON_BUILDING_SHARED_LIBRARY")
ADD_LIBRARY(${STATIC_FREE_ENERGY_TARGET} STATIC ${SOURCE_FREE_ENERGY_FILES} ${SOURCE_FREE_ENERGY_INCLUDE_FILES} ${API_FREE_ENERGY_ABS_INCLUDE_FILES})
SET_TARGET_PROPERTIES(${STATIC_FREE_ENERGY_TARGET} PROPERTIES COMPILE_FLAGS "-DOPENMM_USE_STATIC_LIBRARIES -DOPENMM_BUILDING_STATIC_LIBRARY -DLEPTON_USE_STATIC_LIBRARIES -DLEPTON_BUILDING_STATIC_LIBRARY")
#IF(OPENMM_BUILD_API_FREE_ENERGY_WRAPPERS)
# ADD_DEPENDENCIES(${SHARED_FREE_ENERGY_TARGET} ApiWrappers)
# ADD_DEPENDENCIES(${STATIC_FREE_ENERGY_TARGET} ApiWrappers)
#ENDIF(OPENMM_BUILD_API_FREE_ENERGY_WRAPPERS)
# On Linux need to link to libdl
FIND_LIBRARY(DL_LIBRARY dl)
IF(DL_LIBRARY)
TARGET_LINK_LIBRARIES(${SHARED_FREE_ENERGY_TARGET} ${DL_LIBRARY})
TARGET_LINK_LIBRARIES(${STATIC_FREE_ENERGY_TARGET} ${DL_LIBRARY})
ENDIF(DL_LIBRARY)
ADD_SUBDIRECTORY(platforms/reference/tests)
# Which hardware platforms to build
SET(OPENMM_BUILD_FREE_ENERGY_CUDA_LIB OFF CACHE BOOL "Build OpenMMFreeEnergyCuda library for Nvidia GPUs")
SET(OPENMM_BUILD_FREE_ENERGY_PATH)
SET(OPENMM_BUILD_FREE_ENERGY_CUDA_PATH)
IF(OPENMM_BUILD_FREE_ENERGY_CUDA_LIB)
ADD_SUBDIRECTORY(platforms/cuda)
SET(OPENMM_BUILD_FREE_ENERGY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/platforms/cuda)
SET(OPENMM_BUILD_FREE_ENERGY_CUDA_PATH ${CMAKE_CURRENT_SOURCE_DIR}/platforms/cuda)
SET(OPENMM_FREE_ENERGY_CUDA_SOURCE_SUBDIRS . openmmapi olla platforms/cuda)
ENDIF(OPENMM_BUILD_FREE_ENERGY_CUDA_LIB)
#SET(OPENMM_BUILD_BROOK_LIB OFF CACHE BOOL "Build OpenMMBrook library for ATI GPUs")
#IF(OPENMM_BUILD_BROOK_LIB)
# ADD_SUBDIRECTORY(platforms/brook)
#ENDIF(OPENMM_BUILD_BROOK_LIB)
#
#SET(OPENMM_BUILD_OPENCL_LIB OFF CACHE BOOL "Build OpenMMOpenCL library for Nvidia GPUs")
#IF(OPENMM_BUILD_OPENCL_LIB)
# ADD_SUBDIRECTORY(platforms/opencl)
#ENDIF(OPENMM_BUILD_OPENCL_LIB)
INSTALL_TARGETS(/lib RUNTIME_DIRECTORY /lib ${SHARED_FREE_ENERGY_TARGET})
INSTALL_TARGETS(/lib RUNTIME_DIRECTORY /lib ${STATIC_FREE_ENERGY_TARGET})
FILE(GLOB CORE_HEADERS include/*.h */include/*.h)
FILE(GLOB TOP_HEADERS include/openmm/*.h */include/openmm/*.h)
FILE(GLOB INTERNAL_HEADERS include/openmm/internal/*.h */include/openmm/internal/*.h )
INSTALL_FILES(/include FILES ${CORE_HEADERS})
INSTALL_FILES(/include/openmm FILES ${TOP_HEADERS})
INSTALL_FILES(/include/openmm/internal FILES ${INTERNAL_HEADERS})
#
# Allow automated build and dashboard.
#
#INCLUDE (Dart)
#IF (UNIX AND NOT CYGWIN AND NOT APPLE)
# IF (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES Debug)
# ADD_DEFINITIONS(-fprofile-arcs -ftest-coverage)
# LINK_LIBRARIES(gcov)
# ENDIF (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES Debug)
#ENDIF (UNIX AND NOT CYGWIN AND NOT APPLE)
#
# Testing
#
ENABLE_TESTING()
IF (EXECUTABLE_OUTPUT_PATH)
SET (TEST_PATH ${EXECUTABLE_OUTPUT_PATH})
ELSE (EXECUTABLE_OUTPUT_PATH)
SET (TEST_PATH .)
ENDIF (EXECUTABLE_OUTPUT_PATH)
#INCLUDE(ApiDoxygen.cmake)
#ADD_SUBDIRECTORY(tests)
#ADD_SUBDIRECTORY(examples)
#ifndef OPENMM_FREE_ENERGY_H_
#define OPENMM_FREE_ENERGY_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) 2009 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/GBVISoftcoreForce.h"
#include "openmm/GBSAOBCSoftcoreForce.h"
#include "openmm/NonbondedSoftcoreForce.h"
#endif /*OPENMM_FREE_ENERGY_H_*/
#ifndef OPENMM_FREE_ENERGY_GBSA_OBC_FORCE_FIELD_H_
#define OPENMM_FREE_ENERGY_GBSA_OBC_FORCE_FIELD_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) 2008-2009 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/Force.h"
#include <vector>
#include "openmm/internal/windowsExport.h"
namespace OpenMM {
/**
* This class implements an implicit solvation force using the GBSA-OBC model.
* <p>
* To use this class, create a GBSAOBCSoftcoreForce 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
* 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
* by calling setParticleParameters().
* <p>
* If the System also contains a NonbondedForce, this force will use the cutoffs
* and periodic boundary conditions specified in it.
*/
class OPENMM_EXPORT GBSAOBCSoftcoreForce : public Force {
public:
/*
* Create a GBSAOBCSoftcoreForce.
*/
GBSAOBCSoftcoreForce();
/**
* Get the number of particles in the system.
*/
int getNumParticles() const {
return particles.size();
}
/**
* Add the GBSA parameters for a particle. This should be called once for each particle
* in the System. When it is called for the i'th time, it specifies the parameters for the i'th particle.
*
* @param charge the charge of the particle, measured in units of the proton charge
* @param radius the GBSA radius of the particle, measured in nm
* @param scalingFactor the OBC scaling factor for the particle
* @param nonPolarScalingFactor the nonpolar scaling factor for the particle (default: 1.0)
* @return the index of the particle that was added
* @return the index of the particle that was added
*/
int addParticle(double charge, double radius, double scalingFactor, double nonPolarScalingFactor = 1.0);
/**
* Get the force field parameters for a particle.
*
* @param index the index of the particle for which to get parameters
* @param charge the charge of the particle, measured in units of the proton charge
* @param radius the GBSA radius of the particle, measured in nm
* @param scalingFactor the OBC scaling factor for the particle
*/
void getParticleParameters(int index, double& charge, double& radius, double& scalingFactor) const;
/**
* Get the force field parameters for a particle.
*
* @param index the index of the particle for which to get parameters
* @param charge the charge of the particle, measured in units of the proton charge
* @param radius the GBSA radius of the particle, measured in nm
* @param scalingFactor the OBC scaling factor for the particle
* @param nonPolarScalingFactor the nonpolar scaling factor for the particle
*/
void getParticleParameters(int index, double& charge, double& radius, double& scalingFactor, double& nonPolarScalingFactor) const;
/**
* Set the force field parameters for a particle.
*
* @param index the index of the particle for which to set parameters
* @param charge the charge of the particle, measured in units of the proton charge
* @param radius the GBSA radius of the particle, measured in nm
* @param scalingFactor the OBC scaling factor for the particle
* @param nonPolarScalingFactor the nonpolar scaling factor for the particle (default: 1.0)
*/
void setParticleParameters(int index, double charge, double radius, double scalingFactor, double nonPolarScalingFactor = 1.0);
/**
* Get the dielectric constant for the solvent.
*/
double getSolventDielectric() const {
return solventDielectric;
}
/**
* Set the dielectric constant for the solvent.
*/
void setSolventDielectric(double dielectric) {
solventDielectric = dielectric;
}
/**
* Get the dielectric constant for the solute.
*/
double getSoluteDielectric() const {
return soluteDielectric;
}
/**
* Set the dielectric constant for the solute.
*/
void setSoluteDielectric(double dielectric) {
soluteDielectric = dielectric;
}
/**
* Get the nonPolarPrefactor.
*/
double getNonPolarPrefactor() const {
return nonPolarPrefactor;
}
/**
* Set the nonPolarPrefactor.
*/
void setNonPolarPrefactor(double inputNonPolarPrefactor) {
nonPolarPrefactor = inputNonPolarPrefactor;
}
protected:
ForceImpl* createImpl();
private:
class ParticleInfo;
double solventDielectric, soluteDielectric, nonPolarPrefactor;
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::vector<ParticleInfo> particles;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
};
class GBSAOBCSoftcoreForce::ParticleInfo {
public:
double charge, radius, scalingFactor, nonPolarScalingFactor;
ParticleInfo() {
charge = radius = scalingFactor = nonPolarScalingFactor = 0.0;
}
ParticleInfo(double charge, double radius, double scalingFactor, double nonPolarScalingFactor) :
charge(charge), radius(radius), scalingFactor(scalingFactor), nonPolarScalingFactor(nonPolarScalingFactor) {
}
};
} // namespace OpenMM
#endif /*OPENMM_FREE_ENERGY_GBSA_OBC_FORCE_FIELD_H_*/
#ifndef OPENMM_GBVI_SOFTCORE_FORCE_FIELD_H_
#define OPENMM_GBVI_SOFTCORE_FORCE_FIELD_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) 2008-2009 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/Force.h"
#include <vector>
#include "openmm/internal/windowsExport.h"
using std::pair;
namespace OpenMM {
/**
* This class implements an implicit solvation force using the GB/VI model.
* <p>
* To use this class, create a GBVISoftcoreForce object, then call addParticle() once for each particle in the
* System to define its parameters. The number of particles for which you define GB/VI parameters must
* be exactly equal to the number of particles in the System, or else an exception will be thrown when you
* try to create an Context. After a particle has been added, you can modify its force field parameters
* by calling setParticleParameters().
* <p>
* If the System also contains a NonbondedForce, this force will use the cutoffs
* and periodic boundary conditions specified in it.
*/
class OPENMM_EXPORT GBVISoftcoreForce : public Force {
public:
/**
* This is an enumeration of the different methods that may be used for handling long range nonbonded forces.
*/
enum NonbondedSoftcoreMethod {
/**
* No cutoff is applied to nonbonded interactions. The full set of N^2 interactions is computed exactly.
* This necessarily means that periodic boundary conditions cannot be used. This is the default.
*/
NoCutoff = 0,
/**
* Interactions beyond the cutoff distance are ignored.
*/
CutoffNonPeriodic = 1,
/**
* Periodic boundary conditions are used, so that each particle interacts only with the nearest periodic copy of
* each other particle. Interactions beyond the cutoff distance are ignored.
*/
CutoffPeriodic = 2,
};
/**
* This is an enumeration of the different methods that may be used for scaling of the Born radii.
*/
enum BornRadiusScalingSoftcoreMethod {
/**
* No scaling method is applied.
*/
NoScaling = 0,
/**
* Use the method outlined in Proteins 55, 383-394 (2004), Eq. 6
*/
Tanh = 1,
/**
* Use quintic spline scaling function
*/
QuinticSpline = 2
};
/*
* Create a GBVISoftcoreForce.
*/
GBVISoftcoreForce();
/**
* Get the number of particles in the system.
*/
int getNumParticles() const {
return particles.size();
}
/**
* Add the GB/VI parameters for a particle. This should be called once for each particle
* in the System. When it is called for the i'th time, it specifies the parameters for the i'th particle.
*
* @param charge the charge of the particle, measured in units of the proton charge
* @param radius the GB/VI radius of the particle, measured in nm
* @param gamma the gamma parameter
* @param bornRadiusScaleFactor the Born radius scale factor (used for free energy calculations)
*/
void addParticle(double charge, double radius, double gamma, double bornRadiusScaleFactor = 1.0 );
/**
* Get the force field parameters for a particle.
*
* @param index the index of the particle for which to get parameters
* @param charge the charge of the particle, measured in units of the proton charge
* @param radius the GBSA radius of the particle, measured in nm
* @param gamma the gamma parameter
*/
void getParticleParameters(int index, double& charge, double& radius, double& gamma) const;
/**
* Get the force field parameters for a particle.
*
* @param index the index of the particle for which to get parameters
* @param charge the charge of the particle, measured in units of the proton charge
* @param radius the GBSA radius of the particle, measured in nm
* @param gamma the gamma parameter
* @param bornRadiusScaleFactor the Born radius scale factor (used for free energy calculations)
*/
void getParticleParameters(int index, double& charge, double& radius, double& gamma, double& bornRadiusScaleFactor) const;
/**
* Set the force field parameters for a particle.
*
* @param index the index of the particle for which to set parameters
* @param charge the charge of the particle, measured in units of the proton charge
* @param radius the GB/VI radius of the particle, measured in nm
* @param gamma the gamma parameter
* @param bornRadiusScaleFactor the Born radius scale factor (used for free energy calculations)
*/
void setParticleParameters(int index, double charge, double radius, double gamma, double bornRadiusScaleFactor = 1.0 );
/**
* Add a bond
*
* @param particle1 the index of the first particle
* @param particle2 the index of the second particle
* @param distance the distance between the two particles, measured in nm
* @return the index of the bond that was added
*/
int addBond(int particle1, int particle2, double distance);
/**
* Get the parameters defining a bond
*
* @param index the index of the bond for which to get parameters
* @param particle1 the index of the first particle involved in the bond
* @param particle2 the index of the second particle involved in the bond
* @param distance the distance between the two particles, measured in nm
*/
void getBondParameters(int index, int& particle1, int& particle2, double& distance) const;
/**
* Set 1-2 bonds
*
* @param index index of the bond for which to set parameters
* @param particle1 index of first atom in bond
* @param particle2 index of second atom in bond
* @param bondLength bond length
*/
void setBondParameters( int index, int particle1, int particle2, double bondLength);
/**
* Get number of bonds
*
* @return number of bonds
*/
int getNumBonds( void ) const;
/**
* Get the dielectric constant for the solvent.
*/
double getSolventDielectric() const {
return solventDielectric;
}
/**
* Set the dielectric constant for the solvent.
*/
void setSolventDielectric(double dielectric) {
solventDielectric = dielectric;
}
/**
* Get the dielectric constant for the solute.
*/
double getSoluteDielectric() const {
return soluteDielectric;
}
/**
* Set the dielectric constant for the solute.
*/
void setSoluteDielectric(double dielectric) {
soluteDielectric = dielectric;
}
/**
* Get the method used for handling long range nonbonded interactions.
*/
NonbondedSoftcoreMethod getNonbondedMethod() const;
/**
* Set the method used for handling long range nonbonded interactions.
*/
void setNonbondedMethod(NonbondedSoftcoreMethod method);
/**
* Get the cutoff distance (in nm) being used for nonbonded interactions. If the NonbondedMethod in use
* is NoCutoff, this value will have no effect.
*/
double getCutoffDistance() const;
/**
* Set the cutoff distance (in nm) being used for nonbonded interactions. If the NonbondedMethod in use
* is NoCutoff, this value will have no effect.
*/
void setCutoffDistance(double distance);
/**
* Get the method used for scaling Born radii.
*/
BornRadiusScalingSoftcoreMethod getBornRadiusScalingMethod() const;
/**
* Set the method used for scaling Born radii.
*/
void setBornRadiusScalingMethod(BornRadiusScalingSoftcoreMethod method);
/**
* Get the lower limit factor used in the quintic spline scaling method (typically 0.5-0.8)
*/
double getQuinticLowerLimitFactor( void ) const;
/**
* Set the lower limit factor used in the quintic spline scaling method (typically 0.5-0.8)
*/
void setQuinticLowerLimitFactor(double quinticLowerLimitFactor );
/**
* Get the upper limit used in the quintic spline scaling method (typically 0.5-0.8)
*/
double getQuinticUpperBornRadiusLimit( void ) const;
/**
* Set the upper limit used in the quintic spline scaling method (typically 0.008)
*/
void setQuinticUpperBornRadiusLimit(double quinticUpperBornRadiusLimit);
/**
* Get the cutoff distance (in nm) being used for nonbonded interactions. If the NonbondedMethod in use
* is NoCutoff, this value will have no effect.
*/
void getTanhParameters( double& alpha, double& beta, double& gamma) const;
/**
* Set the cutoff distance (in nm) being used for nonbonded interactions. If the NonbondedMethod in use
* is NoCutoff, this value will have no effect.
*/
void setTanhParameters(double alpha, double beta, double gamma);
protected:
ForceImpl* createImpl();
private:
class ParticleInfo;
NonbondedSoftcoreMethod nonbondedMethod;
double cutoffDistance, solventDielectric, soluteDielectric;
BornRadiusScalingSoftcoreMethod scalingMethod;
double alpha, beta, gamma;
double quinticLowerLimitFactor, quinticUpperBornRadiusLimit;
class BondInfo;
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::vector<ParticleInfo> particles;
std::vector<BondInfo> bonds;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
};
class GBVISoftcoreForce::ParticleInfo {
public:
double charge, radius, gamma, bornRadiusScaleFactor;
ParticleInfo() {
charge = radius = gamma = 0.0;
bornRadiusScaleFactor = 1.0;
}
ParticleInfo(double charge, double radius, double gamma, double bornRadiusScaleFactor) :
charge(charge), radius(radius), gamma(gamma), bornRadiusScaleFactor(bornRadiusScaleFactor) {
}
};
class GBVISoftcoreForce::BondInfo {
public:
int particle1, particle2;
double bondLength;
BondInfo() {
bondLength = 0.0;
particle1 = -1;
particle2 = -1;
}
BondInfo(int atomIndex1, int atomIndex2, double bondLength) :
particle1(atomIndex1), particle2(atomIndex2), bondLength(bondLength) {
}
};
} // namespace OpenMM
#endif /*OPENMM_GBVI_SOFTCORE_FORCEFIELD_H_*/
#ifndef OPENMM_FREE_ENERGY_KERNELS_H_
#define OPENMM_FREE_ENERGY_KERNELS_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) 2008-2009 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/GBSAOBCSoftcoreForce.h"
#include "openmm/GBVISoftcoreForce.h"
#include "openmm/NonbondedForce.h"
#include "openmm/NonbondedSoftcoreForce.h"
#include "openmm/System.h"
#include "openmm/KernelImpl.h"
#include <set>
#include <string>
#include <vector>
namespace OpenMM {
/**
* This kernel is invoked by GBSAOBCSoftcoreForce to calculate the forces acting on the system and the energy of the system.
*/
class CalcGBSAOBCSoftcoreForceKernel : public KernelImpl {
public:
static std::string Name() {
return "CalcGBSAOBCSoftcoreForce";
}
CalcGBSAOBCSoftcoreForceKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
}
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param force the GBSAOBCSoftcoreForce this kernel will be used for
*/
virtual void initialize(const System& system, const GBSAOBCSoftcoreForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the GBSAOBCSoftcoreForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
};
/**
* This kernel is invoked by NonbondedForce to calculate the forces acting on the system and the energy of the system.
*/
class CalcNonbondedSoftcoreForceKernel : public KernelImpl {
public:
enum NonbondedSoftcoreMethod {
NoCutoff = 0,
CutoffNonPeriodic = 1,
CutoffPeriodic = 2,
Ewald = 3,
PME = 4
};
static std::string Name() {
return "CalcNonbondedSoftcoreForce";
}
CalcNonbondedSoftcoreForceKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
}
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param force the NonbondedSoftcoreForce this kernel will be used for
*/
virtual void initialize(const System& system, const NonbondedSoftcoreForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the NonbondedSoftcoreForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
};
/**
* This kernel is invoked by GBVISoftcoreForce to calculate the forces acting on the system and the energy of the system.
*/
class CalcGBVISoftcoreForceKernel : public KernelImpl {
public:
static std::string Name() {
return "CalcGBVISoftcoreForce";
}
CalcGBVISoftcoreForceKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
}
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param force the GBVISoftcoreForce this kernel will be used for
* @param scaledRadii scaled radii
*/
virtual void initialize(const System& system, const GBVISoftcoreForce& force, const std::vector<double>& scaledRadii) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the GBVISoftcoreForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
};
} // namespace OpenMM
#endif /*OPENMM_FREE_ENERGY_KERNELS_H_*/
#ifndef OPENMM_GBSA_OBC_SOFTCORE_FORCE_FIELD_IMPL_H_
#define OPENMM_GBSA_OBC_SOFTCORE_FORCE_FIELD_IMPL_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) 2008 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/internal/ForceImpl.h"
#include "openmm/GBSAOBCSoftcoreForce.h"
#include "openmm/Kernel.h"
#include <string>
namespace OpenMM {
/**
* This is the internal implementation of GBSAOBCSoftcoreForce.
*/
class GBSAOBCSoftcoreForceImpl : public ForceImpl {
public:
GBSAOBCSoftcoreForceImpl(GBSAOBCSoftcoreForce& owner);
void initialize(ContextImpl& context);
GBSAOBCSoftcoreForce& getOwner() {
return owner;
}
void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly.
}
void calcForces(ContextImpl& context);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
}
std::vector<std::string> getKernelNames();
private:
GBSAOBCSoftcoreForce& owner;
Kernel kernel;
};
} // namespace OpenMM
#endif /*OPENMM_GBSA_OBC_SOFTCORE_FORCE_FIELD_IMPL_H_*/
#ifndef OPENMM_GBVI_SOFTCORE_FORCEFIELDIMPL_H_
#define OPENMM_GBVI_SOFTCORE_FORCEFIELDIMPL_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) 2008 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/internal/ForceImpl.h"
#include "openmm/GBVISoftcoreForce.h"
#include "openmm/Kernel.h"
#include <string>
namespace OpenMM {
/**
* This is the internal implementation of GBVISoftcoreForce.
*/
class GBVISoftcoreForceImpl : public ForceImpl {
public:
GBVISoftcoreForceImpl(GBVISoftcoreForce& owner);
void initialize(ContextImpl& context);
GBVISoftcoreForce& getOwner() {
return owner;
}
// set bond info using HarmonicBond and constraints
int getBondsFromForces(ContextImpl& context);
// calculate scaled radii (Eq. 5 of Labute paper [JCC 29 1693-1698 2008])
void findScaledRadii( int numberOfParticles, const std::vector<std::vector<int> >& bondIndices,
const std::vector<double> & bondLengths, std::vector<double> & scaledRadii) const;
void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly.
}
void calcForces(ContextImpl& context);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
}
std::vector<std::string> getKernelNames();
private:
GBVISoftcoreForce& owner;
Kernel kernel;
};
} // namespace OpenMM
#endif /*OPENMM_GBVI_SOFTCORE_FORCEFIELDIMPL_H_*/
#ifndef OPENMM_NONBONDED_SOFTCORE_FORCE_IMPL_H_
#define OPENMM_NONBONDED_SOFTCORE_FORCE_IMPL_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) 2008-2009 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/internal/ForceImpl.h"
#include "openmm/NonbondedSoftcoreForce.h"
#include "openmm/Kernel.h"
#include <utility>
#include <set>
#include <string>
namespace OpenMM {
/**
* This is the internal implementation of NonbondedSoftcoreForce.
*/
class NonbondedSoftcoreForceImpl : public ForceImpl {
public:
NonbondedSoftcoreForceImpl(NonbondedSoftcoreForce& owner);
~NonbondedSoftcoreForceImpl();
void initialize(ContextImpl& context);
NonbondedSoftcoreForce& getOwner() {
return owner;
}
void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly.
}
void calcForces(ContextImpl& context);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
}
std::vector<std::string> getKernelNames();
private:
NonbondedSoftcoreForce& owner;
Kernel kernel;
};
} // namespace OpenMM
#endif /*OPENMM_NONBONDED_SOFTCORE_FORCE_IMPL_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) 2008-2009 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/Force.h"
#include "openmm/OpenMMException.h"
#include "openmm/GBSAOBCSoftcoreForce.h"
#include "openmm/internal/GBSAOBCSoftcoreForceImpl.h"
using namespace OpenMM;
GBSAOBCSoftcoreForce::GBSAOBCSoftcoreForce() : solventDielectric(78.3), soluteDielectric(1.0), nonPolarPrefactor( 0.0054 ){
}
int GBSAOBCSoftcoreForce::addParticle(double charge, double radius, double scalingFactor, double nonPolarScalingFactor) {
particles.push_back(ParticleInfo(charge, radius, scalingFactor, nonPolarScalingFactor));
return particles.size()-1;
}
void GBSAOBCSoftcoreForce::getParticleParameters(int index, double& charge, double& radius, double& scalingFactor) const {
charge = particles[index].charge;
radius = particles[index].radius;
scalingFactor = particles[index].scalingFactor;
}
void GBSAOBCSoftcoreForce::getParticleParameters(int index, double& charge, double& radius, double& scalingFactor, double& nonPolarScalingFactor) const {
charge = particles[index].charge;
radius = particles[index].radius;
scalingFactor = particles[index].scalingFactor;
nonPolarScalingFactor = particles[index].nonPolarScalingFactor;
}
void GBSAOBCSoftcoreForce::setParticleParameters(int index, double charge, double radius, double scalingFactor, double nonPolarScalingFactor) {
particles[index].charge = charge;
particles[index].radius = radius;
particles[index].scalingFactor = scalingFactor;
particles[index].nonPolarScalingFactor = nonPolarScalingFactor;
}
ForceImpl* GBSAOBCSoftcoreForce::createImpl() {
return new GBSAOBCSoftcoreForceImpl(*this);
}
/* -------------------------------------------------------------------------- *
* 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) 2008 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/internal/GBSAOBCSoftcoreForceImpl.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/OpenMMException.h"
#include "openmm/freeEnergyKernels.h"
#include <vector>
using namespace OpenMM;
using std::vector;
GBSAOBCSoftcoreForceImpl::GBSAOBCSoftcoreForceImpl(GBSAOBCSoftcoreForce& owner) : owner(owner) {
}
void GBSAOBCSoftcoreForceImpl::initialize(ContextImpl& context) {
kernel = context.getPlatform().createKernel(CalcGBSAOBCSoftcoreForceKernel::Name(), context);
if (owner.getNumParticles() != context.getSystem().getNumParticles())
throw OpenMMException("GBSAOBCSoftcoreForce must have exactly as many particles as the System it belongs to.");
dynamic_cast<CalcGBSAOBCSoftcoreForceKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner);
}
void GBSAOBCSoftcoreForceImpl::calcForces(ContextImpl& context ) {
dynamic_cast<CalcGBSAOBCSoftcoreForceKernel&>(kernel.getImpl()).executeForces(context);
}
double GBSAOBCSoftcoreForceImpl::calcEnergy(ContextImpl& context) {
return dynamic_cast<CalcGBSAOBCSoftcoreForceKernel&>(kernel.getImpl()).executeEnergy(context);
}
std::vector<std::string> GBSAOBCSoftcoreForceImpl::getKernelNames() {
std::vector<std::string> names;
names.push_back(CalcGBSAOBCSoftcoreForceKernel::Name());
return names;
}
/* -------------------------------------------------------------------------- *
* 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) 2008-2009 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/Force.h"
#include "openmm/OpenMMException.h"
#include "openmm/GBVISoftcoreForce.h"
#include "openmm/internal/GBVISoftcoreForceImpl.h"
#include <sstream>
using namespace OpenMM;
GBVISoftcoreForce::GBVISoftcoreForce() : nonbondedMethod(NoCutoff), cutoffDistance(1.0), solventDielectric(78.3), soluteDielectric(1.0),
scalingMethod(NoScaling), alpha(1.0), beta(0.8), gamma(4.85), quinticLowerLimitFactor(0.8), quinticUpperBornRadiusLimit(5.0) {
}
void GBVISoftcoreForce::addParticle(double charge, double radius, double gamma, double bornRadiusScaleFactor) {
particles.push_back(ParticleInfo(charge, radius, gamma, bornRadiusScaleFactor));
}
void GBVISoftcoreForce::getParticleParameters(int index, double& charge, double& radius, double& gamma ) const {
charge = particles[index].charge;
radius = particles[index].radius;
gamma = particles[index].gamma;
}
void GBVISoftcoreForce::getParticleParameters(int index, double& charge, double& radius, double& gamma, double& bornRadiusScaleFactor ) const {
charge = particles[index].charge;
radius = particles[index].radius;
gamma = particles[index].gamma;
bornRadiusScaleFactor = particles[index].bornRadiusScaleFactor;
}
void GBVISoftcoreForce::setParticleParameters(int index, double charge, double radius, double gamma, double bornRadiusScaleFactor) {
particles[index].charge = charge;
particles[index].radius = radius;
particles[index].gamma = gamma;
particles[index].bornRadiusScaleFactor = bornRadiusScaleFactor;
}
GBVISoftcoreForce::NonbondedSoftcoreMethod GBVISoftcoreForce::getNonbondedMethod() const {
return nonbondedMethod;
}
void GBVISoftcoreForce::setNonbondedMethod(NonbondedSoftcoreMethod method) {
nonbondedMethod = method;
}
double GBVISoftcoreForce::getCutoffDistance() const {
return cutoffDistance;
}
void GBVISoftcoreForce::setCutoffDistance(double distance) {
cutoffDistance = distance;
}
GBVISoftcoreForce::BornRadiusScalingSoftcoreMethod GBVISoftcoreForce::getBornRadiusScalingMethod( void ) const {
return scalingMethod;
}
void GBVISoftcoreForce::setBornRadiusScalingMethod(BornRadiusScalingSoftcoreMethod method) {
scalingMethod = method;
}
double GBVISoftcoreForce::getQuinticLowerLimitFactor( void ) const {
return quinticLowerLimitFactor;
}
void GBVISoftcoreForce::setQuinticLowerLimitFactor(double inputQuinticLowerLimitFactor ){
quinticLowerLimitFactor = inputQuinticLowerLimitFactor;
}
double GBVISoftcoreForce::getQuinticUpperBornRadiusLimit( void ) const {
return quinticUpperBornRadiusLimit;
}
void GBVISoftcoreForce::setQuinticUpperBornRadiusLimit(double inputQuinticUpperBornRadiusLimit){
quinticUpperBornRadiusLimit = inputQuinticUpperBornRadiusLimit;
}
void GBVISoftcoreForce::getTanhParameters( double& returnAlpha, double& returnBeta, double& returnGamma) const {
returnAlpha = alpha;
returnBeta = beta;
returnGamma = gamma;
return;
}
void GBVISoftcoreForce::setTanhParameters(double inputAlpha, double inputBeta, double inputGamma){
alpha = inputAlpha;
beta = inputBeta;
gamma = inputGamma;
}
int GBVISoftcoreForce::addBond(int particle1, int particle2, double bondLength) {
bonds.push_back(BondInfo(particle1, particle2, bondLength));
return bonds.size()-1;
}
void GBVISoftcoreForce::setBondParameters( int index, int particle1, int particle2, double bondLength) {
bonds[index].particle1 = particle1;
bonds[index].particle2 = particle2;
bonds[index].bondLength = bondLength;
}
int GBVISoftcoreForce::getNumBonds( void ) const {
return (int) bonds.size();
}
void GBVISoftcoreForce::getBondParameters(int index, int& bondIndex1, int& bondIndex2, double& bondLength) const {
bondIndex1 = bonds[index].particle1;
bondIndex2 = bonds[index].particle2;
bondLength = bonds[index].bondLength;
}
ForceImpl* GBVISoftcoreForce::createImpl() {
return new GBVISoftcoreForceImpl(*this);
}
/* -------------------------------------------------------------------------- *
* 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) 2008 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/internal/GBVISoftcoreForceImpl.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/OpenMMException.h"
#include "openmm/freeEnergyKernels.h"
#include "openmm/kernels.h"
#include <vector>
#include <cmath>
#include <cstdio>
#include <sstream>
using namespace OpenMM;
using std::vector;
GBVISoftcoreForceImpl::GBVISoftcoreForceImpl(GBVISoftcoreForce& owner) : owner(owner) {
}
void GBVISoftcoreForceImpl::initialize(ContextImpl& context) {
// ---------------------------------------------------------------------------------------
static const std::string methodName = "GBVISoftcoreForceImpl::initialize";
// ---------------------------------------------------------------------------------------
kernel = context.getPlatform().createKernel(CalcGBVISoftcoreForceKernel::Name(), context);
System& system = context.getSystem();
int numberOfParticles = owner.getNumParticles();
// validate number of particles consistent
if( numberOfParticles != system.getNumParticles() ){
throw OpenMMException("GBVISoftcoreForce must have exactly as many particles as the System it belongs to.");
}
// load 1-2 atom pairs along w/ bond distance using HarmonicBondForce & constraints
// if numberOfBonds < 1, indicating they were not set by the user
if( owner.getNumBonds() < 1 ){
getBondsFromForces( context );
}
int numberOfBonds = owner.getNumBonds();
std::vector< std::vector<int> > bondIndices;
bondIndices.resize( numberOfBonds );
std::vector<double> bondLengths;
bondLengths.resize( numberOfBonds );
double maxBond = -1.0;
for (int i = 0; i < numberOfBonds; i++) {
int particle1, particle2;
double bondLength;
owner.getBondParameters(i, particle1, particle2, bondLength);
if (particle1 < 0 || particle1 >= owner.getNumParticles()) {
std::stringstream msg;
msg << "GBVISoftcoreForce: Illegal particle index: ";
msg << particle1;
throw OpenMMException(msg.str());
}
if (particle2 < 0 || particle2 >= owner.getNumParticles()) {
std::stringstream msg;
msg << "GBVISoftcoreForce: Illegal particle index: ";
msg << particle2;
throw OpenMMException(msg.str());
}
if( maxBond < bondLength ) maxBond = bondLength;
if (bondLength < 0.0 ) {
std::stringstream msg;
msg << "GBVISoftcoreForce: negative bondlength: ";
msg << bondLength;
throw OpenMMException(msg.str());
}
bondIndices[i].push_back( particle1 );
bondIndices[i].push_back( particle2 );
bondLengths[i] = bondLength;
}
fprintf( stderr, "%s MaxBond=%14.6e\n", methodName.c_str(), maxBond );
vector<double> scaledRadii;
scaledRadii.resize(numberOfParticles);
findScaledRadii( numberOfParticles, bondIndices, bondLengths, scaledRadii);
dynamic_cast<CalcGBVISoftcoreForceKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner, scaledRadii);
}
int GBVISoftcoreForceImpl::getBondsFromForces(ContextImpl& context) {
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "GBVISoftcoreForceImpl::getBondsFromForces";
// ---------------------------------------------------------------------------------------
// load 1-2 atom pairs along w/ bond distance using HarmonicBondForce & constraints
System& system = context.getSystem();
for (int i = 0; i < system.getNumForces(); i++) {
if (dynamic_cast<HarmonicBondForce*>(&system.getForce(i)) != NULL) {
const HarmonicBondForce& force = dynamic_cast<const HarmonicBondForce&>(system.getForce(i));
for (int j = 0; j < force.getNumBonds(); ++j) {
int particle1, particle2;
double length, k;
force.getBondParameters(j, particle1, particle2, length, k);
owner.addBond( particle1, particle2, length );
}
break;
}
}
// Also treat constrained distances as bonds if mass of one particle is < (2.0 + epsilon) (~2=deuterium)
for (int j = 0; j < system.getNumConstraints(); j++) {
int particle1, particle2;
double distance;
system.getConstraintParameters(j, particle1, particle2, distance);
if( system.getParticleMass( particle1 ) < 2.1 || system.getParticleMass( particle2 ) < 2.1 ){
owner.addBond( particle1, particle2, distance );
}
}
}
#define GBVIDebug 0
void GBVISoftcoreForceImpl::findScaledRadii( int numberOfParticles, const std::vector<std::vector<int> >& bondIndices,
const std::vector<double> & bondLengths, std::vector<double> & scaledRadii) const {
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "GBVISoftcoreForceImpl::findScaledRadii";
// ---------------------------------------------------------------------------------------
// load 1-2 indicies for each atom
std::vector<std::vector<int> > bonded12(numberOfParticles);
for (int i = 0; i < (int) bondIndices.size(); ++i) {
bonded12[bondIndices[i][0]].push_back(i);
bonded12[bondIndices[i][1]].push_back(i);
}
int errors = 0;
// compute scaled radii (Eq. 5 of Labute paper [JCC 29 p. 1693-1698 2008])
for (int j = 0; j < (int) bonded12.size(); ++j){
double charge;
double gamma;
double radiusJ;
double scaledRadiusJ;
owner.getParticleParameters(j, charge, radiusJ, gamma);
if( bonded12[j].size() == 0 ){
// (void) fprintf( stderr, "Warning GBVISoftcoreForceImpl::findScaledRadii atom %d has no covalent bonds; using atomic radius=%.3f.\n", j, radiusJ );
scaledRadiusJ = radiusJ;
// errors++;
} else {
double rJ2 = radiusJ*radiusJ;
// loop over bonded neighbors of atom j, applying Eq. 5 in Labute
scaledRadiusJ = 0.0;
for (int i = 0; i < (int) bonded12[j].size(); ++i){
int index = bonded12[j][i];
int bondedAtomIndex = (j == bondIndices[index][0]) ? bondIndices[index][1] : bondIndices[index][0];
double radiusI;
owner.getParticleParameters(bondedAtomIndex, charge, radiusI, gamma);
double rI2 = radiusI*radiusI;
double a_ij = (radiusI - bondLengths[index]);
a_ij *= a_ij;
a_ij = (rJ2 - a_ij)/(2.0*bondLengths[index]);
double a_ji = radiusJ - bondLengths[index];
a_ji *= a_ji;
a_ji = (rI2 - a_ji)/(2.0*bondLengths[index]);
scaledRadiusJ += a_ij*a_ij*(3.0*radiusI - a_ij) + a_ji*a_ji*( 3.0*radiusJ - a_ji );
}
#if GBVIDebug
//(void) fprintf( stderr, "j=%d rJ=%12.4f scaledRadiusJRaw==%12.4f", j, radiusJ, scaledRadiusJ );
#endif
scaledRadiusJ = (radiusJ*radiusJ*radiusJ) - 0.125*scaledRadiusJ;
#if GBVIDebug
//(void) fprintf( stderr, " scRJInt=%12.4f\n", scaledRadiusJ );
#endif
if( scaledRadiusJ > 0.0 ){
scaledRadiusJ = 0.95*pow( scaledRadiusJ, (1.0/3.0) );
} else {
scaledRadiusJ = 0.0;
}
}
scaledRadii[j] = scaledRadiusJ;
}
// abort if errors
if( errors ){
throw OpenMMException("GBVISoftcoreForceImpl::findScaledRadii errors -- aborting");
}
#if GBVIDebug
(void) fprintf( stderr, " R q gamma scaled radii no. bnds\n" );
double totalQ = 0.0;
for( int i = 0; i < (int) scaledRadii.size(); i++ ){
double charge;
double gamma;
double radiusI;
owner.getParticleParameters(i, charge, radiusI, gamma);
totalQ += charge;
(void) fprintf( stderr, "%4d %14.5e %14.5e %14.5e %14.5e %d\n", i, radiusI, charge, gamma, scaledRadii[i], (int) bonded12[i].size() );
}
(void) fprintf( stderr, "Total charge=%e\n", totalQ );
(void) fflush( stderr );
#endif
#undef GBVIDebug
}
void GBVISoftcoreForceImpl::calcForces(ContextImpl& context) {
dynamic_cast<CalcGBVISoftcoreForceKernel&>(kernel.getImpl()).executeForces(context);
}
double GBVISoftcoreForceImpl::calcEnergy(ContextImpl& context) {
return dynamic_cast<CalcGBVISoftcoreForceKernel&>(kernel.getImpl()).executeEnergy(context);
}
std::vector<std::string> GBVISoftcoreForceImpl::getKernelNames() {
std::vector<std::string> names;
names.push_back(CalcGBVISoftcoreForceKernel::Name());
return names;
}
/* -------------------------------------------------------------------------- *
* 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) 2008-2009 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/Force.h"
#include "openmm/OpenMMException.h"
#include "openmm/NonbondedSoftcoreForce.h"
#include "openmm/internal/NonbondedSoftcoreForceImpl.h"
#include <cmath>
#include <map>
#include <sstream>
#include <utility>
using namespace OpenMM;
using std::map;
using std::pair;
using std::set;
using std::string;
using std::stringstream;
using std::vector;
NonbondedSoftcoreForce::NonbondedSoftcoreForce() : nonbondedMethod(NoCutoff), cutoffDistance(1.0), rfDielectric(78.3), ewaldErrorTol(1e-4), softCoreLJLambda(1.0) {
}
NonbondedSoftcoreForce::NonbondedSoftcoreMethod NonbondedSoftcoreForce::getNonbondedMethod() const {
return nonbondedMethod;
}
void NonbondedSoftcoreForce::setNonbondedMethod(NonbondedSoftcoreMethod method) {
nonbondedMethod = method;
}
double NonbondedSoftcoreForce::getCutoffDistance() const {
return cutoffDistance;
}
void NonbondedSoftcoreForce::setCutoffDistance(double distance) {
cutoffDistance = distance;
}
double NonbondedSoftcoreForce::getSoftCoreLJLambda( void ) const {
return softCoreLJLambda;
}
void NonbondedSoftcoreForce::setSoftCoreLJLambda(double lambda) {
softCoreLJLambda = lambda;
}
double NonbondedSoftcoreForce::getReactionFieldDielectric( void ) const {
return rfDielectric;
}
void NonbondedSoftcoreForce::setReactionFieldDielectric(double dielectric) {
rfDielectric = dielectric;
}
double NonbondedSoftcoreForce::getEwaldErrorTolerance( void ) const {
return ewaldErrorTol;
}
void NonbondedSoftcoreForce::setEwaldErrorTolerance(double tol)
{
ewaldErrorTol = tol;
}
int NonbondedSoftcoreForce::addParticle(double charge, double sigma, double epsilon, double softcoreLJLambda) {
particles.push_back(ParticleInfo(charge, sigma, epsilon, softcoreLJLambda));
return particles.size()-1;
}
void NonbondedSoftcoreForce::getParticleParameters(int index, double& charge, double& sigma, double& epsilon) const {
charge = particles[index].charge;
sigma = particles[index].sigma;
epsilon = particles[index].epsilon;
}
void NonbondedSoftcoreForce::getParticleParameters(int index, double& charge, double& sigma, double& epsilon, double& softcoreLJLambda) const {
charge = particles[index].charge;
sigma = particles[index].sigma;
epsilon = particles[index].epsilon;
softcoreLJLambda = particles[index].softcoreLJLambda;
}
void NonbondedSoftcoreForce::setParticleParameters(int index, double charge, double sigma, double epsilon, double softcoreLJLambda) {
particles[index].charge = charge;
particles[index].sigma = sigma;
particles[index].epsilon = epsilon;
particles[index].softcoreLJLambda = softcoreLJLambda;
}
int NonbondedSoftcoreForce::addException(int particle1, int particle2, double chargeProd, double sigma, double epsilon, bool replace, double softcoreLJLambda ) {
map<pair<int, int>, int>::iterator iter = exceptionMap.find(pair<int, int>(particle1, particle2));
int newIndex;
if (iter == exceptionMap.end())
iter = exceptionMap.find(pair<int, int>(particle2, particle1));
if (iter != exceptionMap.end()) {
if (!replace) {
stringstream msg;
msg << "NonbondedSoftcoreForce: There is already an exception for particles ";
msg << particle1;
msg << " and ";
msg << particle2;
throw OpenMMException(msg.str());
}
exceptions[iter->second] = ExceptionInfo(particle1, particle2, chargeProd, sigma, epsilon, softcoreLJLambda);
newIndex = iter->second;
exceptionMap.erase(iter->first);
}
else {
exceptions.push_back(ExceptionInfo(particle1, particle2, chargeProd, sigma, epsilon, softcoreLJLambda));
newIndex = exceptions.size()-1;
}
exceptionMap[pair<int, int>(particle1, particle2)] = newIndex;
return newIndex;
}
void NonbondedSoftcoreForce::getExceptionParameters(int index, int& particle1, int& particle2, double& chargeProd, double& sigma, double& epsilon ) const {
particle1 = exceptions[index].particle1;
particle2 = exceptions[index].particle2;
chargeProd = exceptions[index].chargeProd;
sigma = exceptions[index].sigma;
epsilon = exceptions[index].epsilon;
}
void NonbondedSoftcoreForce::getExceptionParameters(int index, int& particle1, int& particle2, double& chargeProd, double& sigma, double& epsilon, double& softcoreLJLambda ) const {
particle1 = exceptions[index].particle1;
particle2 = exceptions[index].particle2;
chargeProd = exceptions[index].chargeProd;
sigma = exceptions[index].sigma;
epsilon = exceptions[index].epsilon;
softcoreLJLambda = exceptions[index].softcoreLJLambda;
}
void NonbondedSoftcoreForce::setExceptionParameters(int index, int particle1, int particle2, double chargeProd, double sigma, double epsilon, double softcoreLJLambda) {
exceptions[index].particle1 = particle1;
exceptions[index].particle2 = particle2;
exceptions[index].chargeProd = chargeProd;
exceptions[index].sigma = sigma;
exceptions[index].epsilon = epsilon;
exceptions[index].softcoreLJLambda = softcoreLJLambda;
}
ForceImpl* NonbondedSoftcoreForce::createImpl() {
return new NonbondedSoftcoreForceImpl(*this);
}
void NonbondedSoftcoreForce::createExceptionsFromBonds(const vector<pair<int, int> >& bonds, double coulomb14Scale, double lj14Scale) {
// Find particles separated by 1, 2, or 3 bonds.
vector<set<int> > exclusions(particles.size());
vector<set<int> > bonded12(exclusions.size());
for (int i = 0; i < (int) bonds.size(); ++i) {
bonded12[bonds[i].first].insert(bonds[i].second);
bonded12[bonds[i].second].insert(bonds[i].first);
}
for (int i = 0; i < (int) exclusions.size(); ++i)
addExclusionsToSet(bonded12, exclusions[i], i, i, 2);
// Find particles separated by 1 or 2 bonds and create the exceptions.
for (int i = 0; i < (int) exclusions.size(); ++i) {
set<int> bonded13;
addExclusionsToSet(bonded12, bonded13, i, i, 1);
for (set<int>::const_iterator iter = exclusions[i].begin(); iter != exclusions[i].end(); ++iter)
if (*iter < i) {
if (bonded13.find(*iter) == bonded13.end()) {
// This is a 1-4 interaction.
const ParticleInfo& particle1 = particles[*iter];
const ParticleInfo& particle2 = particles[i];
const double chargeProd = coulomb14Scale*particle1.charge*particle2.charge;
const double sigma = 0.5*(particle1.sigma+particle2.sigma);
const double epsilon = lj14Scale*std::sqrt(particle1.epsilon*particle2.epsilon);
addException(*iter, i, chargeProd, sigma, epsilon);
}
else {
// This interaction should be completely excluded.
addException(*iter, i, 0.0, 1.0, 0.0);
}
}
}
}
void NonbondedSoftcoreForce::addExclusionsToSet(const vector<set<int> >& bonded12, set<int>& exclusions, int baseParticle, int fromParticle, int currentLevel) const {
for (set<int>::const_iterator iter = bonded12[fromParticle].begin(); iter != bonded12[fromParticle].end(); ++iter) {
if (*iter != baseParticle)
exclusions.insert(*iter);
if (currentLevel > 0)
addExclusionsToSet(bonded12, exclusions, baseParticle, *iter, currentLevel-1);
}
}
/* -------------------------------------------------------------------------- *
* 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) 2008-2009 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/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/NonbondedSoftcoreForceImpl.h"
#include "openmm/freeEnergyKernels.h"
#include <sstream>
using namespace OpenMM;
using std::pair;
using std::vector;
using std::set;
using std::stringstream;
NonbondedSoftcoreForceImpl::NonbondedSoftcoreForceImpl(NonbondedSoftcoreForce& owner) : owner(owner) {
}
NonbondedSoftcoreForceImpl::~NonbondedSoftcoreForceImpl() {
}
void NonbondedSoftcoreForceImpl::initialize(ContextImpl& context) {
kernel = context.getPlatform().createKernel(CalcNonbondedSoftcoreForceKernel::Name(), context);
// Check for errors in the specification of exceptions.
System& system = context.getSystem();
if (owner.getNumParticles() != system.getNumParticles())
throw OpenMMException("NonbondedSoftcoreForce must have exactly as many particles as the System it belongs to.");
vector<set<int> > exceptions(owner.getNumParticles());
for (int i = 0; i < owner.getNumExceptions(); i++) {
int particle1, particle2;
double chargeProd, sigma, epsilon, softcoreLJLambda;
owner.getExceptionParameters(i, particle1, particle2, chargeProd, sigma, epsilon, softcoreLJLambda);
if (particle1 < 0 || particle1 >= owner.getNumParticles()) {
stringstream msg;
msg << "NonbondedSoftcoreForce: Illegal particle index for an exception: ";
msg << particle1;
throw OpenMMException(msg.str());
}
if (particle2 < 0 || particle2 >= owner.getNumParticles()) {
stringstream msg;
msg << "NonbondedSoftcoreForce: Illegal particle index for an exception: ";
msg << particle2;
throw OpenMMException(msg.str());
}
if (exceptions[particle1].count(particle2) > 0 || exceptions[particle2].count(particle1) > 0) {
stringstream msg;
msg << "NonbondedSoftcoreForce: Multiple exceptions are specified for particles ";
msg << particle1;
msg << " and ";
msg << particle2;
throw OpenMMException(msg.str());
}
exceptions[particle1].insert(particle2);
exceptions[particle2].insert(particle1);
}
dynamic_cast<CalcNonbondedSoftcoreForceKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner);
}
void NonbondedSoftcoreForceImpl::calcForces(ContextImpl& context ) {
dynamic_cast<CalcNonbondedSoftcoreForceKernel&>(kernel.getImpl()).executeForces(context);
}
double NonbondedSoftcoreForceImpl::calcEnergy(ContextImpl& context) {
return dynamic_cast<CalcNonbondedSoftcoreForceKernel&>(kernel.getImpl()).executeEnergy(context);
}
std::vector<std::string> NonbondedSoftcoreForceImpl::getKernelNames() {
std::vector<std::string> names;
names.push_back(CalcNonbondedSoftcoreForceKernel::Name());
return names;
}
#---------------------------------------------------
# OpenMMFreeEnergy CUDA Platform
#
# Creates OpenMM library, base name=OpenMMFreeEnergyCuda.
# Default libraries are shared & optimized. Variants
# are created for static (_static) and debug (_d).
#
# Windows:
# OpenMMFreeEnergyCuda[_d].dll
# OpenMMFreeEnergyCuda[_d].lib
# OpenMMFreeEnergyCuda_static[_d].lib
# Unix:
# libOpenMMFreeEnergyCuda[_d].so
# libOpenMMFreeEnergyCuda_static[_d].a
#----------------------------------------------------
# ----------------------------------------------------------------------------
# logging
SET(LOG TRUE)
IF(LOG)
SET(LOG_FILE "CMakeLog.txt" )
FILE( WRITE ${LOG_FILE} "In plugins/freeEnergy/platforms/cuda\n")
ENDIF(LOG)
IF(LOG)
MACRO(LOG_DIR LOG_FILE DIR_LIST )
FILE( APPEND ${LOG_FILE} "\n${DIR_LIST}\n")
FOREACH(currentFile ${ARGN})
FILE( APPEND ${LOG_FILE} " ${currentFile}\n" )
ENDFOREACH(currentFile)
ENDMACRO(LOG_DIR)
ENDIF(LOG)
# ----------------------------------------------------------------------------
SUBDIRS (tests)
# The source is organized into subdirectories, but we handle them all from
# this CMakeLists file rather than letting CMake visit them as SUBDIRS.
SET(OPENMM_FREE_ENERGY_SOURCE_SUBDIRS .)
# Collect up information about the version of the OpenMM library we're building
# and make it available to the code so it can be built into the binaries.
SET(OPENMMCUDA_LIBRARY_NAME OpenMMFreeEnergyCuda)
SET(SHARED_TARGET ${OPENMMCUDA_LIBRARY_NAME})
SET(STATIC_TARGET ${OPENMMCUDA_LIBRARY_NAME}_static)
# Ensure that debug libraries have "_d" appended to their names.
# CMake gets this right on Windows automatically with this definition.
IF (${CMAKE_GENERATOR} MATCHES "Visual Studio")
SET(CMAKE_DEBUG_POSTFIX "_d" CACHE INTERNAL "" FORCE)
ENDIF (${CMAKE_GENERATOR} MATCHES "Visual Studio")
# But on Unix or Cygwin we have to add the suffix manually
IF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
SET(SHARED_TARGET ${SHARED_TARGET}_d)
SET(STATIC_TARGET ${STATIC_TARGET}_d)
ENDIF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
# These are all the places to search for header files which are
# to be part of the API.
SET(API_FREE_ENERGY_INCLUDE_DIRS) # start empty
FOREACH(subdir ${OPENMM_FREE_ENERGY_SOURCE_SUBDIRS})
# append
SET(API_FREE_ENERGY_INCLUDE_DIRS ${API_FREE_ENERGY_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include/internal)
ENDFOREACH(subdir)
## ----------------------------------------------------------------------------
IF(LOG)
LOG_DIR( ${LOG_FILE} "OPENMM_SOURCE_SUBDIRS" ${OPENMM_SOURCE_SUBDIRS} )
LOG_DIR( ${LOG_FILE} "OPENMM_FREE_ENERGY_SOURCE_SUBDIRS" ${OPENMM_FREE_ENERGY_SOURCE_SUBDIRS} )
LOG_DIR( ${LOG_FILE} "API_FREE_ENERGY_INCLUDE_DIRS" ${API_FREE_ENERGY_INCLUDE_DIRS} )
LOG_DIR( ${LOG_FILE} "CMAKE_CURRENT_SOURCE_DIR" ${CMAKE_CURRENT_SOURCE_DIR} )
MESSAGE("\nIn0 OpenMM free/cuda: OPENMM_BUILD_FREE_ENERGY_PATH=" ${OPENMM_BUILD_FREE_ENERGY_PATH} " XXX " ${CMAKE_CURRENT_SOURCE_DIR} )
ENDIF(LOG)
## ----------------------------------------------------------------------------
# We'll need both *relative* path names, starting with their API_FREE_ENERGY_INCLUDE_DIRS,
# and absolute pathnames.
SET(API_FREE_ENERGY_REL_INCLUDE_FILES) # start these out empty
SET(API_FREE_ENERGY_ABS_INCLUDE_FILES)
FOREACH(dir ${API_FREE_ENERGY_INCLUDE_DIRS})
FILE(GLOB fullpaths ${dir}/*.h) # returns full pathnames
SET(API_FREE_ENERGY_ABS_INCLUDE_FILES ${API_FREE_ENERGY_ABS_INCLUDE_FILES} ${fullpaths})
FOREACH(pathname ${fullpaths})
GET_FILENAME_COMPONENT(filename ${pathname} NAME)
SET(API_FREE_ENERGY_REL_INCLUDE_FILES ${API_FREE_ENERGY_REL_INCLUDE_FILES} ${dir}/${filename})
ENDFOREACH(pathname)
ENDFOREACH(dir)
## ----------------------------------------------------------------------------
IF(LOG)
LOG_DIR( ${LOG_FILE} "API_FREE_ENERGY_REL_INCLUDE_FILES" ${API_FREE_ENERGY_REL_INCLUDE_FILES} )
LOG_DIR( ${LOG_FILE} "OPENMM_DIR" ${OPENMM_DIR} )
ENDIF(LOG)
## ----------------------------------------------------------------------------
# collect up source files
SET(SOURCE_FILES) # empty
SET(SOURCE_INCLUDE_FILES)
FOREACH(subdir ${OPENMM_FREE_ENERGY_SOURCE_SUBDIRS})
FILE(GLOB_RECURSE src_files ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.c)
FILE(GLOB incl_files ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.h)
SET(SOURCE_FILES ${SOURCE_FILES} ${src_files}) #append
SET(SOURCE_INCLUDE_FILES ${SOURCE_INCLUDE_FILES} ${incl_files})
LOG_DIR( ${LOG_FILE} "Adding include dir: " ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include )
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include)
ENDFOREACH(subdir)
INCLUDE_DIRECTORIES(${OPENMM_DIR}/platforms/cuda/include)
INCLUDE_DIRECTORIES(${OPENMM_DIR}/platforms/cuda/src)
INCLUDE_DIRECTORIES(${OPENMM_DIR}/platforms/cuda/src/kernels)
IF(LOG)
LOG_DIR( ${LOG_FILE} "CMAKE_CURRENT_SOURCE_DIR" ${CMAKE_CURRENT_SOURCE_DIR} )
FILE( APPEND ${LOG_FILE} "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}\n" )
LOG_DIR( ${LOG_FILE} "SOURCE_FILES" ${SOURCE_FILES} )
LOG_DIR( ${LOG_FILE} "SOURCE_INCLUDE_FILES" ${SOURCE_INCLUDE_FILES} )
ENDIF(LOG)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
SET(FINDCUDA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cuda-cmake)
SUBDIRS (sharedTarget staticTarget)
# For more information, please see: http://software.sci.utah.edu
#
# The MIT License
#
# Copyright (c) 2007
# Scientific Computing and Imaging Institute, University of Utah
#
# License for the specific language governing rights and limitations under
# 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 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.
# This code is based on the Manta swig/python wrapper dependency checking code.
# -- Abe Stephens
#####################################################################
## CUDA_INCLUDE_NVCC_DEPENDENCIES
##
# So we want to try and include the dependency file if it exists. If
# it doesn't exist then we need to create an empty one, so we can
# include it.
# If it does exist, then we need to check to see if all the files it
# depends on exist. If they don't then we should clear the dependency
# file and regenerate it later. This covers the case where a header
# file has disappeared or moved.
MACRO(CUDA_INCLUDE_NVCC_DEPENDENCIES dependency_file)
SET(CUDA_NVCC_DEPEND)
SET(CUDA_NVCC_DEPEND_REGENERATE)
# Include the dependency file. Create it first if it doesn't exist
# for make files except for IDEs (see below). The INCLUDE puts a
# dependency that will force CMake to rerun and bring in the new info
# when it changes. DO NOT REMOVE THIS (as I did and spent a few hours
# figuring out why it didn't work.
IF(${CMAKE_MAKE_PROGRAM} MATCHES "make")
IF(NOT EXISTS ${dependency_file})
CONFIGURE_FILE(
${FINDCUDA_DIR}/empty.depend.in
${dependency_file} IMMEDIATE)
ENDIF(NOT EXISTS ${dependency_file})
# Always include this file to force CMake to run again next
# invocation and rebuild the dependencies.
INCLUDE(${dependency_file})
ELSE(${CMAKE_MAKE_PROGRAM} MATCHES "make")
# for IDE generators like MS dev only include the depend files
# if they exist. This is to prevent ecessive reloading of
# workspaces after each build. This also means
# that the depends will not be correct until cmake
# is run once after the build has completed once.
# the depend files are created in the wrap tcl/python sections
# when the .xml file is parsed.
INCLUDE(${dependency_file} OPTIONAL)
ENDIF(${CMAKE_MAKE_PROGRAM} MATCHES "make")
# Now we need to verify the existence of all the included files
# here. If they aren't there we need to just blank this variable and
# make the file regenerate again.
IF(CUDA_NVCC_DEPEND)
FOREACH(f ${CUDA_NVCC_DEPEND})
IF(EXISTS ${f})
ELSE(EXISTS ${f})
SET(CUDA_NVCC_DEPEND_REGENERATE 1)
ENDIF(EXISTS ${f})
ENDFOREACH(f)
ELSE(CUDA_NVCC_DEPEND)
# No dependencies, so regenerate the file.
SET(CABLE_NVCC_DEPEND_REGENERATE 1)
ENDIF(CUDA_NVCC_DEPEND)
# No incoming dependencies, so we need to generate them. Make the
# output depend on the dependency file itself, which should cause the
# rule to re-run.
IF(CUDA_NVCC_DEPEND_REGENERATE)
SET(CUDA_NVCC_DEPEND ${dependency_file})
# Force CMake to run again next build
CONFIGURE_FILE(
${FINDCUDA_DIR}/empty.depend.in
${dependency_file} IMMEDIATE)
ENDIF(CUDA_NVCC_DEPEND_REGENERATE)
ENDMACRO(CUDA_INCLUDE_NVCC_DEPENDENCIES)
\ No newline at end of file
###############################################################################
# For more information, please see: http://software.sci.utah.edu
#
# The MIT License
#
# Copyright (c) 2007-2008
# Scientific Computing and Imaging Institute, University of Utah
#
# License for the specific language governing rights and limitations under
# 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 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.
#
# This script locates the Nvidia Compute Unified Driver Architecture (CUDA)
# tools. It should work on linux, windows, and mac and should be reasonably
# up to date with cuda releases.
#
# The script will prompt the user to specify CUDA_INSTALL_PREFIX if the
# prefix cannot be determined by the location of nvcc in the system path. To
# use a different installed version of the toolkit set the environment variable
# CUDA_BIN_PATH before running cmake (e.g. CUDA_BIN_PATH=/usr/local/cuda1.0
# instead of the default /usr/local/cuda).
#
# Set CUDA_BUILD_TYPE to "Device" or "Emulation" mode.
# _DEVICEEMU is defined in "Emulation" mode.
#
# Set CUDA_BUILD_CUBIN to "ON" or "OFF" to enable and extra compilation pass
# with the -cubin option in Device mode. The output is parsed and register,
# shared memory usage is printed during build. Default ON.
#
# The script creates the following macros:
# CUDA_INCLUDE_DIRECTORIES( path0 path1 ... )
# -- Sets the directories that should be passed to nvcc
# (e.g. nvcc -Ipath0 -Ipath1 ... ). These paths usually contain other .cu
# files.
#
# CUDA_ADD_LIBRARY( cuda_target file0 file1 ... )
# -- Creates a shared library "cuda_target" which contains all of the source
# (*.c, *.cc, etc.) specified and all of the nvcc'ed .cu files specified.
# All of the specified source files and generated .cpp files are compiled
# using the standard CMake compiler, so the normal INCLUDE_DIRECTORIES,
# LINK_DIRECTORIES, and TARGET_LINK_LIBRARIES can be used to affect their
# build and link.
#
# CUDA_ADD_EXECUTABLE( cuda_target file0 file1 ... )
# -- Same as CUDA_ADD_LIBRARY except that an exectuable is created.
#
# CUDA_COMPILE( cuda_files file0 file1 ... )
# -- Returns a list of build commands in the first argument to be used with
# ADD_LIBRARY or ADD_EXECUTABLE.
#
# The script defines the following variables:
#
# ( Note CUDA_ADD_* macros setup cuda/cut library dependencies automatically.
# These variables are only needed if a cuda API call must be made from code in
# a outside library or executable. )
#
# CUDA_INCLUDE -- Include directory for cuda headers.
# CUDA_TARGET_LINK -- Cuda RT library.
# CUDA_CUT_INCLUDE -- Include directory for cuda SDK headers (cutil.h).
# CUDA_CUT_TARGET_LINK -- SDK libraries.
# CUDA_NVCC_FLAGS -- Additional NVCC command line arguments. NOTE:
# multiple arguments must be semi-colon delimited
# e.g. --compiler-options;-Wall
# CUBLAS_TARGET_LINK-- cublas library name.
# CUFFT_TARGET_LINK -- cubfft library name.
#
# The nvcc flag "--host-compilation;c++" should be used if functions declared
# as __host__ contain C++ code.
#
# It might be necessary to set CUDA_INSTALL_PATH manually on certain platforms,
# or to use a cuda runtime not installed in the default location. In newer
# versions of the toolkit the cuda library is included with the graphics
# driver- be sure that the driver version matches what is needed by the cuda
# runtime version.
#
# -- Abe Stephens SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
###############################################################################
# FindCuda.cmake
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
INCLUDE(${FINDCUDA_DIR}/CudaDependency.cmake)
###############################################################################
###############################################################################
# Locate CUDA, Set Build Type, etc.
###############################################################################
###############################################################################
# Parse CUDA build type.
IF (NOT CUDA_BUILD_TYPE)
SET(CUDA_BUILD_TYPE "Device" CACHE STRING "Cuda build type: Emulation or Device")
ENDIF(NOT CUDA_BUILD_TYPE)
# Emulation if the card isn't present.
IF (CUDA_BUILD_TYPE MATCHES "Emulation")
# Emulation.
SET(nvcc_flags --device-emulation -D_DEVICEEMU -g)
ELSE(CUDA_BUILD_TYPE MATCHES "Emulation")
# Device present.
SET(nvcc_flags "")
ENDIF(CUDA_BUILD_TYPE MATCHES "Emulation")
SET(CUDA_BUILD_CUBIN TRUE CACHE BOOL "Generate and parse .cubin files in Device mode.")
SET(CUDA_NVCC_FLAGS "-maxrregcount=32;-use_fast_math;-O0;-arch=sm_11" CACHE STRING "Semi-colon delimit multiple arguments.")
# Search for the cuda distribution.
IF(NOT CUDA_INSTALL_PREFIX)
FIND_PATH(CUDA_INSTALL_PREFIX
NAMES nvcc nvcc.exe
PATHS /usr/local/cuda C:/CUDA
PATH_SUFFIXES bin
ENV CUDA_BIN_PATH
DOC "Toolkit location."
)
IF (CUDA_INSTALL_PREFIX)
STRING(REGEX REPLACE "[/\\\\]?bin[/\\\\]?$" "" CUDA_INSTALL_PREFIX ${CUDA_INSTALL_PREFIX})
ENDIF(CUDA_INSTALL_PREFIX)
IF (NOT EXISTS ${CUDA_INSTALL_PREFIX})
MESSAGE(FATAL_ERROR "Specify CUDA_INSTALL_PREFIX")
ENDIF (NOT EXISTS ${CUDA_INSTALL_PREFIX})
ENDIF (NOT CUDA_INSTALL_PREFIX)
# CUDA_NVCC
IF (NOT CUDA_NVCC)
FIND_PROGRAM(CUDA_NVCC
nvcc
PATHS ${CUDA_INSTALL_PREFIX}/bin $ENV{CUDA_BIN_PATH}
)
IF(NOT CUDA_NVCC)
MESSAGE(FATAL_ERROR "Could not find nvcc")
ELSE(NOT CUDA_NVCC)
MARK_AS_ADVANCED(CUDA_NVCC)
ENDIF(NOT CUDA_NVCC)
ENDIF(NOT CUDA_NVCC)
# CUDA_NVCC_INCLUDE_ARGS
# IF (NOT FOUND_CUDA_NVCC_INCLUDE)
FIND_PATH(FOUND_CUDA_NVCC_INCLUDE
device_functions.h # Header included in toolkit
PATHS ${CUDA_INSTALL_PREFIX}/include
$ENV{CUDA_INC_PATH}
)
IF(NOT FOUND_CUDA_NVCC_INCLUDE)
MESSAGE(FATAL_ERROR "Could not find Cuda headers")
ELSE(NOT FOUND_CUDA_NVCC_INCLUDE)
# Set the initial include dir.
SET (CUDA_NVCC_INCLUDE_ARGS "-I"${FOUND_CUDA_NVCC_INCLUDE})
SET (CUDA_INCLUDE ${FOUND_CUDA_NVCC_INCLUDE})
MARK_AS_ADVANCED(
FOUND_CUDA_NVCC_INCLUDE
CUDA_NVCC_INCLUDE_ARGS
)
ENDIF(NOT FOUND_CUDA_NVCC_INCLUDE)
# ENDIF(NOT FOUND_CUDA_NVCC_INCLUDE)
# CUDA_TARGET_LINK
IF (NOT CUDA_TARGET_LINK)
FIND_LIBRARY(FOUND_CUDART
cudart
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
DOC "\"cudart\" library"
)
# Check to see if cudart library was found.
IF(NOT FOUND_CUDART)
MESSAGE(FATAL_ERROR "Could not find cudart library (cudart)")
ENDIF(NOT FOUND_CUDART)
# 1.1 toolkit on linux doesn't appear to have a separate library on
# some platforms.
FIND_LIBRARY(FOUND_CUDA
cuda
PATHS ${CUDA_INSTALL_PREFIX}/lib
DOC "\"cuda\" library (older versions only)."
NO_DEFAULT_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_CMAKE_PATH
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH
)
# Add cuda library to the link line only if it is found.
IF (FOUND_CUDA)
SET(CUDA_TARGET_LINK ${FOUND_CUDA})
ENDIF(FOUND_CUDA)
# Always add cudart to the link line.
IF(FOUND_CUDART)
SET(CUDA_TARGET_LINK
${CUDA_TARGET_LINK} ${FOUND_CUDART}
)
MARK_AS_ADVANCED(
CUDA_TARGET_LINK
CUDA_LIB
FOUND_CUDA
FOUND_CUDART
)
ELSE(FOUND_CUDART)
MESSAGE(FATAL_ERROR "Could not find cuda libraries.")
ENDIF(FOUND_CUDART)
ENDIF(NOT CUDA_TARGET_LINK)
# CUDA_CUT_INCLUDE
IF(NOT CUDA_CUT_INCLUDE)
FIND_PATH(FOUND_CUT_INCLUDE
cutil.h
PATHS ${CUDA_INSTALL_PREFIX}/local/NVSDK0.2/common/inc
${CUDA_INSTALL_PREFIX}/NVSDK0.2/common/inc
${CUDA_INSTALL_PREFIX}/NV_CUDA_SDK/common/inc
$ENV{HOME}/NVIDIA_CUDA_SDK/common/inc
$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX/common/inc
$ENV{NVSDKCUDA_ROOT}/common/inc
DOC "Location of cutil.h"
)
IF(FOUND_CUT_INCLUDE)
SET(CUDA_CUT_INCLUDE ${FOUND_CUT_INCLUDE})
MARK_AS_ADVANCED(
FOUND_CUT_INCLUDE
)
ENDIF(FOUND_CUT_INCLUDE)
ENDIF(NOT CUDA_CUT_INCLUDE)
# CUDA_CUT_TARGET_LINK
IF(NOT CUDA_CUT_TARGET_LINK)
FIND_LIBRARY(FOUND_CUT
cutil
cutil32
PATHS ${CUDA_INSTALL_PREFIX}/local/NVSDK0.2/lib
${CUDA_INSTALL_PREFIX}/NVSDK0.2/lib
${CUDA_INSTALL_PREFIX}/NV_CUDA_SDK/lib
$ENV{HOME}/NVIDIA_CUDA_SDK/lib
$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX/lib
$ENV{NVSDKCUDA_ROOT}/common/lib
NO_DEFAULT_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_CMAKE_PATH
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH
DOC "Location of cutil library"
)
IF(FOUND_CUT)
SET(CUDA_CUT_TARGET_LINK ${FOUND_CUT})
MARK_AS_ADVANCED(
FOUND_CUT
)
ENDIF(FOUND_CUT)
# Add variables for cufft and cublas target link
FIND_LIBRARY(FOUND_CUFFTEMU
cufftemu
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
DOC "\"cufftemu\" library"
)
FIND_LIBRARY(FOUND_CUBLASEMU
cublasemu
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
DOC "\"cublasemu\" library"
)
FIND_LIBRARY(FOUND_CUFFT
cufft
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
DOC "\"cufft\" library"
)
FIND_LIBRARY(FOUND_CUBLAS
cublas
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
DOC "\"cublas\" library"
)
IF (CUDA_BUILD_TYPE MATCHES "Emulation")
SET(CUFFT_TARGET_LINK ${FOUND_CUFFTEMU})
SET(CUBLAS_TARGET_LINK ${FOUND_CUBLASEMU})
ELSE(CUDA_BUILD_TYPE MATCHES "Emulation")
SET(CUFFT_TARGET_LINK ${FOUND_CUFFT})
SET(CUBLAS_TARGET_LINK ${FOUND_CUBLAS})
ENDIF(CUDA_BUILD_TYPE MATCHES "Emulation")
ENDIF(NOT CUDA_CUT_TARGET_LINK)
###############################################################################
# Add include directories to pass to the nvcc command.
MACRO(CUDA_INCLUDE_DIRECTORIES)
FOREACH(dir ${ARGN})
SET(CUDA_NVCC_INCLUDE_ARGS ${CUDA_NVCC_INCLUDE_ARGS} -I${dir})
ENDFOREACH(dir ${ARGN})
ENDMACRO(CUDA_INCLUDE_DIRECTORIES)
##############################################################################
##############################################################################
# This helper macro populates the following variables and setups up custom commands and targets to
# invoke the nvcc compiler. The compiler is invoked once with -M to generate a dependency file and
# a second time with -cuda to generate a .cpp file
# ${target_srcs}
# ${cuda_cu_sources}
##############################################################################
##############################################################################
MACRO(CUDA_add_custom_commands cuda_target)
SET(target_srcs "")
SET(cuda_cu_sources "")
# Iterate over the macro arguments and create custom
# commands for all the .cu files.
FOREACH(file ${ARGN})
IF(${file} MATCHES ".*\\.cu$")
# Add a custom target to generate a c file.
SET(generated_file "${CMAKE_BINARY_DIR}/src/cuda/${file}_${cuda_target}_generated.cpp")
SET(generated_target "${file}_target")
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/cuda)
SET(source_file ${CMAKE_CURRENT_SOURCE_DIR}/../${file})
# MESSAGE("${CUDA_NVCC} ${source_file} ${CUDA_NVCC_FLAGS} ${nvcc_flags} -cuda -o ${generated_file} ${CUDA_NVCC_INCLUDE_ARGS}")
# Bring in the dependencies. Creates a variable CUDA_NVCC_DEPEND
SET(cmake_dependency_file "${generated_file}.depend")
CUDA_INCLUDE_NVCC_DEPENDENCIES(${cmake_dependency_file})
SET(NVCC_generated_dependency_file "${generated_file}.NVCC-depend")
# Build the NVCC made dependency file
IF (CUDA_BUILD_TYPE MATCHES "Device" AND CUDA_BUILD_CUBIN)
SET(NVCC_generated_cubin_file "${generated_file}.NVCC-cubin.txt")
ADD_CUSTOM_COMMAND(
# Generate the .cubin output.
OUTPUT ${NVCC_generated_cubin_file}
COMMAND ${CUDA_NVCC}
ARGS ${source_file}
${CUDA_NVCC_FLAGS}
${nvcc_flags}
-DNVCC
-cubin
-o ${NVCC_generated_cubin_file}
${CUDA_NVCC_INCLUDE_ARGS}
# Execute the parser script.
COMMAND ${CMAKE_COMMAND}
ARGS
-D input_file="${NVCC_generated_cubin_file}"
-P "${FINDCUDA_DIR}/parse_cubin.cmake"
# MAIN_DEPENDENCY ${source_file}
DEPENDS ${source_file}
DEPENDS ${CUDA_NVCC_DEPEND}
COMMENT "Building (${CUDA_BUILD_TYPE}) NVCC -cubin File: ${NVCC_generated_cubin_file}\n"
)
ELSE (CUDA_BUILD_TYPE MATCHES "Device" AND CUDA_BUILD_CUBIN)
# Depend on something that will exist.
SET(NVCC_generated_cubin_file "${source_file}")
ENDIF (CUDA_BUILD_TYPE MATCHES "Device"AND CUDA_BUILD_CUBIN)
# Build the NVCC made dependency file
ADD_CUSTOM_COMMAND(
OUTPUT ${NVCC_generated_dependency_file}
COMMAND ${CUDA_NVCC}
ARGS ${source_file}
${CUDA_NVCC_FLAGS}
${nvcc_flags}
-DNVCC
-M
-o ${NVCC_generated_dependency_file}
${CUDA_NVCC_INCLUDE_ARGS}
# MAIN_DEPENDENCY ${source_file}
DEPENDS ${source_file}
DEPENDS ${CUDA_NVCC_DEPEND}
COMMENT "Building (${CUDA_BUILD_TYPE}) NVCC Dependency File: ${NVCC_generated_dependency_file}\n"
)
# Build the CMake readible dependency file
ADD_CUSTOM_COMMAND(
OUTPUT ${cmake_dependency_file}
COMMAND ${CMAKE_COMMAND}
ARGS
-D input_file="${NVCC_generated_dependency_file}"
-D output_file="${cmake_dependency_file}"
-P "${FINDCUDA_DIR}/make2cmake.cmake"
MAIN_DEPENDENCY ${NVCC_generated_dependency_file}
COMMENT "Converting NVCC dependency to CMake (${cmake_dependency_file})"
)
ADD_CUSTOM_COMMAND(
OUTPUT ${generated_file}
MAIN_DEPENDENCY ${source_file}
DEPENDS ${CUDA_NVCC_DEPEND}
DEPENDS ${cmake_dependency_file}
DEPENDS ${NVCC_generated_cubin_file}
COMMAND ${CUDA_NVCC}
ARGS ${source_file}
${CUDA_NVCC_FLAGS}
${nvcc_flags}
${CUDA_NVCC_BUILD_FLAGS}
-DNVCC
--keep
-cuda -o ${generated_file}
${CUDA_NVCC_INCLUDE_ARGS}
COMMENT "Building (${CUDA_BUILD_TYPE}) NVCC ${source_file}: ${generated_file}\n"
)
SET(cuda_cu_sources ${cuda_cu_sources} ${source_file})
# Add the generated file name to the source list.
SET(target_srcs ${target_srcs} ${generated_file})
ELSE(${file} MATCHES ".*\\.cu$")
# Otherwise add the file name to the source list.
SET(target_srcs ${target_srcs} ${file})
ENDIF(${file} MATCHES ".*\\.cu$")
ENDFOREACH(file)
ENDMACRO(CUDA_add_custom_commands)
###############################################################################
###############################################################################
# ADD LIBRARY
###############################################################################
###############################################################################
MACRO(CUDA_ADD_LIBRARY cuda_target)
# Create custom commands and targets for each file.
CUDA_add_custom_commands( ${cuda_target} ${ARGN} )
# Add the library.
ADD_LIBRARY(${cuda_target}
${target_srcs}
${cuda_cu_sources}
)
TARGET_LINK_LIBRARIES(${cuda_target}
${CUDA_TARGET_LINK}
)
ENDMACRO(CUDA_ADD_LIBRARY cuda_target)
###############################################################################
###############################################################################
# ADD EXECUTABLE
###############################################################################
###############################################################################
MACRO(CUDA_ADD_EXECUTABLE cuda_target)
# Create custom commands and targets for each file.
CUDA_add_custom_commands( ${cuda_target} ${ARGN} )
# Add the library.
ADD_EXECUTABLE(${cuda_target}
${target_srcs}
${cuda_cu_sources}
)
TARGET_LINK_LIBRARIES(${cuda_target}
${CUDA_TARGET_LINK}
)
ENDMACRO(CUDA_ADD_EXECUTABLE cuda_target)
###############################################################################
###############################################################################
# ADD EXECUTABLE
###############################################################################
###############################################################################
MACRO(CUDA_COMPILE file_variable)
# Create custom commands and targets for each file.
CUDA_add_custom_commands( cuda_compile ${ARGN} )
SET(file_variable ${target_srcs} ${cuda_cu_sources})
ENDMACRO(CUDA_COMPILE)
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