📄 smilesgenerator.java
字号:
{ allrings.getAtom(k).setProperty(RING_CONFIG, UP); } else { allrings.getAtom(k).setProperty(RING_CONFIG, DOWN); } } } } } } } StringBuffer l = new StringBuffer(); createSMILES(start, l, molecule, chiral, doubleBondConfiguration,useAromaticityFlag); rings = null; // remove all CanonicalLable/InvariancePair props for (int k = 0; k < molecule.getAtomCount(); k++) { molecule.getAtom(k).removeProperty("CanonicalLable"); molecule.getAtom(k).removeProperty("InvariancePair"); } return l.toString(); } private org.openscience.cdk.interfaces.IAtom hasWedges(IAtomContainer ac, org.openscience.cdk.interfaces.IAtom a) { List atoms = ac.getConnectedAtomsList(a); IAtom atomi = null;// for (int i = 0; i < atoms.size(); i++)// {// atomi = (IAtom)atoms.get(i);// if (ac.getBond(a, atomi).getStereo() != CDKConstants.STEREO_BOND_NONE && !atomi.getSymbol().equals("H"))// {// return (atomi);// }// } for (int i = 0; i < atoms.size(); i++) { atomi = (IAtom)atoms.get(i); if (ac.getBond(a, atomi).getStereo() != CDKConstants.STEREO_BOND_NONE) { return (atomi); } } return (null); } /** * Says if an atom is the end of a double bond configuration * *@param atom The atom which is the end of configuration *@param container The atomContainer the atom is in *@param parent The atom we came from *@param doubleBondConfiguration The array indicating where double bond * configurations are specified (this method ensures that there is * actually the possibility of a double bond configuration) *@return false=is not end of configuration, true=is */ private boolean isEndOfDoubleBond(IAtomContainer container, org.openscience.cdk.interfaces.IAtom atom, org.openscience.cdk.interfaces.IAtom parent, boolean[] doubleBondConfiguration) { if (container.getBondNumber(atom, parent) == -1 || doubleBondConfiguration.length <= container.getBondNumber(atom, parent) || !doubleBondConfiguration[container.getBondNumber(atom, parent)]) { return false; } // TO-DO: We make the silent assumption of unset hydrogen count equals zero hydrogen count here. int lengthAtom = container.getConnectedAtomsCount(atom) + ((atom.getHydrogenCount() == CDKConstants.UNSET) ? 0 : atom.getHydrogenCount()); // TO-DO: We make the silent assumption of unset hydrogen count equals zero hydrogen count here. int lengthParent = container.getConnectedAtomsCount(parent) + ((parent.getHydrogenCount() == CDKConstants.UNSET) ? 0 : parent.getHydrogenCount()); if (container.getBond(atom, parent) != null) { if (container.getBond(atom, parent).getOrder() == CDKConstants.BONDORDER_DOUBLE && (lengthAtom == 3 || (lengthAtom == 2 && atom.getSymbol().equals("N"))) && (lengthParent == 3 || (lengthParent == 2 && parent.getSymbol().equals("N")))) { List atoms = container.getConnectedAtomsList(atom); org.openscience.cdk.interfaces.IAtom one = null; org.openscience.cdk.interfaces.IAtom two = null; IAtom atomi = null; for (int i = 0; i < atoms.size(); i++) { atomi = (IAtom)container.getAtom(i); if (atomi != parent && one == null) { one = atomi; } else if (atomi != parent && one != null) { two = atomi; } } String[] morgannumbers = MorganNumbersTools.getMorganNumbersWithElementSymbol(container); if ((one != null && two == null && atom.getSymbol().equals("N") && Math.abs(BondTools.giveAngleBothMethods(parent, atom, one, true)) > Math.PI / 10) || (!atom.getSymbol().equals("N") && one != null && two != null && !morgannumbers[container.getAtomNumber(one)].equals(morgannumbers[container.getAtomNumber(two)]))) { return (true); } else { return (false); } } } return (false); } /** * Says if an atom is the start of a double bond configuration * *@param a The atom which is the start of configuration *@param container The atomContainer the atom is in *@param parent The atom we came from *@param doubleBondConfiguration The array indicating where double bond * configurations are specified (this method ensures that there is * actually the possibility of a double bond configuration) *@return false=is not start of configuration, true=is */ private boolean isStartOfDoubleBond(IAtomContainer container, org.openscience.cdk.interfaces.IAtom a, org.openscience.cdk.interfaces.IAtom parent, boolean[] doubleBondConfiguration) { // TO-DO: We make the silent assumption of unset hydrogen count equals zero hydrogen count here. int lengthAtom = container.getConnectedAtomsCount(a) + ((a.getHydrogenCount() == CDKConstants.UNSET) ? 0 : a.getHydrogenCount()); if (lengthAtom != 3 && (lengthAtom != 2 && a.getSymbol() != ("N"))) { return (false); } List atoms = container.getConnectedAtomsList(a); org.openscience.cdk.interfaces.IAtom one = null; org.openscience.cdk.interfaces.IAtom two = null; boolean doubleBond = false; org.openscience.cdk.interfaces.IAtom nextAtom = null; IAtom atomi = null; for (int i = 0; i < atoms.size(); i++) { atomi = (IAtom)atoms.get(i); if (atomi != parent && container.getBond(atomi, a).getOrder() == CDKConstants.BONDORDER_DOUBLE && isEndOfDoubleBond(container, atomi, a, doubleBondConfiguration)) { doubleBond = true; nextAtom = atomi; } if (atomi != nextAtom && one == null) { one = atomi; } else if (atomi != nextAtom && one != null) { two = atomi; } } String[] morgannumbers = MorganNumbersTools.getMorganNumbersWithElementSymbol(container); if (one != null && ((!a.getSymbol().equals("N") && two != null && !morgannumbers[container.getAtomNumber(one)].equals(morgannumbers[container.getAtomNumber(two)]) && doubleBond && doubleBondConfiguration[container.getBondNumber(a, nextAtom)]) || (doubleBond && a.getSymbol().equals("N") && Math.abs(BondTools.giveAngleBothMethods(nextAtom, a, parent, true)) > Math.PI / 10))) { return (true); } else { return (false); } } /** * Gets the bondBroken attribute of the SmilesGenerator object */ private boolean isBondBroken(IAtom a1, IAtom a2) { Iterator it = brokenBonds.iterator(); while (it.hasNext()) { BrokenBond bond = ((BrokenBond) it.next()); if ((bond.getA1().equals(a1) || bond.getA1().equals(a2)) && (bond.getA2().equals(a1) || bond.getA2().equals(a2))) { return (true); } } return false; } /** * Determines if the atom <code>a</code> is a atom with a ring marker. * *@param a the atom to test *@return true if the atom participates in a bond that was broken in the * first pass. */// private boolean isRingOpening(IAtom a)// {// Iterator it = brokenBonds.iterator();// while (it.hasNext())// {// BrokenBond bond = (BrokenBond) it.next();// if (bond.getA1().equals(a) || bond.getA2().equals(a))// {// return true;// }// }// return false;// } /** * Determines if the atom <code>a</code> is a atom with a ring marker. * *@return true if the atom participates in a bond that was broken in the * first pass. */ private boolean isRingOpening(IAtom a1, Vector v) { Iterator it = brokenBonds.iterator(); while (it.hasNext()) { BrokenBond bond = (BrokenBond) it.next(); for (int i = 0; i < v.size(); i++) { if ((bond.getA1().equals(a1) && bond.getA2().equals((IAtom) v.get(i))) || (bond.getA1().equals((IAtom) v.get(i)) && bond.getA2().equals(a1))) { return true; } } } return false; } /** * Return the neighbours of atom <code>a</code> in canonical order with the * atoms that have high bond order at the front. * *@param a the atom whose neighbours are to be found. *@param container the AtomContainer that is being parsed. *@return Vector of atoms in canonical oreder. */ private List getCanNeigh(final org.openscience.cdk.interfaces.IAtom a, final IAtomContainer container) { List v = container.getConnectedAtomsList(a); if (v.size() > 1) { Collections.sort(v, new Comparator() { public int compare(Object o1, Object o2) { return (int) (((Long) ((IAtom) o1).getProperty("CanonicalLable")).longValue() - ((Long) ((IAtom) o2).getProperty("CanonicalLable")).longValue()); } }); } return v; } /** * Gets the ringOpenings attribute of the SmilesGenerator object */ private Vector getRingOpenings(IAtom a, Vector vbonds) { Iterator it = brokenBonds.iterator(); Vector v = new Vector(10); while (it.hasNext()) { BrokenBond bond = (BrokenBond) it.next(); if (bond.getA1().equals(a) || bond.getA2().equals(a)) { v.add(new Integer(bond.getMarker())); if (vbonds != null) { vbonds.add(bond.getA1().equals(a) ? bond.getA2() : bond.getA1()); } } } Collections.sort(v); return v; } /** * Returns true if the <code>atom</code> in the <code>container</code> has * been marked as a chiral center by the user. */// private boolean isChiralCenter(IAtom atom, IAtomContainer container)// {// IBond[] bonds = container.getConnectedBonds(atom);// for (int i = 0; i < bonds.length; i++)// {// IBond bond = bonds[i];// int stereo = bond.getStereo();// if (stereo == CDKConstants.STEREO_BOND_DOWN ||// stereo == CDKConstants.STEREO_BOND_UP)// {// return true;// }// }// return false;// } /** * Gets the last atom object (not Vector) in a Vector as created by * createDSFTree. * *@param v The Vector *@param result The feature to be added to the Atoms attribute */ private void addAtoms(Vector v, Vector result) { for (int i = 0; i < v.size(); i++) { if (v.get(i) instanceof IAtom) { result.add((IAtom) v.get(i)); } else { addAtoms((Vector) v.get(i), result); } } } /** * Performes a DFS search on the <code>atomContainer</code>. Then parses the * resulting tree to create the SMILES string. * *@param a the atom to start the search at. *@param line the StringBuffer that the SMILES is to be * appended to. *@param chiral true=SMILES will be chiral, false=SMILES * will not be chiral. *@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 createSMILES(org.openscience.cdk.interfaces.IAtom a, StringBuffer line, IAtomContainer atomContainer, boolean chiral, boolean[] doubleBondConfiguration, boolean useAromaticity) { Vector tree = new Vector(); // set all ISVISITED labels to FALSE Iterator atoms = atomContainer.atoms(); while (atoms.hasNext()) ((IAtom)atoms.next()).setFlag(CDKConstants.VISITED, false); createDFSTree(a, tree, null, atomContainer); //logger.debug("Done with tree"); parseChain(tree, line, atomContainer, null, chiral, doubleBondConfiguration, new Vector(), useAromaticity); } /** * Recursively perform a DFS search on the <code>container</code> placing * atoms and branches in the vector <code>tree</code>. * *@param a the atom being visited. *@param tree vector holding the tree. *@param parent the atom we came from. *@param container the AtomContainer that we are parsing. */ private void createDFSTree(org.openscience.cdk.interfaces.IAtom a, Vector tree, org.openscience.cdk.interfaces.IAtom parent, IAtomContainer container) { tree.add(a); List neighbours = getCanNeigh(a, container); neighbours.remove(parent); IAtom next; a.setFlag(CDKConstants.VISITED, true); //logger.debug("Starting with DFSTree and AtomContainer of size " + container.getAtomCount()); //logger.debug("Current Atom has " + neighbours.size() + " neighbours"); Iterator iter = neighbours.iterator(); while (iter.hasNext()) { next = (IAtom)iter.next(); if (!next.getFlag(CDKConstants.VISITED)) { if (!iter.hasNext()) { //Last neighbour therefore in this chain createDFSTree(next, tree, a, container); } else { Vector branch = new Vector(); tree.add(branch); //logger.debug("adding branch"); createDFSTree(next, branch, a, container); } } else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -