A pure Python Gaussian basis DFT code with GPU acceleration for efficient quantum chemistry calculations
Explore the docs »
Homepage
·
Try the GUI
·
View Demo
·
Report Bug
·
Request Feature
Table of Contents
PyFock is a pure Python quantum chemistry package that enables efficient Kohn-Sham density functional theory (DFT) calculations for molecular systems. Unlike traditional quantum chemistry codes written in Fortran or C/C++, PyFock is written entirely in Python—including all performance-critical molecular integral evaluations—while achieving computational efficiency comparable to established codes like PySCF and Psi4.
- 100% Pure Python: All code, including computationally intensive molecular integrals, is written in Python
- High Performance: Achieves efficiency comparable to C/C++ backends through Numba JIT compilation, NumPy, NumExpr, SciPy, and CuPy
- GPU Acceleration: Leverages CUDA via Numba and CuPy for up to 14× speedup on large systems
- Easy Installation: Simple
pip installon all major operating systems (Linux, macOS, Windows) - Accessible: Designed for education, prototyping, and community development
- Near-Quadratic Scaling: ~O(N²·⁰⁵) scaling through density fitting with Cauchy-Schwarz screening
- Gaussian-Type Orbitals: Employs GTOs as basis functions for molecular calculations
- Efficient Parallelization: Multi-core CPU support and multi-GPU acceleration capabilities
- Numerical accuracy: Consistent with PySCF (< 10⁻⁷ Ha)
- Parallel efficiency: Comparable to state-of-the-art C++ backends on multicore CPUs
- GPU speedup: Up to 14× faster than 4-core CPU execution for large systems
- Scaling: Near-quadratic ~O(N²·⁰⁵) for electron repulsion integrals (Coulomb term)
- XC evaluation: Sub-quadratic scaling ~O(N¹·²⁵⁻¹·⁵) for exchange-correlation contributions
- ✅ Pure Python Implementation: Including molecular integral evaluations (overlap, kinetic, nuclear attraction, electron repulsion integrals)
- ✅ Density Fitting: Efficient density fitting approximation with Cauchy-Schwarz screening
- ✅ GPU Acceleration: Full GPU support for integral evaluation, XC term, and matrix operations
- ✅ Multiple Integration Schemes:
- Classical Taketa-Huzinaga-O-ohata scheme
- Rys quadrature method (roots 1–10) for efficient ERI evaluation
- Obara-Saika method for ERI evaluation
- ✅ XC Functionals: Support for LDA, GGA and meta-GGA functionals natively and via LibXC integration
- ✅ DIIS Convergence: Direct inversion of iterative subspace for SCF acceleration
- ✅ Parallel Execution: Multi-core CPU and multi-GPU support via Numba and Joblib
- ✅ Modular Design: Standalone integral modules for benchmarking and embedding
- ✅ Web-based GUI: Interactive interface for visualization and input generation
- ✅ Cartesian and Spherical Basis: Support for both CAO and SAO representations
- ✅ Effective Core Potentials: Support for evaluation of ECP integrals
- ✅ Analytical gradients & forces: Fast analytical nuclear gradients for density-fitted DFT — one-electron (overlap/kinetic/nuclear), DF Coulomb (3c2e + 2c2e), and XC for LDA, GGA and meta-GGA (native or LibXC) — matching PySCF forces and faster
- ✅ ASE Calculator: Optional ASE interface (geometry optimization and the wider ASE ecosystem), using analytical forces by default
- ✅ Cross-Platform: Works on Linux, macOS, and Windows
PyFock can be easily installed via pip:
pip install pyfockTo get the latest development version directly from GitHub:
pip install git+https://github.com/manassharma07/pyfock.gitOr clone the repository and install locally:
git clone https://github.com/manassharma07/pyfock.git
cd pyfock
pip install -e .PyFock can use LibXC for exchange-correlation functionals not available natively in PyFock. The installation method depends on your system:
conda install -c conda-forge pylibxc -ysudo apt-get install libxc-dev
pip install pylibxc2brew install libxc
pip install pylibxc2Note: The conda method is recommended as it works reliably across all platforms.
For GPU acceleration:
pip install cupy-cuda11x # Replace 11x with your CUDA versionFor the ASE calculator (geometry optimization and the ASE ecosystem):
pip install ase # or: pip install pyfock[ase]PyFock itself imports and runs without ASE installed; ASE is only required when you use PyFockCalculator.
Here's a minimal example to get you started with 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')})
# Create DFT calculation object
dftObj = DFT(mol, basis, auxbasis, xc='PBE')
# 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")PyFock provides standalone access to all molecular integrals:
from pyfock import Integrals, Basis, Mol
mol = Mol(coordfile='h2o.xyz')
basis = Basis(mol, {'all': Basis.load(mol=mol, basis_name='def2-SVP')})
# One-electron integrals
S_ovlp = Integrals.overlap_mat_symm(basis)
V_kin = Integrals.kin_mat_symm(basis)
V_nuc = Integrals.nuc_mat_symm(basis, mol)
# Two-electron integrals (classical scheme)
ERI_slow = Integrals.conv_4c2e_symm(basis)
# Two-electron integrals (Rys quadrature - faster)
ERI_fast = Integrals.rys_4c2e_symm(basis)
# Three-center integrals for density fitting
ERI_3c2e = Integrals.rys_3c2e_symm(basis, auxbasis)
# Two-center integrals
ERI_2c2e = Integrals.rys_2c2e_symm(basis)# GPU versions (returns CuPy arrays in device memory)
S_ovlp_gpu = Integrals.overlap_mat_symm_cupy(basis)
V_kin_gpu = Integrals.kin_mat_symm_cupy(basis)
V_nuc_gpu = Integrals.nuc_mat_symm_cupy(basis, mol)
ERI_3c2e_gpu = Integrals.rys_3c2e_symm_cupy(basis, auxbasis)# Convert from Cartesian to Spherical atomic orbitals
V_kin_CAO = Integrals.kin_mat_symm(basis)
c2sph_mat = basis.cart2sph_basis()
V_kin_SAO = np.dot(c2sph_mat, np.dot(V_kin_CAO, c2sph_mat.T))# Evaluate integrals for a subset of basis functions
S_ovlp_subset = Integrals.overlap_mat_symm(basis, slice=[0, 5, 0, 5])
# slice = [row_start, row_end, col_start, col_end]from pyfock import Basis, Mol, DFT
# Initialize molecule
xyzFilename = 'benzene.xyz'
mol = Mol(coordfile=xyzFilename)
# Set up basis sets
basis_set_name = 'def2-SVP'
auxbasis_name = 'def2-universal-jfit'
basis = Basis(mol, {'all': Basis.load(mol=mol, basis_name=basis_set_name)})
auxbasis = Basis(mol, {'all': Basis.load(mol=mol, basis_name=auxbasis_name)})
# Configure XC functional (PBE)
funcx = 101 # Exchange
funcc = 130 # Correlation
funcidcrysx = [funcx, funcc]
# Initialize DFT object
dftObj = DFT(mol, basis, auxbasis, xc=funcidcrysx)
# Configure convergence and parallelization
dftObj.conv_crit = 1e-7
dftObj.max_itr = 20
dftObj.ncores = 4
# Run calculation
energyCrysX, dmat = dftObj.scf()
print(f"SCF Energy: {energyCrysX} Ha")After a converged DFT calculation, analytical nuclear gradients (and forces)
are available directly via DFT_Grad (density fitting; LDA/GGA/meta-GGA; CPU):
from pyfock import DFT_Grad
# dftObj must already be converged (dftObj.scf() called)
grad = DFT_Grad(dftObj)
result = grad.calculate()
forces = result["forces"] # (natoms, 3) in Ha/Bohr
gradient = result["gradient"] # = -forcesFor geometry optimization, use the ASE calculator (requires ase). It uses
the analytical forces by default and falls back to finite differences only for
configurations the analytical gradients do not yet cover (e.g. HF, no DF):
from ase import Atoms
from ase.optimize import BFGS
from pyfock import PyFockCalculator
water = Atoms("OHH", positions=[[0, 0, 0.119], [0, 0.763, -0.477], [0, -0.763, -0.477]])
water.calc = PyFockCalculator(functional="PBE", basis="def2-SVP",
auxbasis="def2-universal-jfit", ncores=4)
BFGS(water).run(fmax=0.02)from pyfock import Utils
# Generate cube files for molecular orbitals and density
Utils.write_density_cube(dftObj, filename='benzene_density.cube')PyFock includes a web-based GUI for interactive calculations and visualization:
🌐 Try it online: https://pyfock-gui.bragitoff.com
- Interactive 3D Visualization: View molecules and molecular orbitals using Py3Dmol
- Easy Configuration: Select basis sets, functionals, and calculation parameters
- Automatic Cube File Generation: HOMO, LUMO, and density visualizations
- Input Script Generator: Export Python code for local execution
- PySCF Validation: Built-in comparison with PySCF for accuracy verification
- Molecule Library: Pre-loaded common molecules or custom XYZ input
The GUI source code is available on GitHub and can be run locally:
git clone https://github.com/manassharma07/PyFock-GUI.git
cd PyFock-GUI
pip install -r requirements.txt
streamlit run app.py🚀 Coming Soon: Interactive tutorials on Kaggle and Google Colab
- Kaggle Notebook: Introduction to PyFock
- Kaggle Notebook: Advanced Features and GPU accelerated computations
- Google Colab Notebook: Introduction to PyFock
- Kaggle Notebook: Benchmarking PyFock against PySCF
📚 Full Documentation: https://pyfock-docs.bragitoff.com
- Density Fitting with Cauchy-Schwarz screening
- GPU acceleration for integrals and XC evaluation
- DIIS convergence acceleration
- Web-based GUI
- Rys quadrature (roots 1–10)
- Analytical nuclear gradients & forces (density fitting; LDA/GGA/meta-GGA; CPU)
- ASE calculator & geometry optimization
- Analytical gradients on GPU and for non-DF / ECP calculations
- Electron dynamics & Excited state calculations (RT-TDDFT)
- Periodic boundary conditions
- Hybrid functionals with exact exchange
- Multi-GPU parallelization
- Basis set optimization tools
See the open issues for a full list of proposed features and known issues.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make PyFock better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Don't forget to give the project a star! ⭐ Thanks!
Distributed under the MIT License. See LICENSE file for more information.
If you use PyFock in your research, please cite:
@misc{sharma2026pyfock,
title = {PyFock: A Just-In-Time Compiled Gaussian Basis DFT Python Code for CPU and GPU Architectures},
author = {Sharma, Manas and Sierka, Marek},
year = {2026},
publisher = {ChemRxiv},
note = {Preprint},
doi = {https://doi.org/10.26434/chemrxiv.15003943/v1}
}PyPI Package: https://pypi.org/project/pyfock/
Manas Sharma
- Email: manas.sharma@uni-jena.de
- Website: manas.bragitoff.com
- LinkedIn: linkedin.com/in/manassharma07
- Project Homepage: https://pyfock.bragitoff.com
- Project Link: https://github.com/manassharma07/pyfock
Built With
