Example #1
0
        private string GetChemStructure(LiteEntity le)
        {
            using (new WaitCursor())
            {
                var securityProtocol = ServicePointManager.SecurityProtocol;
                ServicePointManager.SecurityProtocol = securityProtocol | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

                ChebiWebServiceService    ws = new ChebiWebServiceService();
                getCompleteEntityResponse results;

                ws.Url       = UserOptions.ChEBIWebServiceUri;
                ws.UserAgent = "Chem4Word";

                getCompleteEntity gce = new getCompleteEntity();
                gce.chebiId = le.chebiId;

                results = ws.getCompleteEntity(gce);

                _allResults = results.@return;

                var chemStructure = _allResults?.ChemicalStructures?[0]?.structure;

                ServicePointManager.SecurityProtocol = securityProtocol;
                return(chemStructure);
            }
        }
Example #2
0
        private void UpdateDisplay()
        {
            string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()";

            ErrorsAndWarnings.Text = "";

            using (new WaitCursor())
            {
                var tag = ResultsListView.SelectedItems[0]?.Tag;

                LiteEntity le            = (LiteEntity)tag;
                var        chemStructure = GetChemStructure(le);

                if (!string.IsNullOrEmpty(chemStructure))
                {
                    _lastMolfile = ConvertToWindows(chemStructure);

                    SdFileConverter sdConverter = new SdFileConverter();
                    _lastModel = sdConverter.Import(chemStructure);
                    if (_lastModel.AllWarnings.Count > 0 || _lastModel.AllErrors.Count > 0)
                    {
                        Telemetry.Write(module, "Exception(Data)", chemStructure);
                        List <string> lines = new List <string>();
                        if (_lastModel.AllErrors.Count > 0)
                        {
                            Telemetry.Write(module, "Exception(Data)", string.Join(Environment.NewLine, _lastModel.AllErrors));
                            lines.Add("Errors(s)");
                            lines.AddRange(_lastModel.AllErrors);
                        }
                        if (_lastModel.AllWarnings.Count > 0)
                        {
                            Telemetry.Write(module, "Exception(Data)", string.Join(Environment.NewLine, _lastModel.AllWarnings));
                            lines.Add("Warnings(s)");
                            lines.AddRange(_lastModel.AllWarnings);
                        }
                        ErrorsAndWarnings.Text = string.Join(Environment.NewLine, lines);
                    }
                    ChebiId = le.chebiId;
                    if (_lastModel.MeanBondLength < Core.Helpers.Constants.MinimumBondLength - Core.Helpers.Constants.BondLengthTolerance ||
                        _lastModel.MeanBondLength > Core.Helpers.Constants.MaximumBondLength + Core.Helpers.Constants.BondLengthTolerance)
                    {
                        _lastModel.ScaleToAverageBondLength(Core.Helpers.Constants.StandardBondLength);
                    }
                    display1.Chemistry = _lastModel;
                }
                else
                {
                    display1.Chemistry     = null;
                    ErrorsAndWarnings.Text = "No structure available.";
                }

                EnableImport();
            }
        }
Example #3
0
        private string GetChemStructure(LiteEntity le)
        {
            using (new WaitCursor())
            {
                ChebiWebServiceService    ws = new ChebiWebServiceService();
                getCompleteEntityResponse results;

                ws.Url       = UserOptions.ChEBIWebServiceUri;
                ws.UserAgent = "Chem4Word";

                getCompleteEntity gce = new getCompleteEntity();
                gce.chebiId = le.chebiId;

                results = ws.getCompleteEntity(gce);

                _allResults = results.@return;

                var chemStructure = _allResults?.ChemicalStructures?[0]?.structure;
                return(chemStructure);
            }
        }