📄 bondtools.java
字号:
} return 0; } if (up == 1 && down == 0 && !strict) { return 3; } if (down == 1 && up == 0 && !strict) { return 4; } if (down == 2 && up == 1 && !strict) { return 5; } if (down == 1 && up == 2 && !strict) { return 6; } return 0; } /** * Says if an atom as a center of a trigonal-bipyramidal or actahedral * chirality * *@param a The atom which is the center *@param container The atomContainer the atom is in *@return true=is square planar, false=is not */ public static int isTrigonalBipyramidalOrOctahedral(IAtomContainer container, IAtom a) { java.util.List atoms = container.getConnectedAtomsList(a); if (atoms.size() < 5 || atoms.size() > 6) { return (0); } java.util.List bonds = container.getConnectedBondsList(a); int up = 0; int down = 0; for (int i = 0; i < bonds.size(); i++) { IBond bond = (IBond)bonds.get(i); if (bond.getStereo() == CDKConstants.STEREO_BOND_UNDEFINED || bond.getStereo() == CDKConstants.STEREO_BOND_NONE) { } if (bond.getStereo() == CDKConstants.STEREO_BOND_UP) { up++; } if (bond.getStereo() == CDKConstants.STEREO_BOND_DOWN) { down++; } } if (up == 1 && down == 1) { if(atoms.size()==5) return 1; else return 2; } return 0; } /** * Says if an atom as a center of any valid stereo configuration or not * *@param a The atom which is the center *@param container The atomContainer the atom is in *@return true=is a stereo atom, false=is not */ public static boolean isStereo(IAtomContainer container, IAtom a) { java.util.List atoms = container.getConnectedAtomsList(a); if (atoms.size() < 4 || atoms.size() > 6) { return (false); } java.util.List bonds = container.getConnectedBondsList(a); int stereo = 0; for (int i = 0; i < bonds.size(); i++) { if (((IBond)bonds.get(i)).getStereo() != 0) { stereo++; } } if (stereo == 0) { return false; } int differentAtoms = 0; for (int i = 0; i < atoms.size(); i++) { boolean isDifferent = true; for (int k = 0; k < i; k++) { if (((IAtom)atoms.get(i)).getSymbol().equals(((IAtom)atoms.get(i)).getSymbol())) { isDifferent = false; break; } } if (isDifferent) { differentAtoms++; } } if (differentAtoms != atoms.size()) { int[] morgannumbers = MorganNumbersTools.getMorganNumbers(container); Vector differentSymbols = new Vector(); for (int i = 0; i < atoms.size(); i++) { IAtom atom = (IAtom)atoms.get(i); if (!differentSymbols.contains(atom.getSymbol())) { differentSymbols.add(atom.getSymbol()); } } int[] onlyRelevantIfTwo = new int[2]; if (differentSymbols.size() == 2) { for (int i = 0; i < atoms.size(); i++) { IAtom atom = (IAtom)atoms.get(i); if (differentSymbols.indexOf(atom.getSymbol()) == 0) { onlyRelevantIfTwo[0]++; } else { onlyRelevantIfTwo[1]++; } } } boolean[] symbolsWithDifferentMorganNumbers = new boolean[differentSymbols.size()]; Vector[] symbolsMorganNumbers = new Vector[differentSymbols.size()]; for (int i = 0; i < symbolsWithDifferentMorganNumbers.length; i++) { symbolsWithDifferentMorganNumbers[i] = true; symbolsMorganNumbers[i] = new Vector(); } for (int k = 0; k < atoms.size(); k++) { IAtom atom = (IAtom)atoms.get(k); int elementNumber = differentSymbols.indexOf(atom.getSymbol()); if (symbolsMorganNumbers[elementNumber].contains(new Integer(morgannumbers[container.getAtomNumber(atom)]))) { symbolsWithDifferentMorganNumbers[elementNumber] = false; } else { symbolsMorganNumbers[elementNumber].add(new Integer(morgannumbers[container.getAtomNumber(atom)])); } } int numberOfSymbolsWithDifferentMorganNumbers = 0; for (int i = 0; i < symbolsWithDifferentMorganNumbers.length; i++) { if (symbolsWithDifferentMorganNumbers[i] == true) { numberOfSymbolsWithDifferentMorganNumbers++; } } if (numberOfSymbolsWithDifferentMorganNumbers != differentSymbols.size()) { if ((atoms.size() == 5 || atoms.size() == 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); } /** * Says if an atom as a center of a square planar chirality * *@param a The atom which is the center *@param container The atomContainer the atom is in *@return true=is square planar, false=is not */ public static boolean isSquarePlanar(IAtomContainer container, IAtom a) { java.util.List atoms = container.getConnectedAtomsList(a); if (atoms.size() != 4) { return (false); } java.util.List bonds = container.getConnectedBondsList(a); int up = 0; int down = 0; for (int i = 0; i < bonds.size(); i++) { IBond bond = (IBond)bonds.get(i); if (bond.getStereo() == CDKConstants.STEREO_BOND_UNDEFINED || bond.getStereo() == CDKConstants.STEREO_BOND_NONE) { } if (bond.getStereo() == CDKConstants.STEREO_BOND_UP) { up++; } if (bond.getStereo() == CDKConstants.STEREO_BOND_DOWN) { down++; } } if (up == 2 && down == 2 && !stereosAreOpposite(container, a)) { return true; } return false; } /** * Says if of four atoms connected two one atom the up and down bonds are * opposite or not, i. e.if it's tetrehedral or square planar. The method * doesnot check if there are four atoms and if two or up and two are down * *@param a The atom which is the center *@param container The atomContainer the atom is in *@return true=are opposite, false=are not */ public static boolean stereosAreOpposite(IAtomContainer container, IAtom a) { List atoms = container.getConnectedAtomsList(a); TreeMap hm = new TreeMap(); for (int i = 1; i < atoms.size(); i++) { hm.put(new Double(giveAngle(a, (IAtom) atoms.get(0), ((IAtom) atoms.get(i)))), new Integer(i)); } Object[] ohere = hm.values().toArray(); int stereoOne = container.getBond(a, (IAtom) atoms.get(0)).getStereo(); int stereoOpposite = container.getBond(a, (IAtom) atoms.get((((Integer) ohere[1])).intValue())).getStereo(); if (stereoOpposite == stereoOne) { return true; } else { return false; } } /** * Calls giveAngleBothMethods with bool = true * *@param from the atom to view from *@param to1 first direction to look in *@param to2 second direction to look in *@return The angle in rad from 0 to 2*PI */ public static double giveAngle(IAtom from, IAtom to1, IAtom to2) { return (giveAngleBothMethods(from, to1, to2, true)); } /** * Calls giveAngleBothMethods with bool = false * *@param from the atom to view from *@param to1 first direction to look in *@param to2 second direction to look in *@return The angle in rad from -PI to PI */ public static double giveAngleFromMiddle(IAtom from, IAtom to1, IAtom to2) { return (giveAngleBothMethods(from, to1, to2, false)); } public static void makeUpDownBonds(IAtomContainer container){ for (int i = 0; i < container.getAtomCount(); i++) { IAtom a = container.getAtom(i); if (container.getConnectedAtomsList(a).size() == 4) { int up = 0; int down = 0; int hs = 0; IAtom h = null; for (int k = 0; k < 4; k++) { IAtom conAtom = (IAtom)container.getConnectedAtomsList(a).get(k); int stereo = container.getBond(a,conAtom).getStereo(); if (stereo == CDKConstants.STEREO_BOND_UP) { up++; } else if (stereo == CDKConstants.STEREO_BOND_DOWN) { down++; } else if (stereo == CDKConstants.STEREO_BOND_NONE && conAtom.getSymbol().equals("H")) { h = conAtom; hs++; } else { h = null; } } if (up == 0 && down == 1 && h != null && hs == 1) { container.getBond(a, h).setStereo(CDKConstants.STEREO_BOND_UP); } if (up == 1 && down == 0 && h != null && hs == 1) { container.getBond(a, h).setStereo(CDKConstants.STEREO_BOND_DOWN); } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -