Exemple #1
0
        /// <summary>
        /// This function calculates only one solution (exact) because we are looking at the
        /// molecules which are exactly same in terms of the bonds and atoms determined by the
        /// Fingerprint
        /// </summary>
        /// <param name="molecule1"></param>
        /// <param name="molecule2"></param>
        /// <param name="shouldMatchBonds"></param>
        /// <exception cref="CDKException"></exception>
        public void CalculateSubGraphs(IAtomContainer molecule1, IAtomContainer molecule2, bool shouldMatchBonds)
        {
            Source = molecule1;
            Target = molecule2;

            Mappings = new List <IReadOnlyDictionary <int, int> >();

            //Console.Out.WriteLine("Searching: ");
            //List overlaps = UniversalIsomorphismTesterBondTypeInSensitive.GetSubgraphAtomsMap(source, target);

            if ((Source.Atoms.Count == 1) || (Target.Atoms.Count == 1))
            {
                List <CDKRMap> overlaps      = CDKMCS.CheckSingleAtomCases(Source, Target);
                int            nAtomsMatched = overlaps.Count;
                nAtomsMatched = (nAtomsMatched > 0) ? 1 : 0;
                if (nAtomsMatched > 0)
                {
                    IdentifySingleAtomsMatchedParts(overlaps, Source, Target);
                }
            }
            else
            {
                var overlaps = CDKMCS.GetSubgraphMaps(Source, Target, shouldMatchBonds);

                var reducedList    = RemoveSubGraph(overlaps);
                var allMaxOverlaps = GetAllMaximum(reducedList);

                while (allMaxOverlaps.Count != 0)
                {
                    var maxOverlapsAtoms = MakeAtomsMapOfBondsMap(allMaxOverlaps.Peek(), Source,
                                                                  Target);
                    IdentifyMatchedParts(maxOverlapsAtoms, Source, Target);
                    allMaxOverlaps.Pop();
                }
            }
            FinalMappings.Instance.Set(Mappings);
        }
Exemple #2
0
        public void TestSFBug1708336()
        {
            var atomContainer = builder.NewAtomContainer();

            atomContainer.Atoms.Add(builder.NewAtom("C"));
            atomContainer.Atoms.Add(builder.NewAtom("C"));
            atomContainer.Atoms.Add(builder.NewAtom("N"));
            atomContainer.AddBond(atomContainer.Atoms[0], atomContainer.Atoms[1], BondOrder.Single);
            atomContainer.AddBond(atomContainer.Atoms[1], atomContainer.Atoms[2], BondOrder.Single);
            var query = new QueryAtomContainer();
            var a1    = new SymbolQueryAtom()
            {
                Symbol = "C"
            };

            var a2 = new Isomorphisms.Matchers.SMARTS.AnyAtom();
            var b1 = new OrderQueryBond(a1, a2, BondOrder.Single);

            var a3 = new SymbolQueryAtom()
            {
                Symbol = "C"
            };

            var b2 = new OrderQueryBond(a2, a3, BondOrder.Single);

            query.Atoms.Add(a1);
            query.Atoms.Add(a2);
            query.Atoms.Add(a3);

            query.Bonds.Add(b1);
            query.Bonds.Add(b2);

            var list = CDKMCS.GetSubgraphMaps(atomContainer, query, true);

            Assert.IsTrue(list.Count == 0);
        }