def CanSmi(mol, isomeric, kekule): oechem.OEFindRingAtomsAndBonds(mol) oechem.OEAssignAromaticFlags(mol, oechem.OEAroModel_OpenEye) smiflag = oechem.OESMILESFlag_Canonical if isomeric: smiflag |= oechem.OESMILESFlag_ISOMERIC if kekule: for bond in mol.GetBonds(oechem.OEIsAromaticBond()): bond.SetIntType(5) oechem.OECanonicalOrderAtoms(mol) oechem.OECanonicalOrderBonds(mol) oechem.OEClearAromaticFlags(mol) oechem.OEKekulize(mol) smi = oechem.OECreateSmiString(mol, smiflag) return smi
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_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)
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)
print("number of aromatic atoms groups", oechem.OECount(mol, oechem.OEHasGroupType(oechem.OEGetTag("aromatic atoms")))) print("number of aromatic bonds groups", oechem.OECount(mol, oechem.OEHasGroupType(oechem.OEGetTag("aromatic bonds")))) # loop over groups for g in mol.GetGroups(): DumpGroup(g) print() mol = oechem.OEGraphMol() oechem.OESmilesToMol(mol, "CN1c2ccc(cc2C(=NCC1=O)c3ccccc3)Cl") mol.SetTitle("valium") # generate some groups atoms = oechem.OEAtomVector() for atom in mol.GetAtoms(oechem.OEIsAromaticAtom()): atoms.append(atom) atomgroup = mol.NewGroup(oechem.OEGetTag("aromatic atoms"), atoms) bonds = oechem.OEBondVector() for bond in mol.GetBonds(oechem.OEIsAromaticBond()): bonds.append(bond) bondgroup = mol.NewGroup(oechem.OEGetTag("aromatic bonds"), bonds) DumpGroups(mol) # delete a group mol.DeleteGroup(bondgroup) DumpGroups(mol) # @ </SNIPPET>