public void TestIsolated()
        {
            var search   = new RingSearch(hexaphenylene);
            var isolated = search.Isolated();

            Assert.AreEqual(0, isolated.Length);
        }
Exemple #2
0
        public void TestIsolated()
        {
            var search   = new RingSearch(spiro);
            var isolated = search.Isolated();

            Assert.AreEqual(2, isolated.Length);
            Assert.IsTrue(Compares.AreOrderLessDeepEqual(new[] { 4, 7 }, new int[] { isolated[0].Length, isolated[1].Length }));
        }
Exemple #3
0
        public void TestIsolated()
        {
            var search   = new RingSearch(benzene);
            var isolated = search.Isolated();

            Assert.AreEqual(1, isolated.Length);
            Assert.AreEqual(6, isolated[0].Length);
        }
        public void TestIsolated()
        {
            var search   = new RingSearch(biphenyl);
            var isolated = search.Isolated();

            Assert.AreEqual(2, isolated.Length);
            Assert.AreEqual(6, isolated[0].Length);
            Assert.AreEqual(6, isolated[1].Length);
        }
Exemple #5
0
        public void TestIsolated()
        {
            var mock_cyclicSearch            = new Mock <ICyclicVertexSearch>();
            ICyclicVertexSearch cyclicSearch = mock_cyclicSearch.Object;
            IAtomContainer      container    = new Mock <IAtomContainer>().Object;
            IAtom atom = new Mock <IAtom>().Object;

            RingSearch ringSearch = new RingSearch(container, cyclicSearch);

            ringSearch.Isolated();

            mock_cyclicSearch.Verify(n => n.Isolated(), Times.Once());
        }
Exemple #6
0
        /// <summary>
        /// Compute all rings up to and including the <paramref name="maxRingSize"/>. The
        /// container is first partitioned into ring systems which are then processed
        /// separately. If the molecule has already be partitioned, consider using <see cref="FindAllRingsInIsolatedRingSystem(IAtomContainer, int)"/>.
        /// </summary>
        /// <param name="container">The AtomContainer to be searched for rings</param>
        /// <param name="maxRingSize">Maximum ring size to consider. Provides a possible
        ///                    breakout from recursion for complex compounds.</param>
        /// <returns>A RingSet with all rings in the AtomContainer</returns>
        /// <exception cref="CDKException">An exception thrown if the threshold was exceeded</exception>
        public IRingSet FindAllRings(IAtomContainer container, int maxRingSize)
        {
            var edges = EdgeToBondMap.WithSpaceFor(container);
            var graph = GraphUtil.ToAdjList(container, edges);

            var rs      = new RingSearch(container, graph);
            var ringSet = container.Builder.NewRingSet();

            // don't need to run on isolated rings, just need to put vertices in
            // cyclic order
            foreach (var isolated in rs.Isolated())
            {
                if (isolated.Length <= maxRingSize)
                {
                    var ring = ToRing(container, edges, GraphUtil.Cycle(graph, isolated));
                    ringSet.Add(ring);
                }
            }

            // for each set of fused cyclic vertices run the separate search
            foreach (var fused in rs.Fused())
            {
                var ac = new AllCycles(GraphUtil.Subgraph(graph, fused), Math.Min(maxRingSize, fused.Length), threshold.Value);

                if (!ac.Completed)
                {
                    throw new CDKException("Threshold exceeded for AllRingsFinder");
                }

                foreach (var path in ac.GetPaths())
                {
                    IRing ring = ToRing(container, edges, path, fused);
                    ringSet.Add(ring);
                }
            }

            return(ringSet);
        }
        public void TestIsolated()
        {
            var ringSearch = new RingSearch(fusedRings);

            Assert.AreEqual(0, ringSearch.Isolated().Length);
        }
        static void Main(string[] args)
        {
            {
                #region
                // construct the search for a given molecule, if an adjacency list
                // representation (int[][]) is available this can be passed to the
                // constructor for improved performance
                IAtomContainer container  = TestMoleculeFactory.MakeAlphaPinene();
                RingSearch     ringSearch = new RingSearch(container);

                // indices of cyclic vertices
                int[] cyclic = ringSearch.Cyclic();

                // iterate over fused systems (atom indices)
                foreach (int[] fused in ringSearch.Fused())
                {
                    // ...
                }

                // iterate over isolated rings (atom indices)
                foreach (int[] isolated in ringSearch.Isolated())
                {
                    // ...
                }

                // convenience methods for getting the fragments
                IAtomContainer fragments = ringSearch.RingFragments();

                foreach (IAtomContainer fragment in ringSearch.FusedRingFragments())
                {
                    // ...
                }
                foreach (IAtomContainer fragment in ringSearch.IsolatedRingFragments())
                {
                    // ...
                }
                #endregion
            }
            {
                #region Cyclic
                IAtomContainer mol        = TestMoleculeFactory.MakeAlphaPinene();
                RingSearch     ringSearch = new RingSearch(mol);
                foreach (var atom in mol.Atoms)
                {
                    if (ringSearch.Cyclic(atom))
                    {
                        // ...
                    }
                }
                #endregion
            }
            {
                #region Cyclic_int
                IAtomContainer mol    = TestMoleculeFactory.MakeAlphaPinene();
                RingSearch     tester = new RingSearch(mol);

                int n = mol.Atoms.Count;
                for (int i = 0; i < n; i++)
                {
                    if (tester.Cyclic(i))
                    {
                        // ...
                    }
                }
                #endregion
            }
            {
                #region Isolated
                IAtomContainer biphenyl   = TestMoleculeFactory.MakeBiphenyl();
                RingSearch     ringSearch = new RingSearch(biphenyl);

                int[][] isolated = ringSearch.Isolated();
                Console.WriteLine(isolated.Length);    // 2 isolated rings in biphenyl
                Console.WriteLine(isolated[0].Length); // 6 vertices in one benzene
                Console.WriteLine(isolated[1].Length); // 6 vertices in the other benzene
                #endregion
            }
            if (true)
            {
                #region Fused
                IAtomContainer mol        = new Smiles.SmilesParser().ParseSmiles("c1cc(cc2cc(ccc12)C3C4CC34)C6CC5CCC6(C5)");
                RingSearch     ringSearch = new RingSearch(mol);

                int[][] fused = ringSearch.Fused();
                Console.WriteLine(fused.Length);    // e.g. 3 separate fused ring systems
                Console.WriteLine(fused[0].Length); // e.g. 10 vertices in the first system
                Console.WriteLine(fused[1].Length); // e.g. 4 vertices in the second system
                Console.WriteLine(fused[2].Length); // e.g. 7 vertices in the third system
                #endregion
            }
        }