如何使用 RDKit 将氢原子替换为另一个原子?
How to replace Hydrogen atom with another atom using RDKit?
假设我有如下分子。
smile = 'C(CN)SS'
mol = Chem.MolFromSmiles(smile)
可以看出,N有两个氢原子,S有一个氢原子。我想用碳代替那些氢。
我可以通过下面的代码找到相邻的原子。但是,它只有 returns 个非氢原子。而且,我不知道如何用碳代替氢。
for atom in mol.GetAtoms():
if atom.GetAtomicNum() != 6 and atom.GetTotalNumHs() > 0:
print("Neighbors", [x.GetAtomicNum() for x in atom.GetNeighbors()])
如果您有任何想法,非常感谢您指导我。
你不能将氢视为原子对象的原因是因为这里这些氢被建模为 隐式 氢。 隐式和显式氢之间的区别在this article中得到了很好的总结。这也可以使用 rdkit 看到:
smiles = 'C(CN)SS'
mol = Chem.MolFromSmiles(smiles)
for atom in mol.GetAtoms():
if atom.GetAtomicNum() != 6 and atom.GetTotalNumHs() > 0:
element = atom.GetSymbol()
implicit = atom.GetNumImplicitHs()
explicit = atom.GetNumExplicitHs()
print(element, 'Implicit:', implicit, 'Explicit:', explicit)
>>> N Implicit: 2 Explicit: 0
>>> S Implicit: 1 Explicit: 0
您可以轻松地将原子设置为显式:
mol = Chem.AddHs(mol)
更改子结构最简单的方法是使用函数 Chem.ReplaceSubstructs
:
match = Chem.MolFromSmarts('[NH2]')
repl = Chem.MolFromSmarts('N(-C)-C')
new_mol = Chem.ReplaceSubstructs(mol, match, repl)
好的,考虑到您想将与非碳原子相连的任何氢变成碳,您可以这样做:
smiles = 'C(CN)SS'
mol = Chem.MolFromSmiles(smiles)
mol = Chem.AddHs(mol)
edit = Chem.RWMol(mol)
for atom in edit.GetAtoms():
if atom.GetAtomicNum() != 6:
for nbr in atom.GetNeighbors():
if nbr.GetAtomicNum() == 1:
nbr.SetAtomicNum(6)
Chem.SanitizeMol(edit)
mol = Chem.RemoveHs(edit) # Also converts back to standard Mol
这是一种使用 ReplaceSubstructs()
的方法。
from rdkit import Chem
repl = Chem.MolFromSmiles('C')
patt = Chem.MolFromSmarts('[#1;$([#1][!#6])]') # hydrogen not on carbon
#patt = Chem.MolFromSmarts('[#1;$([#1][#7,#16])]') # hydrogen on nitrogen or sulfur
mol = Chem.AddHs(Chem.MolFromSmiles('C(CN)SS'))
rms = Chem.ReplaceSubstructs(mol, patt, repl, replaceAll=True)
newMol = Chem.RemoveHs(rms[0])
假设我有如下分子。
smile = 'C(CN)SS'
mol = Chem.MolFromSmiles(smile)
可以看出,N有两个氢原子,S有一个氢原子。我想用碳代替那些氢。
我可以通过下面的代码找到相邻的原子。但是,它只有 returns 个非氢原子。而且,我不知道如何用碳代替氢。
for atom in mol.GetAtoms():
if atom.GetAtomicNum() != 6 and atom.GetTotalNumHs() > 0:
print("Neighbors", [x.GetAtomicNum() for x in atom.GetNeighbors()])
如果您有任何想法,非常感谢您指导我。
你不能将氢视为原子对象的原因是因为这里这些氢被建模为 隐式 氢。 隐式和显式氢之间的区别在this article中得到了很好的总结。这也可以使用 rdkit 看到:
smiles = 'C(CN)SS'
mol = Chem.MolFromSmiles(smiles)
for atom in mol.GetAtoms():
if atom.GetAtomicNum() != 6 and atom.GetTotalNumHs() > 0:
element = atom.GetSymbol()
implicit = atom.GetNumImplicitHs()
explicit = atom.GetNumExplicitHs()
print(element, 'Implicit:', implicit, 'Explicit:', explicit)
>>> N Implicit: 2 Explicit: 0
>>> S Implicit: 1 Explicit: 0
您可以轻松地将原子设置为显式:
mol = Chem.AddHs(mol)
更改子结构最简单的方法是使用函数 Chem.ReplaceSubstructs
:
match = Chem.MolFromSmarts('[NH2]')
repl = Chem.MolFromSmarts('N(-C)-C')
new_mol = Chem.ReplaceSubstructs(mol, match, repl)
好的,考虑到您想将与非碳原子相连的任何氢变成碳,您可以这样做:
smiles = 'C(CN)SS'
mol = Chem.MolFromSmiles(smiles)
mol = Chem.AddHs(mol)
edit = Chem.RWMol(mol)
for atom in edit.GetAtoms():
if atom.GetAtomicNum() != 6:
for nbr in atom.GetNeighbors():
if nbr.GetAtomicNum() == 1:
nbr.SetAtomicNum(6)
Chem.SanitizeMol(edit)
mol = Chem.RemoveHs(edit) # Also converts back to standard Mol
这是一种使用 ReplaceSubstructs()
的方法。
from rdkit import Chem
repl = Chem.MolFromSmiles('C')
patt = Chem.MolFromSmarts('[#1;$([#1][!#6])]') # hydrogen not on carbon
#patt = Chem.MolFromSmarts('[#1;$([#1][#7,#16])]') # hydrogen on nitrogen or sulfur
mol = Chem.AddHs(Chem.MolFromSmiles('C(CN)SS'))
rms = Chem.ReplaceSubstructs(mol, patt, repl, replaceAll=True)
newMol = Chem.RemoveHs(rms[0])