API
This reference is generated directly from the public classes exported by
pypwdft. The Usage chapter provides complete calculation
examples.
Calculation setup
Structure
- class pypwdft.Structure(symbols, positions, cell, *, units='bohr', center=True)
Bases:
objectAtomic structure in a cubic simulation cell.
- Parameters:
symbols (sequence of str) – Element symbols in the same order as
positions.positions (array_like, shape (natom, 3)) – Cartesian atomic coordinates.
cell (float) – Cubic cell edge length in the selected units.
units ({'bohr', 'angstrom'}, optional) – Units used by
positionsandcell. Internally, coordinates are stored in bohr.center (bool, optional) – Centre the structure’s bounding box in the simulation cell.
- property atomic_numbers
Atomic numbers in structure order.
- property cell
Cubic cell edge length in bohr.
- classmethod from_name(name, *, cell=10.0, center=True)
Load one of PyPWDFT’s bundled XYZ structures.
- classmethod from_xyz(path, *, cell=10.0, center=True)
Load an XYZ file whose coordinates are expressed in angstrom.
- property positions
A copy of the Cartesian positions in bohr.
- property symbols
Element symbols as an immutable tuple.
PWDFT
- class pypwdft.PWDFT(structure, *, cutoff=None, density_cutoff=None, xc='pbe', pseudopotential='gth', device='cpu', fft_backend=None, threads=None)
Bases:
objectHigh-level plane-wave DFT calculation.
- Parameters:
structure (Structure) – Atomic structure and cubic simulation cell.
cutoff (float, optional) – Wavefunction cutoff in Hartree. Required for
Structureinput.density_cutoff (float, optional) – Density cutoff in Hartree. Defaults to four times
cutoff.xc ({'lda', 'svwn5', 'pbe'}, optional) – Exchange-correlation functional.
pseudopotential ({'gth', 'all-electron'}, GTH, object, or None) – Ionic model. The default GTH family automatically matches
xc.device ({'cpu', 'cuda'}, optional) – Compute device. CPU is the predictable default.
fft_backend ({'pyfftw', 'numpy', 'scipy', 'cupy'}, optional) – Expert override for the numerical backend.
threads (int, optional) – Number of FFT threads on the CPU (
'pyfftw'and'scipy'backends); defaults to one. With more than one FFT thread, BLAS is restricted to a single thread during the calculation, because the two thread pools otherwise compete for the same cores. Ignored on a GPU.
- run(settings=None, *, convergence=None, density_convergence=None, max_iterations=None, bands=None, verbosity=None, mixing=None, mixing_fraction=None, mixing_history=None, eigensolver=None)
Run the SCF calculation and return a
DFTResult.Keyword arguments override the corresponding values in
settings. In most calculations the default Pulay mixer is preferable to linear mixing. If convergence oscillates, reducemixing_fraction.
SCFSettings
- class pypwdft.SCFSettings(convergence=1e-05, density_convergence=None, max_iterations=100, bands=None, verbosity=0, mixing='pulay', mixing_fraction=0.5, mixing_history=6, eigensolver='davidson')
Bases:
objectConvergence, eigensolver, and density-mixing settings.
- Parameters:
convergence (float, optional) – Total-energy convergence threshold in Hartree.
density_convergence (float, optional) – RMS density-residual threshold. Defaults to
convergence.max_iterations (int, optional) – Maximum number of SCF iterations.
bands (int, optional) – Number of orbitals to calculate. Occupied orbitals are always included.
verbosity (int, optional) – Set to a non-zero value to print the calculation and iteration tables.
mixing ({'pulay', 'linear'}, optional) – Density-mixing algorithm. Pulay is the default.
mixing_fraction (float, optional) – Damping applied to each density residual. Must be in
(0, 1].mixing_history (int, optional) – Number of recent residuals retained by Pulay mixing.
eigensolver ({'davidson', 'arpack'}, optional) – Iterative eigensolver. Davidson restarts from the orbitals of the previous SCF iteration and is the default.
GTH configuration
- class pypwdft.GTH(family=None, path=None, charges=None)
Bases:
objectConfiguration for a GTH pseudopotential.
family=Noneautomatically chooses PADE for LDA and PBE for PBE.- Parameters:
family (str | None)
path (str | Path | None)
charges (Mapping | None)
Calculation results
DFTResult
- class pypwdft.DFTResult(data, *, system, noccupied)
Bases:
objectTyped result of a completed DFT calculation.
- plot_density(*, plane='xy', save=None, **plot_options)
Plot a central plane through the converged electron density.
- plot_orbitals(*, occupied=True, indices=None, plane='xy', columns=3, save=None, show_imaginary_norm=True, **plot_options)
Plot selected orbitals and return the Matplotlib figure and axes.
EnergyComponents
- class pypwdft.EnergyComponents(total, kinetic, electron_ion, nonlocal_, hartree, xc, ion_ion)
Bases:
objectNamed energy components in Hartree.
- Parameters:
total (float)
kinetic (float)
electron_ion (float)
nonlocal_ (float)
hartree (float)
xc (float)
ion_ion (float)
- property ionic
Combined local, non-local, and ion-ion energy.
OrbitalSet
- class pypwdft.OrbitalSet(energies, real_space, reciprocal_space)
Bases:
objectOrbital energies and wavefunctions returned by an SCF calculation.
- Parameters:
energies (ndarray)
real_space (ndarray)
reciprocal_space (ndarray)
BasisInfo
- class pypwdft.BasisInfo(cutoff, density_cutoff, plane_waves, wavefunction_grid, density_grid)
Bases:
objectPlane-wave basis and real-space grid information.
- Parameters:
cutoff (float)
density_cutoff (float)
plane_waves (int)
wavefunction_grid (int)
density_grid (int)
SCFInfo
- class pypwdft.SCFInfo(converged, iterations, energy_residual, density_residual, elapsed_time, backend, mixing, mixing_fraction, mixing_history, eigensolver, hamiltonian_applications)
Bases:
objectSCF convergence and timing information.
- Parameters:
converged (bool)
iterations (int)
energy_residual (float)
density_residual (float)
elapsed_time (float)
backend (str)
mixing (str)
mixing_fraction (float)
mixing_history (int)
eigensolver (str)
hamiltonian_applications (int)