Overview

This OpenMM plugin implements a sliced variant of OpenMM’s NonbondedForce class. By partitioning all particles among $n$ disjoint subsets, the total potential energy becomes a linear combination of contributions from pairs of subsets like

\[E = \sum_{I=0}^{n-1} \sum_{J=I}^{n-1} (\lambda^{vdW}_{I,J}E^{vdW}_{I,J}+\lambda^{elec}_{I,J}E^{elec}_{I,J}),\]

where each slice is defined by subsets I and J, superscripts vdW and elec denote van der Waals and electrostatic contributions, \(E_{I,J}\) is the potential energy of all particle pairs formed by one particle in subset I and one in subset J, and \(\lambda_{I,J}\) is a scaling parameter.

By default, all scaling parameters are constant and equal to 1. However, the user can turn selected scaling parameters into variables and store their values in openmm.Context global parameters. Derivatives with respect to these variables can be requested and used, for instance, to report individual energy slice contributions or sums thereof via openmm.Context’s getState method with options getEnergy=True and getParameterDerivatives=True. Derivatives are only computed along with the energy: without getEnergy=True, they are NaN.

A global parameter can scale the electrostatic contributions, the van der Waals contributions, or both, of any number of slices. Since the energy is linear in the scaling parameters, the derivative with respect to a parameter \(\lambda\) is the sum of the unscaled contributions it multiplies:

\[\frac{\partial E}{\partial \lambda} = \sum_{(I,J) \in S^{elec}_\lambda} E^{elec}_{I,J} + \sum_{(I,J) \in S^{vdW}_\lambda} E^{vdW}_{I,J},\]

where \(S^{elec}_\lambda\) and \(S^{vdW}_\lambda\) are the sets of slices whose electrostatic and van der Waals contributions are scaled by \(\lambda\). This derivative does not depend on the values of the scaling parameters. For instance, a parameter that scales both contributions of a single slice I, J yields its full energy \(E^{vdW}_{I,J}+E^{elec}_{I,J}\), while one that scales the electrostatic contributions of several slices yields their sum.

Installation

The plugin is distributed on conda-forge:

mamba install -c conda-forge openmm-nonbonded-slicing

Building from Source

Requirements:

  • OpenMM 8.4 or later

  • CMake 3.17 or later and a C++ compiler

  • SWIG, the same version that built your OpenMM (OpenMM’s conda-forge builds 8.4 and 8.5/8.6 used SWIG 4.4 and 4.5, respectively)

  • Optional: OpenCL headers for the OpenCL platform, and a CUDA toolkit with NVRTC and cuFFT for the CUDA platform

In a conda environment where OpenMM is installed:

mkdir build && cd build
cmake ..
make install
make PythonInstall

Useful CMake options:

Option

Default

Meaning

OPENMM_DIR

$CONDA_PREFIX

Where OpenMM is installed

OPENMM_VERSION

detected with python -c "import openmm"

OpenMM version, if Python cannot import it

CMAKE_INSTALL_PREFIX

OPENMM_DIR

Where to install the plugin

PLUGIN_BUILD_OPENCL_LIB

ON if OpenCL headers are found

Build the OpenCL platform

PLUGIN_BUILD_CUDA_LIB

ON if a CUDA toolkit is found

Build the CUDA platform (set CUDAToolkit_ROOT to pick a toolkit)

VKFFT_INCLUDE_DIR

downloaded at configure time

Directory containing vkFFT.h

Test Cases

From the build directory, run the C++ tests with make test (or ctest) and the Python tests with make PythonTest.