public IEnumerable <FetchedData> fetch(SqlConnection conn) { byte[] fp; BingoCore.ringoGetQueryFingerprint(out fp); // Search using fast index _index_data.fingerprints.init(conn); _index_data.storage.validate(conn); IEnumerable <int> screened; if (!_index_data.fingerprints.ableToScreen(fp)) { screened = _index_data.storage.enumerateStorageIds(nextAfterStorageId); } else { screened = _index_data.fingerprints.screenSub(conn, fp, nextAfterStorageId); } int cache_index = 0; foreach (int storage_id in screened) { if (_index_data.storage.isDeleted(storage_id, conn, ref cache_index)) { continue; } byte[] data_with_cmf = _index_data.storage.get(storage_id, 4, -1, conn, ref cache_index); int ret = BingoCore.lib.ringoMatchTargetBinary(data_with_cmf, data_with_cmf.Length); if (ret == -2) { throw new Exception(BingoCore.lib.bingoGetError()); } if (ret == -1) { throw new Exception(BingoCore.lib.bingoGetWarning()); } if (ret == 1) { int id = _index_data.storage.getInt(storage_id, 0, conn, ref cache_index); FetchedData data = new FetchedData(id); if (highlighting) { data.str = BingoCore.ringoGetHightlightedReaction(); } yield return(data); } } }
public IEnumerable<FetchedData> fetch (SqlConnection conn) { byte[] fp; BingoCore.ringoGetQueryFingerprint(out fp); // Search using fast index _index_data.fingerprints.init(conn); _index_data.storage.validate(conn); IEnumerable<int> screened; if (!_index_data.fingerprints.ableToScreen(fp)) screened = _index_data.storage.enumerateStorageIds(nextAfterStorageId); else screened = _index_data.fingerprints.screenSub(conn, fp, nextAfterStorageId); int cache_index = 0; foreach (int storage_id in screened) { if (_index_data.storage.isDeleted(storage_id, conn, ref cache_index)) continue; byte[] data_with_cmf = _index_data.storage.get(storage_id, 4, -1, conn, ref cache_index); int ret = BingoCore.lib.ringoMatchTargetBinary(data_with_cmf, data_with_cmf.Length); if (ret == -2) throw new Exception(BingoCore.lib.bingoGetError()); if (ret == -1) throw new Exception(BingoCore.lib.bingoGetWarning()); if (ret == 1) { int id = _index_data.storage.getInt(storage_id, 0, conn, ref cache_index); FetchedData data = new FetchedData(id); if (highlighting) data.str = BingoCore.ringoGetHightlightedReaction(); yield return data; } } }
public IEnumerable <FetchedData> fetch(SqlConnection conn) { ArrayList res_list = new ArrayList(); StringBuilder command_text = new StringBuilder(); command_text.Append("SELECT sh.id"); if (search_type == SearchType.EXACT) { command_text.Append(", sh.cmf"); if (need_xyz) { command_text.Append(", sh.xyz"); } } if (search_type == SearchType.GROSS) { command_text.Append(", gross"); } if (search_type == SearchType.MASS) { command_text.Append(", mass"); } command_text.AppendFormat(" FROM {0} sh", _index_data.shadowTable); command_text.Append(table_copies); StringBuilder final_where_clause = new StringBuilder(); if (where_clause.Length > 0) { final_where_clause.Append(" ( "); final_where_clause.Append(where_clause); final_where_clause.Append(" ) "); } if (nextAfterStorageId != null) { if (final_where_clause.Length > 0) { final_where_clause.Append(" and "); } final_where_clause.Append(" ("); final_where_clause.AppendFormat(" storage_id > {0} ", nextAfterStorageId.Value); final_where_clause.Append(" )"); } if (final_where_clause.Length > 0) { command_text.Append(" WHERE "); command_text.Append(final_where_clause.ToString()); } if (nextAfterStorageId.HasValue) { command_text.Append(" ORDER BY storage_id"); } UTF8Encoding encoding = new UTF8Encoding(); using (SqlCommand cmd = new SqlCommand(command_text.ToString(), conn)) { cmd.CommandTimeout = 3600; using (SqlDataReader reader = cmd.ExecuteReader()) { byte[] xyz = new byte[0]; while (reader.Read()) { int id = Convert.ToInt32(reader[0]); int res; if (search_type == SearchType.EXACT) { byte[] cmf = (byte[])reader[1]; if (need_xyz) { xyz = (byte[])reader[2]; } res = BingoCore.lib.mangoMatchTargetBinary(cmf, cmf.Length, xyz, xyz.Length); } else if (search_type == SearchType.GROSS) { byte[] gross = encoding.GetBytes((string)reader[1]); res = BingoCore.lib.mangoMatchTarget(gross, gross.Length); } else if (search_type == SearchType.MASS) { res = 1; } else { throw new Exception("Search type is undefined"); } if (res == -2) { throw new Exception(BingoCore.lib.bingoGetError()); } if (res == -1) { throw new Exception(BingoCore.lib.bingoGetWarning()); } if (res == 1) { FetchedData data = new FetchedData(id); if (search_type == SearchType.MASS) { data.value = (float)reader[1]; } yield return(data); } } } } }
public IEnumerable<FetchedData> fetch (SqlConnection conn) { byte[] fp; BingoCore.mangoGetQueryFingerprint(out fp); // Search using fast index _index_data.fingerprints.init(conn); _index_data.storage.validate(conn); int need_coords = BingoCore.lib.mangoNeedCoords(); byte[] xyz = new byte[0]; IEnumerable<int> screened; if (search_type == SearchType.SUB) { if (!_index_data.fingerprints.ableToScreen(fp)) screened = _index_data.storage.enumerateStorageIds(nextAfterStorageId); else screened = _index_data.fingerprints.screenSub(conn, fp, nextAfterStorageId); } else { screened = _index_data.fingerprints.screenSim(conn, fp, nextAfterStorageId, new BingoFingerprints.getBoundsDelegate(simGetMinMaxBounds)); } int cache_index = 0; foreach (int storage_id in screened) { if (_index_data.storage.isDeleted(storage_id, conn, ref cache_index)) continue; // TODO: add match with xyz test for binary molecules byte[] data_with_cmf = _index_data.storage.get(storage_id, 6, -1, conn, ref cache_index); if (need_coords != 0) { xyz = _index_data.getXyz(storage_id, conn); } int ret = BingoCore.lib.mangoMatchTargetBinary(data_with_cmf, data_with_cmf.Length, xyz, xyz.Length); if (ret < 0) { // Exception has happend // Extract id int id = _index_data.storage.getInt(storage_id, 0, conn, ref cache_index); string msg = "Undef"; if (ret == -2) msg = BingoCore.lib.bingoGetError(); if (ret == -1) msg = BingoCore.lib.bingoGetWarning(); throw new Exception(String.Format("Id = {0}: {1}", id, msg)); } if (ret == 1) { // Extract id int id = _index_data.storage.getInt(storage_id, 0, conn, ref cache_index); FetchedData mol = new FetchedData(id); if (highlighting) { if (need_coords == 0) { // Load xyz byte[] xyz_found = _index_data.getXyz(storage_id, conn); BingoCore.lib.mangoLoadTargetBinaryXyz(xyz_found, xyz_found.Length); } mol.str = BingoCore.mangoGetHightlightedMolecule(); } if (search_type == SearchType.SIM) BingoCore.lib.mangoSimilarityGetScore(out mol.value); yield return mol; } } }
public IEnumerable <FetchedData> fetch(SqlConnection conn) { byte[] fp; BingoCore.mangoGetQueryFingerprint(out fp); // Search using fast index _index_data.fingerprints.init(conn); _index_data.storage.validate(conn); int need_coords = BingoCore.lib.mangoNeedCoords(); byte[] xyz = new byte[0]; IEnumerable <int> screened; if (search_type == SearchType.SUB) { if (!_index_data.fingerprints.ableToScreen(fp)) { screened = _index_data.storage.enumerateStorageIds(nextAfterStorageId); } else { screened = _index_data.fingerprints.screenSub(conn, fp, nextAfterStorageId); } } else { screened = _index_data.fingerprints.screenSim(conn, fp, nextAfterStorageId, new BingoFingerprints.getBoundsDelegate(simGetMinMaxBounds)); } int cache_index = 0; foreach (int storage_id in screened) { if (_index_data.storage.isDeleted(storage_id, conn, ref cache_index)) { continue; } // TODO: add match with xyz test for binary molecules byte[] data_with_cmf = _index_data.storage.get(storage_id, 6, -1, conn, ref cache_index); if (need_coords != 0) { xyz = _index_data.getXyz(storage_id, conn); } int ret = BingoCore.lib.mangoMatchTargetBinary(data_with_cmf, data_with_cmf.Length, xyz, xyz.Length); if (ret < 0) { // Exception has happend // Extract id int id = _index_data.storage.getInt(storage_id, 0, conn, ref cache_index); string msg = "Undef"; if (ret == -2) { msg = BingoCore.lib.bingoGetError(); } if (ret == -1) { msg = BingoCore.lib.bingoGetWarning(); } throw new Exception(String.Format("Id = {0}: {1}", id, msg)); } if (ret == 1) { // Extract id int id = _index_data.storage.getInt(storage_id, 0, conn, ref cache_index); FetchedData mol = new FetchedData(id); if (highlighting) { if (need_coords == 0) { // Load xyz byte[] xyz_found = _index_data.getXyz(storage_id, conn); BingoCore.lib.mangoLoadTargetBinaryXyz(xyz_found, xyz_found.Length); } mol.str = BingoCore.mangoGetHightlightedMolecule(); } if (search_type == SearchType.SIM) { BingoCore.lib.mangoSimilarityGetScore(out mol.value); } yield return(mol); } } }
public IEnumerable<FetchedData> fetch (SqlConnection conn) { ArrayList res_list = new ArrayList(); StringBuilder command_text = new StringBuilder(); command_text.Append("SELECT sh.id"); if (search_type == SearchType.EXACT) { command_text.Append(", sh.cmf"); if (need_xyz) command_text.Append(", sh.xyz"); } if (search_type == SearchType.GROSS) command_text.Append(", gross"); if (search_type == SearchType.MASS) command_text.Append(", mass"); command_text.AppendFormat(" FROM {0} sh", _index_data.shadowTable); command_text.Append(table_copies); StringBuilder final_where_clause = new StringBuilder(); if (where_clause.Length > 0) { final_where_clause.Append(" ( "); final_where_clause.Append(where_clause); final_where_clause.Append(" ) "); } if (nextAfterStorageId != null) { if (final_where_clause.Length > 0) final_where_clause.Append(" and "); final_where_clause.Append(" ("); final_where_clause.AppendFormat(" storage_id > {0} ", nextAfterStorageId.Value); final_where_clause.Append(" )"); } if (final_where_clause.Length > 0) { command_text.Append(" WHERE "); command_text.Append(final_where_clause.ToString()); } if (nextAfterStorageId.HasValue) command_text.Append(" ORDER BY storage_id"); UTF8Encoding encoding = new UTF8Encoding(); using (SqlCommand cmd = new SqlCommand(command_text.ToString(), conn)) { cmd.CommandTimeout = 3600; using (SqlDataReader reader = cmd.ExecuteReader()) { byte[] xyz = new byte[0]; while (reader.Read()) { int id = Convert.ToInt32(reader[0]); int res; if (search_type == SearchType.EXACT) { byte[] cmf = (byte[])reader[1]; if (need_xyz) xyz = (byte[])reader[2]; res = BingoCore.lib.mangoMatchTargetBinary(cmf, cmf.Length, xyz, xyz.Length); } else if (search_type == SearchType.GROSS) { byte[] gross = encoding.GetBytes((string)reader[1]); res = BingoCore.lib.mangoMatchTarget(gross, gross.Length); } else if (search_type == SearchType.MASS) res = 1; else throw new Exception("Search type is undefined"); if (res == -2) throw new Exception(BingoCore.lib.bingoGetError()); if (res == -1) throw new Exception(BingoCore.lib.bingoGetWarning()); if (res == 1) { FetchedData data = new FetchedData(id); if (search_type == SearchType.MASS) data.value = (float)reader[1]; yield return data; } } } } }