打开sdf文件下载地址:http://pan.baidu.com/s/1kUWGTJT
linux下生成sdf。
<?php
header("Content-Type:text/html;charset=utf-8");
ini\_set('memory\_limit', '140000M'); // 设置文件上传大小
ini\_set("max\_execution\_time", 0);
require\_once './functions.php';
include './configDB.php';
$starTime = microtime\_float();
$dsn = "mysql:host={$dbHost};dbname={$dbName};charset=utf8";
$dbObj = new \\PDO ( $dsn, $dbUser, $dbPass);
$tbName = "sci\_data";
$mol\_field = 'smiles';
$query = "SELECT id as name ,smiles FROM \`{$tbName}\` where smiles!=''";
$sdfName = "./sdf/indexs117";
$sdf = \[\];
$i = 0;
$j = 0;
$buffer = "";
$resource = $dbObj->query ( $query );
while($data = $resource->fetch ( \\PDO::FETCH\_ASSOC )){
$j++;
$array = \[\];
$string = OBABLE\_PATH." -:\\"{$data\['smiles'\]}\\" --property ";
foreach($data as $k=>$v){
if($k=='smiles')
continue;
$k = str\_replace(\["(",")"\], \["\\\\(","\\\\)"\], $k);
$string .= $k."=\\"".$v."\\"\\\\;";
}
$string .= " -osdf --gen2d \\n";
//echo $string."<br/>";
exec($string,$array);
if(!isset($array\[1\])){
file\_put\_contents($sdfName."StringErr.txt", $string,FILE\_APPEND);
file\_put\_contents($sdfName."err.txt", var\_export($data,1),FILE\_APPEND);
continue;
}
if(!preg\_match("/OpenBabel\*/", $array\[1\])){
file\_put\_contents($sdfName."StringErr.txt", $string,FILE\_APPEND);
file\_put\_contents($sdfName."err.txt", var\_export($data,1),FILE\_APPEND);
continue;
}
$i++;
$buffer .= implode("\\r\\n", $array) . PHP\_EOL;
if(is\_int($i/1000)){
file\_put\_contents($sdfName.".sdf", $buffer,FILE\_APPEND);
$buffer = "";
}
}
if($buffer){
file\_put\_contents($sdfName.".sdf", $buffer,FILE\_APPEND);
}
$endTime = microtime\_float();
echo "using time :".($endTime-$starTime)."<br/>";
echo $i;exit;
exit;
?>
windows下生成sdf
<?php
ini\_set('memory\_limit', '-1'); // 设置文件上传大小
ini\_set("max\_execution\_time", 0);
include "functions.php";
$start = microtime\_float ();
$dsn = 'mysql:host=locahost;dbname=xxxx;charset=utf8';
$dbObj = new \\PDO ( $dsn, "root", "xxxxx" );
$query = 'SELECT id,smiles FROM \`xxx\` ';
$res = $dbObj->query($query);
while(($data = $res->fetch ( \\PDO::FETCH\_ASSOC ))!==false){
$datas\[\] = $data;
}
// p($datas);die();
$sdfName = "t4";
// p($datas);
// /usr/local/bin/obabel -:"\[Na+\].\[O-\]S(=O)(=O)c1ccc(cc1)C(\[\*\])C\[\*\]" --property CAS="25704-18-1"\\;Catalog ID="111"\\;Compound Name="Poly(sodium-p-styrenesulfonate)"\\;M.F.=C8H7NaO3S\\; M.W.=206.194\\;MDL=MFCD00084449\\; Website address="1111"\\;-osdf --gen2d
// /usr/local/bin/obabel -:"O=C1Oc2c(C1)cc(cc2)Br" --property hello=world\\;Catalog ID=123 \\;web size=http://www.baidu.com \\;Compound Name="Poly(sodium-p-styrenesulfonate)" -osdf --gen2d
$sdf = \[ \];
$i = 0;
$buffer = "";
foreach ( $datas as $data ) {
$string = '';
$array = \[\];
$string = OBABLE\_PATH . " -:\\"{$data\['smiles'\]}\\" --property ";
foreach ( $data as $k => $v ) {
if ($k == 'smiles')
continue;
//$k = str\_replace ( \[ "(",")" \], \[ "\\\\(","\\\\)" \], $k );
$string .= $k . "=\\"" . addslashes(html\_entity\_decode($v)) . "\\";";
}
$string .= " -osdf --gen2d \\n";
exec ( $string, $array );
// var\_dump($array);die();
if (! isset ( $array \[1\] )) {
file\_put\_contents ( $sdfName . "StringErr.txt", $string."\\r\\n", FILE\_APPEND );
file\_put\_contents ( $sdfName . "err.txt", var\_export ( $data, 1 )."\\r\\n", FILE\_APPEND );
continue;
}
if (! preg\_match ( "/OpenBabel\*/", $array \[1\] )) {
file\_put\_contents ( $sdfName . "StringErr.txt", $string."\\r\\n", FILE\_APPEND );
file\_put\_contents ( $sdfName . "err.txt", var\_export ( $data, 1 )."\\r\\n", FILE\_APPEND );
continue;
}
$i ++;
$buffer .= implode ( "\\r\\n", $array ) . PHP\_EOL;
// var\_dump($buffer);
if ($i % 100 == 0) {
file\_put\_contents ( $sdfName . ".sdf", $buffer, FILE\_APPEND );
$buffer = "";
//break;
}
}
// p($buffer);
if ($buffer) {
file\_put\_contents ( $sdfName . ".sdf", $buffer, FILE\_APPEND );
}
$end = microtime\_float ();
echo "using time :" . ($end - $start) . "<br/>";
echo $i;
exit ();
本文为wjw原创文章,转载无需和我联系,但请注明来自wjw博客http://wjiawen.cn
最新评论