📄 smilesgenerator.java
字号:
} if (container.getBond(parent, atom).getStereo() == CDKConstants.STEREO_BOND_UNDEFINED || container.getBond(parent, atom).getStereo() == CDKConstants.STEREO_BOND_NONE) { for (int i = 0; i < chiralNeighbours.size(); i++) { if (chiralNeighbours.get(i) != parent) { if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == CDKConstants.STEREO_BOND_DOWN && BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) { sorted[0] = (IAtom) chiralNeighbours.get(i); } if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == CDKConstants.STEREO_BOND_DOWN && !BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) { sorted[2] = (IAtom) chiralNeighbours.get(i); } if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == CDKConstants.STEREO_BOND_UP) { sorted[1] = (IAtom) chiralNeighbours.get(i); } } } } } if (BondTools.isTetrahedral(container, atom,false) == 6) { if (container.getBond(parent, atom).getStereo() == CDKConstants.STEREO_BOND_UP) { for (int i = 0; i < chiralNeighbours.size(); i++) { if (chiralNeighbours.get(i) != parent) { if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == CDKConstants.STEREO_BOND_UP) { sorted[0] = (IAtom) chiralNeighbours.get(i); } if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == 0) { sorted[2] = (IAtom) chiralNeighbours.get(i); } if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == CDKConstants.STEREO_BOND_DOWN) { sorted[1] = (IAtom) chiralNeighbours.get(i); } } } } if (container.getBond(parent, atom).getStereo() == CDKConstants.STEREO_BOND_DOWN) { for (int i = 0; i < chiralNeighbours.size(); i++) { if (chiralNeighbours.get(i) != parent) { if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == CDKConstants.STEREO_BOND_UP && BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) { sorted[2] = (IAtom) chiralNeighbours.get(i); } if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == CDKConstants.STEREO_BOND_UP && !BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) { sorted[0] = (IAtom) chiralNeighbours.get(i); } if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == 0) { sorted[1] = (IAtom) chiralNeighbours.get(i); } } } } if (container.getBond(parent, atom).getStereo() == CDKConstants.STEREO_BOND_UNDEFINED || container.getBond(parent, atom).getStereo() == CDKConstants.STEREO_BOND_NONE) { for (int i = 0; i < chiralNeighbours.size(); i++) { if (chiralNeighbours.get(i) != parent) { if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == CDKConstants.STEREO_BOND_UP && BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) { sorted[2] = (IAtom) chiralNeighbours.get(i); } if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == CDKConstants.STEREO_BOND_UP && !BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) { sorted[0] = (IAtom) chiralNeighbours.get(i); } if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == CDKConstants.STEREO_BOND_DOWN) { sorted[1] = (IAtom) chiralNeighbours.get(i); } } } } } if (BondTools.isSquarePlanar(container, atom)) { sorted = new IAtom[3]; //This produces a U=SP1 order in every case TreeMap hm = new TreeMap(); for (int i = 0; i < chiralNeighbours.size(); i++) { if (chiralNeighbours.get(i) != parent && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) { hm.put(new Double(BondTools.giveAngle(atom, parent, ((IAtom) chiralNeighbours.get(i)))), new Integer(i)); } } Object[] ohere = hm.values().toArray(); for (int i = 0; i < ohere.length; i++) { sorted[i] = ((IAtom) chiralNeighbours.get(((Integer) ohere[i]).intValue())); } } if (BondTools.isTrigonalBipyramidalOrOctahedral(container, atom)!=0) { sorted = new IAtom[container.getConnectedAtomsCount(atom) - 1]; TreeMap hm = new TreeMap(); if (container.getBond(parent, atom).getStereo() == CDKConstants.STEREO_BOND_UP) { for (int i = 0; i < chiralNeighbours.size(); i++) { if (container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == 0) { hm.put(new Double(BondTools.giveAngle(atom, parent, ((IAtom) chiralNeighbours.get(i)))), new Integer(i)); } if (container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == CDKConstants.STEREO_BOND_DOWN) { sorted[sorted.length - 1] = (IAtom) chiralNeighbours.get(i); } } Object[] ohere = hm.values().toArray(); for (int i = 0; i < ohere.length; i++) { sorted[i] = ((IAtom) chiralNeighbours.get(((Integer) ohere[i]).intValue())); } } if (container.getBond(parent, atom).getStereo() == CDKConstants.STEREO_BOND_DOWN) { for (int i = 0; i < chiralNeighbours.size(); i++) { if (container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == 0) { hm.put(new Double(BondTools.giveAngle(atom, parent, ((IAtom) chiralNeighbours.get(i)))), new Integer(i)); } if (container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == CDKConstants.STEREO_BOND_UP) { sorted[sorted.length - 1] = (IAtom) chiralNeighbours.get(i); } } Object[] ohere = hm.values().toArray(); for (int i = 0; i < ohere.length; i++) { sorted[i] = ((IAtom) chiralNeighbours.get(((Integer) ohere[i]).intValue())); } } if (container.getBond(parent, atom).getStereo() == 0) { for (int i = 0; i < chiralNeighbours.size(); i++) { if (chiralNeighbours.get(i) != parent) { if (container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == 0) { hm.put(new Double((BondTools.giveAngleFromMiddle(atom, parent, ((IAtom) chiralNeighbours.get(i))))), new Integer(i)); } if (container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == CDKConstants.STEREO_BOND_UP) { sorted[0] = (IAtom) chiralNeighbours.get(i); } if (container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == CDKConstants.STEREO_BOND_DOWN) { sorted[sorted.length - 2] = (IAtom) chiralNeighbours.get(i); } } } Object[] ohere = hm.values().toArray(); sorted[sorted.length - 1] = ((IAtom) chiralNeighbours.get(((Integer) ohere[ohere.length - 1]).intValue())); if (ohere.length == 2) { sorted[sorted.length - 3] = ((IAtom) chiralNeighbours.get(((Integer) ohere[0]).intValue())); if (BondTools.giveAngleFromMiddle(atom, parent, ((IAtom) chiralNeighbours.get(((Integer) ohere[1]).intValue()))) < 0) { IAtom dummy = sorted[sorted.length - 2]; sorted[sorted.length - 2] = sorted[0]; sorted[0] = dummy; } } if (ohere.length == 3) { sorted[sorted.length - 3] = sorted[sorted.length - 2]; sorted[sorted.length - 2] = ((IAtom) chiralNeighbours.get(((Integer) ohere[ohere.length - 2]).intValue())); sorted[sorted.length - 4] = ((IAtom) chiralNeighbours.get(((Integer) ohere[ohere.length - 3]).intValue())); } } } //This builds an onew[] containing the objects after the center of the chirality in the order given by sorted[] if (sorted != null) { int numberOfAtoms = 3; if (BondTools.isTrigonalBipyramidalOrOctahedral(container, atom)!=0) { numberOfAtoms = container.getConnectedAtomsCount(atom) - 1; } Object[] omy = new Object[numberOfAtoms]; Object[] onew = new Object[numberOfAtoms]; for (int k = getRingOpenings(atom, null).size(); k < numberOfAtoms; k++) { if (positionInVector + 1 + k - getRingOpenings(atom, null).size() < v.size()) { omy[k] = v.get(positionInVector + 1 + k - getRingOpenings(atom, null).size()); } } for (int k = 0; k < sorted.length; k++) { if (sorted[k] != null) { for (int m = 0; m < omy.length; m++) { if (omy[m] instanceof IAtom) { if (omy[m] == sorted[k]) { onew[k] = omy[m]; } } else { if (omy[m] == null) { onew[k] = null; } else { if (((Vector) omy[m]).get(0) == sorted[k]) { onew[k] = omy[m]; } } } } } else { onew[k] = null; } } //This is a workaround for 3624.MOL.2 I don't have a better solution currently boolean doubleentry = false; for (int m = 0; m < onew.length; m++) { for (int k = 0; k < onew.length; k++) { if (m != k && onew[k] == onew[m]) { doubleentry = true; } } } if (!doubleentry) { //Make sure that the first atom in onew is the first one in the original smiles order. This is important to have a canonical smiles. if (positionInVector + 1 < v.size()) { Object atomAfterCenterInOriginalSmiles = v.get(positionInVector + 1); int l = 0; while (onew[0] != atomAfterCenterInOriginalSmiles) { Object placeholder = onew[onew.length - 1]; for (int k = onew.length - 2; k > -1; k--) { onew[k + 1] = onew[k]; } onew[0] = placeholder; l++; if (l > onew.length) { break; } } } //This cares about ring openings. Here the ring closure (represendted by a figure) must be the first atom. In onew the closure is null. if (getRingOpenings(atom, null).size() > 0) { int l = 0; while (onew[0] != null) { Object placeholder = onew[0]; for (int k = 1; k < onew.length; k++) { onew[k - 1] = onew[k]; } onew[onew.length - 1] = placeholder; l++; if (l > onew.length) { break; } } } //The last in onew is a vector: This means we need to exchange the rest of the original smiles with the rest of this vector. if (onew[numberOfAtoms - 1] instanceof Vector) { for (int i = 0; i < numberOfAtoms; i++) { if (onew[i] instanceof IAtom) { Vector vtemp = new Vector(); vtemp.add(onew[i]); for (int k = positionInVector + 1 + numberOfAtoms; k < v.size(); k++) { vtemp.add(v.get(k)); } onew[i] = vtemp; for (int k = v.size() - 1; k > positionInVector + 1 + numberOfAtoms - 1; k--) { v.remove(k); } for (int k = 1; k < ((Vector) onew[numberOfAtoms - 1]).size(); k++) { v.add(((Vector) onew[numberOfAtoms - 1]).get(k)); } onew[numberOfAtoms - 1] = ((Vector) onew[numberOfAtoms - 1]).get(0); break; } } } //Put the onew objects in the original Vector int k = 0; for (int m = 0; m < onew.length; m++) { if (onew[m] != null) { v.set(positionInVector + 1 + k, onew[m]); k++; } } } } } parent = atom; } else { //Have Vector //logger.debug("in parseChain after else"); boolean brackets = true; Vector result = new Vector(); addAtoms((Vector) o, result); if (isRingOpening(parent, result) && container.getConnectedBondsCount(parent) < 4) { brackets = false; } if (brackets) { buffer.append('('); } parseChain((Vector) o, buffer, container, parent, chiral, doubleBondConfiguration, atomsInOrderOfSmiles, useAromaticity); if (brackets) { buffer.append(')'); } } positionInVector++; //logger.debug("in parseChain after positionVector++"); } } /** * Append the symbol for the bond order between <code>a1</code> and <code>a2</code> * to the <code>line</code>. * *@param line the StringBuffer that the bond symbol is appended to. *@param a1 Atom participating in the bond. *@param a2 Atom participating in the bond. *@param atomContainer the AtomContainer that the SMILES string is generated * for. *@param useAromaticity true=aromaticity or sp2 will trigger lower case letters, wrong=only sp2 */ private void parseBond(StringBuffer line, IAtom a1, IAtom a2, IAtomContainer atomContainer, boolean useAromaticity) { //logger.debug("in parseBond()"); if (useAromaticity && a1.getFlag(CDKConstants.ISAROMATIC) && a2.getFlag(CDKConstants.ISAROMATIC)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -