Exemplo n.º 1
0
        public bool ExecuteSearch(string queryString, SearchType searchType, IDictionary<string, object> options)
        {
            try
            {
                _searchCancelled = false;
                _errorState = false;
                _frmProgress = new frmProgress();
                _frmProgress.FormClosed += new FormClosedEventHandler(_frmProgress_FormClosed);

                if (options == null)
                    options = new Dictionary<string, object>();

                #region set common search options

                // setup search options
                var commonSearchOptions = new CommonSearchOptions();

                // Complexity
                if (options.ContainsKey("Complexity"))
                {
                    switch (options["Complexity"].ToString())
                    {
                        case ("Any"):
                            {
                                commonSearchOptions.Complexity = EComplexity.Any;
                                break;
                            }

                        case ("Multi"):
                            {
                                commonSearchOptions.Complexity = EComplexity.Multi;
                                break;
                            }

                        case ("Single"):
                            {
                                commonSearchOptions.Complexity = EComplexity.Single;
                                break;
                            }
                        default:
                            {
                                commonSearchOptions.Complexity = EComplexity.Any;
                                break;
                            }
                    }
                }

                // Isotopic
                if (options.ContainsKey("Isotopic"))
                {
                    switch (options["Isotopic"].ToString())
                    {
                        case ("Any"):
                            {
                                commonSearchOptions.Isotopic = EIsotopic.Any;
                                break;
                            }

                        case ("Labeled"):
                            {
                                commonSearchOptions.Isotopic = EIsotopic.Labeled;
                                break;
                            }

                        case ("NotLabeled"):
                            {
                                commonSearchOptions.Isotopic = EIsotopic.NotLabeled;
                                break;
                            }
                        default:
                            {
                                commonSearchOptions.Isotopic = EIsotopic.Any;
                                break;
                            }
                    }
                }

                var hasPatents = false;
                if (options.ContainsKey("HasPatents"))
                    hasPatents = Convert.ToBoolean(options["HasPatents"]);

                commonSearchOptions.HasPatents = hasPatents;

                var hasSpectra = false;
                if (options.ContainsKey("HasSpectra"))
                    hasSpectra = Convert.ToBoolean(options["HasSpectra"]);

                commonSearchOptions.HasSpectra = hasSpectra;

                #endregion

                #region run search

                switch (searchType)
                {
                    case (SearchType.Elements):
                        {
                            var includeAll = false;
                            if (options.ContainsKey("IncludeAll"))
                                includeAll = Convert.ToBoolean(options["IncludeAll"]);

                            String[] includeElements = null;
                            if (options.ContainsKey("IncludeElements"))
                                includeElements = options["IncludeElements"].ToString().Replace(",", "|").Replace(";", "|").Replace(" ", "").Split("|".ToCharArray());

                            String[] excludeElements = null;
                            if (options.ContainsKey("ExcludeElements"))
                                excludeElements = options["ExcludeElements"].ToString().Replace(",", "|").Replace(";", "|").Replace(" ", "").Split("|".ToCharArray());

                            var searchOptions = new ElementsSearchOptions
                            {
                                IncludeAll = includeAll,
                                IncludeElements = includeElements,
                                ExcludeElements = excludeElements
                            };

                            _cs.ElementsSearchAsync(searchOptions, commonSearchOptions, _token);
                            _frmProgress.ShowDialog(_owner);
                            break;
                        }

                    case (SearchType.IntrinsicProperty):
                        {
                            var searchOptions = new IntrinsicPropertiesSearchOptions();

                            if (options.ContainsKey("EmpiricalFormula") && !String.IsNullOrEmpty(options["EmpiricalFormula"].ToString()))
                            {
                                searchOptions.EmpiricalFormula = options["EmpiricalFormula"].ToString();
                            }

                            if (options.ContainsKey("AverageMassMax") && !String.IsNullOrEmpty(options["AverageMassMax"].ToString()))
                            {
                                searchOptions.AverageMassMax = Convert.ToDouble(options["AverageMassMax"]);
                            }

                            if (options.ContainsKey("AverageMassMin") && !String.IsNullOrEmpty(options["AverageMassMin"].ToString()))
                            {
                                searchOptions.AverageMassMin = Convert.ToDouble(options["AverageMassMin"]);
                            }

                            if (options.ContainsKey("MolWeightMax") && !String.IsNullOrEmpty(options["MolWeightMax"].ToString()))
                            {
                                searchOptions.MolWeightMax = Convert.ToDouble(options["MolWeightMax"]);
                            }

                            if (options.ContainsKey("MolWeightMin") && !String.IsNullOrEmpty(options["MolWeightMin"].ToString()))
                            {
                                searchOptions.MolWeightMin = Convert.ToDouble(options["MolWeightMin"]);
                            }

                            if (options.ContainsKey("MonoisotopicMassMax") && !String.IsNullOrEmpty(options["MonoisotopicMassMax"].ToString()))
                            {
                                searchOptions.MonoisotopicMassMax = Convert.ToDouble(options["MonoisotopicMassMax"]);
                            }

                            if (options.ContainsKey("MonoisotopicMassMin") && !String.IsNullOrEmpty(options["MonoisotopicMassMin"].ToString()))
                            {
                                searchOptions.MonoisotopicMassMin = Convert.ToDouble(options["MonoisotopicMassMin"]);
                            }

                            if (options.ContainsKey("NominalMassMax") && !String.IsNullOrEmpty(options["NominalMassMax"].ToString()))
                            {
                                searchOptions.NominalMassMax = Convert.ToDouble(options["NominalMassMax"]);
                            }

                            if (options.ContainsKey("NominalMassMin") && !String.IsNullOrEmpty(options["NominalMassMin"].ToString()))
                            {
                                searchOptions.NominalMassMin = Convert.ToDouble(options["NominalMassMin"]);
                            }

                            _cs.IntrinsicPropertiesSearchAsync(searchOptions, commonSearchOptions, _token);
                            _frmProgress.ShowDialog(_owner);
                            break;
                        }

                    case (SearchType.Lasso):
                        {
                            var familyMax = new List<string>();
                            if (options.ContainsKey("FamilyMax"))
                                familyMax.AddRange(options["FamilyMax"].ToString().Replace(" ", "").Split(";".ToCharArray()));

                            var familyMin = "";
                            if (options.ContainsKey("FamilyMin"))
                                familyMin = options["FamilyMin"].ToString();

                            double thresholdMax = 0;
                            if (options.ContainsKey("ThresholdMax"))
                                thresholdMax = Convert.ToDouble(options["ThresholdMax"]);

                            double thresholdMin = 0;
                            if (options.ContainsKey("ThresholdMin"))
                                thresholdMin = Convert.ToDouble(options["ThresholdMin"]);

                            var searchOptions = new LassoSearchOptions
                            {
                                FamilyMax = familyMax.ToArray(),
                                FamilyMin = familyMin,
                                ThresholdMax = thresholdMax,
                                ThresholdMin = thresholdMin
                            };

                            _cs.LassoSearchAsync(searchOptions, commonSearchOptions, _token);
                            _frmProgress.ShowDialog(_owner);
                            break;
                        }

                    case (SearchType.PredictedProperty):
                        {
                            var searchOptions = new PredictedPropertiesSearchOptions();

                            if (options.ContainsKey("BoilingPointMax") && !String.IsNullOrEmpty(options["BoilingPointMax"].ToString()))
                            {
                                searchOptions.BoilingPointMax = Convert.ToDouble(options["BoilingPointMax"]);
                            }

                            if (options.ContainsKey("BoilingPointMin") && !String.IsNullOrEmpty(options["BoilingPointMin"].ToString()))
                            {
                                searchOptions.BoilingPointMin = Convert.ToDouble(options["BoilingPointMin"]);
                            }

                            if (options.ContainsKey("DensityMax") && !String.IsNullOrEmpty(options["DensityMax"].ToString()))
                            {
                                searchOptions.DensityMax = Convert.ToDouble(options["DensityMax"]);
                            }

                            if (options.ContainsKey("DensityMin") && !String.IsNullOrEmpty(options["DensityMin"].ToString()))
                            {
                                searchOptions.DensityMin = Convert.ToDouble(options["DensityMin"]);
                            }

                            if (options.ContainsKey("FlashPointMax") && !String.IsNullOrEmpty(options["FlashPointMax"].ToString()))
                            {
                                searchOptions.FlashPointMax = Convert.ToDouble(options["FlashPointMax"]);
                            }

                            if (options.ContainsKey("FlashPointMin") && !String.IsNullOrEmpty(options["FlashPointMin"].ToString()))
                            {
                                searchOptions.FlashPointMin = Convert.ToDouble(options["FlashPointMin"]);
                            }

                            if (options.ContainsKey("FreelyRotatableBondsMax") && !String.IsNullOrEmpty(options["FreelyRotatableBondsMax"].ToString()))
                            {
                                searchOptions.FreelyRotatableBondsMax = Convert.ToInt32(options["FreelyRotatableBondsMax"]);
                            }

                            if (options.ContainsKey("FreelyRotatableBondsMin") && !String.IsNullOrEmpty(options["FreelyRotatableBondsMin"].ToString()))
                            {
                                searchOptions.FreelyRotatableBondsMin = Convert.ToInt32(options["FreelyRotatableBondsMin"]);
                            }

                            if (options.ContainsKey("HAcceptorsMax") && !String.IsNullOrEmpty(options["HAcceptorsMax"].ToString()))
                            {
                                searchOptions.HAcceptorsMax = Convert.ToInt32(options["HAcceptorsMax"]);
                            }

                            if (options.ContainsKey("HAcceptorsMin") && !String.IsNullOrEmpty(options["HAcceptorsMin"].ToString()))
                            {
                                searchOptions.HAcceptorsMin = Convert.ToInt32(options["HAcceptorsMin"]);
                            }

                            if (options.ContainsKey("HDonorsMax") && !String.IsNullOrEmpty(options["HDonorsMax"].ToString()))
                            {
                                searchOptions.HDonorsMax = Convert.ToInt32(options["HDonorsMax"]);
                            }

                            if (options.ContainsKey("HDonorsMin") && !String.IsNullOrEmpty(options["HDonorsMin"].ToString()))
                            {
                                searchOptions.HDonorsMin = Convert.ToInt32(options["HDonorsMin"]);
                            }

                            if (options.ContainsKey("LogD55Max") && !String.IsNullOrEmpty(options["LogD55Max"].ToString()))
                            {
                                searchOptions.LogD55Max = Convert.ToDouble(options["LogD55Max"]);
                            }

                            if (options.ContainsKey("LogD55Min") && !String.IsNullOrEmpty(options["LogD55Min"].ToString()))
                            {
                                searchOptions.LogD55Min = Convert.ToDouble(options["LogD55Min"]);
                            }

                            if (options.ContainsKey("LogD74Max") && !String.IsNullOrEmpty(options["LogD74Max"].ToString()))
                            {
                                searchOptions.LogD74Max = Convert.ToDouble(options["LogD74Max"]);
                            }

                            if (options.ContainsKey("LogD74Min") && !String.IsNullOrEmpty(options["LogD74Min"].ToString()))
                            {
                                searchOptions.LogD74Min = Convert.ToDouble(options["LogD74Min"]);
                            }

                            if (options.ContainsKey("LogPMax") && !String.IsNullOrEmpty(options["LogPMax"].ToString()))
                            {
                                searchOptions.LogPMax = Convert.ToDouble(options["LogPMax"]);
                            }

                            if (options.ContainsKey("LogPMin") && !String.IsNullOrEmpty(options["LogPMin"].ToString()))
                            {
                                searchOptions.LogPMin = Convert.ToDouble(options["LogPMin"]);
                            }

                            if (options.ContainsKey("MolarVolumeMax") && !String.IsNullOrEmpty(options["MolarVolumeMax"].ToString()))
                            {
                                searchOptions.MolarVolumeMax = Convert.ToDouble(options["MolarVolumeMax"]);
                            }

                            if (options.ContainsKey("MolarVolumeMin") && !String.IsNullOrEmpty(options["MolarVolumeMin"].ToString()))
                            {
                                searchOptions.MolarVolumeMin = Convert.ToDouble(options["MolarVolumeMin"]);
                            }

                            if (options.ContainsKey("PolarSurfaceAreaMax") && !String.IsNullOrEmpty(options["PolarSurfaceAreaMax"].ToString()))
                            {
                                searchOptions.PolarSurfaceAreaMax = Convert.ToDouble(options["PolarSurfaceAreaMax"]);
                            }

                            if (options.ContainsKey("PolarSurfaceAreaMin") && !String.IsNullOrEmpty(options["PolarSurfaceAreaMin"].ToString()))
                            {
                                searchOptions.PolarSurfaceAreaMin = Convert.ToDouble(options["PolarSurfaceAreaMin"]);
                            }

                            if (options.ContainsKey("RefractiveIndexMax") && !String.IsNullOrEmpty(options["RefractiveIndexMax"].ToString()))
                            {
                                searchOptions.RefractiveIndexMax = Convert.ToDouble(options["RefractiveIndexMax"]);
                            }

                            if (options.ContainsKey("RefractiveIndexMin") && !String.IsNullOrEmpty(options["RefractiveIndexMin"].ToString()))
                            {
                                searchOptions.RefractiveIndexMin = Convert.ToDouble(options["RefractiveIndexMin"]);
                            }

                            if (options.ContainsKey("RuleOf5Max") && !String.IsNullOrEmpty(options["RuleOf5Max"].ToString()))
                            {
                                searchOptions.RuleOf5Max = Convert.ToInt32(options["RuleOf5Max"]);
                            }

                            if (options.ContainsKey("RuleOf5Min") && !String.IsNullOrEmpty(options["RuleOf5Min"].ToString()))
                            {
                                searchOptions.RuleOf5Min = Convert.ToInt32(options["RuleOf5Min"]);
                            }

                            if (options.ContainsKey("SurfaceTensionMax") && !String.IsNullOrEmpty(options["SurfaceTensionMax"].ToString()))
                            {
                                searchOptions.SurfaceTensionMax = Convert.ToDouble(options["SurfaceTensionMax"]);
                            }

                            if (options.ContainsKey("SurfaceTensionMin") && !String.IsNullOrEmpty(options["SurfaceTensionMin"].ToString()))
                            {
                                searchOptions.SurfaceTensionMin = Convert.ToDouble(options["SurfaceTensionMin"]);
                            }

                            _cs.PredictedPropertiesSearchAsync(searchOptions, commonSearchOptions, _token);
                            _frmProgress.ShowDialog(_owner);
                            break;
                        }

                    case (SearchType.Similarity):
                        {
                            float threshold = 0;
                            if (options.ContainsKey("SimilarityThreshold"))
                                threshold = Convert.ToSingle(options["SimilarityThreshold"]);

                            var searchOptions = new SimilaritySearchOptions
                            {
                                Molecule = queryString,
                                Threshold = threshold
                            };

                            // SimilarityType
                            if (options.ContainsKey("SimilarityType"))
                            {
                                switch (options["SimilarityType"].ToString())
                                {
                                    case ("Euclidian"):
                                        {
                                            searchOptions.SimilarityType = ESimilarityType.Euclidian;
                                            break;
                                        }

                                    case ("Tanimoto"):
                                        {
                                            searchOptions.SimilarityType = ESimilarityType.Tanimoto;
                                            break;
                                        }

                                    case ("Tversky"):
                                        {
                                            searchOptions.SimilarityType = ESimilarityType.Tversky;
                                            break;
                                        }

                                    default:
                                        {
                                            searchOptions.SimilarityType = ESimilarityType.Tanimoto;
                                            break;
                                        }
                                }
                            }

                            _cs.SimilaritySearchAsync(searchOptions, commonSearchOptions, _token);
                            _frmProgress.ShowDialog(_owner);
                            break;
                        }

                    case (SearchType.Simple):
                        {
                            if (string.IsNullOrEmpty(queryString))
                            {
                                var frmSimpleSearch = new frmSimpleSearch();
                                if (frmSimpleSearch.ShowDialog(_owner) == DialogResult.OK)
                                {
                                    _cs.SimpleSearchAsync(frmSimpleSearch.txtQuery.Text, _token);
                                    _frmProgress.ShowDialog(_owner);
                                }
                                else
                                {
                                    _owner.Cursor = Cursors.Default;
                                }
                            }
                            else
                            {
                               _cs.SimpleSearchAsync(queryString, _token);
                               _frmProgress.ShowDialog(_owner);
                            }
                            break;
                        }

                    case (SearchType.ExactStructure):
                        {
                            var searchOptions = new ExactStructureSearchOptions
                            {
                                Molecule = queryString,
                            };

                            // MatchType
                            if (options.ContainsKey("MatchType"))
                            {
                                switch (options["MatchType"].ToString())
                                {
                                    case ("ExactMatch"):
                                        {
                                            searchOptions.MatchType = EMatchType.ExactMatch;
                                            break;
                                        }

                                    case ("AllIsomers"):
                                        {
                                            searchOptions.MatchType = EMatchType.AllIsomers;
                                            break;
                                        }

                                    case ("AllTautomers"):
                                        {
                                            searchOptions.MatchType = EMatchType.AllTautomers;
                                            break;
                                        }

                                    case ("SameSkeletonExcludingH"):
                                        {
                                            searchOptions.MatchType = EMatchType.SameSkeletonExcludingH;
                                            break;
                                        }

                                    case ("SameSkeletonIncludingH"):
                                        {
                                            searchOptions.MatchType = EMatchType.SameSkeletonIncludingH;
                                            break;
                                        }
                                    default:
                                        {
                                            searchOptions.MatchType = EMatchType.ExactMatch;
                                            break;
                                        }
                                }
                            }

                            _cs.StructureSearchAsync(searchOptions, commonSearchOptions, _token);
                            _frmProgress.ShowDialog(_owner);
                            break;
                        }

                    case (SearchType.SubStructure):
                        {
                            var matchTautomers = false;
                            if (options.ContainsKey("MatchTautomers"))
                                matchTautomers = Convert.ToBoolean(options["MatchTautomers"]);

                            var searchOptions = new SubstructureSearchOptions
                            {
                                Molecule = queryString,
                                MatchTautomers = matchTautomers
                            };

                            _cs.SubstructureSearchAsync(searchOptions, commonSearchOptions, _token);
                            _frmProgress.ShowDialog(_owner);
                            break;
                        }

                }

                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(_owner, "Unexpected error: " + ex.Message, Application.ProductName, MessageBoxButtons.OK,
                MessageBoxIcon.Error);

                return false;
            }
            return true;
        }
Exemplo n.º 2
0
 /// <remarks/>
 public void SimilaritySearchAsync(SimilaritySearchOptions options, CommonSearchOptions commonOptions, string token) {
     this.SimilaritySearchAsync(options, commonOptions, token, null);
 }
Exemplo n.º 3
0
 /// <remarks/>
 public void SimilaritySearchAsync(SimilaritySearchOptions options, CommonSearchOptions commonOptions, string token, object userState) {
     if ((this.SimilaritySearchOperationCompleted == null)) {
         this.SimilaritySearchOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSimilaritySearchOperationCompleted);
     }
     this.InvokeAsync("SimilaritySearch", new object[] {
                 options,
                 commonOptions,
                 token}, this.SimilaritySearchOperationCompleted, userState);
 }
Exemplo n.º 4
0
 public string SimilaritySearch(SimilaritySearchOptions options, CommonSearchOptions commonOptions, string token) {
     object[] results = this.Invoke("SimilaritySearch", new object[] {
                 options,
                 commonOptions,
                 token});
     return ((string)(results[0]));
 }