示例#1
0
        public static IAtom FromSubset(IAtom a, int sum, int deg)
        {
            // atom is already a non-subset atom
            if (!a.Subset)
            {
                return(a);
            }

            Element e = a.Element;

            if (a.IsAromatic())
            {
                sum++;
            }
            int hCount = a.IsAromatic() ? e.NumOfAromaticImplicitHydrogens(sum)
                                      : e.NumOfImplicitHydrogens(sum);

            // XXX: if there was an odd number of availableElectrons there was an odd number
            // or aromatic bonds (usually 1 or 3) - if there was one it was
            // only a single bond it's likely a spouting from a ring - otherwise
            // someones making our life difficult (e.g. c1=cc=cc=c1) in which we
            // 'give' back 2 free availableElectrons for use indeterminacy the hCount
            //        int hCount = (electrons & 0x1) == 1 ? deg > 1 ? (electrons + 2) / 2
            //                                                      : electrons / 2
            //                                            : electrons / 2;

            return(new AtomImpl.BracketAtom(-1,
                                            a.Element,
                                            hCount,
                                            0,
                                            0,
                                            a.IsAromatic()));
        }
示例#2
0
        public static IAtom ToSubset(IAtom a, Graph g, int u)
        {
            // atom is already a subset atom
            if (a.Subset)
            {
                return(a);
            }

            // element is not organic and thus cannot be part of the subset
            if (!a.Element.IsOrganic())
            {
                return(a);
            }

            // if any of these values are set the atom cannot be a subset atom
            if (a.Charge != 0 || a.AtomClass != 0 || a.Isotope >= 0)
            {
                return(a);
            }

            IAtom subset = a.IsAromatic() ? AtomImpl.AromaticSubset.OfElement(a.Element)
                                       : AtomImpl.AliphaticSubset.OfElement(a.Element);

            // does the implied availableElectrons from the bond Order sum match that
            // which was stored - if aromatic we only check the lowest valence state
            int impliedHCount = subset.GetNumberOfHydrogens(g, u);

            // mismatch in number of hydrogens we must write this as a bracket atom
            return(impliedHCount != a.NumOfHydrogens ? a : subset);
        }
示例#3
0
        private static IAtom AsBracketAtom(int u, Graph g)
        {
            IAtom a   = g.GetAtom(u);
            int   sum = a.IsAromatic() ? 1 : 0;

            foreach (var e in g.GetEdges(u))
            {
                sum += e.Bond.Order;
            }
            return(new AtomImpl.BracketAtom(-1,
                                            a.Element,
                                            a.IsAromatic() ? a.Element.NumOfAromaticImplicitHydrogens(sum)
                                                         : a.Element.NumOfImplicitHydrogens(sum),
                                            0,
                                            0,
                                            a.IsAromatic()));
        }
示例#4
0
        public void Aliphatic_symbol_c()
        {
            IAtom a = AtomBuilder.Aliphatic("C").Build();

            Assert.AreEqual(a.Element, Element.Carbon);
            Assert.AreEqual(a.Isotope, -1);
            Assert.AreEqual(a.Charge, 0);
            Assert.AreEqual(a.AtomClass, 0);
            Assert.AreEqual(a.IsAromatic(), false);
        }
示例#5
0
        public void IsAromatic_element_c()
        {
            IAtom a = AtomBuilder.Aromatic(Carbon).Build();

            Assert.AreEqual(a.Element, Element.Carbon);
            Assert.AreEqual(a.Isotope, -1);
            Assert.AreEqual(a.Charge, 0);
            Assert.AreEqual(a.AtomClass, 0);
            Assert.AreEqual(a.IsAromatic(), true);
        }
示例#6
0
 /// <summary>
 /// Given two atoms which are explicit connected determine the implicit bond
 /// type. If both atoms are aromatic but connected by a single bond the bond
 /// type is <see cref="Bond.Single"/> otherwise it is implicit.
 /// </summary>
 /// <param name="u">an atom</param>
 /// <param name="v">another atom </param>(connected to u)
 /// <param name="b">explicit bond type</param>
 /// <returns>the bond type</returns>
 static Bond GetBondType(IAtom u, IAtom v, Bond b)
 {
     if (u.IsAromatic() && v.IsAromatic())
     {
         return(b == Bond.Aromatic ? Bond.Implicit : b);
     }
     else
     {
         return(b == Bond.Aromatic ? Bond.Aromatic : Bond.Implicit);
     }
 }
示例#7
0
            public override void Append(StringBuilder sb)
            {
                bool hExpand = atom.Element == Element.Hydrogen &&
                               Graph.Degree(Index) == 0;

                sb.Append('[');
                if (atom.Isotope >= 0)
                {
                    sb.Append(atom.Isotope);
                }
                sb.Append(
                    atom.IsAromatic() ?
                    atom.Element.Symbol.ToLowerInvariant() :
                    atom.Element.Symbol);
                if (c != Configuration.Unknown)
                {
                    sb.Append(c.Shorthand.Symbol);
                }
                if (atom.NumOfHydrogens > 0 && !hExpand)
                {
                    sb.Append(Element.Hydrogen.Symbol);
                }
                if (atom.NumOfHydrogens > 1 && !hExpand)
                {
                    sb.Append(atom.NumOfHydrogens);
                }
                if (atom.Charge != 0)
                {
                    sb.Append(atom.Charge > 0 ? '+' : '-');
                    int absCharge = Math.Abs(atom.Charge);
                    if (absCharge > 1)
                    {
                        sb.Append(absCharge);
                    }
                }
                if (atom.AtomClass != 0)
                {
                    sb.Append(':').Append(atom.AtomClass);
                }
                sb.Append(']');
                if (hExpand)
                {
                    int h = atom.NumOfHydrogens;
                    while (h > 1)
                    {
                        sb.Append("([H])");
                        h--;
                    }
                    if (h > 0)
                    {
                        sb.Append("[H]");
                    }
                }
            }
示例#8
0
 private static IAtom ToSubset(IAtom a)
 {
     if (a.IsAromatic())
     {
         return(AtomImpl.AromaticSubset.OfElement(a.Element));
     }
     else
     {
         return(AtomImpl.AliphaticSubset.OfElement(a.Element));
     }
 }
示例#9
0
        public void Aliphatic_element_n()
        {
            IAtom a = AtomBuilder.Aliphatic(Element.Nitrogen)
                      .Build();

            Assert.AreEqual(a.Element, Element.Nitrogen);
            Assert.AreEqual(a.Isotope, -1);
            Assert.AreEqual(a.Charge, 0);
            Assert.AreEqual(a.AtomClass, 0);
            Assert.AreEqual(a.IsAromatic(), false);
        }
示例#10
0
        public void Create_symbol_IsAromatic_c()
        {
            IAtom a = AtomBuilder.Create("c")
                      .Build();

            Assert.AreEqual(a.Element, Element.Carbon);
            Assert.AreEqual(a.Isotope, -1);
            Assert.AreEqual(a.Charge, 0);
            Assert.AreEqual(a.AtomClass, 0);
            Assert.AreEqual(a.IsAromatic(), true);
        }
示例#11
0
        public void IsAromatic_symbol_n()
        {
            IAtom a = AtomBuilder.Aromatic("N")
                      .Build();

            Assert.AreEqual(a.Element, Element.Nitrogen);
            Assert.AreEqual(a.Isotope, -1);
            Assert.AreEqual(a.Charge, 0);
            Assert.AreEqual(a.AtomClass, 0);
            Assert.AreEqual(a.IsAromatic(), true);
        }
示例#12
0
 public static AtomBuilder FromExisting(IAtom a)
 {
     if (a == null)
     {
         throw new ArgumentNullException(nameof(a), "no atom provided");
     }
     return(new AtomBuilder(a.Element, a.IsAromatic())
            .Charge(a.Charge)
            .NumOfHydrogens(a.NumOfHydrogens)
            .Isotope(a.Isotope)
            .AtomClass(a.AtomClass));
 }
示例#13
0
 private static bool Suppressible(IAtom a, int v)
 {
     if (!a.Subset &&
         a.Element.IsOrganic() &&
         a.Isotope < 0 &&
         a.Charge == 0 &&
         a.AtomClass == 0)
     {
         int h = a.NumOfHydrogens;
         if (a.IsAromatic())
         {
             return(h == a.Element.NumOfAromaticImplicitHydrogens(1 + v));
         }
         else
         {
             return(h == a.Element.NumOfImplicitHydrogens(v));
         }
     }
     return(false);
 }
示例#14
0
 /// <summary>
 /// Given two atoms which are implicitly connected determine the explicit
 /// bond type. The type is 'aromatic' if both atoms are aromatic, if either
 /// or both atoms are non-aromatic then the bond type is 'single'.
 /// </summary>
 /// <param name="u">an atom</param>
 /// <param name="v">another atom </param>(connected to u)
 /// <returns>the bond type</returns>
 public static Bond Type(IAtom u, IAtom v)
 {
     return(u.IsAromatic() && v.IsAromatic() ? Bond.Aromatic : Bond.Single);
 }