Computing λ-SOAP features

import chemfiles
import numpy as np
from metatensor import Labels

from featomic import LodeSphericalExpansion, SphericalExpansion
from featomic.clebsch_gordan import EquivariantPowerSpectrum

Let’s see how to compute the \(\lambda\)-SOAP descriptor using featomic.

First we can read the input systems using chemfiles. You can download the dataset for this example from our website.

with chemfiles.Trajectory("dataset.xyz") as trajectory:
    systems = [s for s in trajectory]

Featomic also handles systems read by ASE:

systems = ase.io.read("dataset.xyz", ":").

Next, define the hyperparameters for the spherical expansion:

HYPERPARAMETERS = {
    "cutoff": {
        "radius": 5.0,
        "smoothing": {"type": "ShiftedCosine", "width": 0.5},
    },
    "density": {
        "type": "Gaussian",
        "width": 0.3,
    },
    "basis": {
        "type": "TensorProduct",
        "max_angular": 2,
        "radial": {"type": "Gto", "max_radial": 2},
    },
}

Create the spherical expansion calculator. The SphericalExpansion class uses the hyperparameters above. Then, wrap it with EquivariantPowerSpectrum to compute the Clebsch-Gordan contraction for \(\lambda\)-SOAP.

Run the actual calculation

power_spectrum = calculator.compute(systems, neighbors_to_properties=True)

The result is a TensorMap whose keys encode symmetry:

metatensor.Labels

o3_lambdao3_sigmacenter_type
011
111
211
1-11
2-11
311
3-11
Show 25 more entries
411
016
116
216
1-16
2-16
316
3-16
416
017
117
217
1-17
2-17
317
3-17
417
018
118
218
1-18
2-18
318
3-18
418


Often, you only need specific \(\lambda\) values. For example, if the target property is the polarizability tensor, (a rank-2 symmetric Cartesian tensor), you can restrict the output to \(\lambda=0\) and \(\lambda=2\) (with \(\sigma=1\) to discard pseudotensors) using the selected_keys parameter:

power_spectrum_0_2 = calculator.compute(
    systems,
    neighbors_to_properties=True,
    selected_keys=Labels(["o3_lambda", "o3_sigma"], np.array([[0, 1], [2, 1]])),
)
power_spectrum_0_2.keys
metatensor.Labels

o3_lambdao3_sigmacenter_type
011
211
016
216
017
217
018
Show 1 more entries
218


You can also compute a \(\lambda\)-SOAP-like descriptor using two different expansions. For instance, combine a standarad spherical expansion with a long-range LodeSphericalExpansion:

LODE_HYPERPARAMETERS = {
    "density": {
        "type": "SmearedPowerLaw",
        "smearing": 0.3,
        "exponent": 1,
    },
    "basis": {
        "type": "TensorProduct",
        "max_angular": 2,
        "radial": {"type": "Gto", "max_radial": 3, "radius": 1.0},
    },
}
lode_calculator = LodeSphericalExpansion(**LODE_HYPERPARAMETERS)
calculator = EquivariantPowerSpectrum(spex_calculator, lode_calculator)
power_spectrum = calculator.compute(systems, neighbors_to_properties=True)
power_spectrum.keys
metatensor.Labels

o3_lambdao3_sigmacenter_type
011
111
211
1-11
2-11
311
3-11
Show 25 more entries
411
016
116
216
1-16
2-16
316
3-16
416
017
117
217
1-17
2-17
317
3-17
417
018
118
218
1-18
2-18
318
3-18
418


Gallery generated by Sphinx-Gallery