You need to enable JavaScript to run this app.
导航

化学分子计算检索(RDKit)

最近更新时间2024.04.28 13:27:58

首次发布时间2024.04.28 11:36:22

RDKit 是一款化学信息学开源工具包,基于机器学习方法生成化合物指纹(fingerprint),用于化合物子结构查询、化合物结构相似性计算。

使用限制

仅支持 PostgreSQL 13 版本实例使用 RDKit 插件,插件的版本需为 3.8。

使用插件

创建与删除插件

  • 创建插件
CREATE EXTENSION rdkit;
  • 删除插件
DROP EXTENSION rdkit;

数据类型

  • 数据类型说明

    插件支持的基本数据类型有 molqmolbfpsfpreaction。各类型的含义如下:

    • mol 是一种常用的化学分子格式,通常用于保存单个分子。
    • qmol 是 RDKit 提供的一种包含查询特征的化学分子数据类型,可由 SMARTS等 格式数据直接转化为 qmol 类型数据,例如 ‘c1cccc[c,n]1’::qmol
    • bfp 是 RDKit 提供的一种位向量形式的化学分子指纹类型。
    • sfp 是 RDKit 提供的一种稀疏向量形式的化学分子指纹类型。
    • reaction 是 RDKit 提供的化学反应模版类型。
  • 数据类型转换

    • SMILES 格式分子转化成 mol 类型并插入表格

      insert into mols values
      (1, 'C1=CC=C\\2C(=C1)C=CC(=O)/C2=N\\NC3=NC=CS3'::mol),
      (2, 'CC1=C(N=CC=C1)NC2=NC(=CS2)C3=CC=CC=N3'::mol),
      (3, 'CC(=NNC1=C(C=C(C=N1)Cl)Cl)C2=CC=CC=N2'::mol),
      (4, 'CC(=NNC(=S)NCC=C)C1=CC=CC=N1'::mol),
      (5, 'CC1=CC=C(C=C1)C(=O)SC2=CC=CC=CC2=O'::mol);
      
    • SMARTS 格式分子转化成 qmol 类型

      select 'c1[o,s]ncn1'::qmol;
      
    • 使用指纹计算函数将 mol 类型数据转换成 sfp 类型数据,并插入表格

      select id, torsion_fp(m) as tfp, morgan_fp(m) as mfp, featmorgan_fp(m) as ffp into sfps from mols;
      
    • 使用指纹计算函数将 mol 类型数据转换成 bfp 类型数据,并插入表格

      select id, torsionbv_fp(m) as tfp, morganbv_fp(m) as mfp, featmorganbv_fp(m) as ffp into bfps from mols;
      
    • SMARTS 格式的化学反应模板转化成 reaction 对象(化学反应引擎对象)

      SELECT reaction_from_smarts('c1ccc[n,c]c1>>c1nccnc1');
      

操作符

本文以 mol 类型和 bfp 类型为例对操作符的含义和使用进行说明,各操作符在其他数据类型下的含义和使用与 mol 类型和 bfp 类型基本一致,本文不再一一列举。如需了解更详细信息,请参见 RDKit 使用指南

mol 类型

mol 类型支持子结构查询操作符(<@@>@=)和比较操作符(>>=<<=<>=)。各操作符在操作 mol 类型对象时的含义及使用如下表所示:

操作符说明使用示例

<@

mol1 <@ mol2
mol1 是 mol2 的子结构则返回 true,否则返回 false。

-- 查询mols表中包含'c1cccnc1'结构的分子
select * from mols where 'c1cccnc1'::mol <@ m;
-- 查询mols表中是'c1cccnc1'子结构的分子
select * from mols where m <@ 'c1cccnc1'::mol;

@>

mol1 @> mol2
mol2 是 mol1 的子结构则返回 true,否则返回 false。

-- 查询mols表中是'c1cccnc1'子结构的分子
select * from mols where 'c1cccnc1'::mol @> m;
-- 查询mols表中包含'c1cccnc1'结构的分子
select * from mols where m @> 'c1cccnc1'::mol;

<@

qmol <@ mol
qmol 是 mol 的子结构则返回 true,否则返回 false。

-- 查询mols表中包含'c1cccnc1'结构的分子
select * from mols where 'c1cccnc1'::qmol <@ m;

@>

mol @> qmol
qmol 是 mol 的子结构则返回 true,否则返回 false。

-- 查询mols表中包含'c1cccnc1'结构的分子
select * from mols where m @> 'c1cccnc1'::qmol;

@=

mol1 @= mol2:mol1 和 mol2的结构相同则返回 true,否则返回 false。

-- 查询mols表中结构同'C=CCNC(=S)NN=C(C)c1ccccn1'的分子
select * from mols where m @= 'C=CCNC(=S)NN=C(C)c1ccccn1'::mol;

>

mol1 > mol2:mol1大于 mol2 则返回 true,否则返回 false。

-- 查询mols表中大于'CC(=NNc1ncc(Cl)cc1Cl)c1ccccn1'的分子
select * from mols where m > 'CC(=NNc1ncc(Cl)cc1Cl)c1ccccn1'::mol;

>=

mol1 >= mol2:mol1 大于或等于 mol2 则返回 true,否则返回 false。

-- 查询mols表中大于等于'CC(=NNc1ncc(Cl)cc1Cl)c1ccccn1'的分子
select * from mols where m >= 'CC(=NNc1ncc(Cl)cc1Cl)c1ccccn1'::mol;

<

mol1 < mol2:mol1小于 mol2 则返回 true,否则返回 false。

-- 查询mols表中小于'CC(=NNc1ncc(Cl)cc1Cl)c1ccccn1'的分子
select * from mols where m < 'CC(=NNc1ncc(Cl)cc1Cl)c1ccccn1'::mol;

<=

mol1 <= mol2:mol1 小于或等于 mol2 则返回 true,否则返回 false。

-- 查询mols表中小于等于'CC(=NNc1ncc(Cl)cc1Cl)c1ccccn1'的分子
select * from mols where m <= 'CC(=NNc1ncc(Cl)cc1Cl)c1ccccn1'::mol;

<>

mol1 <> mol2:mol1 不等于 mol2 则返回 true,否则返回 false。

-- 查询mols表中不等于'CC(=NNc1ncc(Cl)cc1Cl)c1ccccn1'的分子
select * from mols where m <> 'CC(=NNc1ncc(Cl)cc1Cl)c1ccccn1'::mol;

=

mol1 = mol2:mol1 等于 mol2 则返回 true,否则返回 false。

-- 查询mols表中等于'CC(=NNc1ncc(Cl)cc1Cl)c1ccccn1'的分子
select * from mols where m = 'CC(=NNc1ncc(Cl)cc1Cl)c1ccccn1'::mol;

bfp 类型

bfp 类型支持相似度查询操作符(%<%>#<#>)和比较操作符(>>=<<=<>=)。各操作符在操作 bfp 类型对象时的含义及使用如下表所示:

操作符说明使用示例

%

bfp1 % bfp2
bfp1 和 bfp2 的 Tanimoto 相似度超过阈值则返回 true,否则返回 false。

-- 查询bfps表中分子与'c1cccnc1'的Tanimoto相似度
select id, tanimoto_sml(morganbv_fp('c1cccnc1'::mol) , mfp) from bfps;
-- 查询bfps表中分子与'c1cccnc1'的Tanimoto相似度是否超过阈值
select id, morganbv_fp('c1cccnc1'::mol) % mfp from bfps;

<%>

bfp1 <%> bfp2
返回 bfp1 和 bfp2 的 Tanimoto 相似度距离,通常用于排序。

-- 查询bfps表中分子与'c1cccnc1'的Tanimoto相似度距离
select id, morganbv_fp('c1cccnc1'::mol) <%> mfp from bfps order by morganbv_fp('c1cccnc1'::mol) <%> mfp;

#

bfp1 # bfp2
bfp1 和 bfp2 的 Dice 相似度超过阈值则返回 true,否则返回 false。

-- 查询bfps表中分子与'c1cccnc1'的Dice相似度
select id, dice_sml(morganbv_fp('c1cccnc1'::mol), mfp) from bfps;
-- 查询bfps表中分子与'c1cccnc1'的Dice相似度是否超过阈值
select id, morganbv_fp('c1cccnc1'::mol) # mfp from bfps;

<#>

bfp1 <#> bfp2
返回 bfp1 和 bfp2 的 Dice 相似度距离,通常用于排序。

-- 查询bfps表中分子与'c1cccnc1'的Dice相似度距离
select id, morganbv_fp('c1cccnc1'::mol) <#> mfp from bfps order by morganbv_fp('c1cccnc1'::mol) <#> mfp;

>

bfp1 > bfp2:bfp1 大于 bfp2 则返回 true,否则返回 false。

-- 查询bfps表中大于'CC1=CC=C(C=C1)C(=O)SC2=CC=CC=CC2=O'的分子
select id, mfp from bfps where mfp > morganbv_fp('CC1=CC=C(C=C1)C(=O)SC2=CC=CC=CC2=O'::mol);

>=

bfp1 >= bfp2:bfp1 大于或等于 bfp2 则返回 true,否则返回 false。

-- 查询bfps表中大于等于'CC1=CC=C(C=C1)C(=O)SC2=CC=CC=CC2=O'的分子
select id, mfp from bfps where mfp >= morganbv_fp('CC1=CC=C(C=C1)C(=O)SC2=CC=CC=CC2=O'::mol);

<

bfp1 < bfp2:bfp1 小于 bfp2 则返回 true,否则返回 false。

-- 查询mols表中小于'CC1=CC=C(C=C1)C(=O)SC2=CC=CC=CC2=O'的分子
select id, mfp from bfps where mfp < morganbv_fp('CC1=CC=C(C=C1)C(=O)SC2=CC=CC=CC2=O'::mol);

<=

bfp1 <= bfp2:bfp1 小于或等于 bfp2 则返回 true,否则返回 false。

-- 查询mols表中小于等于'CC1=CC=C(C=C1)C(=O)SC2=CC=CC=CC2=O'的分子
select id, mfp from bfps where mfp <= morganbv_fp('CC1=CC=C(C=C1)C(=O)SC2=CC=CC=CC2=O'::mol);

<>

bfp1 <> bfp2:bfp1 不等于 bfp2 则返回 true,否则返回 false。

-- 查询mols表中不等于'CC1=CC=C(C=C1)C(=O)SC2=CC=CC=CC2=O'的分子
select id, mfp from bfps where mfp <> morganbv_fp('CC1=CC=C(C=C1)C(=O)SC2=CC=CC=CC2=O'::mol);

=

bfp1 = bfp2:bfp1 等于 bfp2 则返回 true,否则返回 false。

-- 查询mols表中等于'CC1=CC=C(C=C1)C(=O)SC2=CC=CC=CC2=O'的分子
select id, mfp from bfps where mfp =  morganbv_fp('CC1=CC=C(C=C1)C(=O)SC2=CC=CC=CC2=O'::mol);

函数

RDKit 支持的函数较多,本节只做简单的调用展示。更多详细信息,请参见 RDKit 使用指南

  • tanimoto_sml(bfp, bfp):计算 tanimoto 相似度。

    postgres=# select tanimoto_sml(morganbv_fp('c1cccnc1'::mol), morganbv_fp('c1cccnc1'::mol));
     tanimoto_sml
    --------------
                1
    (1 row)
    
    postgres=# select tanimoto_sml(morganbv_fp('C1C(OC2=CC(=CC(=C2C1=O)))'::mol), morganbv_fp('c1cccnc1'::mol));
        tanimoto_sml
    ---------------------
     0.06666666666666667
    (1 row)
    
  • dice_sml(bfp, bfp):计算 dice 相似度。

    postgres=# select dice_sml(morganbv_fp('c1cccnc1'::mol), morganbv_fp('c1cccnc1'::mol));
     dice_sml
    ----------
            1
    (1 row)
    
    postgres=# select dice_sml(morganbv_fp('C1C(OC2=CC(=CC(=C2C1=O)))'::mol), morganbv_fp('c1cccnc1'::mol));
     dice_sml
    ----------
        0.125
    (1 row)
    

索引

RDKit 支持 btree 索引、gist 索引和 gin 索引。下面以 bfp 类型为例描述各类索引的使用。

  • 创建 btree 索引

    -- 创建btree索引
    drop index if exists bfpidx;
    create index bfpidx ON bfps(tfp);
    
  • 创建 gist 索引

    -- 创建gist索引
    drop index if exists bfpidx;
    create index bfpidx on bfps using gist(tfp);
    
  • 创建 gin 索引

    -- 创建gin索引
    drop index if exists bfpidx;
    create index bfpidx on bfps using gin(tfp);
    

参考文档

RDKit 使用指南