Esempio n. 1
0
        /// <summary>
        /// Check whether a set of atoms in an <see cref="IAtomContainer"/> is connected.
        /// </summary>
        /// <param name="atomContainer">The <see cref="IAtomContainer"/> to be check for connectedness</param>
        /// <returns>true if the <see cref="IAtomContainer"/> is connected</returns>
        public static bool IsConnected(IAtomContainer atomContainer)
        {
            // with one atom or less, we define it to be connected, as there is no
            // partitioning needed
            if (atomContainer.Atoms.Count < 2)
            {
                return(true);
            }

            var cc = new ConnectedComponents(GraphUtil.ToAdjList(atomContainer));

            return(cc.NumberOfComponents == 1);
        }
        public void Main()
        {
            var container = TestMoleculeFactory.MakeBenzene();

            #region
            int[][]             g  = GraphUtil.ToAdjList(container);
            ConnectedComponents cc = new ConnectedComponents(g);
            int[] components       = cc.GetComponents();
            for (int v = 0; v < g.Length; v++)
            {
                Console.WriteLine(components[v]);
            }
            #endregion
        }
Esempio n. 3
0
        /// <summary>
        /// Partitions the atoms in an <see cref="IAtomContainer"/> into covalently connected components.
        /// </summary>
        /// <param name="container">The <see cref="IAtomContainer"/> to be partitioned into connected components, i.e. molecules</param>
        /// <returns>A MoleculeSet.</returns>
        // @cdk.dictref   blue-obelisk:graphPartitioning
        public static IChemObjectSet <IAtomContainer> PartitionIntoMolecules(IAtomContainer container)
        {
            var cc = new ConnectedComponents(GraphUtil.ToAdjList(container));

            return(PartitionIntoMolecules(container, cc.GetComponents()));
        }