Programming Exercises

Table of Contents

1. Introduction

In these exercises. you will explore freely available source code ("Contrib"). You will also write and compile some toolkit code that uses a...
    ... SMILES molecule.
    ... SMILES reaction.
    ... SMARTS pattern.
    ... SMIRKS transform.

2. Compiling Source Code

The main progran syntax should look something like this:

    #include "dt_smiles.h"
    #include "dt_smarts.h"
    
    int main() {
    
      /* toolkit code */
    
      return 0;
    }
    

Place the portions of source code from the tutorial into the main syntax and compile and run the executable. Compare you output to the results shown in the SMARTS - Pattern and SMIRKS - Transform sections. To compile source code, use the following command:

    $ cc -o <filename> <filename>.c -I$DY_ROOT/include -L$DY_ROOT/lib -ldt_smarts -ldt_smiles
    

Let's explore the "Contrib" code and write some new toolkit code that demonstrate the concepts discussed in this tutorial.

3. SMILES - Molecule

In the $DY_ROOT/contrib/src/c/smiles directory, browse the makefile and source code, especially for:

    cansmi
    showmf
    rings
    

In the $DY_ROOT/contrib/src/c/smiles directory, browse the makefile and the source code.

Exercise: Write a program to read SMILES in, write canonical SMILES out, and count the number of atoms, bonds, and cycles.

4. SMILES - Reaction

Exercise: Write a program to read SMILES in and determine if the input is a molecule or a reaction. Then, for molecules, stream the molecule for atoms and write their symbols. For reactions, stream the reaction for molecules and write their reaction role and canonical SMILES out.

5. SMARTS - Pattern

In the $DY_ROOT/contrib/src/c/smarts directory, browse the makefile and source code, especially for:

    smartsmatch
    

Exercise: Write a program to read SMARTS in and perform a match against a target molecule or reaction. Stream the pathset for paths and stream the paths for atoms and write their unique identifiers.

6. SMIRKS - Transform

In the $DY_ROOT/contrib/src/c/transform directory, browse the makefile and the source code, especially for:

    tranfilter
    

Exercise: Write a program to read SMIRKS in and perform a transformation on a sequence of molecules. Loop over the resulting sequence and write canonical SMILES out.

7. EXTRA CREDIT - Contrib Index

Create an HTML index of "Contrib" software by doing the following:

    $ cd $DY_ROOT/contrib
    $ make_index -html > index.html
    

Open the above "index.html" file with a browser. There is a lot of "Contrib" software. Familarize yourself with the breadth of software. Try to locate "Contrib" code that does the following:

    Identify ring systems in input structures.
    Align 2D layout based on a SMARTS query.
    Calculate polar surface area.