PyFock: Pure Python DFT and Quantum Chemistry with GPU Acceleration

A purely Python-based density functional theory package that combines accessibility with high-performance computing capabilities for molecular quantum chemistry calculations.

Useful links:
Official Website: https://pyfock.bragitoff.com
Documentation: https://pyfock-docs.bragitoff.com
Try the GUI: https://pyfock-gui.bragitoff.com
GitHub Repository: https://github.com/manassharma07/pyfock
PyPI Package: https://pypi.org/project/pypi

Overview

PyFock represents a significant advancement in computational chemistry software development. As a pure Python quantum chemistry package, it enables efficient Kohn-Sham density functional theory (DFT) calculations for molecular systems while maintaining the accessibility and readability that Python is known for.

Unlike traditional quantum chemistry codes written in Fortran or C/C++, PyFock is implemented entirely in Python—including all performance-critical molecular integral evaluations. While PySCF and Psi4 are also python based, the key difference is that they still compute the molecular integrals using a low-level language like C. This makes it difficult for other researchers to tinker with the molecular integral evaluation code as it requires a deep comprehension of the particular package as well as also requires proper compilation. Despite being written completely in Python, PyFock achieves computational efficiency comparable to established codes such as PySCF and Psi4 through sophisticated optimization techniques utilizing Numba JIT compilation, NumPy, NumExpr, SciPy, and CuPy.

Key Distinguishing Features

100% Pure Python

All code, including computationally intensive molecular integrals, is written in Python, making it accessible for education and research.

High Performance

Achieves efficiency comparable to C/C++ backends through advanced optimization techniques and just-in-time compilation.

GPU Acceleration

Leverages CUDA via Numba and CuPy for up to 90× speedup compared to a single-core PySCF run for (H2O)139.

Easy Installation

Simple pip installation across all major operating systems: Linux, macOS, and Windows.

Efficient Scaling

Near-quadratic O(N²) scaling through density fitting with Cauchy-Schwarz screening.

Cross-Platform

Multi-core CPU support and multi-GPU acceleration capabilities across different computing environments.

Technical Capabilities

Molecular Integral Evaluation

PyFock provides comprehensive support for molecular integral calculations, including:

  • Overlap integrals
  • Kinetic energy integrals
  • Nuclear attraction integrals
  • Electron repulsion integrals (ERI)

The package implements multiple integration schemes, including the classical Taketa-Huzinaga-Ohata approach and the more efficient Rys quadrature method supporting roots 1 through 10, and Obara-Saika scheme.

Density Fitting Approximation

PyFock employs density fitting techniques with Cauchy-Schwarz screening to dramatically reduce computational costs while maintaining accuracy. This approach enables the near-quadratic scaling behavior that makes calculations on larger systems feasible.

Exchange-Correlation Functionals

Through LibXC integration, PyFock supports a wide range of exchange-correlation functionals, including both Local Density Approximation (LDA) and Generalized Gradient Approximation (GGA) functionals, providing flexibility for various computational chemistry applications.

Installation

Quick Installation

PyFock can be installed using pip:

pip install pyfock

Required Dependencies

PyFock requires LibXC for exchange-correlation functionals. The recommended installation method is via conda:

conda install -c conda-forge pylibxc -y

Optional GPU Support

For GPU acceleration capabilities, install CuPy with the appropriate CUDA version:

pip install cupy-cuda11x  # Replace 11x with your CUDA version

Basic Usage Example

The following example demonstrates a basic DFT calculation using PyFock:

from pyfock import Basis, Mol, DFT

# Define molecule from XYZ file
mol = Mol(coordfile='h2o.xyz')

# Set up basis sets
basis = Basis(mol, {'all': Basis.load(mol=mol, basis_name='def2-SVP')})
auxbasis = Basis(mol, {'all': Basis.load(mol=mol, basis_name='def2-universal-jfit')})

# Configure DFT calculation (PBE functional)
funcx = 101  # PBE exchange (LibXC code)
funcc = 130  # PBE correlation (LibXC code)
dftObj = DFT(mol, basis, auxbasis, xc=[funcx, funcc])

# Set calculation parameters
dftObj.conv_crit = 1e-7
dftObj.max_itr = 20
dftObj.ncores = 4

# Run SCF calculation
energy, dmat = dftObj.scf()
print(f"Total Energy: {energy} Ha")

Performance Characteristics

PyFock demonstrates exceptional performance across various metrics:

  • Numerical Accuracy: Maintains consistency with PySCF at better than 10⁻⁷ Hartree precision
  • Parallel Efficiency: Achieves performance comparable to state-of-the-art C++ backends on multicore CPU systems
  • GPU Acceleration: Delivers up to 90× speedup compared to single-core PySCF CPU execution for large molecular systems
  • Scaling Behavior: Near-quadratic O(N²·⁰⁵) scaling for electron repulsion integrals and sub-quadratic O(N¹·²⁵⁻¹·⁵) scaling for exchange-correlation contributions

Graphical User Interface

PyFock includes a comprehensive web-based graphical user interface that facilitates interactive calculations and visualization. The GUI provides:

  • Interactive 3D molecular visualization using Py3Dmol
  • Intuitive configuration of basis sets, functionals, and calculation parameters
  • Automatic generation of cube files for HOMO, LUMO, and electron density visualization
  • Python script generation for local execution
  • Built-in validation against PySCF for accuracy verification
  • Pre-loaded molecular library and custom XYZ input support

The GUI is accessible online at https://pyfock-gui.bragitoff.com and can also be deployed locally for institutional use.

Development Roadmap

PyFock is under active development with several advanced features planned for future releases:

  • Analytical gradients for geometry optimization (currently in progress)
  • Real-time time-dependent DFT (RT-TDDFT) for electron dynamics and excited state calculations
  • Periodic boundary conditions for solid-state systems
  • Hybrid functionals incorporating exact exchange
  • Enhanced multi-GPU parallelization
  • Basis set optimization utilities

License

PyFock is distributed under the MIT License, promoting open collaboration and community development.

Academic Citation

Researchers using PyFock in their work should cite the following reference:

Sharma, M.  and Sierka M. (2026). PyFock: A Just-In-Time Compiled Gaussian Basis DFT Python Code for CPU and GPU Architectures,

Conclusion

PyFock represents a significant contribution to the computational chemistry software ecosystem. By demonstrating that high-performance quantum chemistry calculations can be achieved in pure Python, it opens new possibilities for education, rapid prototyping, and collaborative development in the field. The combination of accessibility, performance, and GPU acceleration makes PyFock a valuable tool for both educational institutions and research laboratories.

For more information, comprehensive documentation, tutorials, and support, please visit the official documentation or the GitHub repository.
Get Started with PyFock
Try the Online GUI