A real space approach to electronic structure calculations has several important advantages. A regular real-space mesh produces a sparse, local, and highly structured Hamiltonian, which enables effective use of iterative numerical methods and parallel computer architectures. However, a regular real space mesh has equal resolution everywhere, while actual physical systems are inhomogeneous. To remedy this inherent inefficiency without losing the advantages of a regular mesh, we carry out computations on a regular mesh in curvilinear space. There are several choices involved in the implementation of the method. These include the choice of the coordinate transform, the form of the discretized Laplacian, the regularization of the ionic potential for all-electron calculations, and the method of calculating the forces. Of particular interest is the use of error analysis to optimize the grid for a given physical system. The adaptive grid is versatile enough to describe accurately a very wide class of systems, including ones with highly inhomogeneous electronic distributions. We report all-electron calculations for atoms and molecules with is and 2p valence electrons, and pseudopotential calculations for molecules and solids.