class GeometryTools {

    public static Map<Integer, Integer> mapAtomsOfAlignedStructures(IAtomContainer firstAtomContainer,
            IAtomContainer secondAtomContainer, double searchRadius, Map<Integer, Integer> 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");
         * for (int j=0;j<secondAtomContainer.getAtomCount();j++){
         * tmp=Math.floor(distanceMatrix[i][j]*10); //logger.debug(tmp/10+"\t");
         * } }
         */

        double minimumDistance;
        for (int i = 0; i < firstAtomContainer.getAtomCount(); i++) {
            minimumDistance = searchRadius;
            for (int j = 0; j < secondAtomContainer.getAtomCount(); j++) {
                if (distanceMatrix[i][j] < searchRadius && distanceMatrix[i][j] < minimumDistance) {
                    //logger.debug("Distance OK "+i+" "+j+":"+distanceMatrix[i][j]+" AtomCheck:"+checkAtomMapping(firstAtomContainer,secondAtomContainer, i, j));
                    //check atom properties
                    if (checkAtomMapping(firstAtomContainer, secondAtomContainer, i, j)) {
                        minimumDistance = distanceMatrix[i][j];
                        mappedAtoms.put(firstAtomContainer.indexOf(firstAtomContainer.getAtom(i)),
                                secondAtomContainer.indexOf(secondAtomContainer.getAtom(j)));
                        //firstAtomContainer.getAtomAt(i).setProperty("MappedAtom",new Integer(secondAtomContainer.indexOf(secondAtomContainer.getAtomAt(j))));
                        //logger.debug("#:"+countMappedAtoms+" Atom:"+i+" is mapped to Atom"+j);
                        //logger.debug(firstAtomContainer.getConnectedAtoms(firstAtomContainer.getAtomAt(i)).length);
                    }
                }
            }
        }
        return mappedAtoms;
    }

}