.. _chapter_patterns:

********************************************************************************
Fingerprint Patterns
********************************************************************************

Fingerprints are usually generated by enumerating various fragments (patterns)
of a molecule and then hashing them into a fixed-length bitvector.
The :oe:func:`OEGraphSim::OEGetFPPatterns` function provides access to these
patterns by returning an iterator over :ref:`OEFPPattern <OEGraphSim_OEFPPattern>` objects,
each of which has the atoms and bonds of a specific fragment along with the
following information:

* the bit that is set when the pattern is hashed into a  fixed-length bitvector
* the unhashed unique integer encoding of the pattern
* the SMARTS representation of the pattern that encodes the atom and bond properties
  that are specified in the given fingerprint type (:ref:`OEFPTypeBase <OEGraphSim_OEFPTypeBase>`)

The following example shows how the retrieve the patterns that are enumerated 
when generating a tree fingerprint.

..  oe:source:: FPPattern.py
    :language: python
    :refnum:   19
    :caption:  Example of accessing patterns encoded into a fingerprint
    :frag:     SNIPPET-FPPATTERN


..    oe:language:: python

    :ref:`Full listing. <listing-FPPattern.py>`

.. oe:source:: FPPattern.cpp
   :language: c++
   :refnum:   19
   :caption:  Example of accessing patterns encoded into a fingerprint
   :frag:     SNIPPET-FPPATTERN

.. oe:source:: FPPattern.java
   :language: java
   :refnum:   19
   :caption:  Example of accessing patterns encoded into a fingerprint
   :frag:     SNIPPET-FPPATTERN

.. oe:source:: FPPattern.cs
   :language: csharp
   :refnum:   19
   :caption:  Example of accessing patterns encoded into a fingerprint
   :frag:     SNIPPET-FPPATTERN

The output of :oe:src:`Listing 19 <SNIPPET-FPPATTERN-FPPattern>` is the following:

::
 
    1   849                                             [N;D1]  0 N
    2  1611                                             [C;D2]  1 C
    3   740                                             [C;D3]  2 C
    4  2841                                             [O;D1]  3 O
    5  1589                                            [O-;D1]  4 O
    6  2326                                      [N;D1]-[C;D2]  0 N  1 C
    7  3764                             [C;D2](-[C;D3])-[N;D1]  0 N  1 C  2 C
    8  2727                      [C;D2](-[C;D3]=[O;D1])-[N;D1]  0 N  1 C  2 C  3 O
    9   859            [C;D2](-[C;D3](-[O-;D1])=[O;D1])-[N;D1]  0 N  1 C  2 C  3 O  4 O
   10  3537                     [C;D2](-[C;D3]-[O-;D1])-[N;D1]  0 N  1 C  2 C  4 O
   11  3083                                      [C;D3]-[C;D2]  1 C  2 C
   12   793                               [C;D2]-[C;D3]=[O;D1]  1 C  2 C  3 O
   13  1574                     [C;D2]-[C;D3](-[O-;D1])=[O;D1]  1 C  2 C  3 O  4 O
   14  3538                              [C;D2]-[C;D3]-[O-;D1]  1 C  2 C  4 O
   15  1707                                      [O;D1]=[C;D3]  2 C  3 O
   16  1472                            [C;D3](-[O-;D1])=[O;D1]  2 C  3 O  4 O
   17  1397                                     [O-;D1]-[C;D3]  2 C  4 O


.. seealso::

   * :ref:`OEFPPattern <OEGraphSim_OEFPPattern>` class
   * :oe:func:`OEGraphSim::OEGetFPPatterns` function
   * :oe:func:`OEGraphSim::OEGetFPType` function
   * :ref:`chapter_coverage` chapter
   * :ref:`chapter_overlap` chapter
