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 canonical_order_atoms(molecule, in_place=True): """ Canonical order of atom indices. This ensures the map indices are always in the same order. Parameters ---------- molecule: oechem.OEMol in_place: bool, optional, default True If True, the order of atom indices will happen in place. If False, a copy of the molecule with reordered atom indices will be returned. Returns ------- molecule: OEMol with canonical ordered atom indices. """ if not in_place: molecule = copy.deepcopy(molecule) oechem.OECanonicalOrderAtoms(molecule) oechem.OECanonicalOrderBonds(molecule) vatm = [] for atom in molecule.GetAtoms(): if atom.GetAtomicNum() != oechem.OEElemNo_H: vatm.append(atom) molecule.OrderAtoms(vatm) vbnd = [] for bond in molecule.GetBonds(): if bond.GetBgn().GetAtomicNum() != oechem.OEElemNo_H and bond.GetEnd( ).GetAtomicNum() != oechem.OEElemNo_H: vbnd.append(bond) molecule.OrderBonds(vbnd) molecule.Sweep() for bond in molecule.GetBonds(): if bond.GetBgnIdx() > bond.GetEndIdx(): bond.SwapEnds() if not in_place: return molecule
def CanSmi(mol, isomeric, kekule): """ Returns the cannonical smile from the OEMol provided :param mol: OEMolBase object :param isomeric: force isometric :param kekule: use kekule cleaning :return: string of OESmiles """ 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 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
if args.UseOpenEye == 'Y' and not step_complete(charged_FN): from openeye import oechem from openeye import oequacpac mol = oechem.OEGraphMol() if os.path.isfile(args.inp): ifs = oechem.oemolistream(args.inp) oechem.OEReadMolecule(ifs, mol) ifs.close() else: # Create a OpenEye molecule object from the SMILES string if not oechem.OESmilesToMol(mol, smi): raise Exception('Invalid SMILES string', smi) oechem.OECanonicalOrderAtoms(mol) oechem.OECanonicalOrderBonds(mol) # Assign a reasonable protomer if args.RetainProtonation: for atom in mol.GetAtoms(): atom.SetImplicitHCount(0) else: if not oequacpac.OEGetReasonableProtomer(mol): print 'Failed to get a reasonable protomer at pH 7.4' oechem.OEAssignAromaticFlags(mol, oechem.OEAroModelOpenEye) if not args.RetainProtonation: oechem.OEAddExplicitHydrogens(mol)
# 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 src = oechem.OEGraphMol() oechem.OESmilesToMol(src, "c1ccccc1") # make holes in the molecule index space and juggle things around oechem.OEAddExplicitHydrogens(src) oechem.OESuppressHydrogens(src) oechem.OEAddExplicitHydrogens(src) oechem.OECanonicalOrderAtoms(src) atommap = oechem.OEAtomArray(src.GetMaxAtomIdx()) dst = oechem.OEGraphMol() oechem.OECopyMol(dst, src, atommap) for srcatom in src.GetAtoms(): dstatom = atommap[srcatom.GetIdx()] print(srcatom.GetIdx(), " -> ", dstatom.GetIdx()) # @ </SNIPPET>