installing Psi4 and Forte

a step-by-step guide to installing Psi4 and Forte

This tutorial provides a step-by-step guide for installing the quantum chemistry packages Psi4 and Forte in Windows 11 WSL2.

This guide heavily references from Francesco’s psi4/ambit/forte setup (Mac BigSur 11.6.1, Dec. 2021)

1. Update Ubuntu Packages

1.1 Launch WSL

In Windows PowerShell or CMD:

wsl

Enter root mode:

sudo -i

1.2 Change Ubuntu Mirror (Optional)

If network access is slow, consider switching to a faster mirror.

Backup:

cp /etc/apt/sources.list /etc/apt/sources.list.backup

Replace the content of /etc/apt/sources.list with a mirror matching your Ubuntu version.

1.3 Update Packages

apt update
apt upgrade
apt autoremove

Install development tools:

apt install build-essential gfortran

Install spf13-vim (optional):

curl https://j.mp/spf13-vim3 -L > spf13-vim.sh && sh spf13-vim.sh

2. Install CUDA Toolkit (Optional)

Requires NVIDIA driver installed in Windows.

Follow instructions from NVIDIA website.https://developer.nvidia.com/cuda-downloads

Example (WSL-Ubuntu, deb network):

wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda-toolkit-12-6

Verify installation:

nvidia-smi

3. Install Intel oneAPI (Optional)

Install Intel Base Toolkit and HPC Toolkit via APT:https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html

sudo apt update
sudo apt install -y gpg-agent wget
wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB | gpg –dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null
echo “deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main” | sudo tee /etc/apt/sources.list.d/oneAPI.list
sudo apt update
sudo apt install intel-basekit
sudo apt install intel-hpckit

Set up the environment:

source /opt/intel/oneapi/setvars.sh

Optionally, add the following to ~/.bashrc so that the variables are automatically loaded every time starting WSL:

. /opt/intel/oneapi/setvars.sh

4. Configure Python Environment

4.1 Install Miniconda

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

4.2 Add conda-forge Channel

Edit ~/.condarc:

channels:
  - conda-forge
  - defaults

4.3 Create forte.yml

name: forte
dependencies:
  - python=3.12
  - pip
  - cmake
  - clang-format
  - numpy
  - scipy
  - boost
  - hdf5
  - yaml
  - jupyter
  - eigen
  - pytest
  - pydantic
  - pint
  - pybind11
  - pyyaml
  - pythreejs
  - libint

Create environment:

conda env create -f forte.yml
conda activate forte

Add activation command conda activate forte to ~/.bashrc if desired.

5. Install Forte (Non-developer)

The easiest way to install forte is from conda:

conda install conda-forge::forte

Developers may need to compile Forte manually (see below).

6. Install Ambit (Developer)

git clone https://github.com/jturney/ambit.git
cd ambit
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/src/ambit-install \
         -DCMAKE_C_COMPILER=icx \
         -DCMAKE_CXX_COMPILER=icpx
make -j20
make install

Add to ~/.bashrc:

export PYTHONPATH=$HOME/src/ambit-install/lib:$PYTHONPATH
export AMBITPATH=$HOME/src/ambit-install

7. Install block2-preview (Optional for DMRG)

git clone https://github.com/block-hczhai/block2-preview.git
cd block2-preview
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/src/block2-install \
         -DUSE_MKL=ON \
         -DBUILD_CLIB=ON \
         -DLARGE_BOND=ON \
         -DMPI=OFF \
         -DCMAKE_C_COMPILER=icx \
         -DCMAKE_CXX_COMPILER=icpx
make -j20
make install

8. Install Psi4 from Source (Developer)

Install dependencies:

conda install libxc libecpint dkh gau2grid qcelemental qcengine optking

Clone source:

git clone https://github.com/psi4/psi4.git
cd psi4
mkdir build
cd build

Configure:

cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/src/psi4-install \
         -DENABLE_dkh=ON \
         -DENABLE_ambit=ON \
         -DENABLE_ecpint=ON \
         -DMAX_AM_ERI=8 \
         -Dpsi4_CXX_STANDARD=20 \
         -DCMAKE_CXX_STANDARD=20 \
         -Dambit_DIR=$HOME/src/ambit-install/share/cmake/ambit \
         -DCMAKE_C_COMPILER=icx \
         -DCMAKE_CXX_COMPILER=icpx \
         -DCMAKE_Fortran_COMPILER=gfortran

Compile:

make -j20
make install

If Eigen error fatal error: ‘eigen3/Eigen/Core’ file not found occurs, you may install a new eigen via sudo apt install libeigen3-dev. Then, remove CMakeCache.txt and CMakeFiles and reconfigure with -DEigen3_DIR=/usr/share/eigen3/cmake.

Add environment variables to ~/.bashrc:Please check https://psicode.org/psi4manual/1.1.0/build_planning

export PSI4OBJ=$HOME/src/psi4/build
export PSI4INS=$HOME/src/psi4-install
export PSIDATADIR=$PSI4INS/share/psi4
export PSI_SCRATCH=/tmp/scratch/psi4
export PYTHONPATH=$PSI4OBJ/stage/lib:$PYTHONPATH
export PATH=$PSI4OBJ/stage/bin:$PATH

Test:

cd $HOME/src/psi4/tests/scf1
psi4

9. Install Forte (Developer)

9.1 Clone:

git clone https://github.com/evangelistalab/forte.git
cd forte

9.2 Compile

9.2.1 Compile via setup.py (Recommended)

Create setup.cfg:

[CMakeBuild]
ambitpath=$HOME/src/ambit-install
cmake_config_options=-DCMAKE_BUILD_TYPE=Debug -DENABLE_block2=ON -DCMAKE_PREFIX_PATH=$HOME/src/block2-install/share/cmake/block2

You need to replace $HOME to full path in the above lines.

Then execute:

python setup.py develop

9.2.2 Manual CMake build using psi4 --plugin-compile

Create compile-forte.sh:

#! /bin/bash
# Modify the following parameters
ambit_dir=$HOME/src/ambit-install/share/cmake/ambit
block2_dir=$HOME/src/block2-install/share/cmake/block2
srcdir=$HOME/src/forte
build_type=Debug
# Run cmake
cd $srcdir
rm -rf CMakeFiles CMakeCache.txt cmake_install.cmake
cmake_psi4=`psi4 –plugin-compile`
$cmake_psi4 -Dambit_DIR=$ambit_dir -DCMAKE_BUILD_TYPE=$build_type -DMAX_DET_ORB=128 -DENABLE_block2=ON -Dblock2_DIR=$block2_dir
# Compile
make -j20

Execute:

bash compile-forte.sh

Set environment variables in ~/.bashrc:

PYTHONPATH=$HOME/src/forte:$PYTHONPATH

9.3 Test

cd $HOME/src/forte/tests/method
python run_forte_tests.py --type short

🎉 Hooray! You compiled Forte successfully!

Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • setting up WSL2
  • cluster witout internet connection
  • installing CentOS 6 on a cluster node
  • writing scientific papers
  • tutorials for quantum chemistry