Beispiel #1
0
def generate_ligands_figure(molecules, figsize=None, filename='ligands.png'):
    """ Plot an image with all of the ligands passed in

    Parameters
    ----------
    molecules : list
        list of openeye.oemol objects
    figsize : list or tuple
        list or tuple of len() == 2 of the horizontal and vertical lengths of image
    filename : string
        name of file to save the image

    Returns
    -------

    """
    from openeye import oechem, oedepict

    to_draw = []
    for lig in molecules:
        oedepict.OEPrepareDepiction(lig)
        to_draw.append(oechem.OEGraphMol(lig))

    dim = int(np.ceil(len(to_draw)**0.5))

    if figsize is None:
        x_len = 1000 * dim
        y_len = 500 * dim
        image = oedepict.OEImage(x_len, y_len)
    else:
        assert (len(figsize) == 2
                ), "figsize arguement should be a tuple or list of length 2"
        image = oedepict.OEImage(figsize[0], figsize[1])

    rows, cols = dim, dim
    grid = oedepict.OEImageGrid(image, rows, cols)

    opts = oedepict.OE2DMolDisplayOptions(grid.GetCellWidth(),
                                          grid.GetCellHeight(),
                                          oedepict.OEScale_AutoScale)

    minscale = float("inf")
    for mol in to_draw:
        minscale = min(minscale, oedepict.OEGetMoleculeScale(mol, opts))
    #     print(mol.GetTitle())

    opts.SetScale(minscale)
    for idx, cell in enumerate(grid.GetCells()):
        mol = to_draw[idx]
        disp = oedepict.OE2DMolDisplay(mol, opts)
        oedepict.OERenderMolecule(cell, disp)

    oedepict.OEWriteImage(filename, image)

    return
Beispiel #2
0
def DrawHelloWorlds(font, basefilename):

    image = oedepict.OEImage(200, 60)
    DrawHelloWorld(image, font)

    oedepict.OEWriteImage(basefilename + ".png", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)
def DrawFigures(pen, basefilename):

    image = oedepict.OEImage(80, 80)
    DrawFigure(image, pen)

    oedepict.OEWriteImage(basefilename + ".png", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)
def DepictColorGradient(colorg, opts, basefilename):

    width, height = 400, 100
    image = oedepict.OEImage(width, height)
    oegrapheme.OEDrawColorGradient(image, colorg, opts)

    oedepict.OEWriteImage(basefilename + ".png", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)
Beispiel #5
0
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oedepict.OEConfigureImageWidth(itf, 400.0)
    oedepict.OEConfigureImageHeight(itf, 400.0)
    oedepict.OEConfigureImageGridParams(itf)
    oedepict.OEConfigurePrepareDepictionOptions(itf)
    oedepict.OEConfigure2DMolDisplayOptions(itf)

    if not oechem.OEParseCommandLine(itf, argv):
        oechem.OEThrow.Fatal("Unable to interpret command line!")

    oname = itf.GetString("-out")

    ext = oechem.OEGetFileExtension(oname)
    if not oedepict.OEIsRegisteredImageFile(ext):
        oechem.OEThrow.Fatal("Unknown image type!")

    ofs = oechem.oeofstream()
    if not ofs.open(oname):
        oechem.OEThrow.Fatal("Cannot open output file!")

    width, height = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight(
        itf)
    image = oedepict.OEImage(width, height)

    rows = oedepict.OEGetImageGridNumRows(itf)
    cols = oedepict.OEGetImageGridNumColumns(itf)
    grid = oedepict.OEImageGrid(image, rows, cols)

    popts = oedepict.OEPrepareDepictionOptions()
    oedepict.OESetupPrepareDepictionOptions(popts, itf)

    dopts = oedepict.OE2DMolDisplayOptions()
    oedepict.OESetup2DMolDisplayOptions(dopts, itf)
    dopts.SetDimensions(grid.GetCellWidth(), grid.GetCellHeight(),
                        oedepict.OEScale_AutoScale)

    celliter = grid.GetCells()
    for iname in itf.GetStringList("-in"):
        ifs = oechem.oemolistream()
        if not ifs.open(iname):
            oechem.OEThrow.Warning("Cannot open %s input file!" % iname)
            continue

        for mol in ifs.GetOEGraphMols():
            if not celliter.IsValid():
                break

            oedepict.OEPrepareDepiction(mol, popts)
            disp = oedepict.OE2DMolDisplay(mol, dopts)
            oedepict.OERenderMolecule(celliter.Target(), disp)
            celliter.Next()

    oedepict.OEWriteImage(ofs, ext, image)

    return 0
def smiles_to_image_grid_mod(
    smiles: set,
    output_path: str,
    cols: int = 8,
    cell_width: int = 200,
    cell_height: int = 200,
):
    from openeye import oechem, oedepict

    itf = oechem.OEInterface()
    PageByPage = True
    suppress_h = True
    rows = math.ceil(len(smiles) / cols)

    image = oedepict.OEImage(cell_width * cols, cell_height * rows)
    grid = oedepict.OEImageGrid(image, rows, cols)

    opts = oedepict.OE2DMolDisplayOptions(
        grid.GetCellWidth(), grid.GetCellHeight(), oedepict.OEScale_AutoScale
    )
    opts.SetAromaticStyle(oedepict.OEAromaticStyle_Circle)
    opts.SetTitleLocation(oedepict.OETitleLocation_Bottom)


    for i, (smi, cell) in enumerate(zip(smiles, grid.GetCells())):

        mol = oechem.OEGraphMol()
        oechem.OESmilesToMol(mol, smi)
        center_bond = []
        for atom in mol.GetAtoms():
            if atom.GetMapIdx() >0:
                center_bond.append(atom.GetIdx())
        # print(smi, center_bond)
        assert len(center_bond) == 2
        oedepict.OEPrepareDepiction(mol, False, suppress_h)
        disp = oedepict.OE2DMolDisplay(mol, opts)

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

            def __call__(self, bond):
                return (bond.GetBgn().GetIdx() in center_bond) and (bond.GetEnd().GetIdx() in center_bond)

        atoms = mol.GetAtoms(NoAtom())
        bonds = mol.GetBonds(CentralBondInTorsion())
        abset = oechem.OEAtomBondSet(atoms, bonds)
        oedepict.OEAddHighlighting(disp, oechem.OEColor(oechem.OEMandarin), oedepict.OEHighlightStyle_BallAndStick, abset)

        oedepict.OERenderMolecule(cell, disp)

    oedepict.OEWriteImage(output_path, image)
Beispiel #7
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)
def DepictPeptide(opts, smiles, basefilename):

    mol = oechem.OEGraphMol()
    oechem.OESmilesToMol(mol, smiles)
    oedepict.OEPrepareDepiction(mol)

    image = oedepict.OEImage(400, 200)
    oegrapheme.OEDrawPeptide(image, mol, opts)

    oedepict.OEWriteImage(basefilename + ".svg", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)
    oedepict.OEWriteImage(basefilename + ".png", image)
Beispiel #9
0
def plot_indices(mol2, width=200, height=200):
    mol = mol2.CreateCopy()

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

    disp = oedepict.OE2DMolDisplay(mol, opts)
    img = oedepict.OEImage(width, height)

    oedepict.OERenderMolecule(img, disp)
    return img
Beispiel #10
0
def highlight_atoms_in_mol(mol2, dihedralAtomIndices, width=200, height=200):
    mol = mol2.CreateCopy()
    opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale)
    oedepict.OEPrepareDepiction(mol)

    disp = oedepict.OE2DMolDisplay(mol, opts)
    img = oedepict.OEImage(width, height)

    hstyle = oedepict.OEHighlightByBallAndStick(oechem.OEBlueTint)
    for atom_idx in dihedralAtomIndices:
        oedepict.OEAddHighlighting(disp, hstyle, oechem.OEHasAtomIdx(atom_idx))

    oedepict.OERenderMolecule(img, disp)
    return img
def DrawQuadraticBezier():
    # @ <SNIPPET-DRAW-QUADRATIC-BEZIER>
    image = oedepict.OEImage(100, 100)

    b = oedepict.OE2DPoint(20, 70)
    e = oedepict.OE2DPoint(80, 70)
    c = b + oedepict.OE2DPoint(30, -80)

    pen = oedepict.OEPen(oechem.OELightGreen, oechem.OEBlack,
                         oedepict.OEFill_On, 2.0)
    image.DrawQuadraticBezier(b, c, e, pen)
    # @ </SNIPPET-DRAW-QUADRATIC-BEZIER>
    oedepict.OEWriteImage("DrawQuadraticBezier.png", image)
    oedepict.OEWriteImage("DrawQuadraticBezier.pdf", image)
Beispiel #12
0
def DepictMolecules(opts, smiles, basefilename, drawborder=False):

    mol = oechem.OEGraphMol()
    oechem.OESmilesToMol(mol, smiles)
    oedepict.OEPrepareDepiction(mol)

    disp = oedepict.OE2DMolDisplay(mol, opts)
    image = oedepict.OEImage(disp.GetWidth(), disp.GetHeight())
    oedepict.OERenderMolecule(image, disp)

    if drawborder:
        oedepict.OEDrawBorder(image, oedepict.OELightGreyPen)

    oedepict.OEWriteImage(basefilename + ".png", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)
Beispiel #13
0
 def __setupImage(self):
     """Internal method to configure a single page image."""
     #
     self.__image = oedepict.OEImage(self._params["imageSizeX"],
                                     self._params["imageSizeY"])
     self.__grid = oedepict.OEImageGrid(self.__image,
                                        self._params["gridRows"],
                                        self._params["gridCols"])
     self.__grid.SetCellGap(self._params["cellGap"])
     self.__grid.SetMargins(self._params["cellMargin"])
     self._opts = oedepict.OE2DMolDisplayOptions(
         self.__grid.GetCellWidth(), self.__grid.GetCellHeight(),
         oedepict.OEScale_AutoScale)
     #
     logger.debug("Num columns %d", self.__grid.NumCols())
     logger.debug("Num rows    %d", self.__grid.NumRows())
def DrawCubicBezier():
    # @ <SNIPPET-CUBIC-BEZIER>
    image = oedepict.OEImage(100, 100)

    b = oedepict.OE2DPoint(20, 70)
    e = oedepict.OE2DPoint(60, 70)
    c1 = b + oedepict.OE2DPoint(50, -60)
    c2 = e + oedepict.OE2DPoint(50, -60)

    pen = oedepict.OEPen(oechem.OELightGreen, oechem.OEBlack,
                         oedepict.OEFill_On, 2.0)
    image.DrawCubicBezier(b, c1, c2, e, pen)

    # @ </SNIPPET-CUBIC-BEZIER>
    oedepict.OEWriteImage("DrawCubicBezier.png", image)
    oedepict.OEWriteImage("DrawCubicBezier.pdf", image)
Beispiel #15
0
def DepictMoleculesWithHighlight(smiles, ss, highlight, basefilename):

    mol = oechem.OEGraphMol()
    oechem.OESmilesToMol(mol, smiles)
    oedepict.OEPrepareDepiction(mol)
    opts = oedepict.OE2DMolDisplayOptions(220, 160, oedepict.OEScale_AutoScale)
    disp = oedepict.OE2DMolDisplay(mol, opts)

    unique = True
    for match in ss.Match(mol, unique):
        oedepict.OEAddHighlighting(disp, highlight, match)

    image = oedepict.OEImage(disp.GetWidth(), disp.GetHeight())
    oedepict.OERenderMolecule(image, disp)

    oedepict.OEWriteImage(basefilename + ".png", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)
def DrawPolygon():
    # @ <SNIPPET-DRAW-POLYGON>
    image = oedepict.OEImage(100, 100)

    polygon = []
    polygon.append(oedepict.OE2DPoint(20, 20))
    polygon.append(oedepict.OE2DPoint(40, 40))
    polygon.append(oedepict.OE2DPoint(60, 20))
    polygon.append(oedepict.OE2DPoint(80, 40))
    polygon.append(oedepict.OE2DPoint(80, 80))
    polygon.append(oedepict.OE2DPoint(20, 80))

    pen = oedepict.OEPen(oechem.OELightGreen, oechem.OEBlack,
                         oedepict.OEFill_On, 2.0)
    image.DrawPolygon(polygon, pen)
    # @ </SNIPPET-DRAW-POLYGON>
    oedepict.OEWriteImage("DrawPolygon.png", image)
    oedepict.OEWriteImage("DrawPolygon.pdf", image)
Beispiel #17
0
def DepictMoleculesWithHighlight(smiles, ss, highlight, basefilename):

    mol = oechem.OEGraphMol()
    oechem.OESmilesToMol(mol, smiles)
    oedepict.OEPrepareDepiction(mol)

    opts = oedepict.OE2DMolDisplayOptions(250, 160, oedepict.OEScale_AutoScale)
    opts.SetTitleLocation(oedepict.OETitleLocation_Hidden)
    disp = oedepict.OE2DMolDisplay(mol, opts)

    unique = True
    oedepict.OEAddHighlightOverlay(disp, highlight, ss.Match(mol, unique))

    image = oedepict.OEImage(disp.GetWidth(), disp.GetHeight())
    oedepict.OERenderMolecule(image, disp)

    oedepict.OEWriteImage(basefilename + ".png", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)
Beispiel #18
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
Beispiel #19
0
def plot_dihedral(mol2, width=200, height=200):
    mol = mol2.CreateCopy()
    dihedralAtomIndices = [
        int(x) - 1 for x in get_sd_data(mol, "TORSION_ATOMS_FRAGMENT").split()
    ]
    dih, tor = get_dihedral(mol, dihedralAtomIndices)

    opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale)
    oedepict.OEPrepareDepiction(mol)

    disp = oedepict.OE2DMolDisplay(mol, opts)
    img = oedepict.OEImage(width, height)

    hstyle = oedepict.OEHighlightByBallAndStick(oechem.OEBlueTint)
    oedepict.OEAddHighlighting(disp, hstyle, dih)
    hstyle = oedepict.OEHighlightByColor(oechem.OERed)
    oedepict.OEAddHighlighting(disp, hstyle, tor)

    oedepict.OERenderMolecule(img, disp)
    return img
Beispiel #20
0
def WriteTable(tableoptions, basefilename):

    image = oedepict.OEImage(300, 200)
    table = oedepict.OEImageTable(image, tableoptions)

    for idx, cell in enumerate(table.GetHeaderCells()):
        table.DrawText(cell, "(header %d)" % (idx + 1))

    for idx, cell in enumerate(table.GetStubColumnCells()):
        table.DrawText(cell, "(stub %d)" % (idx + 1))

    onlybody = True
    for row in range(1, table.NumRows(onlybody) + 1):
        for col in range(1, table.NumColumns(onlybody) + 1):
            cell = table.GetBodyCell(row, col)
            table.DrawText(cell, "(body %d, %d)" % (row, col))

    oedepict.OEDrawBorder(image, oedepict.OELightGreyPen)
    oedepict.OEWriteImage(basefilename + ".png", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)
Beispiel #21
0
def draw_subsearch_highlights(mol, subsearch, width=400.0, height=400.0):
    """
    Draws the hits for the substructure in a given molecule.
    
    Copied from http://notebooks.eyesopen.com/substructure-search-pandas-oenotebook.html
    """
    opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale)

    mol = oechem.OEGraphMol(mol)
    oedepict.OEPrepareDepiction(mol)
    img = oedepict.OEImage(width, height)
    hstyle = oedepict.OEHighlightByBallAndStick(oechem.OEBlueTint)

    disp = oedepict.OE2DMolDisplay(mol, opts)
    unique = True
    for match in subsearch.Match(mol, unique):
        oedepict.OEAddHighlighting(disp, hstyle, match)

    oedepict.OERenderMolecule(img, disp)
    # return oenb.draw_oeimage_to_img_tag(img)
    return img
def DrawPath():
    # @ <SNIPPET-DRAW-PATH>
    image = oedepict.OEImage(100, 100)

    path = oedepict.OE2DPath(oedepict.OE2DPoint(20, 80))
    path.AddLineSegment(oedepict.OE2DPoint(80, 80))
    path.AddLineSegment(oedepict.OE2DPoint(80, 40))
    path.AddCurveSegment(oedepict.OE2DPoint(80,
                                            10), oedepict.OE2DPoint(20, 10),
                         oedepict.OE2DPoint(20, 40))

    pen = oedepict.OEPen(oechem.OELightGreen, oechem.OEBlack,
                         oedepict.OEFill_On, 2.0)
    image.DrawPath(path, pen)

    # @ </SNIPPET-DRAW-PATH>
    oedepict.OEWriteImage("DrawPath.png", image)
    oedepict.OEWriteImage("DrawPath.pdf", image)

    # @ <SNIPPET-GET-PATH-POINTS>
    for p in path.GetPoints():
        pos = p.GetPoint()
        print(" %.1f %.1f %d" % (pos.GetX(), pos.GetY(), p.GetPointType()))
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 #24
0
# 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-IMAGE-TABLE>
from openeye import oechem
from openeye import oedepict

smiles = ["c1ccccc1 benzene", "c1cccnc1 pyridine", "c1cncnc1 pyrimidine"]

imagewidth, imageheight = 350, 250
image = oedepict.OEImage(imagewidth, imageheight)

mainrows, maincols = 3, 2
maintableopts = oedepict.OEImageTableOptions(
    mainrows, maincols, oedepict.OEImageTableStyle_NoStyle)
maintableopts.SetHeader(False)
maintableopts.SetColumnWidths([10, 20])
maintable = oedepict.OEImageTable(image, maintableopts)

datarows, datacols = 4, 2
datatableopts = oedepict.OEImageTableOptions(
    datarows, datacols, oedepict.OEImageTableStyle_LightGreen)
datatableopts.SetStubColumn(True)
datatableopts.SetMargins(5.0)
datatableopts.SetColumnWidths([10, 20])
#
# 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
from openeye import oegrapheme

# @ <SNIPPET-DRAW-COLOR-GRADIENT>
colorg = oechem.OELinearColorGradient(oechem.OEColorStop(0.0, oechem.OEYellow))
colorg.AddStop(oechem.OEColorStop(+1.0, oechem.OEOrange))
colorg.AddStop(oechem.OEColorStop(-1.0, oechem.OEGreen))

image = oedepict.OEImage(400, 100)
oegrapheme.OEDrawColorGradient(image, colorg)
oedepict.OEWriteImage("DrawColorGradient.png", image)
# @ </SNIPPET-DRAW-COLOR-GRADIENT>
oedepict.OEWriteImage("DrawColorGradient.pdf", image)
Beispiel #26
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>
# 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-TOGGLEATOMTEXT>
width, height = 400, 200
image = oedepict.OEImage(width, height)

mol = oechem.OEGraphMol()
smiles = "Cc1cccnc1/C=C/[C@H](C(=O)O)O"
oechem.OESmilesToMol(mol, smiles)
oedepict.OEPrepareDepiction(mol)

opts = oedepict.OE2DMolDisplayOptions(width, height,
                                      oedepict.OEScale_AutoScale)
opts.SetMargins(10)
disp = oedepict.OE2DMolDisplay(mol, opts)

font = oedepict.OEFont(oedepict.OEFontFamily_Default,
                       oedepict.OEFontStyle_Default, 12,
                       oedepict.OEAlignment_Center, oechem.OEDarkRed)
Beispiel #28
0
# 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

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cc(N)cc(S(=O)(=O)O)c1 3-aminobenzenesulfonic acid")
oedepict.OEPrepareDepiction(mol)

# @ <SNIPPET-DEPICT-MOL-TRANSPARENT>
width, height, scale = 200.0, 200.0, oedepict.OEScale_AutoScale
image = oedepict.OEImage(width, height, oechem.OETransparentColor)

opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
disp = oedepict.OE2DMolDisplay(mol, opts)

clearbackground = True
oedepict.OERenderMolecule("DepictMolTransparent.png", disp, not clearbackground)
# @ </SNIPPET-DEPICT-MOL-TRANSPARENT>
oedepict.OERenderMolecule("DepictMolTransparent.pdf", disp, not clearbackground)
oedepict.OERenderMolecule("DepictMolTransparent.svg", disp, not clearbackground)
Beispiel #29
0
def main(argv=[__name__]):
    """
    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    oname = itf.GetString("-out")
    iname = itf.GetString("-in")

    ext = oechem.OEGetFileExtension(oname)
    if not oedepict.OEIsRegisteredImageFile(ext):
        oechem.OEThrow.Fatal("Unknown image type!")

    ofs = oechem.oeofstream()
    if not ofs.open(oname):
        oechem.OEThrow.Fatal("Cannot open output file!")

  
    ## INPUT PARAMETERS
    #########################################################
    #########################################################
    
    mm = 'tyk2/og_pdbs'
    qml = 'tyk2/forward_snapshots'
    phase = 'solvent'
    which_ligand = 'old'
    dir_name = iname
    ligand_pdbs_mm = glob.glob(f"{mm}/{dir_name}/{which_ligand}*{phase}.pdb")
    print(len(ligand_pdbs_mm))
    ligand_pdbs_qml = glob.glob(f"{qml}/{dir_name}/{which_ligand}*{phase}.pdb")
    print(len(ligand_pdbs_qml))

    #d = np.load('full_data_dict.npy', allow_pickle=True)
    from_ligand, to_ligand = iname.replace('from', '').replace('to', '').replace('lig', '')
    print(from_ligand)
    print(to_ligand)
    #key1 = (1, 8)
    #key2 = ('solvent', which_ligand)
    #########################################################
    #########################################################

    #d = d.flatten()[0]
    #work = d[key1][key2]
    #print(work)

    
    for i, (mm_pdb_path, ani_pdb_path) in enumerate(zip(ligand_pdbs_mm, ligand_pdbs_qml)):
        print(mm_pdb_path, ani_pdb_path)
        if i == 0:
            MM_mol = createOEMolFromSDF(mm_pdb_path, 0)
            ANI_mol = createOEMolFromSDF(ani_pdb_path, 0)
        else:
            # there absolutely must be a better/faster way of doing this because this is ugly and slow
            MM_mol.NewConf(createOEMolFromSDF(mm_pdb_path, 0))
            ANI_mol.NewConf(createOEMolFromSDF(ani_pdb_path, 0))
"""
    ofs = oechem.oeofstream()
    oname = f"tor_out"
    ext = oechem.OEGetFileExtension(oname)

    mm_pdb_path = f"og_lig0_solvent.pdb"
    ani_pdb_path = f"forward_lig0.solvent.pdb"
    MM_mol = createOEMolFromSDF(mm_pdb_path, 0)
    ANI_mol = createOEMolFromSDF(ani_pdb_path, 0)

    mol = MM_mol
    mol2 = ANI_mol

    for m in [mol, mol2]:
        oechem.OESuppressHydrogens(m)
        oechem.OECanonicalOrderAtoms(m)
        oechem.OECanonicalOrderBonds(m)
        m.Sweep()

    refmol = None

    stag = "dihedral_histogram"
    itag = oechem.OEGetTag(stag)

    nrbins = 20

    print(mol.NumConfs())
    print(mol2.NumConfs())

    get_dihedrals(mol, itag)
    set_dihedral_histograms(mol, itag, nrbins)

    get_dihedrals(mol2, itag)
    #set_weighted_dihedral_histograms(mol2, itag, work, nrbins)
    set_dihedral_histograms(mol2, itag, nrbins)

    width, height = 800, 400
    image = oedepict.OEImage(width, height)

    moffset = oedepict.OE2DPoint(0, 0)
    mframe = oedepict.OEImageFrame(image, width * 0.70, height, moffset)
    doffset = oedepict.OE2DPoint(mframe.GetWidth(), height * 0.30)
    dframe = oedepict.OEImageFrame(image, width * 0.30, height * 0.5, doffset)

    flexibility = True
    colorg = get_color_gradient(nrbins, flexibility)

    opts = oedepict.OE2DMolDisplayOptions(mframe.GetWidth(),
                                          mframe.GetHeight(),
                                          oedepict.OEScale_AutoScale)

    depict_dihedrals(mframe, dframe, mol, mol2, refmol, opts, itag, nrbins,
                     colorg)

    if flexibility:
        lopts = oedepict.OELegendLayoutOptions(
            oedepict.OELegendLayoutStyle_HorizontalTopLeft,
            oedepict.OELegendColorStyle_LightBlue,
            oedepict.OELegendInteractiveStyle_Hover)
        lopts.SetButtonWidthScale(1.2)
        lopts.SetButtonHeightScale(1.2)
        lopts.SetMargin(oedepict.OEMargin_Right, 40.0)
        lopts.SetMargin(oedepict.OEMargin_Bottom, 80.0)

        legend = oedepict.OELegendLayout(image, "Legend", lopts)

        legend_area = legend.GetLegendArea()
        draw_color_gradient(legend_area, colorg)

        oedepict.OEDrawLegendLayout(legend)

    iconscale = 0.5
    oedepict.OEAddInteractiveIcon(image, oedepict.OEIconLocation_TopRight,
                                  iconscale)
    oedepict.OEDrawCurvedBorder(image, oedepict.OELightGreyPen, 10.0)

    oedepict.OEWriteImage(ofs, ext, image)

    return 0
Beispiel #30
0
    mol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, mol):
        oechem.OEThrow.Fatal("Unable to read molecule in %s" % filename)

    return mol


if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <receptor> <ligand>" % sys.argv[0])

receptor = ImportMolecule(sys.argv[1])
ligand = ImportMolecule(sys.argv[2])

asite = oechem.OEInteractionHintContainer(receptor, ligand)
oechem.OEPerceiveInteractionHints(asite)
oegrapheme.OEPrepareActiveSiteDepiction(asite)

# @ <SNIPPET-OERENDERACTIVESITE-IMAGE-ADISP>
# initializing asite oechem.OEInteractionHintContainer(receptor, ligand) object

image = oedepict.OEImage(800.0, 600.0)
opts = oegrapheme.OE2DActiveSiteDisplayOptions(image.GetWidth(), image.GetHeight())
opts.SetRenderInteractiveLegend(True)
adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)

oegrapheme.OERenderActiveSite(image, adisp)
oedepict.OEWriteImage("OERenderActiveSite-image-adisp.svg", image)
# @ </SNIPPET-OERENDERACTIVESITE-IMAGE-ADISP>
oedepict.OEWriteImage("OERenderActiveSite-image-adisp.pdf", image)