The Python-based Simulations of Chemistry Framework (PySCF)

Qiming Sun, Timothy C. Berkelbach, Nick S. Blunt, George H. Booth, Sheng Guo, Zhendong Li, Junzi Liu, James McClain, Elvira R. Sayfutyarova, Sandeep Sharma, Sebastian Wouters, Garnet Kin‐Lic Chan · DOI

Abstract

PySCF is a general-purpose electronic structure platform designed from the ground up to emphasize code simplicity, both to aid new method development, as well as for flexibility in computational workflow. The package provides a wide range of tools to support simulations of finite size systems, extended systems with periodic boundary conditions, low dimensional periodic systems, and custom Hamiltonians, using mean-field and post-mean-field methods with standard Gaussian basis functions. To ensure ease of extensibility, PySCF uses the Python language to implement almost all its features, while computationally critical paths are implemented with heavily optimized C routines. Using this combined Python/C implementation, the package is as efficient as the best existing C or Fortran based quantum chemistry programs. In this paper we document the capabilities and design philosophy of the current version of the PySCF package.

Introduction

In the field of quantum chemistry, researchers have historically faced a difficult trade-off between productivity and performance. Traditional software packages, often written in legacy Fortran or C++, offer high execution speeds but function as "black boxes." These programs are notoriously difficult to modify, extend, or integrate into modern data science workflows, often relying on rigid, domain-specific input languages that hinder automation and complex experimentation.

PySCF (Python-based Simulations of Chemistry Framework) was developed to resolve this tension. It provides a "hacker-friendly" platform for method developers that remains as performant as monolithic C/Fortran programs. By prioritizing code simplicity and developer flexibility, PySCF serves as a versatile toolbox for simulating molecular systems, periodic solids, and custom model Hamiltonians.

Design Philosophy and Methods

PySCF is built around the core philosophy of "simplicity, generality, and efficiency, in that order." This is achieved through several distinct architectural choices:

Python/C Hybrid Architecture

To maintain high performance without sacrificing readability, PySCF implements high-level logic and APIs in pure Python. Computationally intensive "hot paths"—specifically integral evaluation and tensor contractions—are offloaded to heavily optimized C libraries. A central component of this efficiency is the Libcint integral engine, which allows PySCF to match the speed of traditional compiled codes.

Functional Programming Approach

Unlike many modern software projects that utilize complex Object-Oriented Programming (OOP) hierarchies, PySCF favors a functional programming style. Most functions are designed to be "pure" and state-free, meaning they do not depend on or modify hidden global variables. This design choice makes the codebase significantly easier to debug and allows researchers to mix and match functions independently to create custom workflows.

Extensibility via Method Decoration

Advanced features, such as relativistic corrections or density fitting, are not hard-coded into the primary solvers. Instead, they function as plugins that can be "decorated" onto a standard calculation object at runtime. This modularity ensures the core code remains lean while allowing for sophisticated scientific extensions.

Capabilities and Benchmarking

PySCF supports a wide array of electronic structure methods using standard Gaussian basis functions. Its capabilities are demonstrated across several challenging benchmarks:

  • Molecular Systems: The framework's efficiency is highlighted by its performance on the Fe(II)-porphine molecule, a complex open-shell system. Using the Second-Order SCF (CIAH) algorithm, PySCF can converge a difficult Hartree-Fock calculation involving nearly 3,000 atomic orbitals in a single day on a 16-core node.
  • Large-Scale Calculations: For high-level correlation methods, PySCF's optimized Coupled Cluster (CCSD) implementation can process an iteration for an $H_{50}$ chain (with 1,500 virtual orbitals) in less than three hours on a 28-core node.
  • Periodic Boundary Conditions (PBC): Uniquely, PySCF uses Gaussian basis sets for both molecules and solids. This allows researchers to apply the same methods (e.g., CCSD or Density Functional Theory) to a single molecule or a crystal lattice with minimal code changes.
  • Custom Hamiltonians: The framework can handle non-standard models, such as the Hubbard Model, demonstrating its utility for condensed matter physics beyond standard chemistry applications.

Key Insights

  • Python as the Input Language: PySCF does not use a custom input format; a simulation is simply a Python script. This grants users the full power of the Python ecosystem—including NumPy, SciPy, and Matplotlib—directly within their computational chemistry workflows.
  • Simplicity and Efficiency: The authors demonstrate that keeping the high-level code simple makes it easier to identify and optimize the specific routines that impact performance. This approach allows the framework to handle simulations with over 5,000 basis functions on a single symmetric multiprocessing (SMP) node.
  • Daemon-based Parallelism: To manage parallel computing without the boilerplate of Message Passing Interface (MPI), PySCF utilizes a "daemon" approach. Remote nodes wait to receive and execute functions dispatched by a master process, simplifying the user experience in high-performance computing environments.

Limitations and Future Work

While PySCF is highly efficient, certain multireference methods like CASSCF still face significant memory and computational scaling challenges as the "active space" of electrons increases. The framework mitigates this by providing interfaces to external high-performance solvers like DMRG (Density Matrix Renormalization Group).

Additionally, the authors chose to prioritize code readability over certain hyper-specialized optimizations, such as aggressive data compression. While PySCF matches best-in-class performance for most applications, niche cases requiring extreme optimization may still favor specialized codes. Future development continues to expand the library's reach into excited-state periodic methods and deeper relativistic treatments.

Summary updated

BibTeX
@inproceedings{sun2017python,
  author = {Qiming Sun and Timothy C. Berkelbach and Nick S. Blunt and George H. Booth and Sheng Guo and Zhendong Li and Junzi Liu and James McClain and Elvira R. Sayfutyarova and Sandeep Sharma and Sebastian Wouters and Garnet Kin‐Lic Chan},
  title = {{The Python-based Simulations of Chemistry Framework (PySCF)}},
  booktitle = {Wiley},
  year = {2017},
  doi = {10.1002/wcms.1340},
}
Figure