コード例 #1
0
        public void TestGetAllChemObjects_IReactionSet()
        {
            var allObjects = ReactionSetManipulator.GetAllChemObjects(set);

            // does not recurse beyond the IAtomContainer, so:
            // set, reaction, 2xreactant, 1xproduct
            Assert.AreEqual(5, allObjects.Count());
        }
コード例 #2
0
        /// <summary>
        /// Retrieve a List of all ChemObject objects within an IChemModel.
        /// </summary>
        /// <param name="chemModel">The IChemModel object.</param>
        /// <returns>A List of all ChemObjects inside.</returns>
        public static List <IChemObject> GetAllChemObjects(IChemModel chemModel)
        {
            var list = new List <IChemObject>();
            // list.Add(chemModel); // only add ChemObjects contained within
            ICrystal crystal = chemModel.Crystal;

            if (crystal != null)
            {
                list.Add(crystal);
            }
            var moleculeSet = chemModel.MoleculeSet;

            if (moleculeSet != null)
            {
                list.Add(moleculeSet);
                var current = MoleculeSetManipulator.GetAllChemObjects(moleculeSet);
                foreach (var chemObject in current)
                {
                    if (!list.Contains(chemObject))
                    {
                        list.Add(chemObject);
                    }
                }
            }
            var reactionSet = chemModel.ReactionSet;

            if (reactionSet != null)
            {
                list.Add(reactionSet);
                var current = ReactionSetManipulator.GetAllChemObjects(reactionSet);
                foreach (var chemObject in current)
                {
                    if (!list.Contains(chemObject))
                    {
                        list.Add(chemObject);
                    }
                }
            }
            return(list);
        }