示例#1
0
        /// <summary>
        /// GetMaxCorpId
        /// </summary>
        /// <returns></returns>
        public static int GetMaxDestMolId()
        {
            int            molId, maxMolId = 0;
            FingerprintDao fpd = new FingerprintDao(Database, FingerprintType);
            List <string>  ids = new List <string>();

            if (!fpd.DataFilesExist())
            {
                return(maxMolId);
            }

            fpd.OpenReaders();

            while (true)
            {
                FingerprintRec rec = fpd.ReadFingerprintRec();
                if (rec == null)
                {
                    break;
                }

                //CorpIds.Add(rec.Cid); // debug

                if (CorpDatabase)
                {
                    int.TryParse(rec.Cid, out molId);
                }
                else
                {
                    molId = rec.molId;
                }

                if (molId > maxMolId)
                {
                    maxMolId = molId;
                }
            }

            fpd.CloseReaders();

            return(maxMolId);
        }
示例#2
0
        /// <summary>
        /// ExecuteSearch
        /// </summary>
        /// <param name="queryMol"></param>

        public List <StructSearchMatch> ExecuteSearch(
            IAtomContainer queryMol)
        {
            AssertMx.IsTrue(FingerprintType == FingerprintType.MACCS || FingerprintType == FingerprintType.Circular,
                            "Invalid FingerprintType: " + FingerprintType);

            QueryMol = queryMol;

            BitSetFingerprint fp =             // generate a fingerprint
                                   CdkMol.BuildBitSetFingerprintForLargestFragment(queryMol, FingerprintType);

            QueryFpCardinality = fp.cardinality();
            QueryFpLongArray   = fp.asBitSet().toLongArray();

            MatchList       = new List <StructSearchMatch>();
            ThreadException = null;

            foreach (string databaseName in FingerprintDbMx.Databases)             // loop on all databases
            {
                int srcId = -1;
                if (Lex.Contains(databaseName, "corp"))
                {
                    if (!GetCorpSim)
                    {
                        continue;
                    }
                    srcId = StructSearchMatch.CorpDbId;
                }

                else if (Lex.Contains(databaseName, "chembl"))
                {
                    if (!GetChemblSim)
                    {
                        continue;
                    }
                    srcId = StructSearchMatch.ChemblDbId;
                }

                if (Debug)
                {
                    DebugLog.Message("Starting sim search on " + databaseName + " database");
                }

                FpDao = new FingerprintDao(databaseName, FingerprintType);

                if (!FpDao.DataFilesExist())
                {
                    continue;                                          // no files for this database
                }
                FileStreamReaders = FpDao.OpenReaders();
                FileMatchLists    = new List <StructSearchMatch> [FileStreamReaders.Length];
                for (int i1 = 0; i1 < FileMatchLists.Length; i1++)
                {
                    FileMatchLists[i1] = new List <StructSearchMatch>();
                }

                DateTime t0 = DateTime.Now;

                if (UseMultipleThreads)
                {
                    ExecuteMultiThreadSearch();
                }
                else
                {
                    ExecuteSingleThreadSearch();
                }

                double et = TimeOfDay.Delta(ref t0);

                FpDao.CloseReaders();

                List <StructSearchMatch> matchList = MergeIndividualFileMatchLists();

                if (KeysToExclude != null || SearchKeySubset != null)                 // filter by any allowed/disallowed keys
                {
                    List <StructSearchMatch> matchList2 = new List <StructSearchMatch>();

                    foreach (StructSearchMatch m0 in matchList)
                    {
                        if (KeysToExclude != null && KeysToExclude.Contains(m0.SrcCid))
                        {
                            continue;
                        }

                        if (SearchKeySubset != null && !SearchKeySubset.Contains(m0.SrcCid))
                        {
                            continue;
                        }

                        matchList2.Add(m0);
                    }

                    matchList = matchList2;
                }

                matchList.Sort(StructSearchMatch.CompareByMatchQuality);

                //int removeCount = matchList.Count - MaxHits; // limit to maxhits per database
                //if (removeCount > 0)
                //	matchList.RemoveRange(MaxHits, removeCount);

                //foreach (StructSearchMatch ssm0 in matchList)
                //	if (ssm0.SrcId != srcId) ssm0.SrcId = srcId; // debug

                MatchList.AddRange(matchList);

                double et2 = TimeOfDay.Delta(ref t0);

                string msg =
                    string.Format("Search complete (" + databaseName + ").Time : {0:0.00} ", et) +
                    string.Format("{0} Hits: ", FileMatchLists[0].Count);

                if (Debug)
                {
                    DebugLog.Message(msg);
                }

                for (int hi = 0; hi < 5 && hi < FileMatchLists[0].Count; hi++)
                {
                    StructSearchMatch sm = FileMatchLists[0][hi];
                    msg += sm.SrcCid + string.Format(" = {0:0.00}, ", sm.MatchScore);
                }
            }             // database loop

            if (ThreadException != null)
            {
                throw new Exception(ThreadException.Message, ThreadException);
            }

            MatchList.Sort(             // sort by decreasing sim value
                delegate(StructSearchMatch p1, StructSearchMatch p2)
                { return(p2.MatchScore.CompareTo(p1.MatchScore)); });

            if (MaxHits > 0 && MatchList.Count > MaxHits)             // remove hits beyond maximum if defined
            {
                MatchList.RemoveRange(MaxHits, MatchList.Count - MaxHits);
            }

            //ShowProgress(msg);
            //Thread.Sleep(10000000);
            return(MatchList);
        }