Added CP2K related options to CMake files
authorDmitry Morozov <aracsmd@gmail.com>
Mon, 13 Sep 2021 12:03:27 +0000 (12:03 +0000)
committerMark Abraham <mark.j.abraham@gmail.com>
Mon, 13 Sep 2021 12:03:27 +0000 (12:03 +0000)
CMakeLists.txt
cmake/gmxManageCP2K.cmake [new file with mode: 0644]
docs/install-guide/index.rst

index 70a941f9e1c53ca0b908dd6ea971be02e5029934..b18f414895b4a685ac84c55f5db957fbfcf8f340 100644 (file)
@@ -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 (file)
index 0000000..99f5b70
--- /dev/null
@@ -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()
+
index 27859f51f7d955ce66740c64a07ec2a7db4acd2d..45c9e1ac950665aad2d40eff8381f300feda287e 100644 (file)
@@ -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 <https://github.com/cp2k/cp2k/releases/>`_.
+For CP2K specific instructions please `follow <https://github.com/cp2k/cp2k/blob/master/INSTALL.md>`_.
+You can also check instructions on the `oficial CP2K web-page <https://www.cp2k.org/howto>`_.
+
+2. Make :file:`libcp2k.a` library by executing the following command::
+    make ARCH=<your arch file> VERSION=<your version like psmp> libcp2k
+
+The library archive (*e.g.* :file:`libcp2k.a`) should appear in the :file:`{<cp2k dir>}/lib/{<arch>}/{<version>}/` 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=<your library like fftw3> -DFFTWF_LIBRARY=<path to library> -DFFTWF_INCLUDE_DIR=<path to directory with headers>``
+* ``-DGMX_BLAS_USER=<path to your BLAS>`` 
+* ``-DGMX_LAPACK_USER=<path to your LAPACK>``
+
+4. Compilation of QM/MM interface is controled by the following flags.
+
+``-DGMX_CP2K=ON``
+    Activates QM/MM interface compilation
+``-DCP2K_DIR="<path to cp2k>/lib/local/psmp``
+    Directory with libcp2k.a library
+``-DCP2K_LINKER_FLAGS="<combination of LDFLAGS and LIBS>"``
+    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