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.get(*args: Anygrad.Variable, method: Anygrad.Method = None)
nablachem.alchemy.Anygrad.print_supported_methods_tables()
staticmethod
Prints markdown tables showing supported methods for each property.
nablachem.alchemy.Anygrad.supported_methods() -> dict
staticmethod
Returns all supported combinations of properties, derivatives, level of theory, and methods.
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Nested dictionary with structure: {property: {derivative_kind: {leveloftheory: [methods]}}} |
nablachem.alchemy.Anygrad.Property
Bases: Enum
Quantum chemical observable to differentiate.
nablachem.alchemy.Anygrad.Variable
Bases: Enum
Variable with respect to which the derivative is taken.
nablachem.alchemy.Anygrad.Method
Bases: Enum
Numerical strategy used to obtain a derivative.
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.
| PARAMETER | DESCRIPTION |
|---|---|
dataframe
|
Holds all data points available for the vicinity of the future center of the expansion.
TYPE:
|
outputs
|
Those columns of the dataframe that are considered to be outputs rather than input coordinates.
TYPE:
|
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.
| PARAMETER | DESCRIPTION |
|---|---|
orders
|
All terms are included in the expansion up to this order.
TYPE:
|
additional_terms
|
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')].
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
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.
| PARAMETER | DESCRIPTION |
|---|---|
target
|
Column name to maximize.
TYPE:
|
bounds
|
Bounds for the search space.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, float]
|
Optimal position found. |
nablachem.alchemy.MultiTaylor.minimize(target: str, bounds: dict[str, tuple[float, float]]) -> dict[str, float]
See _optimize.
| PARAMETER | DESCRIPTION |
|---|---|
target
|
Column name to minimize.
TYPE:
|
bounds
|
Bounds for the search space.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, float]
|
Optimal position found. |
nablachem.alchemy.MultiTaylor.query(**kwargs: float) -> float
Evaluate the Taylor expansion at a given point.
| RETURNS | DESCRIPTION |
|---|---|
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.
| PARAMETER | DESCRIPTION |
|---|---|
output
|
The output variable for which this analysis is done.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
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) -> tuple[float, np.ndarray, np.ndarray, list[str]]
Exports the Taylor expansion for a given output as constant, gradient, and Hessian.
| PARAMETER | DESCRIPTION |
|---|---|
output
|
The output variable for which this analysis is done.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[float, ndarray, 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.
| PARAMETER | DESCRIPTION |
|---|---|
prefactor
|
Weight or coefficient of the monomial.
TYPE:
|
powers
|
Involved variables as keys and the exponent as value, by default {}.
TYPE:
|
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.
| PARAMETER | DESCRIPTION |
|---|---|
pos
|
The position at which the Monomial is evaluated. Keys are the variable names, values are the positions.
TYPE:
|
center
|
The center of the Taylor expansion. Keys are the variable names, values are the positions.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Distance. |
nablachem.alchemy.Monomial.prefactor() -> float
Calculates the Taylor expansion prefactor.
| RETURNS | DESCRIPTION |
|---|---|
float
|
Prefactor for the summation in the Taylor expansion. |