.. _molprop_examples_molfilter:

Basic Filtering for a Molecule File
======================================

All filtering operations are controlled via the
:ref:`OEFilter <OEMolProp_OEFilter>` object.  The :ref:`OEFilter <OEMolProp_OEFilter>`
object is typically configured with a specified filter and then
applied iteratively over a molecule file.  This example
demonstrates configuring the :ref:`OEFilter <OEMolProp_OEFilter>` object with
the :ref:`lead-like filter<filter_theory_variations_of_filters>`
and then writes out the molecules that pass the filter. The
:oe:meth:`OEMolProp::OEFilter::operator()` method is used to
test whether the molecule passes the filter.

.. note::

   The molecule will also be altered by all the specified
   :ref:`filter_process` steps.

Command Line Interface
----------------------

A description of the command line interface can be obtained by
executing the program with the --help argument.

.. oe:language:: c++

   .. code-block:: console

      prompt> molfilter --help

.. oe:language:: python

   .. code-block:: console

      prompt> python molfilter.py --help

.. oe:language:: java

   .. code-block:: console

      prompt> java MolFilter --help

.. oe:language:: csharp

   .. code-block:: console

      prompt> MolFilter --help


will generate the following output:

.. code-block:: console

   Simple parameter list
    filter options :
      -filtertype : filter type

    input/output options :
      -in : Input filename
      -out : Output filename


.. code-block:: console

   Usage: ./molfilter <input> <output>

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

.. oe:language:: python

   .. only:: oehtml

      .. admonition:: Download code

         :download:`molfilter.py <../../../../wrappers/python/examples/molprop/molfilter.py>`

      ..    literalinclude:: ../../../../wrappers/python/examples/molprop/molfilter.py

   .. only:: oepdf

      .. oe:source:: molfilter.py
         :language: python


.. oe:language:: c++

   .. only:: oehtml

      .. admonition:: Download code

         :download:`molfilter.cpp <../../../../sublibs/tklibs/molprop/examples/molfilter.cpp>`

   .. only:: oepdf

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

.. oe:language:: java

   .. only:: oehtml

      .. admonition:: Download code

         :download:`MolFilter.java <../../../../wrappers/java/examples/openeye/examples/oemolprop/MolFilter.java>`

   .. only:: oepdf

      .. oe:source:: MolFilter.java
         :language: java

.. oe:language:: csharp

   .. only:: oehtml

      .. admonition:: Download code

         :download:`MolFilter.cs <../../../../wrappers/csharp/Csharp-Examples/OEMolProp/MolFilter.cs>`

   .. only:: oepdf

      .. oe:source:: MolFilter.cs
         :language: csharp

.. seealso::

   * :oe:func:`OEMolProp::OEFilter` class
   * :oe:func:`OEMolProp::OEConfigureFilterParams` and :oe:func:`OEMolProp::OEConfigureFilterType` functions
   * :oe:func:`OEMolProp::OEGetFilterType` function

.. _molprop_examples_molfilter_output:

Examples
----------------------

.. oe:language:: c++

   .. code-block:: console

      prompt> molfilter -in mcss.smi.gz -out .smi -filtertype Lead

.. oe:language:: python

   .. code-block:: console

      prompt> python molfilter.py -in mcss.smi.gz -out .smi -filtertype Lead

.. oe:language:: java

   .. code-block:: console

      prompt> java MolFilter -in mcss.smi.gz -out .smi -filtertype Lead

.. oe:language:: csharp

   .. code-block:: console

      prompt> MolFilter -in mcss.smi.gz -out .smi -filtertype Lead

The following is an example of the output:

::

   CC1=CC(=O)C=CC1=O    NSC 1,Minimum atom count(10) not reached: 9
   c1ccc2c(c1)nc(s2)SSc3nc4ccccc4s3    NSC 2,Maximum disulfide(0) exceeded: 1
   c1c(cc(c(c1[N+](=O)[O-])[O-])Cl)[N+](=O)[O-]    NSC 3,Maximum heteroatom to carbon ratio(1.10) exceeded: 1.33
   c1c(sc(n1)N)[N+](=O)[O-]    NSC 4,Minimum atom count(10) not reached: 9
   c1ccc2c(c1)C(=O)c3ccc(cc3C2=O)N     NSC 5,Maximum dye(0) exceeded: 2
   c1ccc(c(c1)c2c3ccc(c(c3oc-4c(c(=O)ccc24)Br)Br)O)C(=O)[O-]    NSC 6,Maximum atom count(25) exceeded: 27
   C[NH+](C)C1=C(C(=O)c2ccccc2C1=O)Cl    NSC 7,Maximum alkyl_halide(0) exceeded: 1
   Cc1ccc2c(c1[N+](=O)[O-])C(=O)c3ccccc3C2=O    NSC 8,Maximum nitro(0) exceeded: 1
   CC(C)(C)c1cc(c(cc1O)C(C)(C)C)O    NSC 11,Pass
   CC1=NN(C(=O)C1)c2ccccc2 NSC    12,Pass

By default the :oe:meth:`OEMolProp::OEFilter::operator()` method will emit
information to :oe:constns:`OESystem::OEThrow` about every molecule passed to it. This example
prints that to the screen.  The next example,
:ref:`quietfilter<molprop_examples_quietfilter>`, shows how to suppress
that output.  Only the molecules that pass the filter will be written to
the output file.  The following is the format for what is emitted:

::

   [Isomeric SMILES]\t[Title],[Pass|Reason for failure]

