Category: Scientific computing

El Capitan for Computational Materials Science in 2016

Every few years, I give my laptop a fresh start and remove all the debris (applications, libraries, updates) that have built up. This time I started with a clean install of Mac OS 10.11 (El Capitan).

  • Basics

The first step is to install the essentials including Dropbox, Evernote, Todoist, Xcode (with xcode-select --install), Slack, Mendeley, MS Office, gcc/gfortranPython superpack, VESTA, Transmission, Mactex, Texmaker, Unrar, VLC, Adobe Creative Suite, iTerm, Textmate, XQuartz.

  • Fortran

While it is possible to survive using gfortan and freely available maths libraries, Intel Fortran and MKL tend to be faster and better tested (easier to compile) in my experience. For non-commericial purposes Intel Composer is now free for OS X. The package installs in a few clicks, but be sure source the variables in your .bash_profile:
source /opt/intel/mkl/bin/ intel64
source /opt/intel/bin/ intel64

Finally you will need to make the MKL fast fourier transforms (FFTs) for use in most solid-state simulation packages:
cd $MKLROOT/interfaces/fftw3xf/
sudo make libintel64 CC=gcc

The outcome:
Arons-Air-V:~ aron$ which ifort
Arons-Air-V:~ aron$ ifort --version
ifort (IFORT) 16.0.1 20151020

  • Openmpi

To enable parallelism, I downloaded the latest source code of openmpi (1.10.1).
./configure -prefix=/usr/local/openmpi-1.10.1 CC=gcc FC=ifort F77=ifort
sudo make install

be patient… it can easily take 20 minutes. Finally add to your .bash_profile:
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/openmpi-1.10.1/lib/
export PATH=./:/usr/local/openmpi-1.10.1/bin:$PATH

The outcome:
Arons-Air-V:~ aron$ which mpif90
Arons-Air-V:~ aron$ mpif90 --version
ifort (IFORT) 16.0.1 20151020

  • Phonopy

We use this open-source lattice-dynamics package a lot in our research. There are a few more libraries to install first:
sudo easy_install pip
pip2 install lxml
pip2 install pyyaml
export CC=/usr/local/bin/gcc

then after expanding the source code, simply type:
python install

The outcome:
Arons-Air-V:~ aron$ phonopy
_ __ | |__ ___ _ __ ___ _ __ _ _
| '_ \| '_ \ / _ \| '_ \ / _ \ | '_ \| | | |
| |_) | | | | (_) | | | | (_) || |_) | |_| |
| .__/|_| |_|\___/|_| |_|\___(_) .__/ \__, |
|_| |_| |___/

  • Phono3py

If harmonic phonons are not enough for you, then Phono3py lets you calculate phonon-phonon interactions, but it gets very computationally expensive. We need to install hdf5 (for more efficient data management):
pip2 install h5py

and lapacke for faster code. Download the latest version of lapack and:
make lapackelib

Then you are ready to compile. Download Phono3py and modify to link to your compiled lapacke library.
if platform.system() == 'Darwin':
include_dirs += ['/Users/aron/Documents/progs/lapack/lapack-3.6.1/lapacke/include']
extra_link_args = ['/Users/aron/Documents/progs/lapack/lapack-3.6.1/liblapacke.a']
followed by:
python install

The outcome:
Arons-Air-V:~ aron$ phono3py
_ _____
_ __ | |__ ___ _ __ ___|___ / _ __ _ _
| '_ \| '_ \ / _ \| '_ \ / _ \ |_ \| '_ \| | | |
| |_) | | | | (_) | | | | (_) |__) | |_) | |_| |
| .__/|_| |_|\___/|_| |_|\___/____/| .__/ \__, |
|_| |_| |___/

  • VASP

While we use a range of electronic structure packages, VASP is the old reliable. I downloaded the latest version (5.4.1), which has streamlined the install process.
cp ./arch/makefile.include.linux_intel ./makefile.include

which needs to be modified to point to the correct compilers (here gcc, ifort and mpifort). We will also remove -DscaLAPACK from the precompiler options and set SCALAPACK = . There are now three patches/bug fixes to install:
patch -p1 < patch.
patch -p1 < patch.
patch -p1 < patch.

and one fix to sort out a gcc error. To the file ./src/lib/getshmem.c add one line at the end of the include statements:
#define SHM_NORESERVE 010000

The outcome:
Arons-Air-V:test aron$ mpirun -np 4 ../vasp_std
running on 4 total cores
distrk: each k-point on 4 cores, 1 groups
distr: one band on 1 cores, 4 groups
using from now: INCAR
vasp.5.4.1 24Jun15 (build Jan 02 2016 21:20:37) complex

  • ASE

The atomistic simulation environment is a useful set of Python tools and modules. It now installs, including the gui, in two lines:
brew install pygtk
pip install python-ase

The outcome:


I will update with more codes and tools as I find time (posted in January; revised in July).

My data is your data

Academics in the UK are just coming to terms with an open access policy for publications (from paid ‘gold’ to free ‘green’ university repositories).

What has received significantly less attention is the new UK research data policy. In my experience, raising this issue in conversation is met with blank expressions… what data policy?

Some key points from From 1st May 2015:

Published research papers should include a short statement describing how and on what terms any supporting research data may be accessed.

The metadata must be sufficient to allow others to understand what research data exists, why, when and how it was generated, and how to access it.

My university, like most others, has put together policy and guidance documents but they are quite generic and don’t seem to have really filtered down to the researcher level.

In my field of computational materials science, there are now several options:

  • GitHub – my group has been using this a lot for research (DOIs can be generated via the EU-funded project Zenodo; 2GB limit per repository). Instead of building separate repositories for each paper, we have been collecting related information, e.g. Phonons and Crystal Structures.
  • Mendeley Data – a nice clean interface for uploading data and generating DOIs, but I haven’t seen any clear policy for storage limits or guaranteed data lifetimes.
  • Figshare – this repository plays nice with raw datasets and multimedia (e.g. a hybrid perovskite MD video). The serious drawback is a 1GB storage limit (per free account) with a 250 MB file size limit.
  • NoMaD – a new respository to “host, organize and share materials data”. I have great hopes for this one, but at the moment the website is a little jaded, and the interface is light years behind the Materials Project (which serves a different purpose of being a single source database).

Ideally, a standard protocol would be adopted in the community to avoid the individual ‘data dumps’ that university repositories enable in favour of a systematic and searchable community database. Aiida allows one to do this at the research group or collaborator level, but I hope that NoMaD can build a critical mass of researchers (and sustained funding) to make this a reality.

Installing ASE on Mac OSX

“ASE is an Atomistic Simulation Environment written in the Python programming language with the aim of setting up, steering, and analyzing atomistic simulations.” It links to a wide variety of electronic structure packages and automates many tedious processes. Best of all it’s free and open source.

There is a Homebrew installation option, but sometimes it is nice to know what you are installing. The basic starting point is a system with XCode and SciPy (following the Phonopy installation guide).

1. Feed your Python with GTK
– An “object-oriented widget toolkit” in a simple self-installing package.

2. Water your Python with Libpng
– A png reference library in a simple self-installing package.

3. Download & Link ASE
tar -zxf python-ase-
ln -s python-ase- ase
cd ase
python install --user

4. Nearly there…
– Add to your .bash_profile (with the right pathway):
export PATH=$HOME/progs/ase/tools:$PATH

5. Test (and have fun)!
mkdir tmp; cd tmp
python -c "from ase.test import test; test(verbosity=2, display=False)" 2>&1 | tee testase.log

OUTPUT: (ScriptTestCase) ... ok (ScriptTestCase) ... ok (ScriptTestCase) ... ok

Installing Phonopy on Mac OSX

“Phonopy is an open source package of phonon calculations based on the supercell approach.” It is a wonderful lattice dynamics package, developed by Prof. Atsushi Togo, which links to a wide variety of electronic structure packages. Since it is only used for pre- and post-processing of phonons, it is light enough to run on your laptop.

There is an official Mac installation guide on the website, but I am not a big fan of MacPorts. Each step is simple, but there are many of them. I had help along the way from Adam Jackson. The basic starting point is having XCode with command-line tools (note in OS 10.9, this requires you to run xcode-select --install after installation).

1. Feed your Python with Scipy Superpack
– A script to install the latest versions of NumPy (linear algebra), SciPy (numerical algorithms), Matplotlib (plotting), iPython (interactive shell for python).
chmod +x

2. Pip your Python
– Two more dependencies (and yet another package manager):
sudo easy_install pip
sudo pip install lxml
sudo pip install pyyaml

3. C hack
– Depending on your version of XCode, the default C compiler might be Clang (which fails for Phonopy with “‘omp.h’ file not found”). Change it back to gcc by using export CC=gcc.

4. Nearly there…
– You can now download Phonopy. Enter the main directory and run
python install --home=.
and you will need to add its path to .bash_profile:
export PYTHONPATH=/Volumes/Unix/progs/phonopy/phonopy-1.7.1/lib/python

5. Happy phonons
Once the phonopy bin is in your path, simply type phonopy

aron$ phonopy

_ __ | |__   ___  _ __   ___   _ __  _   _
| '_ \| '_ \ / _ \| '_ \ / _ \ | '_ \| | | |
| |_) | | | | (_) | | | | (_) || |_) | |_| |
| .__/|_| |_|\___/|_| |_|\___(_) .__/ \__, |
|_|                            |_|    |___/


Adams 1991: “(Everything I do) I do it for you”

I am not sure what over research fields are like, but it is quite common in computational chemistry / materials science to keep small analysis codes, scripts and tricks hidden within a research group. With an increasing number of open access projects and packages, this situation is changing.

I regularly get mails from students requesting pieces of information relating to papers I have published. My new policy is to put everything useful and requested online. The best route is not clear, but for the moment, I am adding it to my group’s GitHub. The latest additions include the crystal structure of MIL-125, an inverse spinel geometry, indium oxide nanoclusters and kesterite polytypes (see here).

In terms of version control for codes, both GitHub and Bitbucket do a fine job, especially when paired with Sourcetree. On paper, Bitbucket should be the winner as they offer both public and private repositories for free, but they can’t compete with the Github mascot (octocat):

GithubNow it’s time to learn some python with Code Academy.

Mountain Lions like OpenMPI

Following the previous post on installing Fortran compilers in OSX 10.8 (Mountain Lions like Fortran), the next step is to efficiently exploit all of those lovely i7 cores for computational chemistry.

1. OpenMPI
– Forget any version that comes with XCode as you need to compile OpenMPI against your new Fortran installation.
– Download the binary from (current version 1.6.3).
– Unzip and enter directory.
– Run “./configure –prefix=/usr/local/openmpi-1.6.3 CC=gcc FC=ifort F77=ifort”.
– Run “make”.
– Run “sudo make install”.
– Add to your .bashrc or .bash_profile:
export PATH=./:/usr/local/openmpi-1.6.3/bin:~/bin:/opt/intel/bin:$PATH
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/openmpi-1.6.3/lib

$ which mpif90

– A popular quantum chemistry package (from here; current version 081912).
– Update the Makefile to include:

FC = ifort
FFLAGS = -O3 -ip
LAPACKBLAS = -L/opt/intel/mkl/lib \
-I/opt/intel/mkl/include -lmkl_intel_lp64 \
-lmkl_sequential -lmkl_core
USE_MPI = yes
MPIFC = mpif90

– Run “make mpi”.
– Enjoy parallel calculations, e.g. mpirun -np 4 fhi-aims

– A popular materials modelling package (from here; current version 5.3.3).
– In the main src folder, “cp makefile.linux_ifc_P4 Makefile”.
– Update the Makefile to include:

FFLAGS = -FR -assume byterecl
OFLAG=-O3 -ip -ftz
BLAS=-L/$(MKL)/lib -I/$(MKL)/include -lmkl_intel_lp64 \
-lmkl_sequential -lmkl_core -lmkl_lapack95_lp64

– Run “make”.
– Enjoy parallel calculations, e.g. mpirun -np 4 vasp

Mountain Lions like Fortran

A slow running laptop was a good excuse to play around with a fresh install of OSX 10.8 (Mountain Lion). The implementation of Xcode has been changing over the last few versions, so here are the few straight forward steps required to get command-line Fortran running on your Mac.

1. Download Xcode from the App Store
– Run application to Install
– Xcode Preferences -> Downloads -> Command Line Tools

2. GNU Compilers
– Download 10.8 gcc and gfortran binaries and libraries from
– In terminal run “sudo tar -xvf gcc-mlion.tar -C /”
– Ensure the line “export PATH=/usr/local/bin:$PATH” is in your .bash_profile.

$ gfortran –version
GNU Fortran (GCC) 4.8.0 20120722 (experimental)
$ gcc –version
gcc (GCC) 4.8.0 20120722 (experimental)

3. Intel Compilers (Fortran Composer 2011)
– Install package.
– For install environment choose “Command line install only”.
– If write permission issues arise, run “sudo chmod u+rwx /Users/Shared/Library/Application\ Support/”.
– source /opt/intel/bin/ intel64
– source /opt/intel/mkl/bin/intel64/
– Run once as “sudo ifort” to overcome some permissions issues with the libraries.

$ ifort –version
ifort (IFORT) 12.1.0 20111011

Example Makefile (FHI-AIMS):
FC = ifort
FFLAGS = -O3 -ip
LAPACKBLAS = -L/opt/intel/mkl/lib \
-I/opt/intel/mkl/include -lmkl_intel_lp64 \
-lmkl_sequential -lmkl_core