def testBuildMolFromSDF(self): """Test case - read a test SDF file and build the corresponding OEGraphMol""" self.__lfh.write("\nStarting OeBuildMolTests testBuildolFromSDF\n") try: oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh) if oem.importFile(self.__sdfFilePath, type="3D"): self.__lfh.write("Title = %s\n" % oem.getTitle()) self.__lfh.write("SMILES (canonical) = %s\n" % oem.getCanSMILES()) self.__lfh.write("SMILES (isomeric) = %s\n" % oem.getIsoSMILES()) else: self.__lfh.write("SDF read failed for %s\n" % self.__sdfFilePath) except: # noqa: E722 pylint: disable=bare-except traceback.print_exc(file=self.__lfh) self.fail()
def testDepictOneSDF(self): """Test case - get, read, build OE molecule from SDF file, and depict the molecule.""" self.__lfh.write("\nStarting OeDepictTests testDepictOneSDF\n") try: oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh) if oem.importFile(self.__sdfFilePath, type="3D"): self.__lfh.write("Title = %s\n" % oem.getTitle()) # imagePath = os.path.join(self.__testoutput, "ATP.svg") oed = OeDepict(verbose=self.__verbose, log=self.__lfh) oed.setMolTitleList([("ATP", oem, "Title for ATP")]) oed.setDisplayOptions(labelAtomName=True, labelAtomCIPStereo=True, labelAtomIndex=False, labelBondIndex=False, bondDisplayWidth=0.5) oed.setGridOptions(rows=1, cols=1) oed.prepare() oed.write(imagePath) except: # noqa: E722 pylint: disable=bare-except traceback.print_exc(file=self.__lfh) self.fail()
def __getMiscFile(self, ccPath, suppressHydrogens=False, importType="2D"): """Fetch a miscellaneous chemical file (ccPath) and build OE molecules for comparison and depiction. """ try: oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh) if oem.importFile(ccPath, type=importType): if self.__verbose: self.__lfh.write("+OEAlignDepilsct.__getMiscFile()\n") self.__lfh.write(" Title = %s\n" % oem.getTitle()) self.__lfh.write(" SMILES = %s\n" % oem.getCanSMILES()) self.__lfh.write(" SMILES (stereo) = %s\n" % oem.getIsoSMILES()) self.__lfh.write(" Formula (Hill) = %s\n" % oem.getFormula()) self.__lfh.write(" InChI key = %s\n" % oem.getInChIKey()) self.__lfh.write(" InChI = %s\n" % oem.getInChI()) else: self.__lfh.write( "+OEAlignDepict.__getMiscFile() Read failed for %s\n" % ccPath) return None, None, None # # oem.build2D() ccId = oem.getTitle() if suppressHydrogens: tMol = oem.getGraphMolSuppressH() else: tMol = oem.getMol() molXyzL = [] if importType == "3D": for ii, atm in enumerate(tMol.GetAtoms()): xyzL = OEFloatArray(3) tMol.GetCoords(atm, xyzL) molXyzL.append( (ii, atm.GetIdx(), atm.GetAtomicNum(), atm.GetName(), atm.GetType(), "%.3f" % xyzL[0], "%.3f" % xyzL[1], "%.3f" % xyzL[2])) fD = {} fD = { "Formula": oem.getFormula(), "SMILES": oem.getCanSMILES(), "SMILES_STEREO": oem.getIsoSMILES(), "InChI": oem.getInChI(), "InChIKey": oem.getInChIKey(), "xyz": molXyzL, } for ii, atm in enumerate(tMol.GetAtoms()): xyzL = OEFloatArray(3) tMol.GetCoords(atm, xyzL) if self.__verbose: self.__lfh.write( "OeAlignDepict.__getMiscFile - atom %d %s %s %s %s %r\n" % (ii, atm.GetIdx(), atm.GetAtomicNum(), atm.GetName(), atm.GetType(), xyzL)) return (ccId, tMol, fD) except: # noqa: E722 pylint: disable=bare-except traceback.print_exc(file=self.__lfh) # self.fail() return None, None, None