afqmctools.utils package#
Submodules#
afqmctools.utils.aimbes_utils module#
Utilities for Interfacing with AIMBES
- class afqmctools.utils.aimbes_utils.AIMBESHamiltonian(*values)#
Bases:
EnumEnumerated type corresponding to the Hamiltonian types from AIMBES.
- BARE = 1#
- CRPA = 3#
- FROZEN_CORE = 2#
- class afqmctools.utils.aimbes_utils.TRIQS_HDF5_File(name, kpts, proj_mat, band_window, wan_centres)#
Bases:
objectDataclass to contain orbitals and relevant data from the TRIQS internal format.
- band_window: ndarray#
An array containing the range of KS bands used as inputs to the ‘proj_mat’.
- kpts: ndarray#
Array containing all k-points in fractional coordinates.
- name: str#
The name of the file that Wannier orbitals were read from.
- proj_mat: ndarray#
Has shape (Nspin x Nkpt x Ndefect x Norb x Nband). Defines the projection from the Kohn-Sham (KS) band basis into the basis defined in the file called “name”.
- wan_centres: ndarray#
(if applicable) contains the spatial centers of Wannier orbitals. These are used within AIMBES to translate Wannier orbitals into the home cell. Do not set these if you aren’t using Wannier orbitals!
- afqmctools.utils.aimbes_utils.aimb_1body_2_afqmc(fname, type='gw', gw_iteration=1, include_dc=True, input_band_range=None, force_real=False, nactive=None, ncore=0)#
Generate the 1-body Hamiltonian from am AIMBES checkpoint file.
There are a few variants of the 1-body Hamiltonian to treat. All variants include the terms: Heff_base_sIab = H0_sIab - mu * I.
The variants are: 1. for DFT-based downfolding, we have Heff_sIab = Heff_base_sIab + (Vhf_gw_sIab - Vhf_dc_sIab) 2. for GW-based downfolding, we have Heff_sIab = Heff_base_sIab + (Vhf_gw_sIab - Vhf_dc_sIab) + (Vcorr_gw_sIab - Vcorr_dc_sIab)
- afqmctools.utils.aimbes_utils.aimb_2body_2_afqmc(fname, use_crpa=True, freq=0, tol=1e-06, use_chol=True, symmetrize=True, verbose=False, force_real=False)#
- afqmctools.utils.aimbes_utils.check_aimbes_energy(aimbes_file, H1, V_abcd, scf_iter=1, mode='mixed')#
Calculates and prints the “Hartree-Fock” energy based on the density in the given AIMBES checkpoint file, ‘aimbes_file’, and provided Hamiltonian.
Can evaluate the energy in two modes:
(default) : ‘mixed_mode’ mimics the output of AIMBES. The energy at iteration n is defined as:
E^{mixed HF}_{n} = Tr[ D_{n} H1 ] + Tr[ F[ D_{n-1} ] D_{n} ]
‘variational’ : uses the same density for building the Fock matrix and for evaluating the energy
E^{mixed HF}_{n} = Tr[ D_{n} H1 ] + Tr[ F[ D_{n} ] D_{n} ]
Convenience function to calculation the energy that AIMBES will output. AIMBES computes the “Hartree-Fock” energy at iteration m+1 by: - computing the Fock matrix (F) with the Dm at iteration m - diagonalize F -> generate new density matrix - evaluate the energy with the same F[D_{m}] but using the new D_{m+1}
- TODO: for cRPA and frozen core, we need to be able to map the density matrix
into the local Hilbert space.
- afqmctools.utils.aimbes_utils.get_aimbes_2body(fname, get_screened=True, freq=0, symmetrize=False, reshape=False, force_real=False, nactive=None, ncore=0, sc_iter=1)#
Get 2-body interaction term from the AIMBES HDF5 output.
- afqmctools.utils.aimbes_utils.get_aimbes_hamil_enum(hamil_type)#
Maps general inputs into the AIMBESHamiltonian enumerated type
- Parameters:
hamil_type (
str|AIMBESHamiltonian) – A description of the Hamiltonian type. If an AIMBESHamiltonian enum is provided, it is immediately returned. If a string is provided, a corresponding AIMBESHamitlonian enum is returned. See the table above for the mapping from strings to AIMBESHamiltonian- Returns:
a AIMBESHamiltonian enum corresponding to the input hamil_type parameter
- Return type:
Notes
Input strings are not case sensitive and acceptable input strings include:
AIMBESHamiltonian
strings
BARE
“bare”, “hamil”, “hamiltonian”, “hamil_bare”, “hamil bare”
FROZEN_CORE
“frozen_core”, “frozen core”, “mf_downfold”, “mf downfold”
CRPA
“downfolded”, “crpa”, “crpa downfolded”
- afqmctools.utils.aimbes_utils.read_aimbes_Hamiltonian(fname, hamil_type=None, omega=0, chol_tol=1e-06, sc_iter=1)#
Read aimbes Hamiltonian from an aimbes HDF5 file.
The most general Hamiltonian that can be read is:
\[\hat{H} = \hat{H}_0 + (\hat{V}_{HF} - \hat{V}_{HF-DC}) + + (\hat{V}_{Corr} - \hat{V}_{Corr-DC}) + \hat{V}_{bare} + \hat{U}(omega)\]where,
\(\hat{H}_0\) is the non-interacting Hamiltonian
\(\hat{V}_{HF}\) is the Hartree-Fock potential (i.e. 2*J - K ) evaluated over the full hilbert space
\(\hat{V}_{HF-DC}\) is the double counting correction for \(\hat{V}_{HF}\) (2*J -K evaluated in the active space. For calculations in the full Hilbert space, this is identical to \(\hat{V}_{HF}\))
The “types” of Hamiltonian that can be read are:
the bare Hamiltonian - consists of \(\hat{H}_0 + \hat{V}_{bare}\)
- Parameters:
fname (
str) – The name of an aimbes HDF5 file to readhamil_type (str, optional) – The type of Hamiltonian to read from the HDF5 file. If not specified, the hamil_type will be inferred based on the contents of the ‘fname’.
omega (int, optional) – The index of the frequency to use for the partially screened Coulomb interaction
chol_tol (float, optional) – Cholesky tolerance
sc_iter (int, optional) – Self-consistent iteration number
- afqmctools.utils.aimbes_utils.read_aimbes_dm(fname, scf_iter=0)#
Read the density matrix from an AIMBES output file.
By default, reads the initial density matrix - i.e. scf_iter=0
- afqmctools.utils.aimbes_utils.read_bare_hamiltonian(fname)#
Read Hamiltonian from the output of AIMBES’s ‘hamil’ directive.
- afqmctools.utils.aimbes_utils.read_coqui_orbitals(forbs)#
Extract orbitals and metadata from COQUÍ HDF5 file.
- Parameters:
forbs (str) – orbital HDF file from Coqui
- Returns:
meta (dict) – metadata
orbs (numpy.ndarray) – orbitals
- afqmctools.utils.aimbes_utils.read_crpa_hamiltonian(fname, chol_tol=1e-06, freq=0, sc_iter=0)#
- afqmctools.utils.aimbes_utils.read_frozen_core_hamiltonian(fname, chol_tol=1e-06)#
Read Hamiltonian from the output of AIMBES’s ‘hamil’ directive.
- afqmctools.utils.aimbes_utils.read_triqs_hdf5(fname)#
Read a TRIQS_HDF5_File from fname.
- Return type:
- afqmctools.utils.aimbes_utils.write_downfolding_orbitals(fname, kpts, C_ksIai, band_window, wan_centres=None)#
Save orbitals in Wannier90’s h5 format to be read into AIMBES
afqmctools.utils.chemistry module#
Chemistry Reference Utilities.
Routine Listings#
atomic_num_to_symbol : Convert atomic number to atomic symbol. atomic_symbol_to_num : Convert atomic symbol to atomic number.
- afqmctools.utils.chemistry.atomic_num_to_symbol(atomic_num)#
Convert atomic number to atomic symbol.
- Parameters:
atomic_num (
int) – Atomic number.- Returns:
Atomic symbol.
- Return type:
str
- afqmctools.utils.chemistry.atomic_symbol_to_num(atomic_symbol)#
Convert atomic symbol to atomic number.
- Parameters:
atomic_symbol (
str) – Atomic symbol.- Returns:
Atomic number.
- Return type:
int
afqmctools.utils.gto_basis_utils module#
- afqmctools.utils.gto_basis_utils.default_basis_map(Lmax, atoms)#
- afqmctools.utils.gto_basis_utils.double_basis_map(Lmax, atoms)#
- afqmctools.utils.gto_basis_utils.extend_gto(fname, sym='X', expo=None)#
- afqmctools.utils.gto_basis_utils.extend_gto_id(fname, sym, expo, ids)#
afqmctools.utils.io module#
- afqmctools.utils.io.add_dataset(fh5, name, value)#
Adds value to dataset, and creates dataset if it does not exist.
- Parameters:
fh5 (
File) – File object to write to.name (str) – Name of dataset.
value (np.array) – Value to write to dataset.
- afqmctools.utils.io.add_group(fh5, name)#
- Add a group called “name” to h5py.File instance “fh5”,
deleting fh5[name] if it already exists
- Parameters:
fh5 (
File) – File object to write to.name (str) – Name of group.
- Returns:
Group object.
- Return type:
h5py.Group
- afqmctools.utils.io.dump_dict(d, offset=0, dict_title=None)#
- afqmctools.utils.io.format_fixed_width_floats(floats)#
Format a list of floats to be fixed width.
- afqmctools.utils.io.format_fixed_width_strings(strings)#
Format a list of strings to be fixed width.
- afqmctools.utils.io.from_complex(data, shape=None)#
Convert from internal complex format to numpy.complex128
- afqmctools.utils.io.get_hamiltonian_spin_symm(fname)#
Get the spin symmetry of the Hamiltonian from a Hamiltonian HDF5 file.
- Parameters:
fname (str) – File name of HDF5 file containing the Hamiltonian.
- Returns:
the spin symmetry of the Hamiltonian.
- Return type:
- afqmctools.utils.io.h5_as_dict(fname)#
Load an HDF5 file as a dictionary.
- Parameters:
fname (str) – File name of HDF5 file to load.
- Returns:
Dictionary containing the contents of the HDF5 file.
- Return type:
dict
- afqmctools.utils.io.read_input_params(infile=None)#
Read parameters from a human-readable TOML input file and return them in a dictionary.
- Return type:
dict
- afqmctools.utils.io.read_nmo(fname)#
- afqmctools.utils.io.read_one_body(fname, format='csr')#
Read one-body Hamiltonian from file.
- Parameters:
fname (str) – File name to read from.
format (
str) – Format of the file. Default is ‘csr’.
- afqmctools.utils.io.to_complex(array)#
Convert from numpy.complex128 to internal complex format
- afqmctools.utils.io.write_csr(f, csr_array, prefix)#
Write CSR matrix to HDF5.
- Parameters:
f (h5py.File or h5py.Group) – HDF5 object to write to.
csr_array (
csr_array) – CSR matrix to write.prefix (str) – Prefix to write to.
- afqmctools.utils.io.write_model_hamiltonian(hamiltonian, fname, prefix='Hamiltonian/ModelHamiltonian', nelec=None, spin_symm=None)#
Writes a lattice model Hamiltonian to an HDF5 file.
- Parameters:
hamiltonian (
Hamiltonian) – Hamiltonian object to write.fname (str) – File name of HDF5 file to write to.
prefix (str, optional) – Prefix to write to.
nelec (tuple) – Number of electrons in the system.
spin_symm (SpinSymm, optional) – Spin symmetry of the Walkers to use in AFQMC. If not provided, the spin symmetry is read from the Hamiltonian object.
TODO (consider removing the prefix argument since it should always be the same.)
- afqmctools.utils.io.write_model_params(fname, params=None)#
Write Model Hamiltonian parameters to a human-readable TOML file.
- The files produced by this function can be used as an input files via the
read_input_params(fname) function.
- Parameters:
fname (str) – File name to write to.
params (dict) – Dictionary of model parameters to write. This dictionary has the same conventions as the model Hamiltonian builder. See the User Guide for more information.
- afqmctools.utils.io.write_pair_correlators(fname=None, pairs_dict=None)#
Write pair correlators to an HDF5 file.
Warning
This is an experimental feature and is not officially supported. Use at your own risk.
- Parameters:
fname (
str) – File name of HDF5 file to write to.pairs_dict (dict) – Dictionary of pair correlators to write.
afqmctools.utils.linalg module#
- afqmctools.utils.linalg.get_ortho_ao(cell, kpts, LINDEP_CUTOFF=0)#
Generate canonical orthogonalization transformation matrix.
- Parameters:
cell (
pyscf.pbc.cellobject) – PBC cell object.kpts (
numpy.array) – List of kpoints.LINDEP_CUTOFF (float) – Linear dependency cutoff. Basis functions whose eigenvalues lie below this value are removed from the basis set. Should be set in accordance with value in
pyscf.scf.addons.remove_linear_dep().
- Returns:
X (
numpy.array) – Transformation matrix.nmo_per_kpt (
numpy.array) – Number of OAOs orbitals per kpoint.
- afqmctools.utils.linalg.get_ortho_ao_mol(S, LINDEP_CUTOFF=0)#
Generate canonical orthogonalization transformation matrix.
- Parameters:
S (
numpy.ndarray) – Overlap matrix.LINDEP_CUTOFF (float) – Linear dependency cutoff. Basis functions whose eigenvalues lie below this value are removed from the basis set. Should be set in accordance with value in
pyscf.scf.addons.remove_linear_dep().
- Returns:
X – Transformation matrix.
- Return type:
numpy.array
- afqmctools.utils.linalg.modified_cholesky_direct(M, tol=1e-05, verbose=False, cmax=20)#
Modified cholesky decomposition of matrix.
See, e.g. [MZ18]
- Parameters:
M (
numpy.ndarray) – Positive semi-definite, symmetric matrix.tol (float) – Accuracy desired. Optional. Default : 1e-5.
verbose (bool) – If true print out convergence progress. Optional. Default : False.
cmax (int) – Number of cholesky vectors to store N_gamma = cmax M.
- Returns:
chol_vecs – Matrix of cholesky vectors.
- Return type:
numpy.ndarray
afqmctools.utils.matrix module#
- afqmctools.utils.matrix.force_herm(M, method='upper_triangular')#
Force a matrix to be Hermitian.
- Parameters:
M (array_like or sparse matrix) – Input matrix to be forced to Hermitian.
method (str, optional) – Method to use for forcing Hermitian. Default is ‘upper_triangular’. See notes.
- Returns:
M_herm – Hermitian matrix.
- Return type:
array_like or sparse matrix
Notes
The following methods are available:
- ‘upper_triangular’ or ‘triu’:
Set the lower triangular part of the matrix to zero and add the conjugate transpose of the upper triangular part. This effectively ignores the lower triangular part of the matrix.
- afqmctools.utils.matrix.is_hermitian(M, tol=1e-10)#
Check if a matrix (NumPy array or SciPy sparse array) is Hermitian.
- Parameters:
sps.spmatrix) (M (np.ndarray or)
(float) (tol)
- Returns:
bool
- Return type:
True if the matrix is Hermitian, False otherwise.
afqmctools.utils.misc module#
- class afqmctools.utils.misc.dotdict#
Bases:
dictdot.notation access to dictionary attributes
- afqmctools.utils.misc.get_git_hash()#
Return git revision.
- Adapted from:
http://stackoverflow.com/questions/14989858/get-the-current-git-hash-in-a-python-script
- Returns:
sha1 – git hash with -dirty appended if uncommitted changes.
- Return type:
string
afqmctools.utils.optimizable_basis_set module#
- class afqmctools.utils.optimizable_basis_set.BasisBlock(sym, L, n_gauss=1, n_fun=1, exponents=None)#
Bases:
objectObjects of this class hold a list of exponents and contraction coefficients defining a block of a set angular momentum in the basis set.
- basis_str(x)#
Returns the string associated with this basis block.
- Parameters:
x (array) –
Parameters of the basis set in linearized array. The expected order is:
[ exp1, c11, c12, ..., exp2, c21, c22, ..., exp3, c31, ...]
where expn is the exponent of the nth basis function and cni is the nth contraction coefficient of the ith basis.
- Returns:
Basis block.
- Return type:
string
- class afqmctools.utils.optimizable_basis_set.EvenTemperedBasisBlock(sym, L, alpha=0.1, n_gauss=5, n_fun=1, beta=None)#
Bases:
objectObjects of this class hold a list of exponents and contraction coefficients defining a block of a set angular momentum in the basis set. Exponents are generated from even tempered set:
expo[i] = alpha * beta ** (i - 1.0)
For now, only beta and contraction coefficients are mutable.
- basis_str(x)#
Returns the string associated with this basis block.
- Parameters:
x (array) –
Parameters of the basis set in linearized array. The expected order is:
[ exp1, c11, c12, ..., exp2, c21, c22, ..., exp3, c31, ...]
where expn is the exponent of the nth basis function and cni is the nth contraction coefficient of the ith basis.
- Returns:
Basis block.
- Return type:
string
- class afqmctools.utils.optimizable_basis_set.OptimizableBasisSet(atom_id, def_basis={})#
Bases:
object- add(bblk)#
Extends the basis set of a species by adding a new (possibly optimizable)block.
- Parameters:
bblk (Object of type BasisBlock or EvenTemperedBasisBlock.) – A basis set block.
- basis_str(atm, x)#
Returns a string with the basis set of a given species.
- Parameters:
atm (string) – String with the label of a species.
x (1-D floating point array.) – Array with variational parameters in the basis. Dimension must be equal to self.number_of_params.
- Returns:
- extra_basis: String
A string with the basis set of species atm.
- extended_basis(atm, x)#
- Returns a string that corresponds to the extended part of the basis set for
- species atm. The extended part of the basis corresponds to the blocks
included with self.add(…)
- Parameters:
atm (string) – String with the label of a species.
x (1-D floating point array.) – Array with variational parameters in the basis. Dimension must be equal to self.number_of_params.
- Returns:
extra_basis – A string with the extended basis of species atm.
- Return type:
String
- print_all_to_file(fnames, x)#
Prints all the requested basis sets to separate file.
- Parameters:
fnames (Python Dictionary) – Dictionary with file names. Only those species contained in the object and defined in the dictionary will be printed.
x (1-D floating point array.) – Array with variational parameters in the basis. Dimension must be equal to self.number_of_params.
- print_all_to_stdout(x)#
Prints all the basis sets contained by the object to stdout.
- Parameters:
x (1-D floating point array.) – Array with variational parameters in the basis. Dimension must be equal to self.number_of_params.
- print_to_file(fname, atm, x)#
Prints the basis set of a species to a file.
- Parameters:
fname (string) – Name of file.
atm (string) – String with the label of a species.
x (1-D floating point array.) – Array with variational parameters in the basis. Dimension must be equal to self.number_of_params.
- print_to_stdout(atm, x)#
Prints the basis set of a species to a stdout.
- Parameters:
atm (string) – String with the label of a species.
x (1-D floating point array.) – Array with variational parameters in the basis. Dimension must be equal to self.number_of_params.
- afqmctools.utils.optimizable_basis_set.default_basis_set(Lmax, atoms)#
- Generates a OptimizableBasisSet object with default parameters.
A single uncontracted gaussian per angular momentum will be used.
- Parameters:
Lmax (integer. Requirement: 2 <= L <= 6) – Maximum angular momentum. For each l=2,3,…,Lmax, shells will be added with angular momentum: 0,1,…,l.
atoms (array of strrings) – For each symbol in the array, a new basis set is created.
- Returns:
OptimizableBasisSet.
afqmctools.utils.parallel module#
- afqmctools.utils.parallel.bisect(a, x, lo=0, hi=None)#
Return the index where to insert item x in list a, assuming a is sorted.
The return value i is such that all e in a[:i] have e <= x, and all e in a[i:] have e > x. So if x already appears in the list, a.insert(x) will insert just after the rightmost x already there.
Optional args lo (default 0) and hi (default len(a)) bound the slice of a to be searched.
afqmctools.utils.pyscf_utils module#
afqmctools.utils.qe_tools module#
afqmctools.utils.qe_utils module#
Utilities for interacting with Quantum Espresso
Functionality: 1. Read orbitals and DFT density from PWSCF in HDF5 format
- afqmctools.utils.qe_utils.cubic_pos(spaces)#
- afqmctools.utils.qe_utils.get_qe_realspace_grid(fft_grid, A=None, cartesian=False)#
- afqmctools.utils.qe_utils.get_rvecs(axes, mesh)#
Regular grid in positive quadrant
- afqmctools.utils.qe_utils.read_orbitals(prefix, path=None, new_fft_grid=None, cartesian=False, realspace=False, return_grid=False)#
Read orbitals from Quantum Espresso output.
- Parameters:
prefix (str) – prefix of the output files
path (str | Path, optional) – path to directory containing the output files. If not specified, it is assumed that the files are in the current directory.
new_fft_grid (list(int), optional) – new FFT grid to use for the orbitals.
cartesian (bool, optional) – If True, return real space grid in Cartesian coordinates. If False, return real space grid in fractional coordinates. If ‘realspace’ is False, then this has no effect. If ‘return_grid’ is False, then this has no effect.
realspace (bool, optional) – If True, return orbitals in real space. If False, return orbitals in reciprocal space.
- Returns:
if realspace is True, then return a tuple containing: - dense representation of the realspace grid : np.ndarray with shape (3,N_grid) - orbitals : np.ndarray with shape (N_kpts,N_bands,N_grid) - fft_grid : np.ndarray with shape (3,) containing the size of the FFT grid if realspace is False, then return a tuple containing: - metadata : dict containing metadata - orbitals : list of np.ndarray with shape (N_kpts,N_bands,N_fft) - None : for tuple length consistency with the realspace case
- Return type:
tuple
- afqmctools.utils.qe_utils.read_qe_density(prefix, path=None, new_fft_grid=None, visualize=False, cartesian=True)#
- afqmctools.utils.qe_utils.read_qe_metadata(prefix, path=None)#
Read metadata from Quantum Espresso output.
- Parameters:
forbs (str) – orbital HDF file from Coqui
path (str) – path to directory containing the output files
- Returns:
meta (dict) – metadata
orbs (numpy.ndarray) – orbitals
- afqmctools.utils.qe_utils.shift_m(m, M)#
afqmctools.utils.slater_types module#
Define an enumerated type to simplify specifying a Slater determinant type.
- class afqmctools.utils.slater_types.MultiSlater#
Bases:
object
- class afqmctools.utils.slater_types.NonorthMSD#
Bases:
MultiSlater
- class afqmctools.utils.slater_types.ParticleHoleMSD#
Bases:
MultiSlater
- class afqmctools.utils.slater_types.SlaterDeterminant(type, slater_matrix=None)#
Bases:
object
afqmctools.utils.types module#
- class afqmctools.utils.types.SpinSymm(*values)#
Bases:
IntFlag- An enumerated class/type in order to
document the different types of spin_symmetry.
- The values are meaningful!! a larger
value implies less symmetry. This convention is used to match the internal conventions in the C++
- CLOSED = 1#
- COLLINEAR = 2#
- FULLYPOLARIZED = 4#
- NONCOLLINEAR = 3#
- afqmctools.utils.types.get_spin_symm_enum(spin_symm)#
afqmctools.utils.visualize module#
- afqmctools.utils.visualize.plot_lattice(lattice, show_direct_nearest=True, show_image_nearest=True, nth_neighbor=1, save=False, show_plot=True, show_labels=True, density=None, density_label='Density', show_lattice_vecs=True, **kwargs)#
Plot a lattice with nearest neighbors.
- Parameters:
lattice (
Lattice) – Lattice object to plot.show_direct_nearest (bool, optional) – Show direct nearest neighbors, by default True. Direct neighbors are connected by solid lines.
show_image_nearest (bool, optional) – Show image nearest neighbors, by default True. Image neighbors are connected by dashed lines.
save (bool, optional) – Save the plot to a file, by default False. If False, the plot is displayed.
show_labels (bool, optional) – Show site labels, by default True.
density (np.array, optional) – Array of site densities with shape (nsites,nsites), by default None. If provided, the site color is scaled by the density.
norm_type (str, optional) – Type of normalization to use for the density, by default ‘linear’. Options are ‘linear’ and ‘log’.
- afqmctools.utils.visualize.plot_site(ax, site)#