📄 smilesgenerator.java
字号:
return; } if (atomContainer.getBond(a1, a2) == null) { return; } int type = 0; type = (int) atomContainer.getBond(a1, a2).getOrder(); if (type == 1) { } else if (type == 2) { line.append("="); } else if (type == 3) { line.append("#"); } else { // //logger.debug("Unknown bond type"); } } /** * Generates the SMILES string for the atom * *@param a the atom to generate the SMILES for. *@param buffer the string buffer that the atom is to be * apended to. *@param container the AtomContainer to analyze. *@param chiral is a chiral smiles wished? *@param parent the atom we came from. *@param atomsInOrderOfSmiles a vector containing the atoms in the order * they are in the smiles. *@param currentChain The chain we currently deal with. *@param useAromaticity true=aromaticity or sp2 will trigger lower case letters, wrong=only sp2 */ private void parseAtom(IAtom a, StringBuffer buffer, IAtomContainer container, boolean chiral, boolean[] doubleBondConfiguration, IAtom parent, Vector atomsInOrderOfSmiles, Vector currentChain, boolean useAromaticity) { String symbol = a.getSymbol(); boolean stereo = BondTools.isStereo(container, a); boolean brackets = symbol.equals("B") || symbol.equals("C") || symbol.equals("N") || symbol.equals("O") || symbol.equals("P") || symbol.equals("S") || symbol.equals("F") || symbol.equals("Br") || symbol.equals("I") || symbol.equals("Cl"); brackets = !brackets; //logger.debug("in parseAtom()"); //Deal with the start of a double bond configuration if (isStartOfDoubleBond(container, a, parent, doubleBondConfiguration)) { buffer.append('/'); } if (a instanceof IPseudoAtom) { buffer.append("[*]"); } else { String mass = generateMassString(a); brackets = brackets | !mass.equals(""); String charge = generateChargeString(a); brackets = brackets | !charge.equals(""); if (chiral && stereo && (BondTools.isTrigonalBipyramidalOrOctahedral(container, a)!=0 || BondTools.isSquarePlanar(container, a) || BondTools.isTetrahedral(container, a,false) != 0 || BondTools.isSquarePlanar(container, a))) { brackets = true; } if (brackets) { buffer.append('['); } buffer.append(mass); if ((useAromaticity && a.getFlag(CDKConstants.ISAROMATIC)) || (a.getHybridization() != CDKConstants.UNSET && a.getHybridization() == CDKConstants.HYBRIDIZATION_SP2)) { buffer.append(a.getSymbol().toLowerCase()); } else { buffer.append(symbol); } if (a.getProperty(RING_CONFIG) != null && a.getProperty(RING_CONFIG).equals(UP)) { buffer.append('/'); } if (a.getProperty(RING_CONFIG) != null && a.getProperty(RING_CONFIG).equals(DOWN)) { buffer.append('\\'); } if (chiral && stereo && (BondTools.isTrigonalBipyramidalOrOctahedral(container, a)!=0 || BondTools.isSquarePlanar(container, a) || BondTools.isTetrahedral(container, a,false) != 0)) { buffer.append('@'); } if (chiral && stereo && BondTools.isSquarePlanar(container, a)) { buffer.append("SP1"); } //chiral //hcount buffer.append(charge); if (brackets) { buffer.append(']'); } } //logger.debug("in parseAtom() after dealing with Pseudoatom or not"); //Deal with the end of a double bond configuration if (isEndOfDoubleBond(container, a, parent, doubleBondConfiguration)) { IAtom viewFrom = null; for (int i = 0; i < currentChain.size(); i++) { if (currentChain.get(i) == parent) { int k = i - 1; while (k > -1) { if (currentChain.get(k) instanceof IAtom) { viewFrom = (IAtom) currentChain.get(k); break; } k--; } } } if (viewFrom == null) { for (int i = 0; i < atomsInOrderOfSmiles.size(); i++) { if (atomsInOrderOfSmiles.get(i) == parent) { viewFrom = (IAtom) atomsInOrderOfSmiles.get(i - 1); } } } boolean afterThisAtom = false; IAtom viewTo = null; for (int i = 0; i < currentChain.size(); i++) { if (afterThisAtom && currentChain.get(i) instanceof IAtom) { viewTo = (IAtom) currentChain.get(i); break; } if (afterThisAtom && currentChain.get(i) instanceof Vector) { viewTo = (IAtom) ((Vector) currentChain.get(i)).get(0); break; } if (a == currentChain.get(i)) { afterThisAtom = true; } } try{ if (BondTools.isCisTrans(viewFrom,a,parent,viewTo,container)) { buffer.append('\\'); } else { buffer.append('/'); } }catch(CDKException ex){ //If the user wants a double bond configuration, where there is none, we ignore this. } } Vector v = new Vector(); Iterator it = getRingOpenings(a, v).iterator(); Iterator it2 = v.iterator(); //logger.debug("in parseAtom() after checking for Ring openings"); while (it.hasNext()) { Integer integer = (Integer) it.next(); IAtom a2=(IAtom) it2.next(); IBond b = container.getBond(a2, a); int type = (int) b.getOrder(); if (!(useAromaticity && a.getFlag(CDKConstants.ISAROMATIC) && a2.getFlag(CDKConstants.ISAROMATIC))){ if (type == 2) { buffer.append("="); } else if (type == 3) { buffer.append("#"); } } buffer.append(integer); } atomsInOrderOfSmiles.add(a); //logger.debug("End of parseAtom()"); } /** * Creates a string for the charge of atom <code>a</code>. If the charge is 1 * + is returned if it is -1 - is returned. The positive values all have + in * front of them. * *@return string representing the charge on <code>a</code> */ private String generateChargeString(IAtom a) { int charge = a.getFormalCharge(); StringBuffer buffer = new StringBuffer(3); if (charge > 0) { //Positive buffer.append('+'); if (charge > 1) { buffer.append(charge); } } else if (charge < 0) { //Negative if (charge == -1) { buffer.append('-'); } else { buffer.append(charge); } } return buffer.toString(); } /** * Creates a string containing the mass of the atom <code>a</code>. If the * mass is the same as the majour isotope an empty string is returned. * *@param a the atom to create the mass */ private String generateMassString(IAtom a) { if (isotopeFactory == null) setupIsotopeFactory(a.getBuilder()); if (a instanceof IPseudoAtom) return Integer.toString(a.getMassNumber()); IIsotope majorIsotope = isotopeFactory.getMajorIsotope(a.getSymbol()); if (majorIsotope.getMassNumber() == a.getMassNumber()) { return ""; } else if (a.getMassNumber() == 0) { return ""; } else { return Integer.toString(a.getMassNumber()); } } private void setupIsotopeFactory(IChemObjectBuilder builder) { try { isotopeFactory = IsotopeFactory.getInstance(builder); } catch (IOException e) { e.printStackTrace(); } } class BrokenBond { /** * The atoms which close the ring */ private org.openscience.cdk.interfaces.IAtom a1, a2; /** * The number of the marker */ private int marker; /** * Construct a BrokenBond between <code>a1</code> and <code>a2</code> with * the marker <code>marker</code>. * *@param marker the ring closure marker. (Great comment!) */ BrokenBond(org.openscience.cdk.interfaces.IAtom a1, org.openscience.cdk.interfaces.IAtom a2, int marker) { this.a1 = a1; this.a2 = a2; this.marker = marker; } /** * Getter method for a1 property * *@return The a1 value */ public org.openscience.cdk.interfaces.IAtom getA1() { return a1; } /** * Getter method for a2 property * *@return The a2 value */ public org.openscience.cdk.interfaces.IAtom getA2() { return a2; } /** * Getter method for marker property * *@return The marker value */ public int getMarker() { return marker; } public String toString() { return Integer.toString(marker); } public boolean equals(Object o) { if (!(o instanceof BrokenBond)) { return false; } BrokenBond bond = (BrokenBond) o; return (a1.equals(bond.getA1()) && a2.equals(bond.getA2())) || (a1.equals(bond.getA2()) && a2.equals(bond.getA1())); } } /** * Returns the current AllRingsFinder instance * *@return the current AllRingsFinder instance */ public AllRingsFinder getRingFinder() { return ringFinder; } /** * Sets the current AllRingsFinder instance * Use this if you want to customize the timeout for * the AllRingsFinder. AllRingsFinder is stopping its * quest to find all rings after a default of 5 seconds. * * @see org.openscience.cdk.ringsearch.AllRingsFinder * * @param ringFinder The value to assign ringFinder. */ public void setRingFinder(AllRingsFinder ringFinder) { this.ringFinder = ringFinder; } /** * @param false=only SP2-hybridized atoms will be lower case (default), true=SP2 or aromaticity trigger lower case */ public void setUseAromaticityFlag(boolean useAromaticityFlag) { this.useAromaticityFlag = useAromaticityFlag; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -