Usage

Structures

Bundled molecules can be loaded by name. They are centred automatically in a cubic cell:

methane = Structure.from_name("CH4", cell=12)

Available bundled structures include benzene, bf3, bh3, ch4, co, co2, ethylene, h2, h2o, he, lih, and nh3.

XYZ coordinates are interpreted as angstrom while cell remains expressed in bohr:

water = Structure.from_xyz("water.xyz", cell=12)

A structure can also be constructed directly. Setting units="angstrom" applies to both the coordinates and cell:

hydrogen = Structure(
    symbols=["H", "H"],
    positions=[[0, 0, -0.37], [0, 0, 0.37]],
    cell=6,
    units="angstrom",
)

Calculation settings

The wavefunction cutoff and optional density cutoff belong to the calculation, not the geometry:

calculation = PWDFT(
    methane,
    cutoff=40,
    density_cutoff=160,
    xc="pbe",
    pseudopotential="gth",
    device="cpu",
)

xc accepts "lda" and "pbe". The "gth" pseudopotential selection automatically uses GTH-PADE for LDA and GTH-PBE for PBE. An explicit configuration supports custom parameter directories and valence choices:

from pypwdft import GTH

calculation = PWDFT(
    structure,
    cutoff=40,
    xc="pbe",
    pseudopotential=GTH(charges={"Ga": 13}),
)

Use pseudopotential="all-electron" to disable the frozen-core model.

SCF settings

Common settings can be passed directly to pypwdft.PWDFT.run():

result = calculation.run(
    convergence=1e-6,
    density_convergence=1e-6,
    max_iterations=150,
    bands=8,
    verbosity=1,
    mixing="pulay",
    mixing_fraction=0.5,
    mixing_history=6,
)

Reusable settings can be collected in pypwdft.SCFSettings:

from pypwdft import SCFSettings

settings = SCFSettings(
    convergence=1e-6,
    density_convergence=1e-6,
    max_iterations=150,
    bands=8,
    verbosity=1,
    mixing="pulay",
    mixing_fraction=0.5,
    mixing_history=6,
)
result = calculation.run(settings)

Pulay mixing is the default. It combines a short history of density residuals and normally converges faster than a fixed linear update. If an SCF calculation oscillates, first try a smaller mixing_fraction, such as 0.2. For a plain damped update, select mixing="linear".

The Kohn-Sham equations are solved with a block Davidson eigensolver, which restarts from the orbitals of the previous SCF iteration. Pass eigensolver="arpack" to run() or pypwdft.SCFSettings to use the Lanczos solver from ARPACK instead, for example as a cross-check.

A Lanczos solver builds its search space from one start vector and therefore contains only one state of every degenerate level; the others can be skipped without warning. PyPWDFT guards against this by verifying each Lanczos result: the states found are shifted out of the way and the solver is asked whether a lower state remains. This makes the ARPACK option reliable for degenerate systems, at the cost of several times more Hamiltonian applications than Davidson needs.

Results

Results expose named, typed groups instead of abbreviated dictionary keys:

result.energy.total
result.energy.kinetic
result.energy.electron_ion
result.energy.nonlocal_
result.energy.hartree
result.energy.xc
result.energy.ion_ion

result.density
result.orbitals.energies
result.orbitals.real_space
result.orbitals.reciprocal_space

result.basis.cutoff
result.basis.density_cutoff
result.basis.plane_waves
result.basis.wavefunction_grid
result.basis.density_grid

result.scf.converged
result.scf.iterations
result.scf.energy_residual
result.scf.density_residual
result.scf.elapsed_time
result.scf.backend
result.scf.mixing
result.scf.mixing_fraction
result.scf.mixing_history
result.scf.eigensolver
result.scf.hamiltonian_applications

Plotting

Occupied orbitals are plotted by default:

result.plot_orbitals(
    plane="xz",
    columns=3,
    save="orbitals.pdf",
    show_imaginary_norm=False,
)

Residual imaginary norms are shown in orbital titles by default. Setting show_imaginary_norm=False hides that diagnostic without changing the orbital or the plotted field.

For a collection containing different nodal planes, plane="auto" selects the central Cartesian plane with the largest norm separately for each orbital. Use ngrid and tick_rotation to keep tick labels readable in dense subplot grids.

Specific orbitals and the converged density can also be selected:

result.plot_orbitals(indices=[0, 2, 4], plane="xy")
result.plot_density(plane="xz", save="density.pdf")

GPU calculations

Follow the GPU-compatible installation instructions to install CuPy for the available CUDA version, then request the CUDA device explicitly:

calculation = PWDFT(
    structure,
    cutoff=40,
    xc="pbe",
    pseudopotential="gth",
    device="cuda",
)

Returned arrays are NumPy arrays, independent of the calculation device.