(A1) If you want to use OpenBabel from Perl, you now need to compile the Perl extension.

+

(A1) If OpenBabel was not installed in /usr/lib, you need to add the location of libopenbabel.so to LD_LIBRARY_PATH. For example, on my system libopenbabel.so was installed in /usr/local/lib:

+

<pre>

+

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

+

</pre>

+

If this is not done correctly, step A2 will give the error message "Can't build and link to 'openbabel'".

−

Change directory to 'openbabel-2.0.2/scripts/perl' and run:

+

(A2) If you want to use OpenBabel from Perl, you now need to compile the Perl extension.

+

Change directory to 'openbabel-2.2.1/scripts/perl' and run:

<pre>

<pre>

perl Makefile.PL

perl Makefile.PL

Line 22:

Line 27:

If this happens, you should set the value of the MACOSX_DEPLOYMENT_TARGET environment variable to match the MacOSX major version. For example, if you are using MacOSX 10.4.9, set MACOSX_DEPLOYMENT_TARGET to 10.4. Now run 'make' again.

If this happens, you should set the value of the MACOSX_DEPLOYMENT_TARGET environment variable to match the MacOSX major version. For example, if you are using MacOSX 10.4.9, set MACOSX_DEPLOYMENT_TARGET to 10.4. Now run 'make' again.

−

(A2) To install the Perl bindings globally, as root type:

+

(A3) To install the Perl bindings globally, as root type:

<pre>

<pre>

make install

make install

</pre>

</pre>

−

−

(A3) You may need to add the location of libopenbabel.so (on my system, the location is /usr/local/lib) to the environment variable LD_LIBRARY_PATH if you get an error when you try to import the OpenBabel library in a Perl script.

==== Install the Perl bindings locally ====

==== Install the Perl bindings locally ====

−

(B1) If OpenBabel was not installed in a system-wide location, make sure to add its location to LD_LIBRARY_PATH:

+

(B1) See Step A1 above.

−

<pre>

+

−

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/noel/tree/lib

+

−

</pre>

+

(B2) To compile the Perl extension, instead of Step A2 above, use the 'PREFIX' option to Makefile.PL to specify an install location:

(B2) To compile the Perl extension, instead of Step A2 above, use the 'PREFIX' option to Makefile.PL to specify an install location:

If this happens, you should set the value of the MACOSX_DEPLOYMENT_TARGET environment variable to match the MacOSX major version. For example, if you are using MacOSX 10.4.9, set MACOSX_DEPLOYMENT_TARGET to 10.4. Now run 'make' again.

(A3) To install the Perl bindings globally, as root type:

make install

Install the Perl bindings locally

(B1) See Step A1 above.

(B2) To compile the Perl extension, instead of Step A2 above, use the 'PREFIX' option to Makefile.PL to specify an install location:

perl Makefile.PL PREFIX=/home/noel/tree
make
make test # (Optional - this runs a few standard tests)

(B3) To install the Perl extension, run the following:

make install

This installs the extension into something like /home/noel/tree/lib/perl/5.8.7, so you need to add "/home/noel/tree/lib/perl" to your PERL5LIB environment variable or specify this location in your Perl scripts as follows:

use lib "/home/noel/tree/lib/perl"; # Must come before "use Chemistry::OpenBabel;"

Using Chemistry::OpenBabel

The Chemistry::OpenBabel module is designed to allow Perl scripts to use the C++ Open Babel library. The bindings are generated using the SWIG package and provides access to almost all of the Open Babel interfaces via Perl, including the base classes OBMol, OBAtom, OBBond, and OBResidue, as well as the conversion framework OBConversion.

As such, essentially any call in the C++ API is available to Perl access with very little difference in syntax. This guide is designed to give examples of common Perl syntax for Chemistry::OpenBabel and pointers to the appropriate sections of the API documentation.

More commonly, Open Babel can be used to read in molecules using the OBConversion framework. The following script reads in molecular information (a SMI file) from a string, adds hydrogens, and writes out an MDL file as a string.