Example #1
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);
        }