Wei Zhang's Blog

09 Feb 2023

Build Gromacs with Colvars and PLUMED support

  1. Required packages

    1.1. Colvars

    I used a modified version of Colvars, which requires LibTorch package. In general, it suffices to work with the official version, which can be downloaded using

     git clone https://github.com/Colvars/colvars.git
    

    1.2. Gromacs

    As this post is written, Colvars supports gromacs within the 2020.x or 2021.x. So I use gromacs-2021.6 in the following install.

    1.3. PLUMED

    PLUMED library also provides many enhanced sampling methods and can work together with Gromacs. It should be installed first in order to build a gromacs that supports PLUMED.

    The installation is standard, as described on its official site.

  2. Patch gromacs

    2.1. Colvars Patch

    Under the root directory of Colvars, run the following command.

     ./update-colvars-code.sh -f /path/to/gromacs-2021.6
    

    2.2. PLUMED Patch

    Go to the root directory of Gromacs, run the following command.

    	plumed patch -p
    

    and select the propriate gromacs version to patch.

  3. Build the patched gromacs

    After uncompressing the gromacs package, enter its root directory and run:

     mkdir build 
    
     cd build
    
     cmake .. -DGMX_MPI=on  \
     	-DCMAKE_INSTALL_PREFIX=/path/to/install\
     	-DFFTWF_LIBRARY=/path/to/libfftw3f.so \
     	-DFFTWF_INCLUDE_DIR=/path/to/fftw/header/include/ 
    
     make -j 4
    
     make check
    
     make install
    

    Remarks (GPU support) This is optional. To enable GPU, one can run

     cmake .. -DGMX_MPI=on  \
     	-DCMAKE_INSTALL_PREFIX=/path/to/install\
     	-DFFTWF_LIBRARY=/path/to/libfftw3f.so \
     	-DFFTWF_INCLUDE_DIR=/path/to/fftw/header/include/ \
     	-DGMX_GPU=CUDA -DCUDA_TOOLKIT_ROOT_DIR=/cuda/root/dir/
    

    Troubleshooting

    I had to resolve the following issues during installation.

    3.1. I encountered the following warning due to the fact that there are two libgomp library installed on my machine.

    Cannot generate a safe runtime search path for target libgromacs because files in some directories may conflict with libraries in implicit directories:

    runtime library [libgomp.so.1] in /usr/lib/gcc/x86_64-linux-gnu/10 may be hidden by files in: /home/to/mambaforge/lib

    To resolve it, one can specify the libgomp installed by mamba via:

    -DOpenMP_gomp_LIBRARY=/home/to/mambaforge/lib/libgomp.so
    

    3.2. Link to LibTorch

    I need to specify the location of the LibTorch package when configuring the patched gromacs. (This step is only neccessary because my version of Colvars requires LibTorch.) This can be done by adding the following argument to the cmake command.

    -DTorch_DIR=/path/to/libtorch/share/cmake/Torch
    

    3.3. Although the make command can work successfully and gromacs libraries can be built, error occurs when executing make check. It turns out that the error is due to the fact that the complier /usr/bin/g++ does not work well when building executables that require libgmxapi_mpi.so. This issue can be resolved by specifying mpicxx as compiler. The complete cmake command is as follows.

     cmake .. -DGMX_MPI=on  \
     	-DCMAKE_INSTALL_PREFIX=/path/to/install\
     	-DFFTWF_LIBRARY=/path/to/libfftw3f.so \
     	-DFFTWF_INCLUDE_DIR=/path/to/fftw/header/include/\
    		-DTorch_DIR=/path/to/libtorch/share/cmake/Torch \
     	-DCMAKE_CXX_COMPILER=/usr/bin/mpicxx
    

    With this command, both make and make check run correctly.