Hamiltonian API#

class HamiltonianAPI#

Hamiltonian abstract base class.

generate_connectivity_matrix()#

Generate connectivity matrix.

Returns:

(dictionary, np.ndarray)

Return type:

tuple

abstract generate_one_body_integral(dense: bool, basis: str)#

Generate one body integral in spatial or spin orbital basis.

Parameters:
  • basis (str) – [‘spatial’, ‘spin orbital’]

  • dense (bool) – dense or sparse matrix; default False

Return type:

scipy.sparse.csr_matrix or np.ndarray

abstract generate_two_body_integral(sym: int, basis: str, dense: bool)#

Generate two body integral in spatial or spinorbital basis.

Parameters:
  • sym (int) – symmetry – [2, 4, 8] default is 1

  • basis (str) – [‘spatial’, ‘spin orbital’]

  • dense (bool) – dense or sparse matrix; default False

Return type:

scipy.sparse.csr_matrix or np.ndarray

abstract generate_zero_body_integral()#

Generate zero body integral.

save_fcidump(f: TextIO | str, nelec=0, spinpol=0)#

Save all parts of hamiltonian in fcidump format.

Parameters:
  • f (TextIO file, str) – File object or file name to save the integrals

  • nelec (int) – The number of electrons in the system

  • spinpol (float) – The spin polarization. By default, its value is derived from the molecular orbitals (mo attribute), as abs(nalpha - nbeta). In this case, spinpol cannot be set. When no molecular orbitals are present, this attribute can be set.

Return type:

None

save_triqs(fname: str, integral)#

Save matrix in triqc format.

Parameters:
  • fname (str) – name of the file

  • integral (int) – type of integral, one of 1 (one-body) or 2 (two-body)

Return type:

None

savez(f: TextIO | str)#

Save file as regular npz file.

Parameters:

f (TextIO, str) – File object or file name to save the integrals

Return type:

None

Notes

To provide a TextIO object, use the following code: ` open("file.npz", "wb") as f: `

to_dense(Ms, dim=2)#

Convert to dense matrix.

Convert sparse array of integrals in scipy csr format to dense numpy array.

Parameters:
  • Ms (scipy.sparse.csr_matrix)

  • dim (int) – target dimension of output array (either 2 or 4)

Return type:

np.ndarray

to_sparse(Md)#

Convert dense array of integrals to sparse array in scipy csr format.

Parameters:

Md (np.ndarray) – input matrix of the shape 2d or 4d

Return type:

scipy.sparse.csr_matrix

to_spatial(sym: int, dense: bool, nbody: int)#

Convert one-/two- integral matrix from spin-orbital to spatial basis.

Parameters:
  • sym (int) – symmetry – [2, 4, 8] default is 1

  • dense (bool) – dense or sparse matrix; default False

  • nbody (int) – type of integral, one of 1 (one-body) or 2 (two-body)

Returns:

spatial_int – one-/two-body integrals in spatial basis

Return type:

scipy.sparce.csr_matrix or np.ndarray

Notes

Given the one- or two-body Hamiltonian matrix terms, \(h_{i,j}\) and \(g_{ij,kl}\) respectively, we populate the spatial integrals by calcualting __average__ over the spin-orbitals

Specifically, for the one-body integrals, we have: \(h_{pq} = 0.25*(h_{pq}^{aa} + h_{pq}^{bb} + h_{pq}^{ab} + h_{pq}^{ba}) = h_{pq}^{aa} = h_{pq}^{bb}\) Therefore, the one-body integrals in the spatial basis are the same as the aa part of one-body integrals in the spin-orbital basis.

For the two-body integrals, we have: \(v_{pqrs} = 0.25*(v_{pqrs}^{aaaa} + v_{pqrs}^{bbbb} + v_{pqrs}^{abab} + v_{pqrs}^{baba})\) Assuming that \(v_{pqrs}^{abab} = v_{pqrs}^{baba}\) and \(v_{pqrs}^{aaaa} = v_{pqrs}^{bbbb}\) \(v_{pqrs} = 0.5*(v_{pqrs}^{aaaa} + v_{pqrs}^{abab})\)

to_spinorbital(integral: ndarray, sym=1, dense=False)#

Convert one-/two- integral matrix from spatial to spin-orbital basis.

Parameters:
  • integral (scipy.sparse.csr_matrix) – type of integral, one of 1 (one-body) or 2 (two-body)

  • sym (int) – symmetry – [2, 4, 8] default is 1

  • dense (bool) – dense or sparse matrix; default False

Return type:

None