Loading...
Searching...
No Matches
gpr::FeatomicEnvironmentDescriptor Class Reference

#include <gpr/covariance_functions/FeatomicEnvironmentDescriptor.h>

Public Member Functions

 FeatomicEnvironmentDescriptor (std::vector< int > atomic_numbers, double cutoff=4.0, const Eigen::Matrix3d &cell=Eigen::Matrix3d::Zero(), std::array< bool, 3 > periodic={false, false, false})
AtomicEnvironments operator() (const Eigen::VectorXd &positions, bool gradients=true) const
SupportedAtomicEnvironments supported (const Eigen::VectorXd &positions, bool gradients=true) const

Static Public Member Functions

static SpeciesEnvironmentKernel::Descriptor forConfiguration (const AtomsConfiguration &configuration, double cutoff=4.0, bool gradients=true)
static SpeciesEnvironmentKernel::SupportedDescriptor forConfigurationSupported (const AtomsConfiguration &configuration, double cutoff=4.0, bool gradients=true)

Detailed Description

Normalized, species-resolved SOAP and its Cartesian position derivatives. The element vocabulary is fixed for the lifetime of the descriptor, so crossing a neighbor cutoff cannot change the covariance feature layout.

Definition at line 33 of file FeatomicEnvironmentDescriptor.h.

Constructor & Destructor Documentation

◆ FeatomicEnvironmentDescriptor()

gpr::FeatomicEnvironmentDescriptor::FeatomicEnvironmentDescriptor ( std::vector< int > atomic_numbers,
double cutoff = 4.0,
const Eigen::Matrix3d & cell = Eigen::Matrix3d::Zero(),
std::array< bool, 3 > periodic = {false, false, false} )
inline

Definition at line 35 of file FeatomicEnvironmentDescriptor.h.

38 {false, false, false})
39 : atomic_numbers_(std::move(atomic_numbers)),
40 cell_(cell),
41 periodic_(periodic),
42 calculator_("soap_power_spectrum", parameters(cutoff)),
43 keys_(makeKeys(atomic_numbers_))
44 {
45 if (!cell_.allFinite())
46 throw std::invalid_argument("SOAP cell must be finite");
47 }

Member Function Documentation

◆ forConfiguration()

SpeciesEnvironmentKernel::Descriptor gpr::FeatomicEnvironmentDescriptor::forConfiguration ( const AtomsConfiguration & configuration,
double cutoff = 4.0,
bool gradients = true )
inlinestatic

Keep frozen environments in the energy sum while differentiating only the moving Cartesian coordinates supplied by the GP. With gradients disabled, values and species retain their layout and jacobians is empty.

Definition at line 52 of file FeatomicEnvironmentDescriptor.h.

55 {
56 auto supported =
57 forConfigurationSupported(configuration, cutoff, gradients);
58 return [supported =
59 std::move(supported)](const Eigen::VectorXd& positions) {
60 return denseEnvironments(supported(positions));
61 };
62 }
SupportedAtomicEnvironments supported(const Eigen::VectorXd &positions, bool gradients=true) const
static SpeciesEnvironmentKernel::SupportedDescriptor forConfigurationSupported(const AtomsConfiguration &configuration, double cutoff=4.0, bool gradients=true)

◆ forConfigurationSupported()

SpeciesEnvironmentKernel::SupportedDescriptor gpr::FeatomicEnvironmentDescriptor::forConfigurationSupported ( const AtomsConfiguration & configuration,
double cutoff = 4.0,
bool gradients = true )
inlinestatic

Cartesian derivatives retain their original moving-coordinate indices without allocating absent rows for each atomic environment.

Definition at line 67 of file FeatomicEnvironmentDescriptor.h.

69 {
70 const Eigen::Index atoms = configuration.atomicNrs.size();
71 const bool all_moving = configuration.atoms_mov.type.size() == atoms &&
72 configuration.is_frozen.size() == 0;
73 if (atoms == 0 ||
74 (!all_moving && (configuration.positions.size() != 3 * atoms ||
75 configuration.is_frozen.size() != atoms)))
76 throw std::invalid_argument(
77 "SOAP requires atomic numbers and frozen-atom flags");
78 std::vector<int> numbers(atoms);
79 std::vector<Eigen::Index> moving;
80 for (Eigen::Index atom = 0; atom < atoms; ++atom) {
81 numbers[atom] = configuration.atomicNrs.data()[atom];
82 if (all_moving ||
83 configuration.is_frozen.data()[atom] == MOVING_ATOM)
84 moving.push_back(atom);
85 }
86 if (moving.empty() ||
87 moving.size() != configuration.atoms_mov.type.size())
88 throw std::invalid_argument(
89 "SOAP moving-atom order does not match the GP");
90 Eigen::Matrix3d cell = Eigen::Matrix3d::Zero();
91 std::array<bool, 3> periodic{false, false, false};
92 if (geometry::cellIsMicLattice(configuration.cell)) {
93 for (int axis = 0; axis < 3; ++axis) {
94 for (int other = 0; other < 3; ++other)
95 cell(axis, other) = configuration.cell[3 * axis + other];
96 periodic[axis] = cell.row(axis).squaredNorm() > 0.0;
97 }
98 }
99 auto descriptor = std::make_shared<FeatomicEnvironmentDescriptor>(
100 std::move(numbers), cutoff, cell, periodic);
101 Eigen::VectorXd fixed = Eigen::VectorXd::Zero(3 * atoms);
102 if (configuration.positions.size() == 3 * atoms)
103 fixed = Eigen::Map<const Eigen::VectorXd>(
104 configuration.positions.data(), configuration.positions.size());
105 return [descriptor, moving = std::move(moving), fixed,
106 gradients](const Eigen::VectorXd& positions) {
107 if (positions.size() !=
108 3 * static_cast<Eigen::Index>(moving.size()))
109 throw std::invalid_argument(
110 "SOAP query has incompatible Cartesian dimensions");
111 Eigen::VectorXd all = fixed;
112 for (std::size_t atom = 0; atom < moving.size(); ++atom)
113 all.segment<3>(3 * moving[atom]) =
114 positions.segment<3>(3 * atom);
115 return descriptor->evaluate(all, moving, gradients);
116 };
117 }
@ MOVING_ATOM
Definition Enums.h:35
bool cellIsMicLattice(const double cell[9]) noexcept
Nonzero ASE 3x3 that is not the 25 A vacuum convention.
Definition MinImage.h:56

◆ operator()()

AtomicEnvironments gpr::FeatomicEnvironmentDescriptor::operator() ( const Eigen::VectorXd & positions,
bool gradients = true ) const
inlinenodiscard

Disabling gradients computes the same normalized features without requesting position derivatives or allocating Jacobian blocks.

Definition at line 121 of file FeatomicEnvironmentDescriptor.h.

123 {
124 return denseEnvironments(supported(positions, gradients));
125 }

◆ supported()

SupportedAtomicEnvironments gpr::FeatomicEnvironmentDescriptor::supported ( const Eigen::VectorXd & positions,
bool gradients = true ) const
inlinenodiscard

Definition at line 127 of file FeatomicEnvironmentDescriptor.h.

129 {
130 std::vector<Eigen::Index> atoms;
131 if (gradients) {
132 atoms.resize(atomic_numbers_.size());
133 std::iota(atoms.begin(), atoms.end(), Eigen::Index{0});
134 }
135 return evaluate(positions, atoms, gradients);
136 }

The documentation for this class was generated from the following file: