def getCCDefObj(self, dataContainer, molBuildType="model-xyz", suppressHydrogens=False): """Build OE molecule from the input chemical component definition object.""" # oemf = OeMoleculeFactory() if not self.__verbose: oemf.setQuiet() ccId = oemf.setChemCompDef(dataContainer) oemf.build(molBuildType=molBuildType) if self.__verbose: logger.info(" CCId = %s", ccId) logger.info(" Title = %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()) fD = {} fD = {"Formula": oemf.getFormula(), "SMILES": oemf.getCanSMILES(), "SMILES_STEREO": oemf.getIsoSMILES(), "InChI": oemf.getInChI(), "InChIKey": oemf.getInChIKey()} if suppressHydrogens: tMol = oemf.getGraphMolSuppressH() else: tMol = oemf.getMol() fD["OEMOL"] = tMol fD["xyz"] = oemf.getAtomDetails(xyzType="model") return (ccId, tMol, fD)
def getCCDefFile(self, ccFilePath, molBuildType="model-xyz", suppressHydrogens=False): """Fetch the molecule definition (ccPath) and build OE molecules for comparison. """ # mU = MarshalUtil(workPath=self.__workPath) rdCcObjL = mU.doImport(ccFilePath, fmt="mmcif") oemf = OeMoleculeFactory() if not self.__verbose: oemf.setQuiet() ccId = oemf.setChemCompDef(rdCcObjL[0]) oemf.build(molBuildType=molBuildType) if self.__verbose: logger.info(" CCId = %s", ccId) logger.info(" Title = %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()) fD = {} fD = {"Formula": oemf.getFormula(), "SMILES": oemf.getCanSMILES(), "SMILES_STEREO": oemf.getIsoSMILES(), "InChI": oemf.getInChI(), "InChIKey": oemf.getInChIKey()} if suppressHydrogens: tMol = oemf.getGraphMolSuppressH() else: tMol = oemf.getMol() fD["OEMOL"] = tMol fD["xyz"] = oemf.getAtomDetails(xyzType="model") return (ccId, tMol, fD)
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