This guide explains how to install Open Babel in the Matlantis environment. You will need to install not only the core Open Babel software but also the Python interface.
These installation steps have been tested in a Python 3.9 environment. Please note that the process includes compilation steps and will take approximately 40 minutes.
- Tested Environment: Python 3.9
* We have identified an issue where functions such as "liquid generator" and "smiles_to_atoms" cannot be executed (the kernel crashes) after installing Open Babel. Please follow the instructions below.
Table of Contents
- Creating the Installation Directory
- Downloading Open Babel and the Python Interface
- Activating the Python Environment
- Installing Required Python Libraries
- Installing the Open Babel
- Installing the Python Interface
- Testing Operation in the Notebook Environment
Installation Steps
1. Creating the Installation Directory
You will perform the following steps in the Matlantis environment. First, decide the installation directory for Open Babel, and create the directory as follows. In this example, we will use the home directory as the installation directory. (You can choose any location for the installation directory, and the directory names can be anything you prefer. If you change these, please ensure you use the correct paths in subsequent steps.)
Installation Directory: /home/jovyan (home directory)
- openbabel/
- openbabel/python_package/
- openbabel/build/
- tools/
- tools/openbabel-install/
2. Downloading Open Babel and the Python Interface
Download the two required files and place them in the directory created in step 1. These files should be extracted using the command line in steps (5-2) and (6-2) (they cannot be extracted using the right-click menu: Extract archive).
- Open Babel
- URL: https://github.com/openbabel/openbabel/releases
- Directory: openbabel/
- Python Interface
- URL: https://pypi.org/project/openbabel/#files
- Directory: openbabel/python_package/
3. Activating the Python Environment
From here to step 6, you will be working in the terminal. Open the Terminal in Matlantis and activate the Python environment. Please refer to this guide on how to open the terminal.
use_venv python39
* The method for using Python in the terminal is also described in the Matlantis Guidebook .
4. Installing Required Python Libraries
Install `wheel` and `swig`.
pip install -U wheel swig
5. Installing the Open Babel
-
Navigate to the `openbabel` directory
Use `cd` to change to the `openbabel` directory.
cd /home/jovyan/openbabel
-
Extracting the tar file
Extract the `openbabel-3.1.1-source.tar.bz2` file stored in the `openbabel` directory.
tar -xvf openbabel-3.1.1-source.tar.bz2
-
Installing Open Babel
Within the `openbabel` directory, run the following two commands in sequence. The compilation process will take some time.
cmake ./openbabel-3.1.1 -DCMAKE_INSTALL_PREFIX=~/tools/openbabel-install
make && make install
6. Installing the Python Interface
-
Change to the `openbabel/python_package` directory.
cd /home/jovyan/openbabel/python_package
-
Extracting the tar file
Extract the `openbabel-3.1.1.1.tar.gz` file.
tar -xvf openbabel-3.1.1.1.tar.gz
-
Change to the extracted `openbabel-3.1.1.1` directory.
cd /home/jovyan/openbabel/python_package/openbabel-3.1.1.1
-
Installing the Python Interface
Within the `openbabel-3.1.1.1` directory, run the following two commands.
Because we are installing for a specific user environment, specify the location of the `openbabel3` installation from step (5-3) and its library `lib` location in the execution options. You may see some error-like messages during the process, but if they are warnings from the code check during compilation, they can be ignored.
Specify the path:
- /home/jovyan/tools/openbabel-install/include/openbabel3
- /home/jovyan/tools/openbabel-install/lib
python setup.py build_ext -I /home/jovyan/tools/openbabel-install/include/openbabel3 -L /home/jovyan/tools/openbabel-install/lib
pip install -U .
7. Testing Operation in the Notebook Environment
-
Importing the Open Babel Library
Please import it as follows. *For information on how to set the path for libopenbabel.so.7, please refer to the explanation below. Once the path is set, the first two lines are no longer necessary.
import ctypes
ctypes.cdll.LoadLibrary('/home/jovyan/tools/openbabel-install/lib/libopenbabel.so.7')
from openbabel import openbabel
from openbabel import pybe
Reference: https://qiita.com/namakemono/items/06a606488de03a046f44
-
Running the Sample Code
example:m = pybel.readstring("smiles", "C1=CC=C(C=C1)O")
m
The sample code can be found at `openbabel/python_package/openbabel-3.1.1.1/examples/examples.py`.
Note on using pfcc-extas (Update on Dec. 18, 2024)
We have identified an issue where functions such as "liquid generator" and "smiles_to_atoms" cannot be executed (the kernel crashes) after installing Open Babel. Although this is a temporary workaround, please follow the instructions below.
1) To address the issue for each notebook individually:
Even if you do not plan to use Openbabel, add the following to the initial setup of the notebook:
import ctypes
ctypes.cdll.LoadLibrary('/home/jovyan/openbabel/tools/openbabel-install/lib/libopenbabel.so.7')
2) To set environment variables:
Add the following line to "/home/jovyan/.bashrc"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/tools/openbabel-install/lib
Create /home/jovyan/.ipython/profile_default/startup/00-startup.py and add the following:
import ctypes
ctypes.cdll.LoadLibrary('/home/jovyan/openbabel/tools/openbabel-install/lib/libopenbabel.so.7')