Пример #1
0
        /// <summary>
        /// </summary>
        /// <param name="mol"></param>
        /// <param name="mcss"></param>
        /// <param name="shouldMatchBonds"></param>
        /// <returns>IMolecule Set</returns>
        /// <exception cref="CDKException"></exception>
        private static IChemObjectSet <IAtomContainer> GetUncommon(IAtomContainer mol, IAtomContainer mcss, bool shouldMatchBonds)
        {
            List <int> atomSerialsToDelete = new List <int>();

            var matches = CDKMCS.GetSubgraphAtomsMaps(mol, mcss, shouldMatchBonds);
            var mapList = matches[0];

            foreach (var o in mapList)
            {
                CDKRMap rmap = (CDKRMap)o;
                atomSerialsToDelete.Add(rmap.Id1);
            }

            // at this point we have the serial numbers of the bonds to delete
            // we should get the actual bonds rather than delete by serial numbers
            List <IAtom> atomsToDelete = new List <IAtom>();

            foreach (var serial in atomSerialsToDelete)
            {
                atomsToDelete.Add(mol.Atoms[serial]);
            }

            // now lets get rid of the bonds themselves
            foreach (var atom in atomsToDelete)
            {
                mol.RemoveAtomAndConnectedElectronContainers(atom);
            }

            // now we probably have a set of disconnected components
            // so lets get a set of individual atom containers for
            // corresponding to each component
            return(ConnectivityChecker.PartitionIntoMolecules(mol));
        }
Пример #2
0
        public void TestGetSubgraphAtomsMaps_IAtomContainer()
        {
            int[] result1 = { 6, 5, 7, 8, 0 };
            int[] result2 = { 3, 4, 2, 1, 0 };

            var mol   = TestMoleculeFactory.MakeIndole();
            var frag1 = TestMoleculeFactory.MakePyrrole();

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(frag1);
            var adder = CDK.HydrogenAdder;

            adder.AddImplicitHydrogens(mol);
            adder = CDK.HydrogenAdder;
            adder.AddImplicitHydrogens(frag1);
            Aromaticity.CDKLegacy.Apply(mol);
            Aromaticity.CDKLegacy.Apply(frag1);

            var list  = CDKMCS.GetSubgraphAtomsMaps(mol, frag1, true);
            var first = list[0];

            for (int i = 0; i < first.Count; i++)
            {
                CDKRMap rmap = first[i];
                Assert.AreEqual(rmap.Id1, result1[i]);
                Assert.AreEqual(rmap.Id2, result2[i]);
            }
        }
Пример #3
0
        public void TestRMap_int_int()
        {
            CDKRMap node = new CDKRMap(1, 2);

            Assert.IsNotNull(node);
            Assert.AreEqual(1, node.Id1);
            Assert.AreEqual(2, node.Id2);
        }
Пример #4
0
        protected static bool IsSubgraph(IReadOnlyList <CDKRMap> rmaps1, IReadOnlyList <CDKRMap> rmaps2)
        {
            var rmaps2clone = new List <CDKRMap>(rmaps2);

            foreach (var rmap1 in rmaps1)
            {
                bool found = false;
                for (int i = 0; i < rmaps2clone.Count; ++i)
                {
                    CDKRMap rmap2 = rmaps2clone[i];
                    if (IsSameRMap(rmap1, rmap2))
                    {
                        rmaps2clone.RemoveAt(i);
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #5
0
 /// <summary>
 /// Constructor for the RNode object
 /// </summary>
 /// <param name="id1">number of the bond in the graph 1</param>
 /// <param name="id2">number of the bond in the graph 2</param>
 public CDKRNode(int id1, int id2)
 {
     RMap = new CDKRMap(id1, id2);
     // Initialization of Extension and Forbidden is removed
     // Caller must do it.
 }
Пример #6
0
 protected static bool IsSameRMap(CDKRMap sourceRMap, CDKRMap targetRMap)
 {
     return(sourceRMap.Id1 == targetRMap.Id1 && sourceRMap.Id2 == targetRMap.Id2 ? true : false);
 }
Пример #7
0
        /// <summary>
        ///  This makes atom map of matching atoms out of atom map of matching bonds as produced by the Get(Subgraph|Ismorphism)Map methods.
        ///  Added by Asad since CDK one doesn't pick up the correct changes
        /// </summary>
        /// <param name="list">The list produced by the getMap method.</param>
        /// <param name="sourceGraph">first molecule. Must not be an IQueryAtomContainer.</param>
        /// <param name="targetGraph">second molecule. May be an IQueryAtomContainer.</param>
        /// <returns>The mapping found projected on sourceGraph. This is atom List of CDKRMap objects containing Ids of matching atoms.</returns>
        private static IReadOnlyList <IReadOnlyList <CDKRMap> > MakeAtomsMapOfBondsMapSingleBond(IReadOnlyList <CDKRMap> list, IAtomContainer sourceGraph, IAtomContainer targetGraph)
        {
            if (list == null)
            {
                return(null);
            }
            var bondMap = new Dictionary <IBond, IBond>(list.Count);

            foreach (var solBondMap in list)
            {
                var id1   = solBondMap.Id1;
                var id2   = solBondMap.Id2;
                var qBond = sourceGraph.Bonds[id1];
                var tBond = targetGraph.Bonds[id2];
                bondMap[qBond] = tBond;
            }
            var result1 = new List <CDKRMap>();
            var result2 = new List <CDKRMap>();

            foreach (var qbond in sourceGraph.Bonds)
            {
                if (bondMap.ContainsKey(qbond))
                {
                    var     tbond = bondMap[qbond];
                    CDKRMap map00 = null;
                    CDKRMap map01 = null;
                    CDKRMap map10 = null;
                    CDKRMap map11 = null;

                    if (string.Equals(qbond.Atoms[0].Symbol, tbond.Atoms[0].Symbol, StringComparison.Ordinal) &&
                        string.Equals(qbond.Atoms[1].Symbol, tbond.Atoms[1].Symbol, StringComparison.Ordinal))
                    {
                        map00 = new CDKRMap(sourceGraph.Atoms.IndexOf(qbond.Atoms[0]), targetGraph.Atoms.IndexOf(tbond.Atoms[0]));
                        map11 = new CDKRMap(sourceGraph.Atoms.IndexOf(qbond.Atoms[1]), targetGraph.Atoms.IndexOf(tbond.Atoms[1]));
                        if (!result1.Contains(map00))
                        {
                            result1.Add(map00);
                        }
                        if (!result1.Contains(map11))
                        {
                            result1.Add(map11);
                        }
                    }
                    if (string.Equals(qbond.Atoms[0].Symbol, tbond.Atoms[1].Symbol, StringComparison.Ordinal) &&
                        string.Equals(qbond.Atoms[1].Symbol, tbond.Atoms[0].Symbol, StringComparison.Ordinal))
                    {
                        map01 = new CDKRMap(sourceGraph.Atoms.IndexOf(qbond.Atoms[0]), targetGraph.Atoms.IndexOf(tbond.Atoms[1]));
                        map10 = new CDKRMap(sourceGraph.Atoms.IndexOf(qbond.Atoms[1]), targetGraph.Atoms.IndexOf(tbond.Atoms[0]));
                        if (!result2.Contains(map01))
                        {
                            result2.Add(map01);
                        }
                        if (!result2.Contains(map10))
                        {
                            result2.Add(map10);
                        }
                    }
                }
            }
            var result = new List <IReadOnlyList <CDKRMap> >();

            if (result1.Count == result2.Count)
            {
                result.Add(result1);
                result.Add(result2);
            }
            else if (result1.Count > result2.Count)
            {
                result.Add(result1);
            }
            else
            {
                result.Add(result2);
            }
            return(result);
        }
Пример #8
0
        /// <summary>
        ///  This makes sourceAtom map of matching atoms out of sourceAtom map of matching bonds as produced by the Get(Subgraph|Ismorphism)Map methods.
        /// </summary>
        /// <param name="rMapList">The list produced by the getMap method.</param>
        /// <param name="graph1">first molecule. Must not be an IQueryAtomContainer.</param>
        /// <param name="graph2">second molecule. May be an IQueryAtomContainer.</param>
        /// <returns>The mapping found projected on graph1. This is sourceAtom List of CDKRMap objects containing Ids of matching atoms.</returns>
        private static IReadOnlyList <IReadOnlyList <CDKRMap> > MakeAtomsMapOfBondsMap(IReadOnlyList <CDKRMap> rMapList, IAtomContainer graph1, IAtomContainer graph2)
        {
            if (rMapList == null)
            {
                return(null);
            }
            IReadOnlyList <IReadOnlyList <CDKRMap> > result = null;

            if (rMapList.Count == 1)
            {
                result = MakeAtomsMapOfBondsMapSingleBond(rMapList, graph1, graph2);
            }
            else
            {
                List <CDKRMap> resultLocal = new List <CDKRMap>();
                for (int i = 0; i < rMapList.Count; i++)
                {
                    IBond   qBond  = graph1.Bonds[rMapList[i].Id1];
                    IBond   tBond  = graph2.Bonds[rMapList[i].Id2];
                    IAtom[] qAtoms = BondManipulator.GetAtomArray(qBond);
                    IAtom[] tAtoms = BondManipulator.GetAtomArray(tBond);
                    for (int j = 0; j < 2; j++)
                    {
                        var bondsConnectedToAtom1j = graph1.GetConnectedBonds(qAtoms[j]);
                        foreach (var bondConnectedToAtom1j in bondsConnectedToAtom1j)
                        {
                            if (bondConnectedToAtom1j != qBond)
                            {
                                IBond testBond = bondConnectedToAtom1j;
                                foreach (var rMap in rMapList)
                                {
                                    IBond testBond2;
                                    if ((rMap).Id1 == graph1.Bonds.IndexOf(testBond))
                                    {
                                        testBond2 = graph2.Bonds[(rMap).Id2];
                                        for (int n = 0; n < 2; n++)
                                        {
                                            var bondsToTest = graph2.GetConnectedBonds(tAtoms[n]);
                                            if (bondsToTest.Contains(testBond2))
                                            {
                                                CDKRMap map;
                                                if (j == n)
                                                {
                                                    map = new CDKRMap(graph1.Atoms.IndexOf(qAtoms[0]),
                                                                      graph2.Atoms.IndexOf(tAtoms[0]));
                                                }
                                                else
                                                {
                                                    map = new CDKRMap(graph1.Atoms.IndexOf(qAtoms[1]),
                                                                      graph2.Atoms.IndexOf(tAtoms[0]));
                                                }
                                                if (!resultLocal.Contains(map))
                                                {
                                                    resultLocal.Add(map);
                                                }
                                                CDKRMap map2;
                                                if (j == n)
                                                {
                                                    map2 = new CDKRMap(graph1.Atoms.IndexOf(qAtoms[1]),
                                                                       graph2.Atoms.IndexOf(tAtoms[1]));
                                                }
                                                else
                                                {
                                                    map2 = new CDKRMap(graph1.Atoms.IndexOf(qAtoms[0]),
                                                                       graph2.Atoms.IndexOf(tAtoms[1]));
                                                }
                                                if (!resultLocal.Contains(map2))
                                                {
                                                    resultLocal.Add(map2);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                result = new List <IReadOnlyList <CDKRMap> >
                {
                    resultLocal
                };
            }
            return(result);
        }