Quantum Alchemy
Obtaining derivatives
nablachem.alchemy.Anygrad(calculator, target: Anygrad.Property)
Calculates quantum chemical gradients including those w.r.t. nuclear charges analytically where possible.
Order: xyzZxyzZxyzZ... (in order of atoms)
nablachem.alchemy.Anygrad.Method
Bases: Enum
nablachem.alchemy.Anygrad.Method.COUPLED_PERTURBED = 'CP'
class-attribute
instance-attribute
nablachem.alchemy.Anygrad.Method.FINITE_DIFFERENCES = 'FD'
class-attribute
instance-attribute
nablachem.alchemy.Anygrad.Property
Bases: Enum
nablachem.alchemy.Anygrad.Property.ENERGY = 'energy'
class-attribute
instance-attribute
nablachem.alchemy.Anygrad.Property.HOMO = 'homo'
class-attribute
instance-attribute
nablachem.alchemy.Anygrad.Variable
Bases: Enum
nablachem.alchemy.Anygrad.Variable.NUCLEAR_CHARGE = 'Z'
class-attribute
instance-attribute
nablachem.alchemy.Anygrad.Variable.POSITION = 'R'
class-attribute
instance-attribute
nablachem.alchemy.Anygrad.get(*args: Anygrad.Variable, method: Anygrad.Method = None)
Building Taylor models
nablachem.alchemy.MultiTaylor(dataframe: pd.DataFrame, outputs: list[str])
Multi-dimensional multi-variate arbitrary order Taylor expansion from any evenly spaced finite difference stencil.
Examples
import pandas as pd df = pd.read_csv("some_file.csv") df.columns Index(['RX', 'RY', 'RZ', 'QX', 'QY', 'QZ', 'E', 'BETA1', 'BETA2', 'SIGMA'], dtype='object') mt = MultiTaylor(df, outputs="BETA1 BETA2 SIGMA".split()) spatial_center, electronic_center = 3, 2.5 mt.reset_center( RX=spatial_center, RY=spatial_center, RZ=spatial_center, QX=electronic_center, QY=electronic_center, QZ=electronic_center, ) mt.reset_filter(E=4) mt.build_model(2) mt.query(RX=3.1, RY=3.1, RZ=3.1, QX=2.4, QY=2.4, QZ=2.4) {'BETA1': 0.022412699999999976, 'BETA2': 0.014047600000000134, 'SIGMA': 0.0018744333333333316}
Initialize the Taylor expansion from a dataframe of data points forming the superset of stencils.
Parameters
dataframe : pd.DataFrame Holds all data points available for the vicinity of the future center of the expansion. outputs : list[str] Those columns of the dataframe that are considered to be outputs rather than input coordinates.
nablachem.alchemy.MultiTaylor.build_model(orders: int, additional_terms: list[tuple[str]] = [])
Sets up the model for a specific expansion order or list of terms.
Parameters
orders : int All terms are included in the expansion up to this order. additional_terms : list[tuple[str]] The terms to ADDITIONALLY include, i.e. list of tuples of column names.
To only include d/dx, give [('x',)]
To only include d^2/dx^2, give [('x', 'x')]
To only include d^2/dxdy, give [('x', 'y')]
To include all three, give [('x',), ('x', 'x'), ('x', 'y')]
Raises
NotImplementedError Center needs to be given in dataframe. ValueError Center is not unique. ValueError Duplicate points in the dataset. ValueError Invalid column names for additonal terms.
nablachem.alchemy.MultiTaylor.maximize(target: str, bounds: dict[str, tuple[float, float]]) -> dict[str, float]
See _optimize.
Parameters
target : str Column name to maximize. bounds : dict[str, tuple[float, float]] Bounds for the search space.
Returns
dict[str, float] Optimal position found.
nablachem.alchemy.MultiTaylor.minimize(target: str, bounds: dict[str, tuple[float, float]]) -> dict[str, float]
See _optimize.
Parameters
target : str Column name to minimize. bounds : dict[str, tuple[float, float]] Bounds for the search space.
Returns
dict[str, float] Optimal position found.
nablachem.alchemy.MultiTaylor.query(**kwargs: float) -> float
Evaluate the Taylor expansion at a given point.
Returns
float Value from all terms.
nablachem.alchemy.MultiTaylor.query_detail(output: str, **kwargs: float) -> dict[tuple[str, int], float]
Breaks down the Taylor expansion into its monomials.
Parameters
output : str The output variable for which this analysis is done.
Returns
dict[tuple[str, int], float] Keys are the variable names and the exponents, values are the contributions from each monomial.
nablachem.alchemy.MultiTaylor.reset_center(**kwargs: float)
Sets the expansion center from named arguments for each column.
nablachem.alchemy.MultiTaylor.reset_filter(**kwargs: float)
Sets the filter for the dataframe from named arguments for each column.
All columns which are not filtered and not outputs are considered to be input coordinates.
nablachem.alchemy.MultiTaylor.to_constant_grad_and_hess(output: str)
Exports the Taylor expansion for a given output as constant, gradient, and Hessian.
Parameters
output : str The output variable for which this analysis is done.
Returns
tuple[float, np.ndarray, np.ndarray, list[str]] Constant, gradient, Hessian, and ordered list of variable names.
nablachem.alchemy.Monomial(prefactor: float, powers: dict[str, int] = {})
A single monomial in the multi-dimensional Taylor expansion.
Define the monomial.
Parameters
prefactor : float Weight or coefficient of the monomial. powers : dict[str, int], optional Involved variables as keys and the exponent as value, by default {}.
nablachem.alchemy.Monomial.__repr__()
nablachem.alchemy.Monomial.distance(pos: dict[str, float], center: dict[str, float]) -> float
Evaluate the distance term of the Taylor expansion.
Parameters
pos : dict[str, float] The position at which the Monomial is evaluated. Keys are the variable names, values are the positions. center : dict[str, float] The center of the Taylor expansion. Keys are the variable names, values are the positions.
Returns
float Distance
nablachem.alchemy.Monomial.prefactor() -> float
Calculates the Taylor expansion prefactor.
Returns
float Prefactor for the summation in the Taylor expansion.