Density and hamiltonian objects

class gpaw.density.Density(gd, finegd, nspins, collinear, charge, redistributor, background_charge=None)[source]

Density object.

=============== =====================================================
``gd``          Grid descriptor for coarse grids.
``finegd``      Grid descriptor for fine grids.
``interpolate`` Function for interpolating the electron density.
``mixer``       ``DensityMixer`` object.
=============== =====================================================
Soft and smooth pseudo functions on uniform 3D grids:


Electron density on the coarse grid.


Electron density on the fine grid.


Electron density on the fine grid.


Charge density on the fine grid.


Core electron-density on the coarse grid.

Create the Density object.


Calculate nt_sG from scratch.

nt_sG will be equal to nct_G plus the contribution from wfs.add_to_density().

get_all_electron_density(atoms=None, gridrefinement=2, spos_ac=None, skip_core=False)[source]

Return real all-electron density array.

Usage: Either get_all_electron_density(atoms) or


skip_core=True theoretically returns the

all-electron valence density (use with care; will not in general integrate to valence)

get_correction(a, spin)[source]

Integrated atomic density correction.

Get the integrated correction to the pseuso density relative to the all-electron density.

get_spin_contamination(atoms, majority_spin=0)[source]

Calculate the spin contamination.

Spin contamination is defined as the integral over the spin density difference, where it is negative (i.e. the minority spin density is larger than the majority spin density.

initialize_directly_from_arrays(nt_sG, nt_vG, D_asp)[source]

Set D_asp and nt_sG directly.


Initialize D_asp, nt_sG and Q_aL from atomic densities.

nt_sG is initialized from atomic orbitals, and will be constructed with the specified magnetic moments and obeying Hund’s rules if hund is true.

initialize_from_other_density(dens, kptband_comm)[source]

Redistribute pseudo density and atomic density matrices.

Collect dens.nt_sG and dens.D_asp to world master and distribute.


Initialize D_asp, nt_sG and Q_aL from wave functions.


Normalize pseudo density.

class gpaw.hamiltonian.Hamiltonian(gd, finegd, nspins, collinear, setups, timer, xc, world, redistributor, vext=None)[source]
apply(a_xG, b_xG, wfs, kpt, calculate_P_ani=True)[source]

Apply the Hamiltonian operator to a set of vectors.


a_nG: ndarray

Set of vectors to which the overlap operator is applied.

b_nG: ndarray, output

Resulting S times a_nG vectors.

wfs: WaveFunctions

Wave-function object defined in

kpt: KPoint object

k-point object defined in

calculate_P_ani: bool

When True, the integrals of projector times vectors P_ni = <p_i | a_nG> are calculated. When False, existing P_ani are used

calculate_kinetic_energy_directly(density, wfs)[source]

Calculate kinetic energy as 1/2 (nable psi)^2 it gives better estimate of kinetic energy during the SCF. Important for direct min.

‘calculate_kinetic_energy’ method gives a correct value of kinetic energy only at self-consistent solution.

  • density

  • wfs


total kinetic energy

calculate_kinetic_energy_using_kin_en_matrix(density, wfs)[source]

E_k = sum_{M’M} rho_MM’ T_M’M better agreement between gradients of energy and the total energy during the direct minimisation. This is important when the line search is used. Also avoids using the eigenvalues which are not calculated during the direct minimisation.

‘calculate_kinetic_energy’ method gives a correct value of kinetic energy only at self-consistent solution.

  • density

  • wfs


total kinetic energy

get_energy(e_entropy, wfs, kin_en_using_band=True, e_sic=None)[source]

Sum up all eigenvalues weighted with occupation numbers


Returns the work functions, in Hartree, for a dipole-corrected simulation. Returns None if no dipole correction is present. (wfs can be obtained from calc.wfs)

get_xc_difference(xc, density)[source]

Calculate non-selfconsistent XC-energy difference.

update(density, wfs=None, kin_en_using_band=True)[source]

Calculate effective potential.

The XC-potential and the Hartree potential are evaluated on the fine grid, and the sum is then restricted to the coarse grid.