xharpy.f0j_sources package
Module contents
These modules provide the possibility to generate atomic form factors for the use in XHARPy.
Usage
Each of the modules has to implement three functions:
- calc_f0j
Calculates the atomic form factors that have to be recalculated during the refinement
- calc_f0j_core
Calculates the frozen core density on a spherical grid. This means it is only calculated once for each refinement. The core density can therefore be integrated on much smaller steps close to the core position
- generate_cif_output
Generates the output for the cif file that represents how the atomic form factors were obtained
Development
If you want to write your own new way of calculating atomic form factors you can write a new module within the f0j_sources folder.
In addition to the the implementation of the three functions they need to be added to the core.refine function and to the io.write_cif functions with the same selection key in the refinement_dict[‘f0j_source’]
Subpackages
Submodules
xharpy.f0j_sources.gpaw_mpi_source module
This module provides the necessary functions for calculating atomic form factors using the GPAW library in multi-core mode on a rectangular grid for the valence density and a spherical grid for the core densities.
- xharpy.f0j_sources.gpaw_mpi_source.calc_f0j(cell_mat_m: ndarray, construction_instructions: List[AtomInstructions], parameters: ndarray, index_vec_h: ndarray, symm_mats_vecs: Tuple[ndarray, ndarray], computation_dict: Dict[str, Any], restart: bool = True, explicit_core: bool = True) ndarray
Calculate the atomic form factor or atomic valence form factors using GPAW with MPI for the multi-core calculation. If you have problems and are in a jupyter notebook you probably need to restart. This routine will not work if GPAW has been loaded anywhere else.
- Parameters:
cell_mat_m (np.ndarray) – size (3, 3) array with the unit cell vectors as row vectors
construction_instructions (List[AtomInstructions]) – List of instructions for reconstructing the atomic parameters from the list of refined parameters
parameters (np.ndarray) – Current parameter values
index_vec_h (np.ndarray) – size (H) vector containing Miller indicees of the measured reflections
symm_mats_vecs (Tuple[np.ndarray, np.ndarray]) – size (K, 3, 3) array of symmetry matrices and (K, 3) array of translation vectors for all symmetry elements in the unit cell
computation_dict (Dict[str, Any]) –
contains options for the atomic form factor calculation. The function will use and exclude the following options from the dictionary and pass the rest onto the GPAW calculator without further checks.
save_file (str): Path to the file that is used for saving and loading DFT results, by default ‘gpaw_result.gpw’
gridinterpolation (1, 2, 4): Using GPAWs interpolation this is the factor by which the grid from the wave function will be interpolated for the calculation of atomic form factors with FFT. This can be reduced if you run out of memory for this step. Allowed values are 1, 2, and 4, by default 4
symm_equiv (str): The atomic form factors of symmetry equivalent atoms can be calculated individually for each atom (‘individually’) or they can be calculated once for each atom in the asymmetric unit and expanded to the other atoms (‘once’), finally they can be averaged between symmetry equivalent atoms and expanded afterwards (‘averaged’). Once should be sufficient for most structures and saves time. Try one of the other options if you suspect problems, by default ‘once’
skip_symm (Dict[int, List[int]]): Can used to prevent the expansion of the atom(s) with the index(es) given as dictionary keys as given in the construction_instructions with the symmetry operations of the indexes given in the list, which correspond to the indexes in the symm_mats_vecs object. This has proven to be successful for the calculation of atoms disordered on special positions. Can not be used with if symm_equiv is ‘individually’, by default {}
magmoms (np.ndarray): Experimental: starting values for magnetic moments of atoms. These will be expanded to atoms in the unit cell by just applying the same magnetic moment to all symmetry equivalent atoms. This is probably too simplistic and will fail.
core_grid (Union[str, int]): Determines how the core grid is build on which the core density is evaluated ‘rgd’ will use the default grid from GPAW, an integer k will span a grid of 2**k + 1 points, where the first point is 0 and all other points are determined by exp(-ai) * r_max, where ai is a np linspace between 1.25 * k and 0, by default ‘rgd’
mpicores (Union[int, str]): give the number of cores used for the mpi calculation. If this is ‘auto’ GPAW will select the number itself, by default ‘auto’
For the allowed options of the GPAW calculator consult: https://wiki.fysik.dtu.dk/gpaw/documentation/basic.html
restart (str, optional) – File with the starting density for the DFT calculation, by default None
explicit_core (bool, optional) – If True the frozen core density is assumed to be calculated separately, therefore only the valence density will be split up, by default True
- Returns:
f0j – size (K, N, H) array of atomic form factors for all reflections and symmetry generated atoms within the unit cells. Atoms on special positions are present multiple times and have the atomic form factor of the full atom.
- Return type:
np.ndarray
- xharpy.f0j_sources.gpaw_mpi_source.calc_f0j_core(cell_mat_m: ndarray, construction_instructions: List[AtomInstructions], parameters: ndarray, index_vec_h: ndarray, symm_mats_vecs: ndarray, computation_dict: Dict[str, Any]) ndarray
Calculate the core atomic form factors on an exponential spherical grid. Up to 5000 reflections every reflection will be calculated explicitely. Above that a spline will be generated from 5000 points on an exponential grid. The spline is then used to calculate the individual atomic core form factor values.
- Parameters:
cell_mat_m (np.ndarray) – size (3, 3) array with the unit cell vectors as row vectors
construction_instructions (List[AtomInstructions]) – List of instructions for reconstructing the atomic parameters from the list of refined parameters
parameters (np.ndarray) – Current parameter values
index_vec_h (np.ndarray) – size (H) vector containing Miller indicees of the measured reflections
symm_mats_vecs (Tuple[np.ndarray, np.ndarray]) – size (K, 3, 3) array of symmetry matrices and (K, 3) array of translation vectors for all symmetry elements in the unit cell
computation_dict (Dict[str, Any]) – contains options for the calculation. The custom options will be ignored and everything else is passed on to GPAW for initialisation. The only option that makes a difference here is which setups are used. (Need to be same as in calc_f0j)
- Returns:
f0j_core – size (N, H) array of atomic core form factors calculated separately
- Return type:
np.ndarray
- xharpy.f0j_sources.gpaw_mpi_source.generate_cif_output(computation_dict: Dict[str, Any]) str
Generates at string, that details the computation options for use in the cif generation routine.
- Parameters:
computation_dict (Dict[str, Any]) – contains options for the calculation.
- Returns:
cif_string – The string that will be added to the cif-file
- Return type:
str
xharpy.f0j_sources.gpaw_source module
This module provides the necessary functions for calculating atomic form factors using the GPAW library in single-core mode on a rectangular grid for the valence density and a spherical grid for the core densities.
- class xharpy.f0j_sources.gpaw_source.HirshfeldDensity(*args: Any, **kwargs: Any)
Bases:
RealSpaceDensityDensity as sum of atomic densities.
- get_density(atom_indices=None, gridrefinement=2, skip_core=False)
Get sum of atomic densities from the given atom list.
- Parameters:
atom_indices (list_like) – All atoms are taken if the list is not given.
gridrefinement (1, 2, 4) – Gridrefinement given to get_all_electron_density
- Returns:
spin summed density, grid_descriptor
- Return type:
type
- set_positions(spos_ac, atom_partition)
HirshfeldDensity builds a hack density object to calculate all electron density of atoms. This methods overrides the parallel distribution of atomic density matrices in density.py
- class xharpy.f0j_sources.gpaw_source.HirshfeldPartitioning(calculator, density_cutoff=1e-12)
Bases:
objectPartion space according to the Hirshfeld method.
After: F. L. Hirshfeld Theoret. Chim.Acta 44 (1977) 129-138
- get_calculator()
- get_charges(den_g=None)
Charge on the atom according to the Hirshfeld partitioning
Can be applied to any density den_g.
- get_effective_volume_ratio(atom_index)
Effective volume to free volume ratio.
After: Tkatchenko and Scheffler PRL 102 (2009) 073005, eq. (7)
- get_effective_volume_ratios()
Return the list of effective volume to free volume ratios.
- get_weight(atom_index)
- initialize()
- xharpy.f0j_sources.gpaw_source.calc_f0j(cell_mat_m: ndarray, construction_instructions: List[AtomInstructions], parameters: ndarray, index_vec_h: ndarray, symm_mats_vecs: Tuple[ndarray, ndarray], computation_dict: Dict[str, Any], restart: bool = True, explicit_core: bool = True) ndarray
Calculate the atomic form factor or atomic valence form factors using GPAW.
- Parameters:
cell_mat_m (np.ndarray) – size (3, 3) array with the unit cell vectors as row vectors
construction_instructions (List[AtomInstructions]) – List of instructions for reconstructing the atomic parameters from the list of refined parameters
parameters (np.ndarray) – Current parameter values
index_vec_h (np.ndarray) – size (H) vector containing Miller indicees of the measured reflections
symm_mats_vecs (Tuple[np.ndarray, np.ndarray]) – size (K, 3, 3) array of symmetry matrices and (K, 3) array of translation vectors for all symmetry elements in the unit cell
computation_dict (Dict[str, Any]) –
contains options for the atomic form factor calculation. The function will use and exclude the following options from the dictionary and pass the rest onto the GPAW calculator without further checks.
save_file (str): Path to the file that is used for saving and loading DFT results, by default ‘gpaw_result.gpw’
gridinterpolation (1, 2, 4): Using GPAWs interpolation this is the factor by which the grid from the wave function will be interpolated for the calculation of atomic form factors with FFT. This can be reduced if you run out of memory for this step. Allowed values are 1, 2, and 4, by default 4
symm_equiv (str): The atomic form factors of symmetry equivalent atoms can be calculated individually for each atom (‘individually’) or they can be calculated once for each atom in the asymmetric unit and expanded to the other atoms (‘once’), finally they can be averaged between symmetry equivalent atoms and expanded afterwards (‘averaged’). Once should be sufficient for most structures and saves time. Try one of the other options if you suspect problems, by default ‘once’
skip_symm (Dict[int, List[int]]): Can used to prevent the expansion of the atom(s) with the index(es) given as dictionary keys as given in the construction_instructions with the symmetry operations of the indexes given in the list, which correspond to the indexes in the symm_mats_vecs object. This has proven to be successful for the calculation of atoms disordered on special positions. Can not be used with if symm_equiv is ‘individually’, by default {}
core_grid (Union[str, int]): Determines how the core grid is build on which the core density is evaluated ‘rgd’ will use the default grid from GPAW, an integer k will span a grid of 2**k + 1 points, where the first point is 0 and all other points are determined by exp(-ai) * r_max, where ai is a np linspace between 1.25 * k and 0, by default ‘rgd’
magmoms (np.ndarray): Experimental: starting values for magnetic moments of atoms. These will be expanded to atoms in the unit cell by just applying the same magnetic moment to all symmetry equivalent atoms. This is probably too simplistic and will fail.
For the allowed options of the GPAW calculator consult: https://wiki.fysik.dtu.dk/gpaw/documentation/basic.html
restart (bool, optional) – If true, the DFT calculation will be restarted from a previous calculation
explicit_core (bool, optional) – If True the frozen core density is assumed to be calculated separately, therefore only the valence density will be split up, by default True
- Returns:
f0j – size (K, N, H) array of atomic form factors for all reflections and symmetry generated atoms within the unit cells. Atoms on special positions are present multiple times and have the atomic form factor of the full atom.
- Return type:
np.ndarray
- xharpy.f0j_sources.gpaw_source.calc_f0j_core(cell_mat_m: ndarray, construction_instructions: List[AtomInstructions], parameters: ndarray, index_vec_h: ndarray, symm_mats_vecs: ndarray, computation_dict: Dict[str, Any]) ndarray
Calculate the core atomic form factors on an exponential spherical grid. Up to 5000 reflections every reflection will be calculated explicitely. Above that a spline will be generated from 5000 points on an exponential grid. The spline is then used to calculate the individual atomic core form factor values.
- Parameters:
cell_mat_m (np.ndarray) – size (3, 3) array with the unit cell vectors as row vectors
construction_instructions (List[AtomInstructions]) – List of instructions for reconstructing the atomic parameters from the list of refined parameters
parameters (np.ndarray) – Current parameter values
index_vec_h (np.ndarray) – size (H) vector containing Miller indicees of the measured reflections
symm_mats_vecs (Tuple[np.ndarray, np.ndarray]) – size (K, 3, 3) array of symmetry matrices and (K, 3) array of translation vectors for all symmetry elements in the unit cell
computation_dict (Dict[str, Any]) – contains options for the calculation. The custom options will be ignored and everything else is passed on to GPAW for initialisation. The only option that makes a difference here is which setups are used. (Need to be same as in calc_f0j)
- Returns:
f0j_core – size (N, H) array of atomic core form factors calculated separately
- Return type:
np.ndarray
- xharpy.f0j_sources.gpaw_source.f_core_from_spline(spline: Any, g_k: ndarray, grid: int | ndarray = 13) ndarray
Calculate the spherical atomic form factor from a core density spline
- Parameters:
spline (Any) – GPAW spline containing the core density for expansion. Anything else with a map and get_cutoff function should work too. The unit of length needs to be identical to the reciprocal of the unit used in g_k.
g_k (np.ndarray) – reciprocal distances to origin for all. Reciprocal unit of length needs to be identical to the one used in the spline
k (int, optional) – determines the number of distance points used for the evaluation as 2**k + 1. The first point is always zero, the other points are determined by np.exp(-1 * np.linspace(1.25 * k, 0.0 , 2**k)) * r_max, by default 13
- Returns:
f0j_core – calculated core atomic form factors for the reciprocal distances given in g_k
- Return type:
np.ndarray
- xharpy.f0j_sources.gpaw_source.generate_cif_output(computation_dict: Dict[str, Any]) str
Generates at string, that details the computation options for use in the cif generation routine.
- Parameters:
computation_dict (Dict[str, Any]) – contains options for the calculation.
- Returns:
The string that will be added to the cif-file
- Return type:
str
xharpy.f0j_sources.gpaw_spherical_source module
xharpy.f0j_sources.iam_source module
This module will generate independent atom model atomic form factors for the given atoms. Mainly kept to give the possibility to compare to other implementations of the independent atom model, which usually should be faster.
- xharpy.f0j_sources.iam_source.calc_f0j(cell_mat_m: ndarray, construction_instructions: List[AtomInstructions], parameters: ndarray, index_vec_h: ndarray, symm_mats_vecs: Tuple[ndarray, ndarray], computation_dict: Dict[str, Any], restart: bool = True, explicit_core: bool = True) ndarray
Calculate the atomic form factor according to the tabulated values for the independent atom model
- Parameters:
cell_mat_m (np.ndarray) – size (3, 3) array with the unit cell vectors as row vectors
construction_instructions (List[AtomInstructions]) – List of instructions for reconstructing the atomic parameters from the list of refined parameters
parameters (np.ndarray) – ignored
index_vec_h (np.ndarray) – size (H) vector containing Miller indicees of the measured reflections
symm_mats_vecs (Tuple[np.ndarray, np.ndarray]) – size (K, 3, 3) array of symmetry matrices and (K, 3) array of translation vectors for all symmetry elements in the unit cell
computation_dict (Dict[str, Any]) – There are no options here, will be ignored
restart (bool, optional) – ignored
explicit_core (bool, optional) – ignored
- Returns:
f0j – size (K, N, H) array of atomic form factors for all reflections and symmetry generated atoms within the unit cells. Atoms on special positions are present multiple times and have the atomic form factor of the full atom.
- Return type:
np.ndarray
- xharpy.f0j_sources.iam_source.calc_f0j_core(*args, **kwargs)
- xharpy.f0j_sources.iam_source.generate_cif_output(computation_dict: Dict[str, Any]) str
Generates at string, that details the computation options for use in the cif generation routine.
- Parameters:
computation_dict (Dict[str, Any]) – ignored, there should be no options
- Returns:
cif_string – The string that will be added to the cif-file
- Return type:
str
xharpy.f0j_sources.nosphera2_orca_source module
- xharpy.f0j_sources.nosphera2_orca_source.angle_between(v1, v2)
Returns the angle in radians between vectors v1 and v2
- xharpy.f0j_sources.nosphera2_orca_source.calc_f0j(cell_mat_m: ndarray, construction_instructions: List[AtomInstructions], parameters: ndarray, index_vec_h: ndarray, symm_mats_vecs: Tuple[ndarray, ndarray], computation_dict: Dict[str, Any], restart: bool = True, explicit_core: bool = True) ndarray
Gives the possibility to calculate atomic form factors in the LCAO approximation using ORCA and NoSpherA2. Both Programs need to be installed separately. NoSpherA2 is shipped with Olex or can be compiled from the source provided in Florian Klemiss’ Github Repository.
- Parameters:
cell_mat_m (np.ndarray) – size (3, 3) array with the unit cell vectors as row vectors
construction_instructions (List[AtomInstructions]) – List of instructions for reconstructing the atomic parameters from the list of refined parameters
parameters (np.ndarray) – Current parameter values
index_vec_h (np.ndarray) – size (H) vector containing Miller indicees of the measured reflections
symm_mats_vecs (Tuple[np.ndarray, np.ndarray]) – size (K, 3, 3) array of symmetry matrices and (K, 3) array of translation vectors for all symmetry elements in the unit cell
computation_dict (Dict[str, Any]) –
Contains options for NoSpherA2/ORCA calculation
orca_path (str): Path to the ORCA executable. Is required for multi-core calculations. If the path given is relative, take into account that the executable will be run in the calc_folder and change the relative path accordingly, by default ‘orca’
nosphera2_path (str): Path to the NoSpherA2 executable. If you want to use a relative path, it needs to be given relative to the calc_folder, not the folder, where the script is run.
nosphera2_accuracy (int): Number between 1-5 for the size of the grid nosphera2 uses for the calculation of atomic form factors, by default 3
calc_folder (str): Folder in which the ORCA and NoSpherA2 calculations will be conducted. Mainly used to keep the main directory somewhat clean, by default ‘calc’
basis_set (str): If there is no newline character, this string will be used by ORCA to select the basis set by name (e.g. def2-TZVPP). If a newline is present, it will instead be used within ORCA’s %basis keyword, with a single ‘end’ added at the end. This way basis sets from EMSL can be used, by default ‘def2-SVP’
functional (str): Density functional as ORCA keyword, by default ‘PBE’
charge (float): Fragment charge, by default 0
multiplicity (int): Fragment multiplicity, by default 1
n_cores (int): number of cores used for the ORCA and NoSpherA2 calculations. If larger than 1, the orca path needs to be given as an absolute path, by default 1.
cutoff (float): Cutoff in Angstrom for the generation of cluster- charges. Fragments, which have an atom within this radius will be added completely to the cluster charge list, by default 0.0
build_dict (Dict[str, List(str)]): Dictionary to complete a fragment before the calculation. The key string needs to be a symmetry card (e.g. -x, 1-y, 1/2-z). The following list needs to contain the atom names, on which the symmetry is supposed to be applied.
restart (bool, optional) – If true, the DFT calculation will be restarted from a previous calculation
explicit_core (bool, optional) – If True the frozen core density is assumed to be calculated separately, therefore only the valence density will be split up, by default True
- Returns:
f0j – size (K, N, H) array of atomic form factors for all reflections and symmetry generated atoms within the unit cells. Atoms on special positions are present multiple times and have the atomic form factor of the full atom.
- Return type:
np.ndarray
- xharpy.f0j_sources.nosphera2_orca_source.calc_f0j_core(*args, **kwargs)
- xharpy.f0j_sources.nosphera2_orca_source.generate_cif_output(computation_dict: Dict[str, Any]) str
Generates at string, that details the computation options for use in the cif generation routine.
- Parameters:
computation_dict (Dict[str, Any]) – contains options for the calculation.
- Returns:
The string that will be added to the cif-file
- Return type:
str
- xharpy.f0j_sources.nosphera2_orca_source.generate_cluster_file(symm_mats_vecs: Tuple[ndarray, ndarray], fragment_positions: ndarray, original_labels: List[str], cell_mat_m: ndarray, cutoff: float, calc_folder: str, charge: float) str
Will read the Hirshfeld charges from a NoSpherA2.log file and then generate symmetry equivalent positions, where at least one atom from the fragment is within the cutoff (in Angstrom). The charges are written into a ‘cluster_charges.pc’ file and the string to add to the orca.inp is returned. May be inefficient so if you run out of memory try reducing the cluster radius
- Parameters:
symm_mats_vecs (Tuple[np.ndarray, np.ndarray]) – size (K, 3, 3) array of symmetry matrices and (K, 3) array of translation vectors for all symmetry elements in the unit cell
fragment_positions (np.ndarray) – size (Z, 3) array of positions of the fragment (including added atoms from a build_dict)
original_labels (List[str]) – original_labels of the fragment positions, used for lookup from the NoSpherA2.log
cell_mat_m (np.ndarray) – size (3, 3) array with the unit cell vectors as row vectors
cutoff (float) – cutoff radius in Angstrom
calc_folder (str) – calc_folder for the NoSpherA2 and ORCA calculation
charge (float) – Overall charge. The sum of atom charges from the fragment will be corrected to be this value, to correct rounding errors.
- Returns:
charge_str – Will be an empty string if no cluster charges were added, otherwise will return the string, that needs to be added to the ORCA input file.
- Return type:
str
- xharpy.f0j_sources.nosphera2_orca_source.generate_cube_shell(shell_index: int) ndarray
Generates indicees for the surface of a cube that is constructed from (2 * shell_index + 1)**3 smaller indexed cubes, e.g. if shell_index is 2 will generate all combinations of three coordinates where one coordinate is 2 or -2. Is used for building larger and larger shells of surrounding unit cells.
- Parameters:
shell_index (int) – index of cube shell, index 0 is only one center cube, index one adds the 26 surronding smaller cubes and so on
- Returns:
shell_add – size (s,3) array of coordinates of surrounding unit cells
- Return type:
np.ndarray
xharpy.f0j_sources.qe_source module
This module provides the necessary function to do use Quantum Espresso as source for the atomic form factors. Still very experimental but works in principle.
- xharpy.f0j_sources.qe_source.calc_f0j(cell_mat_m: ndarray, construction_instructions: List[AtomInstructions], parameters: ndarray, index_vec_h: ndarray, symm_mats_vecs: Tuple[ndarray, ndarray], computation_dict: Dict[str, Any], restart: bool = True, explicit_core: bool = True) ndarray
Calculate the atomic form factor or atomic valence form factors using Quantum espresso.
- Parameters:
cell_mat_m (np.ndarray) – size (3, 3) array with the unit cell vectors as row vectors
construction_instructions (List[AtomInstructions]) – List of instructions for reconstructing the atomic parameters from the list of refined parameters
parameters (np.ndarray) – Current parameter values
index_vec_h (np.ndarray) – size (H) vector containing Miller indicees of the measured reflections
symm_mats_vecs (Tuple[np.ndarray, np.ndarray]) – size (K, 3, 3) array of symmetry matrices and (K, 3) array of translation vectors for all symmetry elements in the unit cell
computation_dict (Dict[str, Any]) –
contains options for the atomic form factor calculation. The function will use and exclude the following options from the dictionary and write the rest into the quantum-espresso pw.x output file without further check
mpicores (Union[str, int]): The number of cores used for the pw.x and pp.x calculation in Quantum Espresso, ‘auto’ will mpiexec let select this option. However sometimes it has proven faster to choose a lower number of cores manually. This is not the only option for parallelisation: setting mpicores to 1 might still use non-MPI means of multi-core calculations.
symm_equiv (str): The atomic form factors of symmetry equivalent atoms can be calculated individually for each atom (‘individually’) or they can be calculated once for each atom in the asymmetric unit and expanded to the other atoms (‘once’), finally they can be averaged between symmetry equivalent atoms and expanded afterwards (‘averaged’). Once should be sufficient for most structures and saves time. Try one of the other options if you suspect problems, by default ‘once’
skip_symm (Dict[int, List[int]]): Can used to prevent the expansion of the atom(s) with the index(es) given as dictionary keys as given in the construction_instructions with the symmetry operations of the indexes given in the list, which correspond to the indexes in the symm_mats_vecs object. This has proven to be successful for the calculation of atoms disordered on special positions. Can not be used with if symm_equiv is ‘individually’, by default {}
pw_in_file (str): Filename for the input file of the pw.x scf calculation, by default pw.in
pp_in_file (str): Filename for the input file of pp.x, by default pp.in
pw_out_file (str): Filename for the output file of the pw.x scf calculation, by default pw.out
pp_out_file (str): Filename for the output file of pp.x, by default pp.out
pw_executable (str): Filename or path to the executable of pw, by default pw.x
pp_executable (str): Filename or path to the executable of pp, by default pp.x
windows (bool): If set to True, Windows PowerShell commands will be used to call Quantum Espresso, by default False
non_convergence (str): How to deal with non-convergence in SCF ‘exception’ will stop the calculation with a ValueError, ‘warning’ will print out a warning module ‘print’ will only print the warning in the usual text, by default ‘exception’
K-points are organised into their own entry ‘k_points’ which is a dict ‘mode’ is the selection mode, and ‘input’ is the output after the K_POINTS entry in the pw.x output file.
The other options are organised as subdicts with the naming of the section in the pw.x input file in lowercase. For these options consult the pw.x file format documentation at: https://www.quantum-espresso.org/Doc/INPUT_PW.html
restart (bool, optional) – If true, the DFT calculation will be restarted from a previous calculation
explicit_core (bool, optional) – If True the frozen core density is assumed to be calculated separately, therefore only the valence density will be split up, by default True
- Returns:
f0j – size (K, N, H) array of atomic form factors for all reflections and symmetry generated atoms within the unit cells. Atoms on special positions are present multiple times and have the atomic form factor of the full atom.
- Return type:
np.ndarray
- xharpy.f0j_sources.qe_source.calc_f0j_core(cell_mat_m: ndarray, construction_instructions: List[AtomInstructions], parameters: ndarray, index_vec_h: ndarray, computation_dict: Dict[str, Any]) Tuple[ndarray, Dict[str, Any]]
Reads the .upf files given in the computation_dict and fourier transforms the core charges on the grid given in that file. A direct space transform will be used to add the number of core_electrons to the returned computation_dict for correct normalisation of densities in the calc_f0j function
- Parameters:
cell_mat_m (np.ndarray) – size (3, 3) array with the unit cell vectors as row vectors
construction_instructions (List[AtomInstructions]) – List of instructions for reconstructing the atomic parameters from the list of refined parameters
parameters (np.ndarray) – Current parameter values
index_vec_h (np.ndarray) – size (H) vector containing Miller indicees of the measured reflections
computation_dict (Dict[str, Any]) – contains options for the calculation. The custom options will be ignored and everything else is passed on to GPAW for initialisation. The only option that makes a difference here is which setups are used. (Need to be same as in calc_f0j)
- Returns:
f0j_core (np.ndarray,) – size (N, H) array of atomic core form factors calculated separately
computation_dict (Dict[str, Any]) – original computation dict with added core electrons.
- Raises:
ValueError – No core electron entry found
ValueError – No grid entry found
- xharpy.f0j_sources.qe_source.generate_cif_output(computation_dict: Dict[str, Any]) str
Generates at string, that details the computation options for use in the cif generation routine.
- Parameters:
computation_dict (Dict[str, Any]) – contains options for the calculation.
- Returns:
The string that will be added to the cif-file
- Return type:
str
- xharpy.f0j_sources.qe_source.qe_atomic_density(symm_symbols: List[str], symm_positions: ndarray, cell_mat_m: ndarray, computation_dict: Dict[str, Any], shape: Tuple[int] | None = None, cwd='/home/docs/checkouts/readthedocs.org/user_builds/xharpy/checkouts/latest/docs/source') ndarray
Generates the atomic function needed for Hirshfeld partitioning by setting the quantum espresso options to 0 calculation steps and initialisation to atomic. Subsequently, generates the density cube file with or without the core density and finally loads the density with cubetools.
- Parameters:
symm_symbols (List[str]) – Atom Type indicators for the evaluated atom(s)
symm_positions (np.ndarray) – atomic positions in fractional coordinates for the evaluated atom(s)
cell_mat_m (np.ndarray) – size (3, 3) array with the unit cell vectors as row vectors, only used if ibrav != 0
computation_dict (Dict[str, Any]) – Dictionary with the calculation options, see calc_f0j function for options
shape (Tuple[int]) – tuple containing the shape of the desired atomic density. This circumvents an inconsistency of QE on how large the densities arrays are depending on some parameters in the file.
- Returns:
atomic_density – Numpy array containing the atomic_density. The overall sum of the array is normalised to the number of electrons.
- Return type:
np.ndarray
- xharpy.f0j_sources.qe_source.qe_density(symm_symbols: List[str], symm_positions: ndarray, cell_mat_m: ndarray, computation_dict: Dict[str, Any], cwd='/home/docs/checkouts/readthedocs.org/user_builds/xharpy/checkouts/latest/docs/source') ndarray
Performs the wavefunction calculation with quantum espresso, generates the density cube file with or without the core density and finally loads the density with cubetools.
- Parameters:
symm_symbols (List[str]) – Atom Type indicators for the symmetry expanded atoms in the unit cell
symm_positions (np.ndarray) – atomic positions in fractional coordinates for the symmetry expanded atoms in the unit cell.
cell_mat_m (np.ndarray) – size (3, 3) array with the unit cell vectors as row vectors, only used if ibrav != 0
computation_dict (Dict[str, Any]) – Dictionary with the calculation options, see calc_f0j function for options
- Returns:
density – Numpy array containing the density. The overall sum of the array is normalised to the number of electrons.
- Return type:
np.ndarray
- xharpy.f0j_sources.qe_source.qe_entry_string(name: str, value: str | float | int | bool, string_sign: bool = True) str
Creates a formatted string for output in a quantum-espresso input file
- Parameters:
name (str) – Name of the option
value (Union[str, float, int, bool]) – The value of the option
string_sign (bool, optional) – If the value is a string this value determines, whether the entry, will have ‘’ as an indicator of the type, by default True
- Returns:
Formatted string
- Return type:
str
- Raises:
NotImplementedError – The type of value is currently not implemented
- xharpy.f0j_sources.qe_source.qe_pp_file(computation_dict: Dict[str, Any]) str
Creates an input file for pp.x
- Parameters:
computation_dict (Dict[Any]) – Dictionary with the calculation options, see calc_f0j function for options
- Returns:
pp_file_string – a pp.x input file as string
- Return type:
str
- xharpy.f0j_sources.qe_source.qe_pw_file(symm_symbols: List[str], symm_positions: ndarray, cell_mat_m: ndarray, computation_dict: Dict[str, Any]) str
Creates an input file for pw.x for the density calculation
- Parameters:
symm_symbols (List[str]) – Atom Type indicators for the symmetry expanded atoms in the unit cell
symm_positions (np.ndarray) – atomic positions in fractional coordinates for the symmetry expanded atoms in the unit cell.
cell_mat_m (np.ndarray) – size (3, 3) array with the unit cell vectors as row vectors, only used if ibrav != 0
computation_dict (Dict[str, Any]) – Dictionary with the calculation options, see calc_f0j function for options
- Returns:
pw_file_string – formatted output file as a string
- Return type:
str
- xharpy.f0j_sources.qe_source.read_xsf_density(filename: str) ndarray
Reads the density from an xsf file.
- Parameters:
filename (str) – Path to the xsf file
- Returns:
density – density as a numpy array. Will cut off the repeated points at the edges that are included in the file.
- Return type:
np.ndarray
- xharpy.f0j_sources.qe_source.single_core_function(atom_index, symm_atom_index, symm_mats_vecs, index_vec_h, computation_dict, symm_symbols, symm_positions, cell_mat_m, density, overall_hdensity)
xharpy.f0j_sources.real_spher_harm module
This module contains automatically generated values for the real spherical harmonics (ylm_func_dict), and their products (ylm_yl2m2_dict). May be used in a future implementation to expand even fever density onto the rectangular grid.
- xharpy.f0j_sources.real_spher_harm.get_multiplication_instructions(l1, m1, l2, m2)
- xharpy.f0j_sources.real_spher_harm.spherical_bessel(l, gr)
- xharpy.f0j_sources.real_spher_harm.spherical_harmonic(l, m, xyz)