📄 geometrytoolsinternalcoordinates.java
字号:
/** * Sorts a Vector of atoms such that the 2D distances of the atom locations * from a given point are smallest for the first atoms in the vector * See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets * *@param point The point from which the distances to the atoms are measured *@param atoms The atoms for which the distances to point are measured */ public static void sortBy2DDistance(IAtom[] atoms, Point2d point) { double distance1; double distance2; IAtom atom1; IAtom atom2; boolean doneSomething; do { doneSomething = false; for (int f = 0; f < atoms.length - 1; f++) { atom1 = atoms[f]; atom2 = atoms[f + 1]; distance1 = point.distance(atom1.getPoint2d()); distance2 = point.distance(atom2.getPoint2d()); if (distance2 < distance1) { atoms[f] = atom2; atoms[f + 1] = atom1; doneSomething = true; } } } while (doneSomething); } /** * Determines the scale factor for displaying a structure loaded from disk in * a frame. An average of all bond length values is produced and a scale * factor is determined which would scale the given molecule such that its * See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets * *@param ac The AtomContainer for which the ScaleFactor is to be * calculated *@param bondLength The target bond length *@return The ScaleFactor with which the AtomContainer must be * scaled to have the target bond length */ public static double getScaleFactor(IAtomContainer ac, double bondLength) { double currentAverageBondLength = getBondLengthAverage(ac); if(currentAverageBondLength==0 || Double.isNaN(currentAverageBondLength)) return 1; return bondLength / currentAverageBondLength; } /** * An average of all 2D bond length values is produced. Bonds which have * Atom's with no coordinates are disregarded. * See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets * *@param ac The AtomContainer for which the average bond length is to be * calculated *@return the average bond length */ public static double getBondLengthAverage(IAtomContainer ac) { double bondLengthSum = 0; Iterator bonds = ac.bonds(); int bondCounter = 0; while (bonds.hasNext()) { IBond bond = (IBond) bonds.next(); org.openscience.cdk.interfaces.IAtom atom1 = bond.getAtom(0); org.openscience.cdk.interfaces.IAtom atom2 = bond.getAtom(1); if (atom1.getPoint2d() != null && atom2.getPoint2d() != null) { bondCounter++; bondLengthSum += getLength2D(bond); } } return bondLengthSum / bondCounter; } /** * Returns the geometric length of this bond in 2D space. * See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets * *@param bond Description of the Parameter *@return The geometric length of this bond */ public static double getLength2D(IBond bond) { if (bond.getAtom(0) == null || bond.getAtom(1) == null) { return 0.0; } Point2d p1 = bond.getAtom(0).getPoint2d(); Point2d p2 = bond.getAtom(1).getPoint2d(); if (p1 == null || p2 == null) { return 0.0; } return p1.distance(p2); } /** * Determines if this AtomContainer contains 2D coordinates. * See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets * *@param m Description of the Parameter *@return boolean indication that 2D coordinates are available */ public static boolean has2DCoordinates(IAtomContainer m) { return has2DCoordinatesNew(m)>0; } /** * Determines if this AtomContainer contains 2D coordinates for some or all molecules. * See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets * *@param m Description of the Parameter *@return 0 no 2d, 1=some, 2= for each atom */ public static int has2DCoordinatesNew(IAtomContainer ac) { boolean no2d=false; boolean with2d=false; java.util.Iterator atoms = ac.atoms(); while (atoms.hasNext()) { IAtom atom = (IAtom)atoms.next(); if (atom.getPoint2d() == null) { no2d=true; }else{ with2d=true; } } if(!no2d && with2d){ return 2; } else if(no2d && with2d){ return 1; } else{ return 0; } } /** * Determines if this Atom contains 2D coordinates. * See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets * *@param a Description of the Parameter *@return boolean indication that 2D coordinates are available */ public static boolean has2DCoordinates(IAtom a) { return (a.getPoint2d() != null); } /** * Determines if this Bond contains 2D coordinates. * See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets * *@param b Description of the Parameter *@return boolean indication that 2D coordinates are available */ public static boolean has2DCoordinates(IBond b) { java.util.Iterator atoms = b.atoms(); while (atoms.hasNext()) { IAtom atom = (IAtom)atoms.next(); if (atom.getPoint2d() == null) { return false; } } return true; } /** * Determines if this model contains 3D coordinates * *@param m Description of the Parameter *@return boolean indication that 3D coordinates are available */ public static boolean has3DCoordinates(IAtomContainer ac) { boolean hasinfo = true; java.util.Iterator atoms = ac.atoms(); while (atoms.hasNext()) { IAtom atom = (IAtom)atoms.next(); if (atom.getPoint3d() == null) { return false; } } return hasinfo; } /** * Determines the normalized vector orthogonal on the vector p1->p2. * *@param p1 Description of the Parameter *@param p2 Description of the Parameter *@return Description of the Return Value */ public static Vector2d calculatePerpendicularUnitVector(Point2d p1, Point2d p2) { Vector2d v = new Vector2d(); v.sub(p2, p1); v.normalize(); // Return the perpendicular vector return new Vector2d(-1.0 * v.y, v.x); } /** * Calculates the normalization factor in order to get an average bond length * of 1.5. It takes only into account Bond's with two atoms. * See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets * *@param container Description of the Parameter *@return The normalizationFactor value */ public static double getNormalizationFactor(IAtomContainer container) { double bondlength = 0.0; double ratio; /* * Desired bond length for storing structures in MDL mol files * This should probably be set externally (from system wide settings) */ double desiredBondLength = 1.5; // loop over all bonds and determine the mean bond distance int counter = 0; Iterator bonds = container.bonds(); while (bonds.hasNext()) { IBond bond = (IBond) bonds.next(); // only consider two atom bonds into account if (bond.getAtomCount() == 2) { counter++; org.openscience.cdk.interfaces.IAtom atom1 = bond.getAtom(0); org.openscience.cdk.interfaces.IAtom atom2 = bond.getAtom(1); bondlength += Math.sqrt(Math.pow(atom1.getPoint2d().x - atom2.getPoint2d().x, 2) + Math.pow(atom1.getPoint2d().y - atom2.getPoint2d().y, 2)); } } bondlength = bondlength / counter; ratio = desiredBondLength / bondlength; return ratio; } /** * Determines the best alignment for the label of an atom in 2D space. It * returns 1 if left aligned, and -1 if right aligned. * See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets * *@param container Description of the Parameter *@param atom Description of the Parameter *@return The bestAlignmentForLabel value */ public static int getBestAlignmentForLabel(IAtomContainer container, IAtom atom) { java.util.Iterator connectedAtoms = container.getConnectedAtomsList(atom).iterator(); int overallDiffX = 0; while (connectedAtoms.hasNext()) { IAtom connectedAtom = (IAtom)connectedAtoms.next(); overallDiffX = overallDiffX + (int) (connectedAtom.getPoint2d().x - atom.getPoint2d().x); } if (overallDiffX <= 0) { return 1; } else { return -1; } } /** * Returns the atoms which are closes to an atom in an AtomContainer by * distance in 3d. * *@param ac The AtomContainer to examine *@param a the atom to start from *@param max the number of neighbours to return *@return the average bond length *@exception CDKException Description of the Exception */ public static Vector findClosestInSpace(IAtomContainer ac, IAtom a, int max) throws CDKException { java.util.Iterator atoms = ac.atoms(); Point3d originalPoint = a.getPoint3d(); if (originalPoint == null) { throw new CDKException("No point3d, but findClosestInSpace is working on point3ds"); } Map hm = new TreeMap(); while (atoms.hasNext()) { IAtom atom = (IAtom)atoms.next(); if (atom != a) { if (atom.getPoint3d() == null) { throw new CDKException("No point3d, but findClosestInSpace is working on point3ds"); } double distance = atom.getPoint3d().distance(originalPoint); hm.put(new Double(distance), atom); } } Set ks = hm.keySet(); Iterator it = ks.iterator(); Vector returnValue = new Vector(); int i = 0; while (it.hasNext() && i < max) { returnValue.add(hm.get(it.next())); i++; } return (returnValue); } /** * Returns a Map with the AtomNumbers, the first number corresponds to the first (or the largest * AtomContainer) atomcontainer. It is recommend to sort the atomContainer due to their number of atoms before * calling this function. * * The molecules needs to be aligned before! (coordinates are needed) * *@param firstAtomContainer the (largest) first aligned AtomContainer which is the reference *@param secondAtomContainer the second aligned AtomContainer *@param searchRadius the radius of space search from each atom *@return a Map of the mapped atoms *@exception CDKException Description of the Exception */ public static Map mapAtomsOfAlignedStructures(IAtomContainer firstAtomContainer, IAtomContainer secondAtomContainer, double searchRadius, Map mappedAtoms)throws CDKException { //to return the mapping setProperty("MappedAtom",AtomNumber) //logger.debug("**** MAP ATOMS ****"); getLargestAtomContainer(firstAtomContainer,secondAtomContainer); double[][] distanceMatrix=new double[firstAtomContainer.getAtomCount()][secondAtomContainer.getAtomCount()]; for (int i=0;i<firstAtomContainer.getAtomCount();i++){ Point3d firstAtomPoint=firstAtomContainer.getAtom(i).getPoint3d(); //logger.debug("Closest atoms of "+firstAtomContainer.getAtoms()[i].getSymbol()+" :"); for (int j=0;j<secondAtomContainer.getAtomCount();j++){ distanceMatrix[i][j]=firstAtomPoint.distance(secondAtomContainer.getAtom(j).getPoint3d()); //logger.debug("Distance "+i+" "+j+":"+distanceMatrix[i][j]); } //logger.debug(" Atoms from the secondAtomContainer"); } //logger.debug(); //logger.debug("\t"); //for (int j=0;j<secondAtomContainer.getAtomCount();j++){ //logger.debug(j+" "+secondAtomContainer.getAtomAt(j).getSymbol()+"\t"); //} //DEBUGG /*double tmp=0; for(int i=0;i<firstAtomContainer.getAtomCount();i++){ //logger.debug(i+" "+firstAtomContainer.getAtomAt(i).getSymbol()+"\t");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -