From 1bd1256c17592fe3ee88fbb4ad1b175e079ec9b7 Mon Sep 17 00:00:00 2001 From: Dmitry Morozov Date: Mon, 13 Sep 2021 12:03:27 +0000 Subject: [PATCH] Added CP2K related options to CMake files --- CMakeLists.txt | 12 +++++++ cmake/gmxManageCP2K.cmake | 66 ++++++++++++++++++++++++++++++++++++ docs/install-guide/index.rst | 48 ++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 cmake/gmxManageCP2K.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 70a941f9e1..b18f414895 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,6 +181,13 @@ option(GMX_THREAD_MPI "Build a thread-MPI-based multithreaded version of GROMAC option(GMX_MIMIC "Enable MiMiC QM/MM interface (CPMD is required)" OFF) +option(GMX_CP2K "Enable CP2K QM/MM interface (CP2K 8.1 or later is required)" OFF) + +# We need to enable Fortran, because CP2K will be linked +if(GMX_CP2K) + enable_language(Fortran) +endif() + option(GMX_FAHCORE "Build a library with mdrun functionality" OFF) mark_as_advanced(GMX_FAHCORE) @@ -393,6 +400,11 @@ include(gmxManageMPI) ######################################################################## include(gmxManageMimic) +######################################################################## +#Process CP2K settings +######################################################################## +include(gmxManageCP2K) + ######################################################################## #Process shared/static library settings ######################################################################## diff --git a/cmake/gmxManageCP2K.cmake b/cmake/gmxManageCP2K.cmake new file mode 100644 index 0000000000..99f5b70c04 --- /dev/null +++ b/cmake/gmxManageCP2K.cmake @@ -0,0 +1,66 @@ +# +# This file is part of the GROMACS molecular simulation package. +# +# Copyright (c) 2021, by the GROMACS development team, led by +# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, +# and including many others, as listed in the AUTHORS file in the +# top-level source directory and at http://www.gromacs.org. +# +# GROMACS is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. +# +# GROMACS is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with GROMACS; if not, see +# http://www.gnu.org/licenses, or write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# If you want to redistribute modifications to GROMACS, please +# consider that scientific software is very special. Version +# control is crucial - bugs must be traceable. We will be happy to +# consider code for inclusion in the official distribution, but +# derived work must not be called official GROMACS. Details are found +# in the README & COPYING files - if they are missing, get the +# official version at http://www.gromacs.org. +# +# To help us fund GROMACS development, we humbly ask that you cite +# the research papers on the package. Check out http://www.gromacs.org. + +if(GMX_CP2K) + + # Check that all necessary CMake flags are present + set(CP2K_DIR "" CACHE STRING "Path to the directory with libcp2k.a library") + set(CP2K_LINKER_FLAGS "" CACHE STRING "List of flags and libraries required for linking libcp2k. Typically this should be combination of LDFLAGS and LIBS variables from ARCH file used to compile CP2K") + if ((CP2K_DIR STREQUAL "") OR (CP2K_LINKER_FLAGS STREQUAL "")) + message(FATAL_ERROR "To build GROMACS with CP2K Interface both CP2K_DIR and CP2K_LINKER_FLAGS should be defined") + endif() + + # Add libcp2k and DBCSR for linking + set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -Wl,--allow-multiple-definition -L${CP2K_DIR} -lcp2k -L${CP2K_DIR}/exts/dbcsr -ldbcsr") + + # Add User provided libraries + set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} ${CP2K_LINKER_FLAGS}") + + # If we use GNU compilers then also libgfortran should be linked + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lgfortran") + endif() + + # If we use external MPI then Fortran MPI library should be linked + if (GMX_LIB_MPI) + # If Fortran MPI library is found then add it to GMX_COMMON_LIBRARIES + if (MPI_Fortran_FOUND) + list(APPEND GMX_COMMON_LIBRARIES ${MPI_Fortran_LIBRARIES}) + else() + message(FATAL_ERROR "Could not find Fortran MPI library which is required for CP2K") + endif() + endif() + +endif() + diff --git a/docs/install-guide/index.rst b/docs/install-guide/index.rst index 27859f51f7..45c9e1ac95 100644 --- a/docs/install-guide/index.rst +++ b/docs/install-guide/index.rst @@ -876,6 +876,54 @@ double-precision version of |Gromacs| compiled with MPI support: * ``-DGMX_DOUBLE=ON -DGMX_MPI -DGMX_MIMIC=ON`` +.. _installing with CP2K: + +Building with CP2K QM/MM support +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +CP2K QM/MM interface integration will require linking against libcp2k +library, that incorporates CP2K functionality into |Gromacs|. + +1. Download, compile and install CP2K (version 8.1 or higher is required). +CP2K latest distribution can be downloaded `here `_. +For CP2K specific instructions please `follow `_. +You can also check instructions on the `oficial CP2K web-page `_. + +2. Make :file:`libcp2k.a` library by executing the following command:: + make ARCH= VERSION= libcp2k + +The library archive (*e.g.* :file:`libcp2k.a`) should appear in the :file:`{}/lib/{}/{}/` directory. + +3. Configure |Gromacs| with :command:`cmake`, adding the following flags. + +Build should be static: +* ``-DBUILD_SHARED_LIBS=OFF -DGMXAPI=OFF -DGMX_INSTALL_NBLIB_API=OFF`` + +Double precision in general is better than single for QM/MM +(however both options are viable): +* ``-DGMX_DOUBLE=ON`` + +FFT, BLAS and LAPACK libraries should be the same between CP2K and |Gromacs|. +Use the following flags to do so: + +* ``-DGMX_FFT_LIBRARY= -DFFTWF_LIBRARY= -DFFTWF_INCLUDE_DIR=`` +* ``-DGMX_BLAS_USER=`` +* ``-DGMX_LAPACK_USER=`` + +4. Compilation of QM/MM interface is controled by the following flags. + +``-DGMX_CP2K=ON`` + Activates QM/MM interface compilation +``-DCP2K_DIR="/lib/local/psmp`` + Directory with libcp2k.a library +``-DCP2K_LINKER_FLAGS=""`` + Other libraries used by CP2K. Typically that should be combination + of LDFLAGS and LIBS from the ARCH file used for CP2K compilation. + Sometimes ARCH file could have several lines defining LDFLAGS and LIBS + or even split one line into several using "\". In that case all of them + should be concatenated into one long string without any extra slashes + or quotes. + .. _suffixes: Changing the names of |Gromacs| binaries and libraries -- 2.22.0