# or its use. # @ <SNIPPET> from __future__ import print_function from openeye import oechem mol = oechem.OEGraphMol() oechem.OESmilesToMol(mol, "c1cnc(O)cc1CCCBr") print("Number of chain atoms =", end=" ") print(oechem.OECount(mol, oechem.OENotAtom(oechem.OEAtomIsInRing()))) print("Number of aromatic nitrogens =", end=" ") print( oechem.OECount( mol, oechem.OEAndAtom(oechem.OEIsNitrogen(), oechem.OEIsAromaticAtom()))) print("Number of non-carbons =", end=" ") print( oechem.OECount(mol, oechem.OENotAtom(oechem.OEHasAtomicNum(oechem.OEElemNo_C)))) print("Number of nitrogen and oxygen atoms =", end=" ") print( oechem.OECount( mol, oechem.OEOrAtom(oechem.OEHasAtomicNum(oechem.OEElemNo_N), oechem.OEHasAtomicNum(oechem.OEElemNo_O)))) # @ </SNIPPET>
# # 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. # @ <SNIPPET> from __future__ import print_function from openeye import oechem mol = oechem.OEGraphMol() if not oechem.OEParseSmiles(mol, "C1=CC=CC=C1"): print("SMILES string was invalid!") print("Number of aromatic atoms =", oechem.OECount(mol, oechem.OEIsAromaticAtom())) oechem.OEAssignAromaticFlags(mol) print("Number of aromatic atoms =", oechem.OECount(mol, oechem.OEIsAromaticAtom())) # @ </SNIPPET>
# 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 # @ <SNIPPET-AROM-PERCEIVE> mol = oechem.OEGraphMol() oechem.OEParseSmiles(mol, "C1[NH]C=CC=1CO") oechem.OEAssignAromaticFlags(mol) # @ </SNIPPET-AROM-PERCEIVE> # @ <SNIPPET-AROM-LOOP1> for atom in mol.GetAtoms(oechem.OEIsAromaticAtom()): print(atom.GetIdx(), oechem.OEGetAtomicSymbol(atom.GetAtomicNum())) # @ </SNIPPET-AROM-LOOP1> # @ <SNIPPET-AROM-LOOP2> for atom in mol.GetAtoms(): if atom.IsAromatic(): print(atom.GetIdx(), oechem.OEGetAtomicSymbol(atom.GetAtomicNum())) # @ </SNIPPET-AROM-LOOP2> # @ </SNIPPET>
def highltigh_torsion_by_cluster(mapped_molecule, clustered_dihedrals, fname, width=600, height=400): """ Highlight torsion by cluster. This is used to visualize clustering output. Parameters ---------- mapped_molecule: oemol with map indices clustered_dihedrals fname width height Returns ------- """ mol = oechem.OEMol(mapped_molecule) atom_bond_sets = [] for cluster in clustered_dihedrals: atom_bond_set = oechem.OEAtomBondSet() for dihedral in clustered_dihedrals[cluster]: a = mol.GetAtom(oechem.OEHasMapIdx(dihedral[0] + 1)) atom_bond_set.AddAtom(a) for idx in dihedral[1:]: a2 = mol.GetAtom(oechem.OEHasMapIdx(idx + 1)) atom_bond_set.AddAtom(a2) bond = mol.GetBond(a, a2) atom_bond_set.AddBond(bond) a = a2 atom_bond_sets.append(atom_bond_set) dopt = oedepict.OEPrepareDepictionOptions() dopt.SetSuppressHydrogens(False) oedepict.OEPrepareDepiction(mol, dopt) opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale) opts.SetTitleLocation(oedepict.OETitleLocation_Hidden) disp = oedepict.OE2DMolDisplay(mol, opts) aroStyle = oedepict.OEHighlightStyle_Color aroColor = oechem.OEColor(oechem.OEBlack) oedepict.OEAddHighlighting(disp, aroColor, aroStyle, oechem.OEIsAromaticAtom(), oechem.OEIsAromaticBond()) hstyle = oedepict.OEHighlightStyle_BallAndStick # if color: # highlight = oechem.OEColor(color) # # combine all atom_bond_sets # atom_bond_set = oechem.OEAtomBondSet() # for ab_set in atom_bond_sets: # for a in ab_set.GetAtoms(): # atom_bond_set.AddAtom(a) # for b in ab_set.GetBonds(): # atom_bond_set.AddBond(b) # oedepict.OEAddHighlighting(disp, highlight, hstyle, atom_bond_set) # else: highlight = oedepict.OEHighlightOverlayByBallAndStick( oechem.OEGetContrastColors()) oedepict.OEAddHighlightOverlay(disp, highlight, atom_bond_sets) #hcolor = oechem.OEColor(oechem.OELightBlue) #oedepict.OEAddHighlighting(disp, hcolor, hstyle, atom_bond_sets) return oedepict.OERenderMolecule(fname, disp)
def highlight_torsion(mapped_molecule, dihedrals, fname, width=600, height=400, combine_central_bond=True, color=None): mol = oechem.OEMol(mapped_molecule) atom_bond_sets = [] if combine_central_bond: central_bonds = [(tor[1], tor[2]) for tor in dihedrals] eq_torsions = { cb: [ tor for tor in dihedrals if cb == (tor[1], tor[2]) or cb == (tor[2], tor[1]) ] for cb in central_bonds } for cb in eq_torsions: atom_bond_set = oechem.OEAtomBondSet() for dihedral in eq_torsions[cb]: a = mol.GetAtom(oechem.OEHasMapIdx(dihedral[0] + 1)) atom_bond_set.AddAtom(a) for idx in dihedral[1:]: a2 = mol.GetAtom(oechem.OEHasMapIdx(idx + 1)) atom_bond_set.AddAtom((a2)) bond = mol.GetBond(a, a2) atom_bond_set.AddBond(bond) a = a2 atom_bond_sets.append(atom_bond_set) if not combine_central_bond: for dihedral in dihedrals: atom_bond_set = oechem.OEAtomBondSet() a = mol.GetAtom(oechem.OEHasMapIdx(dihedral[0] + 1)) atom_bond_set.AddAtom(a) for idx in dihedral[1:]: a2 = mol.GetAtom(oechem.OEHasMapIdx(idx + 1)) atom_bond_set.AddAtom((a2)) bond = mol.GetBond(a, a2) atom_bond_set.AddBond(bond) a = a2 atom_bond_sets.append(atom_bond_set) dopt = oedepict.OEPrepareDepictionOptions() dopt.SetSuppressHydrogens(False) oedepict.OEPrepareDepiction(mol, dopt) opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale) opts.SetTitleLocation(oedepict.OETitleLocation_Hidden) disp = oedepict.OE2DMolDisplay(mol, opts) aroStyle = oedepict.OEHighlightStyle_Color aroColor = oechem.OEColor(oechem.OEBlack) oedepict.OEAddHighlighting(disp, aroColor, aroStyle, oechem.OEIsAromaticAtom(), oechem.OEIsAromaticBond()) hstyle = oedepict.OEHighlightStyle_BallAndStick if color: highlight = oechem.OEColor(color) # combine all atom_bond_sets atom_bond_set = oechem.OEAtomBondSet() for ab_set in atom_bond_sets: for a in ab_set.GetAtoms(): atom_bond_set.AddAtom(a) for b in ab_set.GetBonds(): atom_bond_set.AddBond(b) oedepict.OEAddHighlighting(disp, highlight, hstyle, atom_bond_set) else: highlight = oedepict.OEHighlightOverlayByBallAndStick( oechem.OEGetContrastColors()) oedepict.OEAddHighlightOverlay(disp, highlight, atom_bond_sets) #hcolor = oechem.OEColor(oechem.OELightBlue) #oedepict.OEAddHighlighting(disp, hcolor, hstyle, atom_bond_sets) return oedepict.OERenderMolecule(fname, disp)
def highlight_bonds(mol_copy, fname, conjugation=True, rotor=False, width=600, height=400, label=None): """ Generate image of molecule with highlighted bonds. The bonds can either be highlighted with a conjugation tag or if it is rotatable. Parameters ---------- mol_copy: OEMol fname: str Name of image file conjugation: Bool, optional, Default is True If True, the bonds with conjugation tag set to True will be highlighted rotor: Bool, optional, Default is False If True, the rotatable bonds will be highlighted. width: int height: int label: string. Optional, Default is None The bond order label. The options are WibergBondOrder, Wiberg_psi4, Mayer_psi4. """ mol = oechem.OEMol(mol_copy) bond_index_list = [] for bond in mol.GetBonds(): if conjugation: try: if bond.GetData('conjugated'): bond_index_list.append(bond.GetIdx()) except ValueError: pass if rotor: if bond.IsRotor(): bond_index_list.append(bond.GetIdx()) atomBondSet = oechem.OEAtomBondSet() for bond in mol.GetBonds(): if bond.GetIdx() in bond_index_list: atomBondSet.AddBond(bond) atomBondSet.AddAtom(bond.GetBgn()) atomBondSet.AddAtom(bond.GetEnd()) dopt = oedepict.OEPrepareDepictionOptions() dopt.SetSuppressHydrogens(True) oedepict.OEPrepareDepiction(mol, dopt) opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale) opts.SetTitleLocation(oedepict.OETitleLocation_Hidden) if label is not None: bond_label = { 'WibergBondOrder': LabelWibergBondOrder, 'Wiberg_psi4': LabelWibergPsiBondOrder, 'Mayer_psi4': LabelMayerPsiBondOrder } bondlabel = bond_label[label] opts.SetBondPropertyFunctor(bondlabel()) disp = oedepict.OE2DMolDisplay(mol, opts) aroStyle = oedepict.OEHighlightStyle_Color aroColor = oechem.OEColor(oechem.OEBlack) oedepict.OEAddHighlighting(disp, aroColor, aroStyle, oechem.OEIsAromaticAtom(), oechem.OEIsAromaticBond()) hstyle = oedepict.OEHighlightStyle_BallAndStick hcolor = oechem.OEColor(oechem.OELightBlue) oedepict.OEAddHighlighting(disp, hcolor, hstyle, atomBondSet) return oedepict.OERenderMolecule(fname, disp)