This is maybe only somewhat related, but there's a problem I have been trying to solve for about a year now involving lost degrees of freedom that is similar to gimbal lock. Maybe the smart people reading this comment section would have some ideas.

It is frequently more efficient to perform energy minimizations of molecules in a basis of "internal coordinates", in which parameters such as the distance between bonded atoms, the angle formed by three sequentially-bonded atoms, and the dihedral angle[0] formed by four sequentially bonded atoms are used as a coordinate system for minimization. This coordinate system is a lot more complex than the more natural Cartesian coordinate system, but it's more efficient for large molecules because you can e.g. twist a molecule along some central bond without screwing up the bond distances on the far ends of the molecule. Implementing optimization using internal coordinates is not entirely trivial, as the manifold of physically-meaningful internal coordinates is not flat, and internal coordinates tend to be over-specified, but it is often worth implementing despite the complexity.

Anyway, one major problem with this approach is that if three sequentially-bonded atoms ever become collinear (which admittedly is not super common, but it's common enough that we have to consider it), the Jacobian of that angle relative to the Cartesian coordinate system becomes ill-defined (because it is physically impossible to increase the angle, and the angle will decrease if any of the atoms moves in any direction orthogonal to the line that the 3 atoms lie on). Worse, any dihedral angle involving those 3 atoms becomes ill-defined, and if a structure passes through a configuration where the 3 atoms are collinear, the dihedral angle will discontinuously change by 180 degrees.

This causes all sorts of problems during energy minimization. The standard way to "solve" this problem is to define "dummy atoms", fictitious sites that are only used to construct well-defined bending and dihedral angles. But to prevent the dummy atom from "drifting away" since no real forces are acting on it (and to counteract the creation of 3 physically meaningless degrees of freedom), it becomes necessary to add constraints. So now we've turned an unconstrained minimization in a non-euclidean coordinate system to a constrained minimization in a non-euclidean coordinate system. And it's very ambiguous where the best place to put this "dummy atom" is, or how to define its constraints. And what happens if 4 atoms become collinear? Moreover, this is usually done manually, using "chemical intuition", and I am interested in writing code that works automatically for high-throughput applications where it would be infeasible to manually define dummy atoms.

My hope was that there would be some way to augment the traditional definition of the dihedral angle to avoid this singularity/discontinuity, but my attempts at implementing this failed to improve upon anything. My current approach tries to automatically add these dummy atoms, but I find that this has a tendency to make optimization performance drastically worse (presumably due to the sudden addition of constraints).

This problem has been on the backburner for some time now, but I would like to engineer some sort of solution that is more consistent and performant than my current approach, while still being entirely automated, without needing any "chemical intuition".

[0] https://en.wikipedia.org/wiki/Dihedral_angle#In_stereochemis...