Getting the allelectron density¶
The variational quantity of the PAW formalism is the pseudodensity
\(\tilde{n}\). This is also the density returned by the
get_pseudo_density()
method of the GPAW
calculator. Sometimes it is desirable to work with the true allelectron
density. The PAW formalism offers a recipe for reconstructing the allelectron
density from the pseudodensity, and in GPAW, this can be reached by
the method get_all_electron_density()
of the
GPAW
class:

get_all_electron_density
(spin=None, gridrefinement=2, pad=True)¶ Return reconstructed allelectron density array.
The get_all_electron_density()
method is used in
the same way as you would normally use the
get_pseudo_density()
method, i.e.:
>>> from gpaw import GPAW
>>> from ase.build import molecule
>>> calc = GPAW()
>>> mol = molecule('C6H6', calculator=calc)
>>> mol.center(vacuum=5)
>>> E = mol.get_potential_energy()
>>> nt = calc.get_pseudo_density()
>>> n = calc.get_all_electron_density()
would give you the pseudodensity in nt
and the allelectron
density in n
.
As the allelectron density has more structure than the
pseudodensity, it is necessary to refine the density grid used to
represent the pseudodensity. This can be done using the
gridrefinement
keyword of the get_all_electron_density
method:
>>> n = calc.get_all_electron_density(gridrefinement=2)
Current only the values 1, 2, and 4 are supported (2 is default).
The allelectron density will always integrate to the total number of electrons of the considered system (independent of the grid resolution), while the pseudo density will integrate to some more or less arbitrary number. This fact is illustrated in the following example.
See also
Example: NaCl¶
As an example of application, consider the three systems Na, Cl, and
NaCl. The pseudo and allelectron densities of these three systems
can be calculated with the script NaCl.py
:
# Creates: all_electron.csv
from __future__ import print_function
import numpy as np
from ase.build import molecule
from gpaw import GPAW
from ase.parallel import paropen
unitcell = np.array([6.5, 6.6, 9.])
gridrefinement = 2
f = paropen('all_electron.csv', 'w')
for formula in ('Na', 'Cl', 'NaCl',):
calc = GPAW(xc='PBE',
h=0.18,
convergence={'eigenstates': 1e8},
txt=formula + '.txt')
if formula in ['Na', 'Cl']:
calc.set(hund=True)
sys = molecule(formula, cell=unitcell, calculator=calc)
sys.center()
sys.get_potential_energy()
# Get densities
nt = calc.get_pseudo_density()
n = calc.get_all_electron_density(gridrefinement=gridrefinement)
# Get integrated values
dv = sys.get_volume() / calc.get_number_of_grid_points().prod()
It = nt.sum() * dv
I = n.sum() * dv / gridrefinement**3
print('%4s,%4.2f,%5.2f' % (formula, It, I), file=f)
f.close()
The result for the integrated pseudo and allelectron densities of the three systems is:
formula  ñ  n 

Na  1.88  11.00 
Cl  7.50  17.00 
NaCl  9.36  28.00 
From which we see that the allelectron densities integrate to the total number of electrons in the system, as expected.