Beispiel #1
0
        public void TestSplit()
        {
            var          mol       = smilesParser.ParseSmiles("C1CC1C2CCC2");
            SpanningTree st        = new SpanningTree(mol);
            IRingSet     rings     = st.GetAllRings();
            IBond        splitBond = null;

            for (int i = 0; i < mol.Bonds.Count; i++)
            {
                if (rings.GetRings(mol.Bonds[i]).Count() == 0)
                {
                    splitBond = mol.Bonds[i];
                    break;
                }
            }
            var             frags       = FragmentUtils.SplitMolecule(mol, splitBond);
            SmilesGenerator sg          = new SmilesGenerator();
            var             uniqueFrags = new HashSet <string>();

            foreach (var frag in frags)
            {
                uniqueFrags.Add(sg.Create(frag));
            }
            Assert.AreEqual(2, uniqueFrags.Count);
            // You can put the fragments back together with a ring closure and dot
            // [CH]12CC1.[CH]12CCC1
            Assert.IsTrue(uniqueFrags.IsSupersetOf(new[] { "[CH]1CC1", "[CH]1CCC1" }));
        }
Beispiel #2
0
        private static List <IBond> GetSplitableBonds(IAtomContainer atomContainer)
        {
            // do ring detection
            var spanningTree = new SpanningTree(atomContainer);
            var allRings     = spanningTree.GetAllRings();

            // find the splitable bonds
            List <IBond> splitableBonds = new List <IBond>();

            foreach (var bond in atomContainer.Bonds)
            {
                bool isInRing   = false;
                bool isTerminal = false;

                // lets see if it's in a ring
                var rings = allRings.GetRings(bond);
                if (rings.Any())
                {
                    isInRing = true;
                }

                // lets see if it is a terminal bond
                foreach (var atom in bond.Atoms)
                {
                    if (atomContainer.GetConnectedBonds(atom).Count() == 1)
                    {
                        isTerminal = true;
                        break;
                    }
                }

                if (!(isInRing || isTerminal))
                {
                    splitableBonds.Add(bond);
                }
            }
            return(splitableBonds);
        }