Beispiel #1
0
            /// <inheritdoc/>
            public Cycles Find(IAtomContainer molecule, int length)
            {
                var bondMap    = EdgeToBondMap.WithSpaceFor(molecule);
                var graph      = GraphUtil.ToAdjList(molecule, bondMap);
                var ringSearch = new RingSearch(molecule, graph);

                var walks = new List <int[]>(6);

                // all isolated cycles are relevant - all we need to do is walk around
                // the vertices in the subset 'isolated'
                foreach (var isolated in ringSearch.Isolated())
                {
                    if (isolated.Length <= length)
                    {
                        walks.Add(GraphUtil.Cycle(graph, isolated));
                    }
                }

                // each biconnected component which isn't an isolated cycle is processed
                // separately as a subgraph.
                foreach (var fused in ringSearch.Fused())
                {
                    // make a subgraph and 'apply' the cycle computation - the walk
                    // (path) is then lifted to the original graph
                    foreach (var cycle in Apply(GraphUtil.Subgraph(graph, fused), length))
                    {
                        walks.Add(Lift(cycle, fused));
                    }
                }

                return(new Cycles(walks.ToArray(), molecule, bondMap));
            }
Beispiel #2
0
        /// <summary>
        /// Find and mark all cyclic atoms and bonds in the provided molecule.
        /// </summary>
        /// <param name="mol">molecule</param>
        /// <returns>Number of rings found (circuit rank)</returns>
        /// <seealso cref="IMolecularEntity.IsInRing"/>
        /// <seealso href="https://en.wikipedia.org/wiki/Circuit_rank">Circuit Rank</seealso>
        public static int MarkRingAtomsAndBonds(IAtomContainer mol)
        {
            var bonds = EdgeToBondMap.WithSpaceFor(mol);

            return(MarkRingAtomsAndBonds(mol, GraphUtil.ToAdjList(mol, bonds), bonds));
        }