OpenFermion-PySCF

raw JSON →
0.5 verified Fri May 01 auth: no python

A plugin that interfaces OpenFermion with PySCF, enabling the construction of fermionic Hamiltonians from molecular orbital integrals computed by PySCF. Current version 0.5. Low release cadence; no updates since 2021.

pip install openfermionpyscf
error ModuleNotFoundError: No module named 'pyscf'
cause openfermionpyscf does not install pyscf automatically.
fix
pip install pyscf
error AttributeError: module 'openfermionpyscf' has no attribute 'run_pyscf'
cause Using an outdated version of the package or incorrect import path.
fix
Ensure openfermionpyscf is version 0.5 or later. Import as 'from openfermionpyscf import run_pyscf'.
error KeyError: 'mo_occ'
cause PySCF version mismatch; the plugin expects a specific format from PySCF's output.
fix
Downgrade PySCF to a version compatible with openfermionpyscf 0.5 (e.g., pyscf==1.7.6).
gotcha run_pyscf modifies the MolecularData object in-place and returns it. Do not use the returned value as a separate instance; it is the same object.
fix Use the returned object or simply use the original variable; they are identical.
deprecated The function run_pyscf uses a deprecated interface for PySCF 2.x. Future versions of PySCF may break compatibility.
fix Pin PySCF to a compatible version (e.g., <2.1) or contribute an update to the plugin.
gotcha If pyscf is not installed separately, importing openfermionpyscf will fail with no clear error. The package does not list pyscf as a dependency.
fix Install pyscf explicitly: pip install pyscf

Compute H2 Hamiltonian using OpenFermion and PySCF.

from openfermion import MolecularData
from openfermionpyscf import run_pyscf

# Set up molecule
mol = MolecularData(
    geometry=[('H', (0., 0., 0.)), ('H', (0., 0., 0.7414))],
    basis='sto-3g',
    multiplicity=1,
    charge=0
)
mol = run_pyscf(mol)
print(mol.get_hamiltonian())