
Python for Quantum Chemistry
A Full Stack Programming Guide
- 1st Edition, Volume 23 - March 28, 2025
- Author: Qiming Sun
- Language: English
- Paperback ISBN:9 7 8 - 0 - 4 4 3 - 2 3 8 3 7 - 6
- eBook ISBN:9 7 8 - 0 - 4 4 3 - 2 3 8 3 6 - 9
Quantum chemistry requires ever higher computational performance, with more and more sophisticated and dedicated Python scripts being required to solve challenging problems. Al… Read more

Purchase options

Institutional subscription on ScienceDirect
Request a sales quoteQuantum chemistry requires ever higher computational performance, with more and more sophisticated and dedicated Python scripts being required to solve challenging problems. Although resources for basic use of Python are widely (and often freely) available online and in literature, truly cohesive materials for advanced Python programming skills are lacking.
Qiming Sun, a developer of the popular Python package PySCF, provides a comprehensive, end-to-end practical resource for researchers and engineers who have basic Python programming experiences chiefly in computational chemistry but want to take their use of the software forwards to the next level, the book provides an insightful exploration of Numpy, Pandas, and other data analysis tools. Readers will learn how to manage their Python computational projects in a professional way, with various tools and protocols for computational chemistry research and general scientific computing tasks exhibited and analysed from a technical perspective. Multiple programming paradigms including object-oriented, functional, meta-programming, dynamic, concurrent, and vector-oriented are illustrated in various technology scenarios allowing readers to properly use them to enhance their program projects. Readers will also learn how to use the presented optimization technologies to speed up their Python applications, even to the level as fast as a native C++ implementation. The applications of these technologies are then demonstrated using quantum chemistry Python applications.
Python for Quantum Chemistry: A Full Stack Programming Guide is written primarily for graduate students, researchers and software engineers working primarily in the fields of theoretical chemistry, computational chemistry, condensed matter physics, material modelling, molecular simulations, and quantum computing.
- End-to end guide for advanced Python programming skills and tools related to quantum chemistry research
- Tackles the following questions: How can you ensure the Python runtime is manageable when the preliminary implementation becomes complicated or evolves many branches? How do I ensure that others' Python program works properly in my project? How do I make my Python project reusable for others?
- Covers in depth the crucial topic of Python code optimization methods with high-performance computing technologies
- Provides examples of Python applications with cutting-edge technologies such as automatic code generation, cloud computing, and GPGPU
- Includes discussion of Python runtime mechanism and advanced Python technologies
- Title of Book
- Cover image
- Title page
- Table of Contents
- Copyright
- Preface
- List of acronyms
- Chapter 1: Python programming environment
- 1.1. Python package system
- 1.1.1. Python runtime
- 1.1.2. Package, sub-package, and module
- 1.1.3. Python program as CLI tools
- 1.1.4. Virtual environment
- 1.1.5. Conda
- 1.2. Python programs in Docker
- 1.3. Managing a Python project
- 1.3.1. Version control
- 1.3.2. Testing a Python program
- 1.3.3. Coding style and static checks
- 1.3.4. Releasing a Python package
- 1.3.5. CI and DevOps workflow
- 1.4. Modular design and object-oriented programming
- 1.4.1. Method resolution order in multiple inheritances
- 1.4.2. Mixins
- 1.5. Working with IPython and Jupyter
- 1.5.1. Startup configurations
- 1.5.2. Extensions
- 1.5.3. Magics
- 1.5.4. Remote execution
- Summary
- Chapter 2: Data processing
- 2.1. Vectorized data processing with NumPy
- 2.1.1. The basics of NumPy
- 2.1.2. Universal functions (ufunc)
- 2.1.3. Inplace operations
- 2.1.4. Broadcasting
- 2.1.5. Fancy indexing
- 2.1.6. Mask array
- 2.1.7. Data structure of NumPy ndarray
- 2.1.8. Array views
- 2.1.9. The reshape function
- 2.2. Data types in NumPy
- 2.2.1. Type casting
- 2.2.2. Scalar type and zero-dimensional array
- 2.2.3. Infinity (inf) and not-a-number (nan)
- 2.2.4. Data with high precision
- 2.2.5. Structured array
- 2.3. Data with labels: Pandas
- 2.3.1. Pandas data objects
- 2.3.2. Broadcasting
- 2.3.3. Indexing
- 2.3.4. query and eval methods
- 2.3.5. Altering structure of DataFrame
- 2.3.6. Data types
- 2.3.7. Missing data
- 2.3.8. Grouping and aggregation
- 2.3.9. View and copy
- Summary
- Chapter 3: Visualization
- 3.1. Matplotlib
- 3.2. Pandas visualization
- 3.3. Mayavi for 3D plotting
- 3.4. Quantum chemistry visualization
- 3.4.1. Jinja template
- 3.4.2. Molden format
- 3.4.3. Cube format
- Summary
- Chapter 4: Scientific computing tools
- 4.1. Linear algebra
- 4.2. Sparse matrices
- 4.2.1. Storage formats
- 4.2.2. Linear algebra for sparse matrix
- 4.2.3. Linear operator
- 4.3. Tensor contractions
- 4.4. Discrete Fourier transforms
- 4.4.1. SciPy FFT
- 4.4.2. Intel FFT
- 4.4.3. PyFFTW
- 4.4.4. FFT performance benchmark
- 4.4.5. How to choose FFT libraries?
- Summary
- Chapter 5: Meta-programming and non-numerical computation
- 5.1. Code generation
- 5.1.1. eval and exec
- 5.1.2. Composing code programmatically
- 5.1.3. Manipulating classes and functions at runtime
- 5.1.4. Python AST
- 5.2. Symbolic computation
- 5.3. Automatic differentiation
- 5.3.1. PyTorch
- 5.3.2. JAX
- Summary
- Chapter 6: Input and output
- 6.1. Serialization
- 6.1.1. Pickle
- 6.1.2. JSON
- 6.1.3. YAML
- 6.2. File I/O
- 6.2.1. The npy format
- 6.2.2. HDF5 storage
- 6.2.3. Memory mapping
- 6.3. I/O buffering
- 6.4. In-memory I/O
- 6.5. Network I/O
- 6.5.1. Network requests over HTTP
- 6.5.2. REST API
- 6.5.3. RPC over HTTP
- 6.5.4. gPRC
- 6.5.5. Apache arrow
- Summary
- Chapter 7: Working with cloud
- 7.1. Utilizing cloud computing
- 7.1.1. Comparison between cloud and supercomputers
- 7.1.2. Designing a workflow
- 7.1.3. Computing resources
- 7.1.4. Communications among cloud services
- 7.1.5. Function-as-a-Service
- 7.2. Distributed job executors
- 7.2.1. Celery
- 7.2.2. Dask
- 7.2.3. Ray
- Summary
- Chapter 8: Foreign language interfaces
- 8.1. Inter-process communication interfaces
- 8.2. C/C++ interfaces
- 8.2.1. Data types and type conversion
- 8.2.2. Cython
- 8.2.3. pybind11
- 8.2.4. Compiling C++ code into a Python module
- 8.3. Foreign function interfaces
- 8.3.1. Ctypes
- 8.3.2. CFFI
- 8.3.3. Memory leaks
- 8.3.4. Duplicated function names in extensions
- 8.4. Fortran interfaces
- 8.4.1. ctypes for Fortran
- 8.4.2. f2py compiler
- 8.5. Rust interfaces
- Summary
- Chapter 9: Program performance optimization
- 9.1. Principles for performance optimization
- 9.1.1. Cost comparison between Python and C/C++ operations
- 9.1.2. Hardware and operating system overhead
- 9.1.3. Latency and throughput
- 9.1.4. Strategies for optimizing latency and throughput
- 9.1.5. Computation bound and I/O bound
- 9.1.6. Instruction level parallelism
- 9.2. Profiling
- 9.2.1. Benchmark tests
- 9.2.2. Python built-in profiling tools
- 9.2.3. Line profiler
- 9.2.4. Sampling profiler
- 9.2.5. Perf
- 9.3. Python level optimization
- 9.3.1. The dis module
- 9.3.2. Performance-friendly Python code
- 9.3.3. Utilizing tensor operations
- 9.3.4. Optimizing tensor indexing efficiency
- 9.4. Compiling Python code
- 9.4.1. Numba
- 9.4.2. Cython
- 9.4.3. Pythran
- 9.4.4. Comparison of Cython, Pythran, and Numba
- 9.5. Optimization with compiled languages
- 9.5.1. GCC compiler
- 9.6. Optimization for I/O
- 9.6.1. Storage layout
- 9.6.2. Compressing data
- 9.6.3. Overlapping computation and I/O
- 9.7. Precomputation and memoization
- 9.7.1. LRU cache
- 9.7.2. Functional programming
- 9.7.3. Dynamic programming
- 9.8. Optimization with lazy evaluation
- Summary
- Chapter 10: Parallel computation
- 10.1. Multithreading
- 10.1.1. The threading module
- 10.1.2. ThreadPoolExecutor
- 10.2. Lock and thread synchronization
- 10.2.1. Mutex
- 10.2.2. Event and condition variable
- 10.3. Producer-consumer model
- 10.4. Pipeline executor
- 10.5. Asynchronous program
- 10.5.1. Similarity between asynchronous programming and lazy evaluation
- 10.5.2. Asynchronous program with coroutines and asyncio
- 10.6. Multiprocessing
- 10.6.1. Data communication in multiprocessing.Process
- 10.6.2. Data communication in ProcessPoolExecutor
- 10.6.3. Locks in the multiprocessing program
- 10.7. Inter-process communication
- 10.8. OpenMP
- 10.9. MPI
- 10.9.1. Naming conventions in MPI4Py
- 10.9.2. SPMD MPI programs in Python
- 10.9.3. Integrating MPI into serial program
- 10.9.4. Shared memory
- Summary
- Chapter 11: GPU programming
- 11.1. Configuring GPU runtime environment
- 11.2. Architecture-independent optimization
- 11.2.1. CuPy
- 11.2.2. PyTorch
- 11.2.3. JAX
- 11.3. Architecture-aware optimization
- 11.3.1. Pinned memory
- 11.3.2. CUDA stream
- 11.4. Custom GPU kernels in Python
- 11.4.1. Kernel in CUDA code
- 11.4.2. Numba CUDA JIT
- 11.4.3. CuPy custom kernel
- 11.4.4. Integrating CUDA kernels using ctypes
- Summary
- Chapter 12: Integral evaluation
- 12.1. Analytical integral evaluation for Gaussian type orbitals
- 12.1.1. Data structure for GTO basis
- 12.1.2. Basic types for analytical GTO integrals
- 12.1.3. Recurrence relations and the dynamic programming implementation
- 12.1.4. Converting recursion to iteration
- 12.1.5. Eliminating branches and adjusting iterations
- 12.1.6. Optimization with Numba JIT compilation
- 12.1.7. Optimization with Cython compilation
- 12.1.8. Optimization with meta-programming techniques
- 12.1.9. Performance benchmark
- 12.1.10. Other performance factors
- 12.2. Numerical integration
- 12.2.1. Gaussian quadrature
- 12.2.2. Generating quadrature roots and weights
- 12.2.3. Approximating quadratures
- 12.2.4. Numerical integration with Fourier transform
- 12.3. Integral transformation
- Summary
- Chapter 13: Mean-field methods
- 13.1. The self-consistency iteration program
- 13.2. Coulomb and exchange matrices
- 13.2.1. Integral screening for Coulomb and exchange matrices
- 13.2.2. J-engine
- 13.3. Integrals for exchange-correlation functionals
- 13.4. DIIS
- 13.5. Design of Python classes for mean-field methods
- 13.5.1. New mean-field classes via class inheritances
- 13.5.2. Mean-field classes via the visitor pattern
- 13.5.3. Dynamic patches to mean-field objects
- 13.5.4. Dynamic mean-field classes
- 13.6. Speeding up mean-field calculations
- 13.6.1. Cholesky decomposition and resolution of identity methods
- 13.6.2. Improving convergence using DIIS
- 13.6.3. Improving initial guess
- Summary
- Chapter 14: Post Hartree-Fock I: full configuration interaction
- 14.1. Theory of full configuration interaction
- 14.2. The string representation
- 14.3. Davidson diagonalization
- 14.4. Direct CI algorithm
- 14.5. Optimizing tensor contractions
- 14.6. Optimization for memory efficiency
- 14.7. Parallel computation
- Summary
- Chapter 15: Post Hartree-Fock II: coupled cluster
- 15.1. Coupled cluster theory
- 15.2. CCD program
- 15.3. Optimizing data transferring
- 15.4. Just-in-time compilation for I/O readahead
- 15.5. Symbolic programming for coupled cluster theory
- 15.5.1. Defining fundamental symbolic elements
- 15.5.2. Implementing computation rules
- 15.5.3. Evaluating expressions symbolically
- 15.5.4. Generating CCD equations symbolically
- 15.5.5. Applying permutation symmetry to CCD tensors
- Summary
- Chapter 16: Molecular properties
- 16.1. Molecular properties for single-particle operators
- 16.2. Analytical nuclear gradients
- 16.2.1. Basic equations of Hartree-Fock derivatives
- 16.2.2. Derivatives of integrals
- 16.2.3. Nuclear gradients for RHF energy
- 16.2.4. Nuclear gradients with finite difference
- 16.2.5. First order molecular orbitals
- 16.3. Krylov subspace linear equation solver
- 16.4. Nuclear gradients with automatic differentiation
- 16.4.1. Differentiable Python class
- 16.4.2. Implicit differentiation
- 16.4.3. Higher-order derivatives
- 16.4.4. Conversion between JVP and VJP
- Summary
- Index
- No. of pages: 754
- Language: English
- Edition: 1
- Volume: 23
- Published: March 28, 2025
- Imprint: Elsevier
- Paperback ISBN: 9780443238376
- eBook ISBN: 9780443238369
QS