You've hit on the fundamental challenge of using dihedral angles for clustering: circular topology. Even after sine/cosine transformation, each dihedral angle pair (sinθi,cosθi) lies on a unit circle (a 1D manifold embedded in 2D space). For multiple dihedrals, the full space becomes a torus (product of circles). Standard Euclidean distance in this transformed space violates circularity, causing artifacts near 0∘/360∘ boundaries. Here’s how to handle it rigorously:
Core Problem: Why Standard Clustering Fails
- Example: Two conformers differ only by θ=1∘ vs. θ=359∘.
- Euclidean distance:
Solutions: Handling Circular Data Correctly
1. Use Circular Distance Metrics (Most Critical Fix)
Replace Euclidean distance with a periodic distance metric designed for angles:
import numpy as np
def circular_distance(theta1, theta2):
"""Compute shortest angular distance between two angles (in degrees)."""
diff = np.abs(theta1 - theta2) % 360
return np.minimum(diff, 360 - diff)
- For multiple dihedrals: Compute pairwise circular distances across all dihedrals, then aggregate (e.g., sum of squared circular distances).
- In practice:
- Precompute a distance matrix using circular distances for all conformer pairs.
- Feed this matrix to clustering algorithms that accept precomputed distances (e.g.,
DBSCAN(metric='precomputed'), AgglomerativeClustering).
2. Kernel Methods: Embed into Reproducing Kernel Hilbert Space (RKHS)
Map angles to a space where circularity is "unfolded" using periodic kernels:
- Recommended kernel: Spectral Mixture Kernel or Periodic Kernel (from GPyTorch/scikit-learn):
k(θi,θ
where = period (360°), = lengthscale.
3. Topology-Aware Dimensionality Reduction
Reduce dimensionality while preserving circular topology:
4. Data Augmentation: "Unfold" the Circle
Duplicate data across 360∘ boundaries to make the space linear:
- For each conformer with dihedrals θi, generate copies at θi+360k ().
Practical Workflow for Octanoic Acid
- Select dihedrals: Focus on backbone rotatable bonds (e.g., C2-C3 to C7-C8 → 6 dihedrals). Carboxyl rotation is often less conformationally significant.
- Transform to circular coordinates:
Convert each θi to (sinθi,cos → (6 dihedrals × 2).
Why This Works for Octanoic Acid
- Flexible chain dominance: Octanoic acid's conformation is governed by 6–7 backbone dihedrals. Circular metrics ensure:
- A "gauche" rotamer at C3-C4 (60∘) clusters with itself (not its 420∘ equivalent).
- Extended "trans" chains (180) form distinct clusters from coiled ones ().
What NOT to Do
- ❌ Use raw (sinθ,cosθ) with K-Means: Euclidean distance fails at boundaries.
- ❌ Add 360∘ offsets manually: Creates artificial duplicates; doesn’t solve topology.
- ❌ Ignore circularity: Your clusters will be topologically inconsistent (e.g., rings of conformers split at 0).
Key Takeaway
The sine/cosine transform alone is insufficient—you must use a distance metric that respects circularity.
For conformer clustering:
✅ Precomputed circular distance matrices + DBSCAN/Agglomerative Clustering (simplest, most robust)
✅ Periodic kernel methods (if you have >1000 conformers and need scalability)
This approach is standard in computational chemistry (e.g., Lau & Becke, JCTC 2021 for torsion-driven clustering). For octanoic acid, it will cleanly separate extended, helical, and coiled conformers without artifacts.