private void SetCompareTable(IAtomContainer mol) { this.compare = mol; this.compareTable = MorganNumbersTools.GetMorganNumbers(compare); sortedCompareTable = new long[compareTable.Length]; Array.Copy(compareTable, 0, sortedCompareTable, 0, compareTable.Length); Array.Sort(sortedCompareTable); }
private void SetBaseTable(IAtomContainer mol) { this.base_ = mol; this.baseTable = MorganNumbersTools.GetMorganNumbers(base_); sortedBaseTable = new long[baseTable.Length]; Array.Copy(baseTable, 0, sortedBaseTable, 0, baseTable.Length); Array.Sort(sortedBaseTable); }
/// <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); } }
/// <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 lengthAtom = container.getConnectedAtoms(a).Length + a.getHydrogenCount(); if (lengthAtom != 3 && (lengthAtom != 2 && (System.Object)a.Symbol != (System.Object)("N"))) { return(false); } IAtom[] atoms = container.getConnectedAtoms(a); IAtom one = null; IAtom two = null; bool doubleBond = false; IAtom nextAtom = null; for (int i = 0; i < atoms.Length; i++) { if (atoms[i] != parent && container.getBond(atoms[i], a).Order == CDKConstants.BONDORDER_DOUBLE && isEndOfDoubleBond(container, atoms[i], a, doubleBondConfiguration)) { doubleBond = true; nextAtom = atoms[i]; } if (atoms[i] != nextAtom && one == null) { one = atoms[i]; } else if (atoms[i] != nextAtom && one != null) { two = atoms[i]; } } System.String[] morgannumbers = MorganNumbersTools.getMorganNumbersWithElementSymbol(container); if (one != null && ((!a.Symbol.Equals("N") && two != null && !morgannumbers[container.getAtomNumber(one)].Equals(morgannumbers[container.getAtomNumber(two)]) && doubleBond && doubleBondConfiguration[container.getBondNumber(a, nextAtom)]) || (doubleBond && a.Symbol.Equals("N") && System.Math.Abs(giveAngleBothMethods(nextAtom, a, parent, true)) > System.Math.PI / 10))) { return(true); } else { return(false); } }
/// <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) { if (container.getBondNumber(atom, parent) == -1 || doubleBondConfiguration.Length <= container.getBondNumber(atom, parent) || !doubleBondConfiguration[container.getBondNumber(atom, parent)]) { return(false); } int lengthAtom = container.getConnectedAtoms(atom).Length + atom.getHydrogenCount(); int lengthParent = container.getConnectedAtoms(parent).Length + parent.getHydrogenCount(); if (container.getBond(atom, parent) != null) { if (container.getBond(atom, parent).Order == CDKConstants.BONDORDER_DOUBLE && (lengthAtom == 3 || (lengthAtom == 2 && atom.Symbol.Equals("N"))) && (lengthParent == 3 || (lengthParent == 2 && parent.Symbol.Equals("N")))) { IAtom[] atoms = container.getConnectedAtoms(atom); IAtom one = null; IAtom two = null; for (int i = 0; i < atoms.Length; i++) { if (atoms[i] != parent && one == null) { one = atoms[i]; } else if (atoms[i] != parent && one != null) { two = atoms[i]; } } System.String[] morgannumbers = MorganNumbersTools.getMorganNumbersWithElementSymbol(container); if ((one != null && two == null && atom.Symbol.Equals("N") && System.Math.Abs(giveAngleBothMethods(parent, atom, one, true)) > System.Math.PI / 10) || (!atom.Symbol.Equals("N") && one != null && two != null && !morgannumbers[container.getAtomNumber(one)].Equals(morgannumbers[container.getAtomNumber(two)]))) { return(true); } else { return(false); } } } return(false); }
/// <summary> /// Says if an atom as a center of any valid stereo configuration or not. /// This method uses wedge bonds. 3D coordinates are not taken into account. If there /// are no wedge bonds around a potential stereo center, it will not be found. /// </summary> /// <param name="stereoAtom">The atom which is the center</param> /// <param name="container">The atomContainer the atom is in</param> /// <returns>true=is a stereo atom, false=is not</returns> public static bool IsStereo(IAtomContainer container, IAtom stereoAtom) { var atoms = container.GetConnectedAtoms(stereoAtom).ToReadOnlyList(); if (atoms.Count < 4 || atoms.Count > 6) { return(false); } var bonds = container.GetConnectedBonds(stereoAtom); int stereo = 0; foreach (var bond in bonds) { if (bond.Stereo != BondStereo.None) { stereo++; } } if (stereo == 0) { return(false); } int differentAtoms = 0; for (int i = 0; i < atoms.Count; i++) { bool isDifferent = true; for (int k = 0; k < i; k++) { if (atoms[i].Symbol.Equals(atoms[k].Symbol, StringComparison.Ordinal)) { isDifferent = false; break; } } if (isDifferent) { differentAtoms++; } } if (differentAtoms != atoms.Count) { long[] morgannumbers = MorganNumbersTools.GetMorganNumbers(container); var differentSymbols = new List <string>(); foreach (var atom in atoms) { if (!differentSymbols.Contains(atom.Symbol)) { differentSymbols.Add(atom.Symbol); } } int[] onlyRelevantIfTwo = new int[2]; if (differentSymbols.Count == 2) { foreach (var atom in atoms) { if (differentSymbols.IndexOf(atom.Symbol) == 0) { onlyRelevantIfTwo[0]++; } else { onlyRelevantIfTwo[1]++; } } } bool[] symbolsWithDifferentMorganNumbers = new bool[differentSymbols.Count]; var symbolsMorganNumbers = new List <long> [symbolsWithDifferentMorganNumbers.Length]; for (int i = 0; i < symbolsWithDifferentMorganNumbers.Length; i++) { symbolsWithDifferentMorganNumbers[i] = true; symbolsMorganNumbers[i] = new List <long>(); } foreach (var atom in atoms) { int elementNumber = differentSymbols.IndexOf(atom.Symbol); if (symbolsMorganNumbers[elementNumber].Contains(morgannumbers[container.Atoms.IndexOf(atom)])) { symbolsWithDifferentMorganNumbers[elementNumber] = false; } else { symbolsMorganNumbers[elementNumber].Add(morgannumbers[container.Atoms.IndexOf(atom)]); } } int numberOfSymbolsWithDifferentMorganNumbers = 0; foreach (var symbolWithDifferentMorganNumber in symbolsWithDifferentMorganNumbers) { if (symbolWithDifferentMorganNumber) { numberOfSymbolsWithDifferentMorganNumbers++; } } if (numberOfSymbolsWithDifferentMorganNumbers != differentSymbols.Count) { if ((atoms.Count == 5 || atoms.Count == 6) && (numberOfSymbolsWithDifferentMorganNumbers + differentAtoms > 2 || (differentAtoms == 2 && onlyRelevantIfTwo[0] > 1 && onlyRelevantIfTwo[1] > 1))) { return(true); } return(IsSquarePlanar(container, stereoAtom) && (numberOfSymbolsWithDifferentMorganNumbers + differentAtoms > 2 || (differentAtoms == 2 && onlyRelevantIfTwo[0] > 1 && onlyRelevantIfTwo[1] > 1))); } } return(true); }
/// <summary> Says if an atom as a center of any valid stereo configuration or not /// /// </summary> /// <param name="a"> The atom which is the center /// </param> /// <param name="container"> The atomContainer the atom is in /// </param> /// <returns> true=is a stereo atom, false=is not /// </returns> public static bool isStereo(IAtomContainer container, IAtom a) { IAtom[] atoms = container.getConnectedAtoms(a); if (atoms.Length < 4 || atoms.Length > 6) { return(false); } IBond[] bonds = container.getConnectedBonds(a); int stereo = 0; for (int i = 0; i < bonds.Length; i++) { if (bonds[i].Stereo != 0) { stereo++; } } if (stereo == 0) { return(false); } int differentAtoms = 0; for (int i = 0; i < atoms.Length; i++) { bool isDifferent = true; for (int k = 0; k < i; k++) { if (atoms[i].Symbol.Equals(atoms[k].Symbol)) { isDifferent = false; break; } } if (isDifferent) { differentAtoms++; } } if (differentAtoms != atoms.Length) { int[] morgannumbers = MorganNumbersTools.getMorganNumbers(container); System.Collections.ArrayList differentSymbols = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); for (int i = 0; i < atoms.Length; i++) { if (!differentSymbols.Contains(atoms[i].Symbol)) { differentSymbols.Add(atoms[i].Symbol); } } int[] onlyRelevantIfTwo = new int[2]; if (differentSymbols.Count == 2) { for (int i = 0; i < atoms.Length; i++) { if (differentSymbols.IndexOf(atoms[i].Symbol) == 0) { onlyRelevantIfTwo[0]++; } else { onlyRelevantIfTwo[1]++; } } } bool[] symbolsWithDifferentMorganNumbers = new bool[differentSymbols.Count]; System.Collections.ArrayList[] symbolsMorganNumbers = new System.Collections.ArrayList[differentSymbols.Count]; for (int i = 0; i < symbolsWithDifferentMorganNumbers.Length; i++) { symbolsWithDifferentMorganNumbers[i] = true; symbolsMorganNumbers[i] = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); } for (int k = 0; k < atoms.Length; k++) { int elementNumber = differentSymbols.IndexOf(atoms[k].Symbol); if (symbolsMorganNumbers[elementNumber].Contains((System.Int32)morgannumbers[container.getAtomNumber(atoms[k])])) { symbolsWithDifferentMorganNumbers[elementNumber] = false; } else { symbolsMorganNumbers[elementNumber].Add((System.Int32)morgannumbers[container.getAtomNumber(atoms[k])]); } } int numberOfSymbolsWithDifferentMorganNumbers = 0; for (int i = 0; i < symbolsWithDifferentMorganNumbers.Length; i++) { if (symbolsWithDifferentMorganNumbers[i] == true) { numberOfSymbolsWithDifferentMorganNumbers++; } } if (numberOfSymbolsWithDifferentMorganNumbers != differentSymbols.Count) { if ((atoms.Length == 5 || atoms.Length == 6) && (numberOfSymbolsWithDifferentMorganNumbers + differentAtoms > 2 || (differentAtoms == 2 && onlyRelevantIfTwo[0] > 1 && onlyRelevantIfTwo[1] > 1))) { return(true); } if (isSquarePlanar(container, a) && (numberOfSymbolsWithDifferentMorganNumbers + differentAtoms > 2 || (differentAtoms == 2 && onlyRelevantIfTwo[0] > 1 && onlyRelevantIfTwo[1] > 1))) { return(true); } return(false); } } return(true); }