From d8ca3e4b167dc6a9830ec1960b8ea69dbee5c367 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Jul 2021 15:30:28 -0400 Subject: [PATCH] add support for automatically downloading and building libquip --- cmake/Modules/Packages/ML-QUIP.cmake | 70 ++++++++++++++++++++- doc/src/Build_extras.rst | 51 ++++++++------- doc/utils/sphinx-config/false_positives.txt | 1 + 3 files changed, 96 insertions(+), 26 deletions(-) diff --git a/cmake/Modules/Packages/ML-QUIP.cmake b/cmake/Modules/Packages/ML-QUIP.cmake index 790f27def7..ef7a75b422 100644 --- a/cmake/Modules/Packages/ML-QUIP.cmake +++ b/cmake/Modules/Packages/ML-QUIP.cmake @@ -1,3 +1,69 @@ enable_language(Fortran) -find_package(QUIP REQUIRED) -target_link_libraries(lammps PRIVATE QUIP::QUIP ${LAPACK_LIBRARIES}) +find_package(QUIP QUIET) + +if(QUIP_FOUND) + set(DOWNLOAD_QUIP_DEFAULT OFF) +else() + set(DOWNLOAD_QUIP_DEFAULT ON) +endif() +option(DOWNLOAD_QUIP "Download the QUIP library instead of using an already installed one" ${DOWNLOAD_QUIP_DEFAULT}) +if(DOWNLOAD_QUIP) + string(TOUPPER "${CMAKE_BUILD_TYPE}" BTYPE) + set(temp "F77 = ${CMAKE_Fortran_COMPILER}\nF90 = ${CMAKE_Fortran_COMPILER}\nF95 = ${CMAKE_Fortran_COMPILER}\n") + set(temp "${temp}CC=${CMAKE_C_COMPILER}\nCPLUSPLUS=${CMAKE_CXX_COMPILER}\nLINKER=${CMAKE_Fortran_COMPILER}\n") + if(CMAKE_Fortran_COMPILER_ID STREQUAL Intel) + set(temp "${temp}FPP=${CMAKE_Fortran_COMPILER} -E\nOPTIM=${CMAKE_Fortran_FLAGS_${BTYPE}}\n") + set(temp "${temp}DEFINES += -DGETARG_F2003 -DFORTRAN_UNDERSCORE\n") + set(temp "${temp}F95FLAGS += -fpp -free -fPIC\n") + set(temp "${temp}F77FLAGS += -fpp -fixed -fPIC\n") + elseif(CMAKE_Fortran_COMPILER_ID STREQUAL GNU) + set(temp "${temp}FPP=${CMAKE_Fortran_COMPILER} -E -x f95-cpp-input\nOPTIM=${CMAKE_Fortran_FLAGS_${BTYPE}}\n") + set(temp "${temp}DEFINES += -DGETARG_F2003 -DGETENV_F2003 -DGFORTRAN -DFORTRAN_UNDERSCORE\n") + set(temp "${temp}F95FLAGS += -x f95-cpp-input -ffree-line-length-none -ffree-form -fno-second-underscore -fPIC\n") + set(temp "${temp}F77FLAGS += -x f77-cpp-input -fno-second-underscore -fPIC\n") + else() + message(FATAL_ERROR "The ${CMAKE_Fortran_COMPILER_ID} Fortran compiler is not (yet) supported for building QUIP") + endif() + set(temp "${temp}CFLAGS += -fPIC \nCPLUSPLUSFLAGS += -fPIC\nAR_ADD=src\n") + set(temp "${temp}MATH_LINKOPTS=") + foreach(flag ${BLAS_LIBRARIES}) + set(temp "${temp} ${flag}") + endforeach() + foreach(flag ${LAPACK_LIBRARIES}) + set(temp "${temp} ${flag}") + endforeach() + set(temp "${temp}\n") + set(temp "${temp}PYTHON=python\nPIP=pip\nEXTRA_LINKOPTS=\n") + set(temp "${temp}HAVE_CP2K=0\nHAVE_VASP=0\nHAVE_TB=0\nHAVE_PRECON=1\nHAVE_LOTF=0\nHAVE_ONIOM=0\n") + set(temp "${temp}HAVE_LOCAL_E_MIX=0\nHAVE_QC=0\nHAVE_GAP=1\nHAVE_DESCRIPTORS_NONCOMMERCIAL=1\n") + set(temp "${temp}HAVE_TURBOGAP=0\nHAVE_QR=1\nHAVE_THIRDPARTY=0\nHAVE_FX=0\nHAVE_SCME=0\nHAVE_MTP=0\n") + set(temp "${temp}HAVE_MBD=0\nHAVE_TTM_NF=0\nHAVE_CH4=0\nHAVE_NETCDF4=0\nHAVE_MDCORE=0\nHAVE_ASAP=0\n") + set(temp "${temp}HAVE_CGAL=0\nHAVE_METIS=0\nHAVE_LMTO_TBE=0\n") + file(WRITE ${CMAKE_BINARY_DIR}/quip.config "${temp}") + + message(STATUS "QUIP download via git requested - we will build our own") + # QUIP has no releases (except for a tag marking the end of Python 2 support). We use the current "public" branch + # The LAMMPS interface wrapper has a compatibility constant that is being checked at runtime. + include(ExternalProject) + ExternalProject_Add(quip_build + GIT_REPOSITORY "https://github.com/libAtoms/QUIP/" + GIT_TAG origin/public + GIT_SHALLOW YES + GIT_PROGRESS YES + PATCH_COMMAND cp ${CMAKE_BINARY_DIR}/quip.config /arch/Makefile.lammps + CONFIGURE_COMMAND env QUIP_ARCH=lammps make config + BUILD_COMMAND env QUIP_ARCH=lammps make libquip + BUILD_IN_SOURCE YES + BUILD_BYPRODUCTS /build/lammps/libquip.a + ) + ExternalProject_get_property(quip_build SOURCE_DIR) + add_library(LAMMPS::QUIP UNKNOWN IMPORTED) + set_target_properties(LAMMPS::QUIP PROPERTIES + IMPORTED_LOCATION "${SOURCE_DIR}/build/lammps/libquip.a" + INTERFACE_LINK_LIBRARIES "${LAPACK_LIBRARIES}") + target_link_libraries(lammps PRIVATE LAMMPS::QUIP) + add_dependencies(LAMMPS::QUIP quip_build) +else() + find_package(QUIP REQUIRED) + target_link_libraries(lammps PRIVATE QUIP::QUIP ${LAPACK_LIBRARIES}) +endif() diff --git a/doc/src/Build_extras.rst b/doc/src/Build_extras.rst index 7c6bb7a878..2157fe86c8 100644 --- a/doc/src/Build_extras.rst +++ b/doc/src/Build_extras.rst @@ -31,36 +31,36 @@ This is the list of packages that may require additional steps. .. table_from_list:: :columns: 6 - * :ref:`COMPRESS ` - * :ref:`GPU ` - * :ref:`KIM ` - * :ref:`KOKKOS ` - * :ref:`LATTE ` - * :ref:`MESSAGE ` - * :ref:`ML-IAP ` - * :ref:`MSCG ` - * :ref:`OPT ` - * :ref:`POEMS ` - * :ref:`PYTHON ` - * :ref:`VORONOI ` * :ref:`ADIOS ` * :ref:`ATC ` * :ref:`AWPMD ` * :ref:`COLVARS ` + * :ref:`COMPRESS ` + * :ref:`GPU ` * :ref:`H5MD ` - * :ref:`ML-HDNNP ` * :ref:`INTEL ` + * :ref:`KIM ` + * :ref:`KOKKOS ` + * :ref:`LATTE ` + * :ref:`MACHDYN ` * :ref:`MDI ` * :ref:`MESONT ` - * :ref:`MOLFILE ` - * :ref:`NETCDF ` + * :ref:`MESSAGE ` + * :ref:`ML-HDNNP ` + * :ref:`ML-IAP ` * :ref:`ML-PACE ` - * :ref:`PLUMED ` - * :ref:`OPENMP ` - * :ref:`QMMM ` * :ref:`ML-QUIP ` + * :ref:`MOLFILE ` + * :ref:`MSCG ` + * :ref:`NETCDF ` + * :ref:`OPENMP ` + * :ref:`OPT ` + * :ref:`PLUMED ` + * :ref:`POEMS ` + * :ref:`PYTHON ` + * :ref:`QMMM ` * :ref:`SCAFACOS ` - * :ref:`MACHDYN ` + * :ref:`VORONOI ` * :ref:`VTK ` ---------- @@ -1857,8 +1857,8 @@ ML-QUIP package To build with this package, you must download and build the QUIP library. It can be obtained from GitHub. For support of GAP potentials, additional files with specific licensing conditions need -to be downloaded and configured. See step 1 and step 1.1 in the -``lib/quip/README`` file for details on how to do this. +to be downloaded and configured. The automatic download will from +within CMake will download the non-commercial use version. .. tabs:: @@ -1866,11 +1866,14 @@ to be downloaded and configured. See step 1 and step 1.1 in the .. code-block:: bash + -D DOWNLOAD_QUIP=value # download OpenKIM API v2 for build, value = no (default) or yes -D QUIP_LIBRARY=path # path to libquip.a (only needed if a custom location) - CMake will **not** download and build the QUIP library. But once you have - done that, a CMake build of LAMMPS with ``-D PKG_ML-QUIP=yes`` should - work. Set the ``QUIP_LIBRARY`` variable if CMake cannot find the QUIP library. + CMake will try to download and build the QUIP library from GitHub, if it is not + found on the local machine. This requires to have git installed. It will use the same compilers + and flags as used for compiling LAMMPS. Currently this is only supported for the GNU and the + Intel compilers. Set the ``QUIP_LIBRARY`` variable if you want to use a previously compiled + and installed QUIP library and CMake cannot find it. .. tab:: Traditional make diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 846e08f501..45728b5caf 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -1132,6 +1132,7 @@ Germano gerolf Gerolf Gershgorin +getter gettimeofday gewald Gezelter