Beispiel #1
0
def show_oemol_struc(oemol,
                     torsions=False,
                     atom_indices=[],
                     width=500,
                     height=300):
    from IPython.display import Image
    from openeye import oechem, oedepict

    # Highlight element of interest
    class NoAtom(oechem.OEUnaryAtomPred):
        def __call__(self, atom):
            return False

    class AtomInTorsion(oechem.OEUnaryAtomPred):
        def __call__(self, atom):
            return atom.GetIdx() in atom_indices

    class NoBond(oechem.OEUnaryBondPred):
        def __call__(self, bond):
            return False

    class BondInTorsion(oechem.OEUnaryBondPred):
        def __call__(self, bond):
            return (bond.GetBgn().GetIdx()
                    in atom_indices) and (bond.GetEnd().GetIdx()
                                          in atom_indices)

    class CentralBondInTorsion(oechem.OEUnaryBondPred):
        def __call__(self, bond):
            return (bond.GetBgn().GetIdx()
                    in atom_indices[1:3]) and (bond.GetEnd().GetIdx()
                                               in atom_indices[1:3])

    opts = oedepict.OE2DMolDisplayOptions(width, height,
                                          oedepict.OEScale_AutoScale)
    opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx())

    oedepict.OEPrepareDepiction(oemol)
    img = oedepict.OEImage(width, height)
    display = oedepict.OE2DMolDisplay(oemol, opts)
    if torsions:
        atoms = oemol.GetAtoms(AtomInTorsion())
        bonds = oemol.GetBonds(NoBond())
        abset = oechem.OEAtomBondSet(atoms, bonds)
        oedepict.OEAddHighlighting(
            display,
            oechem.OEColor(oechem.OEYellow),
            oedepict.OEHighlightStyle_BallAndStick,
            abset,
        )

    oedepict.OERenderMolecule(img, display)
    png = oedepict.OEWriteImageToString("png", img)
    return Image(png)
Beispiel #2
0
def PoseInteractionsSVG(md_components, width=400, height=300):
    """Generate a OEGrapheme interaction plot for a protein-ligand complex.
    The input protein may have other non-protein components as well so
    the input protein is first split into components to isolate the protein
    only for the plot. This may have to be changed if other components need
    to be included in the plot.
    """
    # # perceive residue hierarchy of total system
    # if not oechem.OEHasResidues(proteinOrig):
    #     oechem.OEPerceiveResidues(proteinOrig, oechem.OEPreserveResInfo_All)
    #     print('Perceiving residues')

    # split the total system into components
    #protein, ligandPsuedo, water, other = oeommutils.split(proteinOrig)

    protein = md_components.get_protein
    ligand = md_components.get_ligand

    # make the OEHintInteractionContainer
    asite = oechem.OEInteractionHintContainer(protein, ligand)
    if not asite.IsValid():
        oechem.OEThrow.Fatal("Cannot initialize active site!")
    # do the perceiving
    oechem.OEPerceiveInteractionHints(asite)
    # set the depiction options
    opts = oegrapheme.OE2DActiveSiteDisplayOptions(width, height)
    opts.SetRenderInteractiveLegend(True)
    magnifyresidue = 1.0
    opts.SetSVGMagnifyResidueInHover(magnifyresidue)
    # make the depiction
    oegrapheme.OEPrepareActiveSiteDepiction(asite)
    adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)
    # make the image
    image = oedepict.OEImage(width, height)
    oegrapheme.OERenderActiveSite(image, adisp)
    # Add a legend
    #iconscale = 0.5
    #oedepict.OEAddInteractiveIcon(image, oedepict.OEIconLocation_TopRight, iconscale)
    svgBytes = oedepict.OEWriteImageToString("svg", image)

    svgString = svgBytes.decode("utf-8")

    return svgString
def _oe_render_parent(
    parent: Molecule,
    rotor_bonds: Optional[Collection[BondTuple]] = None,
    image_width: int = 572,
    image_height: int = 198,
) -> str:

    from openeye import oedepict

    rotor_bonds = [] if rotor_bonds is None else rotor_bonds

    # 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)

    # 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(rotor_bonds))

    display = oedepict.OE2DMolDisplay(oe_parent, display_options)

    oedepict.OERenderMolecule(image, display)

    svg_contents = oedepict.OEWriteImageToString("svg", image)
    return svg_contents.decode()
Beispiel #4
0
#!/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
from openeye import oedepict

# @ <SNIPPET-WRITE-IMAGE-TO-STRING>
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1")
oedepict.OEPrepareDepiction(mol)

image = oedepict.OEImage(200, 200)
oedepict.OERenderMolecule(image, mol)
data = oedepict.OEWriteImageToString("svg", image)
# @ </SNIPPET-WRITE-IMAGE-TO-STRING>
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()
Beispiel #6
0
def oenb_draw_dihedral(mol2, width=200, height=200):
    img = plot_dihedral(mol2, width=width, height=height)
    return Image(data=oedepict.OEWriteImageToString("png", img))
Beispiel #7
0
def show_oemol_struc(oemol, torsions=False, atom_indices=[]):
    """
    Returns the oedepict image with or without the torsion highlighted

    Parameters
    ----------
    oemol: openeye oechem mol object
    torsions: boolean, to highlight dihedrals
    atom_indices: dihedral atom indices to highlight

    Returns
    -------
    Image: image in png format
    """
    from IPython.display import Image
    from openeye import oechem, oedepict

    width = 400
    height = 300

    # Highlight element of interest
    class NoAtom(oechem.OEUnaryAtomPred):
        def __call__(self, atom):
            return False

    class AtomInTorsion(oechem.OEUnaryAtomPred):
        def __call__(self, atom):
            return atom.GetIdx() in atom_indices

    class NoBond(oechem.OEUnaryBondPred):
        def __call__(self, bond):
            return False

    class BondInTorsion(oechem.OEUnaryBondPred):
        def __call__(self, bond):
            return (bond.GetBgn().GetIdx() in atom_indices) and (
                bond.GetEnd().GetIdx() in atom_indices
            )

    class CentralBondInTorsion(oechem.OEUnaryBondPred):
        def __call__(self, bond):
            return (bond.GetBgn().GetIdx() in atom_indices[1:3]) and (
                bond.GetEnd().GetIdx() in atom_indices[1:3]
            )

    opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale)
    opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx())

    oedepict.OEPrepareDepiction(oemol)
    img = oedepict.OEImage(width, height)
    display = oedepict.OE2DMolDisplay(oemol, opts)
    if torsions:
        atoms = oemol.GetAtoms(AtomInTorsion())
        bonds = oemol.GetBonds(NoBond())
        abset = oechem.OEAtomBondSet(atoms, bonds)
        oedepict.OEAddHighlighting(
            display,
            oechem.OEColor(oechem.OEYellow),
            oedepict.OEHighlightStyle_BallAndStick,
            abset,
        )

    oedepict.OERenderMolecule(img, display)
    png = oedepict.OEWriteImageToString("png", img)
    return Image(png)