コード例 #1
0
ファイル: incss.php プロジェクト: Procxl/libraries
 $firstpart = substr($moldfp, 0, -1);
 $lastdigit = intval(substr($moldfp, -1, 1));
 if (1 & $lastdigit) {
     $lastdigit--;
     $lastdigit = strval($lastdigit);
     $moldfp = $firstpart . $lastdigit;
 }
 // create the hash-based fingerprints
 if ($use_cmmmsrv == 'y') {
     $molhfp = filterthroughcmmm($safemol, "#### checkmol:H");
 } else {
     if ($ostype == 1) {
         $molhfp = filterthroughcmd($safemol, "{$CHECKMOL} -H - ");
     }
     if ($ostype == 2) {
         $molhfp = filterthroughcmd2($safemol, "{$CHECKMOL} -H - ");
     }
 }
 $hfparr = explode(";", $molhfp);
 $molhfp = $hfparr[0];
 $qstr = "";
 $qstr .= mk_fpqstr("dfp", $moldfp);
 if (strlen($qstr) > 0) {
     $qstr .= " AND";
 }
 $qstr .= mk_fpqstr("hfp", $molhfp);
 if ($use_cmmmsrv == "y") {
     $bs = 50;
     // block size (number of structures per query SDF)
 } else {
     $bs = 10;
コード例 #2
0
ファイル: editdata.php プロジェクト: Procxl/libraries
function get_inchikey($molfile)
{
    global $ostype;
    global $INCHI;
    global $INCHI_OPT;
    $i = "";
    if ($ostype == 1) {
        $irec = filterthroughcmd($molfile, "{$INCHI} {$INCHI_OPT} ");
    }
    if ($ostype == 2) {
        $irec = filterthroughcmd2($molfile, "{$INCHI} {$INCHI_OPT} ");
    }
    $iarr = explode("InChIKey=", $irec);
    $i = $iarr[1];
    $iarr = explode("\n", $i);
    $i = rtrim($iarr[0]);
    //echo "<pre>$irec\n</pre>\n";
    return $i;
}
コード例 #3
0
ファイル: functions.php プロジェクト: Procxl/libraries
function search_mol_exact($db_id, $mol)
{
    global $prefix;
    global $molstrucsuffix;
    global $molstatsuffix;
    global $molcfpsuffix;
    global $CHECKMOL;
    global $MATCHMOL;
    global $use_cmmmsrv;
    global $cmmmsrv_addr;
    global $cmmmsrv_port;
    global $ostype;
    global $socket;
    $mmopt = "xsgGaid";
    // x = exact, s = strict, g = E/Z, G = R/S, a = charges, i = isotopes, d = radicals
    $dbprefix = $prefix . "db" . $db_id . "_";
    $molstructable = $dbprefix . $molstrucsuffix;
    $molstattable = $dbprefix . $molstatsuffix;
    $molcfptable = $dbprefix . $molcfpsuffix;
    $mmcmd = "{$MATCHMOL} -{$mmopt} -";
    //$use_cmmmsrv = "n";  // for testing only
    if ($use_cmmmsrv == 'y') {
        /* create a TCP/IP socket */
        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        if ($socket < 0) {
            //echo "socket_create() failed.\nreason: " . socket_strerror ($socket) . "\n";
            echo "<!-- could not connect to cmmmsrv - reverting to checkmol/matchmol -->\n";
            $use_cmmmsrv = "n";
        }
        $result = socket_connect($socket, $cmmmsrv_addr, $cmmmsrv_port);
        if ($result === FALSE) {
            //echo "socket_connect() failed.<p />\n";
            echo "<!-- could not connect to cmmmsrv - reverting to checkmol/matchmol -->\n";
            $use_cmmmsrv = "n";
        }
    }
    if ($use_cmmmsrv == 'y') {
        $a = socket_read($socket, 250, PHP_NORMAL_READ);
        //echo "the socket says: $a<br>\n";
        $pos = strpos($a, "READY");
        if ($pos === false) {
            echo "<!-- could not connect to cmmmsrv - reverting to checkmol/matchmol -->\n";
            $use_cmmmsrv = "n";
        }
    }
    $res = array();
    $ndup = 0;
    $safemol = str_replace(";", " ", $mol);
    if ($use_cmmmsrv == 'y') {
        $chkresult = filterthroughcmmm("{$safemol}", "#### checkmol:axH");
        // "a" for charges
    } else {
        if ($ostype == 1) {
            $chkresult = filterthroughcmd("{$safemol}", "{$CHECKMOL} -axH - ");
        }
        if ($ostype == 2) {
            $chkresult = filterthroughcmd2("{$safemol}", "{$CHECKMOL} -axH - ");
        }
    }
    if (strlen($chkresult) < 2) {
        echo "no response from checkmol (maybe a server configuration problem?)\n</body></html>\n";
        exit;
    }
    // first part of output: molstat, second part: hashed fingerprints
    $myres = explode("\n", $chkresult);
    $chkresult1 = $myres[0];
    $chkresult2 = $myres[1];
    // strip trailing "newline"
    $chkresult1 = str_replace("\n", "", $chkresult1);
    $len = strlen($chkresult1);
    // strip trailing semicolon
    if (substr($chkresult1, $len - 1, 1) == ";") {
        $chkresult1 = substr($chkresult1, 0, $len - 1);
    }
    $chkresult2 = str_replace("\n", "", $chkresult2);
    if (strpos($chkresult2, ";") !== false) {
        $chkresult2 = substr($chkresult2, 0, strpos($chkresult2, ";"));
    }
    $hfp = explode(",", $chkresult2);
    // now assemble the pre-selection query string
    $ms_qstr = str_replace(";", " AND ", $chkresult1);
    $ms_qstr = str_replace("n_", "{$molstattable}.n_", $ms_qstr);
    //$op = ">=";
    $op = "=";
    $ms_qstr = str_replace(":", $op, $ms_qstr);
    $hfp_qstr = "";
    for ($h = 0; $h < count($hfp); $h++) {
        $number = $h + 1;
        while (strlen($number) < 2) {
            $number = "0" . $number;
        }
        if (strlen($hfp_qstr) > 0) {
            $hfp_qstr .= "AND ";
        }
        $hfp_qstr .= "{$molcfptable}.hfp{$number} = {$hfp[$h]} ";
    }
    $qstr = "SELECT {$molstructable}.mol_id,{$molstructable}.struc FROM {$molstructable},{$molstattable},{$molcfptable}";
    $qstr .= " WHERE " . $ms_qstr . " AND " . $hfp_qstr;
    $qstr .= " AND ({$molstructable}.mol_id = {$molstattable}.mol_id)";
    $qstr .= " AND ({$molstructable}.mol_id = {$molcfptable}.mol_id)";
    $bs = 50;
    if ($use_cmmmsrv == "n") {
        $bs = 8;
    }
    $sqlbs = 10 * $bs;
    $nqueries = 0;
    do {
        $offset = $nqueries * $sqlbs;
        $offsetstr = " LIMIT {$offset}, {$sqlbs}";
        $qstrlim = $qstr . $offsetstr;
        $result = mysql_query($qstrlim) or die("Query failed! (search_mol_exact #1)");
        $n_cand = mysql_num_rows($result);
        // number of candidate librariess
        if ($n_cand > 0) {
            $qstruct = $safemol . "\n\$\$\$\$\n";
            $n = 0;
            while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $mol_id = $line["mol_id"];
                $haystack = $line["struc"];
                $qstruct = $qstruct . $haystack . "\n\$\$\$\$ #{$mol_id}\n";
                $n++;
                if ($n == $bs || $n == $n_cand) {
                    if ($use_cmmmsrv == "n") {
                        $qstruct = str_replace("\$", "\\\$", $qstruct);
                    }
                    if ($use_cmmmsrv == "y") {
                        $matchresult = filterthroughcmmm("{$qstruct}", "#### matchmol:{$mmopt}");
                    } else {
                        if ($ostype == 1) {
                            $matchresult = filterthroughcmd("{$qstruct} ", "{$mmcmd}");
                        }
                        if ($ostype == 2) {
                            $matchresult = filterthroughcmd2("{$qstruct} ", "{$mmcmd}");
                        }
                    }
                    $br = explode("\n", $matchresult);
                    foreach ($br as $reply) {
                        if (strpos($reply, ":T") > 0) {
                            $reply = chop($reply);
                            $hr = explode("#", $reply);
                            $h_id = $hr[1];
                            if (strlen($h_id) > 0) {
                                $res[$ndup] = $h_id;
                                $ndup++;
                            }
                        }
                    }
                    // foreach...
                    $qstruct = $safemol . "\n\$\$\$\$\n";
                    $n = 0;
                }
            }
            // while ...
        }
        // if n_cand > 0...
        $nqueries++;
    } while ($n_cand == $sqlbs && $nqueries < 100000);
    if ($use_cmmmsrv == "y") {
        socket_write($socket, '#### bye');
        socket_close($socket);
    }
    return $res;
}
コード例 #4
0
ファイル: rxnfunct.php プロジェクト: Procxl/libraries
function matchmolrxn($qmol, $crxn, $options)
{
    global $use_cmmmsrv;
    global $ostype;
    global $mmcmd;
    global $debug;
    $result = TRUE;
    if (strlen($qmol) < 10 || strlen($crxn) < 20) {
        $result = FALSE;
    }
    if ($result == TRUE) {
        $result = FALSE;
        if ($use_cmmmsrv == "y") {
            $separator = "\$\$\$\$";
            $lf = "\n";
        } else {
            $separator = "\\\$\\\$\\\$\\\$";
            if ($ostype == 1) {
                $lf = "\n";
            }
            // Linux
            if ($ostype == 2) {
                $lf = "\r\n";
            }
            // Windows
        }
        $allmol = array();
        $allmol = explode("\$MOL\r\n", $crxn);
        $header = $allmol[0];
        $mol = array();
        $mol = array_slice($allmol, 1);
        $nmol = count($mol);
        if ($debug > 4) {
            debug_output("nmol: {$nmol}\n");
        }
        //============ now match
        if ($nmol > 0) {
            // assemble the SDF files to be passed to matchmol
            $qmol = rtrim($qmol);
            $sdf = $qmol . $lf . $separator . $lf;
            for ($ic = 0; $ic < $nmol; $ic++) {
                $cmol = rtrim($mol[$ic]);
                $sdf .= $cmol . $lf . $separator . $lf;
            }
            // end   for ($ic ...
            if ($debug > 4) {
                debug_output("{$sdf}\n");
            }
            if ($use_cmmmsrv == "y") {
                $matchresult = filterthroughcmmm("{$sdf}", "#### matchmol:{$options}");
            } else {
                if ($ostype == 1) {
                    $matchresult = filterthroughcmd("{$sdf} ", "{$mmcmd}");
                }
                if ($ostype == 2) {
                    $sdf = str_replace("\r", "", $sdf);
                    // for Windows
                    $sdf = str_replace("\n", "\r\n", $sdf);
                    // for Windows
                    $matchresult = filterthroughcmd2("{$sdf} ", "{$mmcmd}");
                }
            }
            //echo "<pre>match result:\n$matchresult\n</pre>";
            $br = explode("\n", $matchresult);
            $nr = count($br);
            for ($ir = 0; $ir < $nr; $ir++) {
                if (strpos($br[$ir], ":T") !== FALSE) {
                    $result = TRUE;
                }
            }
        }
        // end    if ($nmol > 0)
    }
    // end if ($result == TRUE) from initial check
    return $result;
}
コード例 #5
0
ファイル: incsim.php プロジェクト: Procxl/libraries
         $fpnum = "0" . $fpnum;
     }
     $fpsdf = $fpdef[$i];
     $fpsdf = str_replace("\$", "\\\$", $fpsdf);
     $fpchunk = $safemol . "\n\\\$\\\$\\\$\\\$\n" . $fpsdf;
     if ($use_cmmmsrv == "y") {
         // remove extra "\\" for cmmmsrv
         $fpchunk = str_replace("\\\$", "\$", $fpchunk);
         $bfp[$i] = filterthroughcmmm("{$fpchunk}", "#### matchmol:F");
     } else {
         $mmcmd = "{$MATCHMOL} {$fpoptions} -";
         if ($ostype == 1) {
             $bfp[$i] = filterthroughcmd("{$fpchunk} ", "{$mmcmd}");
         }
         if ($ostype == 2) {
             $bfp[$i] = filterthroughcmd2("{$fpchunk} ", "{$mmcmd}");
         }
     }
     $bfp[$i] = rtrim($bfp[$i]);
     if ($bfp[$i] != "0") {
         $in_dict = 1;
     }
 }
 // for ...
 // if we have something in the dictionary, prepare the SQL statements
 $a_sum_dfp = 0;
 for ($i = 0; $i < $fp_count; $i++) {
     $fpnum = $i + 1;
     while (strlen($fpnum) < 2) {
         $fpnum = "0" . $fpnum;
     }
コード例 #6
0
ファイル: dbfunct.php プロジェクト: Procxl/libraries
function create_moltables($db_id)
{
    global $fpdeftable;
    global $prefix;
    global $molstrucsuffix;
    global $moldatasuffix;
    global $molfgbsuffix;
    global $molstatsuffix;
    global $molcfpsuffix;
    global $pic2dsuffix;
    global $use_cmmmsrv;
    global $cmmmsrv_addr;
    global $cmmmsrv_port;
    global $CHECKMOL;
    global $socket;
    global $mysql_charset;
    global $mysql_collation;
    global $ostype;
    global $enable_inchi;
    $dbprefix = $prefix . "db" . $db_id . "_";
    //molstruc
    $createcmd = "CREATE TABLE IF NOT EXISTS {$dbprefix}{$molstrucsuffix} (";
    $createcmd .= "mol_id INT(11) NOT NULL DEFAULT '0', struc MEDIUMBLOB NOT NULL, PRIMARY KEY mol_id (mol_id)";
    $createcmd .= ") ENGINE = MYISAM CHARACTER SET {$mysql_charset} COLLATE {$mysql_collation} COMMENT='Molecular structures'";
    $result = mysql_query($createcmd) or die("Create failed! (create_moltables 1)");
    #mysql_free_result($result);
    //moldatatable
    $inchistr = "";
    if ($enable_inchi == "y") {
        $inchistr = "auto_mol_inchikey VARCHAR(250) NOT NULL COMMENT '>>>>InChIKey<1<inchikey<1<<',";
    }
    $createcmd = "CREATE TABLE IF NOT EXISTS {$dbprefix}{$moldatasuffix} (";
    $createcmd .= "mol_id INT(11) NOT NULL DEFAULT '0', mol_name TEXT NOT NULL, auto_mol_formula VARCHAR(250) NOT NULL COMMENT '>>>>Formula<3<auto_mol_formula<0<<', \n  auto_mol_fw DOUBLE NOT NULL DEFAULT '0.0' COMMENT '>>>>MW<1<auto_mol_fw<0<<', {$inchistr} PRIMARY KEY mol_id (mol_id)";
    $createcmd .= ") ENGINE = MYISAM CHARACTER SET {$mysql_charset} COLLATE {$mysql_collation} COMMENT='Molecular data'";
    $result = mysql_query($createcmd) or die("Create failed! (4b)");
    #mysql_free_result($result);
    //molstattable
    if ($use_cmmmsrv == 'y') {
        $msdef = filterthroughcmmm("\$\$\$\$", "#### checkmol:l");
    } else {
        if ($ostype == 1) {
            $msdef = filterthroughcmd("", "{$CHECKMOL} -l");
        }
        if ($ostype == 2) {
            $msdef = filterthroughcmd2("", "{$CHECKMOL} -l");
        }
    }
    $createcmd = "CREATE TABLE IF NOT EXISTS {$dbprefix}{$molstatsuffix} (\nmol_id int(11) NOT NULL DEFAULT '0', \n";
    $msdef = rtrim($msdef);
    $msline = explode("\n", $msdef);
    $nfields = count($msline);
    foreach ($msline as $line) {
        $element = explode(":", $line);
        $createcmd = $createcmd . "  {$element['0']}" . " SMALLINT(6) NOT NULL DEFAULT '0',\n";
    }
    $createcmd = $createcmd . "  PRIMARY KEY  (mol_id)\n) ENGINE = MYISAM COMMENT='Molecular statistics';";
    //echo "<pre>$createcmd</pre>\n";
    $result = mysql_query($createcmd) or die("Create failed! (4c)");
    #mysql_free_result($result);
    //molfgbtable
    $createcmd = "CREATE TABLE IF NOT EXISTS {$dbprefix}{$molfgbsuffix} (mol_id INT(11) NOT NULL DEFAULT '0', \n  fg01 INT(11) UNSIGNED NOT NULL,\n  fg02 INT(11) UNSIGNED NOT NULL,\n  fg03 INT(11) UNSIGNED NOT NULL,\n  fg04 INT(11) UNSIGNED NOT NULL,\n  fg05 INT(11) UNSIGNED NOT NULL,\n  fg06 INT(11) UNSIGNED NOT NULL,\n  fg07 INT(11) UNSIGNED NOT NULL,\n  fg08 INT(11) UNSIGNED NOT NULL,\n  n_1bits SMALLINT NOT NULL,\n  PRIMARY KEY mol_id (mol_id)) ENGINE = MYISAM COMMENT='Functional group patterns'";
    $result6 = mysql_query($createcmd) or die("Create failed! (4d)");
    #mysql_free_result($result6);
    //molcfptable
    //  first step: analyse the fingerprint dictionary (how many dict.?
    $createstr = "";
    $n_dict = 0;
    $result = mysql_query("SELECT fp_id, fpdef, fptype FROM {$fpdeftable}") or die("Query failed! (fpdef)");
    $fpdef = "";
    $fptype = 1;
    while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $fp_id = $line["fp_id"];
        $fpdef = $line["fpdef"];
        $fptype = $line["fptype"];
        if (strlen($fpdef) > 20) {
            $n_dict++;
            $dictnum = $n_dict;
            while (strlen($dictnum) < 2) {
                $dictnum = "0" . $dictnum;
            }
            if ($fptype == 1) {
                $createstr .= "  dfp{$dictnum} BIGINT NOT NULL,\n";
            } else {
                $createstr .= "  dfp{$dictnum} INT(11) UNSIGNED NOT NULL,\n";
            }
        }
    }
    mysql_free_result($result);
    $createstr = trim($createstr);
    if ($n_dict < 1) {
        die("ERROR: could not retrieve fingerprint definition from table {$fpdeftable}\n");
    }
    $tblname = $dbprefix . $molcfpsuffix;
    $idname = "mol_id";
    $keystr = "PRIMARY KEY mol_id (mol_id)";
    $createcmd = "CREATE TABLE IF NOT EXISTS {$tblname} \n  ({$idname} INT(11) NOT NULL DEFAULT '0', {$createstr}\n  hfp01 INT(11) UNSIGNED NOT NULL,\n  hfp02 INT(11) UNSIGNED NOT NULL,\n  hfp03 INT(11) UNSIGNED NOT NULL,\n  hfp04 INT(11) UNSIGNED NOT NULL,\n  hfp05 INT(11) UNSIGNED NOT NULL,\n  hfp06 INT(11) UNSIGNED NOT NULL,\n  hfp07 INT(11) UNSIGNED NOT NULL,\n  hfp08 INT(11) UNSIGNED NOT NULL,\n  hfp09 INT(11) UNSIGNED NOT NULL,\n  hfp10 INT(11) UNSIGNED NOT NULL,\n  hfp11 INT(11) UNSIGNED NOT NULL,\n  hfp12 INT(11) UNSIGNED NOT NULL,\n  hfp13 INT(11) UNSIGNED NOT NULL,\n  hfp14 INT(11) UNSIGNED NOT NULL,\n  hfp15 INT(11) UNSIGNED NOT NULL,\n  hfp16 INT(11) UNSIGNED NOT NULL,\n  n_h1bits SMALLINT NOT NULL, {$keystr}) \n  ENGINE = MYISAM COMMENT='Combined dictionary-based and hash-based fingerprints'";
    $result6 = mysql_query($createcmd) or die("Create failed! (4e)");
    #mysql_free_result($result6);
    //pic2dtable
    $createcmd = "CREATE TABLE {$dbprefix}{$pic2dsuffix} (\n  `mol_id` INT(11) NOT NULL DEFAULT '0',\n  `type` TINYINT NOT NULL DEFAULT '1' COMMENT '1 = png',\n  `status` TINYINT NOT NULL DEFAULT '0' COMMENT '0 = does not exist, 1 = OK, 2 = OK, but do not show, 3 = to be created/updated, 4 = to be deleted',\n  `svg` BLOB NOT NULL,\n  PRIMARY KEY (mol_id)\n  ) ENGINE = MYISAM CHARACTER SET {$mysql_charset} COLLATE {$mysql_collation} COMMENT='Housekeeping for 2D depiction'";
    $result6 = mysql_query($createcmd) or die("Create failed! (4f)");
    #mysql_free_result($result6);
}