LoginSignup
1
0

More than 5 years have passed since last update.

RDKitで部分構造検索~ハイライト画像表示まで

Last updated at Posted at 2019-03-02

環境

  • Python 3.6
  • RDKit 2018
  • Jupyter Notebook

方法

前提としてmols というリストに検索対象の化合物がMol文字列として入っているものとする。以下の流れで部分構造検索をして、ヒットした化合物に対し、ヒットした部分構造をハイライト表示させることが可能である。

# クエリとなる部分構造を生成
from rdkit.Chem import AllChem, Draw, Descriptors, PandasTools
query = AllChem.MolFromSmiles("c1ccccc1c1ccccc1")
Draw.MolToImage(query)

image.png

# 部分構造検索
result = []
for i, mol in enumerate(mols):
    molObj = AllChem.MolFromMolBlock(mol)
    if molObj.HasSubstructMatch(query):
        pattern = molObj.GetSubstructMatches(query)
        result.append(molObj)     

これでresultにヒットした化合物(molオブジェクト)が格納される。例えば一件目の化合物に対しヒットした箇所をハイライト表示するには以下のようにすればよい。

# ハイライト表示
pattern = result[0].GetSubstructMatches(query)
Draw.MolToImage(result[0], highlightAtoms=pattern[0])

image.png

ここでpatternには、ヒット箇所のリストがはいっているので、ここでは最初に得られたヒット箇所をハイライトさせている。

ちなみに、複数の化合物をまとめて表示させるには、Draw.MolToImagesを用いる。

大量の化合物を検索する場合には、これでは遅いため、部分構造のfingerprintを用いて高速化する方法をあらためて記載したい。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0