PyPWDFT
PyPWDFT is an educational pure-Python plane-wave density-functional theory solver. It supports LDA and PBE exchange-correlation functionals, GTH pseudopotentials, multiple CPU FFT implementations, and an optional CuPy/CUDA backend.
Features
- Spherical plane-wave basis with automatically derived FFT grids
- GTH frozen-core pseudopotentials with local and non-local terms
- LDA/SVWN5 and PBE exchange-correlation functionals
- NumPy, SciPy, and pyFFTW CPU backends
- Optional CuPy/CUDA execution
- Typed energy, orbital, basis, and SCF results
- Molecular-orbital and density contour plotting
Installation
pip install pypwdft
Quick start
from pypwdft import PWDFT, Structure
structure = Structure.from_name("H2", cell=10)
calculation = PWDFT(
structure,
cutoff=40,
xc="pbe",
pseudopotential="gth",
)
result = calculation.run(
convergence=1e-6,
verbosity=1,
)
print(result.energy.total)
result.plot_orbitals(
plane="xz",
save="h2-orbitals.png",
)
The API separates three concepts:
Structure: atoms, coordinates, units, and cubic simulation cell.PWDFT: physical and numerical calculation settings.DFTResult: energies, orbitals, density, basis details, and SCF metadata.
PyPWDFT uses atomic units by default: lengths are in bohr and energies are in Hartree.
Structures
Load a bundled molecule or an XYZ file:
methane = Structure.from_name("CH4", cell=12)
water = Structure.from_xyz("water.xyz", cell=12)
XYZ coordinates are interpreted as angstrom; cell is in bohr. Structures
can also be constructed directly:
hydrogen = Structure(
symbols=["H", "H"],
positions=[[0, 0, -0.37], [0, 0, 0.37]],
cell=6,
units="angstrom",
)
Calculation configuration
calculation = PWDFT(
methane,
cutoff=40,
density_cutoff=160,
xc="pbe",
pseudopotential="gth",
device="cpu",
)
Selecting pseudopotential="gth" automatically matches GTH-PADE to LDA and
GTH-PBE to PBE. Advanced valence selections use GTH:
from pypwdft import GTH
calculation = PWDFT(
structure,
cutoff=40,
xc="pbe",
pseudopotential=GTH(charges={"Ga": 13}),
)
Use pseudopotential="all-electron" for an all-electron Coulomb calculation.
SCF settings
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 and uses recent density residuals to accelerate
self-consistency. Lower mixing_fraction if the SCF cycle oscillates, or use
mixing="linear" for a conventional damped update. Settings can also be
supplied directly to run().
The eigenproblem is solved with a block Davidson solver that restarts from the
orbitals of the previous SCF iteration. Use eigensolver="arpack" to select
the ARPACK Lanczos solver instead; it is verified against missed degenerate
states and is considerably slower, so it mainly serves as a cross-check.
Results
All results are exposed via a DFTResult dataclass which has the following
data items.
result.energy.total
result.energy.kinetic
result.energy.hartree
result.energy.xc
result.density
result.orbitals.energies
result.orbitals.real_space
result.orbitals.reciprocal_space
result.basis.plane_waves
result.basis.wavefunction_grid
result.basis.density_grid
result.scf.converged
result.scf.iterations
result.scf.energy_residual
result.scf.elapsed_time
Plotting
result.plot_orbitals(
plane="xz",
columns=3,
save="orbitals.pdf",
show_imaginary_norm=False,
)
result.plot_density(plane="xz", save="density.pdf")
Contour plots use symmetric orbital amplitudes, black isolines, physical axes,
and configurable xy, xz, or yz planes. By default, titles report any
imaginary norm that cannot be removed by a global phase rotation; set
show_imaginary_norm=False to suppress this diagnostic.
For batches containing orbitals with different nodal planes, use
plane="auto" to select the most informative central plane per orbital.
ngrid controls the number of ticks and tick_rotation rotates their labels.
GPU calculations
After installing a CuPy wheel compatible with the local CUDA runtime:
calculation = PWDFT(
structure,
cutoff=40,
xc="pbe",
pseudopotential="gth",
device="cuda",
)
result = calculation.run()
Returned energies and fields are ordinary Python scalars and NumPy arrays.
Example results
Valence molecular orbitals of CO and first unoccupied orbital:
Valence molecular orbitals of benzene and first three unoccupied orbitals:
Acknowledgements
The bundled GTH-PADE and GTH-PBE pseudopotential parameters originate from the
CP2K data repository and were obtained
through eminus. The GTH implementation
in pypwdft/gth.py is adapted from eminus (Apache-2.0). See
pypwdft/psp/NOTICE for licensing details and the
publications to cite.
License
PyPWDFT is distributed under the GNU General Public License version 3 or later.
Third-party components keep their own licenses; see
pypwdft/psp/NOTICE.
Metadata
Release files for pypwdft 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pypwdft-0.3.0.tar.gz | 135.0 kB | With provenance | Details for pypwdft-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pypwdft-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for pypwdft-0.3.0-py3-none-any.whl |
Total release size: 317.9 kB
Release files / pypwdft-0.3.0.tar.gz
| Download URL | pypwdft-0.3.0.tar.gz |
|---|---|
| Size | 135.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26e6c415498a2cf2b1644da5b3ccf9e941304eb06f0bcd0f9d6fcb3fd24a8a68
|
|
BLAKE2b-256 checksum How to use checksums |
5535f5a3b3c89d6e36e139463421fa8e98bc5446d3723f1d803477e4d632b695
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logRelease files / pypwdft-0.3.0-py3-none-any.whl
| Download URL | pypwdft-0.3.0-py3-none-any.whl |
|---|---|
| Size | 182.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1e0765f815f19b4625e1a26ec9e97697b534e2c5fbd8b9d1ef625a4e3b8ceddf
|
|
BLAKE2b-256 checksum How to use checksums |
8b5c7a401de9adb1c61d8e420a5b54a568ce21dd0fe305552454a6c851f2c49b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logSecurity for pypwdft 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pypwdft-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.