.. _tutorial1_InertialAtHeavyAtoms_section:

InertialAtHeavyAtoms
================================================================================

:oe:meth:`OEFastROCS::OEFastROCSOrientation::InertialAtHeavyAtoms` translates
the center of mass (COM) of each database molecule to each heavy atom of the
query molecule and to the query molecule’s COM. 4 inertial orientations are
then optimized at each translation.

The figures below demonstrate the starting positions optimized for the first 2
heavy atoms in the query molecule:

.. _alternative_starts_figure_4:

.. figure:: ../../images/Tutorial_1_Figure_4a.png
   :align: center

   **Inertial starts optimized at heavy atom 1 (highlighted green)**

.. figure:: ../../images/Tutorial_1_Figure_4b.png
   :align: center

   **Inertial starts optimized at heavy atom 2 (highlighted green)**

Inertial starts continue to be optimized for the remaining atoms of the query
molecule and it’s COM.

.. oe:language:: c++
  
   Below is a link to a c++ script demonstrating the most basic usage of **FastROCS TK**.
   After explaining this simple script it will be modified to make use of the
   :oe:meth:`OEFastROCS::OEFastROCSOrientation::InertialAtHeavyAtoms`
   function.

   .. only:: oehtml

      .. admonition:: Download code

         :download:`simplefastrocssearch.cpp <../../../../../../sublibs/tklibs/fastrocs/examples/simplefastrocssearch.cpp>`

   .. only:: oepdf

      .. oe:source:: simplefastrocssearch.cpp
         :language: c++
    
   The script creates an :ref:`OEMolDatabase <OEChem_OEMolDatabase>` and an
   :ref:`OEShapeDatabase <OEFastROCS_OEShapeDatabase>` object. The database file is first
   opened as an :ref:`OEMolDatabase <OEChem_OEMolDatabase>` object, which is used to load
   the molecules into :ref:`OEShapeDatabase <OEFastROCS_OEShapeDatabase>` via
   :oe:meth:`OEFastROCS::OEShapeDatabase::Open`. This is the simplest example
   of loading a database.  The database is now ready for either combo or
   shape-only searches.

   .. note::

      To restrict searches to shape-only, create a shape-only database object:

      .. oe:source:: tutorial1_inertialatheavyatoms_snippet.cpp
         :language:  c++
         :frag:      SNIPPET-1

      While this reduces the memory footprint of the database as color data is
      no longer stored, the database cannot be searched for color scores.
 
.. oe:language:: python
  
   Below is a link to a python script demonstrating the most basic usage of **FastROCS TK**.
   After explaining this simple script it will be modified to make use of the
   :oe:meth:`OEFastROCS::OEFastROCSOrientation::InertialAtHeavyAtoms`
   function.

   .. only:: oehtml

      .. admonition:: Download code

         :download:`SimpleFastROCSSearch.py <../../../../../../wrappers/python/examples/fastrocs/SimpleFastROCSSearch.py>`

   .. only:: oepdf

      .. oe:source:: SimpleFastROCSSearch.py
         :language: python
    
   The script creates an :ref:`OEMolDatabase <OEChem_OEMolDatabase>` and an
   :ref:`OEShapeDatabase <OEFastROCS_OEShapeDatabase>` object. The database file is first
   opened as an :ref:`OEMolDatabase <OEChem_OEMolDatabase>` object, which is used to load
   the molecules into :ref:`OEShapeDatabase <OEFastROCS_OEShapeDatabase>` via
   :oe:meth:`OEFastROCS::OEShapeDatabase::Open`. This is the simplest example
   of loading a database.  The database is now ready for either combo or
   shape-only searches.

   .. note::

      To restrict searches to shape-only, create a shape-only database object:

      .. oe:source:: Tutorial1_InertialAtHeavyAtoms_Snippet.py
         :language:  python
         :frag:      SNIPPET-1

      While this reduces the memory footprint of the database as color data is
      no longer stored, the database cannot be searched for color scores.

.. oe:language:: java
  
   Below is a link to a java script demonstrating the most basic usage of **FastROCS TK**.
   After explaining this simple script it will be modified to make use of the
   :oe:meth:`OEFastROCS::OEFastROCSOrientation::InertialAtHeavyAtoms`
   function.

   .. only:: oehtml

      .. admonition:: Download code

         :download:`SimpleFastROCSSearch.java <../../../../../../wrappers/java/examples/openeye/examples/oefastrocs/SimpleFastROCSSearch.java>`

   .. only:: oepdf

      .. oe:source:: SimpleFastROCSSearch.java
         :language: java
    
   The script creates an :ref:`OEMolDatabase <OEChem_OEMolDatabase>` and an
   :ref:`OEShapeDatabase <OEFastROCS_OEShapeDatabase>` object. The database file is first
   opened as an :ref:`OEMolDatabase <OEChem_OEMolDatabase>` object, which is used to load
   the molecules into :ref:`OEShapeDatabase <OEFastROCS_OEShapeDatabase>` via
   :oe:meth:`OEFastROCS::OEShapeDatabase::Open`. This is the simplest example
   of loading a database.  The database is now ready for either combo or
   shape-only searches.

   .. note::

      To restrict searches to shape-only, create a shape-only database object:

      .. oe:source:: Tutorial1_InertialAtHeavyAtoms_Snippet.java
         :language:  java
         :frag:      SNIPPET-1

      While this reduces the memory footprint of the database as color data is
      no longer stored, the database cannot be searched for color scores.

.. oe:language:: c++ python java

   In this example, an :ref:`OEShapeDatabaseOptions <OEFastROCS_OEShapeDatabaseOptions>` object is
   also created and the number of results is limited to 5 via the
   :oe:meth:`OEFastROCS::OEShapeDatabaseOptions::SetLimit` method.

   Next, the query molecule is set up is using a molecule stream and the
   :oe:func:`OEChem::OEReadMolecule` function. Queries are used to search the
   loaded database via the :oe:meth:`OEFastROCS::OEShapeDatabase::GetSortedScores`
   method. The :ref:`OEShapeDatabaseOptions <OEFastROCS_OEShapeDatabaseOptions>` class is passed to
   customize the search options.   In this example, a subset of the eMolecules
   database was searched against a benzene query molecule.
   The top 5 scores are shown below.

   .. code-block:: console

      Opening database file eMolecules.2015.1_100subset.oeb ...
      Searching for benzene.oeb
      Score for mol 65(conf 1) 0.530182 shape 0.237350 color
      Score for mol 45(conf 1) 0.678128 shape 0.085376 color
      Score for mol 49(conf 1) 0.596801 shape 0.153465 color
      Score for mol 92(conf 0) 0.503204 shape 0.155330 color
      Score for mol 33(conf 1) 0.442559 shape 0.175599 color

.. oe:language:: c++

   To make use of the
   :oe:meth:`OEFastROCS::OEFastROCSOrientation::InertialAtHeavyAtoms`
   feature, modify the :ref:`OEShapeDatabaseOptions <OEFastROCS_OEShapeDatabaseOptions>` object
   as follows:

      .. oe:source:: tutorial1_inertialatheavyatoms_snippet.cpp
         :language:  c++
         :frag:      SNIPPET-2

.. oe:language:: python

   To make use of the
   :oe:meth:`OEFastROCS::OEFastROCSOrientation::InertialAtHeavyAtoms`
   feature, modify the :ref:`OEShapeDatabaseOptions <OEFastROCS_OEShapeDatabaseOptions>` object
   as follows:

      .. oe:source:: Tutorial1_InertialAtHeavyAtoms_Snippet.py
         :language:  python
         :frag:      SNIPPET-2

.. oe:language:: java

   To make use of the
   :oe:meth:`OEFastROCS::OEFastROCSOrientation::InertialAtHeavyAtoms`
   feature, modify the :ref:`OEShapeDatabaseOptions <OEFastROCS_OEShapeDatabaseOptions>` object
   as follows:

      .. oe:source:: Tutorial1_InertialAtHeavyAtoms_Snippet.java
         :language:  java
         :frag:      SNIPPET-2

.. oe:language:: c++ python java

   An additional option,
   :oe:meth:`OEFastROCS::OEShapeDatabaseOptions::SetInitialOrientation`, is
   also set to the desired method,
   :oe:meth:`OEFastROCS::OEFastROCSOrientation::InertialAtHeavyAtoms`.
   The resultant scores reflect the change in starting points:

   .. code-block:: console

      Opening database file eMolecules.2015.1_100subset.oeb ...
      Searching for benzene.oeb
      Score for mol 45(conf 1) 0.669345 shape 0.121420 color
      Score for mol 65(conf 1) 0.530182 shape 0.237350 color
      Score for mol 49(conf 1) 0.596801 shape 0.153465 color
      Score for mol 92(conf 0) 0.503204 shape 0.155330 color
      Score for mol 33(conf 1) 0.442559 shape 0.175599 color

   The :oe:meth:`OEFastROCS::OEShapeDatabaseOptions::GetNumHeavyAtomStarts`
   method can be used to
   find out how many heavy atom starts are being optimized.
   This method requires the query molecule in order to return the number of starts:

.. oe:language:: c++

      .. oe:source:: tutorial1_inertialatheavyatoms_snippet.cpp
         :language:  c++
         :frag:      SNIPPET-3

   When this code snippet is added to the C++ script, the output should
   look like this:

   .. code-block:: console

      This example will use 7 starts
      Searching for benzene.oeb
      Score for mol 45(conf 1) 0.669345 shape 0.121420 color
      Score for mol 65(conf 1) 0.530182 shape 0.237350 color
      Score for mol 49(conf 1) 0.596801 shape 0.153465 color
      Score for mol 92(conf 0) 0.503204 shape 0.155330 color
      Score for mol 33(conf 1) 0.442559 shape 0.175599 color

   .. only:: oehtml

      .. admonition:: Download code

         The fully modified c++ script used in this tutorial can be found here
         :download:`inertialatheavyatomstarts.cpp <../../../../../../sublibs/tklibs/fastrocs/examples/inertialatheavyatomstarts.cpp>`

   .. only:: oepdf

      .. oe:source:: inertialatheavyatomstarts.cpp
         :language: c++

.. oe:language:: python

      .. oe:source:: Tutorial1_InertialAtHeavyAtoms_Snippet.py
         :language:  python
         :frag:      SNIPPET-3

   When this code snippet is added to the Python script, the output should
   look like this:

   .. code-block:: console

      This example will use 7 starts
      Searching for benzene.oeb
      Score for mol 45(conf 1) 0.669345 shape 0.121420 color
      Score for mol 65(conf 1) 0.530182 shape 0.237350 color
      Score for mol 49(conf 1) 0.596801 shape 0.153465 color
      Score for mol 92(conf 0) 0.503204 shape 0.155330 color
      Score for mol 33(conf 1) 0.442559 shape 0.175599 color

   .. only:: oehtml

      .. admonition:: Download code

         The fully modified python script used in this tutorial can be found here
         :download:`InertialAtHeavyAtomStartsExample.py <../../../../../../wrappers/python/examples/fastrocs/InertialAtHeavyAtomStartsExample.py>`

   .. only:: oepdf

      .. oe:source:: InertialAtHeavyAtomStartsExample.py
         :language: python

.. oe:language:: java

      .. oe:source:: Tutorial1_InertialAtHeavyAtoms_Snippet.java
         :language:  java
         :frag:      SNIPPET-3

   When this code snippet is added to the Java script, the output should
   look like this:

   .. code-block:: console

      This example will use 7 starts
      Searching for benzene.oeb
      Score for mol 45(conf 1) 0.669345 shape 0.121420 color
      Score for mol 65(conf 1) 0.530182 shape 0.237350 color
      Score for mol 49(conf 1) 0.596801 shape 0.153465 color
      Score for mol 92(conf 0) 0.503204 shape 0.155330 color
      Score for mol 33(conf 1) 0.442559 shape 0.175599 color

   .. only:: oehtml

      .. admonition:: Download code

         The fully modified python script used in this tutorial can be found here
         :download:`InertialAtHeavyAtomStartsExample.java <../../../../../../wrappers/java/examples/openeye/examples/oefastrocs/InertialAtHeavyAtomStartsExample.java>`

   .. only:: oepdf

      .. oe:source:: InertialAtHeavyAtomStartsExample.java
         :language: java
