Cheminformatics Tutorials - Herong's Tutorial Examples - v2.03, by Herong Yang
Compile, Link and Run RDKit C++ API Examples
This section provides a tutorial example on how to compile, link and run RDKit C++ API examples provided in the RDKit source package.
With RDKit installed and tested, now I can some example C++ programs provided in the RDKit source package to try its C++ API.
1. Locate the source code of example programs.
herong$ cd ~/rdkit/Docs/Book/C++Examples herong$ ls -l total 80 -rwxr-xr-x. 1 herong herong 1666 Apr 7 18:43 CMakeLists.txt -rwxr-xr-x. 1 herong herong 1241 Apr 7 18:43 example10.cpp -rwxr-xr-x. 1 herong herong 1671 Apr 7 18:43 example11.cpp -rwxr-xr-x. 1 herong herong 2240 Apr 7 18:43 example12.cpp -rwxr-xr-x. 1 herong herong 2298 Apr 7 18:43 example13.cpp -rwxr-xr-x. 1 herong herong 3084 Apr 7 18:43 example14.cpp -rwxr-xr-x. 1 herong herong 2312 Apr 7 18:43 example15.cpp -rwxr-xr-x. 1 herong herong 1278 Apr 7 18:43 example16.cpp -rwxr-xr-x. 1 herong herong 4547 Apr 7 18:43 example17.cpp -rwxr-xr-x. 1 herong herong 1029 Apr 7 18:43 example1.cpp -rwxr-xr-x. 1 herong herong 1876 Apr 7 18:43 example2.cpp -rwxr-xr-x. 1 herong herong 1419 Apr 7 18:43 example3.cpp -rwxr-xr-x. 1 herong herong 1970 Apr 7 18:43 example4.cpp -rwxr-xr-x. 1 herong herong 1476 Apr 7 18:43 example5.cpp -rwxr-xr-x. 1 herong herong 1669 Apr 7 18:43 example6.cpp -rwxr-xr-x. 1 herong herong 1993 Apr 7 18:43 example7.cpp -rwxr-xr-x. 1 herong herong 674 Apr 7 18:43 example8.cpp -rwxr-xr-x. 1 herong herong 1478 Apr 7 18:43 example9.cpp -rwxr-xr-x. 1 herong herong 1458 Apr 7 18:43 FindMyRDKit.cmake
2. Compile the first example, example1.cpp, with CPATH environment variable for RDKit header files.
herong$ export CPATH=/home/herong/rdkit/Code herong$ g++ -c example1.cpp herong$ ls -l example1.* -rwxr-xr-x. 1 herong herong 1029 Apr 7 18:43 example1.cpp -rw-rw-r--. 1 herong herong 94960 Apr 11 22:13 example1.o
3. Link the object code, example1.o, with RDKit dynamic libraries.
herong$ export LIBRARY_PATH=/home/herong/rdkit/lib herong$ export RDKIT_LIBS="-lRDKitFileParsers -lRDKitDepictor \ -lRDKitMolAlign \ -lRDKitMolTransforms -lRDKitEigenSolvers -lRDKitAlignment \ -lRDKitForceFieldHelpers -lRDKitSmilesParse -lRDKitSubstructMatch \ -lRDKitForceField -lRDKitOptimizer -lRDKitTrajectory -lRDKitGraphMol \ -lRDKitRingDecomposerLib -lRDKitRDGeometryLib -lRDKitDataStructs \ -lRDKitRDGeneral -lRDKitcoordgen -lRDKitmaeparser" herong$ g++ $RDKIT_LIBS -o example1 example1.o herong$ ls -l example1 -rwxrwxr-x. 1 herong herong 55608 Apr 11 22:22 example1
4. Run the executable code, example1, with LD_LIBRARY_PATH for RDKit dynamic libraries.
herong$ export LD_LIBRARY_PATH=/home/herong/rdkit/lib herong$ ./example1 Number of atoms 7 Number of atoms : 11 Explicit valence for atom # 1 O, 3, is greater than permitted Can't kekulize mol. Unkekulized atoms: 0 1 2
5. Repeat for other examples.
herong$ g++ $RDKIT_LIBS -o example2 example2.cpp /usr/bin/ld: /home/herong/rdkit/lib/libRDKitmaeparser.so: undefined reference to symbol '_ZN5boost9iostreams4zlib4okayE' //usr/lib64/libboost_iostreams.so.1.66.0: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status herong$ g++ $RDKIT_LIBS -o example3 example3.cpp herong$ ./example3 C[C@H](O)c1ccccc1 CC(O)c1ccccc1 c1ccncc1 c1ccncc1 c1ccncc1 C[C@H](O)C1=CC=CC=C1 ... herong$ g++ $RDKIT_LIBS -o example4 example4.cpp /tmp/ccxa2yre.o: In function `RDKit::DGeomHelpers::EmbedMolecule(...)': example4.cpp: undefined reference to `RDKit::DGeomHelpers::EmbedMultipleConfs(...)' collect2: error: ld returned 1 exit status herong$ g++ $RDKIT_LIBS -o example5 example5.cpp herong$ ./example5 mol-295 RDKit 3D 20 22 0 0 1 0 0 0 0 0999 V2000 2.3200 0.0800 -0.1000 C 0 0 0 0 0 0 0 0 0 0 0 0 1.8400 -1.2200 0.1200 C 0 0 0 0 0 0 0 0 0 0 0 0 3.6800 0.0800 0.2600 C 0 0 0 0 0 0 0 0 0 0 0 0 ... herong$ g++ $RDKIT_LIBS -o example6 example6.cpp herong$ ./example6 6 8 6 6 8 6 1 1 1 0 0 0 0 to 0 is 1 No bond between 0 and 3 1 : 8 0 : 6 herong$ g++ $RDKIT_LIBS -o example7 example7.cpp herong$ ./example7 0 1 2 2 1 1 0 1 2 1 1 1 1 Bond 1 is in a ring Atom 2 is in ring of size 3 : 1 Atom 2 is in ring of size 4 : 1 Atom 2 is in ring of size 5 : 0 Bond 1 is in ring of size 3 : 1 Atom 1 is in ring of size 5 : 0 Number of symmetric SSSR rings : 2 1 2 3 4 5 2 3 Number of SSSR rings : 2 herong$ g++ $RDKIT_LIBS -o example8 example8.cpp herong$ ./example8 Number of atoms : 3 Number of atoms : 9 Number of atoms : 3 herong$ g++ $RDKIT_LIBS -o example9 example9.cpp herong$ ./example9 Order : 12 Aromatic : 1 After default Kekulize : Order : 2 After default Kekulize : Aromatic : 0 After Kekulize, markAtomsBonds false : Aromatic : 1 After Kekulize, markAtomsBonds true : Aromatic : 0 Order : 12 Aromatic : 1 herong$ g++ $RDKIT_LIBS -o example10 example10.cpp herong$ ./example10 CoordGen support not available herong$ g++ $RDKIT_LIBS -o example11 example11.cpp /tmp/ccv0U38c.o: In function `main': example11.cpp:(.text+0x9fc): undefined reference to `RDKit::DGeomHelpers::ETKDG' ... herong$ g++ $RDKIT_LIBS -o example12 example12.cpp herong$ ./example12 c1ccncc1 Wrote 5289 molecules Read mol of name : 1 Read 5289 molecules. herong$ g++ $RDKIT_LIBS -o example13 example13.cpp /tmp/ccLRCjCS.o: In function `main': example13.cpp:(.text+0x1af): undefined reference to `RDKit::MolDraw2D::drawMolecule(...)' ... herong$ g++ $RDKIT_LIBS -o example14 example14.cpp herong$ ./example14 Pattern matched molecule : (0,0)(1,5)(2,6) Match 1 : (0,0)(1,5)(2,6) Match 2 : (0,4)(1,5)(2,6) There were 22 hits in the file. SMILES match SMARTS match SMILES match Not SMARTS match SMARTS match herong$ g++ $RDKIT_LIBS -o example15 example15.cpp herong$ ./example15 SMARTS 1 match SMARTS 2 match SMARTS 3 match SMARTS 1 chiral match Not SMARTS 2 chiral match SMARTS 3 chiral match Chiral mol, non-chiral query : match Non-chiral mol, chiral query : NO match herong$ g++ $RDKIT_LIBS -o example16 example16.cpp herong$ ./example16 0 1 3 4 Match 1 : 1 7 8 10 herong$ g++ $RDKIT_LIBS -o example17 example17.cpp /tmp/ccHQoWV7.o: In function `main': example17.cpp:(.text+0x6d2): undefined reference to `RDKit::MolDraw2D::drawMolecule(...)'
Cool. Most RDKit C++ API examples are working! Some linking issues might be caused by dynamic library references.
Table of Contents
SMILES (Simplified Molecular-Input Line-Entry System)
Open Babel: The Open Source Chemistry Toolbox
Using Open Babel Command: "obabel"
Generating SVG Pictures with Open Babel
Substructure Search with Open Babel
Similarity Search with Open Babel
Fingerprint Index for Fastsearch with Open Babel
Stereochemistry with Open Babel
Command Line Tools Provided by Open Babel
►RDKit: Open-Source Cheminformatics Software
Install RDKit in an Anaconda Environment
Install RDKit Binary Package for CentOS
Build RDKit from Source Code on CentOS System
►Compile, Link and Run RDKit C++ API Examples
Try Python API with RDKit Native Code
rdkit.Chem.rdchem - The Core Module
rdkit.Chem.rdmolfiles - Molecular File Module
rdkit.Chem.rdDepictor - Compute 2D Coordinates
rdkit.Chem.Draw - Handle Molecule Images
Molecule Substructure Search with RDKit
rdkit.Chem.rdmolops - Molecule Operations
Daylight Fingerprint Generator in RDKit
Morgan Fingerprint Generator in RDKit
RDKit Performance on Substructure Search
Introduction to Molecular Fingerprints
OCSR (Optical Chemical Structure Recognition)
AlphaFold - Protein Structure Prediction