Density
class#
Everything is taken care of by the Density
class.
- class fft_electronic_spin_density.classes.Density(fname_cube_file='./seedname.cube', permutation=None, verbose=True, scale_factor=1.0, R_atoms_idx=[0, 1], output_folder='./')#
Bases:
object
Read, visualize and fourier transform (spin) density from gaussian .cube files. Replace by a model function if required.
- FFT(verbose=True, normalized=True)#
Perform the 3D FFT of the scalar field.
- Parameters:
verbose (bool, optional) – Print information about the FFT. Defaults to True.
normalized (bool, optional) – Normalize the squared FFT. Defaults to True.
- conjugate()#
Conjugate the density in-place.
- Returns:
The conjugated density.
- Return type:
np.array
- coordinate_permutation(cube_data, permutation=[2, 1, 0])#
Swap in a cyclic way (x,y,z) -> (y,z,x) -> (z,x,y) depending on number of steps (1 or 2).
- Parameters:
cube_data (tuple) – Tuple with the numpy array and the metadata.
permutation (list, optional) – List of integers for the permutation. Defaults to [2,1,0].
- Returns:
Tuple with the numpy array and the metadata.
- Return type:
tuple
- create_cmap_with_cap(base_cmap_name='viridis', threshold=0.7, num_colors=1024)#
Creates a colormap where colors remain constant beyond a specified threshold.
- Parameters:
base_cmap_name (str, optional) – Name of the base colormap. Defaults to “viridis”.
threshold (float, optional) – Threshold value. Defaults to 0.7.
num_colors (int, optional) – Number of colors in the colormap. Defaults to 1024.
- Returns:
New colormap.
- Return type:
matplotlib.colors.ListedColormap
- get_c_idx_at_z_coordinates(z_coordinates)#
Get the indices of the z coordinates.
- Parameters:
z_coordinates (list) – List of z coordinates.
- Returns:
List of indices.
- Return type:
list
- get_i_kz(kz_target)#
Get the index of the kz plane closest to the target value.
- Parameters:
kz_target (float) – Target value of kz.
- Returns:
Index of the kz plane.
- Return type:
int
- get_index_at_kz(kz_target=15)#
Return the index at a given k_z value (in Angstrom^-1). Check that the k_z value is in range.
- Parameters:
kz_target (int, optional) – k_z value in Angstrom^-1. Defaults to 15.
- Returns:
Index of the k_z value.
- Return type:
int
- get_kz_at_index(kz_index=30)#
Return the k_z value (in Angstrom^-1) at a given index: first or last indices are -+ k_max/2, the middle index is k_z=0 (data is zero-centered; fftshifted after fft was performed). Check that index is in range.
- Parameters:
kz_index (int, optional) – Index of the k_z value. Defaults to 30.
- Returns:
k_z value in Angstrom^-1.
- Return type:
float
- get_sites_of_atoms(site_idx)#
Return the site centers of the atoms at the given indices.
- Parameters:
site_idx (list of integers) – integers of the required sites
- Returns:
tuples are cartesian coordinates (xyz) in Angstrom of the site centers
- Return type:
list of tuples
- integrate_cube_file(data_array=None, volume=None, verbose=True, fft=False)#
Integrate the density in a cube file.
- Parameters:
data_array (nd array, optional) – cube_file data (either provided or taken as the saved array upon loading). Defaults to None.
volume (float, optional) – volume of the cell in Bohr^3 !!!. If None, taken as Defaults to None.
verbose (bool, optional) – Print out the progress. Defaults to True.
- Returns:
total charge in the volume, total absolute charge in the volume
- Return type:
(float, float)
- mask_except_sites(leave_sites, density_to_mask=None)#
Mask the density except for the sites given in leave_sites. If density_to_mask is given, mask and return this density instead of the loaded density.
- Parameters:
leave_sites (dict) – Dictionary with keys ‘site_centers’ and ‘site_radii’ for the sites to leave in the model.
density_to_mask (np.array, optional) – Density to mask. Defaults to None.
- Returns:
Masked density.
- Return type:
np.array
- multiply_with(other)#
Multiply the density by another density object in-place.
- Parameters:
other (Density) – The other density object to multiply with.
- Returns:
The product of the two densities.
- Return type:
np.array
- plot_cube_fft(c_idx_arr=[0, 1, -1], fout_name='rho_sz.png', alpha=0.2, figsize=(8.0, 6), dpi=300, zeros_transparent=True, xlims=None, ylims=None, zlims=None, show_plot=False, output_folder=None)#
Concrete use of plot_cube_file_general for spin density files.
- Parameters:
c_idx_arr (list, optional) – show cuts at these indeces. Defaults to [0,1,-1].
fout_name (str, optional) – _description_. Defaults to ‘rho_sz.png’.
alpha (float, optional) – transparency. Defaults to 0.2.
figsize (tuple, optional) – _description_. Defaults to (8.0, 6).
dpi (int, optional) – _description_. Defaults to 300.
zeros_transparent (bool, optional) – _description_. Defaults to True.
xlims (list, optional) – _description_. Defaults to None.
ylims (list, optional) – _description_. Defaults to None.
zlims (list, optional) – _description_. Defaults to None.
show_plot (bool, optional) – _description_. Defaults to False.
output_folder (str, optional) – _description_. Defaults to None.
- Returns:
None
- plot_cube_file_general(X, Y, z_levels_cart, scalar3D_data, c_idx_arr=[0, 1, -1], fout_name='rho_sz.png', alpha=0.2, figsize=(8.0, 6), dpi=300, zeros_transparent=True, xlims=None, ylims=None, zlims=None, show_plot=False, xlabel=None, ylabel=None, zlabel=None, colors_centered=True, cmap='coolwarm', alpha_baseline=0.5, transparent_sigma=0.15, colorbar_label='spin density')#
For an array of indices, plot a 2D map as contourf at that z index of the 3D scalar field into a 3D plot at the height given by the z value.
- Parameters:
c_idx_arr (list, optional) – show cuts at these indeces. Defaults to [0,1,-1].
fout_name (str, optional) – _description_. Defaults to ‘rho_sz.png’.
- Returns:
None
- plot_cube_file_outer_surface(fout_name='rho_sz.png')#
Plot the outer surface of the scalar field in a 3D plot.
- Parameters:
fout_name (str, optional) – Name of the output file. Defaults to ‘rho_sz.png’.
- Returns:
None
- plot_cube_rho_sz(c_idx_arr=[0, 1, -1], fout_name='rho_sz.png', alpha=0.2, figsize=(8.0, 6), dpi=300, zeros_transparent=True, xlims=None, ylims=None, zlims=None, show_plot=False, output_folder=None)#
Concrete use of plot_cube_file_general for spin density files.
- Parameters:
c_idx_arr (list, optional) – show cuts at these indeces. Defaults to [0,1,-1].
fout_name (str, optional) – _description_. Defaults to ‘rho_sz.png’.
alpha (float, optional) – transparency. Defaults to 0.2.
figsize (tuple, optional) – _description_. Defaults to (8.0, 6).
dpi (int, optional) – _description_. Defaults to 300.
zeros_transparent (bool, optional) – _description_. Defaults to True.
xlims (list, optional) – _description_. Defaults to None.
ylims (list, optional) – _description_. Defaults to None.
zlims (list, optional) – _description_. Defaults to None.
show_plot (bool, optional) – _description_. Defaults to False.
output_folder (str, optional) – _description_. Defaults to None.
- plot_fft_2D(i_kz, fft_as_log=False, k1_idx=0, k2_idx=1, fout_name='fft_2D_out.png', verbose=True, figsize=(6.0, 6.0), dpi=500, fixed_z_scale=True, xlims=None, ylims=None, zlims=None, plot_line_cut=False, kx_arr_along=None, ky_arr_along=None, kx_arr_perp=None, ky_arr_perp=None, cut_along='both', normalized=True, cax_saturation=None, output_folder=None, show_plot=False)#
Plot the 2D FFT of the scalar field.
- Parameters:
i_kz (int) – Index of the kz plane.
fft_as_log (bool, optional) – Plot the log of the FFT. Defaults to False.
k1_idx (int, optional) – Index of the first lattice vector. Defaults to 0.
k2_idx (int, optional) – Index of the second lattice vector. Defaults to 1.
fout_name (str, optional) – Name of the output file. Defaults to ‘fft_2D_out.png’.
verbose (bool, optional) – Print information about the plot. Defaults to True.
figsize (tuple, optional) – Size of the figure. Defaults to (8.0, 6.0).
dpi (int, optional) – Dots per inch. Defaults to 500.
fixed_z_scale (bool, optional) – Fix the z scale. Defaults to True.
xlims (list, optional) – Limits of the x axis. Defaults to None.
ylims (list, optional) – Limits of the y axis. Defaults to None.
zlims (list, optional) – Limits of the z axis. Defaults to None.
plot_line_cut (bool, optional) – Plot the line cuts. Defaults to False.
kx_arr_along (list, optional) – List of kx values for the line cut along the lattice vector. Defaults to None.
ky_arr_along (list, optional) – List of ky values for the line cut along the lattice vector. Defaults to None.
kx_arr_perp (list, optional) – List of kx values for the line cut perpendicular to the lattice vector. Defaults to None.
ky_arr_perp (list, optional) – List of ky values for the line cut perpendicular to the lattice vector. Defaults to None.
cut_along (str, optional) – Direction of the line cut. Defaults to ‘both’.
normalized (bool, optional) – Normalize the FFT. Defaults to True.
cax_saturation (float, optional) – Saturation value for the colorbar. Defaults to None.
output_folder (str, optional) – Output folder. Defaults to None.
- plot_fft_along_line(i_kz=None, cut_along='along_stripes', kx_ky_fun=None, k_dist_lim=15, kx_0_along=None, ky_0_along=None, kx_0_perp=None, ky_0_perp=None, N_points=3001, fout_name='test_1D_plot_along.png', normalized=True, figsize=(4.5, 3.5), ylim=1.4, cax_saturation=None)#
Plot the line cut of the FFT along the stripes.
- Parameters:
i_kz (int, optional) – Index of the kz plane. Defaults to None.
cut_along (str, optional) – Direction of the line cut. Defaults to ‘along_stripes’.
kx_ky_fun (function, optional) – Function to calculate kx, ky for the line cut. Defaults to None.
k_dist_lim (int, optional) – Limit of the distance from the center. Defaults to 15.
kx_0_along (float, optional) – Initial kx for the line cut along the stripes. Defaults to None.
ky_0_along (float, optional) – Initial ky for the line cut along the stripes. Defaults to None.
kx_0_perp (float, optional) – Initial kx for the line cut perpendicular to the stripes. Defaults to None.
ky_0_perp (float, optional) – Initial ky for the line cut perpendicular to the stripes. Defaults to None.
N_points (int, optional) – Number of points in the line cut. Defaults to 3001.
fout_name (str, optional) – Name of the output file. Defaults to ‘test_1D_plot_along.png’.
normalized (bool, optional) – Normalize the FFT. Defaults to True.
figsize (tuple, optional) – Size of the figure. Defaults to (4.5, 3.5).
ylim (float, optional) – Limit of the y axis. Defaults to 1.4.
cax_saturation (float, optional) – Saturation value for the colorbar. Defaults to None.
- Returns:
kx_along, ky_along, F_abs_sq_interp_along, kx_perp, ky_perp, F_abs_sq_interp_per
- Return type:
tuple
- replace_by_model(fit=False, parameters={'centers': [(0.5, 0.5, 0.5)], 'fit_params_init_all': {'amplitude': [1]}, 'sigmas': [0.5], 'spin_down_orbital_all': [False], 'type': ['gaussian']}, leave_sites=None, leave_as_wavefunction=False)#
Replace the scalar field in the numpy array by a model function.
- Parameters:
type (str, optional) – Type of the model function. Defaults to ‘gaussian’.
fit (bool, optional) – Fit the model to the data. Defaults to False.
parameters (dict, optional) – Parameters of the model function. Defaults to {‘sigmas’:[0.5], ‘centers’:[(0.5, 0.5, 0.5)], ‘fit_params_init_all’:{‘amplitude’:[1]}}
leave_sites (dict, optional) – Dictionary with keys ‘site_centers’ and ‘site_radii’ for the sites to leave in the model. If provided, the fitted density will be masked after its construction.
leave_as_wavefunction (bool, optional) – Leave the model as a wavefunction instead of the density (wavefunction squared). Defaults to False.
None. (Defaults to)
- square_data()#
Square the density in-place.
- Returns:
The squared density.
- Return type:
np.array
- write_cube_file_fft(fout='rho_sz_fft.cube', output_folder=None)#
Write out the modified rho_sz to a cube file.
- Parameters:
fout (str, optional) – _description_. Defaults to ‘rho_sz_modified.cube’.
output_folder (str, optional) – _description_. Defaults to None.
- write_cube_file_rho_sz(fout='rho_sz_modified.cube', output_folder=None)#
Write out the modified rho_sz to a cube file.
- Parameters:
fout (str, optional) – _description_. Defaults to ‘rho_sz_modified.cube’.
output_folder (str, optional) – _description_. Defaults to None.