Exemplo n.º 1
0
        /// <summary>
        /// This function calculates all the possible combinations of MCS
        /// </summary>
        /// <param name="molecule1"></param>
        /// <param name="molecule2"></param>
        /// <param name="shouldMatchBonds"></param>
        /// <exception cref="CDKException"></exception>
        public void CalculateOverlapsAndReduce(IAtomContainer molecule1, IAtomContainer molecule2, bool shouldMatchBonds)
        {
            Source = molecule1;
            Target = molecule2;

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

            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)
                {
                    /* UnComment this to get one Unique Mapping */
                    //List reducedList = RemoveRedundantMappingsForSingleAtomCase(overlaps);
                    //int counter = 0;
                    IdentifySingleAtomsMatchedParts(overlaps, Source, Target);
                }
            }
            else
            {
                var overlaps       = CDKMCS.Search(Source, Target, new BitArray(Source.Bonds.Count), new BitArray(Target.Bonds.Count), true, true, 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);
        }
Exemplo n.º 2
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 CalculateOverlapsAndReduceExactMatch(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.Search(Source, Target, new BitArray(Source.Bonds.Count), new BitArray(Target.Bonds.Count), true,
                                             true, 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);
        }