diff --git a/.gitmodules b/.gitmodules index 5eba3cd..2726187 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "gemmi"] - path = gemmi - url = git@github.com:project-gemmi/gemmi.git +[submodule "pybind11"] + path = pybind11 + url = https://github.com/pybind/pybind11 diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c3db48..d6975b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,17 @@ -cmake_minimum_required(VERSION 3.11.0) +############################################################################## +# Build file for amplus project +############################################################################## + +cmake_minimum_required(VERSION 3.17.0) # Set the project name project(amplus CXX) +# Set the build type to release +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + # Set the cmake module path set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) @@ -11,28 +20,18 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) # clusters which may not allow export of LD_LIBRARY_PATH set(CMAKE_INSTALL_RPATH_USE_LINK_PATH True) -# Find Pybind11 -find_package(pybind11 REQUIRED) +# Add pybind sub directory +add_subdirectory(pybind11) # Add a C/C++ extension -pybind11_add_module(freeze_ext +pybind11_add_module(amplus_ext amplus/freeze/freeze_ext.cc) # Ensure we are using C++11 -target_compile_features(freeze_ext PUBLIC cxx_std_11) +target_compile_features(amplus_ext PUBLIC cxx_std_11) # Set the include directory -target_include_directories(freeze_ext PUBLIC .) - -# Set the coverage compile and link flags for gcc or clang -set(COVERAGE_COMPILE_FLAGS -coverage) -set(COVERAGE_LINK_FLAGS -coverage) - -# Set the coverage compile and link flags in the debug build -target_compile_options(freeze_ext - PUBLIC "$<$:${COVERAGE_COMPILE_FLAGS}>") -target_link_options(freeze_ext - PUBLIC "$<$:${COVERAGE_LINK_FLAGS}>") +target_include_directories(amplus_ext PUBLIC .) # Install the python extension -install(TARGETS freeze_ext LIBRARY DESTINATION amplus/freeze) +install(TARGETS amplus_ext LIBRARY DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) diff --git a/README.md b/README.md index 2441165..9bd8c63 100644 --- a/README.md +++ b/README.md @@ -3,25 +3,56 @@ ![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg) -## Dependencies +## Installation -The packages depends on the python-multem package being installed. To do this, -follow the instructions [here](https://github.com/rosalindfranklininstitute/python-multem). +In order to build this package, the following dependencies are required: -## Installation +- The CUDA toolkit +- FFTW + +To install from the github repository do the following + +```sh +export CUDACXX=${PATH_TO_CUDA}/bin/nvcc +python -m pip install git+https://github.com/rosalindfranklininstitute/amplus-digital-twin.git@master#egg=amplus-digital-twin +``` + +To install from source, clone this repository. The repository has a submodule +for pybind11 so after cloning the repository run + +```sh +git submodule update --init --recursive +``` + +Then do the following: + +```sh +export CUDACXX=${PATH_TO_CUDA}/bin/nvcc +python -m pip install . +``` + +If you would like to run the tests then, clone this repository and then do the following: + +```sh +export CUDACXX=${PATH_TO_CUDA}/bin/nvcc +python -m pip install .[test] +``` + +## Installation for developers -To install from source, clone this repository and then do the following: +To install for development, clone this repository and then do the following: ```sh -python setup.py install +export CUDACXX=${PATH_TO_CUDA}/bin/nvcc +python -m pip install -e . ``` ## Testing -To run the tests, clone this repository and the do the following: +To run the tests, follow the installation instructions for developers and then do the following: ```sh -python setup.py test +pytest ``` ## Usage diff --git a/gemmi b/gemmi deleted file mode 160000 index 7c37368..0000000 --- a/gemmi +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7c37368fbdbb0b14c14a1355a2e4b7457f51377a diff --git a/pybind11 b/pybind11 new file mode 160000 index 0000000..5443043 --- /dev/null +++ b/pybind11 @@ -0,0 +1 @@ +Subproject commit 54430436fee2afc4f8443691075a6208f9ea8eba diff --git a/pyproject.toml b/pyproject.toml index 7533528..09a74d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,3 @@ [build-system] -requires = ["setuptools", "wheel", "scikit-build", "cmake", "ninja"] +requires = ["setuptools", "wheel", "cmake", "ninja"] +build-backend = "setuptools.build_meta" diff --git a/requirements.txt b/requirements.txt index 40cf634..a85eb97 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,7 @@ -scikit-build +setuptools cmake ninja wheel +pytest +pytest-cov +mock diff --git a/setup.py b/setup.py index 30bf4aa..bbe8619 100644 --- a/setup.py +++ b/setup.py @@ -3,8 +3,48 @@ # # This code is distributed under the BSD license. # -from skbuild import setup -from setuptools import find_packages +import os +import subprocess +import sys +from setuptools import setup, find_packages, Extension +from setuptools.command.build_ext import build_ext + + +class CMakeBuild(build_ext): + """ + Build the extensions + + """ + + def build_extensions(self): + + # Set the cmake directory + cmake_lists_dir = os.path.abspath(".") + + # Ensure the build directory exists + if not os.path.exists(self.build_temp): + os.makedirs(self.build_temp) + + # Run Cmake once + ext = self.extensions[0] + + # Get the directory + extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) + + # Arguments to cmake + cmake_args = [ + "-DCMAKE_BUILD_TYPE=%s" % "Release", + "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=%s" % extdir, + "-DPYTHON_EXECUTABLE=%s" % sys.executable, + ] + + # Config and the extension + subprocess.check_call( + ["cmake", cmake_lists_dir] + cmake_args, cwd=self.build_temp + ) + + # Build the extension + subprocess.check_call(["cmake", "--build", "."], cwd=self.build_temp) def main(): @@ -21,17 +61,20 @@ def main(): "distributed", "dask_jobqueue", "gemmi", + "guanaco @ git+https://github.com/rosalindfranklininstitute/guanaco.git@master#egg=guanaco", "h5py", "mrcfile", "numpy", "pandas", "pillow", - "python-multem @ https://github.com/rosalindfranklininstitute/python-multem/tarball/master#egg=python-multem", + "python-multem @ git+https://github.com/rosalindfranklininstitute/python-multem.git@master#egg=python-multem", "scipy", "pyyaml", ], tests_require=tests_require, test_suite="tests", + ext_modules=[Extension("amplus_ext", [])], + cmdclass={"build_ext": CMakeBuild}, entry_points={ "console_scripts": [ "amplus.read_pdb=amplus.command_line:read_pdb",