I have been interested in chemistry since high school, and programming since grad school. I dream sometimes about getting a job in cheminformatics or chemical information. To do that, I probably need practice, so I decided to install OpenBabel. This is a library of C functions to do interesting chemistry-related things, like convert between various chemistry file formats, cluster similar compounds, calculate descriptors, etc. It has a set of Python bindings which makes it a lot easier to work with. Sounds like fun, doesn't it?
- Documentation: http://openbabel.org/docs/current/index.html
- Compilation and installation instructions: http://openbabel.org/docs/current/Installation/install.html
Preliminaries
- Downloaded and extracted a tar.gz file from http://sourceforge.net/projects/openbabel/files/openbabel/2.3.1/openbabel-2.3.1.tar.gz/download
- Tried an out-of-source build, and CMake complained about missing prerequisites
Prerequisites
- Eigen
- OpenBabel says it needs version 2, but brew only knows about version 3.x. I installed version 3 anyway.
- This created an entry in /usr/local/include/eigen3 which pointed to ../Cellar/eigen/3.3.7/include/eigen3 which contains the Eigen and unsupported folders.
- Eigen is a header-only project, so I cloned it from its Github mirror and checked out branch 2.0.17.
- Then I created a symlink from /usr/local/include/eigen2 to ../Cellar/eigen/2.0.17/include/eigen2 and copied the Eigen and unsupported folders there.
- Might confuse me if I ever try to brew uninstall Eigen 2, but c'est la vie.
- wxWidgets
- The first two Google hits didn't do it. Finally I searched `wxwidgets mac homebrew`, and sure enough, there's a formula:
brew install wxmac
Cairo
- Did this out of order. The error stack mentioned Cairo, so I first tried installing it with Homebrew:
brew install cairo
After all this, CMake still gave an error, but it seemed related to pkg-config. Another quick Google search fixed that:
brew install pkg-config
Which, if I recall, is a good thing to have for general C development.
CMake was still complaining that Cairo wasn't found, despite the presence of `cairo` in `/usr/local/include`. Looking more closely at the output I saw "Package 'libffi', required by 'gobject-2.0', not found"
Another Google search on that turned up setting the path to libffi as:
PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig" cmake -S . -B build
After that the CMake build completed without error finding all the packages I thought I would need.
Compilation and installation
Since I want to use this in Python I attempted to set the Python bindings. I wasn't finding the Python 3 libraries, but I finally found a web page that said I could point OpenBabel to Python 3 instead of 2 by giving the path to the executable. For the heck of it I also built the GUI. Being a good TDD person I also wanted to run the tests. My final CMake command was:
PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig" cmake -S . -B build -Wno-dev -DBUILD_GUI=ON -DPYTHON_BINDINGS=ON -DPYTHON_EXECUTABLE=/usr/local/bin/python3 -DENABLE_TESTS=ON
make -C build
make test -C build
That caused a problem with a missing
header. Searching for a solution to that, I found that there's a formula for OpenBabel, which would allow me to bypass all this dependency installation by hand stuff.
brew install open-babel
Which went without hitch.
But just to be thorough, it also suggested cloning and building from Github. When I did that:
git clone git@github.com:openbabel/openbabel.git
and used the CMake and make commands, this time there was no problem with the missing header.
But there were no Python bindings. Looking at the build output, I found I needed to add -DRUN_SWIG=ON, and that that failed without SWIG installed. So brew install swig and then the Python bindings were generated.
$ python3
>>> import openbabel
>>>
QED
No comments:
Post a Comment