Source code for oecookbook.acceptor_atom

# (C) 2023 Cadence Design Systems, Inc. (Cadence)
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence 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 Cadence 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 Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

"""Module to identify Lipinski acceptor."""

import rich.console
from openeye import oechem


[docs] class IsLipinskiAcceptor(oechem.OEUnaryAtomPred): """ Predicate class to identify Lipinski acceptor atoms. See Also -------- * num_lipinsky_acceptors_ * :ref:`section_cheminfo_acceptor_donor` section """
[docs] def __call__(self, atom: oechem.OEAtomBase) -> bool: """Evaluate the atom.""" return atom.GetAtomicNum() in [oechem.OEElemNo_O, oechem.OEElemNo_N]
[docs] def num_lipinsky_acceptors(mol: oechem.OEMolBase) -> int: """ Return the number of Lipinski acceptors in the molecule. Parameters ---------- mol: oechem.OEMolBase Input molecule Returns ------- int: Number of Lipinsky donor atoms defined by IsLipinskiAcceptor predicate. Examples -------- >>> lipitor = "CC(C)c1c(c(c(n1CC[C@H](C[C@H](CC(=O)[O-])O)O)c2ccc(cc2)F)c3ccccc3)C(=O)Nc4ccccc4" >>> mol = oechem.OEGraphMol() >>> if oechem.OESmilesToMol(mol, lipitor): ... print(f"Number of acceptors: {oecookbook.num_lipinsky_acceptors(mol)}") Number of acceptors: 7 """ return oechem.OECount(mol, IsLipinskiAcceptor())
def print_lipinsky_acceptors(mol: oechem.OEMolBase) -> None: """Print Lipinsky acceptor atoms to console.""" oechem.OETriposAtomNames(mol) console = rich.console.Console() console.print(f"Acceptor atoms in molecule '{oechem.OEMolToSmiles(mol)}'") for atom in mol.GetAtoms(IsLipinskiAcceptor()): console.print(atom.GetName()) class IsHBondAcceptorCarbonylNitroso(oechem.OEUnaryAtomPred): """Predicate class to identify atoms in [#6,#7;R0]=[#8].""" def __call__(self, atom: oechem.OEAtomBase) -> bool: """Evaluate the atom.""" if not atom.IsOxygen(): return False if atom.GetHvyDegree() != 1: return False for bond in atom.GetBonds(): if bond.GetOrder() != 2: # noqa: PLR2004 return False return all( neigh.GetAtomicNum in [oechem.OEElemNo_O, oechem.OEElemNo_N] for neigh in atom.GetAtoms() )