📄 atomplacer.java
字号:
* appended to allow for it to be laid out. This gives us a vector for * attaching the unplaced ring later. * *@param molecule The molecule to be * search for the longest unplaced chain *@param startAtom A start atom from * which the chain search starts *@return An AtomContainer * holding the longest unplaced chain. *@exception org.openscience.cdk.exception.CDKException Description of the * Exception */ public IAtomContainer getLongestUnplacedChain(IMolecule molecule, IAtom startAtom) throws org.openscience.cdk.exception.CDKException { logger.debug("Start of getLongestUnplacedChain."); //ConnectivityChecker cc = new ConnectivityChecker(); int longest = 0; int longestPathLength = 0; int maxDegreeSum = 0; int degreeSum = 0; IAtomContainer[] pathes = new IAtomContainer[molecule.getAtomCount()]; for (int f = 0; f < molecule.getAtomCount(); f++) { molecule.getAtom(f).setFlag(CDKConstants.VISITED, false); pathes[f] = molecule.getBuilder().newAtomContainer(); pathes[f].addAtom(startAtom); } Vector startSphere = new Vector(); startSphere.addElement(startAtom); breadthFirstSearch(molecule, startSphere, pathes); for (int f = 0; f < molecule.getAtomCount(); f++) { if (pathes[f].getAtomCount() >= longestPathLength) { degreeSum = getDegreeSum(pathes[f], molecule); if (degreeSum > maxDegreeSum) { maxDegreeSum = degreeSum; longest = f; longestPathLength = pathes[f].getAtomCount(); } } } logger.debug("End of getLongestUnplacedChain."); return pathes[longest]; } /** * Performs a breadthFirstSearch in an AtomContainer starting with a * particular sphere, which usually consists of one start atom, and searches * for the longest aliphatic chain which is yet unplaced. If the search * encounters an unplaced ring atom, it is also appended to the chain so that * this last bond of the chain can also be laid out. This gives us the * orientation for the attachment of the ring system. * *@param ac The AtomContainer to * be searched *@param sphere A sphere of atoms to * start the search with *@param pathes A vector of N pathes * (N = no of heavy atoms). *@exception org.openscience.cdk.exception.CDKException Description of the * Exception */ public void breadthFirstSearch(IAtomContainer ac, Vector sphere, IAtomContainer[] pathes) throws org.openscience.cdk.exception.CDKException { IAtom atom = null; IAtom nextAtom = null; int atomNr; int nextAtomNr; //IAtomContainer path = null; Vector newSphere = new Vector(); logger.debug("Start of breadthFirstSearch"); for (int f = 0; f < sphere.size(); f++) { atom = (IAtom) sphere.elementAt(f); if (!atom.getFlag(CDKConstants.ISINRING)) { atomNr = ac.getAtomNumber(atom); logger.debug("BreadthFirstSearch around atom " + (atomNr + 1)); java.util.List bonds = ac.getConnectedBondsList(atom); for (int g = 0; g < bonds.size(); g++) { IBond curBond = (IBond)bonds.get(g); nextAtom = curBond.getConnectedAtom(atom); if (!nextAtom.getFlag(CDKConstants.VISITED) && !nextAtom.getFlag(CDKConstants.ISPLACED)) { nextAtomNr = ac.getAtomNumber(nextAtom); logger.debug("BreadthFirstSearch is meeting new atom " + (nextAtomNr + 1)); pathes[nextAtomNr] = ac.getBuilder().newAtomContainer(pathes[atomNr]); logger.debug("Making copy of path " + (atomNr + 1) + " to form new path " + (nextAtomNr + 1)); logger.debug("Old path " + (atomNr + 1) + " looks like: " + listNumbers(molecule, pathes[atomNr])); logger.debug("Copied path " + (nextAtomNr + 1) + " looks like: " + listNumbers(molecule, pathes[nextAtomNr])); pathes[nextAtomNr].addAtom(nextAtom); logger.debug("Adding atom " + (nextAtomNr + 1) + " to path " + (nextAtomNr + 1)); pathes[nextAtomNr].addBond(curBond); logger.debug("New path " + (nextAtomNr + 1) + " looks like: " + listNumbers(molecule, pathes[nextAtomNr])); if (ac.getConnectedBondsCount(nextAtom) > 1) { newSphere.addElement(nextAtom); } } } } } if (newSphere.size() > 0) { for (int f = 0; f < newSphere.size(); f++) { ((IAtom) newSphere.elementAt(f)).setFlag(CDKConstants.VISITED, true); } breadthFirstSearch(ac, newSphere, pathes); } logger.debug("End of breadthFirstSearch"); } /** * Returns a string with the numbers of all placed atoms in an AtomContainer * *@param ac The AtomContainer for which the placed atoms are to be listed *@return A string with the numbers of all placed atoms in an AtomContainer */ public String listPlaced(IAtomContainer ac) { String s = "Placed: "; for (int f = 0; f < ac.getAtomCount(); f++) { if (ac.getAtom(f).getFlag(CDKConstants.ISPLACED)) { s += (f + 1) + "+ "; } else { s += (f + 1) + "- "; } } return s; } /** * Returns a string with the numbers of all atoms in an AtomContainer relative * to a given molecule. I.e. the number the is listesd is the position of each * atom in the molecule. * *@param ac The AtomContainer for * which the placed atoms are to be listed *@param mol Description of the * Parameter *@return A string with the * numbers of all placed atoms in an AtomContainer *@exception org.openscience.cdk.exception.CDKException Description of the * Exception */ public String listNumbers(IAtomContainer mol, IAtomContainer ac) throws org.openscience.cdk.exception.CDKException { String s = "Numbers: "; for (int f = 0; f < ac.getAtomCount(); f++) { s += (mol.getAtomNumber(ac.getAtom(f)) + 1) + " "; } return s; } /** * Returns a string with the numbers of all atoms in a Vector relative to a * given molecule. I.e. the number the is listesd is the position of each atom * in the molecule. * *@param ac The Vector for which the placed atoms are to * be listed *@param mol Description of the Parameter *@return A string with the numbers of all placed * atoms in an AtomContainer *@exception java.lang.Exception Description of the Exception */ public String listNumbers(IAtomContainer mol, Vector ac) throws java.lang.Exception { String s = "Numbers: "; for (int f = 0; f < ac.size(); f++) { s += (mol.getAtomNumber((IAtom) ac.elementAt(f)) + 1) + " "; } return s; } /** * True is all the atoms in the given AtomContainer have been placed * *@param ac The AtomContainer to be searched *@return True is all the atoms in the given AtomContainer have been placed */ public boolean allPlaced(IAtomContainer ac) { for (int f = 0; f < ac.getAtomCount(); f++) { if (!ac.getAtom(f).getFlag(CDKConstants.ISPLACED)) { return false; } } return true; } /** * Marks all the atoms in the given AtomContainer as not placed * *@param ac The AtomContainer whose atoms are to be marked */ public void markNotPlaced(IAtomContainer ac) { for (int f = 0; f < ac.getAtomCount(); f++) { ac.getAtom(f).setFlag(CDKConstants.ISPLACED, false); } } /** * Marks all the atoms in the given AtomContainer as placed * *@param ac The AtomContainer whose atoms are to be marked */ public void markPlaced(IAtomContainer ac) { for (int f = 0; f < ac.getAtomCount(); f++) { ac.getAtom(f).setFlag(CDKConstants.ISPLACED, true); } } /** * Get all the placed atoms in an AtomContainer * *@param ac The AtomContainer to be searched for placed atoms *@return An AtomContainer containing all the placed atoms */ public IAtomContainer getPlacedAtoms(IAtomContainer ac) { IAtomContainer ret = ac.getBuilder().newAtomContainer(); for (int f = 0; f < ac.getAtomCount(); f++) { if (ac.getAtom(f).getFlag(CDKConstants.ISPLACED)) { ret.addAtom(ac.getAtom(f)); } } return ret; } /** * Sums up the degrees of atoms in an atomcontainer * *@param ac The atomcontainer to be processed *@param superAC The superAtomContainer from which the former has been derived * *@return */ int getDegreeSum(IAtomContainer ac, IAtomContainer superAC) { int degreeSum = 0; //String path = "DegreeSum for Path: "; for (int f = 0; f < ac.getAtomCount(); f++) { //path += ac.getAtom(f).getSymbol(); degreeSum += superAC.getConnectedBondsCount(ac.getAtom(f)); } //System.out.println(path + ": " + degreeSum); return degreeSum; } /** * Calculates weights for unplaced atoms. * *@param ac The atomcontainer for which weights are to be calculated */ void calculateWeights(IAtomContainer ac) { int[] weights = getWeightNumbers(ac); for (int f = 0; f < ac.getAtomCount(); f++) { ac.getAtom(f).setProperty("Weight", new Integer(weights[f])); } } /** * Makes an array containing morgan-number-like number for an atomContainer. * *@param atomContainer The atomContainer to analyse. *@return The morgan numbers value. */ int[] getWeightNumbers(IAtomContainer atomContainer) { int[] morganMatrix; int[] tempMorganMatrix; int N = atomContainer.getAtomCount(); morganMatrix = new int[N]; tempMorganMatrix = new int[N]; java.util.List atoms = null; for (int f = 0; f < N; f++) { morganMatrix[f] = atomContainer.getConnectedBondsCount(f); tempMorganMatrix[f] = atomContainer.getConnectedBondsCount(f); } for (int e = 0; e < N; e++) { for (int f = 0; f < N; f++) { morganMatrix[f] = 0; atoms = atomContainer.getConnectedAtomsList(atomContainer.getAtom(f)); for (int g = 0; g < atoms.size(); g++) { IAtom atom = (IAtom)atoms.get(g); if (!atom.getFlag(CDKConstants.ISPLACED)) { morganMatrix[f] += tempMorganMatrix[atomContainer.getAtomNumber(atom)]; } } } System.arraycopy(morganMatrix, 0, tempMorganMatrix, 0, N); } return tempMorganMatrix; } public boolean shouldBeLinear(IAtom atom, IAtomContainer molecule) { int sum = 0; java.util.List bonds = molecule.getConnectedBondsList(atom); for (int g = 0; g < bonds.size(); g++) { IBond bond = (IBond)bonds.get(g); if (bond.getOrder() == 3) sum += 10; else if (bond.getOrder() == 1) sum += 1;// else if (bond.getOrder() == 2) sum += 5; } if (sum >= 10) return true; return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -