molecules
Utilities for working with molecules.
Support for xyz, sdf, chk files and numpy arrays.
- build_mol_with_even_tempered_basis(mol: Mole, beta: float = 2.5, spin: int | None = 0) Mole[source]
Builds the even-tempered basis set for the given molecule.
Builds the even-tempered basis set with a factor of \(\beta\) (defaults to 2.5) in the exponent to approximate products of the basis functions given by the mole object. This is normally used to build an auxiliary basis to approximate the four-indices Coulomb tensor with a two-indices tensor. Dimensionalities agree with those reported in [M-OFDFT], but we have no way of comparing the exact coefficients.
for atm in ["H", "C", "N", "O", "F"]: mol = gto.M(atom=f"{atm} 0 0 0; {atm} 0 0 0", basis="6-31G(2df,p)") mol_etb = build_even_tempered_basis(mol) print_basis(mol_etb)
H: 6s 3p 1d C: 11s 8p 7d 3f 2g N: 11s 8p 7d 4f 2g O: 11s 8p 7d 4f 2g F: 11s 8p 7d 4f 2g
- Parameters:
mol – The molecule for which the basis set should be built. It contains information about the geometry and the atomic basis set.
beta – The exponent factor \(\beta\) of the even-tempered basis set. Should be larger than 1, defaults to 2.5.
spin – The spin of the molecule. Defaults to 0.
- Returns:
The molecule with the new even-tempered basis set.
- build_molecule_np(charges: ndarray, positions: ndarray, basis: str | dict | None = '6-31G(2df,p)', unit: str = 'Bohr', output: str | None = None, spin: int | None = None) Mole[source]
Given the charges and positions in arrays, build a molecule object using pyscf.
- Parameters:
charges – Array of atomic numbers (A).
positions – Array of atomic positions (A, 3).
basis – Basis set to use for the molecule.
unit – Unit of the positions.
output – Optional output file name.
spin – Optional spin of the molecule. Defaults to None.
- Returns:
A pyscf molecule object.
- Return type:
gto.Mole
- build_molecule_ofdata(ofdata: OFData, basis: dict | str = None, spin: int | None = None) Mole[source]
Convert the data to a pyscf Mole object.
- Parameters:
ofdata – The data to convert.
basis – The basis set to use for the molecule.
spin – The spin of the molecule. Defaults to None.
- Returns:
A pyscf molecule object.
- Return type:
gto.Mole
Note
The basis set can not be inferred from an OFData object alone. If a specific one is required a
BasisInfoobject should be given or the basis should later be set manually.
- check_atom_types(mol: Mole, atom_types: ndarray) None[source]
Check if all atoms in the molecule are of a certain type.
- Parameters:
mol – The molecule.
atom_types – The atom types to check for.
- Raises:
AssertionError – If an atom in the molecule is not of the specified type.
- chem_formula_from_atomic_numbers(atomic_numbers: ndarray)[source]
Returns the chemical formular of a molecule, given the atomic numbers.
for example: “H_6 C_2 O_1 “ for Ethanol
- construct_aux_mol(mol: Mole, aux_basis_name: str = 'even_tempered_2.5', unit='Bohr', spin=None) Mole[source]
Constructs an auxiliary molecule in the basis specified by aux_basis_name.
Possible options for aux_basis_name are: f”even_tempered_{beta}” f”even_tempered_{beta}_from_{basis_name}” f”{basis_name}” :param mol: The molecule for which the auxiliary molecule should be constructed. :param aux_basis_name: The name of the auxiliary basis to construct. :param unit: The unit of the coordinates. :param spin: The spin of the molecule. Defaults to None.
Note
The second option f”even_tempered_{beta}_from_{basis_name}” effects the minimal and maximal exponents of the basis set, the density of the basis function between them doesn’t change.
- construct_coeffs(coeffs_dict: Dict[str, ndarray], coeffs_index_dict: Dict[str, ndarray])[source]
Reads out coeffs_dict and coeffs_index_dict to construct a list of coeffs for each shell.
The coeffs are represented in a block diagonal fashion, where each block corresponds to a contrachted basis function. This was implemented to simplify the use of differentiable integrals. :param coeffs_dict: A dictionary containing a flatted 1d array of the coefficients of the basis functions each atom type contains. :param coeffs_index_dict: A dictionary containing a 2d array providing information about how the coefficients of coeffs_dict are grouped into different shells.
- Returns:
A dictionary containing the coefficients of the basis functions each atom type contains in a block diagonal format.
- Return type:
res_dict
- dict_to_pyscf_dict(angmon_dict: Dict[str, ndarray], coeffs_dict: Dict[str, ndarray], exps_dict: Dict[str, ndarray], exps_index_dict: Dict[str, ndarray], coeffs_index_dict: Dict[str, ndarray]) Dict[str, List[Tuple[int, Tuple[float, float]]]][source]
Translates the basis set from a dictionary format used to store then to a format that can be used by pyscf.
- Parameters:
angmon_dict – A dictionary containing a 1d array of the different angular momentum of the basis functions each atom type contains.
coeffs_dict – A dictionary containing a flatted 1d array of the coefficients of the basis functions each atom type contains.
exps_dict – A dictionary containing a flatted 1d array of the exponents of the basis functions each atom type contains.
exps_index_dict – A dictionary containing a 2d array providing information about how the exponents of exps_dict are grouped into different shells.
coeffs_index_dict – A dictionary containing a 2d array providing information about how the coefficients of coeffs_dict are grouped into different shells.
- Returns:
A dictionary containing the basis set in a format that can be used by
- Return type:
pyscf_dict
- geometry_to_string(mol: Mole, unit: str = 'Angstrom')[source]
Convert the geometry of a molecule to a string.
- Parameters:
mol – The molecule.
unit – The unit of the coordinates.
- Returns:
The geometry as a string.
- load_basis_from_zarr(zarr_path: Path, atomic_numbers) Dict[str, ndarray][source]
Load the basis set from a zarr file.
The basis set is represented using 5 different dictionaries, containing numpy arrays for each different atom type. :param zarr_path: Path to the zarr file. :param atomic_numbers: The atomic numbers of the atoms in the molecule.
- Returns:
A dictionary containing a 1d array of the different angular momentum of the basis functions each atom type contains. coeffs_dict: A dictionary containing a flatted 1d array of the coefficients of the basis functions each atom type contains. exps_dict: A dictionary containing a flatted 1d array of the exponents of the basis functions each atom type contains. exps_index_dict: A dictionary containing a 2d array providing information about how the exponents of exps_dict are grouped into different shells. coeffs_index_dict: A dictionary containing a 2d array providing information about how the coefficients of coeffs_dict are grouped into different shells.
- Return type:
angmon_dict
- load_charges_and_positions_sdf(path: Path) tuple[ndarray, ndarray][source]
Given the path to a .sdf file, build return charges and positions in arrays.
- Parameters:
path – Path to the .sdf file.
- Returns:
Array of atomic numbers (A). np.ndarray: Array of atomic positions (A, 3).
- Return type:
np.ndarray
- Raises:
AssertionError – If the .sdf file contains more than one molecule.
- load_scf(chk_file: Path) Tuple[dict, dict, list[dict]][source]
Load the data of a specific iteration from the chk file.
- Parameters:
chk_file – Path to the chk file.
- Returns:
The pyscf object containing the final result of the calculation. dict: The density matrix and energy of the first iteration. list: A list of dictionaries containing the data of each iteration.
- Return type:
dict