構造式検索エンジンがあるので、実際に検索できるwebアプリを作ってみた
クエリを書くのには JSME Molecule Editor http://peter-ertl.com/jsme/
を利用した。
*javascriptベースの化合物描画ツール。BSD licenseライセンス
*器は、dhtmlxにて作成
#iframe(https://web.chaperone.jp/c/index.html,style=width:100%;height:500px;)
全体はdhtmlxのdhtmlxLayoutを使ってフレーム分けさせて、左側には検索構造式を描いて、右側にはその結果をパネルで表示させた。
*dhtmlxのソースは、https://web.chaperone.jp/c/index.html
から参照してください
*dhtmlxのフリー版でenableSmartRendering機能を使うにはXMLでのデータ受け渡しが必要。
構造式のパネル表示部分†
dhtmlxDataViewをライブラリに使ってます。
myDataView = myLayout.cells("b").attachDataView({
type:{
template:"#mol#",
height:80,
width:80
}
});
myDataView.load("dv.php","xml");
として、こんな感じのphpスクリプトにした
*以前pythonで描いたがphpで作り直した
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| <?php
$posStart = 0;
$count = 500;
if ( isset($_GET['posStart']) ) $posStart = $_GET['posStart'];
if ( isset($_GET['count']) ) $count = $_GET['count'];
if ( isset($_POST['mol']) ) $mol = $_POST['mol'];
$dsn = "pgsql:dbname=chemdb host=localhost port=5432";
$user="caster";
$password="caster";
$dbh = new PDO($dsn, $user, $password);
$sql = "SELECT pubchem_compound_cid FROM pubchem WHERE 1=1";
if ( $posStart == 0 ){
$sqlCount = "SELECT count(*) as cnt FROM (".$sql.") as tbl";
$sth = $dbh->query($sqlCount);
$res = $sth->fetch(PDO::FETCH_NUM);
$output="<data total_count='".$res[0]."' pos='".$posStart."'>";
$sth = null;
$res = null;
}else{
$output="<data pos='".$posStart."'>";
}
if ( $mol ){
$_SESSION['mol'] = $mol;
$sql .= " and rdkit_smiles @> '".$mol."' LIMIT :limit OFFSET :offset";
}else{
$sql .= " LIMIT :limit OFFSET :offset";
}
$sth = $dbh->prepare($sql);
$sth->execute(array(':limit'=> $count, ':offset'=> $posStart) );
while($res = $sth->fetch(PDO::FETCH_NUM)){
$output .= "<item id='".$res[0]."'><mol><![CDATA[<IMG SRC='http://web.chaperone.jp/depict?".$res[0]."' />]]></mol></item>";
}
$output .= "</data>";
$dbh = null;
header("Content-Type: text/xml");
print $output;
?>
|
部分構造検索†
JSMEで描いた構造式はsmilesにもmol形式でも取り出せる。ここではmol形式でクエリーを受け取ってRDKitに流してみる。
まずはボタンの制御のためにjqueryライブラリを設置して、検索ボタンを押下したらJSMEと連携してMOLデータを取得する
$(function() {
$('#run').click(function(e){
if ( jsmeApplet.smiles() != "" ){
$.ajax({
type: "POST",
url: "dv.php",
data: {"mol": jsmeApplet.smiles()}
}).done(function(data){
myDataView.clearAll();
myDataView.parse(data,"xml");
});
}
});
});
こんな感じで。詳しくは現物http://web.chaperone.jp/c/index.html
のソースをご覧下さい。
smilesではなくMDL MOL形式から検索するには†
JSMEには描いた構造式をsmilesで出力する機能の他に、MDL MOL形式での出力も可能である。
このMDL MOL形式のままで検索するには、RDKitのmol_from_ctab関数を使用する。
具体的には
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| -
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
| SELECT pubchem_compound_cid FROM pubchem WHERE 1=1 and rdkit_smiles @> mol_from_ctab('C1=CC=CC=C1
JME 2016-07-31 Wed Oct 25 00:13:04 GMT+900 2017
6 6 0 0 0 0 0 0 0 0999 V2000
2.4249 0.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.4249 2.1000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.2124 2.8000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 2.1000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 0.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.2124 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0 0 0 0
2 3 2 0 0 0 0
3 4 1 0 0 0 0
4 5 2 0 0 0 0
5 6 1 0 0 0 0
6 1 2 0 0 0 0
M END
'::cstring);
|
な感じで直接MDL MOLを入れ込んで、末尾に「::cstring」を加える。これで行けます。