⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 geometrytools.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 *@param  yPosition  The y coordinate	 *@param  atomCon    The molecule that is searched for the closest bond	 *@return            The bond that is closest to the given coordinates	 */	public static IBond getClosestBond(int xPosition, int yPosition, IAtomContainer atomCon, HashMap renderingCoordinates) {		Point2d bondCenter;		IBond closestBond = null;		double smallestMouseDistance = -1;		double mouseDistance;//		IBond[] bonds = atomCon.getBonds();        Iterator bonds = atomCon.bonds();        while (bonds.hasNext()) {            IBond currentBond = (IBond) bonds.next();                   			bondCenter = get2DCenter(currentBond.atoms(),renderingCoordinates);			mouseDistance = Math.sqrt(Math.pow(bondCenter.x - xPosition, 2) + Math.pow(bondCenter.y - yPosition, 2));			if (mouseDistance < smallestMouseDistance || smallestMouseDistance == -1) {				smallestMouseDistance = mouseDistance;				closestBond = currentBond;			}		}		return closestBond;	}	/**	 *  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	 *@param   renderingCoordinates  The set of coordinates to use coming from RendererModel2D	 */	public static void sortBy2DDistance(IAtom[] atoms, Point2d point, HashMap renderingCoordinates) {		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];				if(renderingCoordinates.get(atom1)==null)					renderingCoordinates.put(atom1,atom1.getPoint2d());				if(renderingCoordinates.get(atom2)==null)					renderingCoordinates.put(atom2,atom2.getPoint2d());				distance1 = point.distance(((Point2d)renderingCoordinates.get(atom1)));				distance2 = point.distance(((Point2d)renderingCoordinates.get(atom2)));				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, using an external set of coordinates. 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	 *@param   renderingCoordinates  The set of coordinates to use coming from RendererModel2D	 *@return             The ScaleFactor with which the AtomContainer must be	 *      scaled to have the target bond length	 */	public static double getScaleFactor(IAtomContainer ac, double bondLength, HashMap renderingCoordinates) {		java.util.Iterator atoms = ac.atoms();		while (atoms.hasNext()) {			IAtom atom = (IAtom)atoms.next();			if (renderingCoordinates.get(atom) == null && atom.getPoint2d()!=null) {				renderingCoordinates.put(atom,new Point2d(atom.getPoint2d().x,atom.getPoint2d().y));			}		}		double currentAverageBondLength = getBondLengthAverage(ac,renderingCoordinates);		if(currentAverageBondLength==0 || Double.isNaN(currentAverageBondLength))			return 1;		return bondLength / currentAverageBondLength;	}	/**	 *  An average of all 2D bond length values is produced, using an external set of coordinates. 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	 *@param   renderingCoordinates  The set of coordinates to use coming from RendererModel2D	 *@return     the average bond length	 */	public static double getBondLengthAverage(IAtomContainer ac, HashMap renderingCoordinates) {		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 (renderingCoordinates.get(atom1) != null &&					renderingCoordinates.get(atom2) != null) {				bondCounter++;				bondLengthSum += getLength2D(bond, renderingCoordinates);			}		}		return bondLengthSum / bondCounter;	}	/**	 *  Returns the geometric length of this bond in 2D space, using an external set of coordinates	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  bond  Description of the Parameter	 *@param   renderingCoordinates  The set of coordinates to use coming from RendererModel2D	 *@return       The geometric length of this bond	 */	public static double getLength2D(IBond bond, HashMap renderingCoordinates) {		if (bond.getAtom(0) == null ||				bond.getAtom(1) == null) {			return 0.0;		}		Point2d p1 = ((Point2d)renderingCoordinates.get(bond.getAtom(0)));		Point2d p2 = ((Point2d)renderingCoordinates.get(bond.getAtom(1)));		if (p1 == null || p2 == null) {			return 0.0;		}		return p1.distance(p2);	}		/**	 *  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, HashMap renderingCoordinates) {		List connectedAtoms = container.getConnectedAtomsList(atom);		int overallDiffX = 0;		for (int i = 0; i < connectedAtoms.size(); i++) {			IAtom connectedAtom = (IAtom)connectedAtoms.get(i);			overallDiffX = overallDiffX + (int) (((Point2d)renderingCoordinates.get(connectedAtom)).x - ((Point2d)renderingCoordinates.get(atom)).x);		}		if (overallDiffX <= 0) {			return 1;		} else {			return -1;		}	}		/**	 *  Gets the angle attribute of the GeometryTools class	 *	 *@param  xDiff  Description of the Parameter	 *@param  yDiff  Description of the Parameter	 *@return        The angle value	 */	public static double getAngle(double xDiff, double yDiff) {		return GeometryToolsInternalCoordinates.getAngle(xDiff, yDiff);	}	/**	 *  Gets the coordinates of two points (that represent a bond) and calculates	 *  for each the coordinates of two new points that have the given distance	 *  vertical to the bond.	 *	 *@param  coords  The coordinates of the two given points of the bond like this	 *      [point1x, point1y, point2x, point2y]	 *@param  dist    The vertical distance between the given points and those to	 *      be calculated	 *@return         The coordinates of the calculated four points	 */	public static int[] distanceCalculator(int[] coords, double dist) {		return GeometryToolsInternalCoordinates.distanceCalculator(coords, dist);	}		/**	 *  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 GeometryToolsInternalCoordinates.has2DCoordinatesNew(m)>0;	}		/**	 *  Determines if this model contains 3D coordinates	 *	 *@param  ac  Description of the Parameter	 *@return    boolean indication that 3D coordinates are available	 */	public static boolean has3DCoordinates(IChemModel model) {		Iterator containers = ChemModelManipulator.getAllAtomContainers(model).iterator();		while (containers.hasNext()) {			IAtomContainer ac = (IAtomContainer)containers.next();			boolean hasCoords = GeometryToolsInternalCoordinates.has3DCoordinates(ac); 			if (!hasCoords) return false; 		}		return true;	}			/**	 *  Determines if this model contains 3D coordinates	 *	 *@param  ac  Description of the Parameter	 *@return    boolean indication that 3D coordinates are available	 */	public static boolean has3DCoordinates(IAtomContainer ac) {		return GeometryToolsInternalCoordinates.has3DCoordinates(ac);	}		/**	 *  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  ac  Description of the Parameter	 *@return    0 no 2d, 1=some, 2= for each atom	 */	public static int has2DCoordinatesNew(IChemModel model) {		Iterator containers = ChemModelManipulator.getAllAtomContainers(model).iterator();		int oldCoords = -1;		while (containers.hasNext()) {			IAtomContainer ac = (IAtomContainer)containers.next();			int hasCoords = GeometryToolsInternalCoordinates.has2DCoordinatesNew(ac); 			if (hasCoords == 1) return 1;			if (oldCoords != -1 && oldCoords != hasCoords) return 1;			oldCoords = hasCoords;		}		return oldCoords;	}	/**	 *  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  ac  Description of the Parameter	 *@return    0 no 2d, 1=some, 2= for each atom	 */	public static int has2DCoordinatesNew(IAtomContainer ac) {		return  GeometryToolsInternalCoordinates.has2DCoordinatesNew(ac);	}		public static void makeRenderingCoordinates(IMoleculeSet molset, HashMap renderingCoordinates){		Iterator mols=molset.molecules();		while(mols.hasNext()){			IAtomContainer ac=(IAtomContainer)mols.next();			java.util.Iterator atoms = ac.atoms();			while (atoms.hasNext()) {				IAtom atom = (IAtom)atoms.next();				renderingCoordinates.put(atom,new Point2d(atom.getPoint2d().x,atom.getPoint2d().y));			}		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -