def png_atoms_labeled(smiles, fname): """Write out png file of molecule with atoms labeled with their index. Parameters ---------- smiles: str SMILES fname: str absolute path and filename for png """ mol = oechem.OEGraphMol() oechem.OESmilesToMol(mol, smiles) oedepict.OEPrepareDepiction(mol) width, height = 300, 200 opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale) opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx()) opts.SetAtomPropLabelFont(oedepict.OEFont(oechem.OEDarkGreen)) disp = oedepict.OE2DMolDisplay(mol, opts) return oedepict.OERenderMolecule(fname, disp)
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 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
def genHBIndexGuide(inpmol): """ For each mol, generate depiction of molecule with labeled indices as read in by oechem. Saved as _____ """ mol = oechem.OEGraphMol(inpmol) dopt = oedepict.OEPrepareDepictionOptions() dopt.SetDepictOrientation(oedepict.OEDepictOrientation_Horizontal) oedepict.OEPrepareDepiction(mol, dopt) opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale) opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx()) oedepict.OERenderMolecule(outfn, mol)
def png_atoms_labeled(smiles, fname, map_idx=True, width=600, height=400, label_scale=2.0, scale_bondwidth=True): """Write out png file of molecule with atoms labeled with their map index. Parameters ---------- smiles: str SMILES fname: str absolute path and filename for png map_idx: bool If True, lable atoms with map index instead of atom index. If set to True, input SMILES must have map indices. """ mol = oechem.OEGraphMol() oechem.OESmilesToMol(mol, smiles) oedepict.OEPrepareDepiction(mol) opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale) if map_idx: # check if molecule has map if not cmiles.utils.has_atom_map(mol): raise ValueError( "Input SMILES must have atom maps to display map indices in image" ) opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomMapIdx()) opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomMapIdx()) if not map_idx: opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx()) opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomMapIdx()) opts.SetAtomPropLabelFont(oedepict.OEFont(oechem.OEDarkGreen)) opts.SetAtomPropLabelFontScale(label_scale) opts.SetBondWidthScaling(scale_bondwidth) disp = oedepict.OE2DMolDisplay(mol, opts) return oedepict.OERenderMolecule(fname, disp)
def _assignDisplayOptions(self): if self._params["labelAtomCIPStereo"]: # self._opts.SetAtomStereoStyle( oedepict.OEAtomStereoStyle_Display_All) # self._opts.SetAtomStereoStyle(oedepict.OEAtomStereoStyle_Display_CIPAtomStereo) if self._params["labelBondCIPStereo"]: # will include bowties for undefined stereo # self._opts.SetBondStereoStyle(oedepict.OEBondStereoStyle_Display_All) self._opts.SetBondStereoStyle( oedepict.OEBondStereoStyle_Display_CIPBondStereo) self._opts.SetAtomPropLabelFontScale(0.650) if self._params["labelAtomIndex"]: self._opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx()) self._opts.SetAtomPropLabelFont(oedepict.OEFont( oechem.OEDarkGreen)) self._opts.SetAtomPropLabelFontScale(0.650) if self._params["labelBondIndex"]: self._opts.SetBondPropertyFunctor(oedepict.OEDisplayBondIdx()) self._opts.SetBondPropLabelFont(oedepict.OEFont(oechem.OEDarkBlue)) if self._params["labelAtomName"]: atomlabel = LabelAtoms() self._opts.SetAtomPropertyFunctor(atomlabel) self._opts.SetAtomPropLabelFont(oedepict.OEFont( oechem.OEDarkGreen)) self._opts.SetAtomPropLabelFontScale(0.650) if self._params["bondDisplayWidth"] is not None: pen = oedepict.OEPen(oechem.OEBlack, oechem.OEBlack, oedepict.OEFill_On, self._params["bondDisplayWidth"]) self._opts.SetDefaultBondPen(pen) # remove for the moment. not supported on all platforms # self._opts.SetBondWidthScaling(False) # # 5.0 is minimum size - self._opts.SetTitleHeight(5.0)
# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-LABEL-FONT-SCALE> width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale opts = oedepict.OE2DMolDisplayOptions(width, height, scale) opts.SetAtomLabelFontScale(1.5) # @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-LABEL-FONT-SCALE> DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomLabelFontScale") # @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-PROP-LABEL-FONT> width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale opts = oedepict.OE2DMolDisplayOptions(width, height, scale) font = oedepict.OEFont() font.SetStyle(oedepict.OEFontStyle_Bold) font.SetColor(oechem.OEDarkGreen) opts.SetAtomPropLabelFont(font) opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx()) # @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-PROP-LABEL-FONT> DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomPropLabelFont") # @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-PROPERTY-FUNCTOR> width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale opts = oedepict.OE2DMolDisplayOptions(width, height, scale) opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx()) # @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-PROPERTY-FUNCTOR> DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomPropertyFunctor") # @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-PROP-LABEL-FONT-SCALE> width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale opts = oedepict.OE2DMolDisplayOptions(width, height, scale) opts.SetAtomPropLabelFontScale(1.5) opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx())
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)