Handwritten cosine similarity outputs NaN values for superimposed coordinates due to the singularity in v1 dot v2 / ||v1|| * ||v2|| when one of the vectors has zero distance.
Sometimes, during an MD simulation with many many many atoms, 2 atoms are randomly pushed to the same coordinate value.
When this happens torchani outputs NaN as an energy and the simulation breaks.
Handwritten cosine similarity outputs NaN values for superimposed coordinates due to the singularity in v1 dot v2 / ||v1|| * ||v2|| when one of the vectors has zero distance.
Sometimes, during an MD simulation with many many many atoms, 2 atoms are randomly pushed to the same coordinate value. When this happens torchani outputs NaN as an energy and the simulation breaks.
With clamp:
Without clamp:
Clamp should affect only angular terms so there is essentially no performance dip (~ 0.1 s maybe)