How to install GROMACS

 

If you’re delving into the captivating realm of molecular modeling, chances are you’ve come across GROMACS a popular tool for molecular simulations.

As a beginner, it may seem intimidating to go through the installation procedure for this software.

In this article, I will show you how to quickly install GROMACS on your machine. Take it easy, in most cases it’s a quick and straightforward endeavor that will take just a few minutes.

 

Note
In this tutorial, I will consider that you have some familiarity with the Linux command line. However, I’ll strive to keep things as uncomplicated as possible, ensuring that even newcomers find this guide accessible.

 

 

 

MD simulations require significant computational resources, making common laptop or desktop hardware unsuitable for running them effectively.

To perform most MD simulations, high-performance computing clusters or specially designed GPU workstations are typically required. Although GROMACS has the capability to run on a laptop, it is generally recommended not to rely on such setups.

Linux is the preferred platform for MD simulations. Therefore, we’ll start by looking at the process to install GROMACS on a Linux machine. Below are the six simple steps to get you started:

 

Ensure your system is up to date by running these commands:

1
2
sudo apt update 
sudo apt upgrade

 

Before diving into GROMACS installation, ensure you have these two essential prerequisites installed: cmake and build-essential.

Let’s start by installing cmake.

1
sudo apt install cmake

 

You can check the version with:

1
cmake -version

 

Now we can proceed to install build-essential:

1
sudo apt install build-essential

 

Now, let’s assume you are interested in GROMACS 2022.3.

To get started, the first thing you should do is download the tarball of this specific version of GROMACS. You can access a list of all available GROMACS versions here. Once you’ve made your selection, proceed to download and unpack the GROMACS version you need, in this example, GROMACS 2022.3.

1
2
wget https://ftp.gromacs.org/gromacs/gromacs-2022.3.tar.gz
tar xvf gromacs-2022.3.tar.gz

 

Now create a build directory and move into it.

1
2
3
cd gromacs-2022.3
mkdir build
cd build

 

Now, it’s time to compile the source code and install GROMACS:

1
2
3
4
cmake .. -DGMX_BUILD_OWN_FFTW=ON -DREGRESSION_DOWNLOAD=ON
make 
make check 
sudo make install

To check the version you can still use the gmx -version command.

Note

This is the stage where one can customize its GROMACS installation as needed. For instance, if you want to get the mpi version of GROMACS you can simply add this flag -DGMX_MPI=on.

By default GROMACS will be installed in /usr/local/gromacs. If you want to install it in a specific directory you can add this to the cmake command -DCMAKE_INSTALL_PREFIX=/path/to/dir/.

1
2
3
4
cmake .. -DGMX_BUILD_OWN_FFTW=ON -DREGRESSION_DOWNLOAD=ON -DGMX_MPI=on -DCMAKE_INSTALL_PREFIX=/path/to/dir
make 
make check 
sudo make install

For more details on how to customize your installation you can refer to the official guide.

 

Activate GROMACS by using the following command every time you open a new terminal session:

1
source /usr/local/gromacs/bin/GMXRC

Please note that if you opted to install it in a different directory, make sure to source from that specific location.

 

Once you are done with the installation you may be interested in proceeding with a hands-on GROMACS tutorial.

 

 

In this section, I’ll guide you through two straightforward methods for getting GROMACS up and running on your Mac. You have two options:

  1. The Homebrew Approach: Using the Homebrew package manager
  2. The Recommended Method: The standard procedure for building GROMACS

Now, let’s dive into each of these methods, so you can choose the one that suits you best.

 

 

The first approach to installing GROMACS is the “quick and dirty” method. If you prefer a more customizable installation, I’ll walk you through the recommended approach in the next section. But for now, let’s dive into this straightforward option.

 

1. Installing Homebrew

If you don’t already have homebrew installed just follow the instructions on this link. Don’t worry, you will just need to copy and paste a couple of commands into your terminal. The whole process should take no more than a few minutes.

 

2. Installing GROMACS with the brew command

Once Homebrew is up and running on your system, we’re ready to proceed with the GROMACS installation. Open your terminal and use the brew command as shown below:

1
brew install gromacs

Congratulations. You have just installed GROMACS on your Mac.

 

3. Verify the installation was correct

Congratulations. You have just installed GROMACS on your Mac. To verify that everything proceeded according to our plans you can type the following command:

1
gmx -version

 

This command should display the GROMACS version as well as other information on the software.

Warning
gmx: command not found means that the installation procedure went wrong. Verify that you did everything correctly. Alternatively, try the second approach.

 

 

If you’re looking for a specific version of GROMACS or desire more control over your installation, the standard approach outlined in the official guide is your best bet. Keep in mind that this method offers greater customization but will take a bit more time compared to the previous method.

 

Before diving into GROMACS installation, ensure you have a couple of essential tools in place. If you don’t already have them, use Homebrew to install wget and cmake with these commands:

1
2
brew install cmake 
brew install wget

 

From here on the procedure is very similar to the one reported above for Linux.

Let’s say that you are interested in GROMACS 2020.5. The first thing you should do is download the tarball of this specific version of GROMACS. You can find all the available GROMACS versions here.

Go to the folder where you want to download the program (e.g., Applications) and install GROMACS via wget.

1
wget https://ftp.gromacs.org/gromacs/gromacs-2020.5.tar.gz

 

When the download is over you can unpack the file with tar:

1
tar xvf gromacs-2020.5.tar.gz

 

Change directory:

1
cd gromacs-2020.5

 

Make a new directory named build and move inside it.

1
2
mkdir build
cd build

 

Type this command:

1
cmake .. -DGMX_BUILD_OWN_FFTW=ON -DREGRESSION_DOWNLOAD=ON

 

Now you need to run a sequence of three commands to compile the source code. This will get some time to complete.

1
2
3
make 
make check 
sudo make install

 

Now you have successfully installed GROMACS on your machine. To activate it you have to source it with the following command.

1
source /usr/local/gromacs/bin/GMXRC

 

To check the version you can still use the gmx -version command we previously saw.

Note
You will need to source GROMACS every time you open a new terminal.