.. _chapter_fingerprint:

********************************************************************************
Fingerprint Generation
********************************************************************************

The fingerprint types implemented in the **GraphSim TK** encode the 2D graph
features of molecules.
Fingerprints can be used in applications such as similarity searches,
molecular characterization, molecular diversity and chemical database
clustering.

The following five types of fingerprints are implemented:

#. :ref:`section_fingerprint_maccs` (:oe:const:`OEGraphSim::OEFPType::MACCS166`)

#. :ref:`section_fingerprint_lingo` (:oe:const:`OEGraphSim::OEFPType::Lingo`)

#. :ref:`section_fingerprint_circular`  (:oe:const:`OEGraphSim::OEFPType::Circular`)

#. :ref:`section_fingerprint_path`  (:oe:const:`OEGraphSim::OEFPType::Path`)

#. :ref:`section_fingerprint_tree`  (:oe:const:`OEGraphSim::OEFPType::Tree`)

.. _section_fingerprint_maccs:

MACCS
================================================================================

:term:`MACCS` keys are 166 bit :term:`structural key` descriptors in which each
bit is associated with a :term:`SMARTS` pattern.

The following code snippets demonstrate two **separate** ways to
create a MACCS keys fingerprint:

.. oe:source:: MakeMaccsFP.cpp
   :language: c++
   :noindent:
   :frag:     SNIPPET-MAKE-MACCS-1

.. oe:source:: MakeMaccsFP.py
   :language: python
   :noindent:
   :frag:     SNIPPET-MAKE-MACCS-1

..    oe:language:: python

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

.. oe:source:: MakeMaccsFP.java
   :language: java
   :noindent:
   :frag:     SNIPPET-MAKE-MACCS-1

.. oe:source:: MakeMaccsFP.cs
   :language: csharp
   :noindent:
   :frag:     SNIPPET-MAKE-MACCS-1


.. oe:source:: MakeMaccsFP.cpp
   :language: c++
   :noindent:
   :frag:     SNIPPET-MAKE-MACCS-2

.. oe:source:: MakeMaccsFP.py
   :language: python
   :noindent:
   :frag:     SNIPPET-MAKE-MACCS-2

..    oe:language:: python

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

.. oe:source:: MakeMaccsFP.java
   :language: java
   :noindent:
   :frag:     SNIPPET-MAKE-MACCS-2

.. oe:source:: MakeMaccsFP.cs
   :language: csharp
   :noindent:
   :frag:     SNIPPET-MAKE-MACCS-2


.. _section_fingerprint_lingo:

LINGO
================================================================================

The **GraphSim TK** provides fingerprint API for the :term:`LINGO`
similarity search method implemented in **OEChem TK**.

The following code snippets demonstrate two **separate** ways to
create a :term:`LINGO` fingerprint:

.. oe:source:: MakeLingoFP.cpp
   :language: c++
   :noindent:
   :frag:     SNIPPET-MAKE-LINGO-1

.. oe:source:: MakeLingoFP.py
   :language: python
   :noindent:
   :frag:     SNIPPET-MAKE-LINGO-1

..    oe:language:: python

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

.. oe:source:: MakeLingoFP.java
   :language: java
   :noindent:
   :frag:     SNIPPET-MAKE-LINGO-1

.. oe:source:: MakeLingoFP.cs
   :language: csharp
   :noindent:
   :frag:     SNIPPET-MAKE-LINGO-1

.. oe:source:: MakeLingoFP.cpp
   :language: c++
   :noindent:
   :frag:     SNIPPET-MAKE-LINGO-2

.. oe:source:: MakeLingoFP.py
   :language: python
   :noindent:
   :frag:     SNIPPET-MAKE-LINGO-2

..    oe:language:: python

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

.. oe:source:: MakeLingoFP.java
   :language: java
   :noindent:
   :frag:     SNIPPET-MAKE-LINGO-2

.. oe:source:: MakeLingoFP.cs
   :language: csharp
   :noindent:
   :frag:     SNIPPET-MAKE-LINGO-2


.. _section_fingerprint_circular:

Circular
================================================================================

A circular fingerprint is generated by **exhaustively** enumerating
**all** circular fragments grown radially from each heavy atom of the
molecule up to the given radius and then hashing these fragments into
a fixed-length bitvector.
See :ref:`Figure: Example of enumerating circular fragments with various radii<figure_fingerprint_circular>`.

.. _figure_fingerprint_circular:

.. figure:: images/CircularEnumeration.*
   :scale:  100
   :align:  center

   **Example of enumerating circular fragments with various radii**

The following code snippets demonstrate two **separate** ways to create a
circular fingerprint with default parameters:

.. oe:source:: MakeCircularFP.py
   :language: python
   :noindent:
   :frag:     SNIPPET-MAKE-CIRCULAR-1

..    oe:language:: python

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

.. oe:source:: MakeCircularFP.py
   :language: python
   :noindent:
   :frag:     SNIPPET-MAKE-CIRCULAR-2

..    oe:language:: python

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

.. oe:source:: MakeCircularFP.cpp
   :language: c++
   :noindent:
   :frag:     SNIPPET-MAKE-CIRCULAR-1

.. oe:source:: MakeCircularFP.cpp
   :language: c++
   :noindent:
   :frag:     SNIPPET-MAKE-CIRCULAR-2

.. oe:source:: MakeCircularFP.java
   :language: java
   :noindent:
   :frag:     SNIPPET-MAKE-CIRCULAR-1

.. oe:source:: MakeCircularFP.java
   :language: java
   :noindent:
   :frag:     SNIPPET-MAKE-CIRCULAR-2

.. oe:source:: MakeCircularFP.cs
   :language: csharp
   :noindent:
   :frag:     SNIPPET-MAKE-CIRCULAR-1

.. oe:source:: MakeCircularFP.cs
   :language: csharp
   :noindent:
   :frag:     SNIPPET-MAKE-CIRCULAR-2

.. _section_fingerprint_path:

Path
================================================================================

A path fingerprint is generated by **exhaustively** enumerating
**all** linear fragments of a molecular graph up to a given size
and then hashing these fragments into a fixed-length bitvector.
See :ref:`Figure: Example of enumerating path fragments with various lengths<figure_fingerprint_path>`.

.. _figure_fingerprint_path:

.. figure:: images/PathEnumeration.*
   :scale:  100
   :align:  center

   **Example of enumerating path fragments with various lengths**

The following code snippets demonstrate two **separate** ways to create a
path fingerprint with default parameters:

.. oe:source:: MakePathFP.cpp
   :language: c++
   :noindent:
   :frag:     SNIPPET-MAKE-PATH-1

.. oe:source:: MakePathFP.py
   :language: python
   :noindent:
   :frag:     SNIPPET-MAKE-PATH-1

..    oe:language:: python

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

.. oe:source:: MakePathFP.java
   :language: java
   :noindent:
   :frag:     SNIPPET-MAKE-PATH-1

.. oe:source:: MakePathFP.cs
   :language: csharp
   :noindent:
   :frag:     SNIPPET-MAKE-PATH-1

.. oe:source:: MakePathFP.cpp
   :language: c++
   :noindent:
   :frag:     SNIPPET-MAKE-PATH-2

.. oe:source:: MakePathFP.py
   :language: python
   :noindent:
   :frag:     SNIPPET-MAKE-PATH-2

..    oe:language:: python

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


.. oe:source:: MakePathFP.java
   :language: java
   :noindent:
   :frag:     SNIPPET-MAKE-PATH-2

.. oe:source:: MakePathFP.cs
   :language: csharp
   :noindent:
   :frag:     SNIPPET-MAKE-PATH-2

.. _section_fingerprint_tree:

Tree
================================================================================

A tree fingerprint is generated by **exhaustively** enumerating
**all**  tree fragments of a molecular graph up to a given size
and then hashing these fragments into a fixed-length bitvector.
See :ref:`Figure: Example of enumerating tree fragments with various lengths<figure_fingerprint_tree>`.

.. _figure_fingerprint_tree:

.. figure:: images/TreeEnumeration.*
   :scale:  100
   :align:  center

   **Example of enumerating tree fragments with various lengths**

The following code snippets demonstrate two **separate** ways to create a
tree fingerprint with default parameters:

.. oe:source:: MakeTreeFP.py
   :language: python
   :noindent:
   :frag:     SNIPPET-MAKE-TREE-1

..    oe:language:: python

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


.. oe:source:: MakeTreeFP.py
   :language: python
   :noindent:
   :frag:     SNIPPET-MAKE-TREE-2

..    oe:language:: python

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


.. oe:source:: MakeTreeFP.cpp
   :language: c++
   :noindent:
   :frag:     SNIPPET-MAKE-TREE-1

.. oe:source:: MakeTreeFP.cpp
   :language: c++
   :noindent:
   :frag:     SNIPPET-MAKE-TREE-2

.. oe:source:: MakeTreeFP.java
   :language: java
   :noindent:
   :frag:     SNIPPET-MAKE-TREE-1

.. oe:source:: MakeTreeFP.java
   :language: java
   :noindent:
   :frag:     SNIPPET-MAKE-TREE-2

.. oe:source:: MakeTreeFP.cs
   :language: csharp
   :noindent:
   :frag:     SNIPPET-MAKE-TREE-1

.. oe:source:: MakeTreeFP.cs
   :language: csharp
   :noindent:
   :frag:     SNIPPET-MAKE-TREE-2

.. hint::

   **GraphSim TK** also provides the ability to parameterize the
   circular, path and tree fingerprint generation with arbitrary
   sets of properties.
   For more details see the :ref:`chapter_user_defined` chapter.

