Electronic repulsion integral containers.

ebcc.ham.eris.RERIs(cc, array=None, space=None, mo_coeff=None)

Bases: BaseERIs, BaseRHamiltonian

Restricted ERIs container class.

Initialise the ERIs.

Parameters:
  • cc (BaseEBCC) –

    Coupled cluster object.

  • array (Optional[Any], default: None ) –

    ERIs in the MO basis.

  • space (Optional[tuple[Any, ...]], default: None ) –

    Space object for each index.

  • mo_coeff (Optional[tuple[Any, ...]], default: None ) –

    Molecular orbital coefficients for each index.

Source code in ebcc/ham/base.py
def __init__(
    self,
    cc: BaseEBCC,
    array: Optional[Any] = None,
    space: Optional[tuple[Any, ...]] = None,
    mo_coeff: Optional[tuple[Any, ...]] = None,
) -> None:
    """Initialise the ERIs.

    Args:
        cc: Coupled cluster object.
        array: ERIs in the MO basis.
        space: Space object for each index.
        mo_coeff: Molecular orbital coefficients for each index.
    """
    Namespace.__init__(self)

    # Parameters:
    self.__dict__["cc"] = cc
    self.__dict__["space"] = space if space is not None else (cc.space,) * 4
    self.__dict__["mo_coeff"] = mo_coeff if mo_coeff is not None else (cc.mo_coeff,) * 4
    self.__dict__["array"] = array if array is not None else None

ebcc.ham.eris.RERIs.__getitem__(key)

Just-in-time getter.

Parameters:
  • key (str) –

    Key to get.

Returns:
  • NDArray[T]

    ERIs for the given spaces.

Source code in ebcc/ham/eris.py
def __getitem__(self, key: str) -> NDArray[T]:
    """Just-in-time getter.

    Args:
        key: Key to get.

    Returns:
        ERIs for the given spaces.
    """
    if self.array is None:
        if key not in self._members.keys():
            coeffs = [
                self.mo_coeff[i][:, self.space[i].mask(k)].astype(numpy.float64)
                for i, k in enumerate(key)
            ]
            if getattr(self.cc.mf, "_eri", None) is not None:
                block = ao2mo.incore.general(self.cc.mf._eri, coeffs, compact=False)
            else:
                block = ao2mo.kernel(self.cc.mf.mol, coeffs, compact=False)
            block = block.reshape([c.shape[-1] for c in coeffs])
            self._members[key] = block.astype(types[float])
        return self._members[key]
    else:
        i, j, k, l = [self.space[i].mask(k) for i, k in enumerate(key)]
        return self.array[i][:, j][:, :, k][:, :, :, l]  # type: ignore

ebcc.ham.eris.UERIs(cc, array=None, space=None, mo_coeff=None)

Bases: BaseERIs, BaseUHamiltonian

Unrestricted ERIs container class.

Initialise the ERIs.

Parameters:
  • cc (BaseEBCC) –

    Coupled cluster object.

  • array (Optional[Any], default: None ) –

    ERIs in the MO basis.

  • space (Optional[tuple[Any, ...]], default: None ) –

    Space object for each index.

  • mo_coeff (Optional[tuple[Any, ...]], default: None ) –

    Molecular orbital coefficients for each index.

Source code in ebcc/ham/base.py
def __init__(
    self,
    cc: BaseEBCC,
    array: Optional[Any] = None,
    space: Optional[tuple[Any, ...]] = None,
    mo_coeff: Optional[tuple[Any, ...]] = None,
) -> None:
    """Initialise the ERIs.

    Args:
        cc: Coupled cluster object.
        array: ERIs in the MO basis.
        space: Space object for each index.
        mo_coeff: Molecular orbital coefficients for each index.
    """
    Namespace.__init__(self)

    # Parameters:
    self.__dict__["cc"] = cc
    self.__dict__["space"] = space if space is not None else (cc.space,) * 4
    self.__dict__["mo_coeff"] = mo_coeff if mo_coeff is not None else (cc.mo_coeff,) * 4
    self.__dict__["array"] = array if array is not None else None

ebcc.ham.eris.UERIs.__getitem__(key)

Just-in-time getter.

Parameters:
  • key (str) –

    Key to get.

Returns:
  • RERIs

    ERIs for the given spins.

Source code in ebcc/ham/eris.py
def __getitem__(self, key: str) -> RERIs:
    """Just-in-time getter.

    Args:
        key: Key to get.

    Returns:
        ERIs for the given spins.
    """
    if key not in ("aaaa", "aabb", "bbaa", "bbbb"):
        raise KeyError(f"Invalid key: {key}")
    if key not in self._members:
        i = "ab".index(key[0])
        j = "ab".index(key[2])
        ij = i * (i + 1) // 2 + j

        if self.array is not None:
            array = self.array[ij]
            if key == "bbaa":
                array = array.transpose(2, 3, 0, 1)
        elif isinstance(self.cc.mf._eri, tuple):
            # Support spin-dependent integrals in the mean-field
            coeffs = [
                self.mo_coeff[x][y].astype(numpy.float64)
                for y, x in enumerate(sorted((i, i, j, j)))
            ]
            if getattr(self.cc.mf, "_eri", None) is not None:
                array = ao2mo.incore.general(self.cc.mf.mol, coeffs, compact=False)
            else:
                array = ao2mo.kernel(self.cc.mf.mol, coeffs, compact=False)
            if key == "bbaa":
                array = array.transpose(2, 3, 0, 1)
            array = array.astype(types[float])
        else:
            array = None

        self._members[key] = RERIs(
            self.cc,
            array=array,
            space=(self.space[0][i], self.space[1][i], self.space[2][j], self.space[3][j]),
            mo_coeff=(
                self.mo_coeff[0][i],
                self.mo_coeff[1][i],
                self.mo_coeff[2][j],
                self.mo_coeff[3][j],
            ),
        )
    return self._members[key]

ebcc.ham.eris.GERIs(*args, **kwargs)

Bases: BaseERIs, BaseGHamiltonian

Generalised ERIs container class.

Initialise the class.

Source code in ebcc/ham/eris.py
def __init__(self, *args: Any, **kwargs: Any) -> None:
    """Initialise the class."""
    super().__init__(*args, **kwargs)
    if self.array is None:
        mo_a = [mo[: self.cc.mf.mol.nao].astype(numpy.float64) for mo in self.mo_coeff]
        mo_b = [mo[self.cc.mf.mol.nao :].astype(numpy.float64) for mo in self.mo_coeff]
        if getattr(self.cc.mf, "_eri", None) is not None:
            array = ao2mo.incore.general(self.cc.mf._eri, mo_a)
            array += ao2mo.incore.general(self.cc.mf._eri, mo_b)
            array += ao2mo.incore.general(self.cc.mf._eri, mo_a[:2] + mo_b[2:])
            array += ao2mo.incore.general(self.cc.mf._eri, mo_b[:2] + mo_a[2:])
        else:
            array = ao2mo.kernel(self.cc.mf.mol, mo_a)
            array += ao2mo.kernel(self.cc.mf.mol, mo_b)
            array += ao2mo.kernel(self.cc.mf.mol, mo_a[:2] + mo_b[2:])
            array += ao2mo.kernel(self.cc.mf.mol, mo_b[:2] + mo_a[2:])
        array = ao2mo.addons.restore(1, array, self.cc.nmo).reshape((self.cc.nmo,) * 4)
        array = array.astype(types[float])
        array = array.transpose(0, 2, 1, 3) - array.transpose(0, 2, 3, 1)
        self.__dict__["array"] = array

ebcc.ham.eris.GERIs.__getitem__(key)

Just-in-time getter.

Parameters:
  • key (str) –

    Key to get.

Returns:
  • NDArray[T]

    ERIs for the given spaces.

Source code in ebcc/ham/eris.py
def __getitem__(self, key: str) -> NDArray[T]:
    """Just-in-time getter.

    Args:
        key: Key to get.

    Returns:
        ERIs for the given spaces.
    """
    i, j, k, l = [self.space[i].mask(k) for i, k in enumerate(key)]
    return self.array[i][:, j][:, :, k][:, :, :, l]  # type: ignore