#!/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.

# @ <SNIPPET>
from openeye import oechem

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C1[NH]C=CC=1CO")

# @ <SNIPPET-RING-LOOP1>
for atom in mol.GetAtoms(oechem.OENotAtom(oechem.OEAtomIsInRing())):
    print(atom.GetIdx(), oechem.OEGetAtomicSymbol(atom.GetAtomicNum()))
# @ </SNIPPET-RING-LOOP1>

# @ <SNIPPET-RING-LOOP2>
for atom in mol.GetAtoms():
    if not atom.IsInRing():
        print(atom.GetIdx(), oechem.OEGetAtomicSymbol(atom.GetAtomicNum()))
# @ </SNIPPET-RING-LOOP2>

mol.Clear()
oechem.OESmilesToMol(mol, "C1CC2CC1CC2")
# @ <SNIPPET-RING-SMALLEST-SIZE>
for atom in mol.GetAtoms():
    size = oechem.OEAtomGetSmallestRingSize(atom)
    if size == 0:
        print(atom.GetIdx(), "acyclic")
    else:
        print(atom.GetIdx(), "smallest ring size=", size)
# @ </SNIPPET-RING-SMALLEST-SIZE>

for bond in mol.GetBonds():
    size = oechem.OEBondGetSmallestRingSize(bond)
    if size == 0:
        print(bond.GetIdx(), "acyclic")
    else:
        print(bond.GetIdx(), "smallest ring size=", size)

mol.Clear()
oechem.OESmilesToMol(mol, "c1cccc2c1[nH]cc2")
print("fused atoms:")
# @ <SNIPPET-RING-SIZE>
for atom in mol.GetAtoms():
    if oechem.OEAtomIsInRingSize(atom, 5) and oechem.OEAtomIsInRingSize(atom, 6):
        print(atom.GetIdx())
# @ </SNIPPET-RING-SIZE>
# @ </SNIPPET>
