Plotting wave functions

Creating a wave function file

The following script will do a calculation for a CO molecule and save the wave functions in a file (CO.gpw).

from ase import Atoms
from gpaw import GPAW

d = 1.1   # bondlength of hydrogen molecule
a = 5.0   # sidelength of unit cell
c = a / 2
atoms = Atoms('CO',
              positions=[(c - d / 2, c, c),
                         (c + d / 2, c, c)],
              cell=(a, a, a))

calc = GPAW(nbands=5, h=0.2, txt=None)
atoms.set_calculator(calc)

# Start a calculation:
energy = atoms.get_potential_energy()

# Save wave functions:
calc.write('CO.gpw', mode='all')

Creating wave function cube files

You can get separate cube files (the format used by Gaussian) for each wavefunction with the script:

from __future__ import print_function
from ase.io import write
from gpaw import restart

basename = 'CO'

# load binary file and get calculator
atoms, calc = restart(basename + '.gpw')

# loop over all wfs and write their cube files
nbands = calc.get_number_of_bands()
for band in range(nbands):
    wf = calc.get_pseudo_wave_function(band=band)
    fname = '{0}_{1}.cube'.format(basename, band)
    print('writing wf', band, 'to file', fname)
    write(fname, atoms, data=wf)

The script produced the files CO_0.cube .. CO_5.cube, which might be viewed using for example jmol or VMD.

Plotting wave functions with jmol

See http://jmol.sourceforge.net/docs/surface/

You can visualize an isosurface from a cube file by creating the myscript.spt script:

#isosurface name cutoff "cubefile"
isosurface pos 0.05 "CO_1.cube"

and executing it with jmol:

jmol -s myscript.spt

You can also save the image directly on the command line:

jmol -ions myscript.spt -w JPEG:myfile.jpg

Plotting wave functions with VMD

To view the wavefunctions, start VMD with the command line:

vmd CO_*.cube

You will get two windows, one with a very primitive representation of the molecule, and one called ‘VMD Main’. In the VMD Main window, select Graphics/Representation. In the top panel there will be a single “representation” of the molecule called “Line”. Select it, and change the type to “CPK”. This will show the molecule with spheres for atoms and rods for bonds. You probably want to reduce the size of the spheres and increase the resolution of the spheres. Now you see the atoms!

To see the wavefunctions, click on the “Create Rep” button, and select the new representation. Select type “Isosurface”. Near the bottom, find the menu labeled “Draw” and select the value “Solid Surface”. Now you can see an iso-surface of the wavefunction, you select the value in the field “Isovalue”. The default 0 is rarely useful. You select the different Kohn-Sham states (stored in the different cube files) with the pull-down menu labeled “Vol”.

IMPORTANT: This works best for molecules. In solids, the wavefunctions will be complex, VMD does not handle this well.

Creating cube to plt files (gOpenMol)

Warning this section is obsolete!

The cube files can be transformed to plt format using the program g94cub2pl from the gOpenMol utilities.

Creating wave function plt files with gOpenMol

Warning this section is obsolete!

One can write out the wave functions in the very compact (binary) gOpenMol plt format directly:

from __future__ import print_function
from ase.io.plt import write_plt
from gpaw import restart

basename = 'CO'

# load binary file and get calculator
atoms, calc = restart(basename + '.gpw')

# loop over all wfs and write their cube files
nbands = calc.get_number_of_bands()

for band in range(nbands):
    wf = calc.get_pseudo_wave_function(band=band)
    fname = '{0}_{1}.plt'.format(basename, band)
    print('writing wf', band, 'to file', fname)
    write_plt(fname, atoms, data=wf)