Example #1
0
        /// <summary>
        /// Start McGregor search and extend the mappings if possible.
        /// </summary>
        /// <param name="largestMappingSize"></param>
        /// <param name="cliqueVector"></param>
        /// <param name="compGraphNodes"></param>
        /// <exception cref="IOException"></exception>
        public void StartMcGregorIteration(int largestMappingSize,
                                           IReadOnlyList <int> cliqueVector,
                                           IReadOnlyList <int> compGraphNodes)
        {
            this.globalMCSSize = (largestMappingSize / 2);
            List <string> cTab1Copy = McGregorChecks.GenerateCTabCopy(source);

            List <string> cTab2Copy = McGregorChecks.GenerateCTabCopy(target);

            //find mapped atoms of both molecules and store these in mappedAtoms
            List <int> mappedAtoms = new List <int>();

            int mappedAtomCount = 0;

            List <int> iBondNeighborAtomsA = new List <int>();
            var        cBondNeighborsA     = new List <string>();

            List <int> iBondSetA = new List <int>();
            var        cBondSetA = new List <string>();

            List <int> iBondNeighborAtomsB = new List <int>();
            List <int> iBondSetB           = new List <int>();
            var        cBondNeighborsB     = new List <string>();
            var        cBondSetB           = new List <string>();

            int cliqueSize = cliqueVector.Count;
            int vecSize    = compGraphNodes.Count;

            int cliqueNumber = 0;

            for (int a = 0; a < cliqueSize; a++)
            {
                //go through all clique nodes
                cliqueNumber = cliqueVector[a];
                for (int b = 0; b < vecSize; b += 3)
                {
                    //go through all nodes in the compatibility graph
                    if (cliqueNumber == compGraphNodes[b + 2])
                    {
                        mappedAtoms.Add(compGraphNodes[b]);
                        mappedAtoms.Add(compGraphNodes[b + 1]);
                        mappedAtomCount++;
                    }
                }
            }

            //find unmapped atoms of molecule A
            List <int> unmappedAtomsMolA = McGregorChecks.MarkUnMappedAtoms(true, source, mappedAtoms, cliqueSize);

            int counter = 0;
            int setNumA = 0;
            int setNumB = 0;
            int localNeighborBondnumA = 0; //number of remaining molecule A bonds after the clique search, which are neighbors of the MCS_1
            int localNeighborBondNumB = 0; //number of remaining molecule B bonds after the clique search, which are neighbors of the MCS_1

            //Extract bonds which are related with unmapped atoms of molecule A.
            //In case that unmapped atoms are connected with already mapped atoms, the mapped atoms are labelled with
            //new special signs -> the result are two vectors: cBondNeighborsA and int_bonds_molA, which contain those
            //bonds of molecule A, which are relevant for the McGregorBondTypeInSensitive algorithm.
            //The special signs must be transfered to the corresponding atoms of molecule B

            QueryProcessor queryProcess = new QueryProcessor(cTab1Copy, cTab2Copy, SIGNS, localNeighborBondnumA,
                                                             setNumA, iBondNeighborAtomsA, cBondNeighborsA, cliqueSize, iBondSetA, cBondSetA);

            queryProcess.Process(source, target, unmappedAtomsMolA, mappedAtoms, counter);

            cTab1Copy             = queryProcess.CTab1;
            cTab2Copy             = queryProcess.CTab2;
            setNumA               = queryProcess.BondNumA;
            localNeighborBondnumA = queryProcess.NeighborBondNumA;
            iBondNeighborAtomsA   = queryProcess.IBondNeighboursA;
            cBondNeighborsA       = queryProcess.CBondNeighborsA;

            //find unmapped atoms of molecule B
            List <int> unmappedAtomsMolB = McGregorChecks.MarkUnMappedAtoms(false, target, mappedAtoms, cliqueSize);

            //Extract bonds which are related with unmapped atoms of molecule B.
            //In case that unmapped atoms are connected with already mapped atoms, the mapped atoms are labelled with
            //new special signs -> the result are two vectors: cBondNeighborsA and int_bonds_molB, which contain those
            //bonds of molecule B, which are relevant for the McGregorBondTypeInSensitive algorithm.
            //The special signs must be transfered to the corresponding atoms of molecule A

            TargetProcessor targetProcess = new TargetProcessor(cTab1Copy, cTab2Copy, SIGNS, localNeighborBondNumB,
                                                                setNumB, iBondNeighborAtomsB, cBondNeighborsB, localNeighborBondnumA, iBondNeighborAtomsA,
                                                                cBondNeighborsA);

            targetProcess.Process(target, unmappedAtomsMolB, cliqueSize, iBondSetB, cBondSetB, mappedAtoms, counter);

            cTab1Copy             = targetProcess.CTab1;
            cTab2Copy             = targetProcess.CTab2;
            setNumB               = targetProcess.BondNumB;
            localNeighborBondNumB = targetProcess.NeighborBondNumB;
            iBondNeighborAtomsB   = targetProcess.IBondNeighboursB;
            cBondNeighborsB       = targetProcess.CBondNeighborsB;

            bool dummy = false;

            McgregorHelper mcGregorHelper = new McgregorHelper(dummy, mappedAtomCount, mappedAtoms, localNeighborBondnumA,
                                                               localNeighborBondNumB, iBondNeighborAtomsA, iBondNeighborAtomsB, cBondNeighborsA, cBondNeighborsB,
                                                               setNumA, setNumB, iBondSetA, iBondSetB, cBondSetA, cBondSetB);

            Iterator(mcGregorHelper);
        }
Example #2
0
        private void SearchAndExtendMappings(Stack <IReadOnlyList <int> > bestarcsCopy, McgregorHelper mcGregorHelper)
        {
            int mappedAtomCount = mcGregorHelper.MappedAtomCount;

            int setNumA   = mcGregorHelper.SetNumA;
            int setNumB   = mcGregorHelper.SetNumB;
            var iBondSetA = mcGregorHelper.GetIBondSetA();
            var iBondSetB = mcGregorHelper.GetIBondSetB();
            var cBondSetA = mcGregorHelper.GetCBondSetA();
            var cBondSetB = mcGregorHelper.GetCBondSetB();

            while (bestarcsCopy.Count != 0)
            {
                var mArcsVector = new List <int>(bestarcsCopy.Peek());
                var newMapping  = FindMcGregorMapping(mArcsVector, mcGregorHelper);

                int  newMapingSize     = newMapping.Count / 2;
                bool noFurtherMappings = false;
                if (mappedAtomCount == newMapingSize)
                {
                    noFurtherMappings = true;
                }

                List <int> newINeighborsA = new List <int>();    //instead of iBondNeighborAtomsA
                List <int> newINeighborsB = new List <int>();    //instead of iBondNeighborAtomsB
                var        newCNeighborsA = new List <string>(); //instead of cBondNeighborsA
                var        newCNeighborsB = new List <string>(); //instead of cBondNeighborsB
                List <int> newIBondSetA   = new List <int>();    //instead of iBondSetA
                List <int> newIBondSetB   = new List <int>();    //instead of iBondSetB
                var        newCBondSetA   = new List <string>(); //instead of cBondSetA
                var        newCBondSetB   = new List <string>(); //instead of cBondSetB
                //new values for setNumA + setNumB
                //new arrays for iBondSetA + iBondSetB + cBondSetB + cBondSetB

                List <string> cSetACopy = McGregorChecks.GenerateCSetCopy(setNumA, cBondSetA);
                List <string> cSetBCopy = McGregorChecks.GenerateCSetCopy(setNumB, cBondSetB);

                //find unmapped atoms of molecule A
                List <int> unmappedAtomsMolA = new List <int>();
                int        unmappedNumA      = 0;
                bool       atomAIsUnmapped   = true;

                for (int a = 0; a < source.Atoms.Count; a++)
                {
                    for (int b = 0; b < newMapingSize; b++)
                    {
                        if (a == newMapping[b * 2 + 0])
                        {
                            atomAIsUnmapped = false;
                        }
                    }
                    if (atomAIsUnmapped)
                    {
                        unmappedAtomsMolA.Insert(unmappedNumA++, a);
                    }
                    atomAIsUnmapped = true;
                }

                //The special signs must be transfered to the corresponding atoms of molecule B

                int counter = 0;
                //number of remaining molecule A bonds after the clique search, which aren't neighbors
                int newSetBondNumA  = 0; //instead of setNumA
                int newNeighborNumA = 0; //instead of localNeighborBondnumA

                QueryProcessor queryProcess = new QueryProcessor(cSetACopy, cSetBCopy, SIGNS, newNeighborNumA,
                                                                 newSetBondNumA, newINeighborsA, newCNeighborsA, newMapingSize, newIBondSetA, newCBondSetA);

                queryProcess.Process(setNumA, setNumB, iBondSetA, iBondSetB, unmappedAtomsMolA, newMapping, counter);

                cSetACopy       = queryProcess.CTab1;
                cSetBCopy       = queryProcess.CTab2;
                newSetBondNumA  = queryProcess.BondNumA;
                newNeighborNumA = queryProcess.NeighborBondNumA;
                newINeighborsA  = queryProcess.IBondNeighboursA;
                newCNeighborsA  = queryProcess.CBondNeighborsA;

                //find unmapped atoms of molecule B

                List <int> unmappedAtomsMolB = new List <int>();
                int        unmappedNumB      = 0;
                bool       atomBIsUnmapped   = true;

                for (int a = 0; a < target.Atoms.Count; a++)
                {
                    for (int b = 0; b < newMapingSize; b++)
                    {
                        if (a == newMapping[b * 2 + 1])
                        {
                            atomBIsUnmapped = false;
                        }
                    }
                    if (atomBIsUnmapped)
                    {
                        unmappedAtomsMolB.Insert(unmappedNumB++, a);
                    }
                    atomBIsUnmapped = true;
                }

                //number of remaining molecule B bonds after the clique search, which aren't neighbors
                int newSetBondNumB  = 0; //instead of setNumB
                int newNeighborNumB = 0; //instead of localNeighborBondNumB

                TargetProcessor targetProcess = new TargetProcessor(cSetACopy, cSetBCopy, SIGNS, newNeighborNumB,
                                                                    newSetBondNumB, newINeighborsB, newCNeighborsB, newNeighborNumA, newINeighborsA,
                                                                    newCNeighborsA);

                targetProcess.Process(setNumB, unmappedAtomsMolB, newMapingSize, iBondSetB, cBondSetB, newMapping,
                                      counter, newIBondSetB, newCBondSetB);

                cSetACopy       = targetProcess.CTab1;
                cSetBCopy       = targetProcess.CTab2;
                newSetBondNumB  = targetProcess.BondNumB;
                newNeighborNumB = targetProcess.NeighborBondNumB;
                newINeighborsB  = targetProcess.IBondNeighboursB;
                newCNeighborsB  = targetProcess.CBondNeighborsB;

                //             Console.Out.WriteLine("Mapped Atoms before Iterator2: " + mappedAtoms);
                McgregorHelper newMH = new McgregorHelper(noFurtherMappings, newMapingSize, newMapping, newNeighborNumA,
                                                          newNeighborNumB, newINeighborsA, newINeighborsB, newCNeighborsA, newCNeighborsB,
                                                          newSetBondNumA, newSetBondNumB, newIBondSetA, newIBondSetB, newCBondSetA, newCBondSetB);

                Iterator(newMH);
                bestarcsCopy.Pop();
                //            Console.Out.WriteLine("End of the iterator!!!!");
            }
        }
Example #3
0
        /// <summary>
        /// Start McGregor search and extend the mappings if possible.
        /// </summary>
        /// <param name="largestMappingSize"></param>
        /// <param name="presentMapping"></param>
        /// <exception cref="IOException"></exception>
        public void StartMcGregorIteration(int largestMappingSize, IReadOnlyDictionary <int, int> presentMapping)
        {
            this.globalMCSSize = (largestMappingSize / 2);
            var cTab1Copy = McGregorChecks.GenerateCTabCopy(source);
            var cTab2Copy = McGregorChecks.GenerateCTabCopy(target);

            //find mapped atoms of both molecules and store these in mappedAtoms
            List <int> mappedAtoms = new List <int>();

            //        Console.Out.WriteLine("\nMapped Atoms");
            foreach (var map in presentMapping)
            {
                //            Console.Out.WriteLine("i:" + map.Key + " j:" + map.Value);
                mappedAtoms.Add(map.Key);
                mappedAtoms.Add(map.Value);
            }
            int mappingSize = presentMapping.Count;

            List <int> iBondNeighborsA = new List <int>();
            var        cBondNeighborsA = new List <string>();

            List <int> iBondSetA = new List <int>();
            var        cBondSetA = new List <string>();

            List <int> iBondNeighborsB = new List <int>();
            List <int> iBondSetB       = new List <int>();
            var        cBondNeighborsB = new List <string>();
            var        cBondSetB       = new List <string>();

            //find unmapped atoms of molecule A

            List <int> unmappedAtomsMolA = McGregorChecks.MarkUnMappedAtoms(true, source, presentMapping);
            int        counter           = 0;
            int        gSetBondNumA      = 0;
            int        gSetBondNumB      = 0;
            int        gNeighborBondnumA = 0; //number of remaining molecule A bonds after the clique search, which are neighbors of the MCS_1
            int        gNeighborBondNumB = 0; //number of remaining molecule B bonds after the clique search, which are neighbors of the MCS_1

            QueryProcessor queryProcess = new QueryProcessor(cTab1Copy, cTab2Copy, SIGNS, gNeighborBondnumA,
                                                             gSetBondNumA, iBondNeighborsA, cBondNeighborsA, mappingSize, iBondSetA, cBondSetA);

            if (!(source is IQueryAtomContainer))
            {
                queryProcess.Process(source, target, unmappedAtomsMolA, mappedAtoms, counter);
            }
            else
            {
                queryProcess.Process((IQueryAtomContainer)source, target, unmappedAtomsMolA, mappedAtoms, counter);
            }

            cTab1Copy         = queryProcess.CTab1;
            cTab2Copy         = queryProcess.CTab2;
            gSetBondNumA      = queryProcess.BondNumA;
            gNeighborBondnumA = queryProcess.NeighborBondNumA;
            iBondNeighborsA   = queryProcess.IBondNeighboursA;
            cBondNeighborsA   = queryProcess.CBondNeighborsA;

            //find unmapped atoms of molecule B
            List <int> unmappedAtomsMolB = McGregorChecks.MarkUnMappedAtoms(false, target, presentMapping);

            //        Console.Out.WriteLine("unmappedAtomsMolB: " + unmappedAtomsMolB.Count);

            //Extract bonds which are related with unmapped atoms of molecule B.
            //In case that unmapped atoms are connected with already mapped atoms, the mapped atoms are labelled with
            //new special signs -> the result are two vectors: cBondNeighborsA and int_bonds_molB, which contain those
            //bonds of molecule B, which are relevant for the McGregorBondTypeInSensitive algorithm.
            //The special signs must be transfered to the corresponding atoms of molecule A

            TargetProcessor targetProcess = new TargetProcessor(cTab1Copy, cTab2Copy, SIGNS, gNeighborBondNumB,
                                                                gSetBondNumB, iBondNeighborsB, cBondNeighborsB, gNeighborBondnumA, iBondNeighborsA,
                                                                cBondNeighborsA);

            targetProcess.Process(target, unmappedAtomsMolB, mappingSize, iBondSetB, cBondSetB, mappedAtoms,
                                  counter);

            cTab1Copy         = targetProcess.CTab1;
            cTab2Copy         = targetProcess.CTab2;
            gSetBondNumB      = targetProcess.BondNumB;
            gNeighborBondNumB = targetProcess.NeighborBondNumB;
            iBondNeighborsB   = targetProcess.IBondNeighboursB;
            cBondNeighborsB   = targetProcess.CBondNeighborsB;

            bool dummy = false;

            McgregorHelper mcGregorHelper = new McgregorHelper(dummy, presentMapping.Count, mappedAtoms,
                                                               gNeighborBondnumA, gNeighborBondNumB, iBondNeighborsA, iBondNeighborsB, cBondNeighborsA,
                                                               cBondNeighborsB, gSetBondNumA, gSetBondNumB, iBondSetA, iBondSetB, cBondSetA, cBondSetB);

            Iterator(mcGregorHelper);
        }