LoginSignup
2
1

More than 5 years have passed since last update.

RDKitで原子間の最短パス、距離行列を求める

Last updated at Posted at 2019-04-14

はじめに

RDKitで掲題の件、調査したためメモっておく

環境

  • Windows 10
  • Python 3.6
  • RDKit 2018/9/2

やり方

まずは、必要なものをインポート

from rdkit.Chem import AllChem, Draw, rdmolops
from rdkit.Chem.Draw import IPythonConsole

molファイルを読み込んで、分かりやすいようインデックス付きの画像で化合物を表示。

def mol_with_atom_index( mol ):
    atoms = mol.GetNumAtoms()
    for idx in range( atoms ):
        mol.GetAtomWithIdx( idx ).SetProp( 'molAtomMapNumber', str( mol.GetAtomWithIdx( idx ).GetIdx() ) )
    return mol


mol = AllChem.SDMolSupplier("../som/2D2_new/16.isoliquiritigenin.mol")
mol_with_atom_index(mol[0])

するとこんな画像が得られる。

image.png

0番目のOHと、13番目のOH間のパスは、以下のように得られる。
python
rdmolops.GetShortestPath(mol[0],0,8)
(0, 1, 2, 3, 4, 5, 6, 7, 8)

また全ての原子間の距離行列はこんな感じで得られる。

rdmolops.GetDistanceMatrix(mol[0])
array([[ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  8.,  9., 10., 11.,
        12., 10.,  9., 10.,  3.,  2.],
       [ 1.,  0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  7.,  8.,  9., 10.,
        11.,  9.,  8.,  9.,  2.,  1.],
       [ 2.,  1.,  0.,  1.,  2.,  3.,  4.,  5.,  6.,  6.,  7.,  8.,  9.,
        10.,  8.,  7.,  8.,  3.,  2.],
       [ 3.,  2.,  1.,  0.,  1.,  2.,  3.,  4.,  5.,  5.,  6.,  7.,  8.,
         9.,  7.,  6.,  7.,  2.,  3.],
       [ 4.,  3.,  2.,  1.,  0.,  1.,  2.,  3.,  4.,  4.,  5.,  6.,  7.,
         8.,  6.,  5.,  6.,  1.,  2.],
       [ 5.,  4.,  3.,  2.,  1.,  0.,  1.,  2.,  3.,  3.,  4.,  5.,  6.,
         7.,  5.,  4.,  5.,  2.,  3.],
       [ 6.,  5.,  4.,  3.,  2.,  1.,  0.,  1.,  2.,  2.,  3.,  4.,  5.,
         6.,  4.,  3.,  4.,  3.,  4.],
       [ 7.,  6.,  5.,  4.,  3.,  2.,  1.,  0.,  1.,  1.,  2.,  3.,  4.,
         5.,  3.,  2.,  3.,  4.,  5.],
       [ 8.,  7.,  6.,  5.,  4.,  3.,  2.,  1.,  0.,  2.,  3.,  4.,  5.,
         6.,  4.,  3.,  4.,  5.,  6.],
       [ 8.,  7.,  6.,  5.,  4.,  3.,  2.,  1.,  2.,  0.,  1.,  2.,  3.,
         4.,  2.,  1.,  2.,  5.,  6.],
       [ 9.,  8.,  7.,  6.,  5.,  4.,  3.,  2.,  3.,  1.,  0.,  1.,  2.,
         3.,  3.,  2.,  3.,  6.,  7.],
       [10.,  9.,  8.,  7.,  6.,  5.,  4.,  3.,  4.,  2.,  1.,  0.,  1.,
         2.,  2.,  3.,  4.,  7.,  8.],
       [11., 10.,  9.,  8.,  7.,  6.,  5.,  4.,  5.,  3.,  2.,  1.,  0.,
         1.,  1.,  2.,  3.,  8.,  9.],
       [12., 11., 10.,  9.,  8.,  7.,  6.,  5.,  6.,  4.,  3.,  2.,  1.,
         0.,  2.,  3.,  4.,  9., 10.],
       [10.,  9.,  8.,  7.,  6.,  5.,  4.,  3.,  4.,  2.,  3.,  2.,  1.,
         2.,  0.,  1.,  2.,  7.,  8.],
       [ 9.,  8.,  7.,  6.,  5.,  4.,  3.,  2.,  3.,  1.,  2.,  3.,  2.,
         3.,  1.,  0.,  1.,  6.,  7.],
       [10.,  9.,  8.,  7.,  6.,  5.,  4.,  3.,  4.,  2.,  3.,  4.,  3.,
         4.,  2.,  1.,  0.,  7.,  8.],
       [ 3.,  2.,  3.,  2.,  1.,  2.,  3.,  4.,  5.,  5.,  6.,  7.,  8.,
         9.,  7.,  6.,  7.,  0.,  1.],
       [ 2.,  1.,  2.,  3.,  2.,  3.,  4.,  5.,  6.,  6.,  7.,  8.,  9.,
        10.,  8.,  7.,  8.,  1.,  0.]])

この行列の最大値を調べることにり、全原子間で最大のパスが原子0と原子13の間の12であることもわかる。

2
1
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
2
1