def testSelfConsistency(self): """Compare constructed molecule with underlying chemical definitions -""" try: failL = [] ccMolD = self.__getChemCompDefs() # # molBuildTypeL = ["model-xyz", "ideal-xyz", None] # molBuildTypeL = [None] # oemf = OeMoleculeFactory() macmp = MoleculeAnnotationsCompare() limitPerceptions = False # buildTypeRef = "oe-iso-smiles" buildTypeRef = "model-xyz" filterHydrogens = False if buildTypeRef in [ "oe-iso-smiles", "oe-smiles", "cactvs-smiles", "cactvs-iso-smiles", "acdlabs-smiles", "inchi" ]: filterHydrogens = True # for ccId, ccObj in ccMolD.items(): # ---- tId = oemf.setChemCompDef(ccObj) self.assertEqual(tId, ccId) ok = oemf.build(molBuildType=buildTypeRef, limitPerceptions=limitPerceptions, normalize=False) if not ok: logger.info("Build using %r failed for %s", buildTypeRef, ccId) continue # doTautomers = False if doTautomers: tautomerMolL = oemf.getTautomerMolList() logger.info("%s number reasonable tautomers %d", ccId, len(tautomerMolL)) # refFD = macmp.getChemCompFeatures( ccObj, descriptorProgram="OPENEYE", filterHydrogens=filterHydrogens) tstFD = oemf.getOeMoleculeFeatures( filterHydrogens=filterHydrogens) # logger.info("tstFD %r", tstFD) ok, retCmp = macmp.compare(refFD, tstFD, tstInfo="Openeye ISO SMILES") if not ok: logger.info("Comparison failed build type %r and %r", buildTypeRef, ccId) logger.debug( "diff -> atomatic atoms %r stereo atoms %r bond types %r aromatic bonds %r", retCmp.difAromaticAtoms, retCmp.difStereoAtoms, retCmp.difTypeBonds, retCmp.difAromaticBonds, ) failL.append(ccId) # logger.info("Failures (%d) %r: ", len(failL), failL) except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()
def __getMiscFile(self, filePath, suppressHydrogens=False, importType="2D", title=None, largestPart=False): """Fetch a miscellaneous chemical file (ccPath) and build OE molecules for comparison. """ try: oeioU = OeIoUtils() oeMolL = oeioU.fileToMols(filePath, use3D=importType == "3D", largestPart=largestPart) logger.info("Read (%d) from %s ", len(oeMolL), filePath) oeMol = oeMolL[0] ccId = title if title else oeMol.GetTitle() if title: oeMol.SetTitle(ccId) # oemf = OeMoleculeFactory() if not self.__verbose: oemf.setQuiet() oemf.setOeMol(oeMol, ccId) # fD = oemf.getOeMoleculeFeatures() if self.__verbose: logger.info(" Title = %s", title) logger.info(" Title OEMF = %s", oemf.getTitle()) logger.info(" SMILES = %s", oemf.getCanSMILES()) logger.info(" SMILES (stereo) = %s", oemf.getIsoSMILES()) logger.info(" Formula (Hill) = %s", oemf.getFormula()) logger.info(" InChI key = %s", oemf.getInChIKey()) logger.info(" InChI = %s", oemf.getInChI()) # ccId = oemf.getTitle() if suppressHydrogens: tMol = oemf.getGraphMolSuppressH() else: tMol = oemf.getMol() molXyzL = [] if importType == "3D": for atm in tMol.GetAtoms(): xyzL = oechem.OEFloatArray(3) tMol.GetCoords(atm, xyzL) molXyzL.append( ComponentAtomDetails( atIdx=atm.GetIdx(), atNo=atm.GetAtomicNum(), atName=atm.GetName(), atType=atm.GetType(), x=xyzL[0], y=xyzL[1], z=xyzL[2], atFormalCharge=atm.GetFormalCharge(), ) ) fD = {} fD = { "Formula": oemf.getFormula(), "SMILES": oemf.getCanSMILES(), "SMILES_STEREO": oemf.getIsoSMILES(), "InChI": oemf.getInChI(), "InChIKey": oemf.getInChIKey(), "xyz": molXyzL, } for atm in tMol.GetAtoms(): xyzL = oechem.OEFloatArray(3) tMol.GetCoords(atm, xyzL) if self.__verbose: logger.debug("atom %s %s %s %s %r", atm.GetIdx(), atm.GetAtomicNum(), atm.GetName(), atm.GetType(), xyzL) fD["OEMOL"] = tMol return (ccId, tMol, fD) except Exception as e: logger.exception("Failing with %s", str(e)) return None, None, None