Exemple #1
0
    def GetAdjacentTorsions(mol, refTorsion):
        '''
        Returns all torsions that are 0 or 1 path length away from
        the reference torsion
        @param mol: OEGraphMol
        @param refTorsion: OETorsion
        @return: int
        '''
        adjTorsions = []
        PATH_LENGTH_THRESHOLD = 1
        torset = {
            str(refTorsion.b.GetIdx()) + "_" + str(refTorsion.c.GetIdx()): True
        }
        torset[str(refTorsion.c.GetIdx()) + "_" +
               str(refTorsion.b.GetIdx())] = True
        pred = oechem.OEAndBond(oechem.OEHasOrder(1),
                                oechem.OENotBond(oechem.OEBondIsInRing()))
        for adjTorsion in oechem.OEGetTorsions(mol, pred):
            # skip nitrile
            order_ab = adjTorsion.a.GetBond(adjTorsion.b).GetOrder()
            order_cd = adjTorsion.c.GetBond(adjTorsion.d).GetOrder()
            if order_ab == 3 or order_cd == 3:
                continue

            # skip torsions involving terminal -N-H
            if adjTorsion.a.IsHydrogen() and adjTorsion.b.IsNitrogen():
                continue
            if adjTorsion.d.IsHydrogen() and adjTorsion.c.IsNitrogen():
                continue

            key1 = str(adjTorsion.b.GetIdx()) + "_" + str(
                adjTorsion.c.GetIdx())
            key2 = str(adjTorsion.c.GetIdx()) + "_" + str(
                adjTorsion.b.GetIdx())
            if key1 in torset or key2 in torset:
                continue

            pathLen = TorsionGenerator.GetMinPathLength(refTorsion, adjTorsion)
            if pathLen <= PATH_LENGTH_THRESHOLD:
                adjTorsions.append(adjTorsion)
                torset[key1] = True
                torset[key2] = True

        return adjTorsions
def _oe_render_fragment(
    parent: Molecule,
    fragment: Molecule,
    bond_indices: BondTuple,
    image_width: int = 283,
    image_height: int = 169,
) -> str:

    from openeye import oechem, oedepict

    # Map the OpenFF molecules into OE ones, making sure to explicitly set the atom
    # map on the OE object as this is not handled by the OpenFF toolkit.
    oe_parent = parent.to_openeye()

    for atom in oe_parent.GetAtoms():
        atom.SetMapIdx(get_map_index(parent, atom.GetIdx(), False))

    oedepict.OEPrepareDepiction(oe_parent)

    oe_fragment = fragment.to_openeye()

    for atom in oe_fragment.GetAtoms():
        atom.SetMapIdx(get_map_index(fragment, atom.GetIdx(), False))

    oe_parent_bond = oe_parent.GetBond(
        oe_parent.GetAtom(oechem.OEHasMapIdx(bond_indices[0])),
        oe_parent.GetAtom(oechem.OEHasMapIdx(bond_indices[1])),
    )

    # Set-up common display options.
    image = oedepict.OEImage(image_width, image_height)

    display_options = oedepict.OE2DMolDisplayOptions(
        image_width, image_height, oedepict.OEScale_AutoScale)

    display_options.SetTitleLocation(oedepict.OETitleLocation_Hidden)
    display_options.SetAtomColorStyle(
        oedepict.OEAtomColorStyle_WhiteMonochrome)
    display_options.SetAtomLabelFontScale(1.2)

    # display_options.SetBondPropertyFunctor(_oe_wbo_label_display({bond_indices}))

    display = oedepict.OE2DMolDisplay(oe_parent, display_options)

    fragment_atom_predicate, fragment_bond_predicate = _oe_fragment_predicates(
        {atom.GetMapIdx()
         for atom in oe_fragment.GetAtoms()})

    not_fragment_atoms = oechem.OENotAtom(fragment_atom_predicate)
    not_fragment_bonds = oechem.OENotBond(fragment_bond_predicate)

    oedepict.OEAddHighlighting(
        display,
        oedepict.OEHighlightByColor(oechem.OEGrey, 0.75),
        not_fragment_atoms,
        not_fragment_bonds,
    )

    rotatable_bond = oechem.OEAtomBondSet()

    rotatable_bond.AddBond(oe_parent_bond)
    rotatable_bond.AddAtom(oe_parent_bond.GetBgn())
    rotatable_bond.AddAtom(oe_parent_bond.GetEnd())

    oedepict.OEAddHighlighting(
        display,
        oechem.OEColor(oechem.OELimeGreen),
        oedepict.OEHighlightStyle_BallAndStick,
        rotatable_bond,
    )

    oedepict.OERenderMolecule(image, display)

    svg_contents = oedepict.OEWriteImageToString("svg", image)
    return svg_contents.decode()
Exemple #3
0
def DepictMoleculeWithFragmentCombinations(report, mol, frags, opts): #fragcombs, opts):
    """ This function was taken from https://docs.eyesopen.com/toolkits/cookbook/python/depiction/enumfrags.html with some modification
    """
    stag = "fragment idx"
    itag = oechem.OEGetTag(stag)
    for fidx, frag in enumerate(frags):
        for bond in frags[frag].GetBonds():
            bond.SetData(itag, fidx)

    # setup depiction styles

    nrfrags = len(frags)
    colors = [c for c in oechem.OEGetLightColors()]
    if len(colors) < nrfrags:
        colors = [c for c in oechem.OEGetColors(oechem.OEYellowTint, oechem.OEDarkOrange, nrfrags)]

    bondglyph = ColorBondByFragmentIndex(colors, itag)

    lineWidthScale = 0.75
    fadehighlight = oedepict.OEHighlightByColor(oechem.OEGrey, lineWidthScale)

    # depict each fragment combinations

    for frag in frags:

        cell = report.NewCell()
        disp = oedepict.OE2DMolDisplay(mol, opts)

        fragatoms = oechem.OEIsAtomMember(frags[frag].GetAtoms())
        fragbonds = oechem.OEIsBondMember(frags[frag].GetBonds())

        notfragatoms = oechem.OENotAtom(fragatoms)
        notfragbonds = oechem.OENotBond(fragbonds)

        oedepict.OEAddHighlighting(disp, fadehighlight, notfragatoms, notfragbonds)

        bond = mol.GetBond(oechem.OEHasBondIdx(frag))

        atomBondSet = oechem.OEAtomBondSet()
        atomBondSet.AddBond(bond)
        atomBondSet.AddAtom(bond.GetBgn())
        atomBondSet.AddAtom(bond.GetEnd())

        hstyle = oedepict.OEHighlightStyle_BallAndStick
        hcolor = oechem.OEColor(oechem.OELightBlue)
        oedepict.OEAddHighlighting(disp, hcolor, hstyle, atomBondSet)

        #oegrapheme.OEAddGlyph(disp, bondglyph, fragbonds)

        oedepict.OERenderMolecule(cell, disp)

    # depict original fragmentation in each header

    cellwidth, cellheight = report.GetHeaderWidth(), report.GetHeaderHeight()
    opts.SetDimensions(cellwidth, cellheight, oedepict.OEScale_AutoScale)
    opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_WhiteMonochrome)

    bondlabel = LabelBondOrder()
    opts.SetBondPropertyFunctor(bondlabel)
    disp = oedepict.OE2DMolDisplay(mol, opts)
    #oegrapheme.OEAddGlyph(disp, bondglyph, oechem.IsTrueBond())

    headerpen = oedepict.OEPen(oechem.OEWhite, oechem.OELightGrey, oedepict.OEFill_Off, 2.0)
    for header in report.GetHeaders():
        oedepict.OERenderMolecule(header, disp)
        oedepict.OEDrawBorder(header, headerpen)
# 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

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "N#CCC1CCNC=C1")

print("Number of non-rotatable bonds =", end=" ")
print(oechem.OECount(mol, oechem.OENotBond(oechem.OEIsRotor())))

print("Number of ring double bonds =", end=" ")
print(
    oechem.OECount(
        mol, oechem.OEAndBond(oechem.OEBondIsInRing(), oechem.OEHasOrder(2))))

print("Number of double or triple bonds =", end=" ")
print(
    oechem.OECount(mol,
                   oechem.OEOrBond(oechem.OEHasOrder(2),
                                   oechem.OEHasOrder(3))))
# @ </SNIPPET>