Extensions#

Due to its flexibility and modular nature, many extensions have been developed based on PySCF. As a courtesy, repositories for some of these extensions are hosted by the PySCF organization’s GitHub. However, the PySCF organization provides no support for these extensions, nor a guarantee of future compatibility. Questions should be addressed to the authors of the extension, and issues can be raised on the GitHub repository of the extension.

Once an extension module has been correctly installed (see How to install extensions), you can use it as a regular submodule of PySCF, e.g.,

import pyscf
from pyscf.semiempirical import MINDO3
mol = pyscf.M(atom='N 0 0 0; N 0 0 1')
MINDO3(mol).run()

A list of PySCF extensions is given below.

How to install extensions#

Many extension modules (e.g., the semiempirical module) can be installed using pip’s extra dependency mechanism,

pip install pyscf[semiempirical]

Although not recommended, all extension modules can be installed,

pip install pyscf[all]

How to install extensions (advanced)#

Based on the technique of namespace packages specified in PEP 420, PySCF has developed a couple of methods to install the extension modules.

Pip command#

For pip version newer than 19.0, projects hosted on GitHub can be installed on the command line,

pip install git+https://github.com/pyscf/semiempirical

A particular release on GitHub can be installed with the release URL you can look up on GitHub,

pip install https://github.com/pyscf/semiempirical/archive/v0.1.0.tar.gz

Pip command for local paths#

If you wish to load an extension module developed in a local directory, you can use the local install mode of pip. Use of a Python virtual environment is recommended to avoid polluting the system default Python runtime environment, for example,

python -m venv /home/abc/pyscf-local-env
source /home/abc/pyscf-local-env/bin/activate
git clone https://github.com/pyscf/semiempirical /home/abc/semiempirical
pip install -e /home/abc/semiempirical

Environment variable PYSCF_EXT_PATH#

You can place the location of each extension module (or a file that contains these locations) in this environment variable. The PySCF library will parse the paths defined in this environment variable, and load the relevant submodules. For example,

git clone https://github.com/pyscf/semiempirical /home/abc/semiempirical
git clone https://github.com/pyscf/doci /home/abc/doci
git clone https://github.com/pyscf/dftd3 /home/abc/dftd3
echo /home/abc/doci > /home/abc/.pyscf_ext_modules
echo /home/abc/dftd3 >> /home/abc/.pyscf_ext_modules
export PYSCF_EXT_PATH=/home/abc/semiempirical:/home/abc/.pyscf_ext_modules

Using this definition of PYSCF_EXT_PATH, the three extension submodules (semiempirical, doci, dftd3) are loaded when PySCF is imported, and you don’t have to use a Python virtual environment.

Examples#

Installing DMRG solvers#

The Density Matrix Renormalization Group (DMRG) theory is a method for solving ab initio quantum chemistry problems. PySCF can be used with three implementations of DMRG: Block, block2, and CheMPS2.

Installing Block requires a C++11 compiler. Alternatively, you can download the precompiled Block binary from https://sanshar.github.io/Block/build.html .

block2 can be easily installed via pip install block2 or pip install block2-mpi. To building block2 from source, please refer to the installation guide https://block2.readthedocs.io/en/latest/user/installation.html .

Before using Block or CheMPS2, you need create a configuration file pyscf/dmrgscf/settings.py (as shown by the settings.py.example) to store the path where the DMRG solver was installed.

Installing TBLIS#

TBLIS provides a native algorithm for performing tensor contraction for arbitrarily high-dimensional tensors. Unlike the implementation in numpy.einsum, which transforms tensors into matrices by permuting the indices, invokes BLAS for matrix contractions, and then back-permutes the results, TBLIS eliminates the need for tensor transpositions and data movements. TBLIS eliminates the need to transpose tensors and data movements. This results in improved performance in various correlated quantum chemistry methods in PySCF, such as the coupled cluster methods.

The tblis-einsum extension provides an interface to TBLIS, which offers an efficient implementation for tensor contractions in the style of numpy.einsum. The tblis-einsum plugin can be installed using the command:

$ pip install pyscf-tblis