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

📄 geometrytools.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		minmax[1] = minY;		minmax[2] = maxX;		minmax[3] = maxY;		return minmax;	}	/**	 *  Translates a molecule from the origin to a new point denoted by a vector, using an external set of coordinates.	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  atomCon  molecule to be translated	 *@param  vector   dimension that represents the translation vector	 *@param   renderingCoordinates  The set of coordinates to use coming from RendererModel2D	 */	public static void translate2D(IAtomContainer atomCon, Vector2d vector, HashMap renderingCoordinates) {		java.util.Iterator atoms = atomCon.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));			}			if (renderingCoordinates.get(atom) != null) {				((Point2d)renderingCoordinates.get(atom)).add(vector);			} else {				logger.warn("Could not translate atom in 2D space");			}		}	}		/**	 *  Translates a molecule from the origin to a new point denoted by a vector.	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  atomCon  molecule to be translated	 *@param  p        Description of the Parameter	 */	public static void translate2DCentreOfMassTo(IAtomContainer atomCon, Point2d p, HashMap renderingCoordinates) {		Point2d com = get2DCentreOfMass(atomCon, renderingCoordinates);		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 (renderingCoordinates.get(atom) != null) {				((Point2d)renderingCoordinates.get(atom)).add(translation);			}		}	}		/**	 *  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, HashMap renderingCoordinates) {		Point2d com = get2DCenter(container, renderingCoordinates);		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 (renderingCoordinates.get(atom) != null) {				((Point2d)renderingCoordinates.get(atom)).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	 */	public static Point2d get2DCentreOfMass(IAtomContainer ac, HashMap renderingCoordinates) {		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 * ((Point2d)renderingCoordinates.get(a)).x;			y += mass * ((Point2d)renderingCoordinates.get(a)).y;		}		return new Point2d(x / totalmass, y / totalmass);	}	/**	 *  Centers the molecule in the given area, using an external set of coordinates	 *  Attention: Many methods in this class working on coordinates exist in two versions: One with a HashMap as last parameter, one without	 *  this. The difference is as follows: The methods without the HashMap change the coordinates in the Atoms of the AtomContainer. The methods with the HashMaps	 *  expect in this HashMaps pairs of atoms and Point2ds. They work on the Point2ds associated with a particular atom and leave the atom itself	 *  unchanged. If there is no entry in the HashMap for an atom, they put the coordinates from the Atom in this HashMap and then work on the HashMap.	 *	 *	 *@param  atomCon  molecule to be centered	 *@param  areaDim  dimension in which the molecule is to be centered	 *@param   renderingCoordinates  The set of coordinates to use coming from RendererModel2D	 */	public static void center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) {		Dimension molDim = get2DDimension(atomCon, renderingCoordinates);		int transX = (areaDim.width - molDim.width) / 2;		int transY = (areaDim.height - molDim.height) / 2;		translateAllPositive(atomCon,renderingCoordinates);		translate2D(atomCon, new Vector2d(transX, transY),renderingCoordinates);	}	/**	 *  Calculates the center of the given atoms and returns it as a Point2d, using	 *  an external set of coordinates	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  atoms  The vector of the given atoms	 *@param   renderingCoordinates  The set of coordinates to use coming from RendererModel2D	 *@return        The center of the given atoms as Point2d	 *	 */	public static Point2d get2DCenter(IAtom[] atoms, HashMap renderingCoordinates) {		IAtom atom;		double x = 0;		double y = 0;		for (int f = 0; f < atoms.length; f++) {			atom = atoms[f];			if (renderingCoordinates.get(atom) != null) {				x += ((Point2d)renderingCoordinates.get(atom)).x;				y += ((Point2d)renderingCoordinates.get(atom)).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, using	 *  an external set of coordinates	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  atoms  The Iterator of the given atoms	 *@param   renderingCoordinates  The set of coordinates to use coming from RendererModel2D	 *@return        The center of the given atoms as Point2d	 *	 */	public static Point2d get2DCenter(Iterator atoms, HashMap renderingCoordinates) {		IAtom atom;		double x = 0;		double y = 0;		int length = 0;		while (atoms.hasNext()) {			atom = (IAtom)atoms.next();			if (renderingCoordinates.get(atom) != null) {				x += ((Point2d)renderingCoordinates.get(atom)).x;				y += ((Point2d)renderingCoordinates.get(atom)).y;			}			++length;		}		return new Point2d(x / (double) length, y / (double) length);	}		/**	 *  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	 **@param   renderingCoordinates  The set of coordinates to use coming from RendererModel2D	 *@return            the geometric center of the atoms in this atomContainer	 */	public static Point2d get2DCenter(IAtomContainer container, HashMap renderingCoordinates) {		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 += ((Point2d)renderingCoordinates.get(atom)).x;				centerY += ((Point2d)renderingCoordinates.get(atom)).y;				counter++;			}		}        return new Point2d(centerX / (counter), centerY / (counter));	}			/**	 *  Writes the coordinates of the atoms participating the given bond into an	 *  array, using renderingCoordinates, using an external set of coordinates.	 *  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets	 *	 *@param  bond  The given bond	 *@param  renderingCoordinates  The set of coordinates to use coming from RendererModel2D	 *@return       The array with the coordinates	 */	public static int[] getBondCoordinates(IBond bond, HashMap renderingCoordinates) {		if (renderingCoordinates.get(bond.getAtom(0)) == null && bond.getAtom(0).getPoint2d()!=null) {			renderingCoordinates.put(bond.getAtom(0),new Point2d(bond.getAtom(0).getPoint2d().x,bond.getAtom(0).getPoint2d().y));		}		if (renderingCoordinates.get(bond.getAtom(1)) == null && bond.getAtom(1).getPoint2d()!=null) {			renderingCoordinates.put(bond.getAtom(1),new Point2d(bond.getAtom(1).getPoint2d().x,bond.getAtom(1).getPoint2d().y));		}		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) ((Point2d)renderingCoordinates.get(bond.getAtom(0))).x;		int endX = (int) ((Point2d)renderingCoordinates.get(bond.getAtom(1))).x;		int beginY = (int) ((Point2d)renderingCoordinates.get(bond.getAtom(0))).y;		int endY = (int) ((Point2d)renderingCoordinates.get(bond.getAtom(1))).y;        return new int[]{beginX, beginY, endX, endY};	}    /**     * Returns the atom of the given molecule that is closest to the given     * coordinates, using an external set of 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 renderingCoordinates The set of coordinates to use coming from RendererModel2D     * @return The atom that is closest to the given coordinates     */    public static IAtom getClosestAtom(int xPosition, int yPosition, IChemModel model, IAtom ignore, HashMap renderingCoordinates) {        IAtom closestAtom = null;        IAtom currentAtom;        double smallestMouseDistance = -1;        double mouseDistance;        double atomX;        double atomY;        List atomContainerList = ChemModelManipulator.getAllAtomContainers(model);        Iterator iterator = atomContainerList.iterator();        while(iterator.hasNext())        {        	IAtomContainer ac = (IAtomContainer)iterator.next();            for (int j = 0; j < ac.getAtomCount(); j++) {                currentAtom = ac.getAtom(j);                if (renderingCoordinates.get(currentAtom) == null && currentAtom.getPoint2d() != null) {                    renderingCoordinates.put(currentAtom, new Point2d(currentAtom.getPoint2d().x, currentAtom.getPoint2d().y));                }                if (currentAtom != ignore && renderingCoordinates.get(currentAtom) != null) {                    atomX = ((Point2d) renderingCoordinates.get(currentAtom)).x;                    atomY = ((Point2d) renderingCoordinates.get(currentAtom)).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

⌨️ 快捷键说明

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