private IList <int> FindMcGregorMapping(List <int> mArcs, McgregorHelper mcGregorHelper) { int neighborBondNumA = mcGregorHelper.NeighborBondNumA; int neighborBondNumB = mcGregorHelper.NeighborBondNumB; List <int> currentMapping = new List <int>(mcGregorHelper.GetMappedAtomsOrg()); List <int> additionalMapping = new List <int>(); for (int x = 0; x < neighborBondNumA; x++) { for (int y = 0; y < neighborBondNumB; y++) { if (mArcs[x * neighborBondNumB + y] == 1) { ExtendMapping(x, y, mcGregorHelper, additionalMapping, currentMapping); } } } int additionalMappingSize = additionalMapping.Count; //add McGregorBondTypeInSensitive mapping to the Clique mapping for (int a = 0; a < additionalMappingSize; a += 2) { currentMapping.Add(additionalMapping[a + 0]); currentMapping.Add(additionalMapping[a + 1]); } // remove recurring mappings from currentMapping var uniqueMapping = McGregorChecks.RemoveRecurringMappings(currentMapping); return(uniqueMapping); }
private void Partsearch(int xstart, int ystart, IList <int> tempMArcsOrg, McgregorHelper mcGregorHelper) { int neighborBondNumA = mcGregorHelper.NeighborBondNumA; int neighborBondNumB = mcGregorHelper.NeighborBondNumB; int xIndex = xstart; int yIndex = ystart; List <int> tempMArcs = new List <int>(tempMArcsOrg); if (tempMArcs[xstart * neighborBondNumB + ystart] == 1) { McGregorChecks.RemoveRedundantArcs(xstart, ystart, tempMArcs, mcGregorHelper); int arcsleft = McGregorChecks.CountArcsLeft(tempMArcs, neighborBondNumA, neighborBondNumB); //test Best arcs left and skip rest if needed if (arcsleft >= bestarcsleft) { SetArcs(xIndex, yIndex, arcsleft, tempMArcs, mcGregorHelper); } } else { do { yIndex++; if (yIndex == neighborBondNumB) { yIndex = 0; xIndex++; } } while ((xIndex < neighborBondNumA) && (tempMArcs[xIndex * neighborBondNumB + yIndex] != 1)); //Correction by ASAD set value minus 1 if (xIndex < neighborBondNumA) { Partsearch(xIndex, yIndex, tempMArcs, mcGregorHelper); tempMArcs[xIndex * neighborBondNumB + yIndex] = 0; Partsearch(xIndex, yIndex, tempMArcs, mcGregorHelper); } else { int arcsleft = McGregorChecks.CountArcsLeft(tempMArcs, neighborBondNumA, neighborBondNumB); if (arcsleft >= bestarcsleft) { PopBestArcs(arcsleft); if (CheckmArcs(tempMArcs, neighborBondNumA, neighborBondNumB)) { bestArcs.Push(tempMArcs); } } } } }
internal static bool IsFurtherMappingPossible(IAtomContainer source, IAtomContainer target, McgregorHelper mcGregorHelper, bool shouldMatchBonds) { int neighborBondNumA = mcGregorHelper.NeighborBondNumA; int neighborBondNumB = mcGregorHelper.NeighborBondNumB; var iBondNeighborAtomsA = mcGregorHelper.GetIBondNeighborAtomsA(); var iBondNeighborAtomsB = mcGregorHelper.GetIBondNeighborAtomsB(); var cBondNeighborsA = mcGregorHelper.GetCBondNeighborsA(); var cBondNeighborsB = mcGregorHelper.GetCBondNeighborsB(); for (int row = 0; row < neighborBondNumA; row++) { // Console.Out.WriteLine("i " + row); string g1A = cBondNeighborsA[row * 4 + 0]; string g2A = cBondNeighborsA[row * 4 + 1]; for (int column = 0; column < neighborBondNumB; column++) { string g1B = cBondNeighborsB[column * 4 + 0]; string g2B = cBondNeighborsB[column * 4 + 1]; if (IsAtomMatch(g1A, g2A, g1B, g2B)) { try { int indexI = iBondNeighborAtomsA[row * 3 + 0]; int indexIPlus1 = iBondNeighborAtomsA[row * 3 + 1]; int indexJ = iBondNeighborAtomsB[column * 3 + 0]; int indexJPlus1 = iBondNeighborAtomsB[column * 3 + 1]; IAtom r1A = source.Atoms[indexI]; IAtom r2A = source.Atoms[indexIPlus1]; IBond reactantBond = source.GetBond(r1A, r2A); IAtom p1B = target.Atoms[indexJ]; IAtom p2B = target.Atoms[indexJPlus1]; IBond productBond = target.GetBond(p1B, p2B); if (IsMatchFeasible(source, reactantBond, target, productBond, shouldMatchBonds)) { return(true); } } catch (Exception e) { Console.Out.WriteLine(e.StackTrace); } } } } return(false); }
private int Iterator(McgregorHelper mcGregorHelper) { bool mappingCheckFlag = mcGregorHelper.IsMappingCheckFlag; int mappedAtomCount = mcGregorHelper.MappedAtomCount; List <int> mappedAtoms = new List <int>(mcGregorHelper.GetMappedAtomsOrg()); int neighborBondNumA = mcGregorHelper.NeighborBondNumA; int neighborBondNumB = mcGregorHelper.NeighborBondNumB; // //check possible mappings: bool furtherMappingFlag = McGregorChecks.IsFurtherMappingPossible(source, target, mcGregorHelper, IsBondMatch); if (neighborBondNumA == 0 || neighborBondNumB == 0 || mappingCheckFlag || !furtherMappingFlag) { SetFinalMappings(mappedAtoms, mappedAtomCount); return(0); } modifiedARCS.Clear(); int size = neighborBondNumA * neighborBondNumB; for (int i = 0; i < size; i++) { modifiedARCS.Insert(i, 0); } SetModifedArcs(mcGregorHelper); first = new BinaryTree(-1); last = first; last.Equal = null; last.NotEqual = null; bestarcsleft = 0; Startsearch(mcGregorHelper); var bestArcsCopy = new Stack <IReadOnlyList <int> >(); foreach (var bestArc in bestArcs) { bestArcsCopy.Push(bestArc); } while (bestArcs.Count != 0) { bestArcs.Pop(); } SearchAndExtendMappings(bestArcsCopy, mcGregorHelper); //Console.Out.WriteLine("In the iterator Termination"); //Console.Out.WriteLine("============+++++++++=============="); //Console.Out.WriteLine("Mapped Atoms before iterator Over: " + mappedAtoms); return(0); }
private void ExtendMapping(int xIndex, int yIndex, McgregorHelper mcGregorHelper, List <int> additionalMapping, List <int> currentMapping) { int atom1MoleculeA = mcGregorHelper.GetIBondNeighborAtomsA()[xIndex * 3 + 0]; int atom2MoleculeA = mcGregorHelper.GetIBondNeighborAtomsA()[xIndex * 3 + 1]; int atom1MoleculeB = mcGregorHelper.GetIBondNeighborAtomsB()[yIndex * 3 + 0]; int atom2MoleculeB = mcGregorHelper.GetIBondNeighborAtomsB()[yIndex * 3 + 1]; IAtom r1A = source.Atoms[atom1MoleculeA]; IAtom r2A = source.Atoms[atom2MoleculeA]; IBond reactantBond = source.GetBond(r1A, r2A); IAtom p1B = target.Atoms[atom1MoleculeB]; IAtom p2B = target.Atoms[atom2MoleculeB]; IBond productBond = target.GetBond(p1B, p2B); // Bond Order Check Introduced by Asad if (McGregorChecks.IsMatchFeasible(source, reactantBond, target, productBond, IsBondMatch)) { for (int indexZ = 0; indexZ < mcGregorHelper.MappedAtomCount; indexZ++) { int mappedAtom1 = currentMapping[indexZ * 2 + 0]; int mappedAtom2 = currentMapping[indexZ * 2 + 1]; if ((mappedAtom1 == atom1MoleculeA) && (mappedAtom2 == atom1MoleculeB)) { additionalMapping.Add(atom2MoleculeA); additionalMapping.Add(atom2MoleculeB); } else if ((mappedAtom1 == atom1MoleculeA) && (mappedAtom2 == atom2MoleculeB)) { additionalMapping.Add(atom2MoleculeA); additionalMapping.Add(atom1MoleculeB); } else if ((mappedAtom1 == atom2MoleculeA) && (mappedAtom2 == atom1MoleculeB)) { additionalMapping.Add(atom1MoleculeA); additionalMapping.Add(atom2MoleculeB); } else if ((mappedAtom1 == atom2MoleculeA) && (mappedAtom2 == atom2MoleculeB)) { additionalMapping.Add(atom1MoleculeA); additionalMapping.Add(atom1MoleculeB); } }//for loop } }
private void Startsearch(McgregorHelper mcGregorHelper) { int neighborBondNumA = mcGregorHelper.NeighborBondNumA; int neighborBondNumB = mcGregorHelper.NeighborBondNumB; int size = neighborBondNumA * neighborBondNumB; List <int> fixArcs = new List <int>(size);// Initialize fixArcs with 0 for (int i = 0; i < size; i++) { fixArcs.Insert(i, 0); } int xIndex = 0; int yIndex = 0; while ((xIndex < neighborBondNumA) && (modifiedARCS[xIndex * neighborBondNumB + yIndex] != 1)) { yIndex++; if (yIndex == neighborBondNumB) { yIndex = 0; xIndex++; } } if (xIndex == neighborBondNumA) { yIndex = neighborBondNumB - 1; xIndex -= 1; } if (modifiedARCS[xIndex * neighborBondNumB + yIndex] == 0) { Partsearch(xIndex, yIndex, modifiedARCS, mcGregorHelper); } if (modifiedARCS[xIndex * neighborBondNumB + yIndex] != 0) { Partsearch(xIndex, yIndex, modifiedARCS, mcGregorHelper); modifiedARCS[xIndex * neighborBondNumB + yIndex] = 0; Partsearch(xIndex, yIndex, modifiedARCS, mcGregorHelper); } }
private void SetModifedArcs(McgregorHelper mcGregorHelper) { int neighborBondNumA = mcGregorHelper.NeighborBondNumA; int neighborBondNumB = mcGregorHelper.NeighborBondNumB; var iBondNeighborAtomsA = mcGregorHelper.GetIBondNeighborAtomsA(); var iBondNeighborAtomsB = mcGregorHelper.GetIBondNeighborAtomsB(); var cBondNeighborsA = mcGregorHelper.GetCBondNeighborsA(); var cBondNeighborsB = mcGregorHelper.GetCBondNeighborsB(); for (int row = 0; row < neighborBondNumA; row++) { for (int column = 0; column < neighborBondNumB; column++) { string g1A = cBondNeighborsA[row * 4 + 0]; string g2A = cBondNeighborsA[row * 4 + 1]; string g1B = cBondNeighborsB[column * 4 + 0]; string g2B = cBondNeighborsB[column * 4 + 1]; if (MatchGAtoms(g1A, g2A, g1B, g2B)) { int indexI = iBondNeighborAtomsA[row * 3 + 0]; int indexIPlus1 = iBondNeighborAtomsA[row * 3 + 1]; IAtom r1A = source.Atoms[indexI]; IAtom r2A = source.Atoms[indexIPlus1]; IBond reactantBond = source.GetBond(r1A, r2A); int indexJ = iBondNeighborAtomsB[column * 3 + 0]; int indexJPlus1 = iBondNeighborAtomsB[column * 3 + 1]; IAtom p1B = target.Atoms[indexJ]; IAtom p2B = target.Atoms[indexJPlus1]; IBond productBond = target.GetBond(p1B, p2B); if (McGregorChecks.IsMatchFeasible(source, reactantBond, target, productBond, IsBondMatch)) { modifiedARCS[row * neighborBondNumB + column] = 1; } } } } }
private void SetArcs(int xIndex, int yIndex, int arcsleft, List <int> tempMArcs, McgregorHelper mcGregorHelper) { int neighborBondNumA = mcGregorHelper.NeighborBondNumA; int neighborBondNumB = mcGregorHelper.NeighborBondNumB; do { yIndex++; if (yIndex == neighborBondNumB) { yIndex = 0; xIndex++; } } //Correction by ASAD set value minus 1 while ((xIndex < neighborBondNumA) && (tempMArcs[xIndex * neighborBondNumB + yIndex] != 1)); if (xIndex < neighborBondNumA) { Partsearch(xIndex, yIndex, tempMArcs, mcGregorHelper); tempMArcs[xIndex * neighborBondNumB + yIndex] = 0; Partsearch(xIndex, yIndex, tempMArcs, mcGregorHelper); } else { PopBestArcs(arcsleft); if (CheckmArcs(tempMArcs, neighborBondNumA, neighborBondNumB)) { bestArcs.Push(tempMArcs); } } }
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!!!!"); } }
/// <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); }
/// <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); }
/// <summary> /// The function is called in function partsearch. The function is given a temporary matrix and a position (row/column) /// within this matrix. First the function sets all entries to zero, which can be exlcuded in respect to the current /// atom by atom matching. After this the function replaces all entries in the same row and column of the current /// position by zeros. Only the entry of the current position is set to one. /// Return value "count_arcsleft" counts the number of arcs, which are still in the matrix. /// </summary> internal static void RemoveRedundantArcs(int row, int column, IList <int> marcs, McgregorHelper mcGregorHelper) { int neighborBondNumA = mcGregorHelper.NeighborBondNumA; int neighborBondNumB = mcGregorHelper.NeighborBondNumB; var iBondNeighborAtomsA = mcGregorHelper.GetIBondNeighborAtomsA(); var iBondNeighborAtomsB = mcGregorHelper.GetIBondNeighborAtomsB(); int g1Atom = iBondNeighborAtomsA[row * 3 + 0]; int g2Atom = iBondNeighborAtomsA[row * 3 + 1]; int g3Atom = iBondNeighborAtomsB[column * 3 + 0]; int g4Atom = iBondNeighborAtomsB[column * 3 + 1]; for (int x = 0; x < neighborBondNumA; x++) { int rowAtom1 = iBondNeighborAtomsA[x * 3 + 0]; int rowAtom2 = iBondNeighborAtomsA[x * 3 + 1]; for (int y = 0; y < neighborBondNumB; y++) { int columnAtom3 = iBondNeighborAtomsB[y * 3 + 0]; int columnAtom4 = iBondNeighborAtomsB[y * 3 + 1]; if (McGregorChecks.Cases(g1Atom, g2Atom, g3Atom, g4Atom, rowAtom1, rowAtom2, columnAtom3, columnAtom4)) { marcs[x * neighborBondNumB + y] = 0; } } } for (int v = 0; v < neighborBondNumA; v++) { marcs[v * neighborBondNumB + column] = 0; } for (int w = 0; w < neighborBondNumB; w++) { marcs[row * neighborBondNumB + w] = 0; } marcs[row * neighborBondNumB + column] = 1; }