basisopt.basis package
Submodules
basisopt.basis.atomic module
- class basisopt.basis.atomic.AtomicBasis(name: str = 'H', charge: int = 0, mult: int = 1)
Bases:
BasisObject for preparation and optimization of a basis set for a single atom.
- et_params
even tempered expansion parameters
- Type:
data.ETParams
- charge
net charge on atom
- Type:
int
- multiplicity
spin multiplicity of atom
- Type:
int
- config
configuration of basis, (k, v) pairs of form (angular momentum: no. of functions) e.g. ‘s’: 5, ‘p’: 4, etc.
- Type:
dict
- Special attribute:
- element: gets Mendeleev Element object of atom (_element)
set with atomic symbol
- Private Attributes:
_element (mendeleev Element): object set via element _molecule (Molecule): Molecule object rep of atom _done_setup (bool): flag for whether ready for optimize _symbol (str): atomic symbol in lowercase
- as_dict() dict[str, Any]
Returns MSONable dictionary of AtomicBasis
- as_xyz() str
Returns the atom as an xyz file string
- property charge: int
- property config: dict[str, int]
- configuration(quality: str = 'dz')
Sets the basis set configuration to a desired quality
- Parameters:
quality (str) – name of quality type, see zetatools for options
- contract()
Handles contraction of primitives
- property element: element
- classmethod from_dict(d: dict[str, Any]) object
Creates an AtomicBasis from MSONable dictionary
- minimal() dict[str, int]
Returns the minimal basis configuration for this atom
- property multiplicity: int
- optimize(algorithm: str = 'Nelder-Mead', params: dict[str, Any] = {}) dict[str, scipy.optimize._optimize.OptimizeResult]
Runs the basis optimization
- Parameters:
algorithm (str) – optimization algorithm to use, see scipy.optimize for options
params (dict) – dictionary of parameters to pass to the backend - see the relevant Wrapper object for options
- Returns:
a dictionary of scipy results from each opt step
- Return type:
opt_results (OptResult)
- save(filename: str)
Pickles the AtomicBasis object into a binary file
- set_even_tempered(method: str = 'hf', accuracy: float = 1e-05, max_n: int = 18, max_l: int = -1, exact_ref: bool = True, params: dict[str, Any] = {})
Looks up or computes an even tempered basis expansion for the atom
- Parameters:
method (str) – method to use; possibilities can be found through Wrapper object
accuracy (float) – the tolerance to optimize to, compared to reference value
max_n (int) – max number of primitives per shell
max_l (int) – angular momentum to go up to; if -1, will use max l in minimal config
exact_ref (bool) – uses exact numerical HF energy if True,
False (calculates cc-pV5Z reference value if) –
params (dict) – dictionary of parameters to pass to the backend -
options (see the relevant Wrapper object for) –
- Sets:
self.et_params
- setup(method: str = 'ccsd(t)', quality: str = 'dz', strategy: ~basisopt.opt.strategies.Strategy = <basisopt.opt.strategies.Strategy object>, reference: tuple[str, typing.Optional[dict[str, list[basisopt.containers.Shell]]]] = ('cc-pvqz', None), params: dict[str, typing.Any] = {})
Sets up the basis ready for optimization. Must be called before optimize is called
- Parameters:
method (str) – the method to use; available methods can be checked via the Wrapper object
quality (str) – configuration quality, see zetatools for options
strategy (Strategy) – the optimization strategy to use, e.g. EvenTemperedStrategy
reference (tuple) – the reference value for the objective being calculated, either as
(name (basis_name, None) –
OR (value)) –
BSE (requested basis from the) –
params (dict) – dictionary of parameters to pass to the backend - see the relevant Wrapper object for options
- Sets:
self.strategy (Strategy): optimization strategy self.config (Configuration): basis set configuration self._done_setup (bool): cannot call optimize until this flag is True
- basisopt.basis.atomic.needs_element(func: Callable) Callable
Decorator that checks if the AtomicBasis has an element attribute :raises ElementNotSet if no element found:
basisopt.basis.basis module
- class basisopt.basis.basis.Basis
Bases:
MSONableAbstract parent class object representing a basis type All basis types must inherit from here to work, see e.g. AtomicBasis, MolecularBasis
- results
a Result object where any results (e.g. calculations, optimizations, …)
- can be archived
- Private attributes:
_tests (list): a list of Test objects that can be run and collated together, with results going into the results attribute
- as_dict() dict[str, Any]
A JSON serializable dict representation of an object.
- copy() object
Returns a deepcopy of self
- classmethod from_dict(d: dict[str, Any]) object
- Parameters:
d – Dict representation.
- Returns:
MSONable class.
- get_basis() dict[str, list[basisopt.containers.Shell]]
- load(filename: str) object
Loads and returns a Basis object from a binary file pickle
- optimize(algorithm: str = 'Nelder-Mead', params: dict[str, Any] = {}) dict
All basis objects should implement an optimize method with this signature
- run_all_tests(params: dict[str, Any] = {})
Runs all the tests in basis, printing results
- run_test(name: str, params: dict[str, Any] = {})
Runs a test with the given name, printing result
- save(filename: str)
Pickles the Basis object into a binary file
- basisopt.basis.basis.even_temper_expansion(params: list[tuple[float, float, int]]) list[basisopt.containers.Shell]
Forms a basis for an element from even tempered expansion parameters
- Parameters:
params (list) – list of tuples corresponding to shells
[ (e.g.) –
* (is expanded as c_l) –
- Returns:
list of Shell objects for the expansion
- basisopt.basis.basis.fix_ratio(exps: ndarray, ratio: float = 1.4) ndarray
Returns a sorted numpy array of exponents where x_{i+1}/x_i >= ratio
- basisopt.basis.basis.uncontract(basis: dict[str, list[basisopt.containers.Shell]], elements: list[str] | None = None) dict[str, list[basisopt.containers.Shell]]
Uncontracts all shells in a basis for the elements specified (does not overwrite the old basis).
- Parameters:
basis (dict) – the basis dictionary to be uncontracted
elements (list) – list of atomic symbols
- Returns:
a new basis dictionary with uncontracted shells
basisopt.basis.guesses module
- basisopt.basis.guesses.bse_guess(atomic, params={'name': 'cc-pvdz'})
Takes guess from an existing basis on the BSE
- Params:
name (str): name of desired basis set
- basisopt.basis.guesses.even_tempered_guess(atomic, params={})
Takes guess from an even-tempered expansion
- Params:
see signature for AtomicBasis.set_even_tempered
- basisopt.basis.guesses.log_normal_guess(atomic, params={'mean': 0.0, 'sigma': 1.0})
Generates exponents randomly from a log-normal distribution
- Params:
mean: centre of the log-normal distribution sigma: standard deviation of log-normal distribution
- basisopt.basis.guesses.null_guess(atomic, params={})
Default guess type for testing, returns empty array
basisopt.basis.molecular module
- class basisopt.basis.molecular.MolecularBasis(name: str = 'Empty', molecules: list[basisopt.molecule.Molecule] = [])
Bases:
BasisObject for preparation and optimization of a basis set for multiple atoms across one or more Molecules.
- basis
internal basis used for all molecules
- Type:
dict
- Private Attributes:
_molecules (dict): dictionary of Molecule objects _atoms (set): unique atoms across all molecules _atomic_bases (dict): dictionary of AtomicBasis objects
for each atom in _atoms
_done_setup (bool): if True, setup has been called
- as_dict() dict[str, Any]
Returns as MSONable dictionary
- classmethod from_dict(d: dict[str, Any]) object
Creates a MolecularBasis from an MSONable dictionary
- get_atomic_basis(atom: str) AtomicBasis
Returns the AtomicBasis object for a given atom, if it exists, otherwise None
- get_basis() dict[str, list[basisopt.containers.Shell]]
Returns the basis set used for all molecules
- get_molecule(name: str) Molecule
Returns a Molecule with the given name, if it exists, otherwise None
- molecules() list[basisopt.molecule.Molecule]
Returns a list of all the Molecule objects
- optimize(algorithm: str = 'Nelder-Mead', params: dict[str, typing.Any] = {}, reg: ~typing.Callable[[~numpy.ndarray], float] = <function MolecularBasis.<lambda>>, npass: int = 1, parallel: bool = False) dict[str, dict[str, scipy.optimize._optimize.OptimizeResult]]
Calls collective optimize to optimize all the atomic basis sets in this basis
- Parameters:
algorithm (str) – name of scipy.optimize algorithm to use
params (dict) – parameters to pass to scipy.optimize
reg (callable) – regularization to use
npass (int) – number of optimization passes to do
parallel – if True, molecular calculations will be distributed in parallel
- run_all_tests(params: dict[str, Any] = {}, reference_basis: str | dict[str, list[basisopt.containers.Shell]] | None = None) None
Runs all of the tests across all molecules, and prints the results to logger
- Parameters:
params (dict) – paramerters to pass to the backend
reference_basis (str or dict) – either string name for basis to fetch from the BSE, or an internal basis dictionary, or None
- run_test(name: str, params: dict[str, Any] = {}, reference_basis: str | dict[str, list[basisopt.containers.Shell]] | None = None, do_print: bool = True) dict[str, Any]
Runs a single test with a given name across all molecules
- Parameters:
name (str) – name of the test
params (dict) – parameters for backend
reference_basis (str or dict) – either string name for basis to fetch from the BSE, or an internal basis dictionary, or None
do_print (bool) – if True, test results will be printed to Logger
- Returns:
Dicionary of results for each test, indexed by molecule name
- save(filename: str)
Pickles the MolecularBasis object into a binary file
- setup(method: str = 'ccsd(t)', quality: str = 'dz', strategy: ~basisopt.opt.strategies.Strategy = <basisopt.opt.strategies.Strategy object>, reference: str = 'cc-pvqz', params: dict[str, typing.Any] = {})
Sets up the basis ready for optimization by creating AtomicBasis objects for each unique atom in the set, and calling setup for those - see the signature of AtomicBasis.setup for explanation.
- unique_atoms() list[str]
Returns list of unique atoms across all molecules
basisopt.basis.zetatools module
- basisopt.basis.zetatools.add_np(config: dict[str, int], n: int) dict[str, int]
Helper function to add n polarization functions
- Parameters:
config – configuration dictionary to polarize
n (int) – no. of pol functions to add
- Returns:
a configuration dictionary
- basisopt.basis.zetatools.cc_pv5z(el)
- basisopt.basis.zetatools.cc_pvdz(el)
- basisopt.basis.zetatools.cc_pvqz(el)
- basisopt.basis.zetatools.cc_pvtz(el)
- basisopt.basis.zetatools.compare(c1: dict[str, int], c2: dict[str, int]) int
Compares two configuration dictionaries
- Returns:
< 0 if c1 is bigger than c2 0 if they’re equivalent sizes > 0 if c2 is bigger than c1
- basisopt.basis.zetatools.config_to_string(conf: dict[str, int]) str
Converts a configuration dictionary into a string, e.g. ‘4s3p2d1f’
- basisopt.basis.zetatools.dz(el)
- basisopt.basis.zetatools.dzp(el)
- basisopt.basis.zetatools.dzpp(el)
- basisopt.basis.zetatools.enum_shells(conf: ElectronicConfiguration) dict[str, int]
Enumerates the number of functions of each angular momentum
- Parameters:
conf – an ElectronConfig object from mendeleev
- Returns:
a configuration dictionary
- basisopt.basis.zetatools.get_next_l(l_list: list[str]) str
Given a list of existing angular momenta, gives the angular momentum symbol one higher.
- Parameters:
l_list (list) – (non-unique) list of angular momenta [‘s’, ‘p’, etc]
- Returns:
angular momentum symbol one higher than max in l_list
- basisopt.basis.zetatools.minimal(el)
- basisopt.basis.zetatools.n5z(el)
- basisopt.basis.zetatools.n_cartesian(config: dict[str, int]) int
Returns number of Cartesian Gaussians in configuration
- basisopt.basis.zetatools.n_spherical(config: dict[str, int]) int
Returns number of spherical Gaussians in configuration
- basisopt.basis.zetatools.nz(el: element, n: int) dict[str, int]
Helper function to generate n-zeta split valence configs
- Parameters:
el (Mendeleev element) –
n (int) – split valence level, e.g. DZ=2, TZ=3, etc.
- Returns:
a config dictionary
- basisopt.basis.zetatools.qz(el)
- basisopt.basis.zetatools.qzp(el)
- basisopt.basis.zetatools.qzpp(el)
- basisopt.basis.zetatools.register_quality(func: Callable[[element], dict[str, int]]) Callable[[element], dict[str, int]]
Decorator to make a quality function available
- basisopt.basis.zetatools.string_to_config(string: str) dict[str, int]
converts a configuration string, e.g. ‘4s3p2d1f’, to a Configuration dictionary
- basisopt.basis.zetatools.tz(el)
- basisopt.basis.zetatools.tzp(el)
- basisopt.basis.zetatools.tzpp(el)