Rdkit常用命令/参数设置

该博客介绍了使用RDKit库进行分子结构的读取、可视化及反应位点识别的方法。通过查看SDF文件获取分子信息,使用DrawingOptions绘制带ID的原子图,并高亮显示反应物和生成物的相同结构。此外,还展示了如何通过SMARTS字符串解析反应并识别反应位点。
摘要由CSDN通过智能技术生成

rdkit

1.查看sdf

在这里插入图片描述

	"""
	查看sdf
	"""
mols = Chem.SDMolSupplier('file_path')
for mol in mols:
	#隐藏属性,得到第一行文字
	ID = mol.GetProp('_Name') 
	#得到所有分子属性
	mol_keys = mol.GetPropsAsDict().keys()
	
2.绘制可视图片

可以highlight反应物和生成物里相同的结构
绘制带id的mol文件

	"""
	绘制反应可视图片
	"""
def draw_mol(mol_file, save_mol_path):

    opts = DrawingOptions()
    opts.includeAtomNumbers = True
    opts.includeAtomNumbers = True
    opts.bondLineWidth = 2.8
    Draw.MolToFile(
        mol_file,  # mol对象
        save_mol_path,  # 图片存储地址
        size=(4000, 2000),
        kekulize=True,
        wedgeBonds=True,
        imageType=None,
        fitImage=False,
        options=opts,
    )
    """
    high light
    """
def draw_highlight(reaction, save_reaction_path):
	d2d = Draw.MolDraw2DCairo(4000, 2000)
	d2d.DrawReaction(reaction, highlightByReactant=True)
	png = d2d.GetDrawingText()
	open(save_reaction_path, 'wb+').write(png)

    """
    从mol文件绘制带标签的原子图
    """
def mol_with_atom_index(mol_file):
	atoms = mol_file.GetNumAtoms()
	for idx in range(atoms):
		mol_file.GetAtomWithIdx(idx).SetProp('molAtomMapNumber',
		 str(mol.GetAtomWithIdx(idx).GetIdx()))
def draw_mol(mol_file, save_mol_path):
    opts = DrawingOptions()
    opts.includeAtomNumbers = True
    opts.includeAtomNumbers = True
    opts.bondLineWidth = 2.8
    Draw.MolToFile(
        mol_file,  # mol对象
        save_mol_path,  # 图片存储地址
        size=(4000, 2000),
        kekulize=True,
        wedgeBonds=True,
        imageType=None,
        fitImage=False,
        options=opts,
    )

完整代码:github(Draw.py)

3.根据反应aam识别反应位点
aam = '[CH3:1][CH:28]([CH:26]([CH:25]=[CH:24][CH:23]([CH3:19])[C:20]1([C:17]2([C:2]([H:30])([C:3](=[CH:4][CH:5]=[C:6]3[C:7](=[CH2:8])[CH2:9][CH2:10][CH:11]([OH:12])[CH2:13]3)[CH2:14][CH2:15][CH2:16]2)[CH2:22][CH2:21]1)[CH3:18])[H:31])[CH3:27])[CH3:29]>>[CH3:1][CH:28]([CH3:29])[CH:26]([CH:25]=[CH:24][CH:23]([CH3:19])[C:20]1([C:17]2([C:2]([H:30])([C:3](=[CH:4][CH:5]=[C:6]3[C:7](=[CH2:8])[CH2:9][CH2:10][CH:11]([OH:12])[CH2:13]3)[CH2:14][CH2:15][CH2:16]2)[CH2:22][CH2:21]1)[CH3:18])[H:31])[CH3:27]'
rxn = AllChem.ReactionFromSmarts(aam)
sub_mol = Chem.MolFromSmiles(aam.split('>>')[0])
products = rxn.RunReactants([sub_mol])
print(rxn.GetReactingAtoms())
4.关于mol文件的一些参数

1.MolFromSmiles
在这里插入图片描述

sanitize,分子结构检查,默认值是True。这个选项会列出一些显式H原子(同下面的mergeHs=True),这样的mol文件有些软件识别不了

smi = 'xxxxxxxx'
mol = Chem.MolFromSmiles(smi, sanitize=True/False)

2.MolFromSmarts
mergeHs默认值为False,当值为True时,‘C[H]’ becomes ‘[C;!H0]’

smart = 'xxxxxxxx'
mol = Chem.MolFromSmarts(smi, mergeHs=True/False)

3.SDMolSupplier
removeHs默认值是True。是否忽略H原子

suppl = Chem.SDMolSupplier(sdf_file,removeHs=True)

4.MolToSmiles
isomericSmiles: 立体化学信息。Defaults to true.
kekuleSmiles: 无芳香族键。Defaults to false.
rootedAtAtom: smiles从特定原子开始。 Defaults to -1.
canonical:是否规范化。Defaults to true.
allBondsExplicit: 明确所有键。G Defaults to false.
allHsExplicit: 显示所有H。Defaults to false.

5.MolFromSmarts与MolFromSmiles

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值