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

📄 geometrytoolsinternalcoordinates.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		Point2d com = get2DCentreOfMass(atomCon);		Vector2d translation = new Vector2d(p.x - com.x, p.y - com.y);		java.util.Iterator atoms = atomCon.atoms();		while (atoms.hasNext()) {			IAtom atom = (IAtom)atoms.next();			if (atom.getPoint2d() != null) {				atom.getPoint2d().add(translation);			}		}	}	/**	 *  Calculates the center of the given atoms and returns it as a Point2d	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  atoms  The vector of the given atoms	 *@return        The center of the given atoms as Point2d	 */	public static Point2d get2DCenter(IAtom[] atoms) {		IAtom atom;		double x = 0;		double y = 0;		for (int f = 0; f < atoms.length; f++) {			atom = atoms[f];			if (atom.getPoint2d() != null) {				x += atom.getPoint2d().x;				y += atom.getPoint2d().y;			}		}		return new Point2d(x / (double) atoms.length, y / (double) atoms.length);	}		/**	 *  Calculates the center of the given atoms and returns it as a Point2d	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  atoms  The Iterator of the given atoms	 *@return        The center of the given atoms as Point2d	 */	public static Point2d get2DCenter(java.util.Iterator atoms) {		IAtom atom;		double x = 0;		double y = 0;		int length = 0;		while (atoms.hasNext()) {			atom = (IAtom)atoms.next();			if (atom.getPoint2d() != null) {				x += atom.getPoint2d().x;				y += atom.getPoint2d().y;			}			++length;		}		return new Point2d(x / (double) length, y / (double) length);	}		/**	 *  Returns the geometric center of all the rings in this ringset.	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  ringSet  Description of the Parameter	 *@return          the geometric center of the rings in this ringset	 */	public static Point2d get2DCenter(IRingSet ringSet) {		double centerX = 0;		double centerY = 0;		for (int i = 0; i < ringSet.getAtomContainerCount(); i++) {			Point2d centerPoint = GeometryToolsInternalCoordinates.get2DCenter((org.openscience.cdk.interfaces.IRing)ringSet.getAtomContainer(i));			centerX += centerPoint.x;			centerY += centerPoint.y;		}        return new Point2d(centerX / ((double) ringSet.getAtomContainerCount()), centerY / ((double) ringSet.getAtomContainerCount()));	}	/**	 *  Calculates the center of mass for the <code>Atom</code>s in the	 *  AtomContainer for the 2D coordinates.	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  ac      AtomContainer for which the center of mass is calculated	 *@return         Description of the Return Value	 *@cdk.keyword    center of mass	 */	public static Point2d get2DCentreOfMass(IAtomContainer ac) {		double x = 0.0;		double y = 0.0;		double totalmass = 0.0;		java.util.Iterator atoms = ac.atoms();		while (atoms.hasNext()) {			IAtom a = (IAtom) atoms.next();			double mass = a.getExactMass();			totalmass += mass;			x += mass * a.getPoint2d().x;			y += mass * a.getPoint2d().y;		}		return new Point2d(x / totalmass, y / totalmass);	}	/**	 *  Returns the geometric center of all the atoms in the atomContainer.	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  container  Description of the Parameter	 *@return            the geometric center of the atoms in this atomContainer	 */	public static Point2d get2DCenter(IAtomContainer container) {		double centerX = 0;		double centerY = 0;		double counter = 0;		java.util.Iterator atoms = container.atoms();		while (atoms.hasNext()) {			IAtom atom = (IAtom)atoms.next();			if (atom.getPoint2d() != null) {				centerX += atom.getPoint2d().x;				centerY += atom.getPoint2d().y;				counter++;			}		}        return new Point2d(centerX / (counter), centerY / (counter));	}		/**	 *  Translates the geometric 2DCenter of the given	 *  AtomContainer container to the specified Point2d p.	 *	 *@param  container  AtomContainer which should be translated.	 *@param  p          New Location of the geometric 2D Center.	 *@see #get2DCenter	 *@see #translate2DCentreOfMassTo	 */	public static void translate2DCenterTo(IAtomContainer container, Point2d p) {		Point2d com = get2DCenter(container);		Vector2d translation = new Vector2d(p.x - com.x, p.y - com.y);		java.util.Iterator atoms = container.atoms();		while (atoms.hasNext()) {			IAtom atom = (IAtom)atoms.next();			if (atom.getPoint2d() != null) {				atom.getPoint2d().add(translation);			}		}	}	/**	 *  Calculates the center of mass for the <code>Atom</code>s in the	 *  AtomContainer for the 2D coordinates.	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  ac      AtomContainer for which the center of mass is calculated	 *@return         Description of the Return Value	 *@cdk.keyword    center of mass     * @cdk.dictref   blue-obelisk:calculate3DCenterOfMass	 */	public static Point3d get3DCentreOfMass(IAtomContainer ac) {		double x = 0.0;		double y = 0.0;		double z = 0.0;		double totalmass = 0.0;		java.util.Iterator atoms = ac.atoms();		while (atoms.hasNext()) {			IAtom a = (IAtom)atoms.next();			double mass = a.getExactMass();			totalmass += mass;			x += mass * a.getPoint3d().x;			y += mass * a.getPoint3d().y;			z += mass * a.getPoint3d().z;		}		return new Point3d(x / totalmass, y / totalmass, z / totalmass);	}	/**	 *  Returns the geometric center of all the atoms in this atomContainer.	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  ac  Description of the Parameter	 *@return     the geometric center of the atoms in this atomContainer	 */	public static Point3d get3DCenter(IAtomContainer ac) {		double centerX = 0;		double centerY = 0;		double centerZ = 0;		double counter = 0;		java.util.Iterator atoms = ac.atoms();		while (atoms.hasNext()) {			IAtom atom = (IAtom)atoms.next();			if (atom.getPoint3d() != null) {				centerX += atom.getPoint3d().x;				centerY += atom.getPoint3d().y;				centerZ += atom.getPoint3d().z;				counter++;			}		}        return new Point3d(centerX / (counter), centerY / (counter), centerZ / (counter));	}	/**	 *  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) {		double angle = 0;//		logger.debug("getAngle->xDiff: " + xDiff);//		logger.debug("getAngle->yDiff: " + yDiff);		if (xDiff >= 0 && yDiff >= 0) {			angle = Math.atan(yDiff / xDiff);		} else if (xDiff < 0 && yDiff >= 0) {			angle = Math.PI + Math.atan(yDiff / xDiff);		} else if (xDiff < 0 && yDiff < 0) {			angle = Math.PI + Math.atan(yDiff / xDiff);		} else if (xDiff >= 0 && yDiff < 0) {			angle = 2 * Math.PI + Math.atan(yDiff / xDiff);		}		return angle;	}	/**	 *  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) {		double angle;		if ((coords[2] - coords[0]) == 0) {			angle = Math.PI / 2;		} else {			angle = Math.atan(((double) coords[3] - (double) coords[1]) / ((double) coords[2] - (double) coords[0]));		}		int begin1X = (int) (Math.cos(angle + Math.PI / 2) * dist + coords[0]);		int begin1Y = (int) (Math.sin(angle + Math.PI / 2) * dist + coords[1]);		int begin2X = (int) (Math.cos(angle - Math.PI / 2) * dist + coords[0]);		int begin2Y = (int) (Math.sin(angle - Math.PI / 2) * dist + coords[1]);		int end1X = (int) (Math.cos(angle - Math.PI / 2) * dist + coords[2]);		int end1Y = (int) (Math.sin(angle - Math.PI / 2) * dist + coords[3]);		int end2X = (int) (Math.cos(angle + Math.PI / 2) * dist + coords[2]);		int end2Y = (int) (Math.sin(angle + Math.PI / 2) * dist + coords[3]);        return new int[]{begin1X, begin1Y, begin2X, begin2Y, end1X, end1Y, end2X, end2Y};	}	/**	 *  Writes the coordinates of the atoms participating the given bond into an	 *  array.	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  bond  The given bond	 *@return       The array with the coordinates	 */	public static int[] getBondCoordinates(IBond bond) {		if (bond.getAtom(0).getPoint2d() == null ||				bond.getAtom(1).getPoint2d() == null) {			logger.error("getBondCoordinates() called on Bond without 2D coordinates!");			return new int[0];		}		int beginX = (int) bond.getAtom(0).getPoint2d().x;		int endX = (int) bond.getAtom(1).getPoint2d().x;		int beginY = (int) bond.getAtom(0).getPoint2d().y;		int endY = (int) bond.getAtom(1).getPoint2d().y;        return new int[]{beginX, beginY, endX, endY};	}	/**	 *  Returns the atom of the given molecule that is closest to the given	 *  coordinates.	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  xPosition  The x coordinate	 *@param  yPosition  The y coordinate	 *@param  atomCon    The molecule that is searched for the closest atom	 *@return            The atom that is closest to the given coordinates	 */	public static IAtom getClosestAtom(int xPosition, int yPosition, IAtomContainer atomCon) {		IAtom closestAtom = null;		IAtom currentAtom;		double smallestMouseDistance = -1;		double mouseDistance;		double atomX;		double atomY;		for (int i = 0; i < atomCon.getAtomCount(); i++) {			currentAtom = atomCon.getAtom(i);			atomX = currentAtom.getPoint2d().x;			atomY = currentAtom.getPoint2d().y;			mouseDistance = Math.sqrt(Math.pow(atomX - xPosition, 2) + Math.pow(atomY - yPosition, 2));			if (mouseDistance < smallestMouseDistance || smallestMouseDistance == -1) {				smallestMouseDistance = mouseDistance;				closestAtom = currentAtom;			}		}		return closestAtom;	}	/**	 *  Returns the bond of the given molecule that is closest to the given	 *  coordinates.	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  xPosition  The x coordinate	 *@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) {		Point2d bondCenter;		IBond closestBond = null;		double smallestMouseDistance = -1;		double mouseDistance;        Iterator bonds = atomCon.bonds();        while (bonds.hasNext()) {            IBond currentBond =  (IBond) bonds.next();			bondCenter = get2DCenter(currentBond.atoms());			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;	}

⌨️ 快捷键说明

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