$rxn_id = $bdd->lastInsertId(); // then we want to separate our rxn scheme into products and reactant molecules $rxn_content = explode("\$MOL\n", $rxn); $header_lines = explode("\n", $rxn_content[0]); $num_react = intval(substr($header_lines[4], 0, 3)); $num_prod = intval(substr($header_lines[4], 3, 6)); $molecules = array(); for ($i = 0; $i < $num_react + $num_prod; $i++) { $molecules[] = $rxn_content[$i + 1]; } // then get the compound number (from compounds table) for each molecule. If molecule isn't in table, // put it in and generate fingerprints $cids = array(); for ($i = 0; $i < count($molecules); $i++) { $inchi = getInChI($molecules[$i], $bdd); $cid = findInChI($inchi, $bdd); if ($cid) { $cids[] = $cid; } else { $sql = "INSERT INTO compounds(name, created, user_id_entrant) VALUES('', NOW(), :userid)"; $req = $bdd->prepare($sql); $result = $req->execute(array('userid' => $_SESSION['userid'])); $cid = $bdd->lastInsertId(); $sql = "INSERT INTO 3D_structures(compound_id, molfile) VALUES(:cid, :molfile)"; $req = $bdd->prepare($sql); $result = $req->execute(array('cid' => $cid, 'molfile' => $molecules[$i])); $sql = "INSERT INTO `1D_structures` (`compound_id`,`inchi`,`smiles`) SELECT `compound_id`, MOLECULE_TO_INCHI(`molfile`), MOLECULE_TO_SMILES(`molfile`) FROM `3D_structures` WHERE `compound_id` = :cid;"; $req = $bdd->prepare($sql); $result = $req->execute(array('cid' => $cid)); $sql = "INSERT INTO `bin_structures` (`compound_id`,`fp2`,`obserialized`) SELECT `compound_id`, FINGERPRINT2(`molfile`), MOLECULE_TO_SERIALIZEDOBMOL(`molfile`) FROM `3D_structures` WHERE `compound_id` = :cid;"; $req = $bdd->prepare($sql);
* eLabChem is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * * PURPOSE. See the GNU Affero General Public License for more details. * * * * You should have received a copy of the GNU Affero General Public * * License along with eLabChem. If not, see <http://www.gnu.org/licenses/>. * * * * eLabChem is a fork of elabFTW. * * * ********************************************************************************/ require_once 'inc/connect.php'; require_once 'inc/functions.php'; $mol = $_REQUEST['mol']; $inchi = getInChI($mol, $bdd); $compoundId = findInChI($inchi, $bdd); if ($compoundId) { $sql = "SELECT c.id, c.name as cpd_name, c.iupac_name, c.cas_number, c.pubchem_id, c.chemspider_id, c.notes, cp.mwt, cp.exact_mass, cp.formula, cp.density,\n\t\tcpreg.id AS regid, cpreg.regno, cpreg.validated, cpreg.is_salt, cpreg.parent_regid \n\t\tFROM compounds c INNER JOIN compound_properties cp \n\t\tON c.id = cp.compound_id \n\t\tLEFT JOIN compound_registry AS cpreg \n\t\tON c.id = cpreg.cpd_id \n\t\tWHERE c.id= :cid "; $req = $bdd->prepare($sql, array(PDO::ATTR_EMULATE_PREPARES => false)); $req->execute(array('cid' => $compoundId)); $result = $req->fetch(PDO::FETCH_ASSOC); $result['inchi'] = $inchi; $result = array_filter($result); if (isset($result['is_salt']) && isset($result['parent_regid'])) { // get reg no corresponding to regid $sql = "SELECT regno FROM compound_registry WHERE id = :regid"; $req = $bdd->prepare(); $req->execute(array('regid' => $result['parent_regid'])); $regsearch = $req->fetch(); if ($regsearch) { $result['parent_regno'] = $regsearch[0];
function exact_search($molecule, $table, $explist, $col) { global $bdd; $inchi = getInChI($molecule, $bdd); $cid = findInChI($inchi, $bdd); $results_arr = array(); $sql = "SELECT " . $col . " FROM {$table} WHERE cpd_id = :cid"; $req = $bdd->prepare($sql); $result = $req->execute(array('cid' => $cid)); while ($data = $req->fetch()) { $results_arr[] = $data[$col]; } return array_unique($results_arr); }