basisopt.testing package
Submodules
basisopt.testing.dunham module
- class basisopt.testing.dunham.DunhamTest(name: str, mol: Molecule | None = None, mol_str: str = '', charge: int = 0, mult: int = 1, poly_order: int = 6, step: float = 0.05, Emax: float = 0)
Bases:
TestCarries out a Dunham analysis on a diatomic, calculating spectroscopic constants Initialised with either a diatomic Molecule object, or a mol_string of the form “Atom1Atom2,separation in Ang”, e.g. “H2,0.9”, “NO,1.2”, “LiH,1.3” etc.
- Results:
returned as numpy array, as well as archived Ee: Energy at eq. separation (Ha) Re: Eq. separation (Ang) BRot, ARot: First and second rotational constants (cm-1) We: First vibrational constant (cm-1) Wx, Wy: x and y anharmonic corrections to We (cm-1) De: Dissociation energy (eV) D0: Zero-point dissociation energy (eV)
- Additional data stored:
StencilRi (numpy array): the separation values (Ang) used in the polynomial fit StencilEi (numpy array): the energy values (Ha) at each point in the fit
- Additional attributes:
poly_order (int): order of polynomial to fit, >= 3 step (float): step size in Angstrom to use for polynomial fit Emax (float): energy in Ha to calculate dissociation from (default 0) poly (poly1d): fitted polynomial shift (float): the shift for separations used in the polynomial fit e.g. to calculate the value at the point R, use poly(R-shift)
- as_dict()
Converts Result (and all children) to an MSONable dictionary
- calculate(method: str, basis: dict[str, list[basisopt.containers.Shell]], params: dict[str, Any] = {}) ndarray
Calculates the Dunham analysis results
- Parameters:
method (str) – calculation method to use
basis (InternalBasis) – orbital basis set
params (dict) – parameters to pass to backend
- Returns:
array of results in order specified by _VALUE_NAMES
- classmethod from_dict(d)
Creates Result from dictionary representation, including recursive creation of children.
- from_string(mol_str: str, charge: int = 0, mult: int = 1)
Makes a diatomic molecule from string to use in test
- Parameters:
mol_str (str) – string of diatomic and separation in Angstrom e.g. “NO,1.3”, “H2,0.9”, “LiH,1.1” etc
charge (int) – overall charge of diatomic
mult (int) – spin multipilicity of diatomic
- reduced_mass() float
Calculate the reduced mass of the diatomic
- basisopt.testing.dunham.dunham(energies: ndarray, distances: ndarray, mu: float, poly_order: int = 6, angstrom: bool = True, Emax: float = 0) tuple[numpy.poly1d, float, numpy.ndarray]
Performs a Dunham analysis on a diatomic, given energy/distance values around a minimum and the reduced mass mu
basisopt.testing.rank module
- basisopt.testing.rank.rank_primitives(atomic: AtomicBasis, shells: list[int] | None = None, eval_type: str = 'energy', basis_type: str = 'orbital', params={}) tuple[list[numpy.ndarray], list[numpy.ndarray]]
Systematically eliminates exponents from shells in an AtomicBasis to determine how much they contribute to the target property
- Parameters:
atomic – AtomicBasis object
shells (list) – list of indices for shells in the AtomicBasis to be ranked. If None, will rank all shells
eval_type (str) – property to evaluate (e.g. energy)
basis_type (str) – “orbital/jfit/jkfit”
params (dict) – parameters to pass to the backend, see relevant Wrapper for options
- Returns:
(errors, ranks), where errors is a list of numpy arrays with the change in target property value for each exponent in the shell, and ranks is a list of numpy arrays which contain the indices of each exponent in each shell from smallest to largest error value. Order of errors, ranks is same as order of shells
- Raises:
- basisopt.testing.rank.reduce_primitives(atomic: AtomicBasis, thresh: float = 0.0001, shells: list[int] | None = None, eval_type: str = 'energy', params: dict[str, Any] = {}) tuple[dict[str, list[basisopt.containers.Shell]], Any]
Rank the primitive functions in an atomic basis, and remove those that contribute less than a threshold. TODO: add checking that does not go below minimal config
- Parameters:
atomic – AtomicBasis object
thresh (float) – if a primitive’s contribution to the target is < thresh,
basis (it is removed from the) –
shells (list) – list of indices of shells to be pruned; if None, does all shells
eval_type (str) – property to evaluate
params (dict) – parameters to pass to the backend
- Returns:
(basis, delta) where basis is the pruned basis set (this is non-destructive to the original AtomicBasis), and delta is the change in target property with the pruned basis compared to the original
- Raises:
basisopt.testing.test module
- class basisopt.testing.test.PropertyTest(name: str, prop: str = 'energy', mol: Molecule | None = None, xyz_file: str | None = None, charge: int = 0, mult: int = 1)
Bases:
TestSimplest implementation of Test, calculating some property, e.g. energy
- Additional attributes:
eval_type (str): property to evaluate, e.g. ‘energy’, ‘dipole’
- as_dict()
Converts Result (and all children) to an MSONable dictionary
- calculate(method: str, basis: dict[str, list[basisopt.containers.Shell]], params: dict[str, Any] = {}) Any
Calculates the test value
- Parameters:
method (str) – the method to use, e.g. ‘scf’
basis (dict) – internal basis object
params (dict) – parameters to pass to backend
- Returns:
the value from the calculation
- property eval_type: str
- classmethod from_dict(d)
Creates Result from dictionary representation, including recursive creation of children.
- class basisopt.testing.test.Test(name: str, reference: Any | None = None, mol: Molecule | None = None, xyz_file: str | None = None, charge: int = 0, mult: int = 1)
Bases:
ResultAbstract Test class, a type of Result, for a way of testing a basis set. see e.g. PropertyTest and DunhamTest
- reference
reference value of some kind to compare test result to
- Type:
var
- molecule
Molecule object to perform test with
- Must implement in children:
calculate(self, method, basis, params={})
- as_dict()
Converts Result (and all children) to an MSONable dictionary
- calculate(method: str, basis: dict[str, list[basisopt.containers.Shell]], params: dict[str, Any] = {})
Interface to run the test. Should archive and return the results of the test.
- method
method to run, e.g. ‘rhf’, ‘mp2’
- Type:
str
- basis
internal basis dictionary
- params
parameters to pass to the backend Wrapper
- Type:
dict
- calculate_reference(method: str, basis: dict[str, list[basisopt.containers.Shell]] | None = None, basis_name: str = 'cc-pvqz', params: dict[str, Any] = {})
Calculates reference value for the test, should not need to be overridden
- method
method to run, e.g. ‘rhf’, ‘mp2’
- Type:
str
- basis
internal basis dictionary
- basis_name
calculate using basis with this name from BSE, if basis is None
- Type:
str
- params
parameters to pass to the backend Wrapper
- Type:
dict
- classmethod from_dict(d)
Creates Result from dictionary representation, including recursive creation of children.
- set_molecule_from_xyz(xyz: str, charge: int = 0, mult: int = 1)
Creates Molecule from xyz file
- Parameters:
xyz (str) – the xyz file
charge (int), mult (int) – the charge and multiplicity of the molecule