PySCF
What this library is for
PySCF is a Python-native electronic-structure package for molecular and
periodic quantum chemistry. It provides Gaussian-basis molecule/cell builders,
SCF, DFT, MP2, coupled cluster, CI/FCI, CASSCF, TDDFT, gradients, geometry
optimization, solvent, QM/MM, and periodic boundary-condition workflows.
When to use this vs. alternatives
- Use PySCF for quantum chemistry calculations where method, basis, charge,
spin, SCF convergence, molecular orbitals, density matrices, or post-HF
methods are central to the task.
- Use ASE to orchestrate atomistic workflows or connect structures to
calculators; convert to PySCF only when the calculation is quantum chemistry
in PySCF's method stack.
- Use pymatgen for materials structure/phase analysis; use PySCF PBC modules for
electronic-structure calculations on periodic cells.
- Use RDKit for cheminformatics and conformer generation before a quantum
chemistry calculation; validate charge, spin, coordinates, and atom order
before passing geometries to PySCF.
- Do not implement Hartree-Fock, DFT grids, integrals, or CCSD with generic
NumPy/SciPy unless the user is developing a new electronic-structure method.
Canonical workflow
Most calculations follow: define Mole or periodic Cell, choose a method
object, call .kernel(), then inspect convergence and derived quantities.
from pyscf import cc, dft, gto, mp, scf
mol = gto.M(
atom="""
O 0.000000 0.000000 0.000000
H 0.000000 0.757160 0.586260
H 0.000000 -0.757160 0.586260
""",
basis="cc-pvdz",
charge=0,
spin=0, # 2S = n_alpha - n_beta
unit="Angstrom",
verbose=4,
)
mf = scf.RHF(mol)
e_hf = mf.kernel()
assert mf.converged
ks = dft.RKS(mol)
ks.xc = "b3lyp"
e_dft = ks.kernel()
mp2 = mp.MP2(mf)
e_corr, t2 = mp2.kernel()
mycc = cc.CCSD(mf)
e_ccsd = mycc.kernel()[0]
print("E_HF", e_hf)
print("E_DFT", e_dft)
print("E_MP2_total", e_hf + e_corr)
print("E_CCSD_total", e_hf + e_ccsd)
For deeper examples, read:
Key conventions and gotchas
spin is 2S, equal to n_alpha - n_beta, not multiplicity. A triplet has
spin=2, not spin=3.
- Molecular coordinates are commonly given in Angstrom; set
unit explicitly
when generating geometries from other packages.
- If you mutate a
Mole object's attributes after construction, call build()
again before running a calculation.
- Closed-shell systems normally use RHF/RKS; open-shell systems require UHF/UKS
or ROHF/ROKS as appropriate. Do not run RHF on a radical because it happens to
converge.
- Basis set and ECP/pseudopotential choices define the calculation. Record
basis, ECP/pseudo, charge, spin, XC functional, frozen-core choices, and
density-fitting settings.
- DFT energies depend on XC functional and numerical grid. Tighten grids for
sensitive energies, nonlocal corrections, or reproducibility comparisons.
- Post-HF methods should start from a converged and appropriate mean-field
reference; inspect spin contamination for unrestricted references.
- Periodic calculations use
pyscf.pbc cells, lattice vectors, pseudopotentials,
density fitting, and k-points. Do not treat a periodic material as a large
molecule unless that is the intended approximation.
Anti-patterns
- Do not guess spin from chemical formula alone. Determine charge, electron
count, multiplicity, and whether restricted/open-shell methods are appropriate.
- Do not compare energies across different basis sets, ECPs, grids, frozen-core
settings, charge/spin states, or geometries as if they are one calculation.
- Do not ignore
mf.converged or SCF warnings. Try better initial guesses,
damping, level shifting, Newton SCF, density fitting, or a more suitable
reference before reporting results.
- Do not pass RDKit/ASE/pymatgen coordinates into PySCF without checking units,
atom order, total charge, spin state, and whether hydrogens/protons are
explicit.
- Do not use molecular
gto.M for a periodic cell that needs k-points and
lattice vectors; use pyscf.pbc.gto.Cell.
Diagnostic checks
Before trusting outputs, the agent should:
- Print method, basis, charge, spin, unit, electron count, atom count, and
coordinates or geometry source.
- Check SCF convergence, total energy, HOMO/LUMO or occupations, and warnings.
- For unrestricted calculations, inspect spin expectation or spin contamination
where relevant.
- For DFT, record XC functional, grids, dispersion/nonlocal settings, and
integration-grid changes.
- For correlated methods, record frozen-core settings, reference type, and
whether amplitudes/convergence are sane.
- For PBC, record lattice vectors, pseudopotentials, k-point mesh, density
fitting, and whether all-electron or pseudopotential treatment is used.
Pointers to deeper material
1---2name: pyscf-23description: Use when the user is working with Python-native quantum chemistry or electronic structure: molecular or periodic Hartree-Fock, DFT, MP2, CCSD, CASSCF, FCI, TDDFT, basis sets, effective core potentials, spin/charge setup, geometry optimization, solvent/QM-MM, periodic boundary conditions, k-points, or wavefunction/post-HF analysis. Prefer PySCF over generic NumPy/SciPy linear algebra when quantum chemistry conventions, integrals, SCF convergence, basis sets, spin, and electron counts matter.4---56# PySCF78## What this library is for910PySCF is a Python-native electronic-structure package for molecular and11periodic quantum chemistry. It provides Gaussian-basis molecule/cell builders,12SCF, DFT, MP2, coupled cluster, CI/FCI, CASSCF, TDDFT, gradients, geometry13optimization, solvent, QM/MM, and periodic boundary-condition workflows.1415## When to use this vs. alternatives1617- Use PySCF for quantum chemistry calculations where method, basis, charge,18 spin, SCF convergence, molecular orbitals, density matrices, or post-HF19 methods are central to the task.20- Use ASE to orchestrate atomistic workflows or connect structures to21 calculators; convert to PySCF only when the calculation is quantum chemistry22 in PySCF's method stack.23- Use pymatgen for materials structure/phase analysis; use PySCF PBC modules for24 electronic-structure calculations on periodic cells.25- Use RDKit for cheminformatics and conformer generation before a quantum26 chemistry calculation; validate charge, spin, coordinates, and atom order27 before passing geometries to PySCF.28- Do not implement Hartree-Fock, DFT grids, integrals, or CCSD with generic29 NumPy/SciPy unless the user is developing a new electronic-structure method.3031## Canonical workflow3233Most calculations follow: define `Mole` or periodic `Cell`, choose a method34object, call `.kernel()`, then inspect convergence and derived quantities.3536```python37from pyscf import cc, dft, gto, mp, scf3839mol = gto.M(40 atom="""41 O 0.000000 0.000000 0.00000042 H 0.000000 0.757160 0.58626043 H 0.000000 -0.757160 0.58626044 """,45 basis="cc-pvdz",46 charge=0,47 spin=0, # 2S = n_alpha - n_beta48 unit="Angstrom",49 verbose=4,50)5152mf = scf.RHF(mol)53e_hf = mf.kernel()54assert mf.converged5556ks = dft.RKS(mol)57ks.xc = "b3lyp"58e_dft = ks.kernel()5960mp2 = mp.MP2(mf)61e_corr, t2 = mp2.kernel()6263mycc = cc.CCSD(mf)64e_ccsd = mycc.kernel()[0]6566print("E_HF", e_hf)67print("E_DFT", e_dft)68print("E_MP2_total", e_hf + e_corr)69print("E_CCSD_total", e_hf + e_ccsd)70```7172For deeper examples, read:7374- Quickstart: https://pyscf.org/quickstart.html75- User guide: https://pyscf.org/user/index.html76- How to use PySCF: https://pyscf.org/user/using.html77- Examples: https://github.com/pyscf/pyscf/tree/master/examples7879## Key conventions and gotchas8081- `spin` is `2S`, equal to `n_alpha - n_beta`, not multiplicity. A triplet has82 `spin=2`, not `spin=3`.83- Molecular coordinates are commonly given in Angstrom; set `unit` explicitly84 when generating geometries from other packages.85- If you mutate a `Mole` object's attributes after construction, call `build()`86 again before running a calculation.87- Closed-shell systems normally use RHF/RKS; open-shell systems require UHF/UKS88 or ROHF/ROKS as appropriate. Do not run RHF on a radical because it happens to89 converge.90- Basis set and ECP/pseudopotential choices define the calculation. Record91 basis, ECP/pseudo, charge, spin, XC functional, frozen-core choices, and92 density-fitting settings.93- DFT energies depend on XC functional and numerical grid. Tighten grids for94 sensitive energies, nonlocal corrections, or reproducibility comparisons.95- Post-HF methods should start from a converged and appropriate mean-field96 reference; inspect spin contamination for unrestricted references.97- Periodic calculations use `pyscf.pbc` cells, lattice vectors, pseudopotentials,98 density fitting, and k-points. Do not treat a periodic material as a large99 molecule unless that is the intended approximation.100101## Anti-patterns102103- Do not guess spin from chemical formula alone. Determine charge, electron104 count, multiplicity, and whether restricted/open-shell methods are appropriate.105- Do not compare energies across different basis sets, ECPs, grids, frozen-core106 settings, charge/spin states, or geometries as if they are one calculation.107- Do not ignore `mf.converged` or SCF warnings. Try better initial guesses,108 damping, level shifting, Newton SCF, density fitting, or a more suitable109 reference before reporting results.110- Do not pass RDKit/ASE/pymatgen coordinates into PySCF without checking units,111 atom order, total charge, spin state, and whether hydrogens/protons are112 explicit.113- Do not use molecular `gto.M` for a periodic cell that needs k-points and114 lattice vectors; use `pyscf.pbc.gto.Cell`.115116## Diagnostic checks117118Before trusting outputs, the agent should:119120- Print method, basis, charge, spin, unit, electron count, atom count, and121 coordinates or geometry source.122- Check SCF convergence, total energy, HOMO/LUMO or occupations, and warnings.123- For unrestricted calculations, inspect spin expectation or spin contamination124 where relevant.125- For DFT, record XC functional, grids, dispersion/nonlocal settings, and126 integration-grid changes.127- For correlated methods, record frozen-core settings, reference type, and128 whether amplitudes/convergence are sane.129- For PBC, record lattice vectors, pseudopotentials, k-point mesh, density130 fitting, and whether all-electron or pseudopotential treatment is used.131132## Pointers to deeper material133134- Documentation: https://pyscf.org/135- Quickstart: https://pyscf.org/quickstart.html136- User guide: https://pyscf.org/user/index.html137- Source repository: https://github.com/pyscf/pyscf138- Paper: Sun et al. (2018), "PySCF: the Python-based simulations of chemistry139 framework", WIREs Computational Molecular Science 8, e1340.140 https://doi.org/10.1002/wcms.1340