Hamiltonian Builder#

The HamiltonianBuilder takes an input SCF object, and outputs coefficients for a second-quantised Hamiltonian.

Note it can be used with any PySCF SCF object, not just those which have been embedded with Nbed.

Class to build qubit Hamiltonians from scf object.

class nbed.ham_builder.HamiltonianBuilder(scf_method: SCF, constant_e_shift: float = 0, n_frozen_core: int = 0, n_frozen_virt: int = 0)[source]#

Bases: object

Class to build molecular hamiltonians.

build() tuple[float, ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]#

Returns second quantized fermionic molecular Hamiltonian.

constant_e_shift is a constant energy addition… in this code this will be the classical embedding energy that corrects for the full system.

The active_indices and occupied indices are an active space approximation… where occupied and virtual orbitals can be frozen. This is different to removing the environment orbitals, as core_constant terms must be added to make this approximation.

Parameters:
  • n_qubits (int) – Either total number of qubits to use (positive value) or number of qubits to reduce size by (negative value).

  • taper (bool) – Whether to taper the Hamiltonian.

  • contextual_space (bool) – Whether to project onto the contextual subspace.

  • core_indices (List[int]) – Indices of core orbitals.

  • active_indices (List[int]) – Indices of active orbitals.

Returns:

The one and two body spinorb coefficients

Return type:

(float, npt.NDArray, npt.NDArray)

nbed.ham_builder.get_active_space_integrals(one_body_integrals: ndarray, two_body_integrals: ndarray, occupied_indices: list, active_indices: list) tuple[float, ndarray, ndarray][source]#

Restricts a molecule at a spatial orbital level to an active space.

This function is from Openfermion, see additonal documentation there.

This active space may be defined by a list of active indices and

doubly occupied indices. Note that one_body_integrals and two_body_integrals must be defined n an orthonormal basis set.

Parameters:
  • one_body_integrals – One-body integrals of the target Hamiltonian

  • two_body_integrals – Two-body integrals of the target Hamiltonian

  • occupied_indices – A list of spatial orbital indices indicating which orbitals should be considered doubly occupied.

  • active_indices – A list of spatial orbital indices indicating which orbitals should be considered active.

Returns:

Tuple with the following entries:

core_constant: Adjustment to constant shift in Hamiltonian from integrating out core orbitals

one_body_integrals_new: one-electron integrals over active space.

two_body_integrals_new: two-electron integrals over active space.

Return type:

tuple

nbed.ham_builder.reduce_virtuals(scf_method, n_frozen_virt: int) SCF[source]#

Reduce the number of virtual orbitals.

Parameters:
  • scf_method (scf.hf.SCF) – A PySCF scf object.

  • n_frozen_virt (int) – Number of virtual orbitals to freeze.

Returns:

A new scf object with fewer virtual orbitals.

Return type:

scf.hf.SCF