Cube files: spin density, ELF and density differences

In this tutorial

Tutorial 1 wrote the density and the orbitals of water as cube files. Here you go further: the spin density of a radical, the electron localization function (ELF), and a density difference that shows how a solvent polarizes a molecule. You also integrate cube files, which tells you whether the grid is fine and large enough. Time: 7 s for the radical, 5 s per water run (32 cores). Files: allyl.yaml, h2o_gas.yaml, h2o_water.yaml, run.sh.

The cube section

cube:
  prefix: allyl
  spacing: 0.15
  margin: 4.0
  quantities: density, spin_density, elf, mo_alpha:homo
quantities

density, density_alpha, density_beta, spin_density (\(\rho_\alpha-\rho_\beta\)), elf, orbitals mo_alpha:<sel> and mo_beta:<sel>, and with SIC the Fermi–Löwdin orbitals sic_alpha:<sel> and sic_beta:<sel> (tutorial 7). <sel> is a number, a range (3-6), homo, lumo or all.

spacing and margin

The grid step and how far the box extends beyond the outermost nuclei, both in bohr. All quantities share one grid, so cubes of the same molecule from different runs can be subtracted point by point.

One file <prefix>_<quantity>.cube is written per quantity:

 cube grid: 109 90 55  (spacing   0.150 Bohr, margin   4.000 Bohr)
  cube written: allyl_density.cube
  cube written: allyl_spin_density.cube
  cube written: allyl_elf.cube
  cube written: allyl_mo_alpha_12.cube

The plots below use tutorials/tools/dftsw27plot.py. cube draws isosurfaces, slice draws contour maps through a plane, and cubemath integrates cubes and subtracts them.

The spin density of the allyl radical

The allyl radical C\(_3\)H\(_5\) (files/allyl.yaml, PBE/def2-TZVP, planar, in the \(xy\) plane) has one unpaired electron in a nonbonding \(\pi\) orbital. In Hückel theory that orbital is \((\phi_1-\phi_3)/\sqrt2\), with a node on the central carbon:

$ python3 tutorials/tools/dftsw27plot.py cube allyl_mo_alpha_12.cube --sign --iso 0.03 --view iso --elevation 35
../../_images/allyl_somo.png

Fig. 39 The singly occupied orbital (alpha 12): \(\pi\) lobes on the two terminal carbons, none on the central one.

So the unpaired spin should sit on the terminal carbons only. The spin density says otherwise:

$ python3 tutorials/tools/dftsw27plot.py cube allyl_spin_density.cube --sign --iso 0.004 --view iso --elevation 35
../../_images/allyl_spin_iso.png

Fig. 40 Spin density at \(\pm0.004\): blue is excess \(\alpha\) spin, red excess \(\beta\) spin. The central carbon and the terminal hydrogens carry negative spin.

  Spin populations (alpha - beta) per atom:
   atom 1 (C ):  Mulliken =   -0.19601  Löwdin =   -0.03777
   atom 2 (C ):  Mulliken =    0.64871  Löwdin =    0.52560
   atom 3 (C ):  Mulliken =    0.64871  Löwdin =    0.52560
   atom 5 (H ):  Mulliken =   -0.02795  Löwdin =   -0.00345

This is spin polarization. The unpaired \(\alpha\) electron attracts the other \(\alpha\) electrons through exchange. The doubly occupied orbitals then differ slightly for the two spins, and \(\beta\) density is left behind on the central carbon. A restricted open-shell calculation cannot show this; electron spin resonance can. The hyperfine couplings of allyl confirm the negative spin density on the central carbon, as predicted for odd-alternant radicals.

A slice 1 bohr above the molecular plane shows the \(\pi\) part:

$ python3 tutorials/tools/dftsw27plot.py slice allyl_spin_density.cube --plane xy --at 1.0 --fill
../../_images/allyl_spin_pi.png

Fig. 41 Spin density 1 bohr above the plane. Positive on the terminal carbons, a small negative region above the central one.

--fill draws filled contours with a colour bar. Without values it chooses a symmetric range from the data; --fill 0 1 fixes it, for example for the ELF.

The electron localization function

The ELF (Becke and Edgecombe 1990) compares the local kinetic energy of the electrons with that of a uniform electron gas of the same density. It lies between 0 and 1. It is close to 1 where electron pairs are localized (cores, bonds, lone pairs) and is 1/2 in a uniform gas.

$ python3 tutorials/tools/dftsw27plot.py slice allyl_elf.cube --plane xy --at 0.0 --fill 0 1
../../_images/allyl_elf.png

Fig. 42 ELF in the molecular plane: a ring around each carbon core and the C–H bond basins (yellow). The C–C bond basins are weaker in this plane, because the \(\pi\) pairs lie above and below it.

The ELF is a picture, not a number to integrate: its integral over space has no meaning.

A density difference: how a solvent polarizes water

Two runs of the same geometry give cubes on the same grid. files/h2o_gas.yaml and files/h2o_water.yaml are the inputs of tutorial 12 with a cube section added:

$ python3 tutorials/tools/dftsw27plot.py cubemath h2o_water_density.cube h2o_gas_density.cube --out h2o_polarization.cube
h2o_water_density.cube - h2o_gas_density.cube: grid (81, 110, 93), dV = 0.00100 bohr^3
  integral = -0.000027   positive part = 0.055000   negative part = -0.055026   max = 0.0171   min = -0.06
$ python3 tutorials/tools/dftsw27plot.py slice h2o_polarization.cube --plane yz --at 0 --fill -0.004 0.004 --range 4
../../_images/h2o_polarization.png

Fig. 43 \(\rho_{\rm water}-\rho_{\rm gas}\) in the molecular plane. The reaction field pulls electrons from the hydrogens (blue) toward the oxygen (red).

The difference integrates to zero (the electron count is the same). About 0.055 electrons move, from the hydrogens to the oxygen, and the dipole grows from 2.04 to 2.37 D (tutorial 12). The same recipe gives bonding (deformation) densities, charge-transfer densities and density changes between functionals or between SIC and DFT.

Things to try

1. Is the grid good enough?

cubemath with a single cube prints its integral. For the density that should be the number of electrons, and for the spin density the number of unpaired electrons. run.sh --exercises repeats allyl on several grids:

What you should find

spacing (bohr)

margin (bohr)

\(\int\rho\) (23 e)

\(\int(\rho_\alpha-\rho_\beta)\) (1)

file size

0.3

4

22.852

0.9939

0.9 MB

0.15

4

22.894

0.9928

7 MB

0.1

4

22.974

0.9919

23 MB

0.07

4

22.969

0.9920

68 MB

0.1

6

23.003

0.9998

0.1

8

23.004

1.0000

Two errors add up. The margin has to contain the tails. A box 4 bohr beyond the outer nuclei misses 0.03 electrons and 0.8% of the spin. The spacing has to resolve the cusps of the carbon 1s density. With 0.3 bohr the integral is another 0.12 electrons short; at 0.1 bohr it is within 0.003. For pictures, 0.2–0.3 bohr and the default margin are fine. For integrals, use 0.1 bohr and 6 bohr.

2. ELF of a lone pair

Set quantities: elf in tutorial 1’s water input (run.sh --exercises does this). Then slice through the oxygen perpendicular to the molecule, the \(xz\) plane, since the molecule lies in the \(yz\) plane:

$ python3 tutorials/tools/dftsw27plot.py slice h2o_elf_elf.cube --plane xz --at 0 --fill 0 1 --range 4
What you should find
../../_images/h2o_elf.png

Fig. 44 The two lone pairs of oxygen: ELF maxima of 0.92 at \(x=\pm1.0\) bohr, above the oxygen (away from the hydrogens), merging into one crescent.

The lone pairs are the clearest feature in the ELF of water. Their two maxima lie on either side of the molecular plane, the “rabbit ears” of the textbook picture. They are barely separate: over the top of the crescent, at \(x=0\), the ELF still reaches 0.90.

Troubleshooting

  • Large files. The size grows as spacing\(^{-3}\). Write only the quantities you need, and use margin and spacing to keep the box small.

  • Cubes on different grids cannot be subtracted (cubemath stops). Use the same geometry, spacing and margin.

  • Not available: noncollinear runs, and mo_* with the Jacobi SIC solver (no canonical orbitals). Use sic_* for the FLOs instead.

  • Other viewers. The files are standard Gaussian cubes in bohr. VMD, Avogadro, VESTA, Jmol and ChimeraX read them.

This is the last tutorial of the series; back to the overview.