示例#1
0
        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);
                }
            }
        }