RDKit建化合物库-拼接

  • from rdkit import Chem
  • # 函数一:获取marker邻居原子的indexdef get_neiid_bysymbol(mol, marker):
  •     try:
  •         for atom in mol.GetAtoms():
  •             if atom.GetSymbol() == marker:
  •                 neighbors = atom.GetNeighbors()
  •                 if len(neighbors) > 1:
  •                     print('Cannot process more than one neighbor, will only return one of them')
  •                 atom_nb = neighbors[0]
  •                 return atom_nb.GetIdx()
  •     except Exception as e:
  •         print(e)
  •         return None
  • # 函数二:获取marker原子的indexdef get_id_bysymbol(mol, marker):
  •     for atom in mol.GetAtoms():
  •         if atom.GetSymbol() == marker:
  •             return atom.GetIdx()
  • # 示例
  • mol = Chem.MolFromSmiles('CCBr')
  • marker = 'Br'
  • # 获取标记原子邻居的索引
  • nei_idx = get_neiid_bysymbol(mol, marker)print(f"Neighbor Index: {nei_idx}")
  • # 获取标记原子的索引
  • marker_idx = get_id_bysymbol(mol, marker)print(f"Marker Index: {marker_idx}")