Exemplo n.º 1
0
        public static Graph GenerateKekuleForm(Graph g, BitArray subset, BitArray aromatic, bool inplace)
        {
            // make initial (empty) matching - then improve it, first
            // by matching the first edges we find, most of time this
            // gives us a perfect matching if not we maximise it
            // with Edmonds' algorithm

            Matching m        = Matching.CreateEmpty(g);
            int      n        = BitArrays.Cardinality(subset);
            int      nMatched = ArbitraryMatching.Initial(g, m, subset);

            if (nMatched < n)
            {
                if (n - nMatched == 2)
                {
                    nMatched = ArbitraryMatching.AugmentOnce(g, m, nMatched, subset);
                }
                if (nMatched < n)
                {
                    nMatched = MaximumMatching.Maximise(g, m, nMatched, IntSet.FromBitArray(subset));
                }
                if (nMatched < n)
                {
                    throw new InvalidSmilesException("Could not Kekulise");
                }
            }
            return(inplace ? Assign(g, subset, aromatic, m)
                           : CopyAndAssign(g, subset, aromatic, m));
        }
Exemplo n.º 2
0
        public void Furan_2()
        {
            Graph    g = Graph.FromSmiles("c1ccoc1");
            Matching m = Matching.CreateEmpty(g);

            ArbitraryMatching.Initial(g,
                                      m,
                                      AllOf(0, 1, 2, 4));
            Assert.AreEqual(1, m.GetMatches().Count());
            Assert.IsTrue(Compares.AreOrderLessDeepEqual(
                              new[] { Tuple.Of(0, 1) },
                              m.GetMatches()));
        }
Exemplo n.º 3
0
        public void Furan()
        {
            Graph    g = Graph.FromSmiles("o1cccc1");
            Matching m = Matching.CreateEmpty(g);

            ArbitraryMatching.Initial(g, m,
                                      AllOf(1, 2, 3, 4));
            // note this matching is maximum
            Assert.AreEqual(2, m.GetMatches().Count());
            Assert.IsTrue(Compares.AreOrderLessDeepEqual(
                              new[] { Tuple.Of(1, 2), Tuple.Of(3, 4) },
                              m.GetMatches()));
        }
Exemplo n.º 4
0
        public void Benzene()
        {
            Graph    g = Graph.FromSmiles("c1ccccc1");
            Matching m = Matching.CreateEmpty(g);

            ArbitraryMatching.Initial(g,
                                      m,
                                      AllOf(0, 1, 2, 3, 4, 5));
            Assert.AreEqual(3, m.GetMatches().Count());
            Assert.IsTrue(Compares.AreOrderLessDeepEqual(
                              new[] {
                Tuple.Of(0, 1),
                Tuple.Of(2, 3),
                Tuple.Of(4, 5),
            },
                              m.GetMatches()));
        }