pyscf.gw.utils package#
Submodules#
pyscf.gw.utils.ac_grid module#
Grids and analytical continuation functions for GW and RPA.
- References:
T. Zhu and G.K.-L. Chan, J. Chem. Theory. Comput. 17, 727-741 (2021) New J. Phys. 14 053020 (2012)
- class pyscf.gw.utils.ac_grid.AC_Method(*args, **options)[source]#
Bases:
ABCBase class for AC methods
Attributes#
- shapetuple
Shape of the data array that was passed to ac_fit, excluding the frequency axis.
- abstractmethod ac_eval(freqs: ndarray, axis: int = -1)[source]#
- After you call ac_fit, you can call this function to evaluate the AC at
arbitrary complex frequencies.
Parameters#
- freqsnp.ndarray[np.complex128] | complex
1D array of complex frequencies, or a single complex frequency
- axisint, optional
Indicates which axis of the output array should correspond to the frequency axis, by default -1. Example: if you want (nmo, nmo, nfreq), call ac_eval(freqs, axis=-1)
if you want (nfreq, nmo, nmo), call ac_eval(data, freqs, axis=0)
If freqs is a scalar, the output shape will be the same as the input data shape.
Returns#
- np.ndarray
Interpolated/approximated values at the new complex frequencies
- abstractmethod ac_fit(data: ndarray, omega: ndarray, axis: int = -1)[source]#
The kernel of the AC method. This function should be implemented in the derived class.
Parameters#
- datanp.ndarray
Data to be fit, e.g. self energy
- omeganp.ndarray[np.double]
1D imaginary frequency grid
- axisint, optional
Indicates which axis of the data array corresponds to the frequency axis, by default -1. Example: data.shape is (nmo, nmo, nw), call ac_fit(data, omega, axis=-1)
data.shape is (nw, nmo, nmo), call ac_fit(data, omega, axis=0)
- abstractmethod diagonal(axis1=0, axis2=1)[source]#
- Create a new instance of the AC method with only the diagonal elements
of the self.coeff tensor. Convenient for getting diagonal of self-energy after calculating the full self-energy matrix.
This behaves more or less the same as np.diagonal.
Parameters#
- axis1int, optional
First axis, by default 0
- axis2int, optional
Second axis, by default 1
Returns#
- object
New instance of the AC method with only the diagonal elements.
- pyscf.gw.utils.ac_grid.AC_pade_thiele_diag(sigma, omega, npts=18, step_ratio=0.6666666666666666)[source]#
Pade fitting for diagonal elements for a matrix.
Parameters#
- sigmacomplex ndarray
matrix to fit, (norbs, nomega)
- omegacomplex array
frequency of the matrix sigma (nomega)
- nptsint, optional
number of selected points, by default 18
- step_ratio_type_, optional
step ratio to select points, by default 2.0/3.0
Returns#
- acobj.coeffcomplex ndarray
fitting coefficient
- acobj.omega[acobj.idx]complex ndarray
selected frequency points for fitting
- pyscf.gw.utils.ac_grid.AC_pade_thiele_full(sigma, omega, npts=18, step_ratio=0.6666666666666666)[source]#
Pade fitting for full matrix.
Parameters#
- sigmacomplex ndarray
matrix to fit, (norbs, nomega)
- omegacomplex array
frequency of the matrix sigma (nomega)
- nptsint, optional
number of selected points, by default 18
- step_ratio_type_, optional
step ratio to select points, by default 2.0/3.0
Returns#
- acobj.coeffcomplex ndarray
fitting coefficient
- acobj.omega[acobj.idx]complex ndarray
selected frequency points for fitting
- class pyscf.gw.utils.ac_grid.PadeAC(*args, npts=18, step_ratio=0.6666666666666666, **options)[source]#
Bases:
AC_MethodAnalytic continuation to real axis using a Pade approximation from Thiele’s reciprocal difference method Reference: J. Low Temp. Phys. 29, 179 (1977)
- ac_eval(freqs, axis=-1)[source]#
Evaluate Pade AC at arbitrary complex frequencies.
Parameters#
- freqsnp.ndarray[np.complex128]
1D array of complex frequencies
- axisint, optional
Indicates which axis of the output array should correspond to the frequency axis, by default -1. Example: if you want (nmo, nmo, nfreq), call ac_eval(freqs, axis=-1)
if you want (nfreq, nmo, nmo), call ac_eval(data, freqs, axis=0)
Returns#
- np.ndarray
Pade-Thiele AC evaluated at freqs
- ac_fit(data, omega, axis=-1)[source]#
Compute Pade-Thiele AC coefficients for the given data and omega.
Parameters#
- datanp.ndarray
Data to be fit, e.g. self energy
- omeganp.ndarray[np.double]
1D imaginary frequency grid
- axisint, optional
Indicates which axis of the data array corresponds to the frequency axis, by default -1. Example: data.shape is (nmo, nmo, nw), call ac_fit(data, omega, axis=-1)
data.shape is (nw, nmo, nmo), call ac_fit(data, omega, axis=0)
- diagonal(axis1=0, axis2=1)[source]#
- Create a new instance of the AC method with only the diagonal elements
of the self.coeff tensor. Convenient for getting diagonal of self-energy after calculating the full self-energy matrix.
This behaves more or less the same as np.diagonal.
Parameters#
- axis1int, optional
First axis, by default 0
- axis2int, optional
Second axis, by default 1
Returns#
- object
New instance of the AC method with only the diagonal elements.
- property omega_fit#
Return the frequency grid used for fitting.
- class pyscf.gw.utils.ac_grid.TwoPoleAC(orbs, nocc, **options)[source]#
Bases:
AC_MethodTwo-pole analytic continuation method.
- ac_eval(freqs, axis=-1)[source]#
Evaluate two-pole AC at arbitrary complex frequencies.
Parameters#
- freqsnp.ndarray[np.complex128]
1D array of complex frequencies
- axisint, optional
Indicates which axis of the output array should correspond to the frequency axis, by default -1. Example: if you want (nmo, nmo, nfreq), call ac_eval(freqs, axis=-1)
if you want (nfreq, nmo, nmo), call ac_eval(data, freqs, axis=0)
Returns#
- np.ndarray
Pade-Thiele AC evaluated at freqs
- ac_fit(data, omega, axis=-1)[source]#
Compute two-pole AC coefficients for the given data and omega.
Parameters#
- datanp.ndarray
Data to be fit, e.g. self energy
- omeganp.ndarray[np.double]
1D imaginary frequency grid
- axisint, optional
Indicates which axis of the data array corresponds to the frequency axis, by default -1. Example: data.shape is (nmo, nmo, nw), call ac_fit(data, omega, axis=-1)
data.shape is (nw, nmo, nmo), call ac_fit(data, omega, axis=0)
- diagonal(axis1=0, axis2=1)[source]#
- Create a new instance of the AC method with only the diagonal elements
of the self.coeff tensor. Convenient for getting diagonal of self-energy after calculating the full self-energy matrix.
This behaves more or less the same as np.diagonal.
Parameters#
- axis1int, optional
First axis, by default 0
- axis2int, optional
Second axis, by default 1
Returns#
- object
New instance of the AC method with only the diagonal elements.
- pyscf.gw.utils.ac_grid.load_ac(chkfilename: str, dataname: str = 'ac') AC_Method[source]#
Load an AC object from an HDF5 file.
Parameters#
- chkfilenamestr
Path to the HDF5 file
- datanamestr, optional
Name of the dataset in the HDF5 file, by default ‘ac’
Returns#
- AC_Method
The loaded AC object
- pyscf.gw.utils.ac_grid.pade_thiele_ndarray(freqs, zn, coeff)[source]#
NDarray-friendly analytic continuation using Pade-Thiele method.
Parameters#
- freqsnp.ndarray, shape (nfreqs,), complex
Points in the complex plane at which to evaluate the analytic continuation.
- znnp.ndarray, shape (ncoeff,), complex
interpolation points
- coeffnp.ndarray, shape (ncoeff, M1, M2, …,), complex
Pade-Thiele coefficients
Returns#
- np.ndarray, shape (nfreqs, M1, M2, …,), complex
Pade-Thiele analytic continuation evaluated at freqs
- pyscf.gw.utils.ac_grid.thiele_ndarray(fn, zn)[source]#
Iterative Thiele algorithm to compute coefficients of Pade approximant
Parameters#
- fnnp.ndarray, shape (nw, N1, N2, …,), complex
Function values at the points zn
- znnp.ndarray, shape(nw,), complex
Points in the complex plane used to compute fn
Returns#
- np.ndarray, shape(nw, N1, N2, …), complex
Coefficients of Pade approximant
pyscf.gw.utils.gw_np_helper module#
Math functions for GW and RPA.
- References:
T. Zhu and G.K.-L. Chan, J. Chem. Theory. Comput. 17, 727-741 (2021) New J. Phys. 14 053020 (2012)
- pyscf.gw.utils.gw_np_helper.addto_diagonal(arr, x)[source]#
Add a scalar or vector to the diagonal of a matrix.
Parameters#
- arr(M, M) array_like
Square matrix (will be modified)
- x(M,) array_like | scalar
Vector or scalar.
Returns#
- arr(M, M) ndarray
arr[i, i] <- arr[i, i] + x[i].
- pyscf.gw.utils.gw_np_helper.array_scale(arr, alpha)[source]#
Scale an array in place by a scalar with BLAS if possible. arr <- alpha * arr
Parameters#
- arrarray_like
Array to be scaled.
- alphascalar
Scale factor.
- pyscf.gw.utils.gw_np_helper.get_id_minus_pi(Pi)[source]#
Calculate I - Pi in place.
Parameters#
- Pi(M, M) array_like
Input matrix.
Returns#
- id_minus_pi(M, M) ndarray
(I - Pi)
- pyscf.gw.utils.gw_np_helper.get_id_minus_pi_inv(Pi, overwrite_input=False)[source]#
Calculate (I - Pi)^-1, given Pi
Parameters#
- Pi(M, M) array_like
Input matrix. Must be C-contiguous.
Returns#
- Pi_inv(M, M) ndarray
(I - Pi)^-1
- pyscf.gw.utils.gw_np_helper.get_id_minus_pi_inv_minus_id(Pi, overwrite_input=False)[source]#
Calculate (I - Pi)^-1 - I.
Parameters#
- Pi(M, M) array_like
Input matrix. Must be C-contiguous.
Returns#
- Pi_inv(M, M) ndarray
(I - Pi)^-1 - I.
- pyscf.gw.utils.gw_np_helper.mkslice(l)[source]#
Try to make a slice from a list of integers. If this is not possible, return the input unchanged.
Parameters#
- lslice | list | range | ndarray
Various ways of representing a list of integer indices
Returns#
- slice | list | ndarray
slice if possible, otherwise returns the input unchanged