def _legacyMolToFile(mol, fileName, size, kekulize, wedgeBonds, imageType, fitImage, options, **kwargs): """ Generates a drawing of a molecule and writes it to a file """ if options is None: options = DrawingOptions() useAGG, useCairo, Canvas = _getCanvas() if fitImage: options.dotsPerAngstrom = int(min(size) / 10) options.wedgeDashedBonds = wedgeBonds if useCairo or useAGG: canvas = Canvas(size=size, imageType=imageType, fileName=fileName) else: options.radicalSymbol = '.' # <- the sping canvas doesn't support unicode well canvas = Canvas(size=size, name=fileName, imageType=imageType) drawer = MolDrawing(canvas=canvas, drawingOptions=options) if kekulize: from rdkit import Chem mol = Chem.Mol(mol.ToBinary()) Chem.Kekulize(mol) if not mol.GetNumConformers(): from rdkit.Chem import AllChem AllChem.Compute2DCoords(mol) drawer.AddMol(mol, **kwargs) if useCairo or useAGG: canvas.flush() else: canvas.save()
def MolToFile(mol, fileName, size=(300, 300), kekulize=True, wedgeBonds=True, imageType=None, fitImage=False, options=None, **kwargs): """ Generates a drawing of a molecule and writes it to a file """ # original contribution from Uwe Hoffmann if not fileName: raise ValueError('no fileName provided') if not mol: raise ValueError('Null molecule provided') if imageType is None: imageType = os.path.splitext(fileName)[1][1:] if options is None: options = DrawingOptions() useAGG, useCairo, Canvas = _getCanvas() if fitImage: options.dotsPerAngstrom = int(min(size) / 10) options.wedgeDashedBonds = wedgeBonds if useCairo or useAGG: canvas = Canvas(size=size, imageType=imageType, fileName=fileName) else: options.radicalSymbol = '.' # <- the sping canvas doesn't support unicode well canvas = Canvas(size=size, name=fileName, imageType=imageType) drawer = MolDrawing(canvas=canvas, drawingOptions=options) if kekulize: from rdkit import Chem mol = Chem.Mol(mol.ToBinary()) Chem.Kekulize(mol) if not mol.GetNumConformers(): from rdkit.Chem import AllChem AllChem.Compute2DCoords(mol) drawer.AddMol(mol, **kwargs) if useCairo or useAGG: canvas.flush() else: canvas.save()
def MolToFile(mol, fileName, size=(300, 300), kekulize=True, wedgeBonds=True, imageType=None, fitImage=False, options=None, **kwargs): """ Generates a drawing of a molecule and writes it to a file """ # original contribution from Uwe Hoffmann if not fileName: raise ValueError('no fileName provided') if not mol: raise ValueError('Null molecule provided') if imageType is None: imageType = os.path.splitext(fileName)[1][1:] if options is None: options = DrawingOptions() useAGG, useCairo, Canvas = _getCanvas() if fitImage: options.dotsPerAngstrom = int(min(size) / 10) options.wedgeDashedBonds = wedgeBonds if useCairo or useAGG: canvas = Canvas(size=size, imageType=imageType, fileName=fileName) else: # <- the sping canvas doesn't support unicode well options.radicalSymbol = '.' canvas = Canvas(size=size, name=fileName, imageType=imageType) drawer = MolDrawing(canvas=canvas, drawingOptions=options) if kekulize: from rdkit import Chem mol = Chem.Mol(mol.ToBinary()) Chem.Kekulize(mol) if not mol.GetNumConformers(): from rdkit.Chem import AllChem AllChem.Compute2DCoords(mol) drawer.AddMol(mol, **kwargs) if useCairo or useAGG: canvas.flush() else: canvas.save()