Exemplo n.º 1
0
        public void TestFusedRingFragments()
        {
            var search = new RingSearch(spiro);
            var fused  = search.FusedRingFragments();

            Assert.AreEqual(0, fused.Count());
        }
Exemplo n.º 2
0
        public void TestFusedRingFragments()
        {
            var mock_cyclicSearch = new Mock <ICyclicVertexSearch>();
            var mock_container    = new Mock <IAtomContainer>();
            var mock_builder      = new Mock <IChemObjectBuilder>();
            var mock_atom         = new Mock <IAtom>();

            RingSearch ringSearch = new RingSearch(mock_container.Object, mock_cyclicSearch.Object);

            mock_cyclicSearch.Setup(n => n.Fused()).Returns(new int[][] { new[] { 0, 1 }, new[] { 2 } });
            mock_container.Setup(n => n.Builder).Returns(mock_builder.Object);
            mock_builder.Setup(n => n.NewAtomContainer(It.IsAny <IEnumerable <IAtom> >(), It.IsAny <IEnumerable <IBond> >())).Returns(new Mock <IAtomContainer>().Object);
            mock_container.Setup(n => n.Bonds).Returns(new List <IBond>());
            mock_container.Setup(n => n.Atoms[It.IsAny <int>()]).Returns(new Mock <IAtom>().Object);

            ringSearch.FusedRingFragments().ToReadOnlyList();

            mock_cyclicSearch.Verify(n => n.Fused(), Times.Once());

            // atoms were accessed
            mock_container.Verify(n => n.Atoms[0], Times.Once());
            mock_container.Verify(n => n.Atoms[1], Times.Once());
            mock_container.Verify(n => n.Atoms[2], Times.Once());

            // builder was invoked
            mock_builder.Verify(n => n.NewAtomContainer(It.IsAny <IEnumerable <IAtom> >(), It.IsAny <IEnumerable <IBond> >()), Times.Exactly(2));
        }
        public void TestFusedRingFragments()
        {
            var search = new RingSearch(hexaphenylene);
            var fused  = search.FusedRingFragments().ToReadOnlyList();

            Assert.AreEqual(1, fused.Count);
            Assert.AreEqual(hexaphenylene.Atoms.Count, fused[0].Atoms.Count);
            Assert.AreEqual(hexaphenylene.Bonds.Count, fused[0].Bonds.Count);
        }
Exemplo n.º 4
0
        public void TestFusedRingFragments()
        {
            var ringSearch = new RingSearch(fusedRings);
            var fragments  = ringSearch.FusedRingFragments().ToReadOnlyList();

            Assert.AreEqual(1, fragments.Count);
            IAtomContainer fragment = fragments[0];

            foreach (var atom in fusedRings.Atoms)
            {
                Assert.IsTrue(fragment.Contains(atom));
            }
            foreach (var bond in fusedRings.Bonds)
            {
                Assert.IsTrue(fragment.Contains(bond));
            }
        }
Exemplo n.º 5
0
        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
            }
        }