Installing cinfony on Mac OS X

I just spent a frustrating couple of hours trying to get all the different components of cinfony working on Mac OS X, so I thought I’d share how I finally got it all set up.

What is cinfony?

Basically cinfony is a python wrapper for a whole load of different cheminformatics toolkits. From the cinfony homepage:

Cinfony presents a common API to several cheminformatics toolkits. It uses the Python programming language, and builds on top of Open Babel, RDKit, the CDK, Indigo, OPSIN and cheminformatics webservices.

Installing cinfony

The cinfony home page has some instructions for Mac OS X 10.5 and Linux installation, but they are slightly outdated. Here’s how I got everything to work on Mac OS X 10.7 Lion.

  1. Download cinfony-1.1.tar.gz and extract by double-clicking.

  2. In Terminal, change to the directory:

    cd ~/Downloads/cinfony-1.1
    
  3. Run

    python setup.py install
    

    I did this within a virtualenv so root wasn’t required. If you are using the system python or MacPorts python, you will probably need to use sudo.

  4. Test it out. Load the Python prompt:

    python
    >>> import cinfony
    

    Everything is fine if there are no errors.

Installing OpenBabel

I found the easiest way to install OpenBabel with the Python bindings was to just compile from source.

  1. Download openbabel-2.3.1.tar.gz and extract by double-clicking.

  2. Make sure cmake, libxml2, zlib and Eigen are all installed. Without a doubt, the easiest way to do this is with MacPorts. With MacPorts installed, just do:

    sudo port install cmake
    sudo port install libxml2
    sudo port install zlib
    sudo port install eigen
    
  3. With the openbabel-2.3.1 folder in your Downloads folder:

    cd ~/Downloads
    mv openbabel-2.3.1 ob-src
    mkdir ob-build
    cd ob-build
    cmake ../ob-src  -DPYTHON_BINDINGS=ON
    make
    make install
    

    I had an error at the make stage, which was due to an old version of libz.a installed in /usr/local/lib that was overriding the most recent version installed by MacPorts. Deleting that version solved the problem.

  4. Test it out:

    python
    >>> from cinfony import babel
    

Installing CDK and OPSIN

These are both JAVA libraries, so they can be done at the same time.

  1. Download the jar files: cdk-1.4.7.jar and opsin-1.2.0-jar-with-dependencies.jar and save them in

    ~/Library/Java
    

    (or wherever you want really).

  2. Download JPype, a python module that allows python programs to access java class libraries. The current version is JPype-0.5.4.2.zip. Extract by double-clicking.

  3. Open up JPype-0.5.4.2/setup.py in a text editor. Change line 38 (in the setupMacOSX function) to:

    self.javaHome = '/System/Library/Frameworks/JavaVM.framework/'
    

    and change line 41 to:

    self.libraryDir = [self.javaHome+"/Libraries"]
    

    In the setupInclusion function, change lines 63 and 64 to

    self.javaHome+"/Headers",
    self.javaHome+"/Headers/"+self.jdkInclude,
    
  4. Change to the JPype folder:

    cd ~/Downloads/JPype-0.5.4.2
    

    and install (may require sudo depending on your Python setup):

    python setup.py install
    
  5. Add the following lines to your .bash_profile:

    # Environment variables for cinfony+JPype
    export CLASSPATH=$HOME/Library/Java/opsin-1.2.0-jar-with-dependencies.jar:$HOME/Library/Java/cdk-1.4.7.jar:$CLASSPATH
    export JPYPE_JVM=/System/Library/Frameworks/JavaVM.framework/JavaVM
    export LD_LIBRARY_PATH=/System/Library/Frameworks/JavaVM.framework/Libraries:$LD_LIBRARY_PATH
    

    Make sure the CLASSPATH points towards wherever you saved the jar files.

  6. Test it out:

    python
    >>> from cinfony import cdk
    >>> from cinfony import opsin
    

Installing Indigo

  1. Download the latest versions of the Indigo libraries. Currently this is “C libraries for 10.6”. Also download the Python API for Mac OS X. Unzip both by double-clicking.

  2. Drag the contents of indigo-python-api-1.0.0-osx to your Python site-packages folder. For a virtualenv this is:

    /path/to/virtualenv/lib/python2.7/site-packages/
    

    for MacPorts this is:

    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/
    

    for the system python use:

    /Library/Python/2.7/site-packages/
    
  3. From indigo-libs-1.0.0-osx10.6 drag the two .h files to

    /usr/local/include/
    

    and drag the rest of the files to

    /usr/local/lib/
    
  4. Test it out:

    python
    >>> from cinfony import indy