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, additional_terms=[])
Sets up the model for a specific expansion order or list of terms.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
orders |
int
|
All terms are included in the expansion up to this order. |
required |
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:
Type | Description |
---|---|
NotImplementedError
|
Center needs to be given in dataframe. |
ValueError
|
Center is not unique. |
ValueError
|
Duplicate points in the dataset. |
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.
nablachem.space
nablachem.space.ApproximateCounter
nablachem.space.ApproximateCounter.score_database(search_space, natoms, sum_formulas, selection=None)
Implements the Kolmogorov-Smirnov statistic comparing the distribution of the database to the expected distribution.
The best score is 0, the worst is 1.
This does not test the distribution of molecules within a given sum formula.
nablachem.space.ExactCounter
nablachem.space.SearchSpace
nablachem.space.SearchSpace.covered_search_space(kind)
staticmethod
Returns the pre-defined chemical spaces from the original publication
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind |
str
|
Label, either A or B. |
required |
Returns:
Type | Description |
---|---|
SearchSpace
|
The chosen space. |
nablachem.space.SearchSpace.list_cases_bare(natoms, degree_sequences_only=False, pure_sequences_only=False)
Lists all possible stoichiometries for a given number of atoms.
If degree_sequences_only is set to True, only unique degree sequences are returned, i.e. the element names are not considered.
Optimized for performance, so yields tuples. Use list_cases() for a more user-friendly interface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
natoms |
int
|
Number of atoms in the molecule. |
required |
degree_sequences_only |
bool
|
Flag to switch to degree sequence enumeration, by default False |
False
|
pure_sequences_only |
bool
|
Skips sequences where atoms of one valence belong to more than one element label. Implies degree_sequences_only. |
False
|
Yields:
Type | Description |
---|---|
Iterator[tuple[str, int, int]] | Iterator[tuple[int, int]]
|
Either tuples of (element, valence, count) or (valence, count). Guaranteed to be sorted by (valence, count). |
nablachem.utils
nablachem.utils.integer_partition(total, maxelements)
Builds all integer partitions of total split into maxelements parts.