afqmctools.hamiltonian package#

Subpackages#

Submodules#

afqmctools.hamiltonian.converter module#

afqmctools.hamiltonian.converter.check_sym(ikjl, nmo, sym)#

Check permutational symmetry of integral

Parameters:
  • ikjl (tuple of ints) – Orbital indices of ERI.

  • nmo (int) – Number of orbitals

  • sym (int) – Desired permutational symmetry to check.

Returns:

sym_allowed – True if integral is unique from set of equivalent.

Return type:

bool

afqmctools.hamiltonian.converter.fcidump_header(nel, norb, spin)#

Writes a header for a FCIDUMP file.

Parameters:
  • nel (int) – Total number of electrons.

  • norb (int) – Number of orbitals.

  • spin (int) – Spin of the system.

Returns:

header – Header for FCIDUMP file.

Return type:

str

afqmctools.hamiltonian.converter.fmt_integral(intg, i, k, j, l, cplx, paren=False)#

Format integral for FCIDUMP.

FCIDUMP files contain integrals with one matrix element per line. Integral lines are formatted as:s

  • real 2-body integrals ` (ij|kl) i k j l`

  • complex 2-body integrals ` Re[(ij|kl)] Im[(ij|kl)] i k j l` -OR- ` (Re[(ij|kl)], Im[(ij|kl)]) i k j l`

  • real 1-body integrals ` h_{ik} i k 0 0`

  • complex 1-body integrals ` Re[h_{ik}] Im[h_{ik}] i k 0 0` -OR- ` (Re[h_{ik}], Im[h_{ik}]) i k 0 0`

  • real constant integrals ` C 0 0 0 0`

  • complex constant integrals ` Re[C] Im[C] 0 0 0 0` -OR- ` (Re[C], Im[C]) 0 0 0 0`

where the variation in complex-valued integral format depends on which code will be used to read the FCIDUMP file.

Parameters:
  • intg (float|complex) – Integral value.

  • i (int) – Orbital indices.

  • k (int) – Orbital indices.

  • j (int) – Orbital indices.

  • l (int) – Orbital indices.

  • cplx (bool) – If True, then integrals are printed as complex-valued

  • paren (bool) – If True, complex-valued integrals are printed in parenthesis

afqmctools.hamiltonian.converter.get_kpoint_chol(filename, nchol_pk, minus_k, i, qk_k2, nmo_pk)#

Read standard-format Cholesky vectors for Q = i with time-reversal handling.

Loads Hamiltonian/KPFactorized/L{min(i, -i)} and returns per-k-point Cholesky factors in a flattened (nkp, nmo_i*nmo_i*nchol) layout. If -i < i (time-reversal pairing), applies the (Q, -Q) trick: remap K’ = qk_k2[i, K] and conjugate-transpose from the stored partner to obtain the Q data.

Parameters:
  • filename (str) – Path to the internal-format HDF5 file.

  • nchol_pk (np.ndarray) – Number of Cholesky vectors per Q; shape (nkp,).

  • minus_k (np.ndarray) – Time-reversal partner map; shape (nkp,).

  • i (int) – Q-vector index to read.

  • qk_k2 (np.ndarray) – Momentum mapping (Q, K) -> K’; shape (nkp, nkp).

  • nmo_pk (np.ndarray) – Orbitals per k-point; shape (nkp,).

Returns:

Lk – Cholesky vectors for Q i, shape (nkp, nmo_i*nmo_i*nchol), complex128.

Return type:

np.ndarray

afqmctools.hamiltonian.converter.get_kpoint_chol_coqui(filename, nchol_pk, minus_k, i, qk_k2, nmo_pk)#

Read CoQuí-format Cholesky vectors for a given Q-vector.

This function loads /Interaction/Vq{Q} for Q = min(i, -i) and returns the per-k-point Cholesky factors in a flattened (nkp, nbnd*nbnd*nchol) layout. For Q with -Q < Q (time-reversal pairing), the data are remapped using qk_k2[i, k] to select K’ and conjugate-transposed to obtain the Q partner.

Parameters:
  • filename (str) – Path to the CoQuí HDF5 Hamiltonian file.

  • nchol_pk (np.ndarray) – Number of Cholesky vectors per Q; shape (nkp,).

  • minus_k (np.ndarray) – Time-reversal partner map; shape (nkp,).

  • i (int) – Q-vector index to read.

  • qk_k2 (np.ndarray) – Momentum mapping (Q, K) -> K’; shape (nkp, nkp).

  • nmo_pk (np.ndarray) – Orbitals per k-point; shape (nkp,).

Returns:

Lk – Cholesky vectors for Q-vector i, shape (nkp, nbnd*nbnd*nchol), dtype complex128.

Return type:

np.ndarray

afqmctools.hamiltonian.converter.h1_spat2spin(h1e_new, h1e_old, Mspatial)#

Convert 1-body Hamiltonian from spatial to spinor basis.

Convert K_{ij} = 1-body Hamiltonian represented in a spatial orbital basis {phi_i(r)}

to a spinor basis { \(\phi_i(r) \times |sigma \rangle\) } for use in a FCIDUMP file. The spinor basis should be ordered with alternating up / down components.

i.e. \({ \phi_0(r) \times |\uparrow>, \phi_0(r) \times |\downarrow \rangle, \phi_1(r) x |\uparrow \rangle, \phi_1(r) x |\downarrow \rangle, ... }\)

Parameters:
  • h1e_new (np.ndarray) – New 1-body Hamiltonian in spinor basis.

  • h1e_old (np.ndarray) – Old 1-body Hamiltonian in spatial basis.

  • Mspatial (int) – Number of spatial orbitals.

Returns:

h1e_new – New 1-body Hamiltonian.

Return type:

np.ndarray

afqmctools.hamiltonian.converter.h2_spat2spin(h2e_new, h2e_old, Mspatial)#

Convert 2-body Hamiltonian from spatial to spinor basis.

Convert \(V_{ijkl} = \int dr dr' \phi_i^*(r)\phi_k(r) \frac{1}{|r - r'|} phi_j^*(r') phi_l(r')\)

in a spatial orbital basis \(\{\phi_i(r)\}\) to a spinor basis \({ \phi_i(r) x |\sigma\rangle }\) for use in a FCIDUMP file. The spinor basis should be ordered with alternating up / down components.

i.e. \({ \phi_0(r) \times |\uparrow>, \phi_0(r) \times |\downarrow \rangle, \phi_1(r) x |\uparrow \rangle, \phi_1(r) x |\downarrow \rangle, ... }\)

For \((ik|jl)\) Chemist’s notation

i.e. \(\langle ij|lk\rangle\) in physicists notation.

Warning

There should be no matrix elements between opposite spins in \((ik|\) or in \(|jl)\) !

Parameters:
  • h2e_new (np.ndarray) – New 2-body Hamiltonian in spinor basis.

  • h2e_old (np.ndarray) – Old 2-body Hamiltonian in spatial basis.

  • Mspatial (int) – Number of spatial orbitals.

afqmctools.hamiltonian.converter.read_cholesky_kpoint(filename, get_chol=True)#

Read SAFIRE internal k-point factorized Hamiltonian (standard format).

Reads datasets from the Hamiltonian group in the internal format and returns the one-body matrices and (optionally) per-Q Cholesky vectors.

The following format is expected:

  • Hamiltonian/dims (array, len=8): overall dimensions. Used entries: - dims[2] = nkp: number of k-points. - dims[3] = nmo_tot: total orbitals across all k-points. - dims[4] = nalpha, dims[5] = nbeta: electron counts.

  • Hamiltonian/NMOPerKP (dataset, shape = [nkp]): orbitals per k-point.

  • Hamiltonian/NCholPerKP (dataset, shape = [nkp]): Cholesky count per Q.

  • Hamiltonian/QKTok2 (dataset, shape = [nkp, nkp]): map (Q, K) -> K’.

  • Hamiltonian/MinusK (dataset, shape = [nkp]): time-reversal partner map.

  • Hamiltonian/H1_kp{i} (dataset per k, complex128 memory): one-body H for k.

  • Hamiltonian/KPFactorized/L{Q} (dataset per Q, complex128 memory): Cholesky factors for Q; remapped/conjugated for -Q via the time-reversal trick.

Parameters:
  • filename (str) – Path to the internal-format HDF5 file.

  • get_chol (bool, optional) – If True, read and return per-Q Cholesky vectors (default True).

Returns:

  • hcore (list[np.ndarray]) – List of one-body Hamiltonians per k-point; each (nmo_k, nmo_k) complex.

  • chol_vecs (list[np.ndarray] or None) – If get_chol is True, list over Q of arrays with shape (nkp, nmo_k*nmo_k*nchol_Q) containing flattened L[K][i,k,n] per K. Otherwise None.

  • enuc (float) – Core (nuclear) energy contribution read from Hamiltonian/Energies.

  • nmo_tot (int) – Total number of orbitals across all k-points.

  • nelec (tuple[int, int]) – (nalpha, nbeta) electron counts.

  • nmo_pk (np.ndarray) – Orbitals per k-point; shape (nkp,).

  • qk_k2 (np.ndarray) – Momentum mapping (Q, K) -> K’; shape (nkp, nkp).

  • nchol_pk (np.ndarray) – Number of Cholesky vectors per Q; shape (nkp,), after time-reversal tie-in.

  • minus_k (np.ndarray) – Time-reversal partner map Q -> -Q; shape (nkp,).

afqmctools.hamiltonian.converter.read_cholesky_kpoint_coqui(filename, get_chol=True)#

Read the CoQuí-format k-point factorized Hamiltonian from an HDF5 file.

This reader follows the layout used by SAFIRE’s CoQuí HDF5 files, using groups /System for one-body terms and metadata and /Interaction for two-body Cholesky factors. Complex data are stored as real-imag pairs on the last axis and are converted via from_complex.

Data sources and meanings: - /System (attributes):

  • number_of_bands (int): number of bands per k-point (nmo per k).

  • number_of_elec (float|int): total electron count; split evenly into (nalpha, nbeta) assuming a closed shell.

  • nuclear_energy (float): nuclear-nuclear repulsion.

  • frozen_core_energy (float, optional): frozen-core energy; added to enuc.

  • madelung_constant (float, optional): electron self-interaction factor; subtracted as madelung_constant * (nalpha + nbeta).

  • /System/BZ (group): - number_of_kpoints (attr, int): number of k-points nkp. - qk_to_k2 (dataset, shape = [nkp, nkp]): map (Q, K) -> K’. - qminus (dataset, shape = [nkp]): map Q -> -Q for time-reversal symmetry. - kp_to_ibz (dataset, shape = [nkp], optional): map full BZ k to IBZ index. - kp_trev_pair (dataset, shape = [nkp], optional): time-reversal flags (>0 means conj).

  • /System/H0 (dataset, shape = [nspins, nkpts_or_ibz, nbnd, nbnd, 2]): one-body Hamiltonian per spin and k-point (complex in last dim). If stored over IBZ, it is unfolded using kp_to_ibz and kp_trev_pair.

  • /Interaction/Vq{Q} (dataset per Q, shape = [nchol, 1, nkp, nbnd, nbnd, 2]): Cholesky factors of the two-body term. Normalized by 1/sqrt(nkp).

Parameters:
  • filename (str) – Path to the CoQuí HDF5 Hamiltonian file.

  • get_chol (bool, optional) – If True, read and return the Cholesky vectors (default True).

Returns:

  • hcore (list[np.ndarray]) – List of one-body Hamiltonians for each k-point. Each element has shape (nbnd, nbnd) and dtype complex128 (first spin component used).

  • chol_vecs (list[np.ndarray] or None) – If get_chol is True, a list over Q of arrays of shape (nkp, nbnd*nbnd*nchol) with dtype complex128, storing flattened L[K][i,k,n] per k-point. Otherwise None.

  • enuc (float) – Effective nuclear energy (nuclear + frozen-core, minus Madelung term).

  • nmo_tot (int) – Total number of orbitals over all k-points, nbnd * nkp.

  • nelec (tuple[int, int]) – (nalpha, nbeta) electron counts, closed-shell split if only total given.

  • nmo_pk (np.ndarray) – Orbitals per k-point; shape (nkp,), all entries equal to nbnd.

  • qk_k2 (np.ndarray) – Momentum mapping (Q, K) -> K’; shape (nkp, nkp).

  • nchol_pk (np.ndarray) – Number of Cholesky vectors per Q; shape (nkp,), with time-reversal applied.

  • minus_k (np.ndarray) – Time-reversal partner map Q -> -Q; shape (nkp,).

afqmctools.hamiltonian.converter.read_common_input(filename, get_hcore=True)#

Read common input from internal format (*.h5).

Parameters:
  • filename (string) – File containing integrals in internal format (*.h5).

  • get_hcore (bool) – If True, read one-body Hamiltonian. Optional. Default: True.

Returns:

  • enuc (float) – Nuclear repulsion energy.

  • dims (np.ndarray) – Dimensions of the Hamiltonian.

  • hcore (np.ndarray) – One-body part of the Hamiltonian.

  • real_ints (bool) – True if integrals are real, False if complex

afqmctools.hamiltonian.converter.read_dense(filename, walker_type=None)#

Read in integrals from internal hdf5 format.

Parameters:
  • filename (string) – File containing integrals (*.h5)

  • walker_type (int) –

    integer describing the walker type:
    1. : ‘CLOSED’ - i.e. closed-shell and RHF-like

    2. : ‘COLLINEAR’ - i.e. open-shell and/or UHF-like

    3. : ‘NONCOLLINEAR’ - i.e. GHF-like

Returns:

  • hcore (np.ndarray) – One-body part of the Hamiltonian.

  • chol_vecs (np.ndarray) – Two-electron integrals. Shape: [nmo*nmo, nchol]

  • ecore (float) – Core contribution to the total energy.

:raises RuntimeError : if Cholesky vectors are not present in: the file called ‘filename’

afqmctools.hamiltonian.converter.read_fcidump(filename, symmetry=None, verbose=True)#

Read in integrals from file.

For FCIDUMP files with complex-valued integrals, read_fcidump assumes that the real and imaginary parts are listed as (real,imag) as opposed to real imag

Parameters:
  • filename (string) – File containing integrals in FCIDUMP format.

  • symmetry (int, optional) – Permutational symmetry of two electron integrals. If not specified, the symmetry is read from the header of the FCIDUMP file.

  • verbose (bool) – Controls printing verbosity. Optional. Default: False.

Returns:

  • h1e (np.ndarray) – One-body part of the Hamiltonian.

  • h2e (np.ndarray) – Two-electron integrals.

  • ecore (float) – Core contribution to the total energy.

  • nelec (tuple) – Number of electrons.

afqmctools.hamiltonian.converter.read_fcidump_header(filename, mline=24)#

Read the header of a FCIDUMP file.

Parameters:
  • filename (str) – File containing integrals in FCIDUMP format.

  • mline (int) – Maximum number of lines to read in header.

Returns:

meta – Dictionary containing the metadata from the header.

Return type:

dict

afqmctools.hamiltonian.converter.read_hamil_type(filename)#

Read Hamiltonian type from internal format (HDF5, *.h5).

Parameters:

filename (str) – Hamiltonian file (HDF5, *.h5)

Returns:

ham_type – Type of Hamiltonian.

Return type:

str

afqmctools.hamiltonian.converter.read_hamiltonian(filename, get_chol=True, walker_type=1)#

Read Hamiltonian from internal format (*.h5).

Parameters:

filename (string) – Hamiltonian file (*.h5)

Returns:

hamil – Data read from file.

Return type:

dict

afqmctools.hamiltonian.converter.read_model(filename)#

Read model Hamiltonian from hdf5 file fname

afqmctools.hamiltonian.converter.write_fcidump(filename, hcore, chol, enuc, nmo, nelec, tol=1e-08, ctol=1e-12, sym=1, cplx=True, paren=False, chol_is_eri=False, use_spinor=False)#

Write FCIDUMP based from Cholesky factorised integrals.

Parameters:
  • filename (string) – Filename to write FCIDUMP to.

  • hcore (np.ndarray) – One-body hamiltonian.

  • chol (np.ndarray) – Cholesky matrix L[ik,n] or chemist’s ERI (ik|jl) if chol_is_eri

  • enuc (float) – Nuclear repulsion energy.

  • nmo (int) – Total number of MOs.

  • nelec (tuple) – Number of alpha and beta electrons.

  • tol (float) – Only print eris above tol. Optional. Default 1e-8.

  • sym (int) – Controls whether to only print symmetry inequivalent ERIS. Optional. Default 1, i.e. print everything.

  • cplx (bool) – Write in complex format. Optional. Default : True.

  • paren (bool) – Write complex numbers in parenthesis.

  • chol_is_eri (bool) – Write chemist’s ERI directly instead of using its Cholesky factorization

  • use_spinor (bool) – Convert to a spinor basis before writing FCIDUMP

afqmctools.hamiltonian.converter.write_fcidump_kpoint(filename, hcore, chol, enuc, nmo_tot, nelec, nmo_pk, nchol_pk, qk_k2, tol=1e-08, sym=1, paren=False, cplx=True, ctol=1e-12, use_spinor=False)#

Write FCIDUMP based from Cholesky factorised integrals.

Parameters:
  • filename (string) – Filename to write FCIDUMP to.

  • hcore (list) – One-body hamiltonian.

  • chol (list) – Cholesky matrices L[Q][k_i][i,k]

  • enuc (float) – Nuclear repulsion energy.

  • nmo_tot (int) – Total number of MOs.

  • nelec (tuple) – Number of alpha and beta electrons.

  • nmo_pk (np.ndarray) – Number of MOs per kpoint.

  • nchol_pk (np.ndarray) – Number of Cholesky vectors per kpoint.

  • qk_k2 (np.ndarray) – Array mapping (q,k) pair to kpoint: Q = k_i - k_k + G. qk_k2[iQ,ik_i] = i_kk.

  • tol (float) – Only print eris above tol. Optional. Default 1e-8.

  • sym (int) – Controls whether to only print symmetry inequivalent ERIS. Optional. Default 1, i.e. print everything.

  • paren (bool) – Write complex numbers in parenthesis.

  • use_spinor (bool) – Convert to a spinor basis before writing FCIDUMP

afqmctools.hamiltonian.io module#

afqmctools.hamiltonian.io.to_sparse(vals, cutoff=1e-08)#
afqmctools.hamiltonian.io.write_dense(hcore, chol, nelec, nmo, enuc=0.0, filename='hamiltonian.h5', real_chol=None, ortho=None, verbose=None)#
afqmctools.hamiltonian.io.write_to_hdf5(f, dataset, data, dtype=None)#

afqmctools.hamiltonian.kpoint module#

afqmctools.hamiltonian.mol module#

Generate AFQMC data from PYSCF (molecular) simulation.

afqmctools.hamiltonian.mol.chunked_cholesky(mol, max_error=1e-06, verbose=False, cmax=10)#

Modified cholesky decomposition from pyscf eris.

See, e.g. [MZ18]

Only works for molecular systems.

Parameters:
  • mol (pyscf.mol) – pyscf mol object.

  • max_error (float) – Accuracy desired.

  • verbose (bool) – If true print out convergence progress.

  • cmax (int) – nchol = cmax * M, where M is the number of basis functions. Controls buffer size for cholesky vectors.

Returns:

chol_vecs – Matrix of cholesky vectors in AO basis.

Return type:

np.ndarray

afqmctools.hamiltonian.mol.core_contribution_cholesky(chol_vecs, G)#
afqmctools.hamiltonian.mol.freeze_core(h1e, chol, ecore, nc, ncas, verbose=True)#
afqmctools.hamiltonian.mol.gab(A, B)#

One-particle Green’s function.

This actually returns 1-G since it’s more useful, i.e.,

\[\langle \phi_A|c_i^{\dagger}c_j|\phi_B\rangle = [B(A^{\dagger}B)^{-1}A^{\dagger}]_{ji}\]

where \(A,B\) are the matrices representing the Slater determinants \(|\psi_{A,B}\rangle\).

For example, usually A would represent (an element of) the trial wavefunction.

Warning

Assumes A and B are not orthogonal.

Parameters:
  • A (np.ndarray) – Matrix representation of the bra used to construct G.

  • B (np.ndarray) – Matrix representation of the ket used to construct G.

Returns:

GAB – (One minus) the green’s function.

Return type:

np.ndarray

afqmctools.hamiltonian.mol.generate_hamiltonian(scf_data, chol_cut=1e-05, verbose=False, cas=None, ortho_ao=False, nelec=None, df=False, walker_type=None)#
afqmctools.hamiltonian.mol.local_energy_generic_cholesky(h1e, chol_vecs, G, ecore)#

Calculate local for generic two-body hamiltonian.

This uses the cholesky decomposed two-electron integrals.

Parameters:
  • system (hubbard) – System information for the hubbard model.

  • G (np.ndarray) – Walker’s “green’s function”

Returns:

(E, T, V) – Local, kinetic and potential energies.

Return type:

tuple

afqmctools.hamiltonian.mol.process_generic_hamiltonian(H_one_body, cholesky_vectors=None, coulomb_repulsion_tensor=None, E0=0.0, cholesky_delta=1e-06, spin_orbital_integrals=None, verbose=True)#

Process generic hamiltonian.

Parameters:
  • H_one_body (array) – One-body Hamiltonian.

  • cholesky_vectors (array) – Cholesky vectors with shape (number of Cholesky vectors,number_of_orbitals**2). Must provide either this or coulomb_repulsion_tensor.

  • coulomb_repulsion_tensor (array) – Coulomb repulsion tensor using Chemist’s conventions, (ij|kl). Must provide exactly one of this or cholesky_vectors.

  • E0 (float) – Nuclear repulsion energy.

  • cholesky_delta (float) – Tolerance for Cholesky decomposition. Default is 1e-6.

  • spin_orbital_integrals (array) – Spin orbital integrals. If provided, will be added to the Hamiltonian. See notes for conventions.

  • verbose (bool) – If true print out verbose details.

Returns:

  • Kij (np.ndarray) – One-body Hamiltonian.

  • L_ij_gamma (np.ndarray) – Cholesky vectors.

  • E0 (float) – Constant energy contribution.

Notes

  • The interaction must be provided as either the Coulomb repulsion tensor or the Cholesky vectors.

afqmctools.hamiltonian.mol.transform_cholesky(chol, C)#

Apply the basis rotation C to the cholesky vectors chol

afqmctools.hamiltonian.mol.write_hamil_mol(scf_data, hamil_file, chol_cut, verbose=True, cas=None, ortho_ao=False, nelec=None, real_chol=True, df=False)#

Write hamiltonian from pyscf scf calculation on mol object.

afqmctools.hamiltonian.mol.write_hamiltonian_generic(*arg, filename='afqmc.h', **kwargs)#

Write generic hamiltonian to HDF5 file

Parameters:
  • filename (str) – Name of HDF5 Filename to write to. Default is ‘afqmc.h’.

  • H_one_body (np.ndarray) – One-body Hamiltonian.

  • cholesky_vectors (np.ndarray, optional) – Cholesky vectors with shape (number of Cholesky vectors,number_of_orbitals**2). Must provide either this or coulomb_repulsion_tensor.

  • coulomb_repulsion_tensor (np.ndarray) – Coulomb repulsion tensor using Chemist’s conventions, (ij|kl). Must provide exactly one of this or cholesky_vectors.

  • E0 (float) – Nuclear repulsion energy.

  • spin_orbital_integrals (np.ndarray, not implemented) – Spin orbital integrals. If provided, will be added to the Hamiltonian. See notes for conventions.

  • verbose (bool) – If true print out verbose details.

Returns:

  • Kij (np.ndarray) – One-body Hamiltonian.

  • L_ij_gamma (np.ndarray) – Cholesky vectors.

  • E0 (float) – Constant energy contribution.

Notes

  • The interaction must be provided as either the Coulomb repulsion tensor or the Cholesky vectors.

afqmctools.hamiltonian.supercell module#

Module contents#