Beispiel #1
0
        public void TestToString()
        {
            IAtomContainer     triazole = TestMoleculeFactory.Make123Triazole();
            ShortestPathWalker walker   = new ShortestPathWalker(triazole);

            Assert.AreEqual(
                "C->C1N->C1N1N->C1N2N->C2C->C2C1N->N->N1C->N1C2C->N1N->N1N1C->N1N2N->N2N->N2N1C->N2N1N",
                walker.ToString());
        }
Beispiel #2
0
        public void TestPaths()
        {
            var triazole = TestMoleculeFactory.Make123Triazole();
            var walker   = new ShortestPathWalker(triazole);
            var expected = new SortedSet <string>(new[] { "C", "N2N1N", "N", "N1N1C", "N1C2C", "C1N", "N2N1C",
                                                          "C1N2N", "C1N1N", "N1C", "C2C1N", "C2C", "N2N", "N1N2N", "N1N" });
            var actual = walker.GetPaths();

            Assert.IsTrue(Compares.AreDeepEqual(expected, actual));
        }
        /// <summary>
        /// Get all paths of lengths 0 to the specified length.
        ///
        /// This method will find all paths upto length N starting from each atom in the molecule and return the unique set
        /// of such paths.
        /// </summary>
        /// <param name="container">The molecule to search</param>
        /// <returns>A map of path strings, keyed on themselves</returns>
        private static int[] FindPaths(IAtomContainer container)
        {
            var walker = new ShortestPathWalker(container);
            // convert paths to hashes
            var paths        = new List <int>();
            int patternIndex = 0;

            foreach (var s in walker.GetPaths())
            {
                var toHashCode = Strings.GetJavaHashCode(s);
                paths.Insert(patternIndex, toHashCode);
                patternIndex++;
            }

            // Add ring information
            IRingSet sssr = Cycles.FindEssential(container).ToRingSet();

            RingSetManipulator.Sort(sssr);
            foreach (var ring in sssr)
            {
                var toHashCode = Strings.GetJavaHashCode(ring.Atoms.Count.ToString(NumberFormatInfo.InvariantInfo));
                paths.Insert(patternIndex, toHashCode);
                patternIndex++;
            }
            // Check for the charges
            var l = new List <string>();

            foreach (var atom in container.Atoms)
            {
                var charge = atom.FormalCharge ?? 0;
                if (charge != 0)
                {
                    l.Add(atom.Symbol + charge.ToString(NumberFormatInfo.InvariantInfo));
                }
            }
            {
                l.Sort();
                var toHashCode = Lists.GetHashCode(l);
                paths.Insert(patternIndex, toHashCode);
                patternIndex++;
            }

            l = new List <string>();
            // atom stereo parity
            foreach (var atom in container.Atoms)
            {
                var st = atom.StereoParity;
                if (st != StereoAtomParities.Undefined)
                {
                    l.Add(atom.Symbol + st.ToString(NumberFormatInfo.InvariantInfo));
                }
            }
            {
                l.Sort();
                var toHashCode = Lists.GetHashCode(l);
                paths.Insert(patternIndex, toHashCode);
                patternIndex++;
            }

            if (container.SingleElectrons.Count > 0)
            {
                var radicalInformation = new StringBuilder();
                radicalInformation.Append("RAD: ").Append(container.SingleElectrons.Count);
                paths.Insert(patternIndex, Strings.GetJavaHashCode(radicalInformation.ToString()));
                patternIndex++;
            }
            if (container.LonePairs.Count > 0)
            {
                var lpInformation = new StringBuilder();
                lpInformation.Append("LP: ").Append(container.LonePairs.Count);
                paths.Insert(patternIndex, Strings.GetJavaHashCode(lpInformation.ToString()));
                patternIndex++;
            }
            return(paths.ToArray());
        }