/// <summary> /// Says if an atom is the end of a double bond configuration /// </summary> /// <param name="atom">The atom which is the end of configuration</param> /// <param name="container">The atomContainer the atom is in</param> /// <param name="parent">The atom we came from</param> /// <param name="doubleBondConfiguration">The array indicating where double bond /// configurations are specified (this method ensures that there is /// actually the possibility of a double bond configuration)</param> /// <returns>false=is not end of configuration, true=is</returns> private static bool IsEndOfDoubleBond(IAtomContainer container, IAtom atom, IAtom parent, bool[] doubleBondConfiguration) { var bondNumber = container.Bonds.IndexOf(container.GetBond(atom, parent)); if (bondNumber == -1 || doubleBondConfiguration.Length <= bondNumber || !doubleBondConfiguration[bondNumber]) { return(false); } int hcount = atom.ImplicitHydrogenCount ?? 0; int lengthAtom = container.GetConnectedAtoms(atom).Count() + hcount; hcount = parent.ImplicitHydrogenCount ?? 0; int lengthParent = container.GetConnectedAtoms(parent).Count() + hcount; if (container.GetBond(atom, parent) != null) { if (container.GetBond(atom, parent).Order == BondOrder.Double && (lengthAtom == 3 || (lengthAtom == 2 && atom.AtomicNumber.Equals(AtomicNumbers.N))) && (lengthParent == 3 || (lengthParent == 2 && parent.AtomicNumber.Equals(AtomicNumbers.N)))) { var atoms = container.GetConnectedAtoms(atom); IAtom one = null; IAtom two = null; foreach (var conAtom in atoms) { if (conAtom != parent && one == null) { one = conAtom; } else if (conAtom != parent && one != null) { two = conAtom; } } string[] morgannumbers = MorganNumbersTools.GetMorganNumbersWithElementSymbol(container); if ((one != null && two == null && atom.AtomicNumber.Equals(AtomicNumbers.N) && Math.Abs(GiveAngleBothMethods(parent, atom, one, true)) > Math.PI / 10) || (!atom.AtomicNumber.Equals(AtomicNumbers.N) && one != null && two != null && !morgannumbers[container.Atoms.IndexOf(one)].Equals(morgannumbers[container.Atoms.IndexOf(two)], StringComparison.Ordinal))) { return(true); } else { return(false); } } } return(false); }
/// <summary> /// Says if an atom is the start of a double bond configuration /// </summary> /// <param name="a">The atom which is the start of configuration</param> /// <param name="container">The atomContainer the atom is in</param> /// <param name="parent">The atom we came from</param> /// <param name="doubleBondConfiguration">The array indicating where double bond /// configurations are specified (this method ensures that there is /// actually the possibility of a double bond configuration)</param> /// <returns>false=is not start of configuration, true=is</returns> private static bool IsStartOfDoubleBond(IAtomContainer container, IAtom a, IAtom parent, bool[] doubleBondConfiguration) { int hcount; hcount = a.ImplicitHydrogenCount ?? 0; int lengthAtom = container.GetConnectedAtoms(a).Count() + hcount; if (lengthAtom != 3 && (lengthAtom != 2 && !(a.AtomicNumber.Equals(AtomicNumbers.N)))) { return(false); } var atoms = container.GetConnectedAtoms(a); IAtom one = null; IAtom two = null; bool doubleBond = false; IAtom nextAtom = null; foreach (var atom in atoms) { if (atom != parent && container.GetBond(atom, a).Order == BondOrder.Double && IsEndOfDoubleBond(container, atom, a, doubleBondConfiguration)) { doubleBond = true; nextAtom = atom; } if (atom != nextAtom && one == null) { one = atom; } else if (atom != nextAtom && one != null) { two = atom; } } string[] morgannumbers = MorganNumbersTools.GetMorganNumbersWithElementSymbol(container); if (one != null && ((!a.AtomicNumber.Equals(AtomicNumbers.N) && two != null && !morgannumbers[container.Atoms.IndexOf(one)].Equals(morgannumbers[container.Atoms.IndexOf(two)], StringComparison.Ordinal) && doubleBond && doubleBondConfiguration[container.Bonds.IndexOf(container.GetBond(a, nextAtom))]) || (doubleBond && a.AtomicNumber.Equals(AtomicNumbers.N) && Math.Abs(GiveAngleBothMethods(nextAtom, a, parent, true)) > Math.PI / 10))) { return(true); } else { return(false); } }