最近更新时间: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;
数据类型说明
插件支持的基本数据类型有 mol
,qmol
,bfp
,sfp
和 reaction
。各类型的含义如下:
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
类型对象时的含义及使用如下表所示:
操作符 | 说明 | 使用示例 |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bfp
类型bfp
类型支持相似度查询操作符(%
、<%>
、#
、<#>
)和比较操作符(>
、>=
、<
、<=
、<>
、=
)。各操作符在操作 bfp
类型对象时的含义及使用如下表所示:
操作符 | 说明 | 使用示例 |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);