class aux::Distance¶
Overview¶
Methods to calculate distances between atoms. More…
#include <Distance.h>
class Distance {
public:
// construction
Distance();
virtual ~Distance();
// methods
void dist_max1Dlog(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info, gpr::FieldMatrixd& dist);
void dist_rmsd(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info, gpr::FieldMatrixd& dist);
void dist_at(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info, const gpr::FieldMatrixd& lengthscale, gpr::FieldMatrixd& dist);
void dist_at_vec(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info, const gpr::FieldMatrixd& lengthscale, std::vector<gpr::FieldMatrixd>& dist);
void mindist_interatomic(const gpr::Coord& x, const gpr::AtomsConfiguration& conf_info, gpr::FieldMatrixd& dist);
void dist_emd(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info, gpr::FieldMatrixd& dist);
void cacheInverseDistances(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info);
void dist_at_cached(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info, const gpr::FieldMatrixd& lengthscale, gpr::FieldMatrixd& dist);
void dist_at_cached_sq(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info, const gpr::FieldMatrixd& lengthscale, gpr::FieldMatrixd& dist_sq);
bool hasCachedDistances() const;
void clearCache();
};
Detailed Documentation¶
Methods to calculate distances between atoms.
Methods¶
void dist_max1Dlog(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info, gpr::FieldMatrixd& dist)
Give the maximum difference in the logarithmic inter-atomic distances between atomic configurations C and C’.
dist(C,C’) = MAX_ij{|log(r_ij')-log(r_ij)|} = MAX_ij{|log(r_ij'/r_ij)|}, where r_ij and r_ij’ are the distances between atoms i and j in configurations C and C’, respectively.
The input vectors x1 and x2 are assumed to be row vectors including the gpr::Coordinates of the moving atoms: [x_1,y_1,z_1,x_2,y_2,z_2,…].
Parameters:
x1 |
gpr::Coordinates of the moving atoms in configurations C (n1 x 3*N_mov) |
x2 |
gpr::Coordinates of the moving atoms in configurations C’ (n2 x 3*N_mov) |
conf_info |
Structure array including information about the configurations necessary for the GP model
|
dist |
Matrix including the “distances” from configurations C to configurations C’ (n1 x n2) |
void dist_rmsd(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info, gpr::FieldMatrixd& dist)
Calculates the aligned Root Mean Square Deviation (RMSD) between sets of configurations.
void dist_at(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info, const gpr::FieldMatrixd& lengthscale, gpr::FieldMatrixd& dist)
Give the distance between two atomic configurations as defined in the special GPstuff covariance function ‘gpcf_matern32at’.
The distance between configurations C and C’ is based on the changes of the inter-atomic distances:
dist(C,C’) = sqrt(SUM_ij{[(1/r_ij-1/r_ij’)/l_ij]^2}), where r_ij and r_ij’ are the distances between atoms i and j in configurations C and C’, respectively, and l_ij is the lengthscale of the corresponding atom pair type.
The input vectors x1 and x2 are assumed to be row vectors including the gpr::Coordinates of the moving atoms: [x_1,y_1,z_1,x_2,y_2,z_2,…].
The parameter ‘conf_info’ is a structure array including necessary information about the configurations: conf_info.conf_fro: gpr::Coordinates of active frozen atoms (N_fro x 3) conf_info.atomtype_mov: atomtype indices for moving atoms (1 x N_mov) conf_info.atomtype_fro: atomtype indices for active frozen atoms (1 x N_fro) Atomtypes must be indexed as 1,2,…,n_at (may include also inactive atomtypes). conf_info.pairtype: pairtype indices for pairs of atomtypes (n_at x n_at) conf_info.n_pt: number of active pairtypes Active pairtypes are indexed as 0,1,2,…,n_pt-1. Inactive pairtypes are given index -1.
Note
x2-dependent inverse distances are pre-computed before the x1 loop to avoid redundant coordinate extractions. Frozen atom positions are cached outside the (n, m) inner loops. The final element-wise sqrt uses a vectorised Eigen ArrayXd map.
Parameters:
x1 |
gpr::Coordinates of the moving atoms in configurations C (n1 x 3*N_mov) |
x2 |
gpr::Coordinates of the moving atoms in configurations C’ (n2 x 3*N_mov) |
conf_info |
structure array including information about the configurations necessary for the GP model |
lengthscale |
lengthscales for different atom pair types (1 x n_pt) |
dist |
matrix including the distances between configurations C and C’ (n1 x n2) |
void dist_at_vec(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info, const gpr::FieldMatrixd& lengthscale, std::vector<gpr::FieldMatrixd>& dist)
Similar to dist_at but calculates vector of distances for every pair of moving and frozen atoms.
Note
Same pre-computation optimisations as dist_at: x2 inverse distances are computed once per atom pair, frozen positions are cached outside inner loops.
Parameters:
x1 |
|
x2 |
|
conf_info |
|
lengthscale |
|
dist |
void mindist_interatomic(const gpr::Coord& x, const gpr::AtomsConfiguration& conf_info, gpr::FieldMatrixd& dist)
Give the distance from each moving atom to its nearest neighbour atom in configuration C.
The input vectors in x are assumed to be row vectors including the gpr::Coordinates of the moving atoms: [x_1,y_1,z_1,x_2,y_2,z_2,…].
Parameters:
x |
gpr::Coordinates of the moving atoms in configurations C (n x 3*N_mov) |
conf_info |
structure array including information about the configurations necessary for the GP model
|
dist |
matrix including the minimum interatomic distances for each moving atom in configurations C (n x N_mov) |
void dist_emd(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info, gpr::FieldMatrixd& dist)
Calculates the Earth Mover’s Distance between sets of configurations.
This method is fully permutation-invariant without needing a canonicalization step. It solves the assignment problem for each atom type to find the minimum “work” required to transform one configuration into another.
void cacheInverseDistances(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info)
Pre-compute and cache raw inverse distances for given positions.
Call this once when positions are set (before an optimization loop). Subsequent calls to dist_at_cached() will reuse the cached 1/r values and only apply the lengthscale weighting.
void dist_at_cached(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info, const gpr::FieldMatrixd& lengthscale, gpr::FieldMatrixd& dist)
Compute dist_at using cached inverse distances.
Requires a prior call to cacheInverseDistances() with the same positions. Only recomputes the lengthscale-weighted sum. Falls back to dist_at() if cache is invalid.
void dist_at_cached_sq(const gpr::Coord& x1, const gpr::Coord& x2, const gpr::AtomsConfiguration& conf_info, const gpr::FieldMatrixd& lengthscale, gpr::FieldMatrixd& dist_sq)
Like dist_at_cached but returns SQUARED distances (skips final sqrt).
Use with se_kernel_exp_truncate_sq to avoid the sqrt + square roundtrip.