#!/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 __future__ import print_function
from openeye import oechem

# @ <SNIPPET-CREATE-ROLE-OBJECT>
role = oechem.OERole("my:analysis:active-site")
print(role.GetName())
# @ </SNIPPET-CREATE-ROLE-OBJECT>

# @ <SNIPPET-ADD-ROLE-OBJECT>
frag = oechem.OEAtomBondSet()  # isa OERoleSet
frag.AddRole(role)
# @ </SNIPPET-ADD-ROLE-OBJECT>

# @ <SNIPPET-ADD-ROLE-STRING>
frag.AddRole("my:analysis:low-energy")
# @ </SNIPPET-ADD-ROLE-STRING>

# @ <SNIPPET-HAS-ROLE-OBJECT>
role2 = oechem.OERole("my:analysis:low-energy")
print(frag.HasRole(role2))
# @ </SNIPPET-HAS-ROLE-OBJECT>

# @ <SNIPPET-HAS-ROLE-STRING>
print(frag.HasRole("my:analysis:small"))
# @ </SNIPPET-HAS-ROLE-STRING>

# @ <SNIPPET-HAS-ROLE-PRED>
pred = oechem.OEHasRole(role)
if pred(frag):
    print("has role: ", role.GetName())
# @ </SNIPPET-HAS-ROLE-PRED>

# @ <SNIPPET-GET-ALL-ROLES>
print([r.GetName() for r in frag.GetRoles()])
# @ </SNIPPET-GET-ALL-ROLES>

# @ <SNIPPET-DELETE-ROLE>
frag.DeleteRole(role)
frag.DeleteRole("my:analysis:some-role")
# @ </SNIPPET-DELETE-ROLE>

# @ <SNIPPET-DELETE-ALL-ROLES>
frag.ClearRoles()
# @ </SNIPPET-DELETE-ALL-ROLES>

# @ <SNIPPET-NUM-ROLES>
print(frag.NumRoles())
# @ </SNIPPET-NUM-ROLES>
# @ </SNIPPET>
