Skip to content

Code

nablachem.alchemy

nablachem.alchemy.Monomial

A single monomial in the multi-dimensional Taylor expansion.

nablachem.alchemy.Monomial.__init__(prefactor, powers={})

Define the monomial.

Parameters:

Name Type Description Default
prefactor float

Weight or coefficient of the monomial.

required
powers dict[str, int]

Involved variables as keys and the exponent as value, by default {}.

{}

nablachem.alchemy.Monomial.distance(pos, center)

Evaluate the distance term of the Taylor expansion.

Parameters:

Name Type Description Default
pos dict[str, float]

The position at which the Monomial is evaluated. Keys are the variable names, values are the positions.

required
center dict[str, float]

The center of the Taylor expansion. Keys are the variable names, values are the positions.

required

Returns:

Type Description
float

Distance

nablachem.alchemy.Monomial.prefactor()

Calculates the Taylor expansion prefactor.

Returns:

Type Description
float

Prefactor for the summation in the Taylor expansion.

nablachem.alchemy.MultiTaylor

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}

nablachem.alchemy.MultiTaylor.__init__(dataframe, outputs)

Initialize the Taylor expansion from a dataframe of data points forming the superset of stencils.

Parameters:

Name Type Description Default
dataframe DataFrame

Holds all data points available for the vicinity of the future center of the expansion.

required
outputs list[str]

Those columns of the dataframe that are considered to be outputs rather than input coordinates.

required

nablachem.alchemy.MultiTaylor.build_model(orders)

Sets up the model for a specific expansion order.

Parameters:

Name Type Description Default
orders Union[int, dict[int, list[str]]]

Either int, then all terms are included in the expansion up to this order. Otherwise, a dictionary with the order as key and a list of string-based terms as value.

required

Raises:

Type Description
NotImplementedError

Center needs to be given in dataframe.

ValueError

Center is not unique.

nablachem.alchemy.MultiTaylor.maximize(target, bounds)

See _optimize.

Parameters:

Name Type Description Default
target str

Column name to maximize.

required
bounds dict[str, tuple[float, float]]

Bounds for the search space.

required

Returns:

Type Description
dict[str, float]

Optimal position found.

nablachem.alchemy.MultiTaylor.minimize(target, bounds)

See _optimize.

Parameters:

Name Type Description Default
target str

Column name to minimize.

required
bounds dict[str, tuple[float, float]]

Bounds for the search space.

required

Returns:

Type Description
dict[str, float]

Optimal position found.

nablachem.alchemy.MultiTaylor.query(**kwargs)

Evaluate the Taylor expansion at a given point.

Returns:

Type Description
float

Value from all terms.

nablachem.alchemy.MultiTaylor.query_detail(output, **kwargs)

Breaks down the Taylor expansion into its monomials.

Parameters:

Name Type Description Default
output str

The output variable for which this analysis is done.

required

Returns:

Type 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)

Sets the expansion center from named arguments for each column.

nablachem.alchemy.MultiTaylor.reset_filter(**kwargs)

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.