This page describes how to set up Mac OS X to run Amber specifically. However, this setup is applicable to many other computational chemistry/physics packages as well.
It is more an overview of using a particular package manager to build and maintain Open Source software from the UNIX world on your Mac computer. OS X is, after all, built on a registered UNIX kernel—Darwin.
The first section describes how to use and set up my package manager of choice, MacPorts (previously DarwinPorts). There are alternatives, with homebrew being the most popular. One of the main reasons I like MacPorts better, however, is their selection abilities (you can install different versions of compilers, for instance, and let MacPorts manage symlinks to them), and they build to /opt/local rather than /usr/local (reducing the chance that you will see homebrew files getting in the way).
The second describes installing the necessary packages to build and run Amber.
If you just wish to set your Mac up to run Amber, look at the "Installing MacPorts" section below (especially for Mac OS X Lion), and the "Preparing for AMBER" section near the bottom.
Table of Contents
|
MacPorts
MacPorts is a package manager (like yum in Red Hat/CentOS/Fedora or aptitude in Debian/Ubuntu) that manages software by compiling packages and their dependencies from source code.
MacPorts is used completely using the command line (use the Terminal program that ships with Mac OS X or some alternative terminal program). There are some GUI alternatives (e.g. PortAuthority), but since you need to use the command line for most computational chemistry software, you should probably just stick with the command-line for MacPorts as well. The tutorial below deals with the command-line interface to MacPorts.
Installing MacPorts
Before installing MacPorts, you will have to install Apple's developer tools (Xcode). You can download this from the Mac App store (just search for "xcode").
After installing XCode, you need to agree to the license. So run the following command in a terminal
sudo xcodebuild -license
read through the license (or type q to skip through it), and type agree when prompted. After this, you need to install the command-line tools. Running the following command in the terminal installs the command-line tools:
xcode-select —install
Installing XQuartz
Starting with Mac OS X 10.8, Apple stopped including X11 with their OS. Instead, you have to download the XQuartz program.
You can download XQuartz here
Looking for packages
You'll often find yourself wanting to search for specific packages for a number of reasons.
- You want to know if MacPorts has a port for your program.
- You don't know the exact name that MacPorts uses for that program.
The command to do this is port search. For example, suppose we want to find which versions of the gcc compiler are available.
$ port search gcc4*
gcc43 @4.3.6_11 (lang)
The GNU compiler collection
gcc44 @4.4.7_10 (lang)
The GNU compiler collection
gcc45 @4.5.4_12 (lang)
The GNU compiler collection
gcc46 @4.6.4_9 (lang)
The GNU compiler collection
gcc47 @4.7.4_5 (lang)
The GNU compiler collection
gcc48 @4.8.5 (lang)
The GNU compiler collection
gcc49 @4.9.3 (lang)
The GNU compiler collection
gcc410 @5-20140817 (lang)
this port is only a stub and has been made obsolete by gcc5
Found 8 ports.
In the above list, port versions are listed next to their names following the @ sign. For example, the first port matching the characters "gcc4" is gcc43, version number 4.3.6_11. The package name itself is gcc43 and that is the name that MacPorts will recognize that port with.
Installing ports
Ports are installed in the prefix /opt/local. Programs are stored in /opt/local/bin, libraries are stored in /opt/local/lib, and include header files are stored in /opt/local/include.
To install ports, you need root access (administrator privileges). To provide a particular command with administrator privileges (the ultimate administrator of a UNIX operating system is called the root user), use the sudo command. For instance, to build GCC 4.9, use the command
bash $ sudo port install gcc49
Variants
Some ports have different install options. For instance, NetCDF, the common binary file format used to efficiently store Amber trajectories, can be optionally built with Fortran support. While Amber builds its own NetCDF, which makes this particular package unnecessary for now, it provides a good example for using variants. To see what variants are available for a particular port, use the command port variants <portname>
Using netcdf-fortran as an example:
$ port variants netcdf-fortran
netcdf-fortran has the variants:
dragonegg33: Build using the MacPorts dragonegg 3.3 compiler
* conflicts with dragonegg34 g95 gcc44 gcc45 gcc46 gcc47 gcc48 gcc49 gcc5 gcc6
dragonegg34: Build using the MacPorts dragonegg 3.4 compiler
* conflicts with dragonegg33 g95 gcc44 gcc45 gcc46 gcc47 gcc48 gcc49 gcc5 gcc6
g95: Build using the g95 Fortran compiler
* conflicts with dragonegg33 dragonegg34 gcc44 gcc45 gcc46 gcc47 gcc48 gcc49 gcc5 gcc6
gcc44: Build using the MacPorts gcc 4.4 compiler
* conflicts with dragonegg33 dragonegg34 g95 gcc45 gcc46 gcc47 gcc48 gcc49 gcc5 gcc6
gcc45: Build using the MacPorts gcc 4.5 compiler
* conflicts with dragonegg33 dragonegg34 g95 gcc44 gcc46 gcc47 gcc48 gcc49 gcc5 gcc6
gcc46: Build using the MacPorts gcc 4.6 compiler
* conflicts with dragonegg33 dragonegg34 g95 gcc44 gcc45 gcc47 gcc48 gcc49 gcc5 gcc6
gcc47: Build using the MacPorts gcc 4.7 compiler
* conflicts with dragonegg33 dragonegg34 g95 gcc44 gcc45 gcc46 gcc48 gcc49 gcc5 gcc6
gcc48: Build using the MacPorts gcc 4.8 compiler
* conflicts with dragonegg33 dragonegg34 g95 gcc44 gcc45 gcc46 gcc47 gcc49 gcc5 gcc6
gcc49: Build using the MacPorts gcc 4.9 compiler
* conflicts with dragonegg33 dragonegg34 g95 gcc44 gcc45 gcc46 gcc47 gcc48 gcc5 gcc6
[+]gcc5: Build using the MacPorts gcc 5 compiler
* conflicts with dragonegg33 dragonegg34 g95 gcc44 gcc45 gcc46 gcc47 gcc48 gcc49 gcc6
gcc6: Build using the MacPorts gcc 6 compiler
* conflicts with dragonegg33 dragonegg34 g95 gcc44 gcc45 gcc46 gcc47 gcc48 gcc49 gcc5
mpich: Build using the MPICH compiler
* conflicts with mpich_devel openmpi openmpi_devel universal
mpich_devel: Build using the MPICH-devel compiler
* conflicts with mpich openmpi openmpi_devel universal
openmpi: Build using the OpenMPI compiler
* conflicts with mpich mpich_devel openmpi_devel universal
openmpi_devel: Build using the OpenMPI-devel compiler
* conflicts with mpich mpich_devel openmpi universal
universal: Build for multiple architectures
In order to enable Fortran support, we need to use one of the gcc4x variants. I will choose gcc49 because that is one of the newer stable releases of GCC as of January, 2016, but still not the newest. You can use whatever version you want, just make sure to substitute the version you chose instead of version 4.9 where appropriate. Use "+" to add a variant to the port install. For instance, the above example would be:
bash$ sudo port install netcdf-fortran +gcc48
---> Computing dependencies for netcdf-fortran
... output may vary
---> Cleaning netcdf
---> Scanning binaries for linking errors
---> No broken files found.
Debugging install problems
A number of problems can crop up when building. No package manager is bug-free, and occasionally you will hit a corner case that has not been tested by the developers. If this is the case, you may see something like:
bash$ sudo port install molden
---> Computing dependencies for molden
---> Fetching archive for molden
---> Attempting to fetch molden-5.0-20111201124000_0+gcc44.darwin_11.x86_64.tgz from http://packages.macports.org/molden
---> Fetching molden
---> Verifying checksum(s) for molden
Error: Checksum (sha256) mismatch for molden5.0.tar.gz
Error: Target org.macports.checksum returned: Unable to verify file checksums
Log for molden is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_science_molden/molden/main.log
Error: Status 1 encountered during processing.
To report a bug, see <http://guide.macports.org/#project.tickets>
If you do see a problem installing a port, you should install with the verbose option. Do this by putting -v right after port (before install). Note that the positioning of arguments to port is crucial! Furthermore, if you put the flags in the wrong place, they will just be silently ignored. When verbose mode is toggled, the above error is expanded to
bash$ sudo port -v install molden
---> Computing dependencies for molden.
---> Verifying checksum(s) for molden
---> Checksumming molden5.0.tar.gz
Error: Checksum (sha256) mismatch for molden5.0.tar.gz
Portfile checksum: molden5.0.tar.gz sha256 5672b928ad55d2d4963eeab278a6c7858faabd6855a2b45eb38e2f295d8ccb2g
Distfile checksum: molden5.0.tar.gz sha256 5672b928ad55d2d4963eeab278a6c7858faabd6855a2b45eb38e2f295d8ccb2f
The correct checksum line may be:
checksums rmd160 f87db8e11ca4076074ae9a1c0e9e4b7f7d5c28ab \
sha256 5672b928ad55d2d4963eeab278a6c7858faabd6855a2b45eb38e2f295d8ccb2f
Error: Target org.macports.checksum returned: Unable to verify file checksums
Warning: the following items did not execute (for molden): org.macports.activate org.macports.checksum org.macports.extract org.macports.patch org.macports.configure org.macports.build org.macports.destroot org.macports.install
Log for molden is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_science_molden/molden/main.log
Error: Status 1 encountered during processing.
To report a bug, see <http://guide.macports.org/#project.tickets>
With verbose messages, you can see that the error is that the checksums do not match between the file that was downloaded and the file the MacPorts thinks it should use (this is a security measure).
Sometimes packages are updated silently. That is, the official released source code tarball is changed without notification to anybody, so this error will occur. In my experience, it happens fairly frequently with the Molden program.
If this happens to you, try to update MacPorts first (see below for updating). If that still doesn't work, you can edit the Portfile directly and change the checksums line to match the checksums of the downloaded file. Portfiles are stored in
/opt/local/var/macports/sources/rsync.macports.org/release/ports/<port_category>/<port_name>/Portfile
[ NOTE: The next error is outdated, and I have not seen it in some time since Apple migrated to clang as their base C compiler from gcc. I leave it in here in case it is still helpful]
The other "common" error that is easily fixed that I've found is an error message along the lines of
gcc -g -Wall -O2 -fdollars-in-identifiers -mmacosx-version-min=10.5 -D_DARWIN_USE_64_BIT_INODE -arch x86_64 -fno-omit-frame-pointer -pagezero_size 0x100000 -I. -DSBCL_PREFIX=\"'/opt/local'\" -c -o alloc.o alloc.c
cc1: error: unrecognized command line option "-arch"
make: *** [alloc.o] Error 1
shell command "ulimit -s 8192 && unset LD_PREBIND && unset LD_PREBIND_ALLOW_OVERLAP && cd /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_lang_sbcl/sbcl/work/sbcl-1.0.52 && CC=/Developer/usr/bin/llvm-gcc-4.2 CXX=/Developer/usr/bin/llvm-g++-4.2 CPP=/Developer/usr/bin/llvm-cpp-4.2 sh make.sh "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_lang_sbcl/sbcl/work/sbcl-1.0.48-x86-darwin/src/runtime/sbcl --core /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_lang_sbcl/sbcl/work/sbcl-1.0.48-x86-darwin/output/sbcl.core --disable-debugger --sysinit /dev/null --userinit /dev/null" --prefix=/opt/local" returned error 2
Error: Target org.macports.build returned: shell command failed (see log for details)
Warning: the following items did not execute (for sbcl): org.macports.activate org.macports.build org.macports.destroot org.macports.install
Log for sbcl is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_lang_sbcl/sbcl/main.log
Error: Status 1 encountered during processing.
To report a bug, see <http://guide.macports.org/#project.tickets>
This error occurs because -arch is not a GNU GCC compiler flag. It is a flag added to the GNU compilers by Apple in the version they release with Xcode. Typically, most ports explicitly specify the compiler they use (usually the Xcode compilers unless otherwise specified). However, in some cases parts of the package wind up getting built with the default gcc/g++ available in the PATH. If you have installed another gcc port and have that one activated, you may see this message.
The easy way to fix the above error is to just select the Apple Xcode compilers using gcc_select or port select. This is described below in more detail.
Updating MacPorts and Upgrading Packages
New ports and updates to existing ports are being added all the time to MacPorts. It is typically a good idea to keep your port definitions and ports themselves up-to-date. To upgrade your MacPorts definitions (or your base version of MacPorts if it is out-of-date), run the command sudo port selfupdate:
bash$ sudo port selfupdate
---> Updating MacPorts base sources using rsync
MacPorts base version 2.3.4 installed,
MacPorts base version 2.3.4 downloaded.
---> Updating the ports tree
---> MacPorts base is already the latest version
The ports tree has been updated. To upgrade your installed ports, you should run
port upgrade outdated
To see what packages are outdated, just run
port outdated
To update the outdated ports, follow their suggestion and run the command
sudo port upgrade outdated
You can also upgrade ports on a port-by-port basis by replacing outdated with a particular port name in the above command. It is important to note that MacPorts by default does not remove old versions of installed ports. It simply deactivates them. If you want to clean up all outdated ports, you can use the command
sudo port -u uninstall
You can also remove all inactive ports via the command
sudo port uninstall inactive
That last one will make more sense after reading the next section (about MacPorts introspection/querying capabilities).
MacPorts Introspection / Querying
MacPorts provides easy ways of determining the state that MacPorts and various installed ports are in. The following keywords are recognized by port:
- all: lists all ports listed in the tree
- active: the list of all "active" ports, or ports whose programs, libraries, and header files are in /opt/local/bin, /opt/local/lib, and /opt/local/include, respectively.
- inactive: all ports that are installed but not active.
- installed: all ports that are installed (lists separate installed versions of the same package if more than one version is installed)
- uninstalled: all ports that are not installed
- outdated: lists all ports whose port definitions are newer than the version installed/active.
There are several others, but I've never used them before. The rest are in port's man page (man port).
For instance, to get a list of installed ports, use the commands
port list installed
or
port installed
Likewise for the other ports (port list always works, but not all keywords work with just the port command. For instance, all does not work as port all).
You can also combine some. For instance, to get a list of ports that are inactive but installed, you can run
port installed inactive
Activating/Deactivating Ports
If you want to change the version of a port that is "visible" in /opt/local, you can deactivate the undesired port and activate the desired one. (You should deactivate the one you don't want before activating the one you do).
For instance, to change the version of zlib from 1.2.5_0 to 1.2.4_1, you can use the following commands
sudo port deactivate zlib @1.2.5_0
sudo port activate zlib @1.2.4_1
If you have problems (because of dependencies), you can use the -f flag to force port's hand. Note, though, that this may cause unforeseen errors.
MacPorts is Taking Up Too Much Space!
If you are running low on hard drive space (do you have one of those fancy solid state drives that only has 60-120 GB of space?), you may notice that MacPorts takes up a lot of space. There are 2 things you can do to reclaim space that MacPorts is taking up, but not really using. For instance, I have 479 ports installed taking up a total of 11 GB of space (which is after I uninstalled inactive ports).
The first is to remove (uninstall) inactive or unused ports.
sudo port uninstall inactive
The second is to clean all of the build files and source tarballs from your computer. These really only save time when reinstalling the ports, since they don't have to be downloaded again, and can be resumed where they were ended. To do this, run the command
sudo port clean --all all
This removes all work directories/build directories for every package as well as the distribution tarballs. After running this command, my MacPorts directory dropped in size to 8.2 GB. Some dist files are not removed due to potential dependencies. If you want to get rid of all of them regardless, you'll need to run the command
sudo port -f clean --all all
Ports With Multiple Versions
Some ports overlap with others. For instance, there are several versions of GCC available:
- GCC 4.3
- GCC 4.4
- GCC 4.5
- GCC 4.6
- GCC 4.7
- GCC 4.8
- GCC 4.9
- GCC 5
- Some other Apple-specific versions
- The version that came with Xcode
In order to build many packages (and Amber, in particular), you will need a full GCC version complete with a Fortran compiler.
Another example is Python, which has versions
- Python 2.4
- Python 2.5
- Python 2.6
- Python 2.7
- Python 3.1
- Python 3.2
- Python 3.3
- Python 3.4
- Python 3.5
available. To allow people to take advantage of all of these ports, these ports offer a select port to work with them. For the above two examples, there is gcc_select and python_select. Both are ports themselves and must be installed to switch between them.
However, as of ca. May 2011, the select scripts have been incorporated into the port command itself (after they are installed, of course). To use this ability, the command structure is
sudo port select <port_group> <port_instance>
To get a list of registered options, the command becomes
port select --list <port_group>
For instance, on my machine:
bash$ port select --list gcc
Available versions for gcc:
mp-gcc47
mp-gcc48 (active)
mp-gcc49
mp-gcc5
none
You can see that my active GCC port is the MacPorts-installed GCC 4.8 version. To change to the 4.9 version, I would use the command sudo port select gcc mp-gcc49:
Packages To Install (From MacPorts)
The list of packages below are just packages that I have found useful in my work, along with their variants. Packages listed with a "*" are required to build Amber completely.
- gcc49 *: Provides the full GCC package, including the Fortran compiler gfortran, which is necessary for Amber
- mpich-gcc49 *: Provides an MPI built around GCC 4.8 so you can build Amber in parallel
- python27 : The most up-to-date Python 2 version. Useful to install 3rd-party Python libraries from MacPorts
- py27-matplotlib : Python plotting library (used by MdoutAnalyzer.py)
- py27-scipy : Python package with numerous scientific and statistical analysis capabilities (only needed for using kernel density estimates to smooth histograms in mdout_analyzer.py)
- py27-numpy : Numerical Python has optimized mathematical structures for Python
- molden +gcc49 : Old (but classic) molecular visualizer for output from ab initio programs. Use the gcc49 variant to avoid building GCC 5
- grace : plotting program with a nice GUI
- gnuplot : classic plotting program with a command-line interface
- bkchem : 2D chemistry structure drawing tool
- chemtool : another 2D chemistry structure drawing tool
- netpbm : Assembles images into a movie (MPEG) file. Used by VMD
- pymol : A classic molecular visualization program written in Python
Preparing for AMBER
To prepare for Amber (by installing the packages marked with a "*" above), execute the following commands:
sudo port install gcc49
sudo port install mpich-gcc49
sudo port select --set gcc mp-gcc49
sudo port select --set mpi mpich-gcc49-fortran
The first command installs gcc version 4.8 and a set of scripts that can swap between different GCC versions (by changing around soft links, in case you're curious). The second command installs the MPICH libraries built with GCC 4.8. The final commands select GCC 4.8 and the GCC 4.8-compiled MPICH as the active versions of the GNU compilers and MPI implementation, respectively.
Other Programs to Install
The following list of packages are other programs I installed, but not via MacPorts. These are typically not open source and require an online download.
- VMD : A molecular visualization program that I use the most.
Setting up to Install Amber
- Install gcc49 and mpich-gcc49 from MacPorts as described above.
- Make GCC 4.9 the default GCC version : sudo port select gcc mp-gcc49
- Make MPICH the default MPI implementation : sudo port select mpi mpich-gcc49-fortran
Now you can follow the default instructions on building Amber Version 11(+AT 1.5) or Version 12, optionally using the -macAccelerate flag for the configure step if you wish to take advantage of Apple's Accelerate framework (optimized math libraries).