A general real-space multigrid algorithm for the self-consistent solution o
f the Kohn-Sham equations appearing in the state-of-the-art electronic-stru
cture calculations is described. The most important part of the method is t
he multigrid solver for the Schrodinger equation. Our choice is the Rayleig
h quotient multigrid method (RQMG), which applies directly to the minimizat
ion of the Rayleigh quotient on the finest level. Very coarse correction gr
ids can be used, because there is, in principle, no need to represent the s
tates on the coarse levels. The RQMG method is generalized for the simultan
eous solution of all the states of the system using a penalty functional to
keep the states orthogonal. The performance of the scheme is demonstrated
by applying it in a few molecular and solid-state systems described by nonl
ocal norm-conserving pseudopotentials.