Cholesky-decomposed electron repulsion integral containers.

ebcc.ham.cderis.RCDERIs(cc, array=None, space=None, mo_coeff=None)

Bases: BaseERIs, BaseRHamiltonian

Restricted Cholesky-decomposed 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.cderis.RCDERIs.__getitem__(key, e2=False)

Just-in-time getter.

Parameters:
  • key (str) –

    Key to get.

  • e2 (Optional[bool], default: False ) –

    Whether the key is for the second electron.

Returns:
  • NDArray[T]

    CDERIs for the given spaces.

Source code in ebcc/ham/cderis.py
def __getitem__(self, key: str, e2: Optional[bool] = False) -> NDArray[T]:
    """Just-in-time getter.

    Args:
        key: Key to get.
        e2: Whether the key is for the second electron.

    Returns:
        CDERIs for the given spaces.
    """
    if self.array is not None:
        raise NotImplementedError("`array` is not supported for CDERIs.")

    if len(key) == 4:
        v1 = self.__getitem__("Q" + key[:2])
        v2 = self.__getitem__("Q" + key[2:], e2=True)  # type: ignore
        return util.einsum("Qij,Qkl->ijkl", v1, v2)
    elif len(key) == 3:
        key = key[1:]
    else:
        raise KeyError("Key must be of length 3 or 4.")
    key_e2 = f"{key}_{'e1' if not e2 else 'e2'}"

    # Check the DF is built incore
    if not isinstance(self.cc.mf.with_df._cderi, np.ndarray):
        with lib.temporary_env(self.cc.mf.with_df, max_memory=1e6):
            self.cc.mf.with_df.build()

    if key_e2 not in self._members:
        s = 0 if not e2 else 2
        coeffs = [
            self.mo_coeff[i + s][:, self.space[i + s].mask(k)].astype(numpy.float64)
            for i, k in enumerate(key)
        ]
        ijslice = (
            0,
            coeffs[0].shape[-1],
            coeffs[0].shape[-1],
            coeffs[0].shape[-1] + coeffs[1].shape[-1],
        )
        coeffs = numpy.concatenate(coeffs, axis=1)
        block = ao2mo._ao2mo.nr_e2(
            self.cc.mf.with_df._cderi, coeffs, ijslice, aosym="s2", mosym="s1"
        )
        block = block.reshape(-1, ijslice[1] - ijslice[0], ijslice[3] - ijslice[2])
        self._members[key_e2] = block.astype(types[float])

    return self._members[key_e2]

ebcc.ham.cderis.UCDERIs(cc, array=None, space=None, mo_coeff=None)

Bases: BaseERIs, BaseUHamiltonian

Unrestricted Cholesky-decomposed 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.cderis.UCDERIs.__getitem__(key)

Just-in-time getter.

Parameters:
  • key (str) –

    Key to get.

Returns:
  • RCDERIs

    CDERIs for the given spins.

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

    Args:
        key: Key to get.

    Returns:
        CDERIs for the given spins.
    """
    if len(key) == 3:
        key = key[1:]
    if key not in ("aa", "bb", "aaaa", "aabb", "bbaa", "bbbb"):
        raise KeyError(f"Invalid key: {key}")
    if len(key) == 2:
        key = key + key
    i = "ab".index(key[0])
    j = "ab".index(key[2])

    if key not in self._members:
        self._members[key] = RCDERIs(
            self.cc,
            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]