Skip to content

Commit

Permalink
Changes in CMake configuration (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
craabreu authored Dec 11, 2023
1 parent 99c2e63 commit 17b5808
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 10 deletions.
22 changes: 13 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@

CMAKE_MINIMUM_REQUIRED(VERSION 3.17)

PROJECT(OpenMMNonbondedSlicing VERSION 0.1)
PROJECT(OpenMMNonbondedSlicing VERSION 0.2.0)

IF(DEFINED ENV{CONDA_PREFIX})
SET(OPENMM_DIR $ENV{CONDA_PREFIX} CACHE PATH "Where OpenMM is installed")
EXECUTE_PROCESS(
COMMAND conda list ^openmm\\b
OUTPUT_VARIABLE OPENMM_VERSION
)
STRING(REGEX REPLACE ".* ([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" OPENMM_VERSION_MAJOR "${OPENMM_VERSION}")
STRING(REGEX REPLACE ".* [0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" OPENMM_VERSION_MINOR "${OPENMM_VERSION}")
ADD_COMPILE_DEFINITIONS(OPENMM_VERSION_MAJOR=${OPENMM_VERSION_MAJOR})
ADD_COMPILE_DEFINITIONS(OPENMM_VERSION_MINOR=${OPENMM_VERSION_MINOR})
ENDIF(DEFINED ENV{CONDA_PREFIX})

EXECUTE_PROCESS(
COMMAND conda list ^openmm\\b
OUTPUT_VARIABLE OPENMM_VERSION
)
IF (NOT OPENMM_VERSION)
MESSAGE(FATAL_ERROR "OpenMM conda package not found. Please install OpenMM with conda.")
ENDIF(NOT OPENMM_VERSION)
STRING(REGEX REPLACE ".* ([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" OPENMM_VERSION_MAJOR "${OPENMM_VERSION}")
STRING(REGEX REPLACE ".* [0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" OPENMM_VERSION_MINOR "${OPENMM_VERSION}")
ADD_COMPILE_DEFINITIONS(OPENMM_VERSION_MAJOR=${OPENMM_VERSION_MAJOR})
ADD_COMPILE_DEFINITIONS(OPENMM_VERSION_MINOR=${OPENMM_VERSION_MINOR})

INCLUDE_DIRECTORIES("${OPENMM_DIR}/include")
LINK_DIRECTORIES("${OPENMM_DIR}/lib" "${OPENMM_DIR}/lib/plugins")

Expand Down
45 changes: 45 additions & 0 deletions devtools/conda-recipes/anaconda/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -euxo pipefail

rm -rf build || true

CMAKE_FLAGS=" -DCMAKE_INSTALL_PREFIX=${PREFIX}"
CMAKE_FLAGS+=" -DCMAKE_BUILD_TYPE=Release"

CMAKE_FLAGS+=" -DOPENMM_DIR=${PREFIX}"
CMAKE_FLAGS+=" -DPLUGIN_LIBRARY_DIR=${PREFIX}/lib"

# OpenCL
CMAKE_FLAGS+=" -DPLUGIN_BUILD_OPENCL_LIB=ON"
CMAKE_FLAGS+=" -DOPENCL_INCLUDE_DIR=${PREFIX}/include"
CMAKE_FLAGS+=" -DOPENCL_LIBRARY=${PREFIX}/lib/libOpenCL${SHLIB_EXT}"

# if CUDA_HOME is defined and not empty, we enable CUDA
if [[ -n ${CUDA_HOME-} ]]; then
CMAKE_FLAGS+=" -DCUDA_TOOLKIT_ROOT_DIR=${CUDA_HOME}"
CMAKE_FLAGS+=" -DCMAKE_LIBRARY_PATH=${CUDA_HOME}/lib64/stubs"
CMAKE_FLAGS+=" -DPLUGIN_BUILD_CUDA_LIB=ON"
fi

if [[ "$target_platform" == osx* ]]; then
CMAKE_FLAGS+=" -DCMAKE_OSX_SYSROOT=${CONDA_BUILD_SYSROOT}"
CMAKE_FLAGS+=" -DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}"
fi

# Build in subdirectory and install.
mkdir -p build
cd build
cmake ${CMAKE_FLAGS} ${SRC_DIR}
make -j$CPU_COUNT install
make -j$CPU_COUNT PythonInstall

# Include test executables too
mkdir -p ${PREFIX}/share/openmm-nonbonded-slicing/tests
if [[ "$target_platform" == osx* ]]; then
find . -name "Test*" -perm +0111 -type f \
-exec python $RECIPE_DIR/patch_osx_tests.py "{}" \; \
-exec cp "{}" $PREFIX/share/openmm-nonbonded-slicing/tests/ \;
else
find . -name "Test*" -executable -type f -exec cp "{}" $PREFIX/share/openmm-nonbonded-slicing/tests/ \;
fi
70 changes: 70 additions & 0 deletions devtools/conda-recipes/anaconda/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{% set version = environ['PLUGIN_VERSION'][1:] %}

package:
name: openmm-nonbonded-slicing
version: {{ version }}

source:
git_url: ../../../

build:
number: 0
script: build.sh

requirements:
build:
- {{ compiler('cxx') }}
- {{ compiler('cuda') }} # [linux and cuda_compiler_version != 'None']
- {{ cdt('mesa-libgl-devel') }} # [linux]
- cmake
- make
- conda-build

host:
- python
- pip
- openmm
- swig <4.1
- ocl-icd # [linux]
- khronos-opencl-icd-loader # [osx]
run:
- python
- {{ pin_compatible('openmm', lower_bound='7.7') }}
- ocl-icd # [linux]
- ocl-icd-system # [linux]
- khronos-opencl-icd-loader # [osx]
- ocl_icd_wrapper_apple # [osx]

test:
imports:
- nonbondedslicing
commands: |
cd ${PREFIX}/share/openmm-nonbonded-slicing/tests
set +e
for f in Test*; do
if [[ $f == *Cuda* || $f == *OpenCL* ]]; then
continue
fi
./${f}
((exitcode+=$?))
done
exit $exitcode
about:
home: https://github.com/craabreu/openmm-nonbonded-slicing
summary: 'An OpenMM plugin for slicing nonbonded interactions'
description: |
This plugin contains the SlicedNonbondedForce class, a variant of
OpenMM's NonbondedForce. By partitioning all particles among disjoint
subsets, the total potential energy becomes a linear combination of
contributions from pairs of subsets.
license: MIT
license_family: MIT
license_file: LICENSE.md
doc_url: https://craabreu.github.io/openmm-nonbonded-slicing
dev_url: https://github.com/craabreu/openmm-nonbonded-slicing

extra:
recipe-maintainers:
- craabreu
- jananzhu
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

setup(
name='nonbondedslicing',
version='1.0',
version='@CMAKE_PROJECT_VERSION@',
py_modules=['nonbondedslicing'],
ext_modules=[extension],
)

0 comments on commit 17b5808

Please sign in to comment.