Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating-point precision error in calculating angles #324

Closed
philipmnel opened this issue Sep 19, 2023 · 1 comment
Closed

Floating-point precision error in calculating angles #324

philipmnel opened this issue Sep 19, 2023 · 1 comment

Comments

@philipmnel
Copy link
Contributor

Describe the bug
When using qcel.util.measure_coordinates to measure an angle between coordinates, an angle of 180° can cause a nan value to be returned. The bug is caused by a floating-point precision error in calculating the cosine of the angle; if the cosine is greater than 1.0 due to noise then np.arccos will return nan.

To Reproduce

import qcelemental as qcel
import numpy as np

geometry= np.asarray([[0, 0, 0], [1, 0, 0], [2, 0, 0]])
angle = qcel.util.measure_coordinates(geometry, [0,1,2], True)
print(angle)

geometry= np.asarray([[-5.53102237, -12.51893475, -8.92439275], 
                      [-5.53102237, 2.9394029, 1.97762624], 
                      [-5.53102237, 18.39774056, 12.87964524]])
angle = qcel.util.measure_coordinates(geometry, [0,1,2], True)
print(angle)

The first prints 180.0 as expected, the second returns a nan (calculated cosine is 1.0000000000000002).

Using qcelemental 0.25.0

Expected behavior
The calculated cosine should be properly bounded within [-1, 1].

Additional context

@loriab
Copy link
Collaborator

loriab commented Sep 20, 2023

closed by #325

@loriab loriab closed this as completed Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants