These notes are specifically how to compile GROMACS on a Mac.
We’ll need gcc
and cmake
,netiher of which will be on your Mac by default. Luckily, to get the latter we’ll install MacPorts, which is a Mac package manager (a bit like apt-get
on Ubuntu or yum
on CentOS) that let’s you install all sorts of useful Linux tools and Python packages.
First, therefore, follow the instructions on how to install MacPorts.This does take a bit of time, if you haven’t done it before, as you need to download install Xcode, which is Apple’s Developer environment. Then installing MacPorts itself is simply downloading a package as described on the page.
Now we can install cmake
(and for good measure, although not essential, let’s install wget
as well as that will be useful in a moment).
sudo port install cmake wget
Check we have gcc
$ gcc --version
(It should spew a load of information) . Likewise
$ cmake --version
Ok, at this point you can either head over to the GROMACS source code download page in your browser and choose which version and download it. Or (and perhaps you are doing this remotely via a terminal, or sometimes this just faster), let’s get it directly and then untar the tarball.
$ cd
$ cd packages/
$ wget ftp://ftp.gromacs.org/pub/gromacs/gromacs-2018.4.tar.gz
$ tar zxcf gromacs-2018.4.tar.gz
$ cd gromacs-2018.4
We need to create a folder to build i.e. compile all the source code…
$ mkdir build
$ cd build
Now we can configure the compilation using cmake, compile it and then install!
cmake .. -DGMX_BUILD_OWN_FFTW=ON -DCMAKE_INSTALL_PREFIX='/usr/local/gromacs/4.6.5/‘
The ..
is telling cmake
to look in the parent directory for the source code. The first flag is saying that we want to automatically download and compile our own version of the Fourier transform library FFTW (rather than do it manually), whilst the second flag is overriding the default installation location of /usr/local/gromacs
and appending the version number. This is a good idea so you can have multiple versions of GROMACS all installed on the same machine. Other flags are available (for MPI, GPUs etc), but let’s keep it simple for now. The cmake
command will spew all sorts of checks and decisions. Don’t worry if you see lines with Failed
– you’ll know if it thinks it can’t compile GROMACS. On my laptop it took 30 seconds. Now we can compile. Here we can speed things up a bit by telling make
to use all the cores on your machine where it can, which on my laptop is 4.
$ make -j 4
Again lots will zoom by in the terminal; the first thing it will do is download FFTW
and compile that, then it will compile GROMACS proper. This takes a bit longer (just under 7 minutes on my laptop).
Finally, all we have to do is install i.e. move all the binaries, forcefield files etc into the right place in the file tree.
$ sudo make install
This last command has to be done with root privileges (i.e. sudo
) as we are moving files into /usr/local/gromacs
which is owned by root.
That’s it. To add GROMACS to your $PATH
simply
$ source /usr/local/gromacs/2018.4/bin/GMXRC
and you should be able to issue
$ gmx --version | head -1
:-) GROMACS - gmx, 2018.4 (-: