Saturday, November 13, 2010

GotoBLAS2: A faster BLAS library

This post is about a little trick I have for speeding up my quantum chemistry calculations. For some reason this software is unknown to most people, and thus I decided do a short advertisement!

The bottleneck in all forms of computational quantum chemistry is the CPU time spent to converge a calculation to a given accuracy. The most expensive part is in most cases the evaluation of two-electron integrals,  but during many calculations, a lot of time is also spent doing linear algebra operations. The computational routines for doing linear algebra has been optimized greatly over the years and today there are quite a few standard linear algebra libraries for doing this. One standard API of linear algebra routines is called BLAS, short for "Basic Linear Algebra Subprograms". Many equations involved in quantum chemistry are formulated into matrix notation which is easily interpreted and turned into fast, parallelized code.

When people want to use a fast BLAS library, often well-known libraries such as the ALTAS or Intel MKL BLAS libraries are used. However, there is a slightly faster BLAS library out there, named GotoBLAS2. This library was started by a Japanese guy named Kazushige Goto (the Japanese pronunciation is something lik "go-toe"), who, like Albert Einstein, worked in a patent office while he began developing his own BLAS library. After a while he was 'discovered' by a university in Texas and soon Goto was deported from Japan. Now he is said to be very rich and working for some large coporation somewhere in the US.

Enough with the history! Tobias Wittwer has made a detailed comparison of common, fast BLAS libraries in this pdf: blas_lapack.pdf

You can download the latest GotoBLAS2 here. Not only is GotoBLAS2 faster  than Intel's MKL library, GotoBLAS2 is also completely free of charge and open source under the BSD license.

GotoBLAS2 will be used in future posts on compiling and installing software, for which I am always using GotoBLAS2. So be sure to use this and make the most of your CPU resources!

Friday, November 12, 2010

Installing OpenBabel and compiling with the C++ API

OpenBabel is a tool making life easier for everyone in the computational chemistry business. You can do tons of cool stuff with OpenBabel! I regularly use it to convert PDB files to input files for Gaussian09 and XYZ files, which are then used to calculate quantum chemistry on proteins and often back to PDB  format again. It can also juggle around with SMILES strings, do all sorts of chem-informatics and whatnot. Everything you and I need.  OpenBabel is the King for these kinds of things. 
In addition OpenBabel has API to Python, Pearl and C++, so you can use all the features of OpenBabel in your own scripts or compiled programs!  I started using it for a project requiring automatic generation of thousands protein fragment XYZ files and automatic handling of input and output files. Many of my colleagues use OpenBabel for stuff like this.
Not only is this an absolutely awesome piece of software, it is also completely free and open source under the GNU GPL. I love this! This post concerns basic installation and use of the C++ API, which is not completely straightforward in some cases.

For the some users, installing and compiling with OpenBabel on a Linux machine can be a daunting task. Recently I helped my dear colleague Kasper Thofte setting up OpenBabel and compiling a piece of C++ code on our local Beowulf Cluster.  Kasper is currently developing some very cool  automatic transition state search methods and he is also developing transition search methods in GAMESS, which is free quantum chemistry software
Since we don't have root access on our cluster, everything has to be installed in our home directories and we cannot use the /usr/lib etc. folders.  These are all the steps we went through to get his C++ code to compile.

First I checked out the latest development code from the SourceForge into my ~/src/ dir. Compiled code goes in the ~/programs/ dir on my account.

cd ~/src
svn co openbabel

Step two is to actually compile the code with cmake and telling it to install to my ~/programs/ dir with the a prefix option.
cd openbabel
cmake -DCMAKE_INSTALL_PREFIX=/home/andersx/programs/openbabel .

make install

Now, to make sure that you can access
OpenBabel from the command line as well as having the g++ compilier find the libraries, you have to find a file in your home ~/ directory called .bashrc and insert these two lines:

export PATH=$PATH:/home/andersx/programs/openbabel/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/andersx/programs/openbabel/lib

Now open a new terminal (to refresh the PATH and LD_LIBRARY_PATH variables) and you are ready to compile your OpenBabel code. There is one small catch however. You have to manually tell g++ where your libraries and headers for OpenBabel are located. This looks like this:

g++ -I/home/andersx/programs/openbabel/include/openbabel-2.0 -L/home/andersx/programs/openbabel/lib -lopenbabel OBtest.cpp -o OBtest

There you go! The above took us quite a while to figure out, and this should also work on any type of linux machine with the GNU compilers.

UPDATE: My friend Casper Steinmann just pointed out that he has a detailed blog post on installing and using the Python API for OpenBabel. So you should have no excuses for not using OpenBabel in your workflow: