Commit 27a2456b authored by Peter Eastman's avatar Peter Eastman
Browse files

Created a test case for StandardMMForceFieldImpl's findExclusions() method. ...

Created a test case for StandardMMForceFieldImpl's findExclusions() method.  Fixed some bugs that it found.  Created a CMake script and configured it for building and running test cases.
parent 6ddebdb2
INCLUDE(FindDoxygen)
IF(DOXYGEN_EXECUTABLE-NOTFOUND)
ELSE(DOXYGEN_EXECUTABLE-NOTFOUND)
SET(DOXY_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
${DOXY_CONFIG}
@ONLY )
ADD_CUSTOM_TARGET(DoxygenApiDocs ${DOXYGEN_EXECUTABLE} ${DOXY_CONFIG})
FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/html/")
INSTALL(DIRECTORY "${PROJECT_BINARY_DIR}/html/"
DESTINATION "core/doc/api/${PROJECT_NAME}/"
)
ENDIF(DOXYGEN_EXECUTABLE-NOTFOUND)
#---------------------------------------------------
# OpenMM
#
# Creates OpenMM library, base name=OpenMM.
# Default libraries are shared & optimized. Variants
# are created for static (_static) and debug (_d).
#
# Windows:
# OpenMM[_d].dll
# OpenMM[_d].lib
# OpenMM_static[_d].lib
# Unix:
# libOpenMM[_d].so
# libOpenMM_static[_d].a
#----------------------------------------------------
PROJECT (OpenMM)
SUBDIRS (tests)
ADD_DEFINITIONS(-DOPENMM_BUILDING_SHARED_LIBRARY)
# The source is organized into subdirectories, but we handle them all from
# this CMakeLists file rather than letting CMake visit them as SUBDIRS.
SET(OPENMM_SOURCE_SUBDIRS . openmmapi olla)
# The build system will set ARCH64 for 64 bit builds, which require
# use of the lib64/ library directories rather than lib/.
#SET( ARCH64 OFF CACHE BOOL "ON for 64bit builds, OFF for 32bit builds")
#MARK_AS_ADVANCED( ARCH64 )
#IF (ARCH64)
# SET(LIB64 64)
#ELSE (ARCH64)
# SET(LIB64) # nothing
#ENDIF (ARCH64)
IF( ${CMAKE_SIZEOF_VOID_P} EQUAL 8 )
SET( LIB64 64 )
ELSE( ${CMAKE_SIZEOF_VOID_P} EQUAL 8 )
SET( LIB64 )
ENDIF( ${CMAKE_SIZEOF_VOID_P} EQUAL 8 )
IF(UNIX AND NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Debug or Release build" FORCE)
ENDIF (UNIX AND NOT CMAKE_BUILD_TYPE)
IF (NOT CMAKE_CXX_FLAGS_DEBUG)
SET(CMAKE_CXX_FLAGS_DEBUG "-g" CACHE STRING "To use when CMAKE_BUILD_TYPE=Debug" FORCE)
ENDIF (NOT CMAKE_CXX_FLAGS_DEBUG)
IF (NOT CMAKE_CXX_FLAGS_RELEASE)
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING
"To use when CMAKE_BUILD_TYPE=Release" FORCE)
ENDIF (NOT CMAKE_CXX_FLAGS_RELEASE)
# Collect up information about the version of the simbody library we're building
# and make it available to the code so it can be built into the binaries.
SET(OPENMM_LIBRARY_NAME OpenMM)
SET(OPENMM_MAJOR_VERSION 1)
SET(OPENMM_MINOR_VERSION 0)
SET(OPENMM_BUILD_VERSION 0)
SET(OPENMM_COPYRIGHT_YEARS "2008")
# underbar separated list of dotted authors, no spaces or commas
SET(OPENMM_AUTHORS "Peter.Eastman")
# Get the subversion revision number if we can
# It's possible that WIN32 installs use svnversion through cygwin
# so we'll try for both svnversion.exe and svnversion. Note that
# this will result in warnings if all you have is Tortoise without
# Cygwin, and your "about" string will say "unknown" rather than
# providing the SVN version of the source.
FIND_PROGRAM (SVNVERSION_EXE svnversion.exe)
IF (SVNVERSION_EXE)
EXEC_PROGRAM (${SVNVERSION_EXE}
ARGS \"${PROJECT_SOURCE_DIR}\"
OUTPUT_VARIABLE OPENMM_SVN_REVISION )
ELSE (SVNVERSION_EXE)
FIND_PROGRAM (SVNVERSION svnversion)
IF (SVNVERSION)
EXEC_PROGRAM (${SVNVERSION}
ARGS "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE OPENMM_SVN_REVISION)
ELSE (SVNVERSION)
MESSAGE (STATUS
"Could not find 'svnversion' executable; 'about' will be wrong. (Cygwin provides one on Windows.)"
)
SET (OPENMM_SVN_REVISION unknown)
ENDIF (SVNVERSION)
ENDIF (SVNVERSION_EXE)
# Remove colon from build version, for easier placement in directory names
STRING(REPLACE ":" "_" OPENMM_SVN_REVISION ${OPENMM_SVN_REVISION})
ADD_DEFINITIONS(-DOPENMM_LIBRARY_NAME=${OPENMM_LIBRARY_NAME}
-DOPENMM_MAJOR_VERSION=${OPENMM_MAJOR_VERSION}
-DOPENMM_MINOR_VERSION=${OPENMM_MINOR_VERSION}
-DOPENMM_BUILD_VERSION=${OPENMM_BUILD_VERSION})
# CMake quotes automatically when building Visual Studio projects but we need
# to add them ourselves for Linux or Cygwin. Two cases to avoid duplicate quotes
# in Visual Studio which end up in the binary.
IF (${CMAKE_GENERATOR} MATCHES "Visual Studio")
SET(NEED_QUOTES FALSE)
ELSE (${CMAKE_GENERATOR} MATCHES "Visual Studio")
SET(NEED_QUOTES TRUE)
ENDIF (${CMAKE_GENERATOR} MATCHES "Visual Studio")
##TODO: doesn't work without quotes in nightly build
SET(NEED_QUOTES TRUE)
IF(NEED_QUOTES)
ADD_DEFINITIONS(-DOPENMM_SVN_REVISION="${OPENMM_SVN_REVISION}"
-DOPENMM_COPYRIGHT_YEARS="${OPENMM_COPYRIGHT_YEARS}"
-DOPENMM_AUTHORS="${OPENMM_AUTHORS}")
ELSE(NEED_QUOTES)
ADD_DEFINITIONS(-DOPENMM_SVN_REVISION=${OPENMM_SVN_REVISION}
-DOPENMM_COPYRIGHT_YEARS=${OPENMM_COPYRIGHT_YEARS}
-DOPENMM_AUTHORS=${OPENMM_AUTHORS})
ENDIF(NEED_QUOTES)
# -DOPENMM_TYPE has to be defined in the target subdirectories.
# -Dsimbody_EXPORTS defined automatically when Windows DLL build is being done.
# Report the version number to the CMake UI
SET(OPENMM_VERSION
"${OPENMM_MAJOR_VERSION}.${OPENMM_MINOR_VERSION}.${OPENMM_BUILD_VERSION}"
CACHE STRING "This is the version of OpenMM which will be built." FORCE)
SET(SHARED_TARGET ${OPENMM_LIBRARY_NAME})
SET(STATIC_TARGET ${OPENMM_LIBRARY_NAME}_static)
## If no one says otherwise, change the executable path to drop into the same binary
## location as the DLLs so that the test cases will use the just-build DLLs.
IF(NOT EXECUTABLE_OUTPUT_PATH)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}
CACHE INTERNAL "Single output directory for building all executables.")
ENDIF(NOT EXECUTABLE_OUTPUT_PATH)
IF(NOT LIBRARY_OUTPUT_PATH)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}
CACHE INTERNAL "Single output directory for building all libraries.")
ENDIF(NOT LIBRARY_OUTPUT_PATH)
SET(${PROJECT_NAME}_EXECUTABLE_DIR ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR})
SET(${PROJECT_NAME}_LIBRARY_DIR ${LIBRARY_OUTPUT_PATH}/${CMAKE_CFG_INTDIR})
# Ensure that debug libraries have "_d" appended to their names.
# CMake gets this right on Windows automatically with this definition.
IF (${CMAKE_GENERATOR} MATCHES "Visual Studio")
SET(CMAKE_DEBUG_POSTFIX "_d" CACHE INTERNAL "" FORCE)
ENDIF (${CMAKE_GENERATOR} MATCHES "Visual Studio")
# But on Unix or Cygwin we have to add the suffix manually
IF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
SET(SHARED_TARGET ${SHARED_TARGET}_d)
SET(STATIC_TARGET ${STATIC_TARGET}_d)
ENDIF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
# These are all the places to search for header files which are
# to be part of the API.
SET(API_INCLUDE_DIRS) # start empty
FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS})
# append
SET(API_INCLUDE_DIRS ${API_INCLUDE_DIRS}
${subdir}/include
${subdir}/include/internal)
ENDFOREACH(subdir)
# We'll need both *relative* path names, starting with their API_INCLUDE_DIRS,
# and absolute pathnames.
SET(API_REL_INCLUDE_FILES) # start these out empty
SET(API_ABS_INCLUDE_FILES)
FOREACH(dir ${API_INCLUDE_DIRS})
FILE(GLOB fullpaths ${dir}/*.h) # returns full pathnames
SET(API_ABS_INCLUDE_FILES ${API_ABS_INCLUDE_FILES} ${fullpaths})
FOREACH(pathname ${fullpaths})
GET_FILENAME_COMPONENT(filename ${pathname} NAME)
SET(API_REL_INCLUDE_FILES ${API_REL_INCLUDE_FILES} ${dir}/${filename})
ENDFOREACH(pathname)
ENDFOREACH(dir)
# collect up source files
SET(SOURCE_FILES) # empty
SET(SOURCE_INCLUDE_FILES)
FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS})
FILE(GLOB src_files ${subdir}/src/*.cpp ${subdir}/src/*/*.cpp)
FILE(GLOB incl_files ${subdir}/src/*.h)
SET(SOURCE_FILES ${SOURCE_FILES} ${src_files}) #append
SET(SOURCE_INCLUDE_FILES ${SOURCE_INCLUDE_FILES} ${incl_files})
## Make sure we find these locally before looking in SimTK/core/include if
## OpenMM was previously installed there.
INCLUDE_DIRECTORIES(BEFORE ${PROJECT_SOURCE_DIR}/${subdir}/include)
ENDFOREACH(subdir)
INCLUDE_DIRECTORIES(BEFORE ${PROJECT_SOURCE_DIR}/src)
ADD_LIBRARY(${SHARED_TARGET} SHARED ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_ABS_INCLUDE_FILES})
#
# Allow automated build and dashboard.
#
INCLUDE (Dart)
#IF (UNIX AND NOT CYGWIN AND NOT APPLE)
# IF (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES Debug)
# ADD_DEFINITIONS(-fprofile-arcs -ftest-coverage)
# LINK_LIBRARIES(gcov)
# ENDIF (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES Debug)
#ENDIF (UNIX AND NOT CYGWIN AND NOT APPLE)
#
# Testing
#
ENABLE_TESTING()
IF (EXECUTABLE_OUTPUT_PATH)
SET (TEST_PATH ${EXECUTABLE_OUTPUT_PATH})
ELSE (EXECUTABLE_OUTPUT_PATH)
SET (TEST_PATH .)
ENDIF (EXECUTABLE_OUTPUT_PATH)
INCLUDE(ApiDoxygen.cmake)
# Doxyfile 1.5.3
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = @PROJECT_NAME@
PROJECT_NUMBER =
OUTPUT_DIRECTORY =
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ABBREVIATE_BRIEF =
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = NO
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = YES
QT_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
DETAILS_AT_TOP = YES
INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = NO
TAB_SIZE = 4
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = NO
OPTIMIZE_OUTPUT_JAVA = NO
BUILTIN_STL_SUPPORT = NO
CPP_CLI_SUPPORT = NO
DISTRIBUTE_GROUP_DOC = YES
SUBGROUPING = YES
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_ALL = YES
EXTRACT_PRIVATE = NO
EXTRACT_STATIC = NO
EXTRACT_LOCAL_CLASSES = YES
EXTRACT_LOCAL_METHODS = NO
EXTRACT_ANON_NSPACES = NO
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = NO
HIDE_IN_BODY_DOCS = YES
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = YES
HIDE_SCOPE_NAMES = YES
SHOW_INCLUDE_FILES = YES
INLINE_INFO = YES
SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = NO
SORT_BY_SCOPE_NAME = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
SHOW_DIRECTORIES = YES
FILE_VERSION_FILTER =
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
WARN_FORMAT = "$file:$line: $text "
WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = "@CMAKE_SOURCE_DIR@"
INPUT_ENCODING = UTF-8
FILE_PATTERNS =
RECURSIVE = YES
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS = */tests/* \
*/src/* \
*/.svn/*
EXCLUDE_SYMBOLS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO
IMAGE_PATH =
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
#---------------------------------------------------------------------------
# configuration options related to source browsing
#---------------------------------------------------------------------------
SOURCE_BROWSER = NO
INLINE_SOURCES = NO
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
REFERENCES_LINK_SOURCE = YES
USE_HTAGS = NO
VERBATIM_HEADERS = YES
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = NO
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML = YES
HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
HTML_ALIGN_MEMBERS = YES
GENERATE_HTMLHELP = NO
HTML_DYNAMIC_SECTIONS = YES
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = NO
DISABLE_INDEX = NO
ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = YES
TREEVIEW_WIDTH = 250
#---------------------------------------------------------------------------
# configuration options related to the LaTeX output
#---------------------------------------------------------------------------
GENERATE_LATEX = YES
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4wide
EXTRA_PACKAGES =
LATEX_HEADER =
PDF_HYPERLINKS = NO
USE_PDFLATEX = NO
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
#---------------------------------------------------------------------------
# configuration options related to the RTF output
#---------------------------------------------------------------------------
GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
#---------------------------------------------------------------------------
# configuration options related to the man page output
#---------------------------------------------------------------------------
GENERATE_MAN = NO
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_LINKS = NO
#---------------------------------------------------------------------------
# configuration options related to the XML output
#---------------------------------------------------------------------------
GENERATE_XML = NO
XML_OUTPUT = xml
XML_SCHEMA =
XML_DTD =
XML_PROGRAMLISTING = YES
#---------------------------------------------------------------------------
# configuration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
GENERATE_AUTOGEN_DEF = NO
#---------------------------------------------------------------------------
# configuration options related to the Perl module output
#---------------------------------------------------------------------------
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
PERLMOD_MAKEVAR_PREFIX =
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
SEARCH_INCLUDES = YES
INCLUDE_PATH = "@SimTK_SDK@/core/include"
INCLUDE_FILE_PATTERNS =
PREDEFINED = SimTK_SIMBODY_EXPORT=
EXPAND_AS_DEFINED = SimTK_PIMPL_DOWNCAST
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
# Configuration::additions related to external references
#---------------------------------------------------------------------------
TAGFILES = "@SimTK_SDK@/core/doc/api/SimTKsimmath/SimTKsimmathDoxygenTagFile"="../SimTKsimmath" "@SimTK_SDK@/core/doc/api/SimTKcommon/SimTKcommonDoxygenTagFile"="../SimTKcommon"
GENERATE_TAGFILE = "html/@PROJECT_NAME@DoxygenTagfile"
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = YES
MSCGEN_PATH = /Developer/Applications/Doxygen.app/Contents/Resources/
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = NO
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = NO
TEMPLATE_RELATIONS = YES
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = NO
CALLER_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
DOT_PATH =
DOTFILE_DIRS =
DOT_GRAPH_MAX_NODES = 50
MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = NO
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
#---------------------------------------------------------------------------
# Configuration::additions related to the search engine
#---------------------------------------------------------------------------
SEARCHENGINE = NO
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
Kernel(); Kernel();
Kernel(const Kernel& copy); Kernel(const Kernel& copy);
~Kernel(); ~Kernel();
Kernel operator=(const Kernel& copy); Kernel& operator=(const Kernel& copy);
/** /**
* Get the name of this Kernel. * Get the name of this Kernel.
*/ */
......
...@@ -51,6 +51,7 @@ public: ...@@ -51,6 +51,7 @@ public:
*/ */
KernelImpl(std::string name); KernelImpl(std::string name);
virtual ~KernelImpl() { virtual ~KernelImpl() {
assert(referenceCount == 0);
} }
/** /**
* Get the name of this kernel. * Get the name of this kernel.
......
...@@ -83,7 +83,7 @@ public: ...@@ -83,7 +83,7 @@ public:
* Get the default StreamFactory for this Platform. It will be used to create Streams whenever a * Get the default StreamFactory for this Platform. It will be used to create Streams whenever a
* different StreamFactory has not been registered for the requested stream name. * different StreamFactory has not been registered for the requested stream name.
*/ */
virtual StreamFactory& getDefaultStreamFactory() const = 0; virtual const StreamFactory& getDefaultStreamFactory() const = 0;
/** /**
* Register a KernelFactory which should be used to create Kernels with a particular name. * Register a KernelFactory which should be used to create Kernels with a particular name.
* *
......
...@@ -72,7 +72,7 @@ public: ...@@ -72,7 +72,7 @@ public:
Stream(); Stream();
Stream(const Stream& copy); Stream(const Stream& copy);
~Stream(); ~Stream();
Stream operator=(const Stream& copy); Stream& operator=(const Stream& copy);
/** /**
* This is an enumeration of the allowed data types for a Stream. * This is an enumeration of the allowed data types for a Stream.
*/ */
......
...@@ -52,6 +52,7 @@ public: ...@@ -52,6 +52,7 @@ public:
*/ */
StreamImpl(std::string name, int size, Stream::DataType type); StreamImpl(std::string name, int size, Stream::DataType type);
virtual ~StreamImpl() { virtual ~StreamImpl() {
assert(referenceCount == 0);
} }
/** /**
* Get the name of this stream. * Get the name of this stream.
......
...@@ -45,13 +45,17 @@ Kernel::Kernel(const Kernel& copy) : impl(copy.impl) { ...@@ -45,13 +45,17 @@ Kernel::Kernel(const Kernel& copy) : impl(copy.impl) {
} }
Kernel::~Kernel() { Kernel::~Kernel() {
if (impl) {
impl->referenceCount--; impl->referenceCount--;
if (impl->referenceCount == 0) if (impl->referenceCount == 0)
delete impl; delete impl;
}
} }
Kernel Kernel::operator=(const Kernel& copy) { Kernel& Kernel::operator=(const Kernel& copy) {
return Kernel(copy); impl = copy.impl;
impl->referenceCount++;
return *this;
} }
string Kernel::Kernel::getName() const { string Kernel::Kernel::getName() const {
......
...@@ -63,6 +63,8 @@ Kernel Platform::createKernel(std::string name) const { ...@@ -63,6 +63,8 @@ Kernel Platform::createKernel(std::string name) const {
} }
Stream Platform::createStream(std::string name, int size, Stream::DataType type) const { Stream Platform::createStream(std::string name, int size, Stream::DataType type) const {
if (streamFactories.find(name) == streamFactories.end())
return Stream(getDefaultStreamFactory().createStreamImpl(name, size, type));
return Stream(streamFactories.find(name)->second->createStreamImpl(name, size, type)); return Stream(streamFactories.find(name)->second->createStreamImpl(name, size, type));
} }
......
...@@ -46,13 +46,17 @@ Stream::Stream(const Stream& copy) : impl(copy.impl) { ...@@ -46,13 +46,17 @@ Stream::Stream(const Stream& copy) : impl(copy.impl) {
} }
Stream::~Stream() { Stream::~Stream() {
if (impl) {
impl->referenceCount--; impl->referenceCount--;
if (impl->referenceCount == 0) if (impl->referenceCount == 0)
delete impl; delete impl;
}
} }
Stream Stream::operator=(const Stream& copy) { Stream& Stream::operator=(const Stream& copy) {
return Stream(copy); impl = copy.impl;
impl->referenceCount++;
return *this;
} }
string Stream::Stream::getName() const { string Stream::Stream::getName() const {
......
...@@ -38,12 +38,11 @@ ...@@ -38,12 +38,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
class thalweg_ARRAY;
namespace OpenMM { namespace OpenMM {
class OpenMMContextImpl; class OpenMMContextImpl;
class Vec3; class Vec3;
class Platform;
/** /**
* An OpenMMContext stores the complete state of a simulation. More specifically, it includes: * An OpenMMContext stores the complete state of a simulation. More specifically, it includes:
...@@ -70,6 +69,15 @@ public: ...@@ -70,6 +69,15 @@ public:
* @param integrator the Integrator which will be used to simulate the System * @param integrator the Integrator which will be used to simulate the System
*/ */
OpenMMContext(System& system, Integrator& integrator); OpenMMContext(System& system, Integrator& integrator);
/**
* Construct a new OpenMMContext in which to run a simulation, explicitly specifying what Platform should be used
* to perform calculations.
*
* @param system the System which will be simulated
* @param integrator the Integrator which will be used to simulate the System
* @param platform the Platform to use for calculations
*/
OpenMMContext(System& system, Integrator& integrator, Platform& platform);
/** /**
* Get System being simulated in this context. * Get System being simulated in this context.
*/ */
......
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
/** /**
* Create an OpenMMContextImpl for an OpenMMContext; * Create an OpenMMContextImpl for an OpenMMContext;
*/ */
OpenMMContextImpl(OpenMMContext& owner, System& system, Integrator& integrator); OpenMMContextImpl(OpenMMContext& owner, System& system, Integrator& integrator, Platform* platform);
~OpenMMContextImpl(); ~OpenMMContextImpl();
/** /**
* Get the OpenMMContext for which this is the implementation. * Get the OpenMMContext for which this is the implementation.
......
...@@ -63,7 +63,7 @@ public: ...@@ -63,7 +63,7 @@ public:
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
private: private:
void findExclusions(const std::vector<std::vector<int> >& bondIndices, std::vector<std::set<int> >& exclusions, std::set<std::pair<int, int> >& bonded14Indices) const; void findExclusions(const std::vector<std::vector<int> >& bondIndices, std::vector<std::set<int> >& exclusions, std::set<std::pair<int, int> >& bonded14Indices) const;
void addExclusionsToSet(const std::vector<std::set<int> >& bonded12, std::set<int>& exclusions, int fromAtom, int currentLevel) const; void addExclusionsToSet(const std::vector<std::set<int> >& bonded12, std::set<int>& exclusions, int baseAtom, int fromAtom, int currentLevel) const;
StandardMMForceField& owner; StandardMMForceField& owner;
Kernel forceKernel, energyKernel; Kernel forceKernel, energyKernel;
}; };
......
...@@ -36,7 +36,10 @@ ...@@ -36,7 +36,10 @@
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
OpenMMContext::OpenMMContext(System& system, Integrator& integrator) : impl(new OpenMMContextImpl(*this, system, integrator)) { OpenMMContext::OpenMMContext(System& system, Integrator& integrator) : impl(new OpenMMContextImpl(*this, system, integrator, 0)) {
}
OpenMMContext::OpenMMContext(System& system, Integrator& integrator, Platform& platform) : impl(new OpenMMContextImpl(*this, system, integrator, &platform)) {
} }
const System& OpenMMContext::getSystem() const { const System& OpenMMContext::getSystem() const {
......
...@@ -42,7 +42,8 @@ using namespace OpenMM; ...@@ -42,7 +42,8 @@ using namespace OpenMM;
using std::vector; using std::vector;
using std::string; using std::string;
OpenMMContextImpl::OpenMMContextImpl(OpenMMContext& owner, System& system, Integrator& integrator) : owner(owner), system(system), integrator(integrator) { OpenMMContextImpl::OpenMMContextImpl(OpenMMContext& owner, System& system, Integrator& integrator, Platform* platform) :
owner(owner), system(system), integrator(integrator), platform(platform) {
vector<string> kernelNames; vector<string> kernelNames;
kernelNames.push_back(CalcKineticEnergyKernel::Name()); kernelNames.push_back(CalcKineticEnergyKernel::Name());
for (int i = 0; i < system.getNumForces(); ++i) { for (int i = 0; i < system.getNumForces(); ++i) {
...@@ -52,7 +53,10 @@ OpenMMContextImpl::OpenMMContextImpl(OpenMMContext& owner, System& system, Integ ...@@ -52,7 +53,10 @@ OpenMMContextImpl::OpenMMContextImpl(OpenMMContext& owner, System& system, Integ
} }
vector<string> integratorKernels = integrator.getKernelNames(); vector<string> integratorKernels = integrator.getKernelNames();
kernelNames.insert(kernelNames.begin(), integratorKernels.begin(), integratorKernels.end()); kernelNames.insert(kernelNames.begin(), integratorKernels.begin(), integratorKernels.end());
if (platform == 0)
platform = &Platform::findPlatform(kernelNames); platform = &Platform::findPlatform(kernelNames);
else if (!platform->supportsKernels(kernelNames))
throw OpenMMException("Specified a Platform for an OpenMMContext which does not support all required kernels");
positions = platform->createStream("atomPositions", system.getNumAtoms(), Stream::Double3); positions = platform->createStream("atomPositions", system.getNumAtoms(), Stream::Double3);
velocities = platform->createStream("atomVelocities", system.getNumAtoms(), Stream::Double3); velocities = platform->createStream("atomVelocities", system.getNumAtoms(), Stream::Double3);
forces = platform->createStream("atomForces", system.getNumAtoms(), Stream::Double3); forces = platform->createStream("atomForces", system.getNumAtoms(), Stream::Double3);
......
...@@ -41,14 +41,14 @@ using std::set; ...@@ -41,14 +41,14 @@ using std::set;
StandardMMForceFieldImpl::StandardMMForceFieldImpl(StandardMMForceField& owner, OpenMMContextImpl& context) : owner(owner) { StandardMMForceFieldImpl::StandardMMForceFieldImpl(StandardMMForceField& owner, OpenMMContextImpl& context) : owner(owner) {
forceKernel = context.getPlatform().createKernel(CalcStandardMMForcesKernel::Name()); forceKernel = context.getPlatform().createKernel(CalcStandardMMForcesKernel::Name());
energyKernel = context.getPlatform().createKernel(CalcStandardMMEnergyKernel::Name()); energyKernel = context.getPlatform().createKernel(CalcStandardMMEnergyKernel::Name());
vector<vector<int> > bondIndices; vector<vector<int> > bondIndices(owner.getNumBonds());
vector<vector<double> > bondParameters; vector<vector<double> > bondParameters(owner.getNumBonds());
vector<vector<int> > angleIndices; vector<vector<int> > angleIndices(owner.getNumAngles());
vector<vector<double> > angleParameters; vector<vector<double> > angleParameters(owner.getNumAngles());
vector<vector<int> > periodicTorsionIndices; vector<vector<int> > periodicTorsionIndices(owner.getNumPeriodicTorsions());
vector<vector<double> > periodicTorsionParameters; vector<vector<double> > periodicTorsionParameters(owner.getNumPeriodicTorsions());
vector<vector<int> > rbTorsionIndices; vector<vector<int> > rbTorsionIndices(owner.getNumRBTorsions());
vector<vector<double> > rbTorsionParameters; vector<vector<double> > rbTorsionParameters(owner.getNumRBTorsions());
vector<vector<int> > bonded14Indices; vector<vector<int> > bonded14Indices;
vector<set<int> > exclusions(owner.getNumAtoms()); vector<set<int> > exclusions(owner.getNumAtoms());
vector<vector<double> > nonbondedParameters(owner.getNumAtoms()); vector<vector<double> > nonbondedParameters(owner.getNumAtoms());
...@@ -107,6 +107,12 @@ StandardMMForceFieldImpl::StandardMMForceFieldImpl(StandardMMForceField& owner, ...@@ -107,6 +107,12 @@ StandardMMForceFieldImpl::StandardMMForceFieldImpl(StandardMMForceField& owner,
} }
set<pair<int, int> > bonded14set; set<pair<int, int> > bonded14set;
findExclusions(bondIndices, exclusions, bonded14set); findExclusions(bondIndices, exclusions, bonded14set);
bonded14Indices.resize(bonded14set.size());
int index = 0;
for (set<pair<int, int> >::const_iterator iter = bonded14set.begin(); iter != bonded14set.end(); ++iter) {
bonded14Indices[index].push_back(iter->first);
bonded14Indices[index++].push_back(iter->second);
}
dynamic_cast<CalcStandardMMForcesKernel&>(forceKernel.getImpl()).initialize(bondIndices, bondParameters, angleIndices, angleParameters, dynamic_cast<CalcStandardMMForcesKernel&>(forceKernel.getImpl()).initialize(bondIndices, bondParameters, angleIndices, angleParameters,
periodicTorsionIndices, periodicTorsionParameters, rbTorsionIndices, rbTorsionParameters, bonded14Indices, exclusions, nonbondedParameters); periodicTorsionIndices, periodicTorsionParameters, rbTorsionIndices, rbTorsionParameters, bonded14Indices, exclusions, nonbondedParameters);
dynamic_cast<CalcStandardMMEnergyKernel&>(energyKernel.getImpl()).initialize(bondIndices, bondParameters, angleIndices, angleParameters, dynamic_cast<CalcStandardMMEnergyKernel&>(energyKernel.getImpl()).initialize(bondIndices, bondParameters, angleIndices, angleParameters,
...@@ -135,24 +141,25 @@ void StandardMMForceFieldImpl::findExclusions(const vector<vector<int> >& bondIn ...@@ -135,24 +141,25 @@ void StandardMMForceFieldImpl::findExclusions(const vector<vector<int> >& bondIn
vector<set<int> > bonded12(exclusions.size()); vector<set<int> > bonded12(exclusions.size());
for (int i = 0; i < (int) bondIndices.size(); ++i) { for (int i = 0; i < (int) bondIndices.size(); ++i) {
bonded12[bondIndices[i][0]].insert(bondIndices[i][1]); bonded12[bondIndices[i][0]].insert(bondIndices[i][1]);
bonded12[bondIndices[i][1]].insert(bondIndices[i][2]); bonded12[bondIndices[i][1]].insert(bondIndices[i][0]);
} }
for (int i = 0; i < (int) exclusions.size(); ++i) for (int i = 0; i < (int) exclusions.size(); ++i)
addExclusionsToSet(bonded12, exclusions[i], i, 2); addExclusionsToSet(bonded12, exclusions[i], i, i, 2);
for (int i = 0; i < (int) exclusions.size(); ++i) { for (int i = 0; i < (int) exclusions.size(); ++i) {
set<int> bonded13; set<int> bonded13;
addExclusionsToSet(bonded12, bonded13, i, 1); addExclusionsToSet(bonded12, bonded13, i, i, 1);
for (set<int>::const_iterator iter = exclusions[i].begin(); iter != exclusions[i].end(); ++iter) for (set<int>::const_iterator iter = exclusions[i].begin(); iter != exclusions[i].end(); ++iter)
if (*iter < i && bonded13.find(*iter) == bonded13.end()) if (*iter < i && bonded13.find(*iter) == bonded13.end())
bonded14Indices.insert(pair<int, int> (*iter, i)); bonded14Indices.insert(pair<int, int> (*iter, i));
} }
} }
void StandardMMForceFieldImpl::addExclusionsToSet(const vector<set<int> >& bonded12, set<int>& exclusions, int fromAtom, int currentLevel) const { void StandardMMForceFieldImpl::addExclusionsToSet(const vector<set<int> >& bonded12, set<int>& exclusions, int baseAtom, int fromAtom, int currentLevel) const {
for (set<int>::const_iterator iter = bonded12[fromAtom].begin(); iter != bonded12[fromAtom].end(); ++iter) { for (set<int>::const_iterator iter = bonded12[fromAtom].begin(); iter != bonded12[fromAtom].end(); ++iter) {
if (*iter != baseAtom)
exclusions.insert(*iter); exclusions.insert(*iter);
if (currentLevel > 0) if (currentLevel > 0)
addExclusionsToSet(bonded12, exclusions, *iter, currentLevel-1); addExclusionsToSet(bonded12, exclusions, baseAtom, *iter, currentLevel-1);
} }
} }
#ifndef OPENMM_ASSERTIONUTILITIES_H_
#define OPENMM_ASSERTIONUTILITIES_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
/**
* This file provides a variety of macros useful in test cases.
*/
#include "OpenMMException.h"
#include <string>
#include <sstream>
void throwException(const char* file, int line, const std::string& details) {
std::string fn(file);
std::string::size_type pos = fn.find_last_of("/\\");
if (pos+1>=fn.size())
pos=0;
std::string filename(fn,(int)(pos+1),(int)(fn.size()-(pos+1)));
std::stringstream message;
message << "Assertion failure at "<<filename<<":"<<line;
if (details.size() > 0)
message << ". "<<details;
throw OpenMM::OpenMMException(message.str());
}
#define ASSERT(cond) {if (!(cond)) throwException(__FILE__, __LINE__, "");};
#define ASSERT_EQUAL(expected, found) {if ((expected) != (found)) {std::stringstream details; details << "Expected "<<(expected)<<", found "<<(found); throwException(__FILE__, __LINE__, details.str());}};
#endif /*OPENMM_ASSERTIONUTILITIES_H_*/
#
# Testing
#
ENABLE_TESTING()
# Automatically create tests using files named "Test*.cpp"
FILE(GLOB TEST_PROGS "*Test*.cpp")
FOREACH(TEST_PROG ${TEST_PROGS})
GET_FILENAME_COMPONENT(TEST_ROOT ${TEST_PROG} NAME_WE)
# Link with shared library
ADD_EXECUTABLE(${TEST_ROOT} ${TEST_PROG})
TARGET_LINK_LIBRARIES(${TEST_ROOT} ${SHARED_TARGET})
ADD_TEST(${TEST_ROOT} ${EXECUTABLE_OUTPUT_PATH}/${TEST_ROOT})
# Link with static library
# SET(TEST_STATIC ${TEST_ROOT}Static)
# ADD_EXECUTABLE(${TEST_STATIC} ${TEST_PROG})
# SET_TARGET_PROPERTIES(${TEST_STATIC}
# PROPERTIES
# COMPILE_FLAGS "-DOPENMM_USE_STATIC_LIBRARIES"
# )
# TARGET_LINK_LIBRARIES(${TEST_STATIC} ${STATIC_TARGET})
# ADD_TEST(${TEST_STATIC} ${EXECUTABLE_OUTPUT_PATH}/${TEST_STATIC})
ENDFOREACH(TEST_PROG ${TEST_PROGS})
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
/**
* This tests the findExclusions() method of StandardMMForceFieldImpl, which identifies pairs of atoms
* whose nonbonded atoms are either excluded or decreased. The test system is a chain with branches:
*
* 1 3 5 7 9 11 13 15 17 19
* | | | | | | | | | |
* 0--2--4--6--8--10--12--14--16--18
*/
#include "AssertionUtilities.h"
#include "Kernel.h"
#include "KernelFactory.h"
#include "OpenMMContext.h"
#include "Platform.h"
#include "StandardMMForceField.h"
#include "Stream.h"
#include "StreamFactory.h"
#include "System.h"
#include "VerletIntegrator.h"
#include "kernels.h"
#include <algorithm>
#include <iostream>
#include <iterator>
#include <set>
#include <vector>
using namespace OpenMM;
using namespace std;
static const int NUM_ATOMS = 20;
/**
* Add a pair of atoms to the list of exclusions.
*/
void addAtomsToExclusions(int atom1, int atom2, vector<set<int> >& exclusions) {
if (atom2 < NUM_ATOMS) {
exclusions[atom1].insert(atom2);
exclusions[atom2].insert(atom1);
}
}
/**
* Verify that the exclusions are what we expect.
*/
void verifyExclusions(const vector<set<int> >& exclusions) {
vector<set<int> > expected(NUM_ATOMS);
for (int i = 0; i < NUM_ATOMS; i += 2) {
addAtomsToExclusions(i, i+1, expected);
addAtomsToExclusions(i, i+2, expected);
addAtomsToExclusions(i, i+3, expected);
addAtomsToExclusions(i, i+4, expected);
addAtomsToExclusions(i, i+5, expected);
addAtomsToExclusions(i, i+6, expected);
addAtomsToExclusions(i+1, i+2, expected);
addAtomsToExclusions(i+1, i+3, expected);
addAtomsToExclusions(i+1, i+4, expected);
}
ASSERT_EQUAL(expected.size(), exclusions.size());
for (int i = 0; i < NUM_ATOMS; ++i) {
ASSERT_EQUAL(expected[i].size(), exclusions[i].size());
vector<int> intersection(0);
insert_iterator<vector<int> > inserter(intersection, intersection.begin());
set_intersection(exclusions[i].begin(), exclusions[i].end(), expected[i].begin(), expected[i].end(), inserter);
ASSERT_EQUAL(expected[i].size(), intersection.size());
}
}
/**
* Add a pair of atoms to the list of 1-4 pairs.
*/
void addAtomsTo14List(int atom1, int atom2, set<pair<int, int> >& bonded14Indices) {
if (atom2 < NUM_ATOMS)
bonded14Indices.insert(pair<int, int>(atom1, atom2));
}
/**
* Verify that the 1-4 pairs are what we expect.
*/
void verify14(const vector<vector<int> >& bonded14Indices) {
set<pair<int, int> > expected, found;
for (int i = 0; i < NUM_ATOMS; i += 2) {
addAtomsTo14List(i, i+5, expected);
addAtomsTo14List(i, i+6, expected);
addAtomsTo14List(i+1, i+3, expected);
addAtomsTo14List(i+1, i+4, expected);
}
ASSERT_EQUAL(expected.size(), bonded14Indices.size());
for (int i = 0; i < bonded14Indices.size(); ++i) {
int atom1 = bonded14Indices[i][0];
int atom2 = bonded14Indices[i][1];
found.insert(pair<int, int>(min(atom1, atom2), max(atom1, atom2)));
}
vector<pair<int, int> > intersection(0);
insert_iterator<vector<pair<int, int> > > inserter(intersection, intersection.begin());
set_intersection(expected.begin(), expected.end(), found.begin(), found.end(), inserter);
ASSERT_EQUAL(expected.size(), intersection.size());
}
/**
* The following classes define a Platform whose job is to check whether the correct values were passed
* to the initialize() methods.
*/
class DummyForceKernel : public CalcStandardMMForcesKernel {
public:
DummyForceKernel(string name) : CalcStandardMMForcesKernel(name) {
}
void initialize(const vector<vector<int> >& bondIndices, const vector<vector<double> >& bondParameters,
const vector<vector<int> >& angleIndices, const vector<vector<double> >& angleParameters,
const vector<vector<int> >& periodicTorsionIndices, const vector<vector<double> >& periodicTorsionParameters,
const vector<vector<int> >& rbTorsionIndices, const vector<vector<double> >& rbTorsionParameters,
const vector<vector<int> >& bonded14Indices, const vector<set<int> >& exclusions,
const vector<vector<double> >& nonbondedParameters) {
verifyExclusions(exclusions);
verify14(bonded14Indices);
}
void execute(const Stream& positions, Stream& forces) {
}
};
class DummyEnergyKernel : public CalcStandardMMEnergyKernel {
public:
DummyEnergyKernel(string name) : CalcStandardMMEnergyKernel(name) {
}
void initialize(const vector<vector<int> >& bondIndices, const vector<vector<double> >& bondParameters,
const vector<vector<int> >& angleIndices, const vector<vector<double> >& angleParameters,
const vector<vector<int> >& periodicTorsionIndices, const vector<vector<double> >& periodicTorsionParameters,
const vector<vector<int> >& rbTorsionIndices, const vector<vector<double> >& rbTorsionParameters,
const vector<vector<int> >& bonded14Indices, const vector<set<int> >& exclusions,
const vector<vector<double> >& nonbondedParameters) {
verifyExclusions(exclusions);
verify14(bonded14Indices);
}
double execute(const Stream& positions) {
}
};
class DummyIntegratorKernel : public IntegrateVerletStepKernel {
public:
DummyIntegratorKernel(string name) : IntegrateVerletStepKernel(name) {
}
void initialize(const vector<double>& masses, const vector<vector<int> >& constraintIndices, const vector<double>& constraintLengths) {
}
void execute(Stream& positions, Stream& velocities, const Stream& forces, double stepSize) {
}
};
class DummyKEKernel : public CalcKineticEnergyKernel {
public:
DummyKEKernel(string name) : CalcKineticEnergyKernel(name) {
}
void initialize(const vector<double>& masses) {
}
double execute(const Stream& positions) {
}
};
class DummyStreamImpl : public StreamImpl {
public:
DummyStreamImpl(string name, int size, Stream::DataType type) : StreamImpl(name, size, type) {
}
void loadFromArray(const void* array) {
}
void saveToArray(void* array) {
}
void fillWithValue(void* value) {
}
};
class DummyKernelFactory : public KernelFactory {
public:
KernelImpl* createKernelImpl(string name) const {
if (name == CalcStandardMMForcesKernel::Name())
return new DummyForceKernel(name);
if (name == CalcStandardMMEnergyKernel::Name())
return new DummyEnergyKernel(name);
if (name == IntegrateVerletStepKernel::Name())
return new DummyIntegratorKernel(name);
if (name == CalcKineticEnergyKernel::Name())
return new DummyKEKernel(name);
return 0;
}
};
class DummyStreamFactory : public StreamFactory {
public:
StreamImpl* createStreamImpl(string name, int size, Stream::DataType type) const {
return new DummyStreamImpl(name, size, type);
}
};
class DummyPlatform : public Platform {
public:
DummyPlatform() {
registerKernelFactory(CalcStandardMMForcesKernel::Name(), new DummyKernelFactory());
registerKernelFactory(CalcStandardMMEnergyKernel::Name(), new DummyKernelFactory());
registerKernelFactory(IntegrateVerletStepKernel::Name(), new DummyKernelFactory());
registerKernelFactory(CalcKineticEnergyKernel::Name(), new DummyKernelFactory());
}
string getName() const {
return "Dummy";
}
double getSpeed() const {
return 1.0;
}
bool supportsDoublePrecision() const {
return true;
}
const StreamFactory& getDefaultStreamFactory() const {
return streamFactory;
}
private:
DummyStreamFactory streamFactory;
};
int main() {
try {
DummyPlatform platform;
System system(NUM_ATOMS, 0);
VerletIntegrator integrator(0.01);
StandardMMForceField* forces = new StandardMMForceField(NUM_ATOMS, NUM_ATOMS-1, 0, 0, 0);
for (int i = 0; i < NUM_ATOMS; i += 2) {
forces->setBondParameters(i, i, i+1, 1.0, 1.0);
if (i < NUM_ATOMS-1)
forces->setBondParameters(i+1, i, i+2, 1.0, 1.0);
}
system.addForce(forces);
OpenMMContext context(system, integrator, platform);
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment