def DrawFigures(pen, basefilename):

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

    oedepict.OEWriteImage(basefilename + ".png", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)
Example #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 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)
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)
Example #5
0
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)
Example #6
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)
Example #7
0
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)
Example #8
0
 def write(self, imagePath):
     try:
         dirPath, _ = os.path.split(imagePath)
         if not os.access(dirPath, os.W_OK):
             os.makedirs(dirPath, mode=0o755)
     except Exception:
         pass
     oedepict.OEWriteImage(imagePath, self.__image)
Example #9
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)
Example #10
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
Example #11
0
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)
Example #12
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)
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)
Example #14
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
Example #15
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)
Example #16
0
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()))
opts = oedepict.OE2DMolDisplayOptions(grid.GetCellWidth(),
                                      grid.GetCellHeight(),
                                      oedepict.OEScale_AutoScale)

cell = grid.GetCell(1, 1)
mol.SetTitle("Reaction display")
opts.SetAtomVisibilityFunctor(
    oechem.OEIsTrueAtom())  # explicitly set the default
disp = oedepict.OE2DMolDisplay(mol, opts)
rxnscale = disp.GetScale()
oedepict.OERenderMolecule(cell, disp)

cell = grid.GetCell(1, 2)
mol.SetTitle("Reactant display")
opts.SetAtomVisibilityFunctor(
    OEAtomVisibilityShowRxnRole(oechem.OERxnRole_Reactant))
opts.SetScale(rxnscale)
disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule(cell, disp)

cell = grid.GetCell(1, 3)
mol.SetTitle("Product display")
opts.SetAtomVisibilityFunctor(
    OEAtomVisibilityShowRxnRole(oechem.OERxnRole_Product))
opts.SetScale(rxnscale)
disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule(cell, disp)

# @ </SNIPPET-ATOM-VISIBILITY>
oedepict.OEWriteImage(sys.argv[2], image)
Example #18
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
Example #19
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)
def gen_pdf(
    tid_clusters_list: list,
    output_path: str,
    cols: int = 8,
    cell_width: int = 200,
    cell_height: int = 200,
):
    from openeye import oechem, oedepict
    from openforcefield.topology import Molecule
    itf = oechem.OEInterface()
    PageByPage = True
    suppress_h = True

    n = sum([len(clusters) for tid, clusters in tid_clusters_list.items()])
    rows = math.ceil(n / 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)

    count = 0

    for tid, clusters in tid_clusters_list.items():
        for cluster in clusters:
            torsions = cluster['torsions']
            label = cluster['cluster_label']
            torsions = cluster['torsions']
            for torsion in torsions:
                cell = grid.GetCell(count // cols + 1, count % cols + 1)
                smi = torsion['mol_index']
                atom_indices = torsion['indices']
                # mol = oechem.OEGraphMol()
                # oechem.OESmilesToMol(mol, smi)

                off_mol = Molecule.from_smiles(smi,
                                               allow_undefined_stereo=True)
                off_mol = off_mol.canonical_order_atoms()
                mol = Molecule.to_openeye(off_mol)

                title = '{} ({})'.format(tid, set(torsion['covered_tids']))
                mol.SetTitle(title)

                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 AtomInTorsion(oechem.OEUnaryAtomPred):
                    def __call__(self, atom):
                        return atom.GetIdx() in atom_indices

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

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

                atoms = mol.GetAtoms(AtomInTorsion())
                bonds = mol.GetBonds(NoBond())
                abset = oechem.OEAtomBondSet(atoms, bonds)
                oedepict.OEAddHighlighting(
                    disp, oechem.OEColor(oechem.OEYellow),
                    oedepict.OEHighlightStyle_BallAndStick, abset)

                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)
                count += 1
    oedepict.OEWriteImage(output_path, image)
Example #21
0
image = oedepict.OEImage(500, 300)

rows, cols = 1, 2
grid = oedepict.OEImageGrid(image, rows, cols)

overlaps = oegraphsim.OEGetFPOverlap(refmol, fitmol,
                                     oegraphsim.OEGetFPType(oegraphsim.OEFPType_Tree))
oedepict.OEPrepareMultiAlignedDepiction(fitmol, refmol, overlaps)

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

refscale = oedepict.OEGetMoleculeScale(refmol, opts)
fitscale = oedepict.OEGetMoleculeScale(fitmol, opts)
opts.SetScale(min(refscale, fitscale))

refdisp = oedepict.OE2DMolDisplay(refmol, opts)
fitdisp = oedepict.OE2DMolDisplay(fitmol, opts)

refcell = grid.GetCell(1, 1)
oedepict.OERenderMolecule(refcell, refdisp)

fitcell = grid.GetCell(1, 2)
oedepict.OERenderMolecule(fitcell, fitdisp)

oedepict.OEWriteImage("FPAlign.png", image)
# @ </SNIPPET-FINGERPRINT-ALIGN>
oedepict.OEWriteImage("FPAlign.pdf", image)
Example #22
0
# 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

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol,
                     "c1cc(N)cc(S(=O)(=O)O)c1 3-aminobenzenesulfonic acid")
oedepict.OEPrepareDepiction(mol)
# @ <SNIPPET-OEDEPICTMOLECULE-IMAGE-DISP>
oedepict.OEPrepareDepiction(mol)

image = oedepict.OEImage(200.0, 200.0)
opts = oedepict.OE2DMolDisplayOptions(image.GetWidth(), image.GetHeight(),
                                      oedepict.OEScale_AutoScale)
disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule(image, disp)
# @ </SNIPPET-OEDEPICTMOLECULE-IMAGE-DISP>
oedepict.OEWriteImage("OERenderMolecule-image-disp.png", image)
oedepict.OEWriteImage("OERenderMolecule-image-disp.pdf", image)
Example #23
0
from openeye import oegrapheme
from openeye import oeshape

###############################################################
# USED TO GENERATE CODE SNIPPETS FOR THE GRAPHEME DOCUMENTATION
###############################################################

if len(sys.argv) != 2:
    oechem.OEThrow.Usage("%s <mol file>" % sys.argv[0])

ifs = oechem.oemolistream(sys.argv[1])
refmol = oechem.OEGraphMol()
oechem.OEReadMolecule(ifs, refmol)

# @ <SNIPPET-RENDER-SHAPE-QUERY>
opts = oegrapheme.OEShapeQueryDisplayOptions()
opts.SetTitleLocation(oedepict.OETitleLocation_Hidden)
arcpen = oedepict.OEPen(oechem.OEWhite, oechem.OELightGrey, oedepict.OEFill_On,
                        2.0)
opts.SetSurfaceArcFxn(oegrapheme.OEDefaultArcFxn(arcpen))

cff = oeshape.OEColorForceField()
cff.Init(oeshape.OEColorFFType_ImplicitMillsDean)
disp = oegrapheme.OEShapeQueryDisplay(refmol, cff, opts)

image = oedepict.OEImage(420.0, 280.0)
oegrapheme.OERenderShapeQuery(image, disp)
# @ </SNIPPET-RENDER-SHAPE-QUERY>
oedepict.OEWriteImage("RenderShapeQuery.png", image)
oedepict.OEWriteImage("RenderShapeQuery.pdf", image)
Example #24
0
# 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 oedepict

# @ <SNIPPET-DRAW-LINE>
width, height = 100, 100
# Create image
image = oedepict.OEImage(width, height)

# Draw line with default pen
bgn = oedepict.OE2DPoint(10.0, 10.0)
end = oedepict.OE2DPoint(90.0, 90.0)
image.DrawLine(bgn, end, oedepict.OEBlackPen)

# Write image to SVG file
oedepict.OEWriteImage("DrawLine.svg", image)
# @ </SNIPPET-DRAW-LINE>
oedepict.OEWriteImage("DrawLine.png", image)
oedepict.OEWriteImage("DrawLine.pdf", image)
Example #25
0
# @ <SNIPPET-IMAGE-FRAME>
def DrawMolecule(image, mol, width, height, offset):

    frame = oedepict.OEImageFrame(image, width, height, offset)

    oedepict.OEDrawBorder(frame, oedepict.OELightGreyPen)

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

    clearbackground = True
    oedepict.OERenderMolecule(frame, disp, not clearbackground)


image = oedepict.OEImage(400, 400)

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C1CC(O)CNC1")
oedepict.OEPrepareDepiction(mol)

DrawMolecule(image, mol, 60, 60, oedepict.OE2DPoint(50.0, 40.0))
DrawMolecule(image, mol, 180, 180, oedepict.OE2DPoint(180.0, 120.0))
DrawMolecule(image, mol, 80, 80, oedepict.OE2DPoint(300.0, 20.0))
DrawMolecule(image, mol, 50, 50, oedepict.OE2DPoint(150.0, 320.0))
DrawMolecule(image, mol, 20, 20, oedepict.OE2DPoint(360.0, 360.0))

oedepict.OEWriteImage("ImageFrame.png", image)
# @ </SNIPPET-IMAGE-FRAME>
oedepict.OEWriteImage("ImageFrame.pdf", image)
Example #26
0
                          oedepict.OEFill_Off, 2.0,
                          oedepict.OEStipple_ShortDash)
    arcfxnA = oegrapheme.OEDefaultArcFxn(penA)

    for arc in oegrapheme.OEGet2DSurfaceArcs(
            disp, oegrapheme.OESurfaceArcScale_Minimum):
        arcfxnA(layer, arc)

    penB = oedepict.OEPen(oechem.OEGrey, oechem.OEGrey, oedepict.OEFill_Off,
                          2.0)
    arcfxnB = oegrapheme.OEDefaultArcFxn(penB)

    for arc in oegrapheme.OEGet2DSurfaceArcs(disp, radiusScales):
        arcfxnB(layer, arc)

    oedepict.OERenderMolecule(image, disp)


# @ </SNIPPET-DRAW-2D-SURFACE-VARIOUS-RADII>

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cc(sc1CCl)Br")
oedepict.OEPrepareDepiction(mol)

imagewidth, imageheight = 300.0, 240.0
image = oedepict.OEImage(imagewidth, imageheight)
DrawSurfaces(image, mol)

oedepict.OEWriteImage("Draw2DSurfaceVariousRadii.png", image)
oedepict.OEWriteImage("Draw2DSurfaceVariousRadii.pdf", image)
#
# 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)
Example #28
0
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oedepict.OEConfigureImageWidth(itf, 900.0)
    oedepict.OEConfigureImageHeight(itf, 600.0)
    oedepict.OEConfigure2DMolDisplayOptions(
        itf, oedepict.OE2DMolDisplaySetup_AromaticStyle)
    oechem.OEConfigureSplitMolComplexOptions(
        itf, oechem.OESplitMolComplexSetup_LigName)

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

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

    ifs = oechem.oemolistream()
    if not ifs.open(iname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    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!")

    complexmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, complexmol):
        oechem.OEThrow.Fatal("Unable to read molecule from %s" % iname)

    if not oechem.OEHasResidues(complexmol):
        oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All)

    # Separate ligand and protein

    sopts = oechem.OESplitMolComplexOptions()
    oechem.OESetupSplitMolComplexOptions(sopts, itf)

    ligand = oechem.OEGraphMol()
    protein = oechem.OEGraphMol()
    water = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    pfilter = sopts.GetProteinFilter()
    wfilter = sopts.GetWaterFilter()
    sopts.SetProteinFilter(oechem.OEOrRoleSet(pfilter, wfilter))
    sopts.SetWaterFilter(
        oechem.OEMolComplexFilterFactory(
            oechem.OEMolComplexFilterCategory_Nothing))

    oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts)

    if ligand.NumAtoms() == 0:
        oechem.OEThrow.Fatal("Cannot separate complex!")

    # Perceive interactions

    asite = oechem.OEInteractionHintContainer(protein, ligand)
    if not asite.IsValid():
        oechem.OEThrow.Fatal("Cannot initialize active site!")
    asite.SetTitle(ligand.GetTitle())

    oechem.OEPerceiveInteractionHints(asite)

    oegrapheme.OEPrepareActiveSiteDepiction(asite)

    # Depict active site with interactions

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

    cframe = oedepict.OEImageFrame(image, width * 0.80, height,
                                   oedepict.OE2DPoint(0.0, 0.0))
    lframe = oedepict.OEImageFrame(image, width * 0.20, height,
                                   oedepict.OE2DPoint(width * 0.80, 0.0))

    opts = oegrapheme.OE2DActiveSiteDisplayOptions(cframe.GetWidth(),
                                                   cframe.GetHeight())
    oedepict.OESetup2DMolDisplayOptions(opts, itf)

    adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)
    oegrapheme.OERenderActiveSite(cframe, adisp)

    lopts = oegrapheme.OE2DActiveSiteLegendDisplayOptions(10, 1)
    oegrapheme.OEDrawActiveSiteLegend(lframe, adisp, lopts)

    oedepict.OEWriteImage(oname, image)

    return 0
Example #29
0
    opts.SetTitleLocation(oedepict.OETitleLocation_Hidden)

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

    disp = oedepict.OE2DMolDisplay(mol, opts)
    oedepict.OERenderMolecule(cell, disp)

    # depicting data in table
    cell = maintable.GetBodyCell(r + 1, 2)

    table = oedepict.OEImageTable(cell, datatableopts)

    table.DrawText(table.GetHeaderCell(1, False), "Property")
    table.DrawText(table.GetHeaderCell(1), "Value")

    table.DrawText(table.GetStubColumnCell(1), "Name")
    table.DrawText(table.GetBodyCell(1, 1), mol.GetTitle())

    table.DrawText(table.GetStubColumnCell(2), "SMILES")
    table.DrawText(table.GetBodyCell(2, 1), oechem.OEMolToSmiles(mol))

    table.DrawText(table.GetStubColumnCell(3), "MV")
    table.DrawText(table.GetBodyCell(3, 1),
                   "%.3f" % oechem.OECalculateMolecularWeight(mol))

oedepict.OEWriteImage("ImageTable.png", image)
# @ </SNIPPET-IMAGE-TABLE>
oedepict.OEWriteImage("ImageTable.pdf", image)
Example #30
0
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict

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

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cccnc1O")
oedepict.OEPrepareDepiction(mol)
oedepict.OERenderMolecule(image, mol)

# @ <SNIPPET-LEGEND-LAYOUT>
opts = oedepict.OELegendLayoutOptions(
    oedepict.OELegendLayoutStyle_VerticalTopRight,
    oedepict.OELegendColorStyle_LightGreen,
    oedepict.OELegendInteractiveStyle_Toggle)
opts.SetButtonWidthScale(1.5)
opts.SetButtonHeightScale(1.5)
legend = oedepict.OELegendLayout(image, "Legend", opts)

legend_area = legend.GetLegendArea()
oedepict.OEAddWatermark(legend_area, "This is the legend area")
oedepict.OEAddInteractiveIcon(image, oedepict.OEIconLocation_BottomRight, 0.75)
oedepict.OEDrawLegendLayout(legend)

oedepict.OEWriteImage("LegendLayout.svg", image)
# @ </SNIPPET-LEGEND-LAYOUT>