def plotMol(pdb,filename): pdbName = reformatPDB(pdb,1) mol = Chem.MolFromPDBFile(pdbName,removeHs=False,sanitize=False) os.remove(pdbName) # AllChem.GenerateDepictionMatching2DStructure(mol,refMol) opt = Draw.DrawingOptions() opt.bgColor=None Draw.MolToFile(mol,filename,kekulize=False,options=opt)
def defaultDrawOptions(): '''This function returns an RDKit drawing options object with default drawing options.''' opts = Draw.DrawingOptions() # opts.elemDict = defaultdict(lambda: (0,0,0)) # all atoms are black opts.noCarbonSymbols = True opts.selectColor = (1, 0, 0) opts.wedgeBonds = True return opts
def defaultDrawOptions(): """Returns an RDKit drawing options object with default drawing options.""" opts = Draw.DrawingOptions() # opts.elemDict = defaultdict(lambda: (0,0,0)) # all atoms are black opts.noCarbonSymbols = True opts.selectColor = (1, 0, 0) opts.wedgeBonds = True opts.elemDict = defaultdict(lambda: (0, 0, 0)) opts.dotsPerAngstrom = 20 opts.bondLineWidth = 1.5 atomLabelFontFace = 'arial' return opts
def testSpecialCases(self): options = Draw.DrawingOptions() options.atomLabelDeuteriumTritium = True self._testMolToImage(mol=Chem.MolFromSmiles('[2H][C@]([3H])(C)F'), options=options) # shared rings self._testMolToImage(mol=Chem.MolFromSmiles('c1cccc2cc(cccc3)c3cc21')) self._testMolToImage(mol=Chem.MolFromSmiles('C1=CC=CC=CC=C1')) self._testMolToImage(mol=Chem.MolFromSmiles('C=C=C')) self._testMolToImage(mol=Chem.MolFromSmiles('CC#N'), showImage=False) self._testMolToImage(mol=Chem.MolFromSmiles('[CH2-][C-2]C[CH3+][CH5+2]')) self._testMolToImage(mol=Chem.MolFromSmiles('[Na+].[OH-]')) self._testMolToImage(mol=Chem.MolFromSmiles('c1ccccc1c1ccccc1'), highlightAtoms=(0, 1, 2, 3, 4, 5, 6)) self._testMolToImage(mol=Chem.MolFromSmiles('c1ccccc1c1ccccc1'), highlightBonds=(0, 2, 4, 6, 8, 10)) self._testMolToImage(mol=Chem.MolFromSmiles('c1ccccc1c1ccc(cc1)c1ccc(cc1)c1ccc(cc1)'))
def Convert(self, prop, **kwargs): """ Converts MOL structure into SVG image. Args: prop: pyeds.PropertyValue Property to convert. Returns: image: str or None SVG image data. """ # check value if not prop.Value: return None # try to convert into RDKit object try: from rdkit.Chem import AllChem from rdkit.Chem import Draw mol = AllChem.MolFromMolBlock(prop.Value) except ImportError: return None # get image path filename = "%s.%s" % (str(uuid.uuid4()), "svg") path = os.path.join(tempfile.gettempdir(), filename) # set drawing options options = Draw.DrawingOptions() options.bgColor = None options.defaultColor = (0, 0, 0) options.colorBonds = False options.coordScale = 1.0 # make image Draw.MolToFile(mol, path, size=(120, 75), options=options, fitImage=False, ignoreHs=True) # read image data with open(path) as svg_file: svg = svg_file.read() # delete file os.remove(path) return svg
def _CairoDrawer(self, rdmol): """Render an svg using cairo or agg renderer.""" # Some drawing options options = Draw.DrawingOptions() options.bondLineWidth = 1 # Prepare drawing useAGG, useCairo, Canvas = Draw._getCanvas() canvas = Canvas(size=(self.width, self.height), imageType='svg', fileName=self.svgfile) drawer = Draw.MolDrawing(canvas=canvas, drawingOptions=options) drawer.AddMol(rdmol) if self.legend is not None: from rdkit.Chem.Draw.MolDrawing import Font pos = (self.width / 2, int(.1 * self.height), 0) font = Font(face='serif', size=18) canvas.addCanvasText(self.legend, pos, font) canvas.flush()
data_new = data_new.drop(['ID'],axis = 1) data_new.index = range(len(data_new)) data_new.to_csv(r"C:\Users\86136\Desktop\result\RNN_weight" +'\\'+str(i)+'_new_weight.csv') ################################################################################################### ####画图,画出每个化合物的前10个重要元素 from rdkit import Chem from rdkit.Chem import AllChem from rdkit.Chem import Draw from rdkit.Chem import PandasTools import pandas as pd data_csv= pd.read_csv(r"C:\Users\86136\Desktop\CYSLTR1_DATA\CYSLT1_standerd_database.csv") Chem.PandasTools.AddMoleculeColumnToFrame(data_csv, smilesCol='SMILES', molCol='MOL', includeFingerprints=True) opts = Draw.DrawingOptions() opts.elemDict = {1: (0, 0, 0), 7: (0, 0, 0), 8: (0, 0, 0), 9: (0, 0, 0), 15: (0, 0, 0), 16: (0, 0, 0), 17: (0, 0, 0), 35: (0, 0, 0), 53: (0, 0, 0), 0: (0, 0, 0)} for i in range(len(data_csv)): if data_csv['new_value'][i] == 1: #每一个化合物的attention weight
from rdkit import Chem from rdkit.Chem import Draw from rdkit.Chem.Draw import rdDepictor, SimilarityMaps def RobustSmilesMolSupplier(filename): with open(filename) as f: for line in f: words = line.split() smile = words[0] name = " ".join(words[1:]) # everything after the SMILES string yield (name, Chem.MolFromSmiles(smile)) # draw all atoms in black drawOptions = Draw.DrawingOptions() drawOptions.elemDict = {} drawOptions.bgColor = None if __name__ == '__main__': if len(sys.argv) != 3: print("usage: %s molecules.smi molecules.delta" % sys.argv[0]) exit(1) smiles_fn = sys.argv[1] deltas_fn = sys.argv[2] delta_max = 0.1 # arbitrary, to normalize deltas and color-scale them delta_file = open(deltas_fn, 'r') count = 0 for long_name, mol in RobustSmilesMolSupplier(smiles_fn): # split by '_' in case name was postfixed with underscores # and additional data