RDKit / PostgresSQL

RDKitはPostgresSQLと連携させて構造情報を色々と扱うことができます。
ChemBL DBはPostgresSQL用のファイルが利用できますし、
ローカルにDBを作って作業すると、自分の幅が少し広がりそうです。
SQLなんかの勉強にもなる?
取りあえずやってみました。
まずpostgresql9.2.4をビルドしました。
マニュアルに従って、、、、

./configure
make
su
make install
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
pg_ctl start

でOK
続いてRDKitの設定

cd $RDBASE/Code/PgSQL/rdkit
make
make install
make installcheck

でエラーが出なかったら成功。
途中で何個かwarningでましたが、一応自分の環境では8個のテスト全部パスしました。
ちなみに
RDKit2013_03_2
PostgreSQL 9.2.4
BOOST 1.53.0でビルドしました。
で実際にデーターベースを作ってみます。
先ほどのフォルダの直下にdataという1000件のsmilesが入ったファイルがあったのでこれを使ってみます。

cd ./data
createdb testdb
psql testdb

これでテスト用のDBを作りました。
続いてファイルを読み込みます。

psql testdb
testdb=# create table moltable (id integer primary key, smiles text);
testdb=# copy moltable from filedir/data;

copy xxx from yyy;でファイルを取り込みます。デフォルトの区切りはタブなのでそのまま。
続いてrdkitの機能を入れる(という表現がいいのか不明ですが)

testdb=# create extension if not exists rdkit;
testdb=# create shcema rdk;
testdb=# select * into mols from (select id,mol_from_smiles(smiles::cstring) m from moltable) tmp where m is not null;
testdb=# create index molidx on mols using gist(m);

でmolsテーブルができました。

testdb=# select * from mols limit 10;
   id    |                                     m                                      
---------+----------------------------------------------------------------------------
 6308684 | O=C1C=Cc2ccccc2/C1=N/Nc1nccs1
 6061070 | O=C1C=CC(=Nc2cc(Cl)c3c(c2[N+](=O)[O-])NON3)C=C1
 5485201 | Cl.O=C1CC[C@@]2(O)[C@H]3Cc4ccc(O)c5c4[C@@]2(CCN3CC2CC2)[C@H]1O5
 5307588 | O=C(C1CCN(S(=O)(=O)c2cccc3cccnc32)CC1)N1CCn2c3ccccc3nc21
 5243548 | CC1(C)CC(=O)C(=CNc2cccnc2NC=C2C(=O)CC(C)(C)CC2=O)C(=O)C1
 4209216 | O=C(NN=Cc1cccc2cccnc12)c1ccccc1O
 3746037 | C[N+]1=C2C=CC=CC=C2SC12C([N+](=O)[O-])=CC(=[N+]([O-])[O-])C=C2[N+](=O)[O-]
 3240530 | O=C(C1CCN(S(=O)(=O)c2cccc3nsnc32)CC1)N1CCn2c3ccccc3nc21
 3128208 | O=[N+]([O-])c1c2nonc2c(Cl)cc1Nc1cccc(O)c1
 2772102 | O=[N+]([O-])c1c2nonc2c(Cl)cc1Nc1ccccn1
(10 rows)

Time: 10.815 ms

次にプロパティの計算をしてみます。

testdb=# select id, mol_amw(m) as amw , mol_logp(m) as logp into props from mols;
SELECT 1000
Time: 1699.063 ms
testdb=# \dt
          List of relations
 Schema |   Name   | Type  |  Owner   
--------+----------+-------+----------
 public | data     | table | postgres
 public | fps      | table | postgres
 public | mols     | table | postgres
 public | moltable | table | postgres
 public | props    | table | postgres
(5 rows)

testdb=# select * from props limit 100;
    id    |   amw   |  logp   
----------+---------+---------
  6308684 | 255.302 |  2.5552
  6061070 | 306.665 |  2.6998
  5485201 | 377.868 |  1.9472
  5307588 | 461.547 |   3.032
  5243548 | 409.486 |  3.5896
  4209216 |  291.31 |  2.7043
  3746037 | 362.323 |  1.3066
  3240530 | 468.564 |  2.4885
  3128208 | 306.665 |  3.2336
  2772102 | 291.654 |   2.923
  2104451 | 339.298 |  4.0692
  2082098 | 304.396 | 3.40552
   972880 | 268.345 | 3.65212
   852940 | 257.318 |  2.1271
  5224323 | 345.402 |  3.6678
  3712088 | 402.473 |  4.8402
  3623511 | 329.743 |  3.6509
  2193022 | 363.156 |   4.669
   571783 | 273.723 |   2.889
   161167 |  284.34 |  3.0356
 16219722 | 529.611 |  2.5168
 16129550 | 726.194 |   3.201
  5719581 | 306.665 |  2.6998
Time: 1.419 ms

1000件の分子量とlogpの計算が2秒弱なので早いですね。(と思うんですがどうでしょう。)

Advertisement

Published by iwatobipen

I'm medicinal chemist in mid size of pharmaceutical company. I love chemoinfo, cording, organic synthesis, my family.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: