Exemple #1
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (!StructureChanged)
            {
                return;
            }

            QueryColumn qc = ColInfo.Qc;

            if (String.IsNullOrEmpty(StructureRenditor.MolfileString))
            {
                qc.SecondaryCriteria = qc.SecondaryCriteriaDisplay = "";
            }

            else
            {
                // Chime: CYAAFQwAncwQGj8h7GZ^yjgsajoFd0PQ1OYrnIdaPTl0lGnQYLHH2prJeJi$BhUHcMsE1TyQisJflsW2r293v92iC1^wVm$8wwLM7^krIFa8A1X6Jvu8VIYgCgJ8$y1RuqgCc5ifKbMAflB
                string chimeString = MoleculeMx.MolfileStringToChimeString(StructureRenditor.MolfileString);
                qc.SecondaryCriteria        = "SSS ( " + qc.MetaColumn.Name + ", " + Lex.AddSingleQuotes(chimeString) + ") = 1";
                qc.SecondaryCriteriaDisplay = qc.ActiveLabel + " contains substructure";
            }

            qc.SecondaryFilterType = FilterType.StructureSearch;

            QueryManager.QueryResultsControl.UpdateFiltering(ColInfo);
            FilterBasicCriteriaControl.SyncBaseQuerySecondaryCriteria(qc);             // sync any base query

            StructureChanged = false;
            return;
        }
Exemple #2
0
        private void StructureSearch_Click(object sender, EventArgs e)
        {
            QueryColumn qc = new QueryColumn();
            MetaColumn  mc = new MetaColumn();            // create minimal metacolumn with structure type to assoc with qc

            mc.DataType   = MetaColumnType.Structure;
            qc.MetaColumn = mc;

            bool gotCriteria = CriteriaStructure.Edit(qc);

            if (!gotCriteria || qc.Criteria == "")
            {
                return;
            }
            string sid = "";

            for (int si = 1; ; si++)
            {
                sid = "S" + si.ToString();
                if (!LabeledCriteria.Structures.ContainsKey(sid.ToUpper()))
                {
                    break;
                }
            }

            string chime = MoleculeMx.MolfileStringToChimeString(qc.MolString); // get chime string

            LabeledCriteria.Structures[sid.ToUpper()] = chime;                  // store sid & associated chime string
            qc.MolString = chime;
            string sCriteria = MqlUtil.ConvertQueryColumnStructureCriteriaToMql(qc);

            sCriteria = sCriteria.Replace("(ctab,", "(structure_field,");         // required dummy field name
            sCriteria = sCriteria.Replace(chime, "[Edit Structure " + sid + "]"); // substitute surrogate for structure
            sCriteria = sCriteria.Replace("'[", "[");                             // hack fixup
            sCriteria = sCriteria.Replace("]'", "]");

            Instance.InsertCriteria(sCriteria);
        }
Exemple #3
0
        /// <summary>
        /// Initialize for any structure hilighting
        /// </summary>

        void InitializeStructureHilighting()
        {
            QueryColumn qc = null;

            if (StructureHighlightingInitialized)
            {
                return;
            }

            // Structure match hilighting / orienting

            try
            {
                do
                {
                    qc = Query.GetFirstStructureCriteriaColumn();
                    if (qc == null)
                    {
                        break;
                    }
                    if (Lex.IsUndefined(qc.Criteria))
                    {
                        break;
                    }

                    ParsedSingleCriteria psc = MqlUtil.ParseQueryColumnCriteria(qc);
                    if (psc == null || Lex.IsUndefined(psc.Value))
                    {
                        break;
                    }

                    ParsedStructureCriteria pssc = ParsedStructureCriteria.ConvertFromPscToPssc(psc);

                    StructureDisplayFormat sdf = StructureDisplayFormat.Deserialize(qc.DisplayFormatString);                     // get any hilighting info from format

                    if (pssc.SearchType == StructureSearchType.Substructure)
                    {
                        string chime = MoleculeMx.MolfileStringToChimeString(qc.MolString);
                        if (!String.IsNullOrEmpty(chime))
                        {
                            AlignStructureToQuery     = Lex.Contains(psc.Value2, "Orient") || Lex.Contains(psc.Value2, "Align=True");
                            HighlightStructureMatches = !(Lex.Contains(psc.Value2, "NoHighlight") || Lex.Contains(psc.Value2, "Highlight=false"));
                            MoleculeMx cs = new MoleculeMx(MoleculeFormat.Chime, chime);
                            StrMatcher = new StructureMatcher();
                            StrMatcher.SetSSSQueryMolecule(cs);                             // set query used for highlighting
                        }
                    }

                    else if (pssc.SearchType == StructureSearchType.SmallWorld && pssc.SmallWorldParameters != null)
                    {
                        SmallWorldPredefinedParameters swp = pssc.SmallWorldParameters;
                        HighlightStructureMatches = swp.Highlight;
                        AlignStructureToQuery     = swp.Align;
                        //SmallWorldDepictions = null; // depiction cache
                    }

                    else if (pssc.SearchType == StructureSearchType.Related)                     //
                    {
                        string chime = MoleculeMx.MolfileStringToChimeString(qc.MolString);
                        if (!String.IsNullOrEmpty(chime))
                        {
                            AlignStructureToQuery     = Lex.Contains(psc.Value2, "Orient") || Lex.Contains(psc.Value2, "Align=True");
                            HighlightStructureMatches = !(Lex.Contains(psc.Value2, "NoHighlight") || Lex.Contains(psc.Value2, "Highlight=false"));
                            MoleculeMx cs = new MoleculeMx(MoleculeFormat.Chime, chime);
                            StrMatcher = new StructureMatcher();
                            StrMatcher.SetSSSQueryMolecule(cs);                             // set query used for SSS highlighting
                        }
                    }

                    else if (sdf.Highlight || sdf.Align)                     // other cases
                    {
                        HighlightStructureMatches = sdf.Highlight;
                        AlignStructureToQuery     = sdf.Align;
                    }

                    else
                    {
                        break;                      // no hilighting / orienting
                    }
                    StructureHighlightQc   = qc;
                    StructureHighlightPssc = pssc;
                } while (false);
            }

            catch (Exception ex)             // log & ignore any errors
            {
                string msg = DebugLog.FormatExceptionMessage(ex);
                if (qc != null)
                {
                    msg += "\r\n" +
                           "Criteria: " + qc.Criteria + "\r\n" +
                           "Molstring: " + qc.MolString;
                }

                DebugLog.Message(msg);
                return;
            }

            // Atom number display (not currently used)

            SS.I.DisplayAtomNumbers = (int)AtomNumberDisplayMode.None;             // see if need to display atom numbers
            for (int ti = 1; ti < Rf.Tables.Count; ti++)
            {
                ResultsTable rt = Rf.Tables[ti];
                MetaTable    mt = rt.MetaTable;
                if (mt.Name.IndexOf("todo: table that needs atom number display") >= 0)
                {
                    SS.I.DisplayAtomNumbers = (int)AtomNumberDisplayMode.All;
                    break;
                }
            }

            StructureHighlightingInitialized = true;
            return;
        }
Exemple #4
0
        /// <summary>
        /// Do setup in preparation for decompose
        /// </summary>
        /// <param name="qt"></param>
        /// <param name="q"></param>

        public void PrepareForDecompose(
            QueryTable qt,
            Query q)
        {
            throw new NotImplementedException();
#if false
            Stopwatch sw = Stopwatch.StartNew();

            MetaTable mt = qt.MetaTable;

            QueryColumn qc = qt.GetQueryColumnByName("core");
            if (qc == null)
            {
                throw new UserQueryException("Core column not defined in rgroup_decomposition table");
            }
            string molfile = qc.MolString;
            if (molfile == null || molfile == "")
            {             // core not defined in Rgroup decomposition table, try to get from structure search in rest of query
                foreach (QueryTable qt3 in q.Tables)
                {
                    if (!qt3.MetaTable.IsRootTable)
                    {
                        continue;
                    }
                    MetaColumn mc3 = qt3.MetaTable.FirstStructureMetaColumn;
                    if (mc3 != null)
                    {
                        QueryColumn qc3 = qt3.GetQueryColumnByName(mc3.Name);
                        molfile = qc3.MolString;
                        break;
                    }
                }
            }

            if (molfile == null || molfile == "")
            {
                throw new UserQueryException("R-group decomposition core structure is not defined");
            }

            bool allowHydrogenSubstituents = true;
            qc = qt.GetQueryColumnByName("AllowHydrogenSubstituents");
            if (Lex.Contains(qc?.Criteria, "'N'"))
            {
                allowHydrogenSubstituents = false;                                                // set to false if "no" criteria specified
            }
            TerminateOptionString = "First mapping";
            bool allowMultipleCoreMappings = false;

            qc = qt.GetQueryColumnByName("Terminate_Option");
            if (qc != null && qc.Criteria != "")
            {
                ParsedSingleCriteria psc = MqlUtil.ParseSingleCriteria(qc.Criteria);
                TerminateOptionString     = psc.Value;
                allowMultipleCoreMappings = Lex.Contains(TerminateOptionString, "All");
            }

            MoleculeMx cs = new MoleculeMx(MoleculeFormat.Molfile, molfile);
            cs.GetCoreRGroupInfo(out RgCounts, out RgTotalCount);             // need to redefine these

            RGroupDecomp.Initialize();

            RGroupDecomp.SetAlignStructuresToCore(true);
            RGroupDecomp.SetAllowMultipleCoreMappings(allowMultipleCoreMappings);
            RGroupDecomp.SetIncludeHydrogenFragments(allowHydrogenSubstituents);

            if (DebugMx.True)             // debug
            {
                String  coreSmiles = "[R1]c1cn2c3c(c1= O)cc(c(c3SC(C2)[R4])[R3])[R2]";
                string  coreChime  = "CYAAFQwAUewQeV58YHemfM^EQqPRfIYlJGEkx6M7e4db95jjK5HrNFVP2e1qHphWPL98KvcvrsF7bP9bRcW4QH$si9PXkkuwre6Q5UkHZjciQqeAKVLSHNAeQTAMlkiXEBD$BePpbNQCPD3BkklFEaQqwokeI$FwUoS5cAixQXkMbLTWDaAK7t7cOkSmt3RhwQedbrba6OHKBq3OF4Dhlz$0BfLeKCUUo8ixle176M2aIzXUccTOU8Xy8ARwE3bTyMfjuI3UunZceJf4iZELvsj3PX2MHZG73baUvQGS4DaxUaBGps81PPiDljfvxwFv8OfdOyIRlOBeuEAvk2rT9SRT6oMZIV6UtLFvmCHdwKnu9WtrfV1rEctydNUVxW4qKVlV0rZtpK1oZXuKcv6WVdl6r2hrjVLxBhblTVKO7w1qGRoziquOnPQkKd9H4EQfV0rP6mzI8Au8ulti2fu3YKB94lPXftPGbwr5yA";
                IMolLib coreMol    = MolLibFactory.NewMolLib(MoleculeFormat.Molfile, molfile);
                coreChime = MoleculeMx.MolfileStringToChimeString(molfile);
                molfile   = coreMol.MolfileString;
            }

            CoreMolecule = CdkMol.Util.MolfileStringToMolecule(molfile);
            RGroupDecomp.SetCoreStructure(CoreMolecule, false);

            CoreChemicalStructure = new MoleculeMx(MoleculeFormat.Molfile, molfile);
            StrMatcher            = null;

            int msTime = (int)sw.ElapsedMilliseconds;
            if (RGroupDecomp.Debug)
            {
                DebugLog.Message("Time(ms): " + msTime);
            }

            return;
#endif
        }