├── .codecov.yml ├── python ├── imports.py ├── CMakeLists.txt ├── setup.py ├── rigidbodyplugin.i ├── statedatareporter.py └── forcefield.py ├── TODO.md ├── .gitignore ├── Makefile ├── serialization ├── tests │ ├── CMakeLists.txt │ └── TestSerializeRigidBodyIntegrator.cpp ├── include │ └── RigidBodyIntegratorProxy.h └── src │ ├── RigidBodySerializationProxyRegistration.cpp │ └── RigidBodyIntegratorProxy.cpp ├── platforms ├── reference │ ├── tests │ │ ├── CMakeLists.txt │ │ ├── TestReferenceRigidBodyIntegrator.cpp │ │ └── ReferenceRigidBodyTests.h │ ├── CMakeLists.txt │ ├── include │ │ └── ReferenceRigidBodyKernelFactory.h │ └── src │ │ ├── ReferenceRigidBodyKernelFactory.cpp │ │ ├── ReferenceRigidBodyKernels.h │ │ └── ReferenceRigidBodyKernels.cpp ├── opencl │ ├── tests │ │ ├── CMakeLists.txt │ │ ├── TestOpenCLRigidBodyIntegrator.cpp │ │ └── OpenCLRigidBodyTests.h │ ├── EncodeCLFiles.cmake │ ├── src │ │ ├── OpenCLRigidBodyKernelSources.cpp.in │ │ ├── OpenCLRigidBodyKernelSources.h.in │ │ ├── OpenCLRigidBodyKernelFactory.cpp │ │ ├── kernels │ │ │ └── rigidbodyintegrator.cl │ │ ├── OpenCLRigidBodyKernels.h │ │ └── OpenCLRigidBodyKernels.cpp │ ├── include │ │ └── OpenCLRigidBodyKernelFactory.h │ └── CMakeLists.txt └── cuda │ ├── tests │ ├── CMakeLists.txt │ ├── TestCudaRigidBodyIntegrator.cpp │ └── CudaRigidBodyTests.h │ ├── EncodeCUDAFiles.cmake │ ├── src │ ├── CudaRigidBodyKernelSources.cpp.in │ ├── CudaRigidBodyKernelSources.h.in │ ├── CudaRigidBodyKernelFactory.cpp │ ├── CudaRigidBodyKernels.h │ └── kernels │ │ ├── elliptic.cu │ │ └── vectorOps.cu │ ├── include │ └── CudaRigidBodyKernelFactory.h │ └── CMakeLists.txt ├── LICENSE ├── openmmapi ├── include │ ├── internal │ │ ├── eigenDecomposition.h │ │ ├── windowsExportRigidBody.h │ │ └── MatVec.h │ ├── RigidBodySystem.h │ ├── RigidBody.h │ ├── RigidBodyKernels.h │ └── RigidBodyIntegrator.h └── src │ ├── RigidBodyIntegrator.cpp │ ├── eigenDecomposition.cpp │ └── RigidBodySystem.cpp ├── .travis.yml ├── cmake ├── FindOpenCL.cmake ├── FindGcov.cmake └── Findcodecov.cmake └── CMakeLists.txt /.codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | -------------------------------------------------------------------------------- /python/imports.py: -------------------------------------------------------------------------------- 1 | %pythoncode %{ 2 | import simtk.openmm as mm 3 | import simtk.openmm.app as app 4 | import simtk.unit as unit 5 | import re 6 | %} 7 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | TO DO LIST 2 | ---------- 3 | 4 | 1. Implement a CMMotionRemover force for rigid bodies (or a CMMotionRemove option in integrator) 5 | 2. Download RigidBodySystem before exposing it using RigidBodyIntegrator.getRigidBodySystem 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build directory: 2 | build/ 3 | 4 | # Prerequisites 5 | *.d 6 | 7 | # Compiled Object files 8 | *.slo 9 | *.lo 10 | *.o 11 | *.obj 12 | 13 | # Precompiled Headers 14 | *.gch 15 | *.pch 16 | 17 | # Compiled Dynamic libraries 18 | *.so 19 | *.dylib 20 | *.dll 21 | 22 | # Fortran module files 23 | *.mod 24 | *.smod 25 | 26 | # Compiled Static libraries 27 | *.lai 28 | *.la 29 | *.a 30 | *.lib 31 | 32 | # Executables 33 | *.exe 34 | *.out 35 | *.app 36 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Installation prefix: 2 | #PREFIX ?= /usr/local/openmm 3 | PREFIX ?= /home/charlles/Software/anaconda3/pkgs/openmm-7.2.1-py36_1 4 | NPROC ?= 4 5 | 6 | all: 7 | mkdir -p build/ 8 | cd build && cmake -DOPENMM_DIR=${PREFIX} .. 9 | cd build && make -j ${NPROC} 10 | 11 | .PHONY: install clean PythonInstall 12 | 13 | test: 14 | cd build && make -j ${NPROC} test 15 | 16 | install: 17 | cd build && make -j ${NPROC} install 18 | 19 | PythonInstall: 20 | cd build && make -j ${NPROC} PythonInstall 21 | 22 | clean: 23 | rm -rf build/* 24 | -------------------------------------------------------------------------------- /serialization/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Testing 3 | # 4 | 5 | # Automatically create tests using files named "Test*.cpp" 6 | FILE(GLOB TEST_PROGS "*Test*.cpp") 7 | FOREACH(TEST_PROG ${TEST_PROGS}) 8 | GET_FILENAME_COMPONENT(TEST_ROOT ${TEST_PROG} NAME_WE) 9 | 10 | # Link with shared library 11 | 12 | ADD_EXECUTABLE(${TEST_ROOT} ${TEST_PROG}) 13 | TARGET_LINK_LIBRARIES(${TEST_ROOT} ${SHARED_RIGIDBODY_TARGET}) 14 | SET_TARGET_PROPERTIES(${TEST_ROOT} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS}" COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS}") 15 | ADD_TEST(${TEST_ROOT} ${EXECUTABLE_OUTPUT_PATH}/${TEST_ROOT}) 16 | 17 | ENDFOREACH(TEST_PROG ${TEST_PROGS}) 18 | -------------------------------------------------------------------------------- /serialization/include/RigidBodyIntegratorProxy.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENMM_RIGIDBODY_INTEGRATOR_PROXY_H_ 2 | #define OPENMM_RIGIDBODY_INTEGRATOR_PROXY_H_ 3 | 4 | #include "internal/windowsExportRigidBody.h" 5 | #include "openmm/serialization/SerializationProxy.h" 6 | //#include "openmm/serialization/XmlSerializer.h" 7 | 8 | namespace RigidBodyPlugin { 9 | 10 | class RigidBodyIntegratorProxy : public OpenMM::SerializationProxy { 11 | public: 12 | RigidBodyIntegratorProxy(); 13 | void serialize(const void* object, OpenMM::SerializationNode& node) const; 14 | void* deserialize(const OpenMM::SerializationNode& node) const; 15 | }; 16 | 17 | } 18 | 19 | #endif /*OPENMM_RIGIDBODY_INTEGRATOR_PROXY_H_*/ 20 | -------------------------------------------------------------------------------- /platforms/reference/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Testing 3 | # 4 | 5 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/tests) 6 | 7 | # Automatically create tests using files named "Test*.cpp" 8 | FILE(GLOB TEST_PROGS "*Test*.cpp") 9 | FOREACH(TEST_PROG ${TEST_PROGS}) 10 | GET_FILENAME_COMPONENT(TEST_ROOT ${TEST_PROG} NAME_WE) 11 | 12 | # Link with shared library 13 | 14 | ADD_EXECUTABLE(${TEST_ROOT} ${TEST_PROG}) 15 | TARGET_LINK_LIBRARIES(${TEST_ROOT} ${SHARED_TARGET}) 16 | SET_TARGET_PROPERTIES(${TEST_ROOT} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS}" COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS}") 17 | ADD_TEST(${TEST_ROOT} ${EXECUTABLE_OUTPUT_PATH}/${TEST_ROOT}) 18 | 19 | ENDFOREACH(TEST_PROG ${TEST_PROGS}) 20 | -------------------------------------------------------------------------------- /platforms/opencl/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Testing 3 | # 4 | 5 | INCLUDE_DIRECTORIES(${OPENCL_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/tests) 6 | 7 | # Automatically create tests using files named "Test*.cpp" 8 | FILE(GLOB TEST_PROGS "*Test*.cpp") 9 | FOREACH(TEST_PROG ${TEST_PROGS}) 10 | GET_FILENAME_COMPONENT(TEST_ROOT ${TEST_PROG} NAME_WE) 11 | 12 | # Link with shared library 13 | ADD_EXECUTABLE(${TEST_ROOT} ${TEST_PROG}) 14 | TARGET_LINK_LIBRARIES(${TEST_ROOT} ${SHARED_RIGIDBODY_TARGET} ${SHARED_TARGET}) 15 | SET_TARGET_PROPERTIES(${TEST_ROOT} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS}" COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS}") 16 | ADD_TEST(${TEST_ROOT}Single ${EXECUTABLE_OUTPUT_PATH}/${TEST_ROOT} single) 17 | ADD_TEST(${TEST_ROOT}Mixed ${EXECUTABLE_OUTPUT_PATH}/${TEST_ROOT} mixed) 18 | ADD_TEST(${TEST_ROOT}Double ${EXECUTABLE_OUTPUT_PATH}/${TEST_ROOT} double) 19 | 20 | ENDFOREACH(TEST_PROG ${TEST_PROGS}) 21 | -------------------------------------------------------------------------------- /python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(WRAP_FILE RigidBodyPluginWrapper.cpp) 2 | set(MODULE_NAME rigidbodyplugin) 3 | 4 | # Execute SWIG to generate source code for the Python module. 5 | 6 | add_custom_command( 7 | OUTPUT "${WRAP_FILE}" 8 | COMMAND "${SWIG_EXECUTABLE}" 9 | -python -c++ 10 | -o "${WRAP_FILE}" 11 | "-I${OPENMM_DIR}/include" 12 | "${CMAKE_CURRENT_SOURCE_DIR}/rigidbodyplugin.i" 13 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/rigidbodyplugin.i" "${CMAKE_CURRENT_SOURCE_DIR}/*.py" 14 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" 15 | ) 16 | 17 | # Compile the Python module. 18 | 19 | add_custom_target(PythonInstall DEPENDS "${WRAP_FILE}") 20 | set(RIGIDBODYPLUGIN_HEADER_DIR "${CMAKE_SOURCE_DIR}/openmmapi/include") 21 | set(RIGIDBODYPLUGIN_LIBRARY_DIR "${CMAKE_BINARY_DIR}") 22 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py ${CMAKE_CURRENT_BINARY_DIR}/setup.py) 23 | add_custom_command(TARGET PythonInstall 24 | COMMAND "${PYTHON_EXECUTABLE}" setup.py build 25 | COMMAND "${PYTHON_EXECUTABLE}" setup.py install 26 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" 27 | ) 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018, Charlles R. A. Abreu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software 6 | and associated documentation files (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all copies or 12 | substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 15 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 16 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /platforms/cuda/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Testing 3 | # 4 | 5 | INCLUDE_DIRECTORIES(${CUDA_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/tests) 6 | 7 | # Automatically create tests using files named "Test*.cpp" 8 | FILE(GLOB TEST_PROGS "*Test*.cpp") 9 | FOREACH(TEST_PROG ${TEST_PROGS}) 10 | GET_FILENAME_COMPONENT(TEST_ROOT ${TEST_PROG} NAME_WE) 11 | 12 | # Link with shared library 13 | ADD_EXECUTABLE(${TEST_ROOT} ${TEST_PROG}) 14 | TARGET_LINK_LIBRARIES(${TEST_ROOT} ${SHARED_RIGIDBODY_TARGET} ${SHARED_TARGET}) 15 | IF (APPLE) 16 | SET_TARGET_PROPERTIES(${TEST_ROOT} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS} -F/Library/Frameworks -framework CUDA" COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS}") 17 | ELSE (APPLE) 18 | SET_TARGET_PROPERTIES(${TEST_ROOT} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS}" COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS}") 19 | ENDIF (APPLE) 20 | ADD_TEST(${TEST_ROOT}Single ${EXECUTABLE_OUTPUT_PATH}/${TEST_ROOT} single) 21 | ADD_TEST(${TEST_ROOT}Mixed ${EXECUTABLE_OUTPUT_PATH}/${TEST_ROOT} mixed) 22 | ADD_TEST(${TEST_ROOT}Double ${EXECUTABLE_OUTPUT_PATH}/${TEST_ROOT} double) 23 | 24 | ENDFOREACH(TEST_PROG ${TEST_PROGS}) 25 | -------------------------------------------------------------------------------- /python/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | from distutils.extension import Extension 3 | import os 4 | import sys 5 | import platform 6 | 7 | openmm_dir = '@OPENMM_DIR@' 8 | rigidbodyplugin_header_dir = '@RIGIDBODYPLUGIN_HEADER_DIR@' 9 | rigidbodyplugin_library_dir = '@RIGIDBODYPLUGIN_LIBRARY_DIR@' 10 | 11 | # setup extra compile and link arguments on Mac 12 | extra_compile_args = [] 13 | extra_link_args = [] 14 | 15 | if platform.system() == 'Darwin': 16 | extra_compile_args += ['-stdlib=libc++', '-mmacosx-version-min=10.7'] 17 | extra_link_args += ['-stdlib=libc++', '-mmacosx-version-min=10.7', '-Wl', '-rpath', openmm_dir+'/lib'] 18 | 19 | extension = Extension(name='_rigidbodyplugin', 20 | sources=['RigidBodyPluginWrapper.cpp'], 21 | libraries=['OpenMM', 'RigidBodyPlugin'], 22 | include_dirs=[os.path.join(openmm_dir, 'include'), rigidbodyplugin_header_dir], 23 | library_dirs=[os.path.join(openmm_dir, 'lib'), rigidbodyplugin_library_dir], 24 | extra_compile_args=extra_compile_args, 25 | extra_link_args=extra_link_args 26 | ) 27 | 28 | setup(name='rigidbodyplugin', 29 | version='1.0', 30 | py_modules=['rigidbodyplugin'], 31 | ext_modules=[extension], 32 | ) 33 | -------------------------------------------------------------------------------- /openmmapi/include/internal/eigenDecomposition.h: -------------------------------------------------------------------------------- 1 | // ---------------------------------------------------------------------------- 2 | // Numerical diagonalization of 3x3 matrcies 3 | // Copyright (C) 2006 Joachim Kopp 4 | // ---------------------------------------------------------------------------- 5 | // This library is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU Lesser General Public 7 | // License as published by the Free Software Foundation; either 8 | // version 2.1 of the License, or (at your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | // Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public 16 | // License along with this library; if not, write to the Free Software 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | // ---------------------------------------------------------------------------- 19 | #ifndef __EIGENDECOMPOSITION_H 20 | #define __EIGENDECOMPOSITION_H 21 | 22 | #include "internal/MatVec.h" 23 | #include "openmm/Vec3.h" 24 | 25 | using namespace OpenMM; 26 | using namespace RigidBodyPlugin; 27 | 28 | Vec3 eigenvalues(Mat3 a); 29 | Mat3 eigenvectors(Mat3 A, Vec3& w); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /platforms/opencl/EncodeCLFiles.cmake: -------------------------------------------------------------------------------- 1 | FILE(GLOB OPENCL_KERNELS ${CL_SOURCE_DIR}/kernels/*.cl) 2 | SET(CL_FILE_DECLARATIONS) 3 | SET(CL_FILE_DEFINITIONS) 4 | CONFIGURE_FILE(${CL_SOURCE_DIR}/${CL_SOURCE_CLASS}.cpp.in ${CL_KERNELS_CPP}) 5 | FOREACH(file ${OPENCL_KERNELS}) 6 | # Load the file contents and process it. 7 | FILE(STRINGS ${file} file_content NEWLINE_CONSUME) 8 | # Replace all backslashes by double backslashes as they are being put in a C string. 9 | # Be careful not to replace the backslash before a semicolon as that is the CMAKE 10 | # internal escaping of a semicolon to prevent it from acting as a list seperator. 11 | STRING(REGEX REPLACE "\\\\([^;])" "\\\\\\\\\\1" file_content "${file_content}") 12 | # Escape double quotes as being put in a C string. 13 | STRING(REPLACE "\"" "\\\"" file_content "${file_content}") 14 | # Split in separate C strings for each line. 15 | STRING(REPLACE "\n" "\\n\"\n\"" file_content "${file_content}") 16 | 17 | # Determine a name for the variable that will contain this file's contents 18 | FILE(RELATIVE_PATH filename ${CL_SOURCE_DIR}/kernels ${file}) 19 | STRING(LENGTH ${filename} filename_length) 20 | MATH(EXPR filename_length ${filename_length}-3) 21 | STRING(SUBSTRING ${filename} 0 ${filename_length} variable_name) 22 | 23 | # Record the variable declaration and definition. 24 | SET(CL_FILE_DECLARATIONS ${CL_FILE_DECLARATIONS}static\ const\ std::string\ ${variable_name};\n) 25 | FILE(APPEND ${CL_KERNELS_CPP} const\ string\ ${CL_SOURCE_CLASS}::${variable_name}\ =\ \"${file_content}\"\;\n) 26 | ENDFOREACH(file) 27 | CONFIGURE_FILE(${CL_SOURCE_DIR}/${CL_SOURCE_CLASS}.h.in ${CL_KERNELS_H}) 28 | -------------------------------------------------------------------------------- /platforms/cuda/EncodeCUDAFiles.cmake: -------------------------------------------------------------------------------- 1 | FILE(GLOB CUDA_KERNELS ${CUDA_SOURCE_DIR}/kernels/*.cu) 2 | SET(CUDA_FILE_DECLARATIONS) 3 | SET(CUDA_FILE_DEFINITIONS) 4 | CONFIGURE_FILE(${CUDA_SOURCE_DIR}/${CUDA_SOURCE_CLASS}.cpp.in ${CUDA_KERNELS_CPP}) 5 | FOREACH(file ${CUDA_KERNELS}) 6 | # Load the file contents and process it. 7 | FILE(STRINGS ${file} file_content NEWLINE_CONSUME) 8 | # Replace all backslashes by double backslashes as they are being put in a C string. 9 | # Be careful not to replace the backslash before a semicolon as that is the CMAKE 10 | # internal escaping of a semicolon to prevent it from acting as a list seperator. 11 | STRING(REGEX REPLACE "\\\\([^;])" "\\\\\\\\\\1" file_content "${file_content}") 12 | # Escape double quotes as being put in a C string. 13 | STRING(REPLACE "\"" "\\\"" file_content "${file_content}") 14 | # Split in separate C strings for each line. 15 | STRING(REPLACE "\n" "\\n\"\n\"" file_content "${file_content}") 16 | 17 | # Determine a name for the variable that will contain this file's contents 18 | FILE(RELATIVE_PATH filename ${CUDA_SOURCE_DIR}/kernels ${file}) 19 | STRING(LENGTH ${filename} filename_length) 20 | MATH(EXPR filename_length ${filename_length}-3) 21 | STRING(SUBSTRING ${filename} 0 ${filename_length} variable_name) 22 | 23 | # Record the variable declaration and definition. 24 | SET(CUDA_FILE_DECLARATIONS ${CUDA_FILE_DECLARATIONS}static\ const\ std::string\ ${variable_name};\n) 25 | FILE(APPEND ${CUDA_KERNELS_CPP} const\ string\ ${CUDA_SOURCE_CLASS}::${variable_name}\ =\ \"${file_content}\"\;\n) 26 | ENDFOREACH(file) 27 | CONFIGURE_FILE(${CUDA_SOURCE_DIR}/${CUDA_SOURCE_CLASS}.h.in ${CUDA_KERNELS_H}) 28 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | compiler: 4 | - gcc 5 | 6 | sudo: required 7 | 8 | dist: trusty 9 | 10 | env: 11 | global: 12 | - CUDA_VERSION="7.5-18" 13 | 14 | addons: 15 | apt: 16 | packages: 17 | - cmake 18 | - lcov 19 | 20 | before_install: 21 | # CUDA Installation: 22 | - wget "http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_${CUDA_VERSION}_amd64.deb" 23 | - sudo dpkg -i cuda-repo-ubuntu1404_${CUDA_VERSION}_amd64.deb 24 | - sudo apt-get update -qq 25 | - export CUDA_APT=${CUDA_VERSION%-*} 26 | - export CUDA_APT=${CUDA_APT/./-} 27 | - sudo apt-get install -y cuda-drivers cuda-core-${CUDA_APT} cuda-cudart-dev-${CUDA_APT} cuda-cufft-dev-${CUDA_APT} 28 | - sudo apt-get clean 29 | - export CUDA_HOME=/usr/local/cuda-${CUDA_VERSION%%-*} 30 | - export LD_LIBRARY_PATH=${CUDA_HOME}/lib64/stubs:${LD_LIBRARY_PATH} 31 | - export PATH=${CUDA_HOME}/bin:${PATH} 32 | - sudo apt-get install -y libgl1-mesa-dev 33 | # OpenMM and SWIG installation: 34 | - wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh 35 | - bash Miniconda3-latest-Linux-x86_64.sh -b 36 | - export PATH=$HOME/miniconda3/bin:$PATH 37 | - conda config --add channels http://conda.binstar.org/omnia 38 | - conda create --yes -n py3 python=3.6 39 | - source activate py3 40 | - conda install --yes openmm-cuda75 swig 41 | install: 42 | - mkdir build 43 | - cd build 44 | - export PY3=$HOME/miniconda3/envs/py3 45 | - cmake .. -DENABLE_COVERAGE=On -DENABLE_COVERAGE_ALL=On -DBUILD_CUDA_TESTS=OFF -DCMAKE_INSTALL_PREFIX=$PY3 -DOPENMM_DIR=$PY3 -DSWIG_EXECUTABLE=$PY3/bin/swig 46 | - make VERBOSE=1 47 | - make install 48 | - make PythonInstall 49 | 50 | script: 51 | - make test 52 | 53 | after_success: 54 | - make gcov 55 | - make lcov 56 | - bash <(curl -s https://codecov.io/bash) -X gcov || echo "Codecov did not collect coverage reports" 57 | -------------------------------------------------------------------------------- /openmmapi/include/internal/windowsExportRigidBody.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENMM_WINDOWSEXPORTRIGIDBODY_H_ 2 | #define OPENMM_WINDOWSEXPORTRIGIDBODY_H_ 3 | 4 | /* 5 | * Shared libraries are messy in Visual Studio. We have to distinguish three 6 | * cases: 7 | * (1) this header is being used to build the OpenMM shared library 8 | * (dllexport) 9 | * (2) this header is being used by a *client* of the OpenMM shared 10 | * library (dllimport) 11 | * (3) we are building the OpenMM static library, or the client is 12 | * being compiled with the expectation of linking with the 13 | * OpenMM static library (nothing special needed) 14 | * In the CMake script for building this library, we define one of the symbols 15 | * RIGIDBODY_BUILDING_{SHARED|STATIC}_LIBRARY 16 | * Client code normally has no special symbol defined, in which case we'll 17 | * assume it wants to use the shared library. However, if the client defines 18 | * the symbol OPENMM_USE_STATIC_LIBRARIES we'll suppress the dllimport so 19 | * that the client code can be linked with static libraries. Note that 20 | * the client symbol is not library dependent, while the library symbols 21 | * affect only the OpenMM library, meaning that other libraries can 22 | * be clients of this one. However, we are assuming all-static or all-shared. 23 | */ 24 | 25 | #ifdef _MSC_VER 26 | // We don't want to hear about how sprintf is "unsafe". 27 | #pragma warning(disable:4996) 28 | // Keep MS VC++ quiet about lack of dll export of private members. 29 | #pragma warning(disable:4251) 30 | #if defined(RIGIDBODY_BUILDING_SHARED_LIBRARY) 31 | #define OPENMM_EXPORT_RIGIDBODY __declspec(dllexport) 32 | #elif defined(RIGIDBODY_BUILDING_STATIC_LIBRARY) || defined(RIGIDBODY_USE_STATIC_LIBRARIES) 33 | #define OPENMM_EXPORT_RIGIDBODY 34 | #else 35 | #define OPENMM_EXPORT_RIGIDBODY __declspec(dllimport) // i.e., a client of a shared library 36 | #endif 37 | #else 38 | #define OPENMM_EXPORT_RIGIDBODY // Linux, Mac 39 | #endif 40 | 41 | #endif // OPENMM_WINDOWSEXPORTRIGIDBODY_H_ 42 | -------------------------------------------------------------------------------- /platforms/reference/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------- 2 | # OpenMM RigidBody Plugin Reference Platform 3 | #---------------------------------------------------- 4 | 5 | # Collect up information about the version of the OpenMM library we're building 6 | # and make it available to the code so it can be built into the binaries. 7 | 8 | SET(OPENMMRIGIDBODYREFERENCE_LIBRARY_NAME RigidBodyPluginReference) 9 | 10 | SET(SHARED_TARGET ${OPENMMRIGIDBODYREFERENCE_LIBRARY_NAME}) 11 | 12 | 13 | # These are all the places to search for header files which are 14 | # to be part of the API. 15 | SET(API_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/include/internal") 16 | 17 | # Locate header files. 18 | SET(API_INCLUDE_FILES) 19 | FOREACH(dir ${API_INCLUDE_DIRS}) 20 | FILE(GLOB fullpaths ${dir}/*.h) 21 | SET(API_INCLUDE_FILES ${API_INCLUDE_FILES} ${fullpaths}) 22 | ENDFOREACH(dir) 23 | 24 | # collect up source files 25 | SET(SOURCE_FILES) # empty 26 | SET(SOURCE_INCLUDE_FILES) 27 | 28 | FILE(GLOB_RECURSE src_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.c) 29 | FILE(GLOB incl_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h) 30 | SET(SOURCE_FILES ${SOURCE_FILES} ${src_files}) #append 31 | SET(SOURCE_INCLUDE_FILES ${SOURCE_INCLUDE_FILES} ${incl_files}) 32 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include) 33 | 34 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src) 35 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/platforms/reference/include) 36 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/platforms/reference/src) 37 | 38 | # Create the library 39 | 40 | INCLUDE_DIRECTORIES(${REFERENCE_INCLUDE_DIR}) 41 | 42 | ADD_LIBRARY(${SHARED_TARGET} SHARED ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_INCLUDE_FILES}) 43 | 44 | TARGET_LINK_LIBRARIES(${SHARED_TARGET} OpenMM) 45 | TARGET_LINK_LIBRARIES(${SHARED_TARGET} debug ${SHARED_RIGIDBODY_TARGET} optimized ${SHARED_RIGIDBODY_TARGET}) 46 | SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES 47 | COMPILE_FLAGS "-DOPENMM_BUILDING_SHARED_LIBRARY ${EXTRA_COMPILE_FLAGS}" 48 | LINK_FLAGS "${EXTRA_COMPILE_FLAGS}") 49 | 50 | INSTALL(TARGETS ${SHARED_TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/plugins) 51 | SUBDIRS (tests) 52 | -------------------------------------------------------------------------------- /python/rigidbodyplugin.i: -------------------------------------------------------------------------------- 1 | %module rigidbodyplugin 2 | 3 | %import(module="simtk.openmm") "swig/OpenMMSwigHeaders.i" 4 | %include "swig/typemaps.i" 5 | 6 | %include "std_vector.i" 7 | namespace std { 8 | %template(vectori) vector; 9 | %template(vectord) std::vector; 10 | }; 11 | 12 | %{ 13 | #include "RigidBodyIntegrator.h" 14 | #include "OpenMM.h" 15 | #include "OpenMMAmoeba.h" 16 | #include "OpenMMDrude.h" 17 | #include "openmm/RPMDIntegrator.h" 18 | #include "openmm/RPMDMonteCarloBarostat.h" 19 | %} 20 | 21 | %include "imports.py" 22 | %include "forcefield.py" 23 | %include "statedatareporter.py" 24 | 25 | %pythonappend RigidBodyPlugin::RigidBodySystem::getTranslationalEnergy() const %{ 26 | val = unit.Quantity(val, unit.kilojoule_per_mole) 27 | %} 28 | 29 | %pythonappend RigidBodyPlugin::RigidBodySystem::getRotationalEnergy() const %{ 30 | val = unit.Quantity(val, unit.kilojoule_per_mole) 31 | %} 32 | 33 | %pythonappend RigidBodyPlugin::RigidBodySystem::getKineticEnergy() const %{ 34 | val = unit.Quantity(val, unit.kilojoule_per_mole) 35 | %} 36 | 37 | %pythonappend RigidBodyPlugin::RigidBodyIntegrator::getKineticEnergies() %{ 38 | val = tuple(unit.Quantity(v, unit.kilojoule_per_mole) for v in val) 39 | %} 40 | 41 | %pythonappend RigidBodyPlugin::RigidBodyIntegrator::getRefinedKineticEnergies() %{ 42 | val = tuple(unit.Quantity(v, unit.kilojoule_per_mole) for v in val) 43 | %} 44 | 45 | %pythonappend RigidBodyPlugin::RigidBodyIntegrator::getPotentialEnergyRefinement() %{ 46 | val = unit.Quantity(val, unit.kilojoule_per_mole) 47 | %} 48 | 49 | namespace RigidBodyPlugin { 50 | 51 | class RigidBodySystem { 52 | public: 53 | int getNumDOF() const; 54 | double getTranslationalEnergy() const; 55 | double getRotationalEnergy() const; 56 | double getKineticEnergy() const; 57 | }; 58 | 59 | class RigidBodyIntegrator : public OpenMM::Integrator { 60 | public: 61 | explicit RigidBodyIntegrator(double stepSize, const std::vector& bodyIndices); 62 | void setRotationMode(int mode); 63 | int getRotationMode(); 64 | void setComputeRefinedEnergies(bool compute); 65 | bool getComputeRefinedEnergies(); 66 | RigidBodySystem getRigidBodySystem(); 67 | std::vector getKineticEnergies(); 68 | std::vector getRefinedKineticEnergies(); 69 | double getPotentialEnergyRefinement(); 70 | void step(int steps); 71 | }; 72 | 73 | } 74 | -------------------------------------------------------------------------------- /openmmapi/include/RigidBodySystem.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMM Rigid Body Plugin * 3 | * -------------------------------------------------------------------------- */ 4 | 5 | #include "RigidBody.h" 6 | #include "internal/MatVec.h" 7 | #include "openmm/Vec3.h" 8 | #include "openmm/internal/ContextImpl.h" 9 | #include 10 | 11 | using namespace OpenMM; 12 | using namespace std; 13 | 14 | namespace RigidBodyPlugin { 15 | 16 | /** 17 | * This class represents a system of rigid bodies and free atoms 18 | */ 19 | 20 | class FreeAtom { 21 | public: 22 | int index; 23 | double invMass; 24 | OpenMM::Vec3 savedPos; 25 | }; 26 | 27 | class RigidBodySystem { 28 | public: 29 | RigidBodySystem() {} 30 | void initialize(ContextImpl& contextRef, const vector& bodyIndices, int rotationMode); 31 | void update(ContextImpl& contextRef, bool geometry, bool velocities); 32 | void copy(const RigidBodySystem& bodySystem); 33 | void integratePart1(double dt, const vector& F, vector& V, vector& R); 34 | void integratePart2(double dt, const vector& R, const vector& F, vector& V); 35 | void computeKineticEnergies(const vector& V); 36 | int getNumDOF() const {return numDOF; } 37 | int getNumFree() const { return numFree; } 38 | int getNumBodies() const { return numBodies; } 39 | int getNumActualAtoms() const { return numActualAtoms; } 40 | int getNumBodyAtoms() const { return numBodyAtoms; } 41 | int getAtomIndex(int i) const { return atomIndex[i]; } 42 | Vec3 getBodyFixedPosition(int i) const { return bodyFixedPositions[i]; } 43 | RigidBody getRigidBody(int i) const { return body[i]; } 44 | double getTranslationalEnergy() const { return transKE; } 45 | double getRotationalEnergy() const { return rotKE; } 46 | double getKineticEnergy() const { return transKE + rotKE; } 47 | private: 48 | int rotationMode; 49 | std::vector bodyIndex; 50 | std::vector atomIndex; 51 | std::vector body; 52 | std::vector bodyFixedPositions; 53 | std::vector freeAtom; 54 | int numFree; 55 | int numBodies; 56 | int numActualAtoms; 57 | int numBodyAtoms; 58 | int numDOF; 59 | double transKE; 60 | double rotKE; 61 | }; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /platforms/cuda/src/CudaRigidBodyKernelSources.cpp.in: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMM * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2014 Stanford University and the Authors. * 10 | * Authors: Peter Eastman * 11 | * Contributors: * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #include "CudaRigidBodyKernelSources.h" 33 | 34 | using namespace RigidBodyPlugin; 35 | using namespace std; 36 | -------------------------------------------------------------------------------- /platforms/cuda/tests/TestCudaRigidBodyIntegrator.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMM * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2015 Stanford University and the Authors. * 10 | * Authors: Peter Eastman * 11 | * Contributors: * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #include "CudaRigidBodyTests.h" 33 | #include "TestRigidBodyIntegrator.h" 34 | 35 | void runPlatformTests() { 36 | } 37 | -------------------------------------------------------------------------------- /platforms/opencl/src/OpenCLRigidBodyKernelSources.cpp.in: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMM * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2014 Stanford University and the Authors. * 10 | * Authors: Peter Eastman * 11 | * Contributors: * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #include "OpenCLRigidBodyKernelSources.h" 33 | 34 | using namespace RigidBodyPlugin; 35 | using namespace std; 36 | -------------------------------------------------------------------------------- /platforms/opencl/tests/TestOpenCLRigidBodyIntegrator.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMM * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2015 Stanford University and the Authors. * 10 | * Authors: Peter Eastman * 11 | * Contributors: * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #include "OpenCLRigidBodyTests.h" 33 | #include "TestRigidBodyIntegrator.h" 34 | 35 | void runPlatformTests() { 36 | } 37 | -------------------------------------------------------------------------------- /platforms/reference/tests/TestReferenceRigidBodyIntegrator.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMM * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2015 Stanford University and the Authors. * 10 | * Authors: Peter Eastman * 11 | * Contributors: * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #include "ReferenceRigidBodyTests.h" 33 | #include "TestRigidBodyIntegrator.h" 34 | 35 | void runPlatformTests() { 36 | } 37 | -------------------------------------------------------------------------------- /platforms/reference/tests/ReferenceRigidBodyTests.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMM * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2015-2016 Stanford University and the Authors. * 10 | * Authors: Peter Eastman * 11 | * Contributors: * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #ifdef WIN32 33 | #define _USE_MATH_DEFINES // Needed to get M_PI 34 | #endif 35 | 36 | #include "openmm/reference/ReferencePlatform.h" 37 | #include 38 | 39 | extern "C" OPENMM_EXPORT void registerRigidBodyReferenceKernelFactories(); 40 | 41 | std::string platformName = "Reference"; 42 | 43 | void registerCurrentPlatformKernelFactories() { 44 | registerRigidBodyReferenceKernelFactories(); 45 | } 46 | 47 | void initializeTests(OpenMM::Platform& platform, int argc, char* argv[]) { 48 | } 49 | -------------------------------------------------------------------------------- /openmmapi/include/RigidBody.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMM Rigid Body Plugin * 3 | * -------------------------------------------------------------------------- */ 4 | 5 | #include "internal/MatVec.h" 6 | #include "openmm/Vec3.h" 7 | #include 8 | 9 | using namespace OpenMM; 10 | using namespace std; 11 | 12 | namespace RigidBodyPlugin { 13 | 14 | /** 15 | * This class represents a rigid body 16 | */ 17 | 18 | class RigidBody { 19 | public: 20 | void buildGeometry(vector& R, vector& F, vector& M); 21 | void buildDynamics(vector& V, vector& M); 22 | void updateAtomicPositions(vector& R); 23 | void updateAtomicVelocities(vector& V); 24 | void forceAndTorque(const vector& F); 25 | void uniaxialRotationAxis1(double dt); 26 | void uniaxialRotationAxis2(double dt); 27 | void uniaxialRotationAxis3(double dt); 28 | void noSquishRotation(double dt, int n); 29 | void exactRotation(double dt); 30 | 31 | int N; // number of atoms 32 | int dof; // Number of degrees of freedom 33 | double mass; // total body mass and its inverse 34 | Vec3 I; // Principal moments of inertia and their inverses 35 | Vec3 rcm; // Center-of-mass position 36 | Vec3 pcm; // Center-of-mass momentum 37 | Quat q; // Unit orientation quaternion 38 | Quat pi; // Quaternion-conjugated momentum 39 | 40 | Vec3 force; // Resultant force 41 | Quat torque; // Resultant quaternion-fixed torque 42 | 43 | int loc; // location of first atom index 44 | int* atom; // pointer to the index of the first atom 45 | Vec3* d; // pointer to the body-fixed position of the first atom 46 | 47 | double invMass; // total body mass and its inverse 48 | Vec3 invI; // Principal moments of inertia and their inverses 49 | 50 | double twoKt; // Twice the translational kinetic energy 51 | double twoKr; // Twice the rotational kinetic energy 52 | vector delta; // Space-fixed displacements from the center of mass 53 | }; 54 | 55 | template 56 | class bodyType { 57 | public: 58 | int N; // number of atoms 59 | int loc; // pointer to set of atoms 60 | real invm; // inverse mass 61 | real3 invI; // inverse principal moments of inertia 62 | real3 r; // center-of-mass position 63 | real3 v; // center-of-mass velocity 64 | real3 F; // resultant force 65 | real3 rdot; // time-derivative of center-of-mass position 66 | real4 q; // orientation quaternion 67 | real4 pi; // quaternion-conjugated momentum 68 | real4 Ctau; // quaternion-frame resultant torque 69 | real4 qdot; // time-derivative of orientation quaternion 70 | }; 71 | 72 | } 73 | -------------------------------------------------------------------------------- /platforms/cuda/include/CudaRigidBodyKernelFactory.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENMM_CUDARIGIDBODYKERNELFACTORY_H_ 2 | #define OPENMM_CUDARIGIDBODYKERNELFACTORY_H_ 3 | 4 | /* -------------------------------------------------------------------------- * 5 | * OpenMM * 6 | * -------------------------------------------------------------------------- * 7 | * This is part of the OpenMM molecular simulation toolkit originating from * 8 | * Simbios, the NIH National Center for Physics-Based Simulation of * 9 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 10 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 11 | * * 12 | * Portions copyright (c) 2014 Stanford University and the Authors. * 13 | * Authors: Peter Eastman * 14 | * Contributors: * 15 | * * 16 | * Permission is hereby granted, free of charge, to any person obtaining a * 17 | * copy of this software and associated documentation files (the "Software"), * 18 | * to deal in the Software without restriction, including without limitation * 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 20 | * and/or sell copies of the Software, and to permit persons to whom the * 21 | * Software is furnished to do so, subject to the following conditions: * 22 | * * 23 | * The above copyright notice and this permission notice shall be included in * 24 | * all copies or substantial portions of the Software. * 25 | * * 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 29 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 30 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 31 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 32 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 33 | * -------------------------------------------------------------------------- */ 34 | 35 | #include "openmm/KernelFactory.h" 36 | 37 | namespace OpenMM { 38 | 39 | /** 40 | * This KernelFactory creates kernels for the CUDA implementation of the RigidBody plugin. 41 | */ 42 | 43 | class CudaRigidBodyKernelFactory : public KernelFactory { 44 | public: 45 | KernelImpl* createKernelImpl(std::string name, const Platform& platform, ContextImpl& context) const; 46 | }; 47 | 48 | } // namespace OpenMM 49 | 50 | #endif /*OPENMM_CUDARIGIDBODYKERNELFACTORY_H_*/ 51 | -------------------------------------------------------------------------------- /platforms/cuda/src/CudaRigidBodyKernelSources.h.in: -------------------------------------------------------------------------------- 1 | #ifndef OPENMM_CUDARIGIDBODYKERNELSOURCES_H_ 2 | #define OPENMM_CUDARIGIDBODYKERNELSOURCES_H_ 3 | 4 | /* -------------------------------------------------------------------------- * 5 | * OpenMM * 6 | * -------------------------------------------------------------------------- * 7 | * This is part of the OpenMM molecular simulation toolkit originating from * 8 | * Simbios, the NIH National Center for Physics-Based Simulation of * 9 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 10 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 11 | * * 12 | * Portions copyright (c) 2014 Stanford University and the Authors. * 13 | * Authors: Peter Eastman * 14 | * Contributors: * 15 | * * 16 | * Permission is hereby granted, free of charge, to any person obtaining a * 17 | * copy of this software and associated documentation files (the "Software"), * 18 | * to deal in the Software without restriction, including without limitation * 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 20 | * and/or sell copies of the Software, and to permit persons to whom the * 21 | * Software is furnished to do so, subject to the following conditions: * 22 | * * 23 | * The above copyright notice and this permission notice shall be included in * 24 | * all copies or substantial portions of the Software. * 25 | * * 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 29 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 30 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 31 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 32 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 33 | * -------------------------------------------------------------------------- */ 34 | 35 | #include 36 | 37 | namespace RigidBodyPlugin { 38 | 39 | /** 40 | * This class is a central holding place for the source code of CUDA kernels. 41 | * The CMake build script inserts declarations into it based on the .cu files in the 42 | * kernels subfolder. 43 | */ 44 | 45 | class CudaRigidBodyKernelSources { 46 | public: 47 | @CUDA_FILE_DECLARATIONS@ 48 | }; 49 | 50 | } // namespace RigidBodyPlugin 51 | 52 | #endif /*OPENMM_CUDARIGIDBODYKERNELSOURCES_H_*/ 53 | -------------------------------------------------------------------------------- /platforms/cuda/tests/CudaRigidBodyTests.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMM * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2015-2016 Stanford University and the Authors. * 10 | * Authors: Peter Eastman * 11 | * Contributors: * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #ifdef WIN32 33 | #define _USE_MATH_DEFINES // Needed to get M_PI 34 | #endif 35 | 36 | #include "openmm/cuda/CudaPlatform.h" 37 | #include 38 | 39 | extern "C" OPENMM_EXPORT void registerRigidBodyCudaKernelFactories(); 40 | 41 | std::string platformName = "CUDA"; 42 | 43 | void registerCurrentPlatformKernelFactories() { 44 | registerRigidBodyCudaKernelFactories(); 45 | } 46 | 47 | void initializeTests(OpenMM::Platform& platform, int argc, char* argv[]) { 48 | if (argc > 1) 49 | platform.setPropertyDefaultValue("CudaPrecision", std::string(argv[1])); 50 | } 51 | -------------------------------------------------------------------------------- /platforms/opencl/src/OpenCLRigidBodyKernelSources.h.in: -------------------------------------------------------------------------------- 1 | #ifndef OPENMM_OPENCLRIGIDBODYKERNELSOURCES_H_ 2 | #define OPENMM_OPENCLRIGIDBODYKERNELSOURCES_H_ 3 | 4 | /* -------------------------------------------------------------------------- * 5 | * OpenMM * 6 | * -------------------------------------------------------------------------- * 7 | * This is part of the OpenMM molecular simulation toolkit originating from * 8 | * Simbios, the NIH National Center for Physics-Based Simulation of * 9 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 10 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 11 | * * 12 | * Portions copyright (c) 2014 Stanford University and the Authors. * 13 | * Authors: Peter Eastman * 14 | * Contributors: * 15 | * * 16 | * Permission is hereby granted, free of charge, to any person obtaining a * 17 | * copy of this software and associated documentation files (the "Software"), * 18 | * to deal in the Software without restriction, including without limitation * 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 20 | * and/or sell copies of the Software, and to permit persons to whom the * 21 | * Software is furnished to do so, subject to the following conditions: * 22 | * * 23 | * The above copyright notice and this permission notice shall be included in * 24 | * all copies or substantial portions of the Software. * 25 | * * 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 29 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 30 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 31 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 32 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 33 | * -------------------------------------------------------------------------- */ 34 | 35 | #include 36 | 37 | namespace RigidBodyPlugin { 38 | 39 | /** 40 | * This class is a central holding place for the source code of OpenCL kernels. 41 | * The CMake build script inserts declarations into it based on the .cl files in the 42 | * kernels subfolder. 43 | */ 44 | 45 | class OpenCLRigidBodyKernelSources { 46 | public: 47 | @CL_FILE_DECLARATIONS@ 48 | }; 49 | 50 | } // namespace RigidBodyPlugin 51 | 52 | #endif /*OPENMM_OPENCLRIGIDBODYKERNELSOURCES_H_*/ 53 | -------------------------------------------------------------------------------- /platforms/opencl/tests/OpenCLRigidBodyTests.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMM * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2015-2016 Stanford University and the Authors. * 10 | * Authors: Peter Eastman * 11 | * Contributors: * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #ifdef WIN32 33 | #define _USE_MATH_DEFINES // Needed to get M_PI 34 | #endif 35 | 36 | #include "openmm/opencl/OpenCLPlatform.h" 37 | #include 38 | 39 | extern "C" OPENMM_EXPORT void registerRigidBodyOpenCLKernelFactories(); 40 | 41 | std::string platformName = "OpenCL"; 42 | 43 | void registerCurrentPlatformKernelFactories() { 44 | registerRigidBodyOpenCLKernelFactories(); 45 | } 46 | 47 | void initializeTests(OpenMM::Platform& platform, int argc, char* argv[]) { 48 | if (argc > 1) 49 | platform.setPropertyDefaultValue("OpenCLPrecision", std::string(argv[1])); 50 | } 51 | -------------------------------------------------------------------------------- /platforms/reference/include/ReferenceRigidBodyKernelFactory.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENMM_REFERENCERIGIDBODYKERNELFACTORY_H_ 2 | #define OPENMM_REFERENCERIGIDBODYKERNELFACTORY_H_ 3 | 4 | /* -------------------------------------------------------------------------- * 5 | * OpenMM * 6 | * -------------------------------------------------------------------------- * 7 | * This is part of the OpenMM molecular simulation toolkit originating from * 8 | * Simbios, the NIH National Center for Physics-Based Simulation of * 9 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 10 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 11 | * * 12 | * Portions copyright (c) 2014 Stanford University and the Authors. * 13 | * Authors: Peter Eastman * 14 | * Contributors: * 15 | * * 16 | * Permission is hereby granted, free of charge, to any person obtaining a * 17 | * copy of this software and associated documentation files (the "Software"), * 18 | * to deal in the Software without restriction, including without limitation * 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 20 | * and/or sell copies of the Software, and to permit persons to whom the * 21 | * Software is furnished to do so, subject to the following conditions: * 22 | * * 23 | * The above copyright notice and this permission notice shall be included in * 24 | * all copies or substantial portions of the Software. * 25 | * * 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 29 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 30 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 31 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 32 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 33 | * -------------------------------------------------------------------------- */ 34 | 35 | #include "openmm/KernelFactory.h" 36 | 37 | namespace OpenMM { 38 | 39 | /** 40 | * This KernelFactory creates kernels for the reference implementation of the RigidBody plugin. 41 | */ 42 | 43 | class ReferenceRigidBodyKernelFactory : public KernelFactory { 44 | public: 45 | KernelImpl* createKernelImpl(std::string name, const Platform& platform, ContextImpl& context) const; 46 | }; 47 | 48 | } // namespace OpenMM 49 | 50 | #endif /*OPENMM_REFERENCERIGIDBODYKERNELFACTORY_H_*/ 51 | -------------------------------------------------------------------------------- /cmake/FindOpenCL.cmake: -------------------------------------------------------------------------------- 1 | 2 | ### OPENCL_INCLUDE_DIR ### 3 | # Try OPENCL_DIR variable before looking elsewhere 4 | find_path(OPENCL_INCLUDE_DIR 5 | NAMES OpenCL/opencl.h CL/opencl.h 6 | PATHS $ENV{OPENCL_DIR} 7 | PATH_SUFFIXES "include" 8 | NO_DEFAULT_PATH 9 | ) 10 | # Next look in environment variables set by OpenCL SDK installations 11 | find_path(OPENCL_INCLUDE_DIR 12 | NAMES OpenCL/opencl.h CL/opencl.h 13 | PATHS 14 | $ENV{CUDA_PATH} 15 | $ENV{AMDAPPSDKROOT} 16 | PATH_SUFFIXES "include" 17 | NO_DEFAULT_PATH 18 | ) 19 | # On Macs, look inside the platform SDK 20 | if(DEFINED CMAKE_OSX_SYSROOT) 21 | find_path(OPENCL_INCLUDE_DIR 22 | NAMES opencl.h opencl.h 23 | PATHS 24 | "${CMAKE_OSX_SYSROOT}/System/Library/Frameworks/OpenCL.framework/Headers" 25 | NO_DEFAULT_PATH 26 | ) 27 | endif(DEFINED CMAKE_OSX_SYSROOT) 28 | # As a last resort, look in default system areas followed by other possible locations 29 | find_path(OPENCL_INCLUDE_DIR 30 | NAMES OpenCL/opencl.h CL/opencl.h 31 | PATHS 32 | "C:/CUDA" 33 | "/usr/local/cuda" 34 | "/usr/local/streamsdk" 35 | "/usr" 36 | PATH_SUFFIXES "include" 37 | ) 38 | 39 | ### OPENCL_LIBRARY ### 40 | if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") 41 | if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") 42 | set(path_suffixes "lib/x86_64") 43 | else("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") 44 | set(path_suffixes "lib/x86") 45 | endif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") 46 | elseif(MSVC) 47 | if(CMAKE_CL_64) 48 | set(path_suffixes "lib/x64" "lib/x86_64") 49 | else(CMAKE_CL_64) 50 | set(path_suffixes "lib/Win32" "lib/x86") 51 | endif(CMAKE_CL_64) 52 | else(MSVC) 53 | set(path_suffixes "lib") 54 | endif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") 55 | # Try OPENCL_DIR variable before looking elsewhere 56 | find_library(OPENCL_LIBRARY 57 | NAMES OpenCL 58 | PATHS 59 | $ENV{OPENCL_DIR} 60 | ${OPENCL_LIB_SEARCH_PATH} 61 | PATH_SUFFIXES ${path_suffixes} 62 | NO_DEFAULT_PATH 63 | ) 64 | # Next look in environment variables set by OpenCL SDK installations 65 | find_library(OPENCL_LIBRARY 66 | NAMES OpenCL 67 | PATHS 68 | $ENV{CUDA_PATH} 69 | $ENV{AMDAPPSDKROOT} 70 | PATH_SUFFIXES ${path_suffixes} 71 | NO_DEFAULT_PATH 72 | ) 73 | # As a last resort, look in default system areas followed by other possible locations 74 | find_library(OPENCL_LIBRARY 75 | NAMES OpenCL 76 | PATHS 77 | "C:/CUDA" 78 | "/usr/local/cuda" 79 | "/usr/local/streamsdk" 80 | "/usr" 81 | PATH_SUFFIXES ${path_suffixes} "lib" 82 | ) 83 | 84 | include(FindPackageHandleStandardArgs) 85 | find_package_handle_standard_args(OPENCL DEFAULT_MSG OPENCL_LIBRARY OPENCL_INCLUDE_DIR) 86 | 87 | if(OPENCL_FOUND) 88 | set(OPENCL_LIBRARIES ${OPENCL_LIBRARY}) 89 | mark_as_advanced(CLEAR OPENCL_INCLUDE_DIR) 90 | mark_as_advanced(CLEAR OPENCL_LIBRARY) 91 | else(OPENCL_FOUND) 92 | set(OPENCL_LIBRARIES) 93 | mark_as_advanced(OPENCL_INCLUDE_DIR) 94 | mark_as_advanced(OPENCL_LIBRARY) 95 | endif(OPENCL_FOUND) 96 | -------------------------------------------------------------------------------- /platforms/opencl/include/OpenCLRigidBodyKernelFactory.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENMM_OPENCLRIGIDBODYKERNELFACTORY_H_ 2 | #define OPENMM_OPENCLRIGIDBODYKERNELFACTORY_H_ 3 | 4 | /* -------------------------------------------------------------------------- * 5 | * OpenMM * 6 | * -------------------------------------------------------------------------- * 7 | * This is part of the OpenMM molecular simulation toolkit originating from * 8 | * Simbios, the NIH National Center for Physics-Based Simulation of * 9 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 10 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 11 | * * 12 | * Portions copyright (c) 2014 Stanford University and the Authors. * 13 | * Authors: Peter Eastman * 14 | * Contributors: * 15 | * * 16 | * Permission is hereby granted, free of charge, to any person obtaining a * 17 | * copy of this software and associated documentation files (the "Software"), * 18 | * to deal in the Software without restriction, including without limitation * 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 20 | * and/or sell copies of the Software, and to permit persons to whom the * 21 | * Software is furnished to do so, subject to the following conditions: * 22 | * * 23 | * The above copyright notice and this permission notice shall be included in * 24 | * all copies or substantial portions of the Software. * 25 | * * 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 29 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 30 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 31 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 32 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 33 | * -------------------------------------------------------------------------- */ 34 | 35 | #include "openmm/KernelFactory.h" 36 | 37 | namespace RigidBodyPlugin { 38 | 39 | /** 40 | * This KernelFactory creates kernels for the OpenCL implementation of the RigidBody plugin. 41 | */ 42 | 43 | class OpenCLRigidBodyKernelFactory : public OpenMM::KernelFactory { 44 | public: 45 | OpenMM::KernelImpl* createKernelImpl(std::string name, const OpenMM::Platform& platform, OpenMM::ContextImpl& context) const; 46 | }; 47 | 48 | } // namespace RigidBodyPlugin 49 | 50 | #endif /*OPENMM_OPENCLRIGIDBODYKERNELFACTORY_H_*/ 51 | -------------------------------------------------------------------------------- /serialization/src/RigidBodySerializationProxyRegistration.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMMRigidBody * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2014 Stanford University and the Authors. * 10 | * Authors: Peter Eastman * 11 | * Contributors: * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #ifdef WIN32 33 | #include 34 | #include 35 | #else 36 | #include 37 | #include 38 | #include 39 | #endif 40 | 41 | #include "RigidBodyIntegrator.h" 42 | #include "RigidBodyIntegratorProxy.h" 43 | 44 | #include "openmm/serialization/SerializationProxy.h" 45 | 46 | #if defined(WIN32) 47 | #include 48 | extern "C" OPENMM_EXPORT_RIGIDBODY void registerRigidBodySerializationProxies(); 49 | BOOL WINAPI DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { 50 | if (ul_reason_for_call == DLL_PROCESS_ATTACH) 51 | registerRigidBodySerializationProxies(); 52 | return TRUE; 53 | } 54 | #else 55 | extern "C" void __attribute__((constructor)) registerRigidBodySerializationProxies(); 56 | #endif 57 | 58 | using namespace RigidBodyPlugin; 59 | using namespace OpenMM; 60 | 61 | extern "C" OPENMM_EXPORT_RIGIDBODY void registerRigidBodySerializationProxies() { 62 | SerializationProxy::registerProxy(typeid(RigidBodyIntegrator), new RigidBodyIntegratorProxy()); 63 | } 64 | -------------------------------------------------------------------------------- /platforms/opencl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------- 2 | # OpenMM RigidBody Plugin OpenCL Platform 3 | #---------------------------------------------------- 4 | 5 | # Collect up information about the version of the OpenMM library we're building 6 | # and make it available to the code so it can be built into the binaries. 7 | 8 | SET(OPENMMRIGIDBODYOPENCL_LIBRARY_NAME RigidBodyPluginOpenCL) 9 | 10 | SET(SHARED_TARGET ${OPENMMRIGIDBODYOPENCL_LIBRARY_NAME}) 11 | 12 | 13 | # These are all the places to search for header files which are 14 | # to be part of the API. 15 | SET(API_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/include/internal") 16 | 17 | # Locate header files. 18 | SET(API_INCLUDE_FILES) 19 | FOREACH(dir ${API_INCLUDE_DIRS}) 20 | FILE(GLOB fullpaths ${dir}/*.h) 21 | SET(API_INCLUDE_FILES ${API_INCLUDE_FILES} ${fullpaths}) 22 | ENDFOREACH(dir) 23 | 24 | # collect up source files 25 | SET(SOURCE_FILES) # empty 26 | SET(SOURCE_INCLUDE_FILES) 27 | 28 | FILE(GLOB_RECURSE src_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.c) 29 | FILE(GLOB incl_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h) 30 | SET(SOURCE_FILES ${SOURCE_FILES} ${src_files}) #append 31 | SET(SOURCE_INCLUDE_FILES ${SOURCE_INCLUDE_FILES} ${incl_files}) 32 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include) 33 | 34 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src) 35 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/platforms/opencl/include) 36 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/platforms/opencl/src) 37 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR}/platforms/opencl/src) 38 | 39 | # Set variables needed for encoding kernel sources into a C++ class 40 | 41 | SET(CL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) 42 | SET(CL_SOURCE_CLASS OpenCLRigidBodyKernelSources) 43 | SET(CL_KERNELS_CPP ${CMAKE_CURRENT_BINARY_DIR}/src/${CL_SOURCE_CLASS}.cpp) 44 | SET(CL_KERNELS_H ${CMAKE_CURRENT_BINARY_DIR}/src/${CL_SOURCE_CLASS}.h) 45 | SET(SOURCE_FILES ${SOURCE_FILES} ${CL_KERNELS_CPP} ${CL_KERNELS_H}) 46 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/src) 47 | 48 | # Create the library 49 | 50 | INCLUDE_DIRECTORIES(${OPENCL_INCLUDE_DIR}) 51 | 52 | FILE(GLOB OPENCL_KERNELS ${CL_SOURCE_DIR}/kernels/*.cl) 53 | ADD_CUSTOM_COMMAND(OUTPUT ${CL_KERNELS_CPP} ${CL_KERNELS_H} 54 | COMMAND ${CMAKE_COMMAND} 55 | ARGS -D CL_SOURCE_DIR=${CL_SOURCE_DIR} -D CL_KERNELS_CPP=${CL_KERNELS_CPP} -D CL_KERNELS_H=${CL_KERNELS_H} -D CL_SOURCE_CLASS=${CL_SOURCE_CLASS} -P ${CMAKE_SOURCE_DIR}/platforms/opencl/EncodeCLFiles.cmake 56 | DEPENDS ${OPENCL_KERNELS} 57 | ) 58 | SET_SOURCE_FILES_PROPERTIES(${CL_KERNELS_CPP} ${CL_KERNELS_H} PROPERTIES GENERATED TRUE) 59 | ADD_LIBRARY(${SHARED_TARGET} SHARED ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_INCLUDE_FILES}) 60 | 61 | TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${OPENCL_LIBRARIES}) 62 | TARGET_LINK_LIBRARIES(${SHARED_TARGET} OpenMM) 63 | TARGET_LINK_LIBRARIES(${SHARED_TARGET} OpenMMOpenCL) 64 | TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${SHARED_RIGIDBODY_TARGET}) 65 | SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES 66 | COMPILE_FLAGS "-DOPENMM_BUILDING_SHARED_LIBRARY ${EXTRA_COMPILE_FLAGS}" 67 | LINK_FLAGS "${EXTRA_COMPILE_FLAGS}") 68 | 69 | INSTALL(TARGETS ${SHARED_TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/plugins) 70 | # Ensure that links to the main OpenCL library will be resolved. 71 | IF (APPLE) 72 | SET(OPENCL_LIBRARY libOpenMMOpenCL.dylib) 73 | INSTALL(CODE "EXECUTE_PROCESS(COMMAND install_name_tool -change ${OPENCL_LIBRARY} @loader_path/${OPENCL_LIBRARY} ${CMAKE_INSTALL_PREFIX}/lib/plugins/lib${SHARED_TARGET}.dylib)") 74 | ENDIF (APPLE) 75 | 76 | SUBDIRS (tests) 77 | -------------------------------------------------------------------------------- /serialization/tests/TestSerializeRigidBodyIntegrator.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMM * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2010-2015 Stanford University and the Authors. * 10 | * Authors: Peter Eastman, Yutong Zhao * 11 | * Contributors: * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #include "openmm/internal/AssertionUtilities.h" 33 | #include "RigidBodyIntegrator.h" 34 | #include "openmm/serialization/XmlSerializer.h" 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | using namespace RigidBodyPlugin; 43 | using namespace OpenMM; 44 | using namespace std; 45 | 46 | extern "C" void registerRigidBodySerializationProxies(); 47 | 48 | void testSerializeRigidBodyIntegrator() { 49 | vector bodyIndices; 50 | int indices[] = {5, 4, 3, 2, 1}; 51 | bodyIndices.assign(indices, indices+5); 52 | RigidBodyIntegrator *intg = new RigidBodyIntegrator(0.00342, bodyIndices); 53 | stringstream ss; 54 | XmlSerializer::serialize(intg, "RigidBodyIntegrator", ss); 55 | RigidBodyIntegrator *intg2 = dynamic_cast(XmlSerializer::deserialize(ss)); 56 | ASSERT_EQUAL(intg->getConstraintTolerance(), intg2->getConstraintTolerance()); 57 | ASSERT_EQUAL(intg->getStepSize(), intg2->getStepSize()); 58 | int i = 0; 59 | for (auto index : intg2->getBodyIndices()) 60 | ASSERT_EQUAL(index, indices[i++]); 61 | delete intg; 62 | delete intg2; 63 | } 64 | 65 | int main() { 66 | try { 67 | testSerializeRigidBodyIntegrator(); 68 | } 69 | catch(const exception& e) { 70 | cout << "exception: " << e.what() << endl; 71 | return 1; 72 | } 73 | cout << "Done" << endl; 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /platforms/cuda/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------- 2 | # OpenMM RigidBody Plugin CUDA Platform 3 | #---------------------------------------------------- 4 | 5 | # Collect up information about the version of the OpenMM library we're building 6 | # and make it available to the code so it can be built into the binaries. 7 | 8 | SET(RIGIDBODY_CUDA_LIBRARY_NAME RigidBodyPluginCUDA) 9 | 10 | SET(SHARED_TARGET ${RIGIDBODY_CUDA_LIBRARY_NAME}) 11 | 12 | 13 | # These are all the places to search for header files which are 14 | # to be part of the API. 15 | SET(API_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/include/internal") 16 | 17 | # Locate header files. 18 | SET(API_INCLUDE_FILES) 19 | FOREACH(dir ${API_INCLUDE_DIRS}) 20 | FILE(GLOB fullpaths ${dir}/*.h) 21 | SET(API_INCLUDE_FILES ${API_INCLUDE_FILES} ${fullpaths}) 22 | ENDFOREACH(dir) 23 | 24 | # collect up source files 25 | SET(SOURCE_FILES) # empty 26 | SET(SOURCE_INCLUDE_FILES) 27 | 28 | FILE(GLOB_RECURSE src_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.c) 29 | FILE(GLOB incl_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h) 30 | SET(SOURCE_FILES ${SOURCE_FILES} ${src_files}) #append 31 | SET(SOURCE_INCLUDE_FILES ${SOURCE_INCLUDE_FILES} ${incl_files}) 32 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include) 33 | 34 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src) 35 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/platforms/cuda/include) 36 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/platforms/cuda/src) 37 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR}/platforms/cuda/src) 38 | 39 | # Set variables needed for encoding kernel sources into a C++ class 40 | 41 | SET(CUDA_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) 42 | SET(CUDA_SOURCE_CLASS CudaRigidBodyKernelSources) 43 | SET(CUDA_KERNELS_CPP ${CMAKE_CURRENT_BINARY_DIR}/src/${CUDA_SOURCE_CLASS}.cpp) 44 | SET(CUDA_KERNELS_H ${CMAKE_CURRENT_BINARY_DIR}/src/${CUDA_SOURCE_CLASS}.h) 45 | SET(SOURCE_FILES ${SOURCE_FILES} ${CUDA_KERNELS_CPP} ${CUDA_KERNELS_H}) 46 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/src) 47 | 48 | # Create the library 49 | 50 | INCLUDE_DIRECTORIES(${CUDA_TOOLKIT_INCLUDE}) 51 | 52 | FILE(GLOB CUDA_KERNELS ${CUDA_SOURCE_DIR}/kernels/*.cu) 53 | ADD_CUSTOM_COMMAND(OUTPUT ${CUDA_KERNELS_CPP} ${CUDA_KERNELS_H} 54 | COMMAND ${CMAKE_COMMAND} 55 | ARGS -D CUDA_SOURCE_DIR=${CUDA_SOURCE_DIR} -D CUDA_KERNELS_CPP=${CUDA_KERNELS_CPP} -D CUDA_KERNELS_H=${CUDA_KERNELS_H} -D CUDA_SOURCE_CLASS=${CUDA_SOURCE_CLASS} -P ${CMAKE_SOURCE_DIR}/platforms/cuda/EncodeCUDAFiles.cmake 56 | DEPENDS ${CUDA_KERNELS} 57 | ) 58 | SET_SOURCE_FILES_PROPERTIES(${CUDA_KERNELS_CPP} ${CUDA_KERNELS_H} PROPERTIES GENERATED TRUE) 59 | ADD_LIBRARY(${SHARED_TARGET} SHARED ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_INCLUDE_FILES}) 60 | 61 | TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${CUDA_LIBRARIES}) 62 | TARGET_LINK_LIBRARIES(${SHARED_TARGET} OpenMM) 63 | TARGET_LINK_LIBRARIES(${SHARED_TARGET} OpenMMCUDA) 64 | TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${RIGIDBODY_LIBRARY_NAME}) 65 | SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES 66 | COMPILE_FLAGS "-DOPENMM_BUILDING_SHARED_LIBRARY ${EXTRA_COMPILE_FLAGS}" 67 | LINK_FLAGS "${EXTRA_COMPILE_FLAGS}") 68 | IF (APPLE) 69 | SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES LINK_FLAGS "-F/Library/Frameworks -framework CUDA ${EXTRA_COMPILE_FLAGS}") 70 | ENDIF (APPLE) 71 | 72 | INSTALL(TARGETS ${SHARED_TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/plugins) 73 | # Ensure that links to the main CUDA library will be resolved. 74 | IF (APPLE) 75 | SET(CUDA_LIBRARY libOpenMMCUDA.dylib) 76 | INSTALL(CODE "EXECUTE_PROCESS(COMMAND install_name_tool -change ${CUDA_LIBRARY} @loader_path/${CUDA_LIBRARY} ${CMAKE_INSTALL_PREFIX}/lib/plugins/lib${SHARED_TARGET}.dylib)") 77 | ENDIF (APPLE) 78 | 79 | set(BUILD_CUDA_TESTS TRUE CACHE BOOL "Whether to build CUDA test cases") 80 | if(BUILD_CUDA_TESTS) 81 | SUBDIRS (tests) 82 | endif(BUILD_CUDA_TESTS) 83 | -------------------------------------------------------------------------------- /platforms/reference/src/ReferenceRigidBodyKernelFactory.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMMRigidBody * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2014 Stanford University and the Authors. * 10 | * Authors: Peter Eastman * 11 | * Contributors: * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #include "ReferenceRigidBodyKernelFactory.h" 33 | #include "ReferenceRigidBodyKernels.h" 34 | #include "openmm/reference/ReferencePlatform.h" 35 | #include "openmm/internal/ContextImpl.h" 36 | #include "openmm/OpenMMException.h" 37 | 38 | using namespace RigidBodyPlugin; 39 | using namespace OpenMM; 40 | 41 | extern "C" OPENMM_EXPORT void registerPlatforms() { 42 | } 43 | 44 | extern "C" OPENMM_EXPORT void registerKernelFactories() { 45 | for (int i = 0; i < Platform::getNumPlatforms(); i++) { 46 | Platform& platform = Platform::getPlatform(i); 47 | if (dynamic_cast(&platform) != NULL) { 48 | ReferenceRigidBodyKernelFactory* factory = new ReferenceRigidBodyKernelFactory(); 49 | platform.registerKernelFactory(IntegrateRigidBodyStepKernel::Name(), factory); 50 | } 51 | } 52 | } 53 | 54 | extern "C" OPENMM_EXPORT void registerRigidBodyReferenceKernelFactories() { 55 | registerKernelFactories(); 56 | } 57 | 58 | KernelImpl* ReferenceRigidBodyKernelFactory::createKernelImpl(std::string name, const Platform& platform, ContextImpl& context) const { 59 | ReferencePlatform::PlatformData& data = *static_cast(context.getPlatformData()); 60 | if (name == IntegrateRigidBodyStepKernel::Name()) 61 | return new ReferenceIntegrateRigidBodyStepKernel(name, platform, data); 62 | throw OpenMMException((std::string("Tried to create kernel with illegal kernel name '")+name+"'").c_str()); 63 | } 64 | -------------------------------------------------------------------------------- /platforms/cuda/src/CudaRigidBodyKernelFactory.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMMRigidBody * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2014 Stanford University and the Authors. * 10 | * Authors: Peter Eastman * 11 | * Contributors: * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #include 33 | 34 | #include "CudaRigidBodyKernelFactory.h" 35 | #include "CudaRigidBodyKernels.h" 36 | #include "openmm/internal/windowsExport.h" 37 | #include "openmm/internal/ContextImpl.h" 38 | #include "openmm/OpenMMException.h" 39 | 40 | using namespace RigidBodyPlugin; 41 | using namespace OpenMM; 42 | 43 | extern "C" OPENMM_EXPORT void registerPlatforms() { 44 | } 45 | 46 | extern "C" OPENMM_EXPORT void registerKernelFactories() { 47 | try { 48 | Platform& platform = Platform::getPlatformByName("CUDA"); 49 | CudaRigidBodyKernelFactory* factory = new CudaRigidBodyKernelFactory(); 50 | platform.registerKernelFactory(IntegrateRigidBodyStepKernel::Name(), factory); 51 | } 52 | catch (std::exception ex) { 53 | // Ignore 54 | } 55 | } 56 | 57 | extern "C" OPENMM_EXPORT void registerRigidBodyCudaKernelFactories() { 58 | try { 59 | Platform::getPlatformByName("CUDA"); 60 | } 61 | catch (...) { 62 | Platform::registerPlatform(new CudaPlatform()); 63 | } 64 | registerKernelFactories(); 65 | } 66 | 67 | KernelImpl* CudaRigidBodyKernelFactory::createKernelImpl(std::string name, const Platform& platform, ContextImpl& context) const { 68 | CudaContext& cu = *static_cast(context.getPlatformData())->contexts[0]; 69 | if (name == IntegrateRigidBodyStepKernel::Name()) 70 | return new CudaIntegrateRigidBodyStepKernel(name, platform, cu); 71 | throw OpenMMException((std::string("Tried to create kernel with illegal kernel name '")+name+"'").c_str()); 72 | } 73 | -------------------------------------------------------------------------------- /platforms/opencl/src/OpenCLRigidBodyKernelFactory.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMMRigidBody * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2014 Stanford University and the Authors. * 10 | * Authors: Peter Eastman * 11 | * Contributors: * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #include 33 | 34 | #include "OpenCLRigidBodyKernelFactory.h" 35 | #include "OpenCLRigidBodyKernels.h" 36 | #include "openmm/internal/windowsExport.h" 37 | #include "openmm/internal/ContextImpl.h" 38 | #include "openmm/OpenMMException.h" 39 | 40 | using namespace RigidBodyPlugin; 41 | using namespace OpenMM; 42 | 43 | extern "C" OPENMM_EXPORT void registerPlatforms() { 44 | } 45 | 46 | extern "C" OPENMM_EXPORT void registerKernelFactories() { 47 | try { 48 | Platform& platform = Platform::getPlatformByName("OpenCL"); 49 | OpenCLRigidBodyKernelFactory* factory = new OpenCLRigidBodyKernelFactory(); 50 | platform.registerKernelFactory(IntegrateRigidBodyStepKernel::Name(), factory); 51 | } 52 | catch (std::exception ex) { 53 | // Ignore 54 | } 55 | } 56 | 57 | extern "C" OPENMM_EXPORT void registerRigidBodyOpenCLKernelFactories() { 58 | try { 59 | Platform::getPlatformByName("OpenCL"); 60 | } 61 | catch (...) { 62 | Platform::registerPlatform(new OpenCLPlatform()); 63 | } 64 | registerKernelFactories(); 65 | } 66 | 67 | KernelImpl* OpenCLRigidBodyKernelFactory::createKernelImpl(std::string name, const Platform& platform, ContextImpl& context) const { 68 | OpenCLContext& cl = *static_cast(context.getPlatformData())->contexts[0]; 69 | if (name == IntegrateRigidBodyStepKernel::Name()) 70 | return new OpenCLIntegrateRigidBodyStepKernel(name, platform, cl); 71 | throw OpenMMException((std::string("Tried to create kernel with illegal kernel name '")+name+"'").c_str()); 72 | } 73 | -------------------------------------------------------------------------------- /openmmapi/src/RigidBodyIntegrator.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMM Rigid Body Plugin * 3 | * -------------------------------------------------------------------------- */ 4 | 5 | #include "RigidBodyIntegrator.h" 6 | #include "openmm/Context.h" 7 | #include "openmm/OpenMMException.h" 8 | #include "openmm/internal/ContextImpl.h" 9 | #include "openmm/kernels.h" 10 | #include "RigidBodyKernels.h" 11 | #include 12 | 13 | using namespace RigidBodyPlugin; 14 | using namespace OpenMM; 15 | using std::string; 16 | using std::vector; 17 | 18 | RigidBodyIntegrator::RigidBodyIntegrator(double stepSize, const vector& bodyIndices) { 19 | setStepSize(stepSize); 20 | setConstraintTolerance(1e-5); 21 | this->bodyIndices = bodyIndices; 22 | rotationMode = 0; 23 | computeRefinedEnergies = false; 24 | } 25 | 26 | void RigidBodyIntegrator::setRotationMode(int mode) { 27 | if (mode < 0) 28 | throw OpenMMException("Rotation mode cannot be negative"); 29 | if (owner != NULL) 30 | throw OpenMMException("Cannot set rotation mode: integrator already bound to a context"); 31 | rotationMode = mode; 32 | } 33 | 34 | void RigidBodyIntegrator::setComputeRefinedEnergies(bool compute) { 35 | if (owner != NULL) 36 | throw OpenMMException("Cannot set refined energy computation: integrator already bound to a context"); 37 | computeRefinedEnergies = compute; 38 | } 39 | 40 | void RigidBodyIntegrator::initialize(ContextImpl& contextRef) { 41 | if (owner != NULL && &contextRef.getOwner() != owner) 42 | throw OpenMMException("This Integrator is already bound to a context"); 43 | context = &contextRef; 44 | owner = &contextRef.getOwner(); 45 | const System *system = &contextRef.getSystem(); 46 | if (system->getNumParticles() != bodyIndices.size()) 47 | throw OpenMMException("Number of body indices differs from that of atoms in Context"); 48 | bodySystem.initialize(*context, bodyIndices, rotationMode); 49 | kernel = context->getPlatform().createKernel(IntegrateRigidBodyStepKernel::Name(), contextRef); 50 | kernel.getAs().initialize(*context, *this); 51 | } 52 | 53 | void RigidBodyIntegrator::cleanup() { 54 | kernel = Kernel(); 55 | } 56 | 57 | vector RigidBodyIntegrator::getKernelNames() { 58 | std::vector names; 59 | names.push_back(IntegrateRigidBodyStepKernel::Name()); 60 | return names; 61 | } 62 | 63 | void RigidBodyIntegrator::stateChanged(State::DataType changed) { 64 | if (changed == State::Positions || changed == State::Velocities) { 65 | if (changed == State::Positions) { 66 | context->updateContextState(); 67 | context->calcForcesAndEnergy(true, false); 68 | bodySystem.update(*context, true, true); 69 | } 70 | else 71 | bodySystem.update(*context, false, true); 72 | kernel.getAs().uploadBodySystem(bodySystem); 73 | } 74 | } 75 | 76 | double RigidBodyIntegrator::computeKineticEnergy() { 77 | return kernel.getAs().computeKineticEnergy(*context, *this); 78 | } 79 | 80 | std::vector RigidBodyIntegrator::getKineticEnergies() { 81 | return kernel.getAs().getKineticEnergies(*this); 82 | } 83 | 84 | std::vector RigidBodyIntegrator::getRefinedKineticEnergies() { 85 | return kernel.getAs().getRefinedKineticEnergies(*this); 86 | } 87 | 88 | double RigidBodyIntegrator::getPotentialEnergyRefinement() { 89 | return kernel.getAs().getPotentialEnergyRefinement(*this); 90 | } 91 | 92 | std::vector RigidBodyIntegrator::getBodyIndices() const { 93 | return bodyIndices; 94 | } 95 | 96 | void RigidBodyIntegrator::step(int steps) { 97 | if (context == NULL) 98 | throw OpenMMException("This Integrator is not bound to a context!"); 99 | for (int i = 0; i < steps; ++i) 100 | kernel.getAs().execute(*context, *this); 101 | } 102 | -------------------------------------------------------------------------------- /serialization/src/RigidBodyIntegratorProxy.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMM * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2010 Stanford University and the Authors. * 10 | * Authors: Peter Eastman, Yutong Zhao * 11 | * Contributors: * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #include "RigidBodyIntegratorProxy.h" 33 | #include "RigidBodyIntegrator.h" 34 | #include 35 | 36 | using namespace std; 37 | using namespace RigidBodyPlugin; 38 | using namespace OpenMM; 39 | 40 | RigidBodyIntegratorProxy::RigidBodyIntegratorProxy() : SerializationProxy("RigidBodyIntegrator") { 41 | } 42 | 43 | void RigidBodyIntegratorProxy::serialize(const void* object, SerializationNode& node) const { 44 | node.setIntProperty("version", 1); 45 | const RigidBodyIntegrator& integrator = *reinterpret_cast(object); 46 | node.setDoubleProperty("stepSize", integrator.getStepSize()); 47 | node.setDoubleProperty("constraintTolerance", integrator.getConstraintTolerance()); 48 | vector bodyIndices; 49 | bodyIndices = integrator.getBodyIndices(); 50 | SerializationNode& bodyIndicesNode = node.createChildNode("bodyIndices"); 51 | for (auto index : bodyIndices) 52 | bodyIndicesNode.createChildNode("bodyIndex").setIntProperty("index", index); 53 | } 54 | 55 | void* RigidBodyIntegratorProxy::deserialize(const SerializationNode& node) const { 56 | if (node.getIntProperty("version") != 1) 57 | throw OpenMMException("Unsupported version number"); 58 | double stepSize = node.getDoubleProperty("stepSize"); 59 | double constraintTolerance = node.getDoubleProperty("constraintTolerance"); 60 | const SerializationNode& bodyIndicesNode = node.getChildNode("bodyIndices"); 61 | vector bodyIndices; 62 | for (auto& child : bodyIndicesNode.getChildren()) 63 | bodyIndices.push_back(child.getIntProperty("index")); 64 | RigidBodyIntegrator *integrator = new RigidBodyIntegrator(stepSize, bodyIndices); 65 | integrator->setConstraintTolerance(constraintTolerance); 66 | return integrator; 67 | } 68 | -------------------------------------------------------------------------------- /python/statedatareporter.py: -------------------------------------------------------------------------------- 1 | %pythoncode %{ 2 | 3 | def _isRigid(simulation): 4 | return isinstance(simulation.integrator, RigidBodyIntegrator) 5 | 6 | class StateDataReporter(app.StateDataReporter): 7 | 8 | def __init__(self, *args, **kwargs): 9 | self._translationalEnergy = kwargs.pop('translationalEnergy', False) 10 | self._rotationalEnergy = kwargs.pop('rotationalEnergy', False) 11 | self._refinedPotentialEnergy = kwargs.pop('refinedPotentialEnergy', False) 12 | self._refinedKineticEnergy = kwargs.pop('refinedKineticEnergy', False) 13 | self._refinedTotalEnergy = kwargs.pop('refinedTotalEnergy', False) 14 | self._refinedTemperature = kwargs.pop('refinedTemperature', False) 15 | self._refinedTranslationalEnergy = kwargs.pop('refinedTranslationalEnergy', False) 16 | self._refinedRotationalEnergy = kwargs.pop('refinedRotationalEnergy', False) 17 | super(StateDataReporter, self).__init__(*args, **kwargs) 18 | 19 | def _initializeConstants(self, simulation): 20 | super(StateDataReporter, self)._initializeConstants(simulation) 21 | if (self._temperature or self._refinedTemperature) and _isRigid(simulation): 22 | self._dof = simulation.integrator.getRigidBodySystem().getNumDOF() 23 | system = simulation.system 24 | forces = [system.getForce(i) for i in range(system.getNumForces())] 25 | if any(isinstance(f, mm.CMMotionRemover) for f in forces): 26 | self._dof -= 3 27 | elif self._refinedTemperature: 28 | self._dof = 1 29 | 30 | def _constructHeaders(self): 31 | headers = super(StateDataReporter, self)._constructHeaders() 32 | if self._translationalEnergy: 33 | headers.append('Translational Energy (kJ/mole)') 34 | if self._rotationalEnergy: 35 | headers.append('Rotational Energy (kJ/mole)') 36 | if self._refinedPotentialEnergy: 37 | headers.append('Refined Potential Energy (kJ/mole)') 38 | if self._refinedKineticEnergy: 39 | headers.append('Refined Kinetic Energy (kJ/mole)') 40 | if self._refinedTotalEnergy: 41 | headers.append('Refined Total Energy (kJ/mole)') 42 | if self._refinedTemperature: 43 | headers.append('Refined Temperature (K)') 44 | if self._refinedTranslationalEnergy: 45 | headers.append('Refined Translational Energy (kJ/mole)') 46 | if self._refinedRotationalEnergy: 47 | headers.append('Refined Rotational Energy (kJ/mole)') 48 | return headers 49 | 50 | def _constructReportValues(self, simulation, state): 51 | values = super(StateDataReporter, self)._constructReportValues(simulation, state) 52 | 53 | if (self._translationalEnergy or self._rotationalEnergy): 54 | if _isRigid(simulation): 55 | KE = simulation.integrator.getKineticEnergies() 56 | else: 57 | KE = [state.getKineticEnergy(), 0.0*unit.kilojoules_per_mole] 58 | if self._translationalEnergy: 59 | values.append(KE[0].value_in_unit(unit.kilojoules_per_mole)) 60 | if self._rotationalEnergy: 61 | values.append(KE[1].value_in_unit(unit.kilojoules_per_mole)) 62 | 63 | if (self._refinedPotentialEnergy or self._refinedTotalEnergy): 64 | U = state.getPotentialEnergy() 65 | if _isRigid(simulation): 66 | U += simulation.integrator.getPotentialEnergyRefinement() 67 | if self._refinedPotentialEnergy: 68 | values.append(U.value_in_unit(unit.kilojoules_per_mole)) 69 | 70 | if (self._refinedKineticEnergy or self._refinedTotalEnergy or self._refinedTemperature or 71 | self._refinedTranslationalEnergy or self._refinedRotationalEnergy): 72 | if _isRigid(simulation): 73 | KE = simulation.integrator.getRefinedKineticEnergies() 74 | else: 75 | KE = [state.getKineticEnergy(), 0.0*unit.kilojoules_per_mole] 76 | if self._refinedKineticEnergy: 77 | values.append((KE[0] + KE[1]).value_in_unit(unit.kilojoules_per_mole)) 78 | if self._refinedTotalEnergy: 79 | values.append((KE[0] + KE[1] + U).value_in_unit(unit.kilojoules_per_mole)) 80 | if self._refinedTemperature: 81 | T = 2*(KE[0] + KE[1])/(self._dof*unit.MOLAR_GAS_CONSTANT_R) 82 | values.append(T.value_in_unit(unit.kelvin)) 83 | if self._refinedTranslationalEnergy: 84 | values.append(KE[0].value_in_unit(unit.kilojoules_per_mole)) 85 | if self._refinedRotationalEnergy: 86 | values.append(KE[1].value_in_unit(unit.kilojoules_per_mole)) 87 | 88 | return values 89 | 90 | %} 91 | -------------------------------------------------------------------------------- /openmmapi/include/internal/MatVec.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENMM_MATVEC_H_ 2 | #define OPENMM_MATVEC_H_ 3 | 4 | /* -------------------------------------------------------------------------- * 5 | * OpenMM Rigid Body Plugin * 6 | * -------------------------------------------------------------------------- */ 7 | 8 | #include 9 | #include 10 | #include "openmm/Vec3.h" 11 | #include 12 | 13 | using namespace OpenMM; 14 | using std::vector; 15 | 16 | namespace RigidBodyPlugin { 17 | 18 | // Forward declaration: 19 | class Diag3; 20 | 21 | /** 22 | * This class represents a 3x3 matrix 23 | */ 24 | 25 | class Mat3 { 26 | public: 27 | Mat3(); 28 | Mat3(Vec3 x, Vec3 y, Vec3 z); 29 | 30 | Vec3 operator[](int index) const; 31 | Vec3& operator[](int index); 32 | Vec3 col(int index) const; 33 | Vec3 diag() const; 34 | bool operator==(const Mat3& rhs) const; 35 | bool operator!=(const Mat3& rhs) const; 36 | Mat3 operator+() const; 37 | Mat3 operator+(const Mat3& rhs) const; 38 | Mat3& operator+=(const Mat3& rhs); 39 | Mat3 operator-() const; 40 | Mat3 operator-(const Mat3& rhs) const; 41 | Mat3 operator-(const Diag3& rhs) const; 42 | Mat3& operator-=(const Mat3& rhs); 43 | Mat3 operator*(double rhs) const; 44 | Mat3& operator*=(double rhs); 45 | Mat3 operator/(double rhs) const; 46 | Mat3& operator/=(double rhs); 47 | Mat3 symmetric() const; 48 | double trace() const; 49 | double det() const; 50 | Mat3 t() const; 51 | Vec3 operator*(const Vec3& rhs) const; 52 | Mat3 operator*(const Mat3& rhs) const; 53 | Mat3 operator*(const Diag3& rhs) const; 54 | protected: 55 | vector row; 56 | }; 57 | 58 | class Diag3 { 59 | public: 60 | Diag3(); 61 | Diag3(Vec3 x); 62 | Diag3(double x); 63 | 64 | Vec3 operator[](int index) const; 65 | Vec3 diag() const; 66 | bool operator==(const Diag3& rhs) const; 67 | bool operator!=(const Diag3& rhs) const; 68 | Diag3 operator+() const; 69 | Diag3 operator+(const Diag3& rhs) const; 70 | Diag3& operator+=(const Diag3& rhs); 71 | Diag3 operator-() const; 72 | Diag3 operator-(const Diag3& rhs) const; 73 | Diag3& operator-=(const Diag3& rhs); 74 | Diag3 operator*(double rhs) const; 75 | Diag3& operator*=(double rhs); 76 | Diag3 operator/(double rhs) const; 77 | Diag3& operator/=(double rhs); 78 | Diag3 t() const; 79 | Vec3 operator*(const Vec3& rhs) const; 80 | Diag3 operator*(const Diag3& rhs) const; 81 | Mat3 operator*(const Mat3& rhs) const; 82 | Diag3 inv() const; 83 | Mat3 asMat3() const; 84 | private: 85 | Vec3 data; 86 | }; 87 | 88 | /** 89 | * This class represents a four component vector. It is used for storing quaternions. 90 | */ 91 | 92 | class Quat { 93 | public: 94 | Quat(); 95 | Quat(double x, double y, double z, double w); 96 | Quat(const Mat3& A); 97 | 98 | double operator[](int index) const; 99 | double& operator[](int index); 100 | bool operator==(const Quat& rhs) const; 101 | bool operator!=(const Quat& rhs) const; 102 | Quat operator+() const; 103 | Quat operator+(const Quat& rhs) const; 104 | Quat& operator+=(const Quat& rhs); 105 | Quat operator-() const; 106 | Quat operator-(const Quat& rhs) const; 107 | Quat& operator-=(const Quat& rhs); 108 | Quat operator*(double rhs) const; 109 | Quat& operator*=(double rhs); 110 | Quat operator/(double rhs) const; 111 | Quat& operator/=(double rhs); 112 | double dot(const Quat& rhs) const; 113 | double norm() const; 114 | int maxloc() const; 115 | Quat B(Vec3 x) const; 116 | Quat C(Vec3 x) const; 117 | Vec3 Bt(Quat y) const; 118 | Vec3 Ct(Quat y) const; 119 | Quat B1() const; 120 | Quat B2() const; 121 | Quat B3() const; 122 | Vec3 A(Vec3 x) const; 123 | Vec3 At(Vec3 x) const; 124 | private: 125 | double data[4]; 126 | }; 127 | 128 | class Projection : public Mat3 { 129 | public: 130 | Projection(Vec3 x); 131 | }; 132 | 133 | template 134 | std::basic_ostream& operator<<(std::basic_ostream& o, const Mat3& M) { 135 | o<<'['< 140 | std::basic_ostream& operator<<(std::basic_ostream& o, const Diag3& D) { 141 | o<<'['< 146 | std::basic_ostream& operator<<(std::basic_ostream& o, const Quat& q) { 147 | o<<'['< 0.0f) 106 | newStepSize = min(newStepSize, oldStepSize*2.0f); // For safety, limit how quickly dt can increase. 107 | if (newStepSize > oldStepSize && newStepSize < 1.1f*oldStepSize) 108 | newStepSize = oldStepSize; // Keeping dt constant between steps improves the behavior of the integrator. 109 | if (newStepSize > maxStepSize) 110 | newStepSize = maxStepSize; 111 | dt[0].y = newStepSize; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /platforms/opencl/src/OpenCLRigidBodyKernels.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENCL_RIGIDBODY_KERNELS_H_ 2 | #define OPENCL_RIGIDBODY_KERNELS_H_ 3 | 4 | /* -------------------------------------------------------------------------- * 5 | * OpenMM * 6 | * -------------------------------------------------------------------------- * 7 | * This is part of the OpenMM molecular simulation toolkit originating from * 8 | * Simbios, the NIH National Center for Physics-Based Simulation of * 9 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 10 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 11 | * * 12 | * Portions copyright (c) 2014 Stanford University and the Authors. * 13 | * Authors: Peter Eastman * 14 | * Contributors: * 15 | * * 16 | * Permission is hereby granted, free of charge, to any person obtaining a * 17 | * copy of this software and associated documentation files (the "Software"), * 18 | * to deal in the Software without restriction, including without limitation * 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 20 | * and/or sell copies of the Software, and to permit persons to whom the * 21 | * Software is furnished to do so, subject to the following conditions: * 22 | * * 23 | * The above copyright notice and this permission notice shall be included in * 24 | * all copies or substantial portions of the Software. * 25 | * * 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 29 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 30 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 31 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 32 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 33 | * -------------------------------------------------------------------------- */ 34 | 35 | #include "RigidBodyKernels.h" 36 | #include "openmm/opencl/OpenCLContext.h" 37 | #include "openmm/opencl/OpenCLArray.h" 38 | #include 39 | 40 | namespace RigidBodyPlugin { 41 | 42 | /** 43 | * This kernel is invoked by RigidBodyIntegrator to take one time step. 44 | */ 45 | class OpenCLIntegrateRigidBodyStepKernel : public IntegrateRigidBodyStepKernel { 46 | public: 47 | OpenCLIntegrateRigidBodyStepKernel(std::string name, const OpenMM::Platform& platform, OpenMM::OpenCLContext& cl) : IntegrateRigidBodyStepKernel(name, platform), cl(cl), 48 | hasInitializedKernels(false) { 49 | } 50 | ~OpenCLIntegrateRigidBodyStepKernel(); 51 | /** 52 | * Initialize the kernel. 53 | * 54 | * @param system the System this kernel will be applied to 55 | * @param integrator the RigidBodyIntegrator this kernel will be used for 56 | */ 57 | void initialize(OpenMM::ContextImpl& context, const RigidBodyIntegrator& integrator); 58 | /** 59 | * Upload the rigid body system to the device. 60 | * 61 | * @param integrator the RigidBodyIntegrator this kernel will be used for 62 | */ 63 | void uploadBodySystem(RigidBodySystem& bodySystem) {} // MUDAR DEPOIS 64 | /** 65 | * Execute the kernel. 66 | * 67 | * @param context the context in which to execute this kernel 68 | * @param integrator the RigidBodyIntegrator this kernel is being used for 69 | */ 70 | void execute(OpenMM::ContextImpl& context, const RigidBodyIntegrator& integrator); 71 | /** 72 | * Compute the kinetic energy. 73 | * 74 | * @param context the context in which to execute this kernel 75 | * @param integrator the RigidBodyIntegrator this kernel is being used for 76 | */ 77 | double computeKineticEnergy(OpenMM::ContextImpl& context, const RigidBodyIntegrator& integrator); 78 | /** 79 | * Compute the different kinetic energy terms. 80 | * 81 | * @param context the context in which to execute this kernel 82 | * @param integrator the RigidBodyIntegrator this kernel is being used for 83 | */ 84 | std::vector getKineticEnergies(OpenMM::ContextImpl& context, const RigidBodyIntegrator& integrator); 85 | private: 86 | OpenMM::OpenCLContext& cl; 87 | bool hasInitializedKernels; 88 | cl::Kernel kernel1, kernel2; 89 | }; 90 | 91 | } // namespace RigidBodyPlugin 92 | 93 | #endif /*OPENCL_RIGIDBODY_KERNELS_H_*/ 94 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------- 2 | # OpenMM RigidBody Plugin 3 | #---------------------------------------------------- 4 | 5 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 6 | 7 | # We need to know where OpenMM is installed so we can access the headers and libraries. 8 | IF(NOT OPENMM_DIR) 9 | IF(WIN32) 10 | SET(OPENMM_DIR "$ENV{ProgramFiles}/OpenMM" CACHE PATH "Where OpenMM is installed") 11 | ELSE(WIN32) 12 | SET(OPENMM_DIR "/usr/local/openmm" CACHE PATH "Where OpenMM is installed") 13 | ENDIF(WIN32) 14 | ENDIF(NOT OPENMM_DIR) 15 | INCLUDE_DIRECTORIES("${OPENMM_DIR}/include") 16 | LINK_DIRECTORIES("${OPENMM_DIR}/lib" "${OPENMM_DIR}/lib/plugins") 17 | 18 | # Specify the C++ version we are building for. 19 | SET (CMAKE_CXX_STANDARD 11) 20 | 21 | # Set flags for linking on mac 22 | IF(APPLE) 23 | SET (CMAKE_INSTALL_NAME_DIR "@rpath") 24 | SET(EXTRA_COMPILE_FLAGS "-msse2 -stdlib=libc++") 25 | ENDIF(APPLE) 26 | 27 | # Select where to install 28 | IF(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}) 29 | SET(CMAKE_INSTALL_PREFIX ${OPENMM_DIR} CACHE PATH "Where to install the plugin" FORCE) 30 | ENDIF(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}) 31 | 32 | # The source is organized into subdirectories, but we handle them all from 33 | # this CMakeLists file rather than letting CMake visit them as SUBDIRS. 34 | SET(RIGIDBODY_PLUGIN_SOURCE_SUBDIRS openmmapi serialization) 35 | 36 | # Set the library name 37 | SET(RIGIDBODY_LIBRARY_NAME RigidBodyPlugin) 38 | SET(SHARED_RIGIDBODY_TARGET ${RIGIDBODY_LIBRARY_NAME}) 39 | 40 | # These are all the places to search for header files which are to be part of the API. 41 | SET(API_INCLUDE_DIRS "openmmapi/include" "openmmapi/include/internal") 42 | 43 | # Locate header files. 44 | SET(API_INCLUDE_FILES) 45 | FOREACH(dir ${API_INCLUDE_DIRS}) 46 | FILE(GLOB fullpaths ${dir}/*.h) 47 | SET(API_INCLUDE_FILES ${API_INCLUDE_FILES} ${fullpaths}) 48 | ENDFOREACH(dir) 49 | 50 | # Collect up source files 51 | SET(SOURCE_FILES) # empty 52 | SET(SOURCE_INCLUDE_FILES) 53 | FOREACH(subdir ${RIGIDBODY_PLUGIN_SOURCE_SUBDIRS}) 54 | FILE(GLOB src_files ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.cpp) 55 | FILE(GLOB incl_files ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.h) 56 | SET(SOURCE_FILES ${SOURCE_FILES} ${src_files}) #append 57 | SET(SOURCE_INCLUDE_FILES ${SOURCE_INCLUDE_FILES} ${incl_files}) 58 | 59 | ## Make sure we find these locally before looking in OpenMM/include if 60 | ## OpenMM was previously installed there. 61 | INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include) 62 | ENDFOREACH(subdir) 63 | 64 | # Create the library. 65 | 66 | ADD_LIBRARY(${SHARED_RIGIDBODY_TARGET} SHARED ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_INCLUDE_FILES}) 67 | SET_TARGET_PROPERTIES(${SHARED_RIGIDBODY_TARGET} 68 | PROPERTIES COMPILE_FLAGS "-DRIGIDBODY_BUILDING_SHARED_LIBRARY ${EXTRA_COMPILE_FLAGS}" 69 | LINK_FLAGS "${EXTRA_COMPILE_FLAGS}") 70 | TARGET_LINK_LIBRARIES(${SHARED_RIGIDBODY_TARGET} OpenMM) 71 | INSTALL_TARGETS(/lib RUNTIME_DIRECTORY /lib ${SHARED_RIGIDBODY_TARGET}) 72 | 73 | # install headers 74 | FILE(GLOB API_ONLY_INCLUDE_FILES "openmmapi/include/*.h") 75 | INSTALL (FILES ${API_ONLY_INCLUDE_FILES} DESTINATION include) 76 | FILE(GLOB API_ONLY_INCLUDE_FILES_INTERNAL "openmmapi/include/internal/*.h") 77 | INSTALL (FILES ${API_ONLY_INCLUDE_FILES_INTERNAL} DESTINATION include/internal) 78 | 79 | # Enable testing 80 | 81 | ENABLE_TESTING() 82 | ADD_SUBDIRECTORY(serialization/tests) 83 | 84 | # Build the implementations for different platforms 85 | 86 | ADD_SUBDIRECTORY(platforms/reference) 87 | 88 | SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") 89 | 90 | #FIND_PACKAGE(OpenCL QUIET) 91 | #IF(OPENCL_FOUND) 92 | # SET(RIGIDBODY_BUILD_OPENCL_LIB ON CACHE BOOL "Build implementation for OpenCL") 93 | #ELSE(OPENCL_FOUND) 94 | # SET(RIGIDBODY_BUILD_OPENCL_LIB OFF CACHE BOOL "Build implementation for OpenCL") 95 | #ENDIF(OPENCL_FOUND) 96 | #IF(RIGIDBODY_BUILD_OPENCL_LIB) 97 | # ADD_SUBDIRECTORY(platforms/opencl) 98 | #ENDIF(RIGIDBODY_BUILD_OPENCL_LIB) 99 | 100 | IF(ENABLE_COVERAGE) 101 | FIND_PACKAGE(codecov QUIET) 102 | ENDIF(ENABLE_COVERAGE) 103 | 104 | FIND_PACKAGE(CUDA QUIET) 105 | IF(CUDA_FOUND) 106 | SET(RIGIDBODY_BUILD_CUDA_LIB ON CACHE BOOL "Build implementation for CUDA") 107 | ELSE(CUDA_FOUND) 108 | SET(RIGIDBODY_BUILD_CUDA_LIB OFF CACHE BOOL "Build implementation for CUDA") 109 | ENDIF(CUDA_FOUND) 110 | IF(RIGIDBODY_BUILD_CUDA_LIB) 111 | ADD_SUBDIRECTORY(platforms/cuda) 112 | ENDIF(RIGIDBODY_BUILD_CUDA_LIB) 113 | 114 | # Build the Python API 115 | 116 | FIND_PROGRAM(PYTHON_EXECUTABLE python) 117 | FIND_PROGRAM(SWIG_EXECUTABLE swig) 118 | IF(PYTHON_EXECUTABLE AND SWIG_EXECUTABLE) 119 | SET(RIGIDBODY_BUILD_PYTHON_WRAPPERS ON CACHE BOOL "Build wrappers for Python") 120 | ELSE(PYTHON_EXECUTABLE AND SWIG_EXECUTABLE) 121 | SET(RIGIDBODY_BUILD_PYTHON_WRAPPERS OFF CACHE BOOL "Build wrappers for Python") 122 | ENDIF(PYTHON_EXECUTABLE AND SWIG_EXECUTABLE) 123 | IF(RIGIDBODY_BUILD_PYTHON_WRAPPERS) 124 | ADD_SUBDIRECTORY(python) 125 | ENDIF(RIGIDBODY_BUILD_PYTHON_WRAPPERS) 126 | -------------------------------------------------------------------------------- /openmmapi/include/RigidBodyKernels.h: -------------------------------------------------------------------------------- 1 | #ifndef RIGIDBODY_KERNELS_H_ 2 | #define RIGIDBODY_KERNELS_H_ 3 | 4 | /* -------------------------------------------------------------------------- * 5 | * OpenMM * 6 | * -------------------------------------------------------------------------- * 7 | * This is part of the OpenMM molecular simulation toolkit originating from * 8 | * Simbios, the NIH National Center for Physics-Based Simulation of * 9 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 10 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 11 | * * 12 | * Portions copyright (c) 2014 Stanford University and the Authors. * 13 | * Authors: Peter Eastman * 14 | * Contributors: * 15 | * * 16 | * Permission is hereby granted, free of charge, to any person obtaining a * 17 | * copy of this software and associated documentation files (the "Software"), * 18 | * to deal in the Software without restriction, including without limitation * 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 20 | * and/or sell copies of the Software, and to permit persons to whom the * 21 | * Software is furnished to do so, subject to the following conditions: * 22 | * * 23 | * The above copyright notice and this permission notice shall be included in * 24 | * all copies or substantial portions of the Software. * 25 | * * 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 29 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 30 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 31 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 32 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 33 | * -------------------------------------------------------------------------- */ 34 | 35 | #include "RigidBodyIntegrator.h" 36 | #include "openmm/KernelImpl.h" 37 | #include "openmm/Platform.h" 38 | #include "openmm/System.h" 39 | #include 40 | #include 41 | 42 | namespace RigidBodyPlugin { 43 | 44 | /** 45 | * This kernel is invoked by RigidBodyIntegrator to take one time step. 46 | */ 47 | class IntegrateRigidBodyStepKernel : public OpenMM::KernelImpl { 48 | public: 49 | static std::string Name() { 50 | return "IntegrateRigidBodyStep"; 51 | } 52 | IntegrateRigidBodyStepKernel(std::string name, const OpenMM::Platform& platform) : OpenMM::KernelImpl(name, platform) { 53 | } 54 | /** 55 | * Initialize the kernel. 56 | * 57 | * @param system the System this kernel will be applied to 58 | * @param integrator the RigidBodyIntegrator this kernel will be used for 59 | */ 60 | virtual void initialize(OpenMM::ContextImpl& context, const RigidBodyIntegrator& integrator) = 0; 61 | /** 62 | * Upload the rigid body system. 63 | * 64 | * @param integrator the RigidBodyIntegrator this kernel will be used for 65 | */ 66 | virtual void uploadBodySystem(RigidBodySystem& bodySystem) = 0; 67 | /** 68 | * Execute the kernel. 69 | * 70 | * @param context the context in which to execute this kernel 71 | * @param integrator the RigidBodyIntegrator this kernel is being used for 72 | */ 73 | virtual void execute(OpenMM::ContextImpl& context, const RigidBodyIntegrator& integrator) = 0; 74 | /** 75 | * Compute the kinetic energy. 76 | * 77 | * @param context the context in which to execute this kernel 78 | * @param integrator the RigidBodyIntegrator this kernel is being used for 79 | */ 80 | virtual double computeKineticEnergy(OpenMM::ContextImpl& context, const RigidBodyIntegrator& integrator) = 0; 81 | /** 82 | * Compute the different kinetic energy terms. 83 | * 84 | * @param integrator the RigidBodyIntegrator this kernel is being used for 85 | */ 86 | virtual std::vector getKineticEnergies(const RigidBodyIntegrator& integrator) = 0; 87 | /** 88 | * Compute the translational and rotational terms of the refined kinetic energy. 89 | * 90 | * @param integrator the RigidBodyIntegrator this kernel is being used for 91 | */ 92 | virtual std::vector getRefinedKineticEnergies(const RigidBodyIntegrator& integrator) = 0; 93 | /** 94 | * Compute the potential energy refinement. 95 | * 96 | * @param integrator the RigidBodyIntegrator this kernel is being used for 97 | */ 98 | virtual double getPotentialEnergyRefinement(const RigidBodyIntegrator& integrator) = 0; 99 | }; 100 | 101 | } // namespace RigidBodyPlugin 102 | 103 | #endif /*RIGIDBODY_KERNELS_H_*/ 104 | -------------------------------------------------------------------------------- /platforms/reference/src/ReferenceRigidBodyKernels.h: -------------------------------------------------------------------------------- 1 | #ifndef REFERENCE_RIGIDBODY_KERNELS_H_ 2 | #define REFERENCE_RIGIDBODY_KERNELS_H_ 3 | 4 | /* -------------------------------------------------------------------------- * 5 | * OpenMM * 6 | * -------------------------------------------------------------------------- * 7 | * This is part of the OpenMM molecular simulation toolkit originating from * 8 | * Simbios, the NIH National Center for Physics-Based Simulation of * 9 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 10 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 11 | * * 12 | * Portions copyright (c) 2014 Stanford University and the Authors. * 13 | * Authors: Peter Eastman * 14 | * Contributors: * 15 | * * 16 | * Permission is hereby granted, free of charge, to any person obtaining a * 17 | * copy of this software and associated documentation files (the "Software"), * 18 | * to deal in the Software without restriction, including without limitation * 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 20 | * and/or sell copies of the Software, and to permit persons to whom the * 21 | * Software is furnished to do so, subject to the following conditions: * 22 | * * 23 | * The above copyright notice and this permission notice shall be included in * 24 | * all copies or substantial portions of the Software. * 25 | * * 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 29 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 30 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 31 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 32 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 33 | * -------------------------------------------------------------------------- */ 34 | 35 | #include "RigidBodyKernels.h" 36 | #include "openmm/Platform.h" 37 | #include "openmm/System.h" 38 | #include "openmm/reference/ReferencePlatform.h" 39 | #include 40 | 41 | namespace RigidBodyPlugin { 42 | 43 | /** 44 | * This kernel is invoked by RigidBodyIntegrator to take one time step. 45 | */ 46 | class ReferenceIntegrateRigidBodyStepKernel : public IntegrateRigidBodyStepKernel { 47 | public: 48 | ReferenceIntegrateRigidBodyStepKernel(std::string name, const OpenMM::Platform& platform, OpenMM::ReferencePlatform::PlatformData& data) : IntegrateRigidBodyStepKernel(name, platform), 49 | data(data) { 50 | } 51 | ~ReferenceIntegrateRigidBodyStepKernel(); 52 | /** 53 | * Initialize the kernel. 54 | * 55 | * @param system the System this kernel will be applied to 56 | * @param integrator the RigidBodyIntegrator this kernel will be used for 57 | */ 58 | void initialize(OpenMM::ContextImpl& context, const RigidBodyIntegrator& integrator); 59 | /** 60 | * Upload the rigid body system to the device. 61 | * 62 | * @param integrator the RigidBodyIntegrator this kernel will be used for 63 | */ 64 | void uploadBodySystem(RigidBodySystem& bodySystem); 65 | /** 66 | * Execute the kernel. 67 | * 68 | * @param context the context in which to execute this kernel 69 | * @param integrator the RigidBodyIntegrator this kernel is being used for 70 | */ 71 | void execute(OpenMM::ContextImpl& context, const RigidBodyIntegrator& integrator); 72 | /** 73 | * Compute the kinetic energy. 74 | * 75 | * @param context the context in which to execute this kernel 76 | * @param integrator the RigidBodyIntegrator this kernel is being used for 77 | */ 78 | double computeKineticEnergy(OpenMM::ContextImpl& context, const RigidBodyIntegrator& integrator); 79 | /** 80 | * Compute the different kinetic energy terms. 81 | * 82 | * @param integrator the RigidBodyIntegrator this kernel is being used for 83 | */ 84 | std::vector getKineticEnergies(const RigidBodyIntegrator& integrator); 85 | /** 86 | * Compute the translational and rotational terms of the refined kinetic energy. 87 | * 88 | * @param integrator the RigidBodyIntegrator this kernel is being used for 89 | */ 90 | std::vector getRefinedKineticEnergies(const RigidBodyIntegrator& integrator); 91 | /** 92 | * Compute the potential energy refinement. 93 | * 94 | * @param integrator the RigidBodyIntegrator this kernel is being used for 95 | */ 96 | double getPotentialEnergyRefinement(const RigidBodyIntegrator& integrator); 97 | private: 98 | OpenMM::ReferencePlatform::PlatformData& data; 99 | RigidBodySystem bodySystem; 100 | std::vector invMass; 101 | std::vector oldPos; 102 | }; 103 | 104 | } // namespace RigidBodyPlugin 105 | 106 | #endif /*REFERENCE_RIGIDBODY_KERNELS_H_*/ 107 | -------------------------------------------------------------------------------- /cmake/FindGcov.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of CMake-codecov. 2 | # 3 | # Copyright (c) 4 | # 2015-2017 RWTH Aachen University, Federal Republic of Germany 5 | # 6 | # See the LICENSE file in the package base directory for details 7 | # 8 | # Written by Alexander Haase, alexander.haase@rwth-aachen.de 9 | # 10 | 11 | 12 | # include required Modules 13 | include(FindPackageHandleStandardArgs) 14 | 15 | 16 | # Search for gcov binary. 17 | set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET}) 18 | set(CMAKE_REQUIRED_QUIET ${codecov_FIND_QUIETLY}) 19 | 20 | get_property(ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES) 21 | foreach (LANG ${ENABLED_LANGUAGES}) 22 | # Gcov evaluation is dependent on the used compiler. Check gcov support for 23 | # each compiler that is used. If gcov binary was already found for this 24 | # compiler, do not try to find it again. 25 | if (NOT GCOV_${CMAKE_${LANG}_COMPILER_ID}_BIN) 26 | get_filename_component(COMPILER_PATH "${CMAKE_${LANG}_COMPILER}" PATH) 27 | 28 | if ("${CMAKE_${LANG}_COMPILER_ID}" STREQUAL "GNU") 29 | # Some distributions like OSX (homebrew) ship gcov with the compiler 30 | # version appended as gcov-x. To find this binary we'll build the 31 | # suggested binary name with the compiler version. 32 | string(REGEX MATCH "^[0-9]+" GCC_VERSION 33 | "${CMAKE_${LANG}_COMPILER_VERSION}") 34 | 35 | find_program(GCOV_BIN NAMES gcov-${GCC_VERSION} gcov 36 | HINTS ${COMPILER_PATH}) 37 | 38 | elseif ("${CMAKE_${LANG}_COMPILER_ID}" STREQUAL "Clang") 39 | # Some distributions like Debian ship llvm-cov with the compiler 40 | # version appended as llvm-cov-x.y. To find this binary we'll build 41 | # the suggested binary name with the compiler version. 42 | string(REGEX MATCH "^[0-9]+.[0-9]+" LLVM_VERSION 43 | "${CMAKE_${LANG}_COMPILER_VERSION}") 44 | 45 | # llvm-cov prior version 3.5 seems to be not working with coverage 46 | # evaluation tools, but these versions are compatible with the gcc 47 | # gcov tool. 48 | if(LLVM_VERSION VERSION_GREATER 3.4) 49 | find_program(LLVM_COV_BIN NAMES "llvm-cov-${LLVM_VERSION}" 50 | "llvm-cov" HINTS ${COMPILER_PATH}) 51 | mark_as_advanced(LLVM_COV_BIN) 52 | 53 | if (LLVM_COV_BIN) 54 | find_program(LLVM_COV_WRAPPER "llvm-cov-wrapper" PATHS 55 | ${CMAKE_MODULE_PATH}) 56 | if (LLVM_COV_WRAPPER) 57 | set(GCOV_BIN "${LLVM_COV_WRAPPER}" CACHE FILEPATH "") 58 | 59 | # set additional parameters 60 | set(GCOV_${CMAKE_${LANG}_COMPILER_ID}_ENV 61 | "LLVM_COV_BIN=${LLVM_COV_BIN}" CACHE STRING 62 | "Environment variables for llvm-cov-wrapper.") 63 | mark_as_advanced(GCOV_${CMAKE_${LANG}_COMPILER_ID}_ENV) 64 | endif () 65 | endif () 66 | endif () 67 | 68 | if (NOT GCOV_BIN) 69 | # Fall back to gcov binary if llvm-cov was not found or is 70 | # incompatible. This is the default on OSX, but may crash on 71 | # recent Linux versions. 72 | find_program(GCOV_BIN gcov HINTS ${COMPILER_PATH}) 73 | endif () 74 | endif () 75 | 76 | 77 | if (GCOV_BIN) 78 | set(GCOV_${CMAKE_${LANG}_COMPILER_ID}_BIN "${GCOV_BIN}" CACHE STRING 79 | "${LANG} gcov binary.") 80 | 81 | if (NOT CMAKE_REQUIRED_QUIET) 82 | message("-- Found gcov evaluation for " 83 | "${CMAKE_${LANG}_COMPILER_ID}: ${GCOV_BIN}") 84 | endif() 85 | 86 | unset(GCOV_BIN CACHE) 87 | endif () 88 | endif () 89 | endforeach () 90 | 91 | 92 | 93 | 94 | # Add a new global target for all gcov targets. This target could be used to 95 | # generate the gcov files for the whole project instead of calling -gcov 96 | # for each target. 97 | if (NOT TARGET gcov) 98 | add_custom_target(gcov) 99 | endif (NOT TARGET gcov) 100 | 101 | 102 | 103 | # This function will add gcov evaluation for target . Only sources of 104 | # this target will be evaluated and no dependencies will be added. It will call 105 | # Gcov on any source file of once and store the gcov file in the same 106 | # directory. 107 | function (add_gcov_target TNAME) 108 | set(TDIR ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TNAME}.dir) 109 | 110 | # We don't have to check, if the target has support for coverage, thus this 111 | # will be checked by add_coverage_target in Findcoverage.cmake. Instead we 112 | # have to determine which gcov binary to use. 113 | get_target_property(TSOURCES ${TNAME} SOURCES) 114 | set(SOURCES "") 115 | set(TCOMPILER "") 116 | foreach (FILE ${TSOURCES}) 117 | codecov_path_of_source(${FILE} FILE) 118 | if (NOT "${FILE}" STREQUAL "") 119 | codecov_lang_of_source(${FILE} LANG) 120 | if (NOT "${LANG}" STREQUAL "") 121 | list(APPEND SOURCES "${FILE}") 122 | set(TCOMPILER ${CMAKE_${LANG}_COMPILER_ID}) 123 | endif () 124 | endif () 125 | endforeach () 126 | 127 | # If no gcov binary was found, coverage data can't be evaluated. 128 | if (NOT GCOV_${TCOMPILER}_BIN) 129 | message(WARNING "No coverage evaluation binary found for ${TCOMPILER}.") 130 | return() 131 | endif () 132 | 133 | set(GCOV_BIN "${GCOV_${TCOMPILER}_BIN}") 134 | set(GCOV_ENV "${GCOV_${TCOMPILER}_ENV}") 135 | 136 | 137 | set(BUFFER "") 138 | foreach(FILE ${SOURCES}) 139 | get_filename_component(FILE_PATH "${TDIR}/${FILE}" PATH) 140 | 141 | # call gcov 142 | add_custom_command(OUTPUT ${TDIR}/${FILE}.gcov 143 | COMMAND ${GCOV_ENV} ${GCOV_BIN} ${TDIR}/${FILE}.gcno > /dev/null 144 | DEPENDS ${TNAME} ${TDIR}/${FILE}.gcno 145 | WORKING_DIRECTORY ${FILE_PATH} 146 | ) 147 | 148 | list(APPEND BUFFER ${TDIR}/${FILE}.gcov) 149 | endforeach() 150 | 151 | 152 | # add target for gcov evaluation of 153 | add_custom_target(${TNAME}-gcov DEPENDS ${BUFFER}) 154 | 155 | # add evaluation target to the global gcov target. 156 | add_dependencies(gcov ${TNAME}-gcov) 157 | endfunction (add_gcov_target) 158 | -------------------------------------------------------------------------------- /platforms/opencl/src/OpenCLRigidBodyKernels.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMM * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2014 Stanford University and the Authors. * 10 | * Authors: Peter Eastman * 11 | * Contributors: * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #include "OpenCLRigidBodyKernels.h" 33 | #include "OpenCLRigidBodyKernelSources.h" 34 | #include "openmm/internal/ContextImpl.h" 35 | #include "openmm/opencl/OpenCLBondedUtilities.h" 36 | #include "openmm/opencl/OpenCLForceInfo.h" 37 | #include "openmm/opencl/OpenCLIntegrationUtilities.h" 38 | 39 | using namespace RigidBodyPlugin; 40 | using namespace OpenMM; 41 | using namespace std; 42 | 43 | static void setPosqCorrectionArg(OpenCLContext& cl, cl::Kernel& kernel, int index) { 44 | if (cl.getUseMixedPrecision()) 45 | kernel.setArg(index, cl.getPosqCorrection().getDeviceBuffer()); 46 | else 47 | kernel.setArg(index, NULL); 48 | } 49 | 50 | OpenCLIntegrateRigidBodyStepKernel::~OpenCLIntegrateRigidBodyStepKernel() { 51 | } 52 | 53 | void OpenCLIntegrateRigidBodyStepKernel::initialize(ContextImpl& context, const RigidBodyIntegrator& integrator) { 54 | throw OpenMMException("This version of Rigid Body Plugin does not support OpenCL Platform"); 55 | cl.getPlatformData().initializeContexts(context.getSystem()); 56 | cl::Program program = cl.createProgram(OpenCLRigidBodyKernelSources::rigidbodyintegrator, ""); 57 | kernel1 = cl::Kernel(program, "integrateRigidBodyPart1"); 58 | kernel2 = cl::Kernel(program, "integrateRigidBodyPart2"); 59 | } 60 | 61 | void OpenCLIntegrateRigidBodyStepKernel::execute(ContextImpl& context, const RigidBodyIntegrator& integrator) { 62 | OpenCLIntegrationUtilities& integration = cl.getIntegrationUtilities(); 63 | int numAtoms = cl.getNumAtoms(); 64 | double dt = integrator.getStepSize(); 65 | if (!hasInitializedKernels) { 66 | hasInitializedKernels = true; 67 | kernel1.setArg(0, numAtoms); 68 | kernel1.setArg(1, cl.getIntegrationUtilities().getStepSize().getDeviceBuffer()); 69 | kernel1.setArg(2, cl.getPosq().getDeviceBuffer()); 70 | setPosqCorrectionArg(cl, kernel1, 3); 71 | kernel1.setArg(4, cl.getVelm().getDeviceBuffer()); 72 | kernel1.setArg(5, cl.getForce().getDeviceBuffer()); 73 | kernel1.setArg(6, integration.getPosDelta().getDeviceBuffer()); 74 | kernel2.setArg(0, numAtoms); 75 | kernel2.setArg(1, cl.getIntegrationUtilities().getStepSize().getDeviceBuffer()); 76 | kernel2.setArg(2, cl.getPosq().getDeviceBuffer()); 77 | setPosqCorrectionArg(cl, kernel2, 3); 78 | kernel2.setArg(4, cl.getVelm().getDeviceBuffer()); 79 | kernel2.setArg(5, integration.getPosDelta().getDeviceBuffer()); 80 | } 81 | cl.getIntegrationUtilities().setNextStepSize(dt); 82 | 83 | // Call the first integration kernel. 84 | 85 | cl.executeKernel(kernel1, numAtoms); 86 | 87 | // Apply constraints. 88 | 89 | integration.applyConstraints(integrator.getConstraintTolerance()); 90 | 91 | // Call the second integration kernel. 92 | 93 | cl.executeKernel(kernel2, numAtoms); 94 | integration.computeVirtualSites(); 95 | 96 | // Update the time and step count. 97 | 98 | cl.setTime(cl.getTime()+dt); 99 | cl.setStepCount(cl.getStepCount()+1); 100 | cl.reorderAtoms(); 101 | 102 | // Reduce UI lag. 103 | 104 | #ifdef WIN32 105 | cl.getQueue().flush(); 106 | #endif 107 | } 108 | 109 | double OpenCLIntegrateRigidBodyStepKernel::computeKineticEnergy(ContextImpl& context, const RigidBodyIntegrator& integrator) { 110 | return cl.getIntegrationUtilities().computeKineticEnergy(0.5*integrator.getStepSize()); 111 | } 112 | 113 | vector OpenCLIntegrateRigidBodyStepKernel::getKineticEnergies(ContextImpl& context, const RigidBodyIntegrator& integrator) { 114 | vector KE(2); 115 | return KE; 116 | } 117 | -------------------------------------------------------------------------------- /openmmapi/src/eigenDecomposition.cpp: -------------------------------------------------------------------------------- 1 | #include "internal/eigenDecomposition.h" 2 | #include "openmm/OpenMMException.h" 3 | #include 4 | #include 5 | 6 | /* References: 7 | 1) Oliver K. Smith 8 | Eigenvalues of a symmetric 3 × 3 matrix 9 | Communications of the ACM, 4 (1961), p. 168 10 | 11 | 2) Joachim Kopp 12 | Efficient numerical diagonalization of hermitian 3x3 matrices 13 | Int. J. Mod. Phys. C, 19 (2008), p. 523 14 | */ 15 | 16 | using namespace RigidBodyPlugin; 17 | using namespace OpenMM; 18 | 19 | // Constants 20 | #define M_SQRT3 1.73205080756887729352744634151 // sqrt(3) 21 | #define PI 3.14159265358979323846264338328 22 | #define eps std::numeric_limits::epsilon() 23 | 24 | // Macros 25 | #define SQR(x) ((x)*(x)) // x^2 26 | 27 | //-------------------------------------------------------------------------------------------------- 28 | 29 | void swap(double& a, double& b) { 30 | double c = a; 31 | a = b; 32 | b = c; 33 | } 34 | 35 | //-------------------------------------------------------------------------------------------------- 36 | 37 | void computeEigenvector( Vec3& q, Mat3 a, double n1tmp, double n2tmp, double thresh ) { 38 | double norm = q.dot(q); 39 | double n1 = n1tmp + a[0][0]*a[0][0]; 40 | double n2 = n2tmp + a[1][1]*a[1][1]; 41 | double error = n1*n2; 42 | 43 | // If the first column is zero, then (1, 0, 0) is an eigenvector 44 | if (n1 <= thresh) 45 | q = Vec3(1.0, 0.0, 0.0); 46 | 47 | // If the second column is zero, then (0, 1, 0) is an eigenvector 48 | else if (n2 <= thresh) 49 | q = Vec3(0.0, 1.0, 0.0); 50 | 51 | // If angle between A(*,1) and A(*,2) is too small, don't use 52 | // cross product, but calculate v ~ (1, -A0/A1, 0) 53 | else if (norm < 4096.0*eps*eps*error) { 54 | double t = fabs(a[0][1]); 55 | double f = -a[0][0]/a[0][1]; 56 | if (fabs(a[1][1]) > t) { 57 | t = fabs(a[1][1]); 58 | f = -a[0][1]/a[1][1]; 59 | } 60 | if (fabs(a[1][2]) > t) 61 | f = -a[0][2]/a[1][2]; 62 | norm = 1.0/sqrt(1.0 + f*f); 63 | q = Vec3(norm, f*norm, 0.0); 64 | } 65 | // This is the standard branch 66 | else 67 | q *= sqrt(1.0/norm); 68 | } 69 | 70 | //-------------------------------------------------------------------------------------------------- 71 | 72 | Vec3 eigenvalues(Mat3 A) { 73 | double p1 = SQR(A[0][1]) + SQR(A[0][2]) + SQR(A[1][2]); 74 | if (p1 < eps) { 75 | Vec3 w = A.diag(); 76 | if (w[0] < w[1]) swap(w[0], w[1]); 77 | if (w[0] < w[2]) swap(w[0], w[2]); 78 | if (w[1] < w[2]) swap(w[1], w[2]); 79 | return w; 80 | } 81 | else { 82 | Vec3 d = A.diag(); 83 | double TrA = d[0] + d[1] + d[2]; 84 | double q = TrA/3.0; 85 | d -= Vec3(q, q, q); 86 | double p2 = d.dot(d) + 2.0*p1; 87 | double p = sqrt(p2/6.0); 88 | double r = (A - Diag3(q)).det()*(3.0/(p*p2)); 89 | double phi; 90 | if (r <= -1.0) 91 | phi = PI/3.0; 92 | else if (r >= 1.0) 93 | phi = 0.0; 94 | else 95 | phi = acos(r)/3.0; 96 | double w0 = q + 2.0*p*cos(phi); 97 | double w2 = q + 2.0*p*cos(phi + 2.0*PI/3.0); 98 | return Vec3(w0, TrA - (w0 + w2), w2); 99 | } 100 | } 101 | 102 | //-------------------------------------------------------------------------------------------------- 103 | 104 | Mat3 eigenvectors(Mat3 A, Vec3& w) { 105 | double wmax8eps = 8.0*eps*fabs(w[0]); 106 | double thresh = wmax8eps*wmax8eps; 107 | 108 | // Prepare calculation of eigenvectors 109 | Vec3 q0, q1; 110 | Mat3 a = A.symmetric(); 111 | double n1 = SQR(a[0][1]) + SQR(a[0][2]); 112 | double n2 = SQR(a[0][1]) + SQR(a[1][2]); 113 | q0[0] = a[0][1]*a[1][2] - a[0][2]*a[1][1]; 114 | q1[0] = q0[0]; 115 | q0[1] = a[0][2]*a[0][1] - a[1][2]*a[0][0]; 116 | q1[1] = q0[1]; 117 | q1[2] = SQR(a[0][1]); 118 | 119 | // Calculate first eigenvector by the formula v(1) = (A - lambda(1)).e1 x (A - lambda(1)).e2 120 | a[0][0] -= w[0]; 121 | a[1][1] -= w[0]; 122 | q0 = Vec3(q1[0] + a[0][2]*w[0], q1[1] + a[1][2]*w[0], a[0][0]*a[1][1] - q1[2]); 123 | computeEigenvector( q0, a, n1, n2, thresh ); 124 | 125 | // Prepare calculation of second eigenvector 126 | double t = w[0] - w[1]; 127 | 128 | // Is this eigenvalue degenerate? 129 | if (fabs(t) > wmax8eps) { 130 | // For non-degenerate eigenvalue, calculate second eigenvector by the formula 131 | // v[1] = (A - lambda[1]).e1 x (A - lambda[1]).e2 132 | a[0][0] += t; 133 | a[1][1] += t; 134 | q1 = Vec3(q1[0] + a[0][2]*w[1], q1[1] + a[1][2]*w[1], a[0][0]*a[1][1] - q1[2]); 135 | computeEigenvector( q1, a, n1, n2, thresh ); 136 | 137 | } 138 | else { 139 | // For degenerate eigenvalue, calculate second eigenvector according to 140 | // v[1] = v(1) x (A - lambda[1]).e[i] 141 | 142 | // This would really get too complicated if we could not assume all of A to 143 | // contain meaningful values. 144 | a[0][0] += w[0]; 145 | a[1][1] += w[0]; 146 | bool success = false; 147 | for (int i = 0; i < 3 && !success; i++) { 148 | a[i][i] -= w[1]; 149 | Vec3 ai = a.col(i); 150 | n1 = ai.dot(ai); 151 | success = n1 > thresh; 152 | if (success) { 153 | q1 = q0.cross(ai); 154 | double norm = q1.dot(q1); 155 | success = norm > 65536.0*eps*eps*n1; 156 | if (success) 157 | q1 *= sqrt(1.0/norm); 158 | } 159 | } 160 | 161 | // This means that any vector orthogonal to v(1) is an EV. 162 | if (!success) { 163 | int i = 0; 164 | while (q0[i] == 0.0) 165 | i++; 166 | int j = i % 3; 167 | double norm = 1.0/sqrt(SQR(q0[i]) + SQR(q0[j])); 168 | q1[i] = q0[j]*norm; 169 | q1[j] = -q0[i]*norm; 170 | q1[i+1 % 3] = 0.0; 171 | } 172 | } 173 | 174 | // Calculate third eigenvector according to v[2] = v(1) x v[1] 175 | return Mat3(q0, q1, q0.cross(q1)); 176 | } 177 | -------------------------------------------------------------------------------- /platforms/cuda/src/CudaRigidBodyKernels.h: -------------------------------------------------------------------------------- 1 | #ifndef CUDA_RIGIDBODY_KERNELS_H_ 2 | #define CUDA_RIGIDBODY_KERNELS_H_ 3 | 4 | /* -------------------------------------------------------------------------- * 5 | * OpenMM * 6 | * -------------------------------------------------------------------------- * 7 | * This is part of the OpenMM molecular simulation toolkit originating from * 8 | * Simbios, the NIH National Center for Physics-Based Simulation of * 9 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 10 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 11 | * * 12 | * Portions copyright (c) 2014 Stanford University and the Authors. * 13 | * Authors: Peter Eastman * 14 | * Contributors: * 15 | * * 16 | * Permission is hereby granted, free of charge, to any person obtaining a * 17 | * copy of this software and associated documentation files (the "Software"), * 18 | * to deal in the Software without restriction, including without limitation * 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 20 | * and/or sell copies of the Software, and to permit persons to whom the * 21 | * Software is furnished to do so, subject to the following conditions: * 22 | * * 23 | * The above copyright notice and this permission notice shall be included in * 24 | * all copies or substantial portions of the Software. * 25 | * * 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 29 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 30 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 31 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 32 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 33 | * -------------------------------------------------------------------------- */ 34 | 35 | #include "RigidBodyKernels.h" 36 | #include "openmm/cuda/CudaContext.h" 37 | #include "openmm/cuda/CudaArray.h" 38 | #include 39 | 40 | namespace RigidBodyPlugin { 41 | 42 | /** 43 | * This kernel is invoked by RigidBodyIntegrator to take one time step. 44 | */ 45 | class CudaIntegrateRigidBodyStepKernel : public IntegrateRigidBodyStepKernel { 46 | public: 47 | CudaIntegrateRigidBodyStepKernel(std::string name, const OpenMM::Platform& platform, OpenMM::CudaContext& cu) : 48 | IntegrateRigidBodyStepKernel(name, platform), cu(cu) { 49 | } 50 | 51 | ~CudaIntegrateRigidBodyStepKernel(); 52 | 53 | /** 54 | * Initialize the kernel. 55 | * 56 | * @param system the System this kernel will be applied to 57 | * @param integrator the RigidBodyIntegrator this kernel will be used for 58 | */ 59 | void initialize(OpenMM::ContextImpl& context, const RigidBodyIntegrator& integrator); 60 | /** 61 | * Upload the rigid body system to the device. 62 | * 63 | * @param integrator the RigidBodyIntegrator this kernel will be used for 64 | */ 65 | void uploadBodySystem(RigidBodySystem& bodySystem); 66 | /** 67 | * Execute the kernel. 68 | * 69 | * @param context the context in which to execute this kernel 70 | * @param integrator the RigidBodyIntegrator this kernel is being used for 71 | */ 72 | void execute(OpenMM::ContextImpl& context, const RigidBodyIntegrator& integrator); 73 | /** 74 | * Compute the kinetic energy. 75 | * 76 | * @param context the context in which to execute this kernel 77 | * @param integrator the RigidBodyIntegrator this kernel is being used for 78 | */ 79 | double computeKineticEnergy(OpenMM::ContextImpl& context, const RigidBodyIntegrator& integrator); 80 | /** 81 | * Compute the different kinetic energy terms. 82 | * 83 | * @param integrator the RigidBodyIntegrator this kernel is being used for 84 | */ 85 | std::vector getKineticEnergies(const RigidBodyIntegrator& integrator); 86 | /** 87 | * Compute the translational and rotational terms of the refined kinetic energy. 88 | * 89 | * @param integrator the RigidBodyIntegrator this kernel is being used for 90 | */ 91 | std::vector getRefinedKineticEnergies(const RigidBodyIntegrator& integrator); 92 | /** 93 | * Compute the potential energy refinement. 94 | * 95 | * @param integrator the RigidBodyIntegrator this kernel is being used for 96 | */ 97 | double getPotentialEnergyRefinement(const RigidBodyIntegrator& integrator); 98 | private: 99 | class ReorderListener; 100 | ReorderListener* reorderListener = NULL; 101 | 102 | template 103 | std::vector kineticEnergy(const RigidBodyIntegrator& integrator, bool refined); 104 | 105 | template 106 | real potentialEnergyRefinement(); 107 | 108 | template 109 | size_t allocateArrays(); 110 | 111 | OpenMM::CudaContext& cu; 112 | CUfunction freeAtomsDelta, freeAtomsDot; 113 | CUfunction rigidBodiesPart1, rigidBodiesPart2; 114 | CUfunction kineticEnergyKernel, refinedKineticEnergyKernel; 115 | CUfunction potentialEnergyRefinementKernel; 116 | void* pinnedBuffer = NULL; 117 | 118 | OpenMM::CudaArray* atomLocation = NULL; 119 | OpenMM::CudaArray* bodyData = NULL; 120 | OpenMM::CudaArray* bodyFixedPos = NULL; 121 | OpenMM::CudaArray* savedPos = NULL; 122 | OpenMM::CudaArray* atomE = NULL; 123 | OpenMM::CudaArray* bodyE1 = NULL; 124 | OpenMM::CudaArray* bodyE2 = NULL; 125 | OpenMM::CudaArray* rdot = NULL; 126 | 127 | int numBodies; 128 | int numFree; 129 | int paddedNumActualAtoms; 130 | int paddedNumBodies; 131 | int paddedNumBodyAtoms; 132 | int paddedNumFree; 133 | }; 134 | 135 | } // namespace RigidBodyPlugin 136 | 137 | #endif /*CUDA_RIGIDBODY_KERNELS_H_*/ 138 | -------------------------------------------------------------------------------- /openmmapi/include/RigidBodyIntegrator.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENMM_RIGIDBODYINTEGRATOR_H_ 2 | #define OPENMM_RIGIDBODYINTEGRATOR_H_ 3 | 4 | /* -------------------------------------------------------------------------- * 5 | * OpenMM * 6 | * -------------------------------------------------------------------------- * 7 | * This is part of the OpenMM molecular simulation toolkit originating from * 8 | * Simbios, the NIH National Center for Physics-Based Simulation of * 9 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 10 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 11 | * * 12 | * Portions copyright (c) 2008-2012 Stanford University and the Authors. * 13 | * Authors: Peter Eastman * 14 | * Contributors: * 15 | * * 16 | * Permission is hereby granted, free of charge, to any person obtaining a * 17 | * copy of this software and associated documentation files (the "Software"), * 18 | * to deal in the Software without restriction, including without limitation * 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 20 | * and/or sell copies of the Software, and to permit persons to whom the * 21 | * Software is furnished to do so, subject to the following conditions: * 22 | * * 23 | * The above copyright notice and this permission notice shall be included in * 24 | * all copies or substantial portions of the Software. * 25 | * * 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 29 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 30 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 31 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 32 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 33 | * -------------------------------------------------------------------------- */ 34 | 35 | #include "RigidBodySystem.h" 36 | #include "openmm/Context.h" 37 | #include "openmm/Integrator.h" 38 | #include "openmm/Kernel.h" 39 | #include 40 | #include "internal/windowsExportRigidBody.h" 41 | 42 | namespace RigidBodyPlugin { 43 | 44 | /** 45 | * This is an Integrator which simulates a System of rigid bodies and free atoms using a symplectic, 46 | time-reversible, volume-preserving algorithm. 47 | */ 48 | 49 | class OPENMM_EXPORT_RIGIDBODY RigidBodyIntegrator : public OpenMM::Integrator { 50 | public: 51 | /** 52 | * Create a RigidBodyIntegrator. 53 | * 54 | * @param stepSize the integration step size (in picoseconds) 55 | * @param bodyIndices the index of the rigid body to which each atom belongs (0 = free atom) 56 | */ 57 | explicit RigidBodyIntegrator(double stepSize, const std::vector& bodyIndices); 58 | /** 59 | * Set the integration mode for rotations. 60 | * 61 | * @param mode the mode for solving rotations: 0 = exact (default); n = NO-SQUISH with n steps 62 | */ 63 | void setRotationMode(int mode); 64 | /** 65 | * Retrieve the employed integration mode for rotations. 66 | */ 67 | int getRotationMode() const { return rotationMode; } 68 | /** 69 | * Set the tag for computing refined energies. 70 | * 71 | * @param compute true if refined energies are to be computed 72 | */ 73 | void setComputeRefinedEnergies(bool compute); 74 | /** 75 | * Retrieve the tag for computing refined energies. 76 | */ 77 | bool getComputeRefinedEnergies() const { return computeRefinedEnergies; } 78 | /** 79 | * Advance a simulation through time by taking a series of time steps. 80 | * 81 | * @param steps the number of time steps to take 82 | */ 83 | void step(int steps); 84 | /** 85 | * Retrieve a vector of integers containing the rigid-body indices. 86 | */ 87 | std::vector getBodyIndices() const; 88 | /** 89 | * Pointer to the system of rigid bodies 90 | */ 91 | const RigidBodySystem& getRigidBodySystem() const { return bodySystem; } 92 | /** 93 | * Compute the different terms of the kinetic energy of the system at the current time. 94 | */ 95 | std::vector getKineticEnergies(); 96 | /** 97 | * Compute the translational and rotational terms of the refined kinetic energy. 98 | */ 99 | std::vector getRefinedKineticEnergies(); 100 | /** 101 | * Compute the potential energy refinement. 102 | */ 103 | double getPotentialEnergyRefinement(); 104 | protected: 105 | /** 106 | * This will be called by the Context when it is created. It informs the Integrator 107 | * of what context it will be integrating, and gives it a chance to do any necessary initialization. 108 | * It will also get called again if the application calls reinitialize() on the Context. 109 | */ 110 | void initialize(OpenMM::ContextImpl& context); 111 | /** 112 | * This will be called by the Context when it is destroyed to let the Integrator do any necessary 113 | * cleanup. It will also get called again if the application calls reinitialize() on the Context. 114 | */ 115 | void cleanup(); 116 | /** 117 | * Get the names of all Kernels used by this Integrator. 118 | */ 119 | std::vector getKernelNames(); 120 | /** 121 | * This will be called by the Context when the user modifies aspects of the context state, such 122 | * as positions, velocities, or parameters. 123 | * 124 | * @param changed this specifies what aspect of the Context was changed 125 | */ 126 | void stateChanged(State::DataType changed); 127 | /** 128 | * Compute the kinetic energy of the system at the current time. 129 | */ 130 | double computeKineticEnergy(); 131 | private: 132 | std::vector bodyIndices; 133 | RigidBodySystem bodySystem; 134 | OpenMM::Kernel kernel; 135 | int rotationMode; 136 | bool computeRefinedEnergies; 137 | }; 138 | 139 | } // namespace OpenMM 140 | 141 | #endif /*OPENMM_RIGIDBODYINTEGRATOR_H_*/ 142 | -------------------------------------------------------------------------------- /platforms/reference/src/ReferenceRigidBodyKernels.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- * 2 | * OpenMM * 3 | * -------------------------------------------------------------------------- * 4 | * This is part of the OpenMM molecular simulation toolkit originating from * 5 | * Simbios, the NIH National Center for Physics-Based Simulation of * 6 | * Biological Structures at Stanford, funded under the NIH Roadmap for * 7 | * Medical Research, grant U54 GM072970. See https://simtk.org. * 8 | * * 9 | * Portions copyright (c) 2014 Stanford University and the Authors. * 10 | * Authors: Peter Eastman * 11 | * Contributors: '' * 12 | * * 13 | * Permission is hereby granted, free of charge, to any person obtaining a * 14 | * copy of this software and associated documentation files (the "Software"), * 15 | * to deal in the Software without restriction, including without limitation * 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 17 | * and/or sell copies of the Software, and to permit persons to whom the * 18 | * Software is furnished to do so, subject to the following conditions: * 19 | * * 20 | * The above copyright notice and this permission notice shall be included in * 21 | * all copies or substantial portions of the Software. * 22 | * * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 26 | * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 27 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 29 | * USE OR OTHER DEALINGS IN THE SOFTWARE. * 30 | * -------------------------------------------------------------------------- */ 31 | 32 | #include "ReferenceRigidBodyKernels.h" 33 | #include "openmm/OpenMMException.h" 34 | #include "openmm/internal/ContextImpl.h" 35 | #include "openmm/reference/RealVec.h" 36 | #include "openmm/reference/ReferenceConstraints.h" 37 | #include "openmm/reference/ReferencePlatform.h" 38 | #include "openmm/reference/ReferenceVirtualSites.h" 39 | 40 | using namespace RigidBodyPlugin; 41 | using namespace OpenMM; 42 | using namespace std; 43 | 44 | static vector& extractPositions(ContextImpl& context) { 45 | ReferencePlatform::PlatformData* data = reinterpret_cast(context.getPlatformData()); 46 | return *((vector*) data->positions); 47 | } 48 | 49 | static vector& extractVelocities(ContextImpl& context) { 50 | ReferencePlatform::PlatformData* data = reinterpret_cast(context.getPlatformData()); 51 | return *((vector*) data->velocities); 52 | } 53 | 54 | static vector& extractForces(ContextImpl& context) { 55 | ReferencePlatform::PlatformData* data = reinterpret_cast(context.getPlatformData()); 56 | return *((vector*) data->forces); 57 | } 58 | 59 | static ReferenceConstraints& extractConstraints(ContextImpl& context) { 60 | ReferencePlatform::PlatformData* data = reinterpret_cast(context.getPlatformData()); 61 | return *(ReferenceConstraints*) data->constraints; 62 | } 63 | 64 | ReferenceIntegrateRigidBodyStepKernel::~ReferenceIntegrateRigidBodyStepKernel() { 65 | } 66 | 67 | void ReferenceIntegrateRigidBodyStepKernel::initialize(ContextImpl& context, const RigidBodyIntegrator& integrator) { 68 | const System& system = context.getSystem(); 69 | int numAtoms = system.getNumParticles(); 70 | invMass.resize(numAtoms); 71 | for (int i = 0; i < numAtoms; ++i) { 72 | double mass = system.getParticleMass(i); 73 | invMass[i] = mass == 0.0 ? 0.0 : 1.0/mass; 74 | } 75 | oldPos.resize(numAtoms); 76 | } 77 | 78 | void ReferenceIntegrateRigidBodyStepKernel::uploadBodySystem(RigidBodySystem& bodySystem) { 79 | this->bodySystem.copy(bodySystem); 80 | } 81 | 82 | void ReferenceIntegrateRigidBodyStepKernel::execute(ContextImpl& context, const RigidBodyIntegrator& integrator) { 83 | double dt = integrator.getStepSize(); 84 | double halfDt = 0.5*dt; 85 | double tol = integrator.getConstraintTolerance(); 86 | 87 | vector& R = extractPositions(context); 88 | vector& V = extractVelocities(context); 89 | vector& F = extractForces(context); 90 | ReferenceConstraints& constraints = extractConstraints(context); 91 | 92 | int numFree = bodySystem.getNumFree(); 93 | for (int k = 0; k < bodySystem.getNumFree(); k++) { 94 | int i = bodySystem.getAtomIndex(k); 95 | oldPos[i] = R[i]; 96 | } 97 | bodySystem.integratePart1(dt, F, V, R); 98 | if (numFree != 0) 99 | constraints.apply(oldPos, R, invMass, tol); 100 | ReferenceVirtualSites::computePositions(context.getSystem(), R); 101 | context.calcForcesAndEnergy(true, false); 102 | bodySystem.integratePart2(dt, R, F, V); 103 | if (numFree != 0) 104 | constraints.applyToVelocities(R, V, invMass, tol); 105 | 106 | data.time += dt; 107 | data.stepCount++; 108 | } 109 | 110 | double ReferenceIntegrateRigidBodyStepKernel::computeKineticEnergy(ContextImpl& context, const RigidBodyIntegrator& integrator) { 111 | vector& V = extractVelocities(context); 112 | bodySystem.computeKineticEnergies(V); 113 | return bodySystem.getKineticEnergy(); 114 | } 115 | 116 | vector ReferenceIntegrateRigidBodyStepKernel::getKineticEnergies(const RigidBodyIntegrator& integrator) { 117 | vector KE(2); 118 | KE[0] = bodySystem.getTranslationalEnergy(); 119 | KE[1] = bodySystem.getRotationalEnergy(); 120 | return KE; 121 | } 122 | 123 | vector ReferenceIntegrateRigidBodyStepKernel::getRefinedKineticEnergies(const RigidBodyIntegrator& integrator) { 124 | vector KE(2); 125 | KE[0] = bodySystem.getTranslationalEnergy(); 126 | KE[1] = bodySystem.getRotationalEnergy(); 127 | return KE; 128 | } 129 | 130 | double ReferenceIntegrateRigidBodyStepKernel::getPotentialEnergyRefinement(const RigidBodyIntegrator& integrator) { 131 | return 0.0; 132 | } 133 | -------------------------------------------------------------------------------- /python/forcefield.py: -------------------------------------------------------------------------------- 1 | %pythoncode %{ 2 | 3 | class ForceField(app.ForceField): 4 | def __init__(self, *files): 5 | super(ForceField, self).__init__(*files) 6 | self._bodyTemplates = {} 7 | 8 | class _bodyTemplateData(object): 9 | """Inner class used to encapsulate data about a rigid body template definition.""" 10 | def __init__(self, residue, pattern, virtualSites): 11 | self.residue = residue 12 | self.pattern = pattern 13 | self.virtualSites = virtualSites 14 | 15 | def __str__(self): 16 | return "%s: [%s]" % (self.residue, " ".join(self.atoms)) 17 | 18 | def getBodyTemplate(self, name): 19 | return self._bodyTemplates[name] 20 | 21 | def registerBodyTemplate(self, name, residue, pattern='.+'): 22 | """Register a new rigid body template. 23 | 24 | Parameters 25 | ---------- 26 | name : string 27 | A name for the rigid body template being registered. 28 | residue : string 29 | The name of the residue template to which this body belongs. 30 | pattern : string='.+' 31 | A string containing a regular expression for selecting the atoms in residue which will 32 | form the body. A list of atom names can be passed as '(name1|name2|...)', for instance. 33 | Only actual atoms will be considered (i.e. virtual sites will be ignored). If patttern 34 | is None, then the whole residue will form the rigid body. 35 | 36 | """ 37 | if name in self._bodyTemplates: 38 | raise ValueError('A rigid body template named %s has already been registered.' % name) 39 | if residue not in self._templates: 40 | raise ValueError('Unknown residue %s in rigid body registration.' % residue) 41 | template = self._templates[residue] 42 | allAtoms = [a.name for a in template.atoms] 43 | virtualSites = set(allAtoms[vs.index] for vs in template.virtualSites) 44 | self._bodyTemplates[name] = self._bodyTemplateData(residue, pattern, virtualSites) 45 | 46 | def _disjointSets(self, sets): 47 | new = [] 48 | mixed = set() 49 | for s in sets: 50 | if s.isdisjoint(mixed): 51 | new.append(s) 52 | else: 53 | i = 0 54 | while s.isdisjoint(new[i]): 55 | i += 1 56 | new[i] = new[i].union(s) 57 | mixed = mixed.union(s) 58 | return new if sum([len(n) for n in new]) == len(mixed) else self._disjointSets(new) 59 | 60 | 61 | def resolveBodies(self, topology, merge=None): 62 | """For each atom in topology, determine the index of the rigid body to which it belongs 63 | (an index 0 means that the atom does not belong to any body). 64 | 65 | Parameters 66 | ---------- 67 | topology : Topology 68 | The Topology for which to resolve the rigid body indices. 69 | merge : list of list(int)=None 70 | A nested list of indices of rigid bodies to be merged together after the templates are 71 | applied. If this is None, then no merging will happen. 72 | 73 | Returns 74 | ------- 75 | list(int) 76 | the newly created list of rigid body indices. 77 | 78 | """ 79 | index = [0 for i in range(topology.getNumAtoms())] 80 | bodies = self._bodyTemplates.values() 81 | n = 0 82 | for res in topology.residues(): 83 | for body in filter(lambda x: x.residue == res.name, bodies): 84 | n += 1 85 | inBody = lambda x: x not in body.virtualSites and re.match(body.pattern, x) 86 | atoms = [atom for atom in res.atoms() if inBody(atom.name)] 87 | if atoms: 88 | for atom in atoms: 89 | index[atom.index] = n 90 | else: 91 | raise ValueError('no atom in residue %s matches pattern %s' % (res.name, body.pattern)) 92 | 93 | if merge is not None: 94 | if not hasattr(merge, '__iter__'): 95 | raise ValueError('merge parameter is not a sequence') 96 | if all(hasattr(a, '__iter__') for a in merge): 97 | mergeSets = self._disjointSets([set(a) for a in merge]) 98 | else: 99 | mergeSets = [set(merge)] 100 | newIndex = [min(a) for a in mergeSets] 101 | for (i, body) in enumerate(index): 102 | for (j, s) in enumerate(mergeSets): 103 | if body in s: 104 | index[i] = newIndex[j] 105 | return index 106 | 107 | def _intraBodyPairs(self, bodyIndices): 108 | head = [-1]*max(bodyIndices) 109 | next = [-1]*len(bodyIndices) 110 | for i in range(len(bodyIndices)): 111 | if bodyIndices[i] != 0: 112 | next[i] = head[bodyIndices[i]-1] 113 | head[bodyIndices[i]-1] = i 114 | pairs = list() 115 | for k in filter(lambda x: x != -1, head): 116 | i = k 117 | while (i != -1): 118 | j = next[i] 119 | while (j != -1): 120 | pairs.append((i, j)) 121 | j = next[j] 122 | i = next[i] 123 | return pairs 124 | 125 | def removeConstraints(self, system, bodyIndices): 126 | for i in reversed(range(system.getNumConstraints())): 127 | (atom1, atom2, distance) = system.getConstraintParameters(i) 128 | if bodyIndices[atom1] != 0 or bodyIndices[atom2] != 0: 129 | system.removeConstraint(i) 130 | 131 | def removeForces(self, system, bodyIndices): 132 | def isNonbonded(force): 133 | return isinstance(force, (mm.NonbondedForce, mm.CustomNonbondedForce)) 134 | forces = [system.getForce(i) for i in range(system.getNumForces())] 135 | nonbondedForces = [f for f in forces if isNonbonded(f)] 136 | for (i, j) in self._intraBodyPairs(bodyIndices): 137 | for force in nonbondedForces: 138 | force.addException(i, j, 0, 1, 0, replace=True) 139 | 140 | def createSystem(self, topology, **kwargs): 141 | """Construct an OpenMM System representing a Topology with this force field. 142 | This extends the original method by creating rigid bodies from previously 143 | registered body templates. 144 | 145 | Parameters 146 | ---------- 147 | topology : Topology 148 | The Topology for which to create a System 149 | kwargs : Multiple types 150 | All keyword arguments of the original OpenMM's `ForceField.createSystem` method. 151 | mergeList : list(list(int))=None 152 | A nested list of indices of rigid bodies to be merged together after the templates 153 | are applied. If this is None, then no merging will occur. 154 | removeConstraints : bool=False 155 | If true, every constraint involving at least one atom that belongs to a rigid body 156 | will be silently removed from the system. 157 | removeForces : bool=False 158 | If true, all interactions whose all involved atoms belong to the same rigid body 159 | will be silently removed from the system. 160 | 161 | Returns 162 | ------- 163 | system : System 164 | the newly created System 165 | bodyIndices : list(int) 166 | a list with the index of each atom's rigid body (index=0 for free atoms) 167 | 168 | """ 169 | mergeList = kwargs.pop('mergeList', None) 170 | removeForces = kwargs.pop('removeForces', False) 171 | removeConstraints = kwargs.pop('removeConstraints', False) 172 | system = super(ForceField, self).createSystem(topology, **kwargs) 173 | bodyIndices = self.resolveBodies(topology, merge=mergeList) 174 | if removeConstraints: 175 | self.removeConstraints(system, bodyIndices) 176 | if removeForces: 177 | self.removeForces(system, bodyIndices) 178 | return (system, bodyIndices) 179 | 180 | %} 181 | -------------------------------------------------------------------------------- /platforms/cuda/src/kernels/elliptic.cu: -------------------------------------------------------------------------------- 1 | #include "float.h" 2 | 3 | #define SIGN(x) ((x) >= 0 ? 1 : -1) 4 | 5 | #ifdef USE_MIXED_PRECISION 6 | # define NaN nan("0") 7 | # define EPSILON DBL_EPSILON 8 | # define MAXREAL DBL_MAX 9 | # define MINREAL DBL_MIN 10 | # define errtol 0.001 11 | #else 12 | # define NaN nanf("0") 13 | # define EPSILON FLT_EPSILON 14 | # define MAXREAL FLT_MAX 15 | # define MINREAL FLT_MIN 16 | # define errtol 0.03 17 | #endif 18 | 19 | /*-------------------------------------------------------------------------------------------------- 20 | --------------------------------------------------------------------------------------------------*/ 21 | 22 | inline __device__ void jacobi(mixed u, mixed m, mixed& sn, mixed& cn, mixed& dn) 23 | { 24 | if (fabs(m) > 1.0) 25 | sn = cn = dn = NaN; 26 | else if(fabs(m) < 2.0*EPSILON) { 27 | sn = sin(u); 28 | cn = cos(u); 29 | dn = 1.0; 30 | } 31 | else if (fabs(m - 1.0) < 2.0*EPSILON) { 32 | sn = tanh(u); 33 | cn = 1.0/cosh(u); 34 | dn = cn; 35 | } 36 | else { 37 | const int N = 16; 38 | mixed mu[16]; 39 | mixed nu[16]; 40 | mixed c[16]; 41 | mixed d[16]; 42 | mixed sin_umu, cos_umu, t, r; 43 | int n = 0; 44 | mu[0] = 1.0; 45 | nu[0] = sqrt(1.0 - m); 46 | while ( fabs(mu[n] - nu[n]) > 4.0 * EPSILON * fabs(mu[n]+nu[n])) { 47 | mu[n+1] = 0.5 * (mu[n] + nu[n]); 48 | nu[n+1] = sqrt(mu[n] * nu[n]); 49 | ++n; 50 | if (n >= N - 1) { 51 | sn = cn = dn = NaN; 52 | return; 53 | } 54 | } 55 | sin_umu = sin(u * mu[n]); 56 | cos_umu = cos(u * mu[n]); 57 | /* Since sin(u*mu(n)) can be zero we switch to computing sn(K-u), 58 | cn(K-u), dn(K-u) when |sin| < |cos| */ 59 | if (fabs(sin_umu) < fabs(cos_umu)) { 60 | t = sin_umu / cos_umu; 61 | c[n] = mu[n] * t; 62 | d[n] = 1.0; 63 | while(n > 0) { 64 | n--; 65 | c[n] = d[n+1] * c[n+1]; 66 | r = (c[n+1] * c[n+1]) / mu[n+1]; 67 | d[n] = (r + nu[n]) / (r + mu[n]); 68 | } 69 | dn = sqrt(1.0-m) / d[n]; 70 | cn = (dn) * SIGN(cos_umu) / hypot(1.0, c[n]); 71 | sn = (cn) * c[n] /sqrt(1.0-m); 72 | } 73 | else { 74 | t = cos_umu / sin_umu; 75 | c[n] = mu[n] * t; 76 | d[n] = 1.0; 77 | while (n > 0) { 78 | --n; 79 | c[n] = d[n+1] * c[n+1]; 80 | r = (c[n+1] * c[n+1]) / mu[n+1]; 81 | d[n] = (r + nu[n]) / (r + mu[n]); 82 | } 83 | dn = d[n]; 84 | sn = SIGN(sin_umu) / hypot(1.0, c[n]); 85 | cn = c[n] * (sn); 86 | } 87 | } 88 | } 89 | 90 | /*-------------------------------------------------------------------------------------------------- 91 | --------------------------------------------------------------------------------------------------*/ 92 | 93 | inline __device__ mixed carlsonRC(mixed x, mixed y) 94 | { 95 | const mixed lolim = 5.0 * MINREAL; 96 | const mixed uplim = 0.2 * MAXREAL; 97 | const int nmax = 10000; 98 | if (x < 0.0 || y < 0.0 || x + y < lolim) 99 | return NaN; 100 | else if (max(x, y) < uplim) { 101 | const mixed c1 = 1.0 / 7.0; 102 | const mixed c2 = 9.0 / 22.0; 103 | mixed xn = x; 104 | mixed yn = y; 105 | mixed mu, sn, lamda, s; 106 | int n = 0; 107 | while (1) { 108 | mu = (xn + yn + yn) / 3.0; 109 | sn = (yn + mu) / mu - 2.0; 110 | if (fabs(sn) < errtol) break; 111 | lamda = 2.0 * sqrt(xn) * sqrt(yn) + yn; 112 | xn = (xn + lamda) * 0.25; 113 | yn = (yn + lamda) * 0.25; 114 | n++; 115 | if (n==nmax) return NaN; 116 | } 117 | s = sn * sn * (0.3 + sn * (c1 + sn * (0.375 + sn * c2))); 118 | return (1.0 + s) / sqrt(mu); 119 | } 120 | else 121 | return NaN; 122 | } 123 | 124 | /*-------------------------------------------------------------------------------------------------- 125 | --------------------------------------------------------------------------------------------------*/ 126 | 127 | inline __device__ mixed carlsonRF(mixed x, mixed y, mixed z) 128 | { 129 | const mixed lolim = 5.0 * MINREAL; 130 | const mixed uplim = 0.2 * MAXREAL; 131 | const int nmax = 10000; 132 | if (x < 0.0 || y < 0.0 || z < 0.0) 133 | return NaN; 134 | else if (x+y < lolim || x+z < lolim || y+z < lolim) 135 | return NaN; 136 | else if (max(x,max(y,z)) < uplim) { 137 | const mixed c1 = 1.0 / 24.0; 138 | const mixed c2 = 3.0 / 44.0; 139 | const mixed c3 = 1.0 / 14.0; 140 | mixed xn = x; 141 | mixed yn = y; 142 | mixed zn = z; 143 | mixed mu, xndev, yndev, zndev, e2, e3, s; 144 | int n = 0; 145 | while (1) { 146 | mixed epslon, lamda; 147 | mixed xnroot, ynroot, znroot; 148 | mu = (xn + yn + zn) / 3.0; 149 | xndev = 2.0 - (mu + xn) / mu; 150 | yndev = 2.0 - (mu + yn) / mu; 151 | zndev = 2.0 - (mu + zn) / mu; 152 | epslon = max(fabs(xndev), max(fabs(yndev), fabs(zndev))); 153 | if (epslon < errtol) break; 154 | xnroot = sqrt(xn); 155 | ynroot = sqrt(yn); 156 | znroot = sqrt(zn); 157 | lamda = xnroot * (ynroot + znroot) + ynroot * znroot; 158 | xn = (xn + lamda) * 0.25; 159 | yn = (yn + lamda) * 0.25; 160 | zn = (zn + lamda) * 0.25; 161 | n++; 162 | if (n == nmax) return NaN; 163 | } 164 | e2 = xndev * yndev - zndev * zndev; 165 | e3 = xndev * yndev * zndev; 166 | s = 1.0 + (c1 * e2 - 0.1 - c2 * e3) * e2 + c3 * e3; 167 | return s / sqrt(mu); 168 | } 169 | else 170 | return NaN; 171 | } 172 | 173 | /*-------------------------------------------------------------------------------------------------- 174 | --------------------------------------------------------------------------------------------------*/ 175 | 176 | inline __device__ mixed carlsonRJ(mixed x, mixed y, mixed z, mixed p) 177 | { 178 | const mixed lolim = pow(5.0*MINREAL, 1.0/3.0); 179 | const mixed uplim = 0.3*pow(0.2*MAXREAL, 1.0/3.0); 180 | const int nmax = 10000; 181 | if (x < 0.0 || y < 0.0 || z < 0.0) 182 | return NaN; 183 | else if (x + y < lolim || x + z < lolim || y + z < lolim || p < lolim) 184 | return NaN; 185 | else if (max(max(x,y),max(z,p)) < uplim) { 186 | const mixed c1 = 3.0 / 14.0; 187 | const mixed c2 = 1.0 / 3.0; 188 | const mixed c3 = 3.0 / 22.0; 189 | const mixed c4 = 3.0 / 26.0; 190 | mixed xn = x; 191 | mixed yn = y; 192 | mixed zn = z; 193 | mixed pn = p; 194 | mixed sigma = 0.0; 195 | mixed power4 = 1.0; 196 | mixed mu, xndev, yndev, zndev, pndev; 197 | mixed ea, eb, ec, e2, e3, s1, s2, s3; 198 | int n = 0; 199 | while(1) { 200 | mixed xnroot, ynroot, znroot; 201 | mixed lamda, alfa, beta; 202 | mixed epslon; 203 | mu = (xn + yn + zn + pn + pn) * 0.2; 204 | xndev = (mu - xn) / mu; 205 | yndev = (mu - yn) / mu; 206 | zndev = (mu - zn) / mu; 207 | pndev = (mu - pn) / mu; 208 | epslon = max(max(fabs(xndev), fabs(yndev)), max(fabs(zndev), fabs(pndev))); 209 | if (epslon < errtol) break; 210 | xnroot = sqrt(xn); 211 | ynroot = sqrt(yn); 212 | znroot = sqrt(zn); 213 | lamda = xnroot * (ynroot + znroot) + ynroot * znroot; 214 | alfa = pn * (xnroot + ynroot + znroot) + xnroot * ynroot * znroot; 215 | alfa = alfa * alfa; 216 | beta = pn * (pn + lamda) * (pn + lamda); 217 | mixed rc = carlsonRC(alfa, beta); 218 | if (isnan(rc)) return NaN; 219 | sigma += power4 * rc; 220 | power4 *= 0.25; 221 | xn = (xn + lamda) * 0.25; 222 | yn = (yn + lamda) * 0.25; 223 | zn = (zn + lamda) * 0.25; 224 | pn = (pn + lamda) * 0.25; 225 | n++; 226 | if (n == nmax) return NaN; 227 | } 228 | ea = xndev * (yndev + zndev) + yndev * zndev; 229 | eb = xndev * yndev * zndev; 230 | ec = pndev * pndev; 231 | e2 = ea - 3.0 * ec; 232 | e3 = eb + 2.0 * pndev * (ea - ec); 233 | s1 = 1.0 + e2 * (- c1 + 0.75 * c3 * e2 - 1.5 * c4 * e3); 234 | s2 = eb * (0.5 * c2 + pndev * (- c3 - c3 + pndev * c4)); 235 | s3 = pndev * ea * (c2 - pndev * c3) - c2 * pndev * ec; 236 | return 3.0 * sigma + power4 * (s1 + s2 + s3) / (mu * sqrt(mu)); 237 | } 238 | else 239 | return NaN; 240 | } 241 | 242 | /*-------------------------------------------------------------------------------------------------- 243 | --------------------------------------------------------------------------------------------------*/ 244 | 245 | inline __device__ mixed Omega(mixed x, mixed n, mixed m) { 246 | mixed x2 = x*x; 247 | return (-1.0/3.0)*n*x*x2*carlsonRJ(1.0 - x2, 1.0 - m*x2, 1.0, 1.0 + n*x2); 248 | } 249 | -------------------------------------------------------------------------------- /openmmapi/src/RigidBodySystem.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------------------------- * 2 | * OpenMM Rigid Body Plugin * 3 | * ---------------------------------------------------------------------------------------------- */ 4 | 5 | #include "RigidBodySystem.h" 6 | #include "internal/MatVec.h" 7 | #include "openmm/Vec3.h" 8 | #include "openmm/System.h" 9 | #include "openmm/OpenMMException.h" 10 | #include "openmm/internal/ContextImpl.h" 11 | #include "internal/eigenDecomposition.h" 12 | #include 13 | #include 14 | #include 15 | 16 | #include // TEMPORARY 17 | 18 | using namespace RigidBodyPlugin; 19 | using namespace OpenMM; 20 | using std::vector; 21 | 22 | /*-------------------------------------------------------------------------------------------------- 23 | Create a clean list of rigid body indices. The rule is: if bodyIndices[i] <= 0 or is unique, then 24 | index[i] = 0. Otherwise, 1 <= index[i] <= number of distinct positive entries which are 25 | non-unique. 26 | --------------------------------------------------------------------------------------------------*/ 27 | 28 | vector cleanBodyIndices(const vector& bodyIndices) { 29 | int listSize = bodyIndices.size(); 30 | int maxIndex = *std::max_element(std::begin(bodyIndices), std::end(bodyIndices)); 31 | vector head(maxIndex, -1), next(listSize, -1), index(listSize, 0); 32 | for (int i = 0; i < listSize; i++) 33 | if (bodyIndices[i] > 0) { 34 | next[i] = head[bodyIndices[i]-1]; 35 | head[bodyIndices[i]-1] = i; 36 | } 37 | int body = 0; 38 | for (int i = 0; i < maxIndex; i++) { 39 | int j = head[i]; 40 | if (j != -1) { 41 | body++; 42 | while (j != -1) { 43 | index[j] = body; 44 | j = next[j]; 45 | } 46 | } 47 | } 48 | return index; 49 | } 50 | 51 | /*-------------------------------------------------------------------------------------------------- 52 | Create a data structure for the system of rigid bodies and free atoms. 53 | --------------------------------------------------------------------------------------------------*/ 54 | 55 | void RigidBodySystem::initialize(ContextImpl& context, const vector& bodyIndices, int rotationMode) { 56 | bodyIndex = cleanBodyIndices(bodyIndices); 57 | this->rotationMode = rotationMode; 58 | 59 | numBodies = 0; 60 | for (auto index : bodyIndex) 61 | numBodies = std::max(numBodies, index); 62 | 63 | const System& system = context.getSystem(); 64 | int numAtoms = system.getNumParticles(); 65 | numActualAtoms = numAtoms; 66 | for (int i = 0; i < numAtoms; i++) 67 | if (system.isVirtualSite(i)) 68 | numActualAtoms--; 69 | atomIndex.resize(numActualAtoms); 70 | 71 | numFree = 0; 72 | body.resize(numBodies); 73 | for (int i = 0; i < numAtoms; i++) 74 | if (!(system.isVirtualSite(i) || system.getParticleMass(i) == 0.0)) { 75 | int ibody = bodyIndex[i]; 76 | if (ibody == 0) 77 | atomIndex[numFree++] = i; 78 | else 79 | body[ibody-1].N++; 80 | } 81 | numBodyAtoms = numActualAtoms - numFree; 82 | bodyFixedPositions.resize(numBodyAtoms); 83 | 84 | freeAtom.resize(numFree); 85 | int loc = 0; 86 | for (auto& a : freeAtom) { 87 | a.index = atomIndex[loc++]; 88 | a.invMass = 1.0/system.getParticleMass(a.index); 89 | } 90 | 91 | loc = 0; 92 | for (auto& b : body) { 93 | b.loc = loc; 94 | b.atom = &atomIndex[numFree+loc]; 95 | b.d = &bodyFixedPositions[loc]; 96 | loc += b.N; 97 | } 98 | 99 | vector iatom(numBodies, 0); 100 | for (int i = 0; i < numAtoms; i++) { 101 | int ibody = bodyIndex[i]; 102 | if (ibody > 0) { 103 | body[ibody-1].atom[iatom[ibody-1]++] = i; 104 | } 105 | } 106 | 107 | for (int i = 0; i < system.getNumConstraints(); i++) { 108 | int atom1, atom2; 109 | double distance; 110 | system.getConstraintParameters(i, atom1, atom2, distance); 111 | if (bodyIndex[atom1] != 0 || bodyIndex[atom2] != 0) 112 | throw OpenMMException("Constraints involving rigid-body atoms are not allowed"); 113 | } 114 | } 115 | 116 | /*-------------------------------------------------------------------------------------------------- 117 | Update the kinematic properties of all rigid bodies. 118 | --------------------------------------------------------------------------------------------------*/ 119 | 120 | void RigidBodySystem::update(ContextImpl& context, bool geometry, bool velocities) { 121 | const System& system = context.getSystem(); 122 | int N = system.getNumParticles(); 123 | vector M(N); 124 | for (int i = 0; i < N; i++) 125 | M[i] = system.getParticleMass(i); 126 | if (geometry) { 127 | vector R(N), F(N); 128 | context.getPositions(R); 129 | context.getForces(F); 130 | numDOF = numFree - system.getNumConstraints(); 131 | for (auto& b : body) { 132 | b.buildGeometry(R, F, M); 133 | numDOF += b.dof; 134 | } 135 | } 136 | if (velocities) { 137 | vector V(N); 138 | context.getVelocities(V); 139 | for (auto& b : body) 140 | b.buildDynamics(V, M); 141 | } 142 | } 143 | 144 | /*-------------------------------------------------------------------------------------------------- 145 | Copy structure from another rigid body system. 146 | --------------------------------------------------------------------------------------------------*/ 147 | 148 | void RigidBodySystem::copy(const RigidBodySystem& bodySystem) { 149 | rotationMode = bodySystem.rotationMode; 150 | numFree = bodySystem.numFree; 151 | numBodies = bodySystem.numBodies; 152 | numActualAtoms = bodySystem.numActualAtoms; 153 | numBodyAtoms = bodySystem.numBodyAtoms; 154 | numDOF = bodySystem.numDOF; 155 | bodyIndex = bodySystem.bodyIndex; 156 | atomIndex = bodySystem.atomIndex; 157 | bodyFixedPositions = bodySystem.bodyFixedPositions; 158 | freeAtom = bodySystem.freeAtom; 159 | body = bodySystem.body; 160 | for (auto& b : body) { 161 | b.atom = &atomIndex[numFree+b.loc]; 162 | b.d = &bodyFixedPositions[b.loc]; 163 | } 164 | } 165 | 166 | /*-------------------------------------------------------------------------------------------------- 167 | First part of rigid body NVE integration step. 168 | --------------------------------------------------------------------------------------------------*/ 169 | 170 | void RigidBodySystem::integratePart1(double dt, const vector& F, vector& V, vector& R) { 171 | double halfDt = 0.5*dt; 172 | for (auto& a : freeAtom) { 173 | V[a.index] += F[a.index]*a.invMass*halfDt; 174 | R[a.index] += V[a.index]*dt; 175 | a.savedPos = R[a.index]; 176 | } 177 | for (auto& b : body) { 178 | b.pcm += b.force*halfDt; 179 | b.pi += b.torque*dt; 180 | b.rcm += b.pcm*(b.invMass*dt); 181 | if (rotationMode == 0) 182 | b.exactRotation(dt); 183 | else 184 | b.noSquishRotation(dt, rotationMode); 185 | b.updateAtomicPositions(R); 186 | } 187 | } 188 | 189 | /*-------------------------------------------------------------------------------------------------- 190 | Second part of rigid body NVE integration step. 191 | --------------------------------------------------------------------------------------------------*/ 192 | 193 | void RigidBodySystem::integratePart2(double dt, const vector& R, const vector& F, vector& V) { 194 | double halfDt = 0.5*dt; 195 | double invDt = 1.0/dt; 196 | for (auto& a : freeAtom) 197 | V[a.index] += F[a.index]*a.invMass*halfDt + (R[a.index] - a.savedPos)*invDt; 198 | for (auto& b : body) { 199 | b.forceAndTorque(F); 200 | b.pcm += b.force*halfDt; 201 | b.pi += b.torque*dt; 202 | b.updateAtomicVelocities(V); 203 | } 204 | } 205 | 206 | /*-------------------------------------------------------------------------------------------------- 207 | Compute kinetic energy. 208 | --------------------------------------------------------------------------------------------------*/ 209 | 210 | void RigidBodySystem::computeKineticEnergies(const vector& V) { 211 | transKE = rotKE = 0.0; 212 | for (auto& a : freeAtom) 213 | transKE += V[a.index].dot(V[a.index])/a.invMass; 214 | for (auto& b : body) { 215 | transKE += b.twoKt; 216 | rotKE += b.twoKr; 217 | } 218 | transKE *= 0.5; 219 | rotKE *= 0.5; 220 | } 221 | -------------------------------------------------------------------------------- /platforms/cuda/src/kernels/vectorOps.cu: -------------------------------------------------------------------------------- 1 | /** 2 | * This file defines vector operations to simplify code elsewhere. 3 | */ 4 | 5 | // Versions of make_x() that take a single value and set all components to that. 6 | 7 | inline __device__ float3 make_float3(float a) { 8 | return make_float3(a, a, a); 9 | } 10 | 11 | inline __device__ float4 make_float4(float a) { 12 | return make_float4(a, a, a, a); 13 | } 14 | 15 | inline __device__ double3 make_double3(double a) { 16 | return make_double3(a, a, a); 17 | } 18 | 19 | inline __device__ double4 make_double4(double a) { 20 | return make_double4(a, a, a, a); 21 | } 22 | 23 | // Negate a vector. 24 | 25 | inline __device__ float3 operator-(float3 a) { 26 | return make_float3(-a.x, -a.y, -a.z); 27 | } 28 | 29 | inline __device__ float4 operator-(float4 a) { 30 | return make_float4(-a.x, -a.y, -a.z, -a.w); 31 | } 32 | 33 | inline __device__ double3 operator-(double3 a) { 34 | return make_double3(-a.x, -a.y, -a.z); 35 | } 36 | 37 | inline __device__ double4 operator-(double4 a) { 38 | return make_double4(-a.x, -a.y, -a.z, -a.w); 39 | } 40 | 41 | // Add two vectors. 42 | 43 | inline __device__ float3 operator+(float3 a, float3 b) { 44 | return make_float3(a.x+b.x, a.y+b.y, a.z+b.z); 45 | } 46 | 47 | inline __device__ float4 operator+(float4 a, float4 b) { 48 | return make_float4(a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w); 49 | } 50 | 51 | inline __device__ double3 operator+(double3 a, double3 b) { 52 | return make_double3(a.x+b.x, a.y+b.y, a.z+b.z); 53 | } 54 | 55 | inline __device__ double4 operator+(double4 a, double4 b) { 56 | return make_double4(a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w); 57 | } 58 | 59 | // Subtract two vectors. 60 | 61 | inline __device__ float3 operator-(float3 a, float3 b) { 62 | return make_float3(a.x-b.x, a.y-b.y, a.z-b.z); 63 | } 64 | 65 | inline __device__ float4 operator-(float4 a, float4 b) { 66 | return make_float4(a.x-b.x, a.y-b.y, a.z-b.z, a.w-b.w); 67 | } 68 | 69 | inline __device__ double3 operator-(double3 a, double3 b) { 70 | return make_double3(a.x-b.x, a.y-b.y, a.z-b.z); 71 | } 72 | 73 | inline __device__ double4 operator-(double4 a, double4 b) { 74 | return make_double4(a.x-b.x, a.y-b.y, a.z-b.z, a.w-b.w); 75 | } 76 | 77 | // Multiply two vectors. 78 | 79 | inline __device__ float3 operator*(float3 a, float3 b) { 80 | return make_float3(a.x*b.x, a.y*b.y, a.z*b.z); 81 | } 82 | 83 | inline __device__ float4 operator*(float4 a, float4 b) { 84 | return make_float4(a.x*b.x, a.y*b.y, a.z*b.z, a.w*b.w); 85 | } 86 | 87 | inline __device__ double3 operator*(double3 a, double3 b) { 88 | return make_double3(a.x*b.x, a.y*b.y, a.z*b.z); 89 | } 90 | 91 | inline __device__ double4 operator*(double4 a, double4 b) { 92 | return make_double4(a.x*b.x, a.y*b.y, a.z*b.z, a.w*b.w); 93 | } 94 | 95 | // Divide two vectors. 96 | 97 | inline __device__ float3 operator/(float3 a, float3 b) { 98 | return make_float3(a.x/b.x, a.y/b.y, a.z/b.z); 99 | } 100 | 101 | inline __device__ float4 operator/(float4 a, float4 b) { 102 | return make_float4(a.x/b.x, a.y/b.y, a.z/b.z, a.w/b.w); 103 | } 104 | 105 | inline __device__ double3 operator/(double3 a, double3 b) { 106 | return make_double3(a.x/b.x, a.y/b.y, a.z/b.z); 107 | } 108 | 109 | inline __device__ double4 operator/(double4 a, double4 b) { 110 | return make_double4(a.x/b.x, a.y/b.y, a.z/b.z, a.w/b.w); 111 | } 112 | 113 | // += operator 114 | 115 | inline __device__ void operator+=(float3& a, float3 b) { 116 | a.x += b.x; a.y += b.y; a.z += b.z; 117 | } 118 | 119 | inline __device__ void operator+=(float4& a, float4 b) { 120 | a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w; 121 | } 122 | 123 | inline __device__ void operator+=(double3& a, double3 b) { 124 | a.x += b.x; a.y += b.y; a.z += b.z; 125 | } 126 | 127 | inline __device__ void operator+=(double4& a, double4 b) { 128 | a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w; 129 | } 130 | 131 | // -= operator 132 | 133 | inline __device__ void operator-=(float3& a, float3 b) { 134 | a.x -= b.x; a.y -= b.y; a.z -= b.z; 135 | } 136 | 137 | inline __device__ void operator-=(float4& a, float4 b) { 138 | a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w; 139 | } 140 | 141 | inline __device__ void operator-=(double3& a, double3 b) { 142 | a.x -= b.x; a.y -= b.y; a.z -= b.z; 143 | } 144 | 145 | inline __device__ void operator-=(double4& a, double4 b) { 146 | a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w; 147 | } 148 | 149 | // *= operator 150 | 151 | inline __device__ void operator*=(float3& a, float3 b) { 152 | a.x *= b.x; a.y *= b.y; a.z *= b.z; 153 | } 154 | 155 | inline __device__ void operator*=(float4& a, float4 b) { 156 | a.x *= b.x; a.y *= b.y; a.z *= b.z; a.w *= b.w; 157 | } 158 | 159 | inline __device__ void operator*=(double3& a, double3 b) { 160 | a.x *= b.x; a.y *= b.y; a.z *= b.z; 161 | } 162 | 163 | inline __device__ void operator*=(double4& a, double4 b) { 164 | a.x *= b.x; a.y *= b.y; a.z *= b.z; a.w *= b.w; 165 | } 166 | 167 | // /= operator 168 | 169 | inline __device__ void operator/=(float3& a, float3 b) { 170 | a.x /= b.x; a.y /= b.y; a.z /= b.z; 171 | } 172 | 173 | inline __device__ void operator/=(float4& a, float4 b) { 174 | a.x /= b.x; a.y /= b.y; a.z /= b.z; a.w /= b.w; 175 | } 176 | 177 | inline __device__ void operator/=(double3& a, double3 b) { 178 | a.x /= b.x; a.y /= b.y; a.z /= b.z; 179 | } 180 | 181 | inline __device__ void operator/=(double4& a, double4 b) { 182 | a.x /= b.x; a.y /= b.y; a.z /= b.z; a.w /= b.w; 183 | } 184 | 185 | // Multiply a vector by a constant. 186 | 187 | inline __device__ float3 operator*(float3 a, float b) { 188 | return make_float3(a.x*b, a.y*b, a.z*b); 189 | } 190 | 191 | inline __device__ float4 operator*(float4 a, float b) { 192 | return make_float4(a.x*b, a.y*b, a.z*b, a.w*b); 193 | } 194 | 195 | inline __device__ double3 operator*(double3 a, double b) { 196 | return make_double3(a.x*b, a.y*b, a.z*b); 197 | } 198 | 199 | inline __device__ double4 operator*(double4 a, double b) { 200 | return make_double4(a.x*b, a.y*b, a.z*b, a.w*b); 201 | } 202 | 203 | // Divide a vector by a constant. 204 | 205 | inline __device__ float3 operator/(float3 a, float b) { 206 | float scale = 1.0f/b; 207 | return a*scale; 208 | } 209 | 210 | inline __device__ float4 operator/(float4 a, float b) { 211 | float scale = 1.0f/b; 212 | return a*scale; 213 | } 214 | 215 | inline __device__ double3 operator/(double3 a, double b) { 216 | double scale = 1.0/b; 217 | return a*scale; 218 | } 219 | 220 | inline __device__ double4 operator/(double4 a, double b) { 221 | double scale = 1.0/b; 222 | return a*scale; 223 | } 224 | 225 | // *= operator (multiply vector by constant) 226 | 227 | inline __device__ void operator*=(float3& a, float b) { 228 | a.x *= b; a.y *= b; a.z *= b; 229 | } 230 | 231 | inline __device__ void operator*=(float4& a, float b) { 232 | a.x *= b; a.y *= b; a.z *= b; a.w *= b; 233 | } 234 | 235 | inline __device__ void operator*=(double3& a, double b) { 236 | a.x *= b; a.y *= b; a.z *= b; 237 | } 238 | 239 | inline __device__ void operator*=(double4& a, double b) { 240 | a.x *= b; a.y *= b; a.z *= b; a.w *= b; 241 | } 242 | 243 | // Dot product 244 | 245 | inline __device__ float dot(float3 a, float3 b) { 246 | return a.x*b.x+a.y*b.y+a.z*b.z; 247 | } 248 | 249 | inline __device__ double dot(double3 a, double3 b) { 250 | return a.x*b.x+a.y*b.y+a.z*b.z; 251 | } 252 | 253 | inline __device__ float dot(float4 a, float4 b) { 254 | return a.x*b.x+a.y*b.y+a.z*b.z+a.w*b.w; 255 | } 256 | 257 | inline __device__ double dot(double4 a, double4 b) { 258 | return a.x*b.x+a.y*b.y+a.z*b.z+a.w*b.w; 259 | } 260 | 261 | // Cross product 262 | 263 | inline __device__ float3 cross(float3 a, float3 b) { 264 | return make_float3(a.y*b.z-a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x); 265 | } 266 | 267 | inline __device__ double3 cross(double3 a, double3 b) { 268 | return make_double3(a.y*b.z-a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x); 269 | } 270 | 271 | // Normalize a vector 272 | 273 | inline __device__ float3 normalize(float3 a) { 274 | return a*rsqrtf(a.x*a.x+a.y*a.y+a.z*a.z); 275 | } 276 | 277 | inline __device__ float4 normalize(float4 a) { 278 | return a*rsqrtf(a.x*a.x+a.y*a.y+a.z*a.z+a.w*a.w); 279 | } 280 | 281 | inline __device__ double3 normalize(double3 a) { 282 | return a*rsqrt(a.x*a.x+a.y*a.y+a.z*a.z); 283 | } 284 | 285 | inline __device__ double4 normalize(double4 a) { 286 | return a*rsqrt(a.x*a.x+a.y*a.y+a.z*a.z+a.w*a.w); 287 | } 288 | 289 | // Strip off the fourth component of a vector. 290 | 291 | inline __device__ float3 trim(float4 v) { 292 | return make_float3(v.x, v.y, v.z); 293 | } 294 | 295 | inline __device__ double3 trim(double4 v) { 296 | return make_double3(v.x, v.y, v.z); 297 | } 298 | 299 | // Add fourth component to a vector. 300 | 301 | inline __device__ float4 fuse(float3 v, float a) { 302 | return make_float4(v.x, v.y, v.z, a); 303 | } 304 | 305 | inline __device__ double4 fuse(double3 v, double a) { 306 | return make_double4(v.x, v.y, v.z, a); 307 | } 308 | -------------------------------------------------------------------------------- /cmake/Findcodecov.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of CMake-codecov. 2 | # 3 | # Copyright (c) 4 | # 2015-2017 RWTH Aachen University, Federal Republic of Germany 5 | # 6 | # See the LICENSE file in the package base directory for details 7 | # 8 | # Written by Alexander Haase, alexander.haase@rwth-aachen.de 9 | # 10 | 11 | 12 | # Add an option to choose, if coverage should be enabled or not. If enabled 13 | # marked targets will be build with coverage support and appropriate targets 14 | # will be added. If disabled coverage will be ignored for *ALL* targets. 15 | option(ENABLE_COVERAGE "Enable coverage build." OFF) 16 | 17 | set(COVERAGE_FLAG_CANDIDATES 18 | # gcc and clang 19 | "-O0 -g -fprofile-arcs -ftest-coverage" 20 | 21 | # gcc and clang fallback 22 | "-O0 -g --coverage" 23 | ) 24 | 25 | 26 | # Add coverage support for target ${TNAME} and register target for coverage 27 | # evaluation. If coverage is disabled or not supported, this function will 28 | # simply do nothing. 29 | # 30 | # Note: This function is only a wrapper to define this function always, even if 31 | # coverage is not supported by the compiler or disabled. This function must 32 | # be defined here, because the module will be exited, if there is no coverage 33 | # support by the compiler or it is disabled by the user. 34 | function (add_coverage TNAME) 35 | # only add coverage for target, if coverage is support and enabled. 36 | if (ENABLE_COVERAGE) 37 | foreach (TNAME ${ARGV}) 38 | add_coverage_target(${TNAME}) 39 | endforeach () 40 | endif () 41 | endfunction (add_coverage) 42 | 43 | 44 | # Add global target to gather coverage information after all targets have been 45 | # added. Other evaluation functions could be added here, after checks for the 46 | # specific module have been passed. 47 | # 48 | # Note: This function is only a wrapper to define this function always, even if 49 | # coverage is not supported by the compiler or disabled. This function must 50 | # be defined here, because the module will be exited, if there is no coverage 51 | # support by the compiler or it is disabled by the user. 52 | function (coverage_evaluate) 53 | # add lcov evaluation 54 | if (LCOV_FOUND) 55 | lcov_capture_initial() 56 | lcov_capture() 57 | endif (LCOV_FOUND) 58 | endfunction () 59 | 60 | 61 | # Exit this module, if coverage is disabled. add_coverage is defined before this 62 | # return, so this module can be exited now safely without breaking any build- 63 | # scripts. 64 | if (NOT ENABLE_COVERAGE) 65 | return() 66 | endif () 67 | 68 | 69 | 70 | 71 | # Find the required flags foreach language. 72 | set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET}) 73 | set(CMAKE_REQUIRED_QUIET ${codecov_FIND_QUIETLY}) 74 | 75 | get_property(ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES) 76 | foreach (LANG ${ENABLED_LANGUAGES}) 77 | # Coverage flags are not dependent on language, but the used compiler. So 78 | # instead of searching flags foreach language, search flags foreach compiler 79 | # used. 80 | set(COMPILER ${CMAKE_${LANG}_COMPILER_ID}) 81 | if (NOT COVERAGE_${COMPILER}_FLAGS) 82 | foreach (FLAG ${COVERAGE_FLAG_CANDIDATES}) 83 | if(NOT CMAKE_REQUIRED_QUIET) 84 | message(STATUS "Try ${COMPILER} code coverage flag = [${FLAG}]") 85 | endif() 86 | 87 | set(CMAKE_REQUIRED_FLAGS "${FLAG}") 88 | unset(COVERAGE_FLAG_DETECTED CACHE) 89 | 90 | if (${LANG} STREQUAL "C") 91 | include(CheckCCompilerFlag) 92 | check_c_compiler_flag("${FLAG}" COVERAGE_FLAG_DETECTED) 93 | 94 | elseif (${LANG} STREQUAL "CXX") 95 | include(CheckCXXCompilerFlag) 96 | check_cxx_compiler_flag("${FLAG}" COVERAGE_FLAG_DETECTED) 97 | 98 | elseif (${LANG} STREQUAL "Fortran") 99 | # CheckFortranCompilerFlag was introduced in CMake 3.x. To be 100 | # compatible with older Cmake versions, we will check if this 101 | # module is present before we use it. Otherwise we will define 102 | # Fortran coverage support as not available. 103 | include(CheckFortranCompilerFlag OPTIONAL 104 | RESULT_VARIABLE INCLUDED) 105 | if (INCLUDED) 106 | check_fortran_compiler_flag("${FLAG}" 107 | COVERAGE_FLAG_DETECTED) 108 | elseif (NOT CMAKE_REQUIRED_QUIET) 109 | message("-- Performing Test COVERAGE_FLAG_DETECTED") 110 | message("-- Performing Test COVERAGE_FLAG_DETECTED - Failed" 111 | " (Check not supported)") 112 | endif () 113 | endif() 114 | 115 | if (COVERAGE_FLAG_DETECTED) 116 | set(COVERAGE_${COMPILER}_FLAGS "${FLAG}" 117 | CACHE STRING "${COMPILER} flags for code coverage.") 118 | mark_as_advanced(COVERAGE_${COMPILER}_FLAGS) 119 | break() 120 | else () 121 | message(WARNING "Code coverage is not available for ${COMPILER}" 122 | " compiler. Targets using this compiler will be " 123 | "compiled without it.") 124 | endif () 125 | endforeach () 126 | endif () 127 | endforeach () 128 | 129 | set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE}) 130 | 131 | 132 | 133 | 134 | # Helper function to get the language of a source file. 135 | function (codecov_lang_of_source FILE RETURN_VAR) 136 | get_filename_component(FILE_EXT "${FILE}" EXT) 137 | string(TOLOWER "${FILE_EXT}" FILE_EXT) 138 | string(SUBSTRING "${FILE_EXT}" 1 -1 FILE_EXT) 139 | 140 | get_property(ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES) 141 | foreach (LANG ${ENABLED_LANGUAGES}) 142 | list(FIND CMAKE_${LANG}_SOURCE_FILE_EXTENSIONS "${FILE_EXT}" TEMP) 143 | if (NOT ${TEMP} EQUAL -1) 144 | set(${RETURN_VAR} "${LANG}" PARENT_SCOPE) 145 | return() 146 | endif () 147 | endforeach() 148 | 149 | set(${RETURN_VAR} "" PARENT_SCOPE) 150 | endfunction () 151 | 152 | 153 | # Helper function to get the relative path of the source file destination path. 154 | # This path is needed by FindGcov and FindLcov cmake files to locate the 155 | # captured data. 156 | function (codecov_path_of_source FILE RETURN_VAR) 157 | string(REGEX MATCH "TARGET_OBJECTS:([^ >]+)" _source ${FILE}) 158 | 159 | # If expression was found, SOURCEFILE is a generator-expression for an 160 | # object library. Currently we found no way to call this function automatic 161 | # for the referenced target, so it must be called in the directoryso of the 162 | # object library definition. 163 | if (NOT "${_source}" STREQUAL "") 164 | set(${RETURN_VAR} "" PARENT_SCOPE) 165 | return() 166 | endif () 167 | 168 | 169 | string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}/" "" FILE "${FILE}") 170 | if(IS_ABSOLUTE ${FILE}) 171 | file(RELATIVE_PATH FILE ${CMAKE_CURRENT_SOURCE_DIR} ${FILE}) 172 | endif() 173 | 174 | # get the right path for file 175 | string(REPLACE ".." "__" PATH "${FILE}") 176 | 177 | set(${RETURN_VAR} "${PATH}" PARENT_SCOPE) 178 | endfunction() 179 | 180 | 181 | 182 | 183 | # Add coverage support for target ${TNAME} and register target for coverage 184 | # evaluation. 185 | function(add_coverage_target TNAME) 186 | # Check if all sources for target use the same compiler. If a target uses 187 | # e.g. C and Fortran mixed and uses different compilers (e.g. clang and 188 | # gfortran) this can trigger huge problems, because different compilers may 189 | # use different implementations for code coverage. 190 | get_target_property(TSOURCES ${TNAME} SOURCES) 191 | set(TARGET_COMPILER "") 192 | set(ADDITIONAL_FILES "") 193 | foreach (FILE ${TSOURCES}) 194 | # If expression was found, FILE is a generator-expression for an object 195 | # library. Object libraries will be ignored. 196 | string(REGEX MATCH "TARGET_OBJECTS:([^ >]+)" _file ${FILE}) 197 | if ("${_file}" STREQUAL "") 198 | codecov_lang_of_source(${FILE} LANG) 199 | if (LANG) 200 | list(APPEND TARGET_COMPILER ${CMAKE_${LANG}_COMPILER_ID}) 201 | 202 | list(APPEND ADDITIONAL_FILES "${FILE}.gcno") 203 | list(APPEND ADDITIONAL_FILES "${FILE}.gcda") 204 | endif () 205 | endif () 206 | endforeach () 207 | 208 | list(REMOVE_DUPLICATES TARGET_COMPILER) 209 | list(LENGTH TARGET_COMPILER NUM_COMPILERS) 210 | 211 | if (NUM_COMPILERS GREATER 1) 212 | message(WARNING "Can't use code coverage for target ${TNAME}, because " 213 | "it will be compiled by incompatible compilers. Target will be " 214 | "compiled without code coverage.") 215 | return() 216 | 217 | elseif (NUM_COMPILERS EQUAL 0) 218 | message(WARNING "Can't use code coverage for target ${TNAME}, because " 219 | "it uses an unknown compiler. Target will be compiled without " 220 | "code coverage.") 221 | return() 222 | 223 | elseif (NOT DEFINED "COVERAGE_${TARGET_COMPILER}_FLAGS") 224 | # A warning has been printed before, so just return if flags for this 225 | # compiler aren't available. 226 | return() 227 | endif() 228 | 229 | 230 | # enable coverage for target 231 | set_property(TARGET ${TNAME} APPEND_STRING 232 | PROPERTY COMPILE_FLAGS " ${COVERAGE_${TARGET_COMPILER}_FLAGS}") 233 | set_property(TARGET ${TNAME} APPEND_STRING 234 | PROPERTY LINK_FLAGS " ${COVERAGE_${TARGET_COMPILER}_FLAGS}") 235 | 236 | 237 | # Add gcov files generated by compiler to clean target. 238 | set(CLEAN_FILES "") 239 | foreach (FILE ${ADDITIONAL_FILES}) 240 | codecov_path_of_source(${FILE} FILE) 241 | list(APPEND CLEAN_FILES "CMakeFiles/${TNAME}.dir/${FILE}") 242 | endforeach() 243 | 244 | set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES 245 | "${CLEAN_FILES}") 246 | 247 | 248 | add_gcov_target(${TNAME}) 249 | add_lcov_target(${TNAME}) 250 | endfunction(add_coverage_target) 251 | 252 | 253 | 254 | 255 | # Include modules for parsing the collected data and output it in a readable 256 | # format (like gcov and lcov). 257 | find_package(Gcov) 258 | find_package(Lcov) 259 | --------------------------------------------------------------------------------