code: public Point3d getGridPointFrom3dCoordinates(Point3d coord) throws Exception {
          Point3d gridPoint = new Point3d();
  
          if (coord.x >= minx & coord.x <= maxx) {
              gridPoint.x = (int) Math.round(Math.abs(minx - coord.x) / latticeConstant);
          } else {
              throw new Exception("CDKGridError: Given coordinates are not in grid");
          }
          if (coord.y >= miny & coord.y <= maxy) {
              gridPoint.y = (int) Math.round(Math.abs(miny - coord.y) / latticeConstant);
          } else {
              throw new Exception("CDKGridError: Given coordinates are not in grid");
          }
          if (coord.z >= minz & coord.z <= maxz) {
              gridPoint.z = (int) Math.round(Math.abs(minz - coord.z) / latticeConstant);
          } else {
              throw new Exception("CDKGridError: Given coordinates are not in grid");
          }
  
          return gridPoint;
      }
docs: Method calculates the nearest grid point from given coordinates.