.. _section_example_oechem_libgen:

Library generation
================================================================================

A program that uses a SMIRKS string or an MDL reaction file to perform
reactions on input molecules. The program has a number of
flags. OELibraryGen options are: ``-implicitH``, performs the reaction
with implicit hydrogens (default ``false``), ``-relax``, ensures
unmapped atoms on the reactant side are not deleted during reaction
(default ``false``), ``-valence``, applies automatic valence
correction (default ``false``). SMILES generation options are:
``-isomeric``, includes atom and bond stereochemistry in the output
(default ``false``), ``-unique``, only include unique product
canonical SMILES (default ``false``). Input and output options are:
``-reactants``, a molecule file, or files, of reactants, ``-smirks``,
a SMIRKS string of the reaction or ``-rxn``, an MDL reaction file of
the reaction, and optionally, ``-product``, the output molecule
file. The program will output the molecules to stdout as SMILES if no
output file is set.


Example
--------------------------------------------------------------------------------

.. oe:language:: c++

   .. code-block:: console

      prompt > libgen -smirks '[C:1]c1c([N:2])cccc1>>[C:1]c1cc([N:2])ccc1' -reactants input.smi
      prompt > libgen -rxn reaction.rxn -reactants input.smi -product output.smi -valence -isomeric

.. oe:language:: python

   .. code-block:: console

      prompt > libgen.py -smirks '[C:1]c1c([N:2])cccc1>>[C:1]c1cc([N:2])ccc1' -reactants input.smi
      prompt > libgen.py -rxn reaction.rxn -reactants input.smi -product output.smi -valence -isomeric

.. oe:language:: java

   .. code-block:: console

      prompt > LibGen -smirks '[C:1]c1c([N:2])cccc1>>[C:1]c1cc([N:2])ccc1' -reactants input.smi
      prompt > LibGen -rxn reaction.rxn -reactants input.smi -product output.smi -valence -isomeric

.. oe:language:: csharp

   .. code-block:: console

      prompt > LibGen -smirks '[C:1]c1c([N:2])cccc1>>[C:1]c1cc([N:2])ccc1' -reactants input.smi
      prompt > LibGen -rxn reaction.rxn -reactants input.smi -product output.smi -valence -isomeric


Code
--------------------------------------------------------------------------------

.. oe:language:: c++

   .. only:: oehtml

      .. admonition:: Download code

         :download:`libgen.cpp <../../../../../sublibs/tklibs/oechem/examples/libgen.cpp>`

   .. only:: oepdf

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

.. oe:language:: python

   .. only:: oehtml

      .. admonition:: Download code

         :download:`libgen.py <../../../../../wrappers/python/examples/oechem/libgen.py>`

      .. literalinclude:: ../../../../../wrappers/python/examples/oechem/libgen.py


   .. only:: oepdf

      .. oe:source:: libgen.py
         :language: python

.. oe:language:: java

   .. only:: oehtml

      .. admonition:: Download code

         :download:`LibGen.java <../../../../../wrappers/java/examples/openeye/examples/oechem/LibGen.java>`

   .. only:: oepdf

      .. oe:source:: LibGen.java
         :language: java

.. oe:language:: csharp

   .. only:: oehtml

      .. admonition:: Download code

         :download:`LibGen.cs <../../../../../wrappers/csharp/Csharp-Examples/OEChem/LibGen.cs>`

   .. only:: oepdf

      .. oe:source:: LibGen.cs
         :language: csharp

.. seealso::

   * :oe:cls:`OELibraryGen<OEChem::OELibraryGen>` class
   * :oe:func:`OEChem::OEParseSmirks` function
   * :oe:func:`OEReadMDLReactionQueryFile<OEChem::OEReadMDLReactionQueryFile>` function
