#!/usr/bin/env python
# (C) 2017 OpenEye Scientific Software Inc. All rights reserved.
#
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of OpenEye products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable OpenEye offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall OpenEye be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem

mdlquery = '''\

 MDL-Draw02280812162D

  5  5  0  0  0  0  0  0  0  0999 V2000
   -5.8501    7.6070    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
   -6.5378    7.1074    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -6.2751    6.2989    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -5.4251    6.2989    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -5.1624    7.1074    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
  2  3  5  0  0  0  0
  1  2  5  0  0  0  0
  3  4  5  0  0  0  0
  4  5  5  0  0  0  0
  5  1  5  0  0  0  0
M  END
$$$$
'''

ifs = oechem.oemolistream()
ifs.SetFormat(oechem.OEFormat_MDL)
ifs.openstring(mdlquery)

# @ <SNIPPET>
qmol = oechem.OEQMol()
queryopts = oechem.OEMDLQueryOpts_Default | oechem.OEMDLQueryOpts_SuppressExplicitH
oechem.OEReadMDLQueryFile(ifs, qmol, queryopts)

qscreen = oechem.OESubSearchScreen()
if not oechem.OEMakeSubSearchQueryScreen(qscreen, qmol, oechem.OESubSearchScreenType_MDL):
    print("query MDL screen cannot be generated")

tmol = oechem.OEGraphMol()
oechem.OESmilesToMol(tmol, "c1c[nH]cc1")

tscreen = oechem.OESubSearchScreen()
if not oechem.OEMakeSubSearchTargetScreen(tscreen, tmol, oechem.OESubSearchScreenType_MDL):
    print("target MDL screen cannot be generated")
# @ </SNIPPET>

if oechem.OEScreen(qscreen, tscreen):
    print("screen match")
else:
    print("no match")
